source: source/ariba/overlay/messages/DHTMessage.h@ 6786

Last change on this file since 6786 was 6786, checked in by mies, 15 years ago

Changed Data to Message conversion constructor in Message to explicit
Fixed some general bugs in Data: operator<<
Fixed bug in DHTMessage: allow unspecified key/values
Added local DHT message delivery
Adapted sources to work with gcc 4.4.1

File size: 1.9 KB
Line 
1#ifndef DHTMESSAGE_H_
2#define DHTMESSAGE_H_
3
4#include "ariba/utility/messages.h"
5#include "ariba/utility/serialization.h"
6
7namespace ariba {
8namespace overlay {
9
10using ariba::utility::Message;
11using_serialization;
12
13class DHTMessage : public Message { VSERIALIZEABLE
14public:
15 DHTMessage();
16 DHTMessage( const Data& key );
17 DHTMessage( const Data& key, const Data& value );
18 DHTMessage( const Data& key, const vector<Data>& values );
19 virtual ~DHTMessage();
20
21 const NodeID& getHashedKey() const {
22 return hash;
23 }
24
25 const Data& getKey() const {
26 return key;
27 }
28
29 /// returns the first element of the key vector
30 const Data& getValue() const {
31 return values.at(0);
32 }
33
34 bool hasValues() const {
35 values.size() != 0;
36 }
37
38 uint16_t getTTL() const {
39 return ttl;
40 }
41
42 void setTTL( uint16_t ttl ) {
43 this->ttl = ttl;
44 }
45
46 /// return alles values for the key
47 const vector<Data>& getValues() const {
48 return values;
49 }
50
51private:
52 NodeID hash;
53 uint16_t ttl;
54 Data key;
55 vector<Data> values;
56};
57
58}} // namespace ariba::overlay
59
60sznBeginDefault( ariba::overlay::DHTMessage, X ) {
61
62 X && ttl;
63
64// std::cout << "1" << std::endl;
65
66 // key serialization
67 uint16_t key_length = key.isUnspecified() ? 0 : key.getLength();
68 X && key_length;
69 if (X.isDeserializer()) key.setLength( key_length );
70
71// std::cout << "2 - " << key_length << std::endl;
72 X && this->key;
73// std::cout << "2b" << std::endl;
74
75 // store number of values
76 uint16_t num_values = values.size();
77 X && num_values;
78
79// std::cout << "3" << std::endl;
80
81 // value serialization
82 for (size_t i=0; i<num_values; i++) {
83// std::cout << "4" << std::endl;
84 Data value;
85 if (X.isSerializer()) value = values[i];
86 uint16_t value_length = value.isUnspecified() ? 0 : value.getLength();
87 X && value_length;
88// std::cout << "5" << std::endl;
89 if (X.isDeserializer()) value.setLength( value_length );
90 X && value;
91// std::cout << "6" << std::endl;
92 if (X.isDeserializer()) values.push_back(value);
93 }
94} sznEnd();
95
96#endif /* DHTMESSAGE_H_ */
Note: See TracBrowser for help on using the repository browser.