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}
2008-02-01 17:36:33 +00:00
|
|
|
#include "DHTGetPeersMessage.h"
|
2008-12-14 05:46:45 +00:00
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
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}
2008-02-01 17:36:33 +00:00
|
|
|
#include "DHTNode.h"
|
|
|
|
#include "Exception.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2008-02-11 12:32:46 +00:00
|
|
|
#include "MockDHTMessageFactory.h"
|
|
|
|
#include "MockDHTMessage.h"
|
|
|
|
#include "MockDHTMessageDispatcher.h"
|
|
|
|
#include "DHTTokenTracker.h"
|
|
|
|
#include "DHTPeerAnnounceStorage.h"
|
|
|
|
#include "DHTRoutingTable.h"
|
2010-06-19 17:54:54 +00:00
|
|
|
#include "bencode2.h"
|
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}
2008-02-01 17:36:33 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
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}
2008-02-01 17:36:33 +00:00
|
|
|
class DHTGetPeersMessageTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(DHTGetPeersMessageTest);
|
|
|
|
CPPUNIT_TEST(testGetBencodedMessage);
|
2008-02-11 12:32:46 +00:00
|
|
|
CPPUNIT_TEST(testDoReceivedAction);
|
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}
2008-02-01 17:36:33 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
|
|
void setUp() {}
|
|
|
|
|
|
|
|
void tearDown() {}
|
|
|
|
|
|
|
|
void testGetBencodedMessage();
|
2008-02-11 12:32:46 +00:00
|
|
|
void testDoReceivedAction();
|
|
|
|
|
|
|
|
class MockDHTMessageFactory2:public MockDHTMessageFactory {
|
|
|
|
public:
|
2013-06-21 16:10:38 +00:00
|
|
|
virtual std::shared_ptr<DHTResponseMessage>
|
2010-02-28 12:30:11 +00:00
|
|
|
createGetPeersReplyMessage
|
2013-06-21 16:10:38 +00:00
|
|
|
(const std::shared_ptr<DHTNode>& remoteNode,
|
|
|
|
const std::vector<std::shared_ptr<DHTNode> >& closestKNodes,
|
|
|
|
const std::vector<std::shared_ptr<Peer> >& peers,
|
2010-02-28 12:30:11 +00:00
|
|
|
const std::string& token,
|
|
|
|
const std::string& transactionID)
|
2008-02-11 12:32:46 +00:00
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<MockDHTResponseMessage> m
|
2010-06-13 11:25:21 +00:00
|
|
|
(new MockDHTResponseMessage
|
2010-06-21 13:51:56 +00:00
|
|
|
(localNode_, remoteNode, "get_peers", transactionID));
|
|
|
|
m->nodes_ = closestKNodes;
|
2010-08-07 14:15:21 +00:00
|
|
|
m->peers_ = peers;
|
2010-06-21 13:51:56 +00:00
|
|
|
m->token_ = token;
|
2008-02-11 12:32:46 +00:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
};
|
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}
2008-02-01 17:36:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DHTGetPeersMessageTest);
|
|
|
|
|
|
|
|
void DHTGetPeersMessageTest::testGetBencodedMessage()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DHTNode> localNode(new DHTNode());
|
|
|
|
std::shared_ptr<DHTNode> remoteNode(new DHTNode());
|
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}
2008-02-01 17:36:33 +00:00
|
|
|
|
2008-03-07 12:05:50 +00:00
|
|
|
unsigned char tid[DHT_TRANSACTION_ID_LENGTH];
|
2009-10-22 14:43:42 +00:00
|
|
|
util::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH);
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string transactionID(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]);
|
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}
2008-02-01 17:36:33 +00:00
|
|
|
|
|
|
|
unsigned char infoHash[DHT_ID_LENGTH];
|
2009-10-22 14:43:42 +00:00
|
|
|
util::generateRandomData(infoHash, DHT_ID_LENGTH);
|
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}
2008-02-01 17:36:33 +00:00
|
|
|
|
|
|
|
DHTGetPeersMessage msg(localNode, remoteNode, infoHash, transactionID);
|
2010-03-20 09:10:23 +00:00
|
|
|
msg.setVersion("A200");
|
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}
2008-02-01 17:36:33 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string msgbody = msg.getBencodedMessage();
|
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}
2008-02-01 17:36:33 +00:00
|
|
|
|
2010-06-19 17:54:54 +00:00
|
|
|
Dict dict;
|
|
|
|
dict.put("t", transactionID);
|
|
|
|
dict.put("v", "A200");
|
|
|
|
dict.put("y", "q");
|
|
|
|
dict.put("q", "get_peers");
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Dict> aDict = Dict::g();
|
2010-06-19 17:54:54 +00:00
|
|
|
aDict->put("id", String::g(localNode->getID(), DHT_ID_LENGTH));
|
|
|
|
aDict->put("info_hash", String::g(infoHash, DHT_ID_LENGTH));
|
|
|
|
dict.put("a", aDict);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(util::percentEncode(bencode2::encode(&dict)),
|
2010-03-07 14:24:21 +00:00
|
|
|
util::percentEncode(msgbody));
|
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}
2008-02-01 17:36:33 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-02-11 12:32:46 +00:00
|
|
|
void DHTGetPeersMessageTest::testDoReceivedAction()
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DHTNode> localNode(new DHTNode());
|
|
|
|
std::shared_ptr<DHTNode> remoteNode(new DHTNode());
|
2008-02-11 12:32:46 +00:00
|
|
|
remoteNode->setIPAddress("192.168.0.1");
|
|
|
|
remoteNode->setPort(6881);
|
|
|
|
|
2008-03-07 12:05:50 +00:00
|
|
|
unsigned char tid[DHT_TRANSACTION_ID_LENGTH];
|
2009-10-22 14:43:42 +00:00
|
|
|
util::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH);
|
2008-02-11 12:32:46 +00:00
|
|
|
std::string transactionID(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]);
|
|
|
|
|
|
|
|
unsigned char infoHash[DHT_ID_LENGTH];
|
2009-10-22 14:43:42 +00:00
|
|
|
util::generateRandomData(infoHash, DHT_ID_LENGTH);
|
2008-02-11 12:32:46 +00:00
|
|
|
|
|
|
|
DHTTokenTracker tokenTracker;
|
|
|
|
MockDHTMessageDispatcher dispatcher;
|
|
|
|
MockDHTMessageFactory2 factory;
|
|
|
|
factory.setLocalNode(localNode);
|
2010-08-07 14:15:21 +00:00
|
|
|
DHTRoutingTable routingTable(localNode);
|
2008-02-11 12:32:46 +00:00
|
|
|
|
|
|
|
DHTGetPeersMessage msg(localNode, remoteNode, infoHash, transactionID);
|
2010-11-12 12:48:48 +00:00
|
|
|
msg.setRoutingTable(&routingTable);
|
|
|
|
msg.setTokenTracker(&tokenTracker);
|
|
|
|
msg.setMessageDispatcher(&dispatcher);
|
|
|
|
msg.setMessageFactory(&factory);
|
2008-02-11 12:32:46 +00:00
|
|
|
{
|
|
|
|
// localhost has peer contact information for that infohash.
|
|
|
|
DHTPeerAnnounceStorage peerAnnounceStorage;
|
|
|
|
peerAnnounceStorage.addPeerAnnounce(infoHash, "192.168.0.100", 6888);
|
|
|
|
peerAnnounceStorage.addPeerAnnounce(infoHash, "192.168.0.101", 6889);
|
|
|
|
|
2010-11-12 12:48:48 +00:00
|
|
|
msg.setPeerAnnounceStorage(&peerAnnounceStorage);
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2008-02-11 12:32:46 +00:00
|
|
|
msg.doReceivedAction();
|
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher.messageQueue_.size());
|
2013-06-21 16:10:38 +00:00
|
|
|
auto m = std::dynamic_pointer_cast<MockDHTResponseMessage>
|
|
|
|
(dispatcher.messageQueue_[0].message_);
|
2010-11-11 07:33:43 +00:00
|
|
|
CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
|
|
|
|
CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
|
2008-02-11 12:32:46 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("get_peers"), m->getMessageType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID());
|
2010-06-21 13:51:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(tokenTracker.generateToken(infoHash, remoteNode->getIPAddress(), remoteNode->getPort()), m->token_);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, m->nodes_.size());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, m->peers_.size());
|
2008-02-11 12:32:46 +00:00
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Peer> peer = m->peers_[0];
|
2010-06-13 01:53:49 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.100"), peer->getIPAddress());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)6888, peer->getPort());
|
2008-02-11 12:32:46 +00:00
|
|
|
}
|
|
|
|
{
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Peer> peer = m->peers_[1];
|
2010-06-13 01:53:49 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.101"), peer->getIPAddress());
|
|
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)6889, peer->getPort());
|
2008-02-11 12:32:46 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
dispatcher.messageQueue_.clear();
|
2008-02-11 12:32:46 +00:00
|
|
|
{
|
|
|
|
// localhost doesn't have peer contact information for that infohash.
|
|
|
|
DHTPeerAnnounceStorage peerAnnounceStorage;
|
|
|
|
DHTRoutingTable routingTable(localNode);
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<DHTNode> returnNode1(new DHTNode());
|
2008-02-11 12:32:46 +00:00
|
|
|
routingTable.addNode(returnNode1);
|
|
|
|
|
2010-11-12 12:48:48 +00:00
|
|
|
msg.setPeerAnnounceStorage(&peerAnnounceStorage);
|
|
|
|
msg.setRoutingTable(&routingTable);
|
2008-02-11 12:32:46 +00:00
|
|
|
|
|
|
|
msg.doReceivedAction();
|
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher.messageQueue_.size());
|
2013-06-21 16:10:38 +00:00
|
|
|
auto m = std::dynamic_pointer_cast<MockDHTResponseMessage>
|
|
|
|
(dispatcher.messageQueue_[0].message_);
|
2010-11-11 07:33:43 +00:00
|
|
|
CPPUNIT_ASSERT(*localNode == *m->getLocalNode());
|
|
|
|
CPPUNIT_ASSERT(*remoteNode == *m->getRemoteNode());
|
2008-02-11 12:32:46 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("get_peers"), m->getMessageType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID());
|
2010-06-21 13:51:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(tokenTracker.generateToken(infoHash, remoteNode->getIPAddress(), remoteNode->getPort()), m->token_);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, m->nodes_.size());
|
2010-11-11 07:33:43 +00:00
|
|
|
CPPUNIT_ASSERT(*returnNode1 == *m->nodes_[0]);
|
2010-06-21 13:51:56 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, m->peers_.size());
|
2008-02-11 12:32:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|