int OverFillBuckets(smart_ptr<DhtImpl> &dhtObj, time_t rtt) { int added = 0; DhtID dctr; DhtPeerID peerId; peerId.addr.set_port(128); peerId.addr.set_addr4(0xf0f0f0f0); int numPrefixBits; for(int bucketNum=0; bucketNum < dhtObj->_buckets.size(); ++bucketNum) { numPrefixBits = 160 - dhtObj->_buckets[bucketNum]->span; for(int ctr=0; ctr<16; ++ctr) { // copy "first" for(int y=0; y<5; ++y) peerId.id.id[y] = dhtObj->_buckets[bucketNum]->first.id[y]; dctr.id[4] = ctr; // move the counter bits (4 bits) into the bits immediatly following the prefix bits // the bit range is 0 -> 159 for(int x=0; x<4; ++x) { ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(dctr, 3-x)); } (dhtObj->Update(peerId, 0, true, rtt))? ++added:0; } } return added; }
int FillPreallocatedBuckets(smart_ptr<DhtImpl> &dhtObj, time_t rtt) { int added = 0; DhtID dctr; DhtPeerID peerId; peerId.addr.set_port(128); peerId.addr.set_addr4(0xf0f0f0f0); for(int ctr=0; ctr<32; ++ctr) { dctr.id[4] = ctr; // put 8 nodes in the bucket for(int nodenum=0; nodenum<8; nodenum++) { // make a random myID for(int y=0; y<5; ++y) peerId.id.id[y] = rand(); // copy the counter bits (5 bits) into the upper 5 bits of the id to be added // (to address the particular preallocated bucket) for(int x=0; x<5; ++x) { ProgramBit(peerId.id, 159-x, GetBit(dctr, 4-x)); } // add the node (dhtObj->Update(peerId, 0, true, rtt))? ++added:0; } } return added; }
/** Uses the dht's ID (myId) as the base for nodes to be added. New nodes are always added to the bucket that contains myId thus forcing the split. The dht buckets quit splitting once the span of the bucket containing myId reaches 3 (decending from 160). At this there are only 8 possible ID's that can fill the 8 slots in the bucket. Note that the number of additions returned includes both new nodes added and existing nodes already in the list that are updated. */ int FillBucketList(smart_ptr<DhtImpl> &dhtObj, time_t rtt, SubPrefixType subPrefixType, int numPrefixBits = 0, int diff = 1) { int added = 0; if(numPrefixBits >=160 || numPrefixBits < 0) return added; DhtID subPrefixBits; DhtPeerID peerId; peerId.addr.set_port(128); peerId.addr.set_addr4(0xf0f0f0f0); for(int ctr=0; ctr<16; ++ctr) { // copy myID for(int y=0; y<5; ++y) peerId.id.id[y] = dhtObj->_my_id.id[y]; subPrefixBits.id[4] = subPrefixType==evenBitDistribution ? ctr : rand()*rand(); if(subPrefixType==evenBitDistribution) { // move the counter bits (4 bits) into the bits immediatly following the prefix bits // the bit range is 0 -> 159 for(int x=0; x<4; ++x) { ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(subPrefixBits, 3-x)); } } else { for(int x=0; x<32; ++x) { ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(subPrefixBits, x)); } } //dctr.id[4] = subPrefixType==evenBitDistribution ? ctr : rand()*rand(); //// move the counter bits (4 bits) into the bits immediatly following the prefix bits //// the bit range is 0 -> 159 //for(int x=0; x<32; ++x) //{ // ProgramBit(peerId.id, 159-numPrefixBits-x, GetBit(dctr, x)); //} (dhtObj->Update(peerId, 0, true, rtt))? ++added:0; } added += FillBucketList(dhtObj, rtt, subPrefixType, numPrefixBits+diff, diff); return added; }