2006-10-01 11:29:14 +00:00
|
|
|
#include "DefaultPeerListProcessor.h"
|
|
|
|
#include "MetaFileUtil.h"
|
|
|
|
#include "Exception.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Dictionary.h"
|
|
|
|
#include "Peer.h"
|
2006-10-01 11:29:14 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-10-01 11:29:14 +00:00
|
|
|
|
|
|
|
class DefaultPeerListProcessorTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(DefaultPeerListProcessorTest);
|
|
|
|
CPPUNIT_TEST(testExtractPeer);
|
|
|
|
CPPUNIT_TEST(testExtract2Peers);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void testExtractPeer();
|
|
|
|
void testExtract2Peers();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( DefaultPeerListProcessorTest );
|
|
|
|
|
|
|
|
void DefaultPeerListProcessorTest::testExtractPeer() {
|
2008-03-09 12:24:01 +00:00
|
|
|
DefaultPeerListProcessor proc;
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti2006eeee";
|
2006-10-01 11:29:14 +00:00
|
|
|
|
2008-08-07 14:21:50 +00:00
|
|
|
SharedHandle<Dictionary> dic
|
|
|
|
(dynamic_cast<Dictionary*>(MetaFileUtil::bdecoding(peersString)));
|
2006-10-18 14:57:00 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT(proc.canHandle(dic->get("peers")));
|
2006-10-01 11:29:14 +00:00
|
|
|
|
2008-05-12 11:05:21 +00:00
|
|
|
std::deque<SharedHandle<Peer> > peers;
|
|
|
|
proc.extractPeer(peers, dic->get("peers"));
|
2006-10-01 11:29:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, peers.size());
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Peer> peer = *peers.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->ipaddr);
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)2006, peer->port);
|
2006-10-01 11:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultPeerListProcessorTest::testExtract2Peers() {
|
2008-03-09 12:24:01 +00:00
|
|
|
DefaultPeerListProcessor proc;
|
2008-02-08 15:53:45 +00:00
|
|
|
std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti2006eed2:ip11:192.168.0.27:peer id20:aria2-000000000000004:porti2007eeee";
|
2006-10-01 11:29:14 +00:00
|
|
|
|
2008-08-07 14:21:50 +00:00
|
|
|
SharedHandle<Dictionary> dic
|
|
|
|
(dynamic_cast<Dictionary*>(MetaFileUtil::bdecoding(peersString)));
|
2006-10-01 11:29:14 +00:00
|
|
|
|
2008-05-12 11:05:21 +00:00
|
|
|
std::deque<SharedHandle<Peer> > peers;
|
|
|
|
proc.extractPeer(peers, dic->get("peers"));
|
2006-10-01 11:29:14 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, peers.size());
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<Peer> peer = *peers.begin();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->ipaddr);
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)2006, peer->port);
|
2006-10-01 11:29:14 +00:00
|
|
|
|
|
|
|
peer = *(peers.begin()+1);
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.2"), peer->ipaddr);
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((uint16_t)2007, peer->port);
|
2006-10-01 11:29:14 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|