| 1 | #include "DhtMessage.h"
|
---|
| 2 |
|
---|
| 3 | #include<boost/foreach.hpp>
|
---|
| 4 |
|
---|
| 5 | namespace ariba_service {
|
---|
| 6 | namespace dht {
|
---|
| 7 |
|
---|
| 8 | vsznDefault(DhtMessage);
|
---|
| 9 |
|
---|
| 10 | DhtMessage::DhtMessage() :
|
---|
| 11 | ttl( 0 ),
|
---|
| 12 | replace( false ),
|
---|
| 13 | sourceNode(NodeID::UNSPECIFIED)
|
---|
| 14 | {}
|
---|
| 15 |
|
---|
| 16 | DhtMessage::DhtMessage( DhtMessageType type, const std::string& key, const NodeID& sourceNodeID ) :
|
---|
| 17 | type( static_cast<uint8_t>(type) ),
|
---|
| 18 | ttl( 0 ),
|
---|
| 19 | replace( false ),
|
---|
| 20 | key( key ),
|
---|
| 21 | sourceNode(sourceNodeID)
|
---|
| 22 |
|
---|
| 23 | {}
|
---|
| 24 |
|
---|
| 25 | DhtMessage::DhtMessage( DhtMessageType type, const std::string& key,
|
---|
| 26 | const std::string& value, uint16_t ttl, const NodeID& sourceNodeID ) :
|
---|
| 27 | type( static_cast<uint8_t>(type) ),
|
---|
| 28 | ttl( ttl ),
|
---|
| 29 | replace( false ),
|
---|
| 30 | key( key ),
|
---|
| 31 | values(1, value),
|
---|
| 32 | sourceNode(sourceNodeID)
|
---|
| 33 | {}
|
---|
| 34 |
|
---|
| 35 | DhtMessage::DhtMessage( DhtMessageType type, const std::string& key,
|
---|
| 36 | const vector<string>& values, uint16_t ttl, const NodeID& sourceNodeID ) :
|
---|
| 37 | type( static_cast<uint8_t>(type) ),
|
---|
| 38 | ttl( ttl ),
|
---|
| 39 | replace( false ),
|
---|
| 40 | key( key ),
|
---|
| 41 | sourceNode(sourceNodeID)
|
---|
| 42 | {
|
---|
| 43 | // preallocate enough room so we don't need to copy a lot
|
---|
| 44 | this->values.reserve(values.size());
|
---|
| 45 | BOOST_FOREACH(const std::string value, values )
|
---|
| 46 | this->values.push_back( value );
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | DhtMessage::~DhtMessage() {
|
---|
| 50 | // empty
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | string DhtMessage::DhtMessageTypeToString(DhtMessageType type) {
|
---|
| 54 | string temp;
|
---|
| 55 | switch (type)
|
---|
| 56 | {
|
---|
| 57 | case DhtMessage::DhtInvalid:
|
---|
| 58 | {
|
---|
| 59 | temp = "DhtInvalid";
|
---|
| 60 | break;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | case DhtMessage::DhtGet:
|
---|
| 64 | {
|
---|
| 65 | temp = "DhtGet";
|
---|
| 66 | break;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | case DhtMessage::DhtPut:
|
---|
| 70 | {
|
---|
| 71 | temp = "DhtPut";
|
---|
| 72 | break;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | case DhtMessage::DhtPutAndGet:
|
---|
| 76 | {
|
---|
| 77 | temp = "DhtPutAndGet";
|
---|
| 78 | break;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | case DhtMessage::DhtRemove:
|
---|
| 82 | {
|
---|
| 83 | temp = "DhtRemove";
|
---|
| 84 | break;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | case DhtMessage::DhtRepublish:
|
---|
| 88 | {
|
---|
| 89 | temp = "DhtRepublish";
|
---|
| 90 | break;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | case DhtMessage::DhtAnswer:
|
---|
| 94 | {
|
---|
| 95 | temp = "DhtAnswer";
|
---|
| 96 | break;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | case DhtMessage::DhtReplica:
|
---|
| 100 | {
|
---|
| 101 | temp = "DhtReplica";
|
---|
| 102 | break;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | return temp;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | }}
|
---|