Changeset 6786 for source/ariba/overlay
- Timestamp:
- Nov 2, 2009, 1:31:19 AM (15 years ago)
- Location:
- source/ariba/overlay
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/overlay/BaseOverlay.cpp
r6760 r6786 727 727 sideport(&SideportListener::DEFAULT), started(false), counter(0) { 728 728 dht = new DHT(); 729 localDHT = new DHT(); 729 730 } 730 731 … … 1913 1914 if (msg->getType()==OverlayMsg::typeDHTData) { 1914 1915 const ServiceID& service = msg->getService(); 1915 logging_ debug( "Received DHT data for service " << service.toString() );1916 logging_info( "Received DHT data for service " << service.toString() ); 1916 1917 1917 1918 // delegate data message … … 1940 1941 1941 1942 case OverlayMsg::typeDHTGet: { 1943 logging_info("DHT-Get: key=" << dhtMsg->getKey() ); 1942 1944 vector<Data> vect = dht->get(dhtMsg->getKey()); 1945 BOOST_FOREACH(const Data& d, vect) 1946 logging_info("DHT-Get: value=" << d); 1943 1947 OverlayMsg omsg(*msg); 1944 1948 omsg.swapRoles(); … … 1946 1950 DHTMessage dhtmsg(dhtMsg->getKey(), vect); 1947 1951 omsg.encapsulate(&dhtmsg); 1948 this->send(&omsg, omsg.getDestinationNode());1952 dhtSend(&omsg, omsg.getDestinationNode()); 1949 1953 break; 1950 1954 } … … 1969 1973 /// put a value to the DHT with a ttl given in seconds 1970 1974 void BaseOverlay::dhtPut( const Data& key, const Data& value, int ttl ) { 1975 1976 logging_info("DHT: putting key=" << key 1977 << " value=" << value 1978 << " ttl=" << ttl 1979 ); 1980 1981 // put into local data store (for refreshes) 1982 localDHT->put(key,value,ttl); 1983 1971 1984 // calculate hash 1972 1985 NodeID dest = NodeID::sha1(key.getBuffer(), key.getLength() / 8); 1973 OverlayMsg msg(OverlayMsg::typeDHTPut);1974 1986 DHTMessage dhtmsg(key,value); 1975 1987 dhtmsg.setTTL(ttl); 1976 msg.setDestinationNode(dest); 1988 1989 OverlayMsg msg(OverlayMsg::typeDHTPut); 1977 1990 msg.encapsulate( &dhtmsg ); 1978 send(&msg, dest);1991 dhtSend(&msg, dest); 1979 1992 } 1980 1993 1981 1994 /// removes a key value pair from the DHT 1982 1995 void BaseOverlay::dhtRemove( const Data& key, const Data& value ) { 1996 // remove from local data store 1997 localDHT->remove(key,value); 1998 1983 1999 // calculate hash 1984 2000 NodeID dest = NodeID::sha1(key.getBuffer(), key.getLength() / 8); 2001 DHTMessage dhtmsg(key,value); 2002 2003 // send message 1985 2004 OverlayMsg msg(OverlayMsg::typeDHTRemove); 1986 DHTMessage dhtmsg(key,value);1987 msg.setDestinationNode(dest);1988 2005 msg.encapsulate( &dhtmsg ); 1989 send(&msg, dest);2006 dhtSend(&msg, dest); 1990 2007 } 1991 2008 … … 1994 2011 // calculate hash 1995 2012 NodeID dest = NodeID::sha1(key.getBuffer(), key.getLength() / 8); 2013 DHTMessage dhtmsg(key); 2014 2015 // send message 1996 2016 OverlayMsg msg(OverlayMsg::typeDHTRemove); 1997 DHTMessage dhtmsg(key);1998 msg.setDestinationNode(dest);1999 2017 msg.encapsulate( &dhtmsg ); 2000 send(&msg, dest);2018 dhtSend(&msg, dest); 2001 2019 } 2002 2020 2003 2021 /// requests data stored using key 2004 2022 void BaseOverlay::dhtGet( const Data& key, const ServiceID& service ) { 2023 logging_info("DHT: trying to resolve key=" << 2024 key << " for service=" << service.toString() ); 2025 2005 2026 // calculate hash 2006 2027 NodeID dest = NodeID::sha1(key.getBuffer(), key.getLength() / 8); 2028 DHTMessage dhtmsg(key); 2029 2030 // send message 2007 2031 OverlayMsg msg(OverlayMsg::typeDHTGet); 2008 DHTMessage dhtmsg(key);2009 msg.setDestinationNode(dest);2010 2032 msg.setService(service); 2011 2033 msg.encapsulate( &dhtmsg ); 2012 send(&msg, dest); 2013 } 2034 dhtSend(&msg, dest); 2035 } 2036 2037 void BaseOverlay::dhtSend( OverlayMsg* msg, const NodeID& dest ) { 2038 logging_info("DHT: sending message with key=" << dest.toString() ); 2039 msg->setSourceNode(this->nodeId); 2040 msg->setDestinationNode(dest); 2041 2042 // local storage? yes-> put into DHT directly 2043 if (overlayInterface->isClosestNodeTo(msg->getDestinationNode())) { 2044 Data d = data_serialize(msg); 2045 Message* m2 = new Message(d); 2046 OverlayMsg* m3 = m2->decapsulate<OverlayMsg>(); 2047 handleDHTMessage(m3); 2048 delete m2; 2049 return; 2050 } 2051 2052 // send message "normally" 2053 send(msg, dest); 2054 } 2055 2014 2056 2015 2057 }} // namespace ariba, overlay -
source/ariba/overlay/BaseOverlay.h
r6266 r6786 506 506 507 507 DHT* dht; 508 DHT* localDHT; 508 509 509 510 void stabilizeDHT(); 511 void dhtSend( OverlayMsg* msg, const NodeID& dest ); 510 512 511 513 // misc -------------------------------------------------------------------- -
source/ariba/overlay/messages/DHTMessage.h
r6266 r6786 62 62 X && ttl; 63 63 64 // std::cout << "1" << std::endl; 65 64 66 // key serialization 65 uint16_t key_length = key. getLength();67 uint16_t key_length = key.isUnspecified() ? 0 : key.getLength(); 66 68 X && key_length; 67 69 if (X.isDeserializer()) key.setLength( key_length ); 68 X && key; 70 71 // std::cout << "2 - " << key_length << std::endl; 72 X && this->key; 73 // std::cout << "2b" << std::endl; 69 74 70 75 // store number of values … … 72 77 X && num_values; 73 78 79 // std::cout << "3" << std::endl; 80 74 81 // value serialization 75 82 for (size_t i=0; i<num_values; i++) { 76 Data value = values[i]; 77 uint16_t value_length = value.getLength(); 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(); 78 87 X && value_length; 88 // std::cout << "5" << std::endl; 79 89 if (X.isDeserializer()) value.setLength( value_length ); 80 90 X && value; 91 // std::cout << "6" << std::endl; 81 92 if (X.isDeserializer()) values.push_back(value); 82 93 }
Note:
See TracChangeset
for help on using the changeset viewer.