mirror of
https://github.com/aria2/aria2.git
synced 2025-04-05 05:27:38 +03:00
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}
57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
#include "DHTNode.h"
|
|
#include "DHTNodeLookupEntry.h"
|
|
#include "DHTIDCloser.h"
|
|
#include "Exception.h"
|
|
#include "Util.h"
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
class DHTIDCloserTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(DHTIDCloserTest);
|
|
CPPUNIT_TEST(testOperator);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
public:
|
|
void setUp() {}
|
|
|
|
void tearDown() {}
|
|
|
|
void testOperator();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DHTIDCloserTest);
|
|
|
|
void DHTIDCloserTest::testOperator()
|
|
{
|
|
unsigned char id[DHT_ID_LENGTH];
|
|
memset(id, 0xf0, DHT_ID_LENGTH);
|
|
|
|
DHTNodeLookupEntryHandle e1 = new DHTNodeLookupEntry(new DHTNode(id));
|
|
|
|
id[0] = 0xb0;
|
|
DHTNodeLookupEntryHandle e2 = new DHTNodeLookupEntry(new DHTNode(id));
|
|
|
|
id[0] = 0xa0;
|
|
DHTNodeLookupEntryHandle e3 = new DHTNodeLookupEntry(new DHTNode(id));
|
|
|
|
id[0] = 0x80;
|
|
DHTNodeLookupEntryHandle e4 = new DHTNodeLookupEntry(new DHTNode(id));
|
|
|
|
id[0] = 0x00;
|
|
DHTNodeLookupEntryHandle e5 = new DHTNodeLookupEntry(new DHTNode(id));
|
|
|
|
DHTNodeLookupEntries entries;
|
|
entries.push_back(e1);
|
|
entries.push_back(e2);
|
|
entries.push_back(e3);
|
|
entries.push_back(e4);
|
|
entries.push_back(e5);
|
|
|
|
std::sort(entries.begin(), entries.end(), DHTIDCloser(e3->_node->getID()));
|
|
|
|
CPPUNIT_ASSERT(e3 == entries[0]);
|
|
CPPUNIT_ASSERT(e2 == entries[1]);
|
|
CPPUNIT_ASSERT(e4 == entries[2]);
|
|
CPPUNIT_ASSERT(e1 == entries[3]);
|
|
CPPUNIT_ASSERT(e5 == entries[4]);
|
|
}
|