mirror of https://github.com/aria2/aria2
2009-04-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Increase prefixLength for the bucket which doesn't own local node ID when splitting bucket. * src/DHTBucket.cc * test/DHTBucketTest.ccpull/1/head
parent
a0527905ff
commit
0e70ba46a9
|
@ -1,3 +1,10 @@
|
||||||
|
2009-04-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Increase prefixLength for the bucket which doesn't own local node
|
||||||
|
ID when splitting bucket.
|
||||||
|
* src/DHTBucket.cc
|
||||||
|
* test/DHTBucketTest.cc
|
||||||
|
|
||||||
2009-04-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-04-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
* Release 1.3.1
|
* Release 1.3.1
|
||||||
|
|
|
@ -185,38 +185,27 @@ SharedHandle<DHTBucket> DHTBucket::split()
|
||||||
|
|
||||||
DHTUtil::flipBit(_min, DHT_ID_LENGTH, _prefixLength);
|
DHTUtil::flipBit(_min, DHT_ID_LENGTH, _prefixLength);
|
||||||
|
|
||||||
size_t rPrefixLength;
|
++_prefixLength;
|
||||||
size_t lPrefixLength;
|
SharedHandle<DHTBucket> rBucket(new DHTBucket(_prefixLength,
|
||||||
if(isInRange(_localNode->getID(), rMax, rMin)) {
|
|
||||||
rPrefixLength = _prefixLength+1;
|
|
||||||
lPrefixLength = _prefixLength;
|
|
||||||
} else if(isInRange(_localNode->getID(), _max, _min)) {
|
|
||||||
rPrefixLength = _prefixLength;
|
|
||||||
lPrefixLength = _prefixLength+1;
|
|
||||||
} else {
|
|
||||||
rPrefixLength = _prefixLength;
|
|
||||||
lPrefixLength = _prefixLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedHandle<DHTBucket> rBucket(new DHTBucket(rPrefixLength,
|
|
||||||
rMax, rMin, _localNode));
|
rMax, rMin, _localNode));
|
||||||
std::deque<SharedHandle<DHTNode> > tempNodes = _nodes;
|
|
||||||
for(std::deque<SharedHandle<DHTNode> >::iterator i = tempNodes.begin();
|
std::deque<SharedHandle<DHTNode> > lNodes;
|
||||||
i != tempNodes.end();) {
|
for(std::deque<SharedHandle<DHTNode> >::iterator i = _nodes.begin();
|
||||||
|
i != _nodes.end(); ++i) {
|
||||||
if(rBucket->isInRange(*i)) {
|
if(rBucket->isInRange(*i)) {
|
||||||
assert(rBucket->addNode(*i));
|
assert(rBucket->addNode(*i));
|
||||||
i = tempNodes.erase(i);
|
|
||||||
} else {
|
} else {
|
||||||
++i;
|
lNodes.push_back(*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_prefixLength = lPrefixLength;
|
_nodes = lNodes;
|
||||||
_nodes = tempNodes;
|
|
||||||
// TODO create toString() and use it.
|
// TODO create toString() and use it.
|
||||||
_logger->debug("New bucket. Range:%s-%s",
|
_logger->debug("New bucket. prefixLength=%u, Range:%s-%s",
|
||||||
|
static_cast<unsigned int>(rBucket->getPrefixLength()),
|
||||||
Util::toHex(rBucket->getMinID(), DHT_ID_LENGTH).c_str(),
|
Util::toHex(rBucket->getMinID(), DHT_ID_LENGTH).c_str(),
|
||||||
Util::toHex(rBucket->getMaxID(), DHT_ID_LENGTH).c_str());
|
Util::toHex(rBucket->getMaxID(), DHT_ID_LENGTH).c_str());
|
||||||
_logger->debug("Existing bucket. Range:%s-%s",
|
_logger->debug("Existing bucket. prefixLength=%u, Range:%s-%s",
|
||||||
|
static_cast<unsigned int>(_prefixLength),
|
||||||
Util::toHex(getMinID(), DHT_ID_LENGTH).c_str(),
|
Util::toHex(getMinID(), DHT_ID_LENGTH).c_str(),
|
||||||
Util::toHex(getMaxID(), DHT_ID_LENGTH).c_str());
|
Util::toHex(getMaxID(), DHT_ID_LENGTH).c_str());
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
#include "DHTBucket.h"
|
#include "DHTBucket.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include <cstring>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -224,8 +227,7 @@ void DHTBucketTest::testSplit()
|
||||||
Util::toHex(bucket.getMaxID(), DHT_ID_LENGTH));
|
Util::toHex(bucket.getMaxID(), DHT_ID_LENGTH));
|
||||||
CPPUNIT_ASSERT_EQUAL(Util::toHex(expectedLMin, DHT_ID_LENGTH),
|
CPPUNIT_ASSERT_EQUAL(Util::toHex(expectedLMin, DHT_ID_LENGTH),
|
||||||
Util::toHex(bucket.getMinID(), DHT_ID_LENGTH));
|
Util::toHex(bucket.getMinID(), DHT_ID_LENGTH));
|
||||||
// prefixLength is not changed because bucket cannot include localNode
|
CPPUNIT_ASSERT_EQUAL((size_t)1, bucket.getPrefixLength());
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)0, bucket.getPrefixLength());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -268,8 +270,7 @@ void DHTBucketTest::testSplit()
|
||||||
Util::toHex(r->getMaxID(), DHT_ID_LENGTH));
|
Util::toHex(r->getMaxID(), DHT_ID_LENGTH));
|
||||||
CPPUNIT_ASSERT_EQUAL(Util::toHex(expectedRMin, DHT_ID_LENGTH),
|
CPPUNIT_ASSERT_EQUAL(Util::toHex(expectedRMin, DHT_ID_LENGTH),
|
||||||
Util::toHex(r->getMinID(), DHT_ID_LENGTH));
|
Util::toHex(r->getMinID(), DHT_ID_LENGTH));
|
||||||
// prefixLength is not changed because bucket cannot include localNode
|
CPPUNIT_ASSERT_EQUAL((size_t)1, r->getPrefixLength());
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)0, r->getPrefixLength());
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
unsigned char expectedLMax[DHT_ID_LENGTH];
|
unsigned char expectedLMax[DHT_ID_LENGTH];
|
||||||
|
|
Loading…
Reference in New Issue