diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-02-01 17:36:33 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-02-01 17:36:33 +0000 |
| commit | 0f133632298e31dab0efe6fd36f00c84d2175f33 (patch) | |
| tree | 0e9effc84f05b47e3a6c6ec4a9f7b38391d8be86 /test/DHTConnectionImplTest.cc | |
| parent | 0bce06348e3be57c97e246d2a7af71683dc76ede (diff) | |
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}
Diffstat (limited to 'test/DHTConnectionImplTest.cc')
| -rw-r--r-- | test/DHTConnectionImplTest.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/DHTConnectionImplTest.cc b/test/DHTConnectionImplTest.cc new file mode 100644 index 00000000..74c975af --- /dev/null +++ b/test/DHTConnectionImplTest.cc @@ -0,0 +1,47 @@ +#include "DHTConnectionImpl.h" +#include "Exception.h" +#include <cppunit/extensions/HelperMacros.h> + +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; + /*uint16_t con1port =*/ con1.bind(0); + DHTConnectionImpl con2; + uint16_t con2port = con2.bind(0); + + string message1 = "hello world."; + con1.sendMessage(message1.c_str(), message1.size(), "localhost", con2port); + + char readbuffer[100]; + string remoteHost; + uint16_t remotePort; + { + ssize_t rlength = con2.receiveMessage(readbuffer, sizeof(readbuffer), remoteHost, remotePort); + CPPUNIT_ASSERT_EQUAL(string("127.0.0.1"), remoteHost); + CPPUNIT_ASSERT_EQUAL((ssize_t)message1.size(), rlength); + readbuffer[rlength] = '\0'; + CPPUNIT_ASSERT_EQUAL(message1, string(readbuffer)); + } + } catch(Exception* e) { + cerr << *e << endl; + delete e; + CPPUNIT_FAIL("exception thrown"); + } +} |
