mirror of
https://github.com/aria2/aria2.git
synced 2025-01-01 15:44:55 +00:00
26d6692376
Added IPv6 DHT. Added --dht-entry-porint6, --dht-file-path6, --dht-listen-addr6 and --enable-dht6 option. IPv6 DHT is disabled by default. To use IPv6 DHT, you need to use --enable-dht6 and specify a global unicast address to --dht-listen-addr6. IPv6 DHT is highly experimental. * src/BtSetup.cc * src/DHTAutoSaveCommand.cc * src/DHTAutoSaveCommand.h * src/DHTConnectionImpl.cc * src/DHTConnectionImpl.h * src/DHTEntryPointNameResolveCommand.cc * src/DHTFindNodeReplyMessage.cc * src/DHTFindNodeReplyMessage.h * src/DHTGetPeersMessage.cc * src/DHTGetPeersReplyMessage.cc * src/DHTGetPeersReplyMessage.h * src/DHTMessageFactory.h * src/DHTMessageFactoryImpl.cc * src/DHTMessageFactoryImpl.h * src/DHTMessageTracker.cc * src/DHTRegistry.cc * src/DHTRegistry.h * src/DHTRoutingTableDeserializer.cc * src/DHTRoutingTableDeserializer.h * src/DHTRoutingTableSerializer.cc * src/DHTRoutingTableSerializer.h * src/DHTSetup.cc * src/DHTSetup.h * src/FtpConnection.cc * src/LpdMessageReceiver.cc * src/OptionHandlerFactory.cc * src/OptionHandlerImpl.h * src/PeerInteractionCommand.cc * src/RequestGroup.cc * src/SocketCore.cc * src/SocketCore.h * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/prefs.cc * src/prefs.h * src/usage_text.h * test/DHTConnectionImplTest.cc * test/DHTFindNodeReplyMessageTest.cc * test/DHTGetPeersMessageTest.cc * test/DHTGetPeersReplyMessageTest.cc * test/DHTMessageFactoryImplTest.cc * test/DHTRoutingTableDeserializerTest.cc * test/DHTRoutingTableSerializerTest.cc * test/LpdMessageDispatcherTest.cc * test/MockDHTMessageFactory.h
60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
#include "DHTConnectionImpl.h"
|
|
|
|
#include <iostream>
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include "Exception.h"
|
|
#include "SocketCore.h"
|
|
#include "A2STR.h"
|
|
|
|
namespace aria2 {
|
|
|
|
class DHTConnectionImplTest:public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(DHTConnectionImplTest);
|
|
CPPUNIT_TEST(testWriteAndReadData);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
public:
|
|
void setUp() {}
|
|
|
|
void tearDown() {}
|
|
|
|
void testWriteAndReadData();
|
|
};
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DHTConnectionImplTest);
|
|
|
|
void DHTConnectionImplTest::testWriteAndReadData()
|
|
{
|
|
try {
|
|
DHTConnectionImpl con1(AF_INET);
|
|
uint16_t con1port = 0;
|
|
CPPUNIT_ASSERT(con1.bind(con1port, A2STR::NIL));
|
|
|
|
DHTConnectionImpl con2(AF_INET);
|
|
uint16_t con2port = 0;
|
|
CPPUNIT_ASSERT(con2.bind(con2port, A2STR::NIL));
|
|
|
|
std::string message1 = "hello world.";
|
|
// hostname should be "localhost", not 127.0.0.1. Test failed on Mac OSX10.5
|
|
con1.sendMessage(reinterpret_cast<const unsigned char*>(message1.c_str()),
|
|
message1.size(), "localhost", con2port);
|
|
|
|
unsigned char readbuffer[100];
|
|
std::string remoteHost;
|
|
uint16_t remotePort;
|
|
{
|
|
while(!con2.getSocket()->isReadable(0));
|
|
ssize_t rlength = con2.receiveMessage(readbuffer, sizeof(readbuffer), remoteHost, remotePort);
|
|
CPPUNIT_ASSERT_EQUAL((ssize_t)message1.size(), rlength);
|
|
CPPUNIT_ASSERT_EQUAL(message1,
|
|
std::string(&readbuffer[0], &readbuffer[rlength]));
|
|
}
|
|
} catch(Exception& e) {
|
|
CPPUNIT_FAIL(e.stackTrace());
|
|
}
|
|
}
|
|
|
|
} // namespace aria2
|