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
112
test/DHTMessageTrackerTest.cc
Normal file
112
test/DHTMessageTrackerTest.cc
Normal file
|
@ -0,0 +1,112 @@
|
|||
#include "DHTMessageTracker.h"
|
||||
#include "Exception.h"
|
||||
#include "Util.h"
|
||||
#include "MockDHTMessage.h"
|
||||
#include "MockDHTMessageCallback.h"
|
||||
#include "DHTNode.h"
|
||||
#include "MetaEntry.h"
|
||||
#include "DHTMessageTrackerEntry.h"
|
||||
#include "DHTRoutingTable.h"
|
||||
#include "MockDHTMessageFactory.h"
|
||||
#include "Dictionary.h"
|
||||
#include "Data.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
class DHTMessageTrackerTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(DHTMessageTrackerTest);
|
||||
CPPUNIT_TEST(testMessageArrived);
|
||||
CPPUNIT_TEST(testHandleTimeout);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void setUp() {}
|
||||
|
||||
void tearDown() {}
|
||||
|
||||
void testMessageArrived();
|
||||
|
||||
void testHandleTimeout();
|
||||
|
||||
class MockDHTMessageCallback2:public MockDHTMessageCallback {
|
||||
public:
|
||||
uint32_t _countOnRecivedCalled;
|
||||
|
||||
MockDHTMessageCallback2():_countOnRecivedCalled(0) {}
|
||||
|
||||
virtual void onReceived(const DHTMessageHandle& message)
|
||||
{
|
||||
++_countOnRecivedCalled;
|
||||
}
|
||||
};
|
||||
|
||||
typedef SharedHandle<MockDHTMessageCallback2> MockDHTMessageCallback2Handle;
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(DHTMessageTrackerTest);
|
||||
|
||||
void DHTMessageTrackerTest::testMessageArrived()
|
||||
{
|
||||
DHTNodeHandle localNode = new DHTNode();
|
||||
DHTRoutingTableHandle routingTable = new DHTRoutingTable(localNode);
|
||||
MockDHTMessageFactoryHandle factory = new MockDHTMessageFactory();
|
||||
factory->setLocalNode(localNode);
|
||||
|
||||
MockDHTMessageHandle m1 = new MockDHTMessage(localNode, new DHTNode());
|
||||
MockDHTMessageHandle m2 = new MockDHTMessage(localNode, new DHTNode());
|
||||
MockDHTMessageHandle m3 = new MockDHTMessage(localNode, new DHTNode());
|
||||
|
||||
m1->getRemoteNode()->setIPAddress("192.168.0.1");
|
||||
m1->getRemoteNode()->setPort(6881);
|
||||
m2->getRemoteNode()->setIPAddress("192.168.0.2");
|
||||
m2->getRemoteNode()->setPort(6882);
|
||||
m3->getRemoteNode()->setIPAddress("192.168.0.3");
|
||||
m3->getRemoteNode()->setPort(6883);
|
||||
|
||||
MockDHTMessageCallback2Handle c2 = new MockDHTMessageCallback2();
|
||||
|
||||
DHTMessageTracker tracker;
|
||||
tracker.setRoutingTable(routingTable);
|
||||
tracker.setMessageFactory(factory);
|
||||
tracker.addMessage(m1);
|
||||
tracker.addMessage(m2, c2);
|
||||
tracker.addMessage(m3);
|
||||
|
||||
{
|
||||
SharedHandle<Dictionary> res = new Dictionary();
|
||||
res->put("t", new Data(m2->getTransactionID()));
|
||||
|
||||
std::pair<DHTMessageHandle, DHTMessageCallbackHandle> p =
|
||||
tracker.messageArrived(res.get(), m2->getRemoteNode()->getIPAddress(), m2->getRemoteNode()->getPort());
|
||||
DHTMessageHandle reply = p.first;
|
||||
|
||||
CPPUNIT_ASSERT(!reply.isNull());
|
||||
CPPUNIT_ASSERT_EQUAL((uint32_t)0, c2->_countOnRecivedCalled);
|
||||
CPPUNIT_ASSERT(tracker.getEntryFor(m2).isNull());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)2, tracker.countEntry());
|
||||
}
|
||||
{
|
||||
SharedHandle<Dictionary> res = new Dictionary();
|
||||
res->put("t", new Data(m3->getTransactionID()));
|
||||
|
||||
std::pair<DHTMessageHandle, DHTMessageCallbackHandle> p = tracker.messageArrived(res.get(), m3->getRemoteNode()->getIPAddress(), m3->getRemoteNode()->getPort());
|
||||
DHTMessageHandle reply = p.first;
|
||||
|
||||
CPPUNIT_ASSERT(!reply.isNull());
|
||||
CPPUNIT_ASSERT(tracker.getEntryFor(m3).isNull());
|
||||
CPPUNIT_ASSERT_EQUAL((size_t)1, tracker.countEntry());
|
||||
}
|
||||
{
|
||||
SharedHandle<Dictionary> res = new Dictionary();
|
||||
res->put("t", new Data(m1->getTransactionID()));
|
||||
|
||||
std::pair<DHTMessageHandle, DHTMessageCallbackHandle> p = tracker.messageArrived(res.get(), "192.168.1.100", 6889);
|
||||
DHTMessageHandle reply = p.first;
|
||||
|
||||
CPPUNIT_ASSERT(reply.isNull());
|
||||
}
|
||||
}
|
||||
|
||||
void DHTMessageTrackerTest::testHandleTimeout()
|
||||
{
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue