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 "DHTUtil.h"
|
|
|
|
#include "Exception.h"
|
|
|
|
#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"
|
2008-12-14 05:46:45 +00:00
|
|
|
#include "bencode.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:
|
|
|
|
virtual SharedHandle<DHTMessage>
|
|
|
|
createGetPeersReplyMessage(const SharedHandle<DHTNode>& remoteNode,
|
|
|
|
const std::deque<SharedHandle<Peer> >& peers,
|
|
|
|
const std::string& token,
|
|
|
|
const std::string& transactionID)
|
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MockDHTMessage> m
|
|
|
|
(new MockDHTMessage(_localNode, remoteNode, "get_peers", transactionID));
|
2008-02-11 12:32:46 +00:00
|
|
|
m->_peers = peers;
|
|
|
|
m->_token = token;
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SharedHandle<DHTMessage>
|
|
|
|
createGetPeersReplyMessage(const SharedHandle<DHTNode>& remoteNode,
|
|
|
|
const std::deque<SharedHandle<DHTNode> >& closestKNodes,
|
|
|
|
const std::string& token,
|
|
|
|
const std::string& transactionID)
|
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MockDHTMessage> m
|
|
|
|
(new MockDHTMessage(_localNode, remoteNode, "get_peers", transactionID));
|
2008-02-11 12:32:46 +00:00
|
|
|
m->_nodes = closestKNodes;
|
|
|
|
m->_token = token;
|
|
|
|
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()
|
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<DHTNode> localNode(new DHTNode());
|
|
|
|
SharedHandle<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];
|
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
|
|
|
DHTUtil::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];
|
|
|
|
DHTUtil::generateRandomData(infoHash, DHT_ID_LENGTH);
|
|
|
|
|
|
|
|
DHTGetPeersMessage msg(localNode, remoteNode, infoHash, transactionID);
|
|
|
|
|
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
|
|
|
|
2008-12-14 05:46:45 +00:00
|
|
|
bencode::BDE dict = bencode::BDE::dict();
|
|
|
|
dict["t"] = transactionID;
|
|
|
|
dict["y"] = bencode::BDE("q");
|
|
|
|
dict["q"] = bencode::BDE("get_peers");
|
|
|
|
bencode::BDE aDict = bencode::BDE::dict();
|
|
|
|
aDict["id"] = bencode::BDE(localNode->getID(), DHT_ID_LENGTH);
|
|
|
|
aDict["info_hash"] = bencode::BDE(infoHash, DHT_ID_LENGTH);
|
|
|
|
dict["a"] = aDict;
|
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-12-14 05:46:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(Util::urlencode(bencode::encode(dict)),
|
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
|
|
|
Util::urlencode(msgbody));
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-02-11 12:32:46 +00:00
|
|
|
void DHTGetPeersMessageTest::testDoReceivedAction()
|
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<DHTNode> localNode(new DHTNode());
|
|
|
|
SharedHandle<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];
|
2008-02-11 12:32:46 +00:00
|
|
|
DHTUtil::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH);
|
|
|
|
std::string transactionID(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]);
|
|
|
|
|
|
|
|
unsigned char infoHash[DHT_ID_LENGTH];
|
|
|
|
DHTUtil::generateRandomData(infoHash, DHT_ID_LENGTH);
|
|
|
|
|
|
|
|
DHTTokenTracker tokenTracker;
|
|
|
|
MockDHTMessageDispatcher dispatcher;
|
|
|
|
MockDHTMessageFactory2 factory;
|
|
|
|
factory.setLocalNode(localNode);
|
|
|
|
|
|
|
|
DHTGetPeersMessage msg(localNode, remoteNode, infoHash, transactionID);
|
2008-04-20 00:50:22 +00:00
|
|
|
msg.setTokenTracker(WeakHandle<DHTTokenTracker>
|
|
|
|
(&tokenTracker));
|
|
|
|
msg.setMessageDispatcher(WeakHandle<DHTMessageDispatcher>
|
|
|
|
(&dispatcher));
|
|
|
|
msg.setMessageFactory(WeakHandle<DHTMessageFactory>
|
|
|
|
(&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);
|
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
msg.setPeerAnnounceStorage(WeakHandle<DHTPeerAnnounceStorage>
|
|
|
|
(&peerAnnounceStorage));
|
2008-02-11 12:32:46 +00:00
|
|
|
|
|
|
|
msg.doReceivedAction();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher._messageQueue.size());
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MockDHTMessage> m
|
|
|
|
(dynamic_pointer_cast<MockDHTMessage>(dispatcher._messageQueue[0]._message));
|
2008-02-11 12:32:46 +00:00
|
|
|
CPPUNIT_ASSERT(localNode == m->getLocalNode());
|
|
|
|
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("get_peers"), m->getMessageType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID());
|
|
|
|
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());
|
|
|
|
{
|
|
|
|
SharedHandle<Peer> peer = m->_peers[0];
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.100"), peer->ipaddr);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)6888, peer->port);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SharedHandle<Peer> peer = m->_peers[1];
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.101"), peer->ipaddr);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)6889, peer->port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dispatcher._messageQueue.clear();
|
|
|
|
{
|
|
|
|
// localhost doesn't have peer contact information for that infohash.
|
|
|
|
DHTPeerAnnounceStorage peerAnnounceStorage;
|
|
|
|
DHTRoutingTable routingTable(localNode);
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<DHTNode> returnNode1(new DHTNode());
|
2008-02-11 12:32:46 +00:00
|
|
|
routingTable.addNode(returnNode1);
|
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
msg.setPeerAnnounceStorage(WeakHandle<DHTPeerAnnounceStorage>
|
|
|
|
(&peerAnnounceStorage));
|
|
|
|
msg.setRoutingTable(WeakHandle<DHTRoutingTable>
|
|
|
|
(&routingTable));
|
2008-02-11 12:32:46 +00:00
|
|
|
|
|
|
|
msg.doReceivedAction();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, dispatcher._messageQueue.size());
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MockDHTMessage> m
|
|
|
|
(dynamic_pointer_cast<MockDHTMessage>(dispatcher._messageQueue[0]._message));
|
2008-02-11 12:32:46 +00:00
|
|
|
CPPUNIT_ASSERT(localNode == m->getLocalNode());
|
|
|
|
CPPUNIT_ASSERT(remoteNode == m->getRemoteNode());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("get_peers"), m->getMessageType());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(msg.getTransactionID(), m->getTransactionID());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(tokenTracker.generateToken(infoHash, remoteNode->getIPAddress(), remoteNode->getPort()), m->_token);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, m->_nodes.size());
|
|
|
|
CPPUNIT_ASSERT(returnNode1 == m->_nodes[0]);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, m->_peers.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|