Ignore:
Timestamp:
Jun 18, 2012, 1:40:59 PM (12 years ago)
Author:
Michael Tänzer
Message:

Fix DHT: messages got lost if not communicating over a direct link.

Also:

  • Fix mem leak
  • Code clean up
File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/ariba/overlay/messages/DHTMessage.cpp

    r6919 r10572  
    88vsznDefault(DHTMessage);
    99
    10 DHTMessage::DHTMessage() {
    11         this->key.setLength(0);
    12         this->ttl = 0;
    13         this->replace = false;
    14 }
     10DHTMessage::DHTMessage() :
     11        ttl( 0 ),
     12        replace( false )
     13{}
    1514
    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 }
     15DHTMessage::DHTMessage( const Data& key ) :
     16        ttl( 0 ),
     17        replace( false ),
     18        key( key.clone() )
     19{}
    2320
    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 }
     21DHTMessage::DHTMessage( const Data& key, const Data& value ) :
     22        ttl( 0 ),
     23        replace( false ),
     24        key( key.clone() ),
     25        values(1, value.clone())
     26{}
    3227
    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();
     28DHTMessage::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());
    3635        BOOST_FOREACH(const Data value, values )
    3736                this->values.push_back( value.clone() );
    38         this->ttl = 0;
    39         this->replace = false;
    4037}
    4138
Note: See TracChangeset for help on using the changeset viewer.