Changeset 6786 for source/ariba
- Timestamp:
- Nov 2, 2009, 1:31:19 AM (15 years ago)
- Location:
- source/ariba
- Files:
-
- 9 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 } -
source/ariba/utility/addressing/facades/address_v.hpp
r5284 r6786 2 2 #define ADDRESS_V_H_ 3 3 4 #include <stdint.h> 4 5 #include <string> 5 6 #include <iostream> -
source/ariba/utility/addressing/facades/to_bytes_v.hpp
r5284 r6786 5 5 6 6 #include <memory> 7 #include <stdint.h> 7 8 #include "vfacade.hpp" 8 9 -
source/ariba/utility/addressing/port_address.hpp
r5284 r6786 5 5 6 6 #include<string> 7 #include<cstdio> 8 7 9 #include<boost/tr1/functional.hpp> 8 10 -
source/ariba/utility/messages/Message.h
r5484 r6786 105 105 * data. 106 106 */ 107 inline Message( const Data& data ) :107 explicit inline Message( const Data& data ) : 108 108 srcAddr(NULL),destAddr(NULL), releasePayload(true) { 109 109 this->payload = data.clone(); -
source/ariba/utility/serialization/Data.hpp
r5870 r6786 49 49 template<typename T = uint8_t, typename DataModel = DefaultDataModel<uint8_t> > class DataTpl; 50 50 typedef DataTpl<> Data; 51 template<typename T, typename DataModel> std::ostream& operator<<(std::ostream& stream, DataTpl<T, DataModel>& data);51 template<typename T, typename DataModel> std::ostream& operator<<(std::ostream& stream, const DataTpl<T, DataModel>& data); 52 52 53 53 //== internal includes == … … 324 324 }; 325 325 326 /* default human readable text output */327 template<typename T, typename DataModel>328 std::ostream& operator<<(std::ostream& stream, DataTpl<T, DataModel>& data) {329 stream << "[" << bitstr(data.getBuffer(), data.getLength(), 4)330 << "|'";331 char* buffer = (char*) data.getBuffer();332 for (size_t i = 0; i < data.getLength() / 8; i++) {333 char c = buffer[i] < 32 ? '.' : buffer[i];334 stream << c;335 }336 stream << "']";337 return stream;338 }339 340 326 /* unspecified type */ 341 327 template<typename T, typename DataModel> … … 397 383 398 384 finline int32_t length() const { 399 return bufferLen;385 return (bufferLen == -1) ? 0 : bufferLen; 400 386 } 401 387 … … 442 428 }sznEnd(); 443 429 430 /* default human readable text output */ 431 template<typename T, typename DataModel> 432 std::ostream& operator<<(std::ostream& stream, const DataTpl<T, DataModel>& data) { 433 stream << "[" << bitstr(data.getBuffer(), data.getLength(), 4) 434 << "|'"; 435 const char* buffer = (const char*) data.getBuffer(); 436 for (size_t i = 0; i < data.getLength() / 8; i++) { 437 char c = buffer[i] < 32 ? '.' : buffer[i]; 438 stream << c; 439 } 440 stream << "']"; 441 return stream; 442 } 444 443 #endif /* DATA_HPP_ */ -
source/ariba/utility/transport/tcpip/protlib/address.cpp
r5876 r6786 534 534 char ipstr[INET6_ADDRSTRLEN] = {0}; 535 535 // look for / 536 i = strchr( str,'/');536 i = strchr((char*)str,'/'); 537 537 if (i) { 538 538 iplen = i-str;
Note:
See TracChangeset
for help on using the changeset viewer.