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

Last change on this file since 10643 was 10573, checked in by Michael Tänzer, 12 years ago

Doh, fix some errors that somehow slipped through a non-clean make

File size: 1.9 KB
RevLine 
[6266]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
[10573]21 NodeID getHashedKey() const {
[10572]22 return NodeID::sha1( key.getBuffer(), key.getLength() / 8 );
[6266]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 {
[6919]35 return values.size() != 0;
[6266]36 }
37
38 uint16_t getTTL() const {
39 return ttl;
40 }
41
42 void setTTL( uint16_t ttl ) {
43 this->ttl = ttl;
44 }
45
[6835]46 void setReplace( bool replace ) {
47 this->replace = replace;
48 }
49
50 bool doReplace() const {
51 return replace;
52 }
53
[6266]54 /// return alles values for the key
55 const vector<Data>& getValues() const {
56 return values;
57 }
58
59private:
60 uint16_t ttl;
[6835]61 bool replace;
[6266]62 Data key;
63 vector<Data> values;
64};
65
66}} // namespace ariba::overlay
67
68sznBeginDefault( ariba::overlay::DHTMessage, X ) {
69
[6835]70 // serialize flags
71 X && replace && cI(0,7);
72
73 // serialize tll
[6266]74 X && ttl;
75
76 // key serialization
[6786]77 uint16_t key_length = key.isUnspecified() ? 0 : key.getLength();
[6266]78 X && key_length;
79 if (X.isDeserializer()) key.setLength( key_length );
[6786]80 X && this->key;
81
[6266]82 // store number of values
83 uint16_t num_values = values.size();
84 X && num_values;
85
86 // value serialization
87 for (size_t i=0; i<num_values; i++) {
[6786]88 Data value;
89 if (X.isSerializer()) value = values[i];
90 uint16_t value_length = value.isUnspecified() ? 0 : value.getLength();
[6266]91 X && value_length;
92 if (X.isDeserializer()) value.setLength( value_length );
93 X && value;
94 if (X.isDeserializer()) values.push_back(value);
95 }
96} sznEnd();
97
98#endif /* DHTMESSAGE_H_ */
Note: See TracBrowser for help on using the repository browser.