mirror of
https://github.com/aria2/aria2.git
synced 2025-04-05 13:37:40 +03:00
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline. DHT is disabled by default. To enable it, give --enable-dht to aria2c. You may need to specify entry point to DHT network using --dht-entry-point. DHT uses UDP port to listen incoming message. Use --dht-listen-port to specify port number. Make sure that your firewall configuration can pass through UDP traffic to the port. The routing table is saved in $HOME/.aria2/dht.dat. * src/DHT* * src/BNode.{h, cc} * src/PeerInteractionCommand.cc: enable DHT functionality for a particular torrent. * src/Data.cc: Rewritten ctor. * src/OptionHandlerFactory.cc: Added --enable-dht, --dht-listen-port, --dht-entry-point. * src/DefaultBtInteractive.cc: Send port message if dht is enabled. * src/RequestGroup.cc: Initialize DHT functionality. When download ends, remove BtContext from DHTPeerAnnounceStorage. * src/BtPortMessage.{h, cc}: Rewritten. * src/message.h * src/OptionHandlerImpl.cc * src/option_processing.cc: Added --enable-dht, --dht-listen-port, --dht-entry-point. * src/Dictionary.{h, cc} (remove): New function. * src/prefs.h * src/DefaultBtMessageFactory.h * src/BtHandshakeMessage.cc * src/ActivePeerConnectionCommand.cc * src/SocketCore.{h, cc}: Added datagram socket support. * src/DefaultBtMessageFactory.cc * src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here. Create DHT commands. * src/BtMessageFactory.h * src/PeerMessageUtil.{h, cc}
This commit is contained in:
parent
0bce06348e
commit
0f13363229
209 changed files with 14405 additions and 117 deletions
69
test/DHTFindNodeReplyMessageTest.cc
Normal file
69
test/DHTFindNodeReplyMessageTest.cc
Normal file
|
@ -0,0 +1,69 @@
|
|||
#include "DHTFindNodeReplyMessage.h"
|
||||
#include "DHTNode.h"
|
||||
#include "DHTUtil.h"
|
||||
#include "BencodeVisitor.h"
|
||||
#include "Dictionary.h"
|
||||
#include "Data.h"
|
||||
#include "Exception.h"
|
||||
#include "Util.h"
|
||||
#include "DHTBucket.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
class DHTFindNodeReplyMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(DHTFindNodeReplyMessageTest);
|
||||
CPPUNIT_TEST(testGetBencodedMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void setUp() {}
|
||||
|
||||
void tearDown() {}
|
||||
|
||||
void testGetBencodedMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(DHTFindNodeReplyMessageTest);
|
||||
|
||||
void DHTFindNodeReplyMessageTest::testGetBencodedMessage()
|
||||
{
|
||||
DHTNodeHandle localNode = new DHTNode();
|
||||
DHTNodeHandle remoteNode = new DHTNode();
|
||||
|
||||
char tid[DHT_TRANSACTION_ID_LENGTH];
|
||||
DHTUtil::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH);
|
||||
string transactionID(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]);
|
||||
|
||||
DHTFindNodeReplyMessage msg(localNode, remoteNode, transactionID);
|
||||
|
||||
string compactNodeInfo;
|
||||
DHTNodeHandle nodes[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
for(size_t i = 0; i < DHTBucket::K; ++i) {
|
||||
nodes[i] = new DHTNode();
|
||||
nodes[i]->setIPAddress("192.168.0."+Util::uitos(i+1));
|
||||
nodes[i]->setPort(6881+i);
|
||||
|
||||
char buf[6];
|
||||
CPPUNIT_ASSERT(PeerMessageUtil::createcompact(buf, nodes[i]->getIPAddress(), nodes[i]->getPort()));
|
||||
compactNodeInfo +=
|
||||
string(&nodes[i]->getID()[0], &nodes[i]->getID()[DHT_ID_LENGTH])+
|
||||
string(&buf[0], &buf[sizeof(buf)]);
|
||||
}
|
||||
msg.setClosestKNodes(DHTNodes(&nodes[0], &nodes[DHTBucket::K]));
|
||||
|
||||
string msgbody = msg.getBencodedMessage();
|
||||
|
||||
SharedHandle<Dictionary> cm = new Dictionary();
|
||||
cm->put("t", new Data(transactionID));
|
||||
cm->put("y", new Data("r"));
|
||||
Dictionary* r = new Dictionary();
|
||||
cm->put("r", r);
|
||||
r->put("id", new Data(reinterpret_cast<const char*>(localNode->getID()), DHT_ID_LENGTH));
|
||||
r->put("nodes", new Data(compactNodeInfo));
|
||||
|
||||
BencodeVisitor v;
|
||||
cm->accept(&v);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(v.getBencodedData(), msgbody);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue