2010-08-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added support for peers6 key in tracker response.  Added added6,
	added6.f and dropped6 in ut_pex.
	* src/BtAnnounce.cc
	* src/BtAnnounce.h
	* src/DefaultBtAnnounce.cc
	* src/UTPexExtensionMessage.cc
	* src/UTPexExtensionMessage.h
	* test/DefaultBtAnnounceTest.cc
	* test/UTPexExtensionMessageTest.cc
This commit is contained in:
Tatsuhiro Tsujikawa 2010-08-05 11:54:44 +00:00
parent cba1283aae
commit c685ea9de9
8 changed files with 131 additions and 19 deletions

View file

@ -81,19 +81,33 @@ void UTPexExtensionMessageTest::testGetBencodedData()
p4->startBadCondition();
CPPUNIT_ASSERT(msg.addDroppedPeer(p4));
SharedHandle<Peer> p5(new Peer("1002:1035:4527:3546:7854:1237:3247:3217",
6881));
CPPUNIT_ASSERT(msg.addFreshPeer(p5));
SharedHandle<Peer> p6(new Peer("2001:db8:bd05:1d2:288a:1fc0:1:10ee", 6882));
p6->startBadCondition();
CPPUNIT_ASSERT(msg.addDroppedPeer(p6));
unsigned char c1[COMPACT_LEN_IPV6];
unsigned char c2[COMPACT_LEN_IPV6];
unsigned char c3[COMPACT_LEN_IPV6];
unsigned char c4[COMPACT_LEN_IPV6];
unsigned char c5[COMPACT_LEN_IPV6];
unsigned char c6[COMPACT_LEN_IPV6];
bittorrent::packcompact(c1, p1->getIPAddress(), p1->getPort());
bittorrent::packcompact(c2, p2->getIPAddress(), p2->getPort());
bittorrent::packcompact(c3, p3->getIPAddress(), p3->getPort());
bittorrent::packcompact(c4, p4->getIPAddress(), p4->getPort());
bittorrent::packcompact(c5, p5->getIPAddress(), p5->getPort());
bittorrent::packcompact(c6, p6->getIPAddress(), p6->getPort());
std::string expected = "d5:added12:"+
std::string(&c1[0], &c1[6])+std::string(&c2[0], &c2[6])+
"7:added.f2:"+util::fromHex("0200")+"7:dropped12:"+
std::string(&c3[0], &c3[6])+std::string(&c4[0], &c4[6])+
"7:added.f2:"+util::fromHex("0200")+
"6:added618:"+std::string(&c5[0], &c5[COMPACT_LEN_IPV6])+
"8:added6.f1:"+util::fromHex("00")+
"7:dropped12:"+std::string(&c3[0], &c3[6])+std::string(&c4[0], &c4[6])+
"8:dropped618:"+std::string(&c6[0], &c6[COMPACT_LEN_IPV6])+
"e";
std::string bd = msg.getPayload();
CPPUNIT_ASSERT_EQUAL(util::percentEncode(expected),
@ -125,12 +139,13 @@ void UTPexExtensionMessageTest::testDoReceivedAction()
p1->allocateSessionResource(256*1024, 1024*1024);
p1->setAllBitfield();
msg.addFreshPeer(p1);// added seeder, check add.f flag
SharedHandle<Peer> p2(new Peer("10.1.1.2", 9999));
SharedHandle<Peer> p2(new Peer("1002:1035:4527:3546:7854:1237:3247:3217",
9999));
msg.addFreshPeer(p2);
SharedHandle<Peer> p3(new Peer("192.168.0.2", 6882));
p3->startBadCondition();
msg.addDroppedPeer(p3);
SharedHandle<Peer> p4(new Peer("10.1.1.3", 10000));
SharedHandle<Peer> p4(new Peer("2001:db8:bd05:1d2:288a:1fc0:1:10ee", 10000));
p4->startBadCondition();
msg.addDroppedPeer(p4);
msg.setPeerStorage(peerStorage_);
@ -145,9 +160,19 @@ void UTPexExtensionMessageTest::testDoReceivedAction()
}
{
SharedHandle<Peer> p = peerStorage_->getPeers()[1];
CPPUNIT_ASSERT_EQUAL(std::string("10.1.1.2"), p->getIPAddress());
CPPUNIT_ASSERT_EQUAL(std::string("1002:1035:4527:3546:7854:1237:3247:3217"),
p->getIPAddress());
CPPUNIT_ASSERT_EQUAL((uint16_t)9999, p->getPort());
}
{
SharedHandle<Peer> p = peerStorage_->getPeers()[2];
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), p->getIPAddress());
}
{
SharedHandle<Peer> p = peerStorage_->getPeers()[3];
CPPUNIT_ASSERT_EQUAL(std::string("2001:db8:bd05:1d2:288a:1fc0:1:10ee"),
p->getIPAddress());
}
}
void UTPexExtensionMessageTest::testCreate()
@ -156,17 +181,24 @@ void UTPexExtensionMessageTest::testCreate()
unsigned char c2[COMPACT_LEN_IPV6];
unsigned char c3[COMPACT_LEN_IPV6];
unsigned char c4[COMPACT_LEN_IPV6];
unsigned char c5[COMPACT_LEN_IPV6];
unsigned char c6[COMPACT_LEN_IPV6];
bittorrent::packcompact(c1, "192.168.0.1", 6881);
bittorrent::packcompact(c2, "10.1.1.2", 9999);
bittorrent::packcompact(c3, "192.168.0.2", 6882);
bittorrent::packcompact(c4, "10.1.1.3",10000);
bittorrent::packcompact(c5, "1002:1035:4527:3546:7854:1237:3247:3217", 6997);
bittorrent::packcompact(c6, "2001:db8:bd05:1d2:288a:1fc0:1:10ee",6998);
char id[1] = { 1 };
std::string data = std::string(&id[0], &id[1])+"d5:added12:"+
std::string(&c1[0], &c1[6])+std::string(&c2[0], &c2[6])+
"7:added.f2:207:dropped12:"+
std::string(&c3[0], &c3[6])+std::string(&c4[0], &c4[6])+
"7:added.f2:"+util::fromHex("0200")+
"6:added618:"+std::string(&c5[0], &c5[COMPACT_LEN_IPV6])+
"8:added6.f1:"+util::fromHex("00")+
"7:dropped12:"+std::string(&c3[0], &c3[6])+std::string(&c4[0], &c4[6])+
"8:dropped618:"+std::string(&c6[0], &c6[COMPACT_LEN_IPV6])+
"e";
SharedHandle<UTPexExtensionMessage> msg =
@ -174,14 +206,18 @@ void UTPexExtensionMessageTest::testCreate()
(reinterpret_cast<const unsigned char*>(data.c_str()), data.size());
CPPUNIT_ASSERT_EQUAL((uint8_t)1, msg->getExtensionMessageID());
CPPUNIT_ASSERT_EQUAL((size_t)2, msg->getFreshPeers().size());
CPPUNIT_ASSERT_EQUAL((size_t)3, msg->getFreshPeers().size());
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"),
msg->getFreshPeers()[0]->getIPAddress());
CPPUNIT_ASSERT_EQUAL((uint16_t)6881, msg->getFreshPeers()[0]->getPort());
CPPUNIT_ASSERT_EQUAL(std::string("10.1.1.2"),
msg->getFreshPeers()[1]->getIPAddress());
CPPUNIT_ASSERT_EQUAL((uint16_t)9999, msg->getFreshPeers()[1]->getPort());
CPPUNIT_ASSERT_EQUAL((size_t)2, msg->getDroppedPeers().size());
CPPUNIT_ASSERT_EQUAL(std::string("1002:1035:4527:3546:7854:1237:3247:3217"),
msg->getFreshPeers()[2]->getIPAddress());
CPPUNIT_ASSERT_EQUAL((uint16_t)6997, msg->getFreshPeers()[2]->getPort());
CPPUNIT_ASSERT_EQUAL((size_t)3, msg->getDroppedPeers().size());
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"),
msg->getDroppedPeers()[0]->getIPAddress());
CPPUNIT_ASSERT_EQUAL((uint16_t)6882, msg->getDroppedPeers()[0]->getPort());
@ -189,6 +225,11 @@ void UTPexExtensionMessageTest::testCreate()
msg->getDroppedPeers()[1]->getIPAddress());
CPPUNIT_ASSERT_EQUAL((uint16_t)10000,
msg->getDroppedPeers()[1]->getPort());
CPPUNIT_ASSERT_EQUAL(std::string("2001:db8:bd05:1d2:288a:1fc0:1:10ee"),
msg->getDroppedPeers()[2]->getIPAddress());
CPPUNIT_ASSERT_EQUAL((uint16_t)6998,
msg->getDroppedPeers()[2]->getPort());
try {
// 0 length data
std::string in = "";