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 "SocketCore.h"
|
2011-10-18 13:57:59 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
2008-03-03 11:30:12 +00:00
|
|
|
#include <iostream>
|
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 <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2011-10-18 13:57:59 +00:00
|
|
|
#include "a2functional.h"
|
|
|
|
#include "Exception.h"
|
|
|
|
|
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 SocketCoreTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(SocketCoreTest);
|
|
|
|
CPPUNIT_TEST(testWriteAndReadDatagram);
|
2008-11-26 12:50:07 +00:00
|
|
|
CPPUNIT_TEST(testGetSocketError);
|
2011-10-18 13:57:59 +00:00
|
|
|
CPPUNIT_TEST(testInetNtop);
|
2012-05-13 16:17:50 +00:00
|
|
|
CPPUNIT_TEST(testInetPton);
|
2011-10-19 14:14:13 +00:00
|
|
|
CPPUNIT_TEST(testGetBinAddr);
|
2012-04-01 07:42:38 +00:00
|
|
|
CPPUNIT_TEST(testVerifyHostname);
|
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 testWriteAndReadDatagram();
|
2008-11-26 12:50:07 +00:00
|
|
|
void testGetSocketError();
|
2011-10-18 13:57:59 +00:00
|
|
|
void testInetNtop();
|
2012-05-13 16:17:50 +00:00
|
|
|
void testInetPton();
|
2011-10-19 14:14:13 +00:00
|
|
|
void testGetBinAddr();
|
2012-04-01 07:42:38 +00:00
|
|
|
void testVerifyHostname();
|
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(SocketCoreTest);
|
|
|
|
|
|
|
|
void SocketCoreTest::testWriteAndReadDatagram()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
SocketCore s(SOCK_DGRAM);
|
|
|
|
s.bind(0);
|
|
|
|
SocketCore c(SOCK_DGRAM);
|
|
|
|
c.bind(0);
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
std::pair<std::string, uint16_t> svaddr;
|
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
|
|
|
s.getAddrInfo(svaddr);
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string message1 = "hello world.";
|
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
|
|
|
c.writeData(message1.c_str(), message1.size(), "localhost", svaddr.second);
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string message2 = "chocolate coated pie";
|
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
|
|
|
c.writeData(message2.c_str(), message2.size(), "localhost", svaddr.second);
|
|
|
|
|
|
|
|
char readbuffer[100];
|
2008-02-08 15:53:45 +00:00
|
|
|
std::pair<std::string, uint16_t> peer;
|
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
|
|
|
{
|
|
|
|
ssize_t rlength = s.readDataFrom(readbuffer, sizeof(readbuffer), peer);
|
2008-02-02 13:06:55 +00:00
|
|
|
// commented out because ip address may vary
|
2008-02-08 15:53:45 +00:00
|
|
|
//CPPUNIT_ASSERT_EQUAL(std::std::string("127.0.0.1"), peer.first);
|
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_ASSERT_EQUAL((ssize_t)message1.size(), rlength);
|
|
|
|
readbuffer[rlength] = '\0';
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(message1, std::string(readbuffer));
|
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-20 13:02:48 +00:00
|
|
|
ssize_t rlength = s.readDataFrom(readbuffer, sizeof(readbuffer), peer);
|
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_ASSERT_EQUAL((ssize_t)message2.size(), rlength);
|
|
|
|
readbuffer[rlength] = '\0';
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(message2, std::string(readbuffer));
|
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-04-27 02:22:14 +00:00
|
|
|
} catch(Exception& e) {
|
|
|
|
std::cerr << e.stackTrace() << std::endl;
|
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_FAIL("exception thrown");
|
|
|
|
}
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-11-26 12:50:07 +00:00
|
|
|
void SocketCoreTest::testGetSocketError()
|
|
|
|
{
|
|
|
|
SocketCore s;
|
|
|
|
s.bind(0);
|
|
|
|
// See there is no error at this point
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(""), s.getSocketError());
|
|
|
|
}
|
|
|
|
|
2011-10-18 13:57:59 +00:00
|
|
|
void SocketCoreTest::testInetNtop()
|
|
|
|
{
|
|
|
|
char dest[NI_MAXHOST];
|
|
|
|
{
|
|
|
|
std::string s = "192.168.0.1";
|
|
|
|
addrinfo* res;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, callGetaddrinfo(&res, s.c_str(), 0, AF_INET,
|
|
|
|
SOCK_STREAM, 0, 0));
|
|
|
|
WSAAPI_AUTO_DELETE<struct addrinfo*> resDeleter(res, freeaddrinfo);
|
|
|
|
sockaddr_in addr;
|
|
|
|
memcpy(&addr, res->ai_addr, sizeof(addr));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, inetNtop(AF_INET, &addr.sin_addr,
|
|
|
|
dest, sizeof(dest)));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(s, std::string(dest));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::string s = "2001:db8::2:1";
|
|
|
|
addrinfo* res;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, callGetaddrinfo(&res, s.c_str(), 0, AF_INET6,
|
|
|
|
SOCK_STREAM, 0, 0));
|
|
|
|
WSAAPI_AUTO_DELETE<struct addrinfo*> resDeleter(res, freeaddrinfo);
|
|
|
|
sockaddr_in6 addr;
|
|
|
|
memcpy(&addr, res->ai_addr, sizeof(addr));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, inetNtop(AF_INET6, &addr.sin6_addr,
|
|
|
|
dest, sizeof(dest)));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(s, std::string(dest));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-13 16:17:50 +00:00
|
|
|
void SocketCoreTest::testInetPton()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char ipaddr[] = "192.168.0.1";
|
2012-05-16 14:28:19 +00:00
|
|
|
in_addr ans;
|
2012-05-13 16:17:50 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, net::getBinAddr(&ans, ipaddr));
|
|
|
|
in_addr dest;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, inetPton(AF_INET, ipaddr, &dest));
|
2012-05-16 14:28:19 +00:00
|
|
|
CPPUNIT_ASSERT(memcmp(&ans, &dest, sizeof(ans)) == 0);
|
2012-05-13 16:17:50 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
const char ipaddr[] = "2001:db8::2:1";
|
2012-05-16 14:28:19 +00:00
|
|
|
in6_addr ans;
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)16, net::getBinAddr(&ans, ipaddr));
|
2012-05-13 16:17:50 +00:00
|
|
|
in6_addr dest;
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, inetPton(AF_INET6, ipaddr, &dest));
|
2012-05-16 14:28:19 +00:00
|
|
|
CPPUNIT_ASSERT(memcmp(&ans, &dest, sizeof(ans)) == 0);
|
2012-05-13 16:17:50 +00:00
|
|
|
}
|
|
|
|
unsigned char dest[16];
|
|
|
|
CPPUNIT_ASSERT_EQUAL(-1, inetPton(AF_INET, "localhost", &dest));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(-1, inetPton(AF_INET6, "localhost", &dest));
|
|
|
|
}
|
|
|
|
|
2011-10-19 14:14:13 +00:00
|
|
|
void SocketCoreTest::testGetBinAddr()
|
|
|
|
{
|
|
|
|
unsigned char dest[16];
|
|
|
|
unsigned char ans1[] = { 192, 168, 0, 1 };
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)4, net::getBinAddr(dest, "192.168.0.1"));
|
|
|
|
CPPUNIT_ASSERT(std::equal(&dest[0], &dest[4], &ans1[0]));
|
|
|
|
|
|
|
|
unsigned char ans2[] = { 0x20u, 0x01u, 0x0du, 0xb8u,
|
|
|
|
0x00u, 0x00u, 0x00u, 0x00u,
|
|
|
|
0x00u, 0x00u, 0x00u, 0x00u,
|
|
|
|
0x00u, 0x02u, 0x00u, 0x01u };
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)16, net::getBinAddr(dest, "2001:db8::2:1"));
|
|
|
|
CPPUNIT_ASSERT(std::equal(&dest[0], &dest[16], &ans2[0]));
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, net::getBinAddr(dest, "localhost"));
|
|
|
|
}
|
|
|
|
|
2012-04-01 07:42:38 +00:00
|
|
|
void SocketCoreTest::testVerifyHostname()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::vector<std::string> dnsNames, ipAddrs;
|
|
|
|
std::string commonName;
|
|
|
|
CPPUNIT_ASSERT(!net::verifyHostname("example.org",
|
|
|
|
dnsNames, ipAddrs, commonName));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Only commonName is provided
|
|
|
|
std::vector<std::string> dnsNames, ipAddrs;
|
|
|
|
std::string commonName = "example.org";
|
|
|
|
CPPUNIT_ASSERT(net::verifyHostname("example.org",
|
|
|
|
dnsNames, ipAddrs, commonName));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Match against dNSName in subjectAltName
|
|
|
|
std::vector<std::string> dnsNames, ipAddrs;
|
|
|
|
dnsNames.push_back("foo");
|
|
|
|
dnsNames.push_back("example.org");
|
|
|
|
std::string commonName = "exampleX.org";
|
|
|
|
CPPUNIT_ASSERT(net::verifyHostname("example.org",
|
|
|
|
dnsNames, ipAddrs, commonName));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// If dNsName is provided, don't match with commonName
|
|
|
|
std::vector<std::string> dnsNames, ipAddrs;
|
|
|
|
dnsNames.push_back("foo");
|
|
|
|
dnsNames.push_back("exampleX.org");
|
|
|
|
ipAddrs.push_back("example.org");
|
|
|
|
std::string commonName = "example.org";
|
|
|
|
CPPUNIT_ASSERT(!net::verifyHostname("example.org",
|
|
|
|
dnsNames, ipAddrs, commonName));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// IPAddress in dnsName don't match.
|
|
|
|
std::vector<std::string> dnsNames, ipAddrs;
|
|
|
|
dnsNames.push_back("192.168.0.1");
|
|
|
|
std::string commonName = "example.org";
|
|
|
|
CPPUNIT_ASSERT(!net::verifyHostname("192.168.0.1",
|
|
|
|
dnsNames, ipAddrs, commonName));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// IPAddress string match with commonName
|
|
|
|
std::vector<std::string> dnsNames, ipAddrs;
|
|
|
|
std::string commonName = "192.168.0.1";
|
|
|
|
CPPUNIT_ASSERT(net::verifyHostname("192.168.0.1",
|
|
|
|
dnsNames, ipAddrs, commonName));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Match against iPAddress in subjectAltName
|
|
|
|
std::vector<std::string> dnsNames, ipAddrs;
|
|
|
|
unsigned char binAddr[16];
|
|
|
|
size_t len;
|
|
|
|
len = net::getBinAddr(binAddr, "192.168.0.1");
|
|
|
|
ipAddrs.push_back(std::string(binAddr, binAddr+len));
|
|
|
|
std::string commonName = "example.org";
|
|
|
|
CPPUNIT_ASSERT(net::verifyHostname("192.168.0.1",
|
|
|
|
dnsNames, ipAddrs, commonName));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Match against iPAddress (ipv6) in subjectAltName
|
|
|
|
std::vector<std::string> dnsNames, ipAddrs;
|
|
|
|
unsigned char binAddr[16];
|
|
|
|
size_t len;
|
|
|
|
len = net::getBinAddr(binAddr, "::1");
|
|
|
|
ipAddrs.push_back(std::string(binAddr, binAddr+len));
|
|
|
|
std::string commonName = "example.org";
|
|
|
|
CPPUNIT_ASSERT(net::verifyHostname("::1",
|
|
|
|
dnsNames, ipAddrs, commonName));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// If iPAddress is privided, don't match with commonName
|
|
|
|
std::vector<std::string> dnsNames, ipAddrs;
|
|
|
|
unsigned char binAddr[16];
|
|
|
|
size_t len;
|
|
|
|
len = net::getBinAddr(binAddr, "192.168.0.2");
|
|
|
|
ipAddrs.push_back(std::string(binAddr, binAddr+len));
|
|
|
|
std::string commonName = "192.168.0.1";
|
|
|
|
CPPUNIT_ASSERT(!net::verifyHostname("192.168.0.1",
|
|
|
|
dnsNames, ipAddrs, commonName));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|