Changeset 10572 for source/ariba/overlay
- Timestamp:
- Jun 18, 2012, 1:40:59 PM (13 years ago)
- Location:
- source/ariba/overlay
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/overlay/BaseOverlay.cpp
r9971 r10572 1832 1832 1833 1833 // handle dht messages (do not route) 1834 if (overlayMsg->isDHTMessage()) 1835 return handleDHTMessage(overlayMsg); 1834 if (overlayMsg->isDHTMessage()) { 1835 bool ret = handleDHTMessage(overlayMsg); 1836 delete overlayMsg; 1837 return ret; 1838 } 1836 1839 1837 1840 // handle signaling messages (do not route!) … … 2161 2164 2162 2165 // route message to closest node 2163 if (!overlayInterface->isClosestNodeTo( msg->getDestinationNode())) {2166 if (!overlayInterface->isClosestNodeTo(dhtMsg->getHashedKey())) { 2164 2167 logging_debug("Routing DHT message to closest node " 2165 2168 << " from " << msg->getSourceNode() 2166 << " to " << msg->getDestinationNode()2169 << " to " << dhtMsg->getHashedKey() 2167 2170 ); 2168 route( msg);2169 delete msg;2171 dhtSend(msg, dhtMsg->getHashedKey()); 2172 delete dhtMsg; 2170 2173 return true; 2171 2174 } … … 2219 2222 return false; 2220 2223 } 2221 delete msg;2224 delete dhtMsg; 2222 2225 return true; 2223 2226 } … … 2239 2242 } 2240 2243 2241 // calculate hash2242 NodeID dest = NodeID::sha1(key.getBuffer(), key.getLength() / 8);2243 2244 DHTMessage dhtmsg( key, value ); 2244 2245 dhtmsg.setReplace( replace ); … … 2247 2248 OverlayMsg msg( OverlayMsg::typeDHTPut ); 2248 2249 msg.encapsulate( &dhtmsg ); 2249 dhtSend(&msg, d est);2250 dhtSend(&msg, dhtmsg.getHashedKey()); 2250 2251 } 2251 2252 … … 2255 2256 localDHT->remove(key,value); 2256 2257 2257 // calculate hash2258 NodeID dest = NodeID::sha1(key.getBuffer(), key.getLength() / 8);2259 2258 DHTMessage dhtmsg(key,value); 2260 2259 … … 2262 2261 OverlayMsg msg(OverlayMsg::typeDHTRemove); 2263 2262 msg.encapsulate( &dhtmsg ); 2264 dhtSend(&msg, d est);2263 dhtSend(&msg, dhtmsg.getHashedKey()); 2265 2264 } 2266 2265 … … 2270 2269 logging_info("DHT-Remove: Removing key=" << key ); 2271 2270 2272 // calculate hash2273 NodeID dest = NodeID::sha1(key.getBuffer(), key.getLength() / 8);2274 2271 DHTMessage dhtmsg(key); 2275 2272 … … 2277 2274 OverlayMsg msg(OverlayMsg::typeDHTRemove); 2278 2275 msg.encapsulate( &dhtmsg ); 2279 dhtSend(&msg, d est);2276 dhtSend(&msg, dhtmsg.getHashedKey()); 2280 2277 } 2281 2278 … … 2286 2283 key << " for service=" << service.toString() ); 2287 2284 2288 // calculate hash2289 NodeID dest = NodeID::sha1(key.getBuffer(), key.getLength() / 8);2290 2285 DHTMessage dhtmsg(key); 2291 2286 … … 2294 2289 msg.setService(service); 2295 2290 msg.encapsulate( &dhtmsg ); 2296 dhtSend(&msg, d est);2291 dhtSend(&msg, dhtmsg.getHashedKey()); 2297 2292 } 2298 2293 … … 2303 2298 /// set source and destination 2304 2299 msg->setSourceNode(this->nodeId); 2305 msg->setDestinationNode(dest);2306 2300 2307 2301 // local storage? yes-> put into DHT directly 2308 if (overlayInterface->isClosestNodeTo(msg->getDestinationNode())) { 2302 if (overlayInterface->isClosestNodeTo(dest)) { 2303 // be compatible with old code so set destination to hashed key 2304 msg->setDestinationNode(dest); 2305 2309 2306 Data d = data_serialize(msg); 2310 Message* m2 = new Message(d); 2311 OverlayMsg* m3 = m2->decapsulate<OverlayMsg>(); 2307 Message m2(d); 2308 OverlayMsg* m3 = m2.decapsulate<OverlayMsg>(); 2309 2312 2310 handleDHTMessage(m3); 2313 delete m2; 2311 2312 delete m3; 2314 2313 return; 2315 } 2316 2317 // send message "normally" 2318 send( msg, dest ); 2314 } else { 2315 // need to route 2316 NodeID next_hop = overlayInterface->getNextNodeId(dest); 2317 msg->setDestinationNode(next_hop); 2318 2319 send(msg, next_hop); 2320 2321 return; 2322 } 2319 2323 } 2320 2324 -
source/ariba/overlay/messages/DHTMessage.cpp
r6919 r10572 8 8 vsznDefault(DHTMessage); 9 9 10 DHTMessage::DHTMessage() { 11 this->key.setLength(0); 12 this->ttl = 0; 13 this->replace = false; 14 } 10 DHTMessage::DHTMessage() : 11 ttl( 0 ), 12 replace( false ) 13 {} 15 14 16 DHTMessage::DHTMessage( const Data& key ) { 17 // calculate hash of key 18 this->hash = NodeID::sha1( key.getBuffer(), key.getLength() / 8 ); 19 this->key = key.clone(); 20 this->ttl = 0; 21 this->replace = false; 22 } 15 DHTMessage::DHTMessage( const Data& key ) : 16 ttl( 0 ), 17 replace( false ), 18 key( key.clone() ) 19 {} 23 20 24 DHTMessage::DHTMessage( const Data& key, const Data& value ) { 25 // calculate hash of key 26 this->hash = NodeID::sha1( key.getBuffer(), key.getLength() / 8 ); 27 this->key = key.clone(); 28 this->values.push_back( value.clone() ); 29 this->ttl = 0; 30 this->replace = false; 31 } 21 DHTMessage::DHTMessage( const Data& key, const Data& value ) : 22 ttl( 0 ), 23 replace( false ), 24 key( key.clone() ), 25 values(1, value.clone()) 26 {} 32 27 33 DHTMessage::DHTMessage( const Data& key, const vector<Data>& values ) { 34 this->hash = NodeID::sha1( key.getBuffer(), key.getLength() / 8 ); 35 this->key = key.clone(); 28 DHTMessage::DHTMessage( const Data& key, const vector<Data>& values ) : 29 ttl( 0 ), 30 replace( false ), 31 key( key.clone() ) 32 { 33 // preallocate enough room so we don't need to copy a lot 34 this->values.reserve(values.size()); 36 35 BOOST_FOREACH(const Data value, values ) 37 36 this->values.push_back( value.clone() ); 38 this->ttl = 0;39 this->replace = false;40 37 } 41 38 -
source/ariba/overlay/messages/DHTMessage.h
r6919 r10572 20 20 21 21 const NodeID& getHashedKey() const { 22 return hash;22 return NodeID::sha1( key.getBuffer(), key.getLength() / 8 ); 23 23 } 24 24 … … 58 58 59 59 private: 60 NodeID hash;61 60 uint16_t ttl; 62 61 bool replace; -
source/ariba/overlay/modules/OverlayInterface.h
r8606 r10572 145 145 */ 146 146 virtual const LinkID& getNextLinkId( const NodeID& id ) const = 0; 147 148 /** 149 * Returns the NodeID of the next hop a route message would take. 150 * 151 * @param id The destination node id 152 * @return The node id of the next hop 153 */ 154 virtual const NodeID& getNextNodeId( const NodeID& id ) const; 147 155 148 156 //--- functions from CommunicationListener that we _can_ use as overlay --- -
source/ariba/overlay/modules/chord/Chord.cpp
r7744 r10572 201 201 } 202 202 203 /// @see OverlayInterface.h 204 const NodeID& Chord::getNextNodeId( const NodeID& id ) const { 205 // get next hop 206 const route_item* item = table->get_next_hop(id); 207 208 // return unspecified if no next hop could be found 209 if (item == NULL) { 210 return NodeID::UNSPECIFIED; 211 } 212 213 return item->id; 214 } 215 203 216 OverlayInterface::NodeList Chord::getKnownNodes(bool deep) const { 204 217 OverlayInterface::NodeList nodelist; -
source/ariba/overlay/modules/chord/Chord.h
r6854 r10572 104 104 /// @see OverlayInterface.h 105 105 virtual const LinkID& getNextLinkId( const NodeID& id ) const; 106 107 /// @see OverlayInterface.h 108 virtual const NodeID& getNextNodeId( const NodeID& id ) const; 106 109 107 110 /// @see OverlayInterface.h -
source/ariba/overlay/modules/onehop/OneHop.cpp
r8620 r10572 122 122 } 123 123 124 /// @see OverlayInterface.h 125 const NodeID& OneHop::getNextNodeId( const NodeID& id ) const { 126 OverlayNodeMapping::const_iterator i = overlayNodes.find( id ); 127 128 // FIXME: in case the NodeID is not known we should return the nearest node 129 if (i == overlayNodes.end()) { 130 return NodeID::UNSPECIFIED; 131 } 132 133 return i->first; 134 } 135 124 136 void OneHop::createOverlay() { 125 137 // don't need to bootstrap against ourselfs. -
source/ariba/overlay/modules/onehop/OneHop.h
r6266 r10572 85 85 /// @see OverlayInterface.h 86 86 virtual const LinkID& getNextLinkId( const NodeID& id ) const; 87 88 /// @see OverlayInterface.h 89 virtual const NodeID& getNextNodeId( const NodeID& id ) const; 87 90 88 91 /// @see OverlayInterface.h
Note:
See TracChangeset
for help on using the changeset viewer.