diff --git a/ChangeLog b/ChangeLog index c3fc5fd4..cf2dce3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2009-04-23 Tatsuhiro Tsujikawa + + Rewritten PeerListProcessor + * src/PeerListProcessor.h + * src/CompactPeerListProcessor.h: Removed + * src/CompactPeerListProcessor.cc: Removed + * src/DelegatingPeerListProcessor.cc: Removed. + * src/DefaultBtAnnounce.cc + * src/Makefile.am + * src/UTPexExtensionMessage.cc + * src/DefaultPeerListProcessor.h: Removed. + * src/DefaultPeerListProcessor.cc: Removed. + * src/DelegatingPeerListProcessor.h: Removed. + * test/Makefile.am + * test/PeerListProcessorTest.cc + * test/DefaultPeerListProcessorTest.cc: Removed. + 2009-04-23 Tatsuhiro Tsujikawa Rewritten RequestGroupMan::calculateStat() diff --git a/src/CompactPeerListProcessor.cc b/src/CompactPeerListProcessor.cc deleted file mode 100644 index 1feb78a4..00000000 --- a/src/CompactPeerListProcessor.cc +++ /dev/null @@ -1,69 +0,0 @@ -/* - * aria2 - The high speed download utility - * - * Copyright (C) 2006 Tatsuhiro Tsujikawa - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * In addition, as a special exception, the copyright holders give - * permission to link the code of portions of this program with the - * OpenSSL library under certain conditions as described in each - * individual source file, and distribute linked combinations - * including the two. - * You must obey the GNU General Public License in all respects - * for all of the code used other than OpenSSL. If you modify - * file(s) with this exception, you may extend this exception to your - * version of the file(s), but you are not obligated to do so. If you - * do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source - * files in the program, then also delete it here. - */ -/* copyright --> */ -#include "CompactPeerListProcessor.h" -#include "a2netcompat.h" -#include "bencode.h" -#include "Peer.h" - -namespace aria2 { - -CompactPeerListProcessor::CompactPeerListProcessor() {} - -CompactPeerListProcessor::~CompactPeerListProcessor() {} - -bool CompactPeerListProcessor::canHandle(const bencode::BDE& peerData) const -{ - return peerData.isString(); -} - -void CompactPeerListProcessor::extractPeer -(std::deque >& peers, const bencode::BDE& peerData) -{ - if(!canHandle(peerData)) { - return; - } - size_t length = peerData.s().size(); - if(length%6 == 0) { - for(size_t i = 0; i < length; i += 6) { - struct in_addr in; - in.s_addr = *(uint32_t*)(peerData.s().c_str()+i); - std::string ipaddr = inet_ntoa(in); - uint16_t port = ntohs(*(uint16_t*)(peerData.s().c_str()+i+4)); - PeerHandle peer(new Peer(ipaddr, port)); - peers.push_back(peer); - } - } -} - -} // namespace aria2 diff --git a/src/CompactPeerListProcessor.h b/src/CompactPeerListProcessor.h deleted file mode 100644 index 6a72444d..00000000 --- a/src/CompactPeerListProcessor.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * aria2 - The high speed download utility - * - * Copyright (C) 2006 Tatsuhiro Tsujikawa - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * In addition, as a special exception, the copyright holders give - * permission to link the code of portions of this program with the - * OpenSSL library under certain conditions as described in each - * individual source file, and distribute linked combinations - * including the two. - * You must obey the GNU General Public License in all respects - * for all of the code used other than OpenSSL. If you modify - * file(s) with this exception, you may extend this exception to your - * version of the file(s), but you are not obligated to do so. If you - * do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source - * files in the program, then also delete it here. - */ -/* copyright --> */ -#ifndef _D_COMPACT_PEER_LIST_PROCESSOR_H_ -#define _D_COMPACT_PEER_LIST_PROCESSOR_H_ - -#include "PeerListProcessor.h" - -namespace aria2 { - -class CompactPeerListProcessor : public PeerListProcessor { -public: - CompactPeerListProcessor(); - - virtual ~CompactPeerListProcessor(); - - virtual void extractPeer - (std::deque >& peers, const bencode::BDE& peerData); - - virtual bool canHandle(const bencode::BDE& peerData) const; -}; - -} // namespace aria2 - -#endif // _D_COMPACT_PEER_LIST_PROCESSOR_H_ diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc index 5086532b..a2e99f1f 100644 --- a/src/DefaultBtAnnounce.cc +++ b/src/DefaultBtAnnounce.cc @@ -35,7 +35,7 @@ #include "DefaultBtAnnounce.h" #include "LogFactory.h" #include "Logger.h" -#include "DelegatingPeerListProcessor.h" +#include "PeerListProcessor.h" #include "Util.h" #include "prefs.h" #include "DlAbortEx.h" @@ -250,15 +250,14 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse, logger->debug("Incomplete:%d", incomplete); } const bencode::BDE& peerData = dict[BtAnnounce::PEERS]; - if(!peerData.isNone()) { + if(peerData.isNone()) { + logger->info(MSG_NO_PEER_LIST_RECEIVED); + } else { if(!btRuntime->isHalt() && btRuntime->lessThanMinPeers()) { - DelegatingPeerListProcessor proc; std::deque > peers; - proc.extractPeer(peers, peerData); + PeerListProcessor().extractPeer(peerData, std::back_inserter(peers)); peerStorage->addPeer(peers); } - } else { - logger->info(MSG_NO_PEER_LIST_RECEIVED); } } diff --git a/src/DefaultPeerListProcessor.cc b/src/DefaultPeerListProcessor.cc deleted file mode 100644 index 3e52a15a..00000000 --- a/src/DefaultPeerListProcessor.cc +++ /dev/null @@ -1,77 +0,0 @@ -/* */ -#include "DefaultPeerListProcessor.h" -#include "Peer.h" -#include "bencode.h" - -namespace aria2 { - -const std::string DefaultPeerListProcessor::IP("ip"); - -const std::string DefaultPeerListProcessor::PORT("port"); - -DefaultPeerListProcessor::DefaultPeerListProcessor() {} - -DefaultPeerListProcessor::~DefaultPeerListProcessor() {} - -bool DefaultPeerListProcessor::canHandle(const bencode::BDE& peerData) const -{ - return peerData.isList(); -} - -void DefaultPeerListProcessor::extractPeer -(std::deque >& peers, const bencode::BDE& peerData) -{ - if(!canHandle(peerData)) { - return; - } - for(bencode::BDE::List::const_iterator itr = peerData.listBegin(); - itr != peerData.listEnd(); ++itr) { - const bencode::BDE& peerDict = *itr; - if(!peerDict.isDict()) { - continue; - } - const bencode::BDE& ip = peerDict[IP]; - const bencode::BDE& port = peerDict[PORT]; - if(!ip.isString() || !port.isInteger() || - !(0 < port.i() && port.i() < 65536)) { - continue; - } - PeerHandle peer(new Peer(ip.s(), port.i())); - peers.push_back(peer); - } -} - -} // namespace aria2 diff --git a/src/DefaultPeerListProcessor.h b/src/DefaultPeerListProcessor.h deleted file mode 100644 index f82bdeec..00000000 --- a/src/DefaultPeerListProcessor.h +++ /dev/null @@ -1,60 +0,0 @@ -/* */ -#ifndef _D_DEFAULT_PEER_LIST_PROCESSOR_H_ -#define _D_DEFAULT_PEER_LIST_PROCESSOR_H_ - -#include "PeerListProcessor.h" - -namespace aria2 { - -class DefaultPeerListProcessor : public PeerListProcessor { -private: - static const std::string IP; - - static const std::string PORT; -public: - DefaultPeerListProcessor(); - - virtual ~DefaultPeerListProcessor(); - - virtual void extractPeer - (std::deque >& peers, const bencode::BDE& peerData); - - virtual bool canHandle(const bencode::BDE& peerData) const; -}; - -} // namespace aria2 - -#endif // _D_DEFAULT_PEER_LIST_PROCESSOR_H_ diff --git a/src/DelegatingPeerListProcessor.cc b/src/DelegatingPeerListProcessor.cc deleted file mode 100644 index 30068de7..00000000 --- a/src/DelegatingPeerListProcessor.cc +++ /dev/null @@ -1,83 +0,0 @@ -/* - * aria2 - The high speed download utility - * - * Copyright (C) 2006 Tatsuhiro Tsujikawa - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * In addition, as a special exception, the copyright holders give - * permission to link the code of portions of this program with the - * OpenSSL library under certain conditions as described in each - * individual source file, and distribute linked combinations - * including the two. - * You must obey the GNU General Public License in all respects - * for all of the code used other than OpenSSL. If you modify - * file(s) with this exception, you may extend this exception to your - * version of the file(s), but you are not obligated to do so. If you - * do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source - * files in the program, then also delete it here. - */ -/* copyright --> */ -#include "DelegatingPeerListProcessor.h" - -#include - -#include "DefaultPeerListProcessor.h" -#include "CompactPeerListProcessor.h" -#include "Peer.h" -#include "bencode.h" - -namespace aria2 { - -DelegatingPeerListProcessor::DelegatingPeerListProcessor() -{ - { - SharedHandle proc(new DefaultPeerListProcessor); - processors.push_back(proc); - } - { - SharedHandle proc(new CompactPeerListProcessor); - processors.push_back(proc); - } -} - -DelegatingPeerListProcessor::~DelegatingPeerListProcessor() {} - -void DelegatingPeerListProcessor::extractPeer -(std::deque >& peers, const bencode::BDE& peerData) -{ - for(std::deque >::iterator itr = - processors.begin(); itr != processors.end(); ++itr) { - PeerListProcessorHandle processor = *itr; - if(processor->canHandle(peerData)) { - processor->extractPeer(peers, peerData); - break; - } - } -} - -bool DelegatingPeerListProcessor::canHandle(const bencode::BDE& peerData) const -{ - for(std::deque >::const_iterator itr = - processors.begin(); itr != processors.end(); ++itr) { - if((*itr)->canHandle(peerData)) { - return true; - } - } - return false; -} - -} // namespace aria2 diff --git a/src/DelegatingPeerListProcessor.h b/src/DelegatingPeerListProcessor.h deleted file mode 100644 index 967f3b2d..00000000 --- a/src/DelegatingPeerListProcessor.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * aria2 - The high speed download utility - * - * Copyright (C) 2006 Tatsuhiro Tsujikawa - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * In addition, as a special exception, the copyright holders give - * permission to link the code of portions of this program with the - * OpenSSL library under certain conditions as described in each - * individual source file, and distribute linked combinations - * including the two. - * You must obey the GNU General Public License in all respects - * for all of the code used other than OpenSSL. If you modify - * file(s) with this exception, you may extend this exception to your - * version of the file(s), but you are not obligated to do so. If you - * do not wish to do so, delete this exception statement from your - * version. If you delete this exception statement from all source - * files in the program, then also delete it here. - */ -/* copyright --> */ -#ifndef _D_DELEGATING_PEER_LIST_PROCESSOR_H_ -#define _D_DELEGATING_PEER_LIST_PROCESSOR_H_ - -#include "PeerListProcessor.h" - -namespace aria2 { - -class DelegatingPeerListProcessor : public PeerListProcessor { -private: - std::deque > processors; -public: - DelegatingPeerListProcessor(); - - virtual ~DelegatingPeerListProcessor(); - - virtual void extractPeer - (std::deque >& peers, const bencode::BDE& peerData); - - virtual bool canHandle(const bencode::BDE& peerData) const; -}; - -} // namespace aria2 - -#endif // _D_DELEGATING_PEER_LIST_PROCESSOR_H_ diff --git a/src/Makefile.am b/src/Makefile.am index 7d74565a..abf8a448 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -268,9 +268,6 @@ SRCS += PeerMessageUtil.cc PeerMessageUtil.h\ UnionSeedCriteria.h\ SeedCheckCommand.cc SeedCheckCommand.h\ PeerListProcessor.h\ - DefaultPeerListProcessor.cc DefaultPeerListProcessor.h\ - CompactPeerListProcessor.cc CompactPeerListProcessor.h\ - DelegatingPeerListProcessor.cc DelegatingPeerListProcessor.h\ AnnounceTier.h\ AnnounceList.h AnnounceList.cc\ BtContext.cc BtContext.h\ diff --git a/src/Makefile.in b/src/Makefile.in index 46be5ff7..06a64a58 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -68,9 +68,6 @@ bin_PROGRAMS = aria2c$(EXEEXT) @ENABLE_BITTORRENT_TRUE@ UnionSeedCriteria.h\ @ENABLE_BITTORRENT_TRUE@ SeedCheckCommand.cc SeedCheckCommand.h\ @ENABLE_BITTORRENT_TRUE@ PeerListProcessor.h\ -@ENABLE_BITTORRENT_TRUE@ DefaultPeerListProcessor.cc DefaultPeerListProcessor.h\ -@ENABLE_BITTORRENT_TRUE@ CompactPeerListProcessor.cc CompactPeerListProcessor.h\ -@ENABLE_BITTORRENT_TRUE@ DelegatingPeerListProcessor.cc DelegatingPeerListProcessor.h\ @ENABLE_BITTORRENT_TRUE@ AnnounceTier.h\ @ENABLE_BITTORRENT_TRUE@ AnnounceList.h AnnounceList.cc\ @ENABLE_BITTORRENT_TRUE@ BtContext.cc BtContext.h\ @@ -438,10 +435,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \ PeerChokeCommand.cc PeerChokeCommand.h SeedCriteria.h \ TimeSeedCriteria.h ShareRatioSeedCriteria.h \ UnionSeedCriteria.h SeedCheckCommand.cc SeedCheckCommand.h \ - PeerListProcessor.h DefaultPeerListProcessor.cc \ - DefaultPeerListProcessor.h CompactPeerListProcessor.cc \ - CompactPeerListProcessor.h DelegatingPeerListProcessor.cc \ - DelegatingPeerListProcessor.h AnnounceTier.h AnnounceList.h \ + PeerListProcessor.h AnnounceTier.h AnnounceList.h \ AnnounceList.cc BtContext.cc BtContext.h DefaultBtContext.cc \ DefaultBtContext.h PeerStorage.h DefaultPeerStorage.cc \ DefaultPeerStorage.h BtAnnounce.cc BtAnnounce.h \ @@ -598,9 +592,6 @@ am__objects_3 = @ENABLE_BITTORRENT_TRUE@ TrackerWatcherCommand.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ PeerChokeCommand.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ SeedCheckCommand.$(OBJEXT) \ -@ENABLE_BITTORRENT_TRUE@ DefaultPeerListProcessor.$(OBJEXT) \ -@ENABLE_BITTORRENT_TRUE@ CompactPeerListProcessor.$(OBJEXT) \ -@ENABLE_BITTORRENT_TRUE@ DelegatingPeerListProcessor.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ AnnounceList.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ BtContext.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DefaultBtContext.$(OBJEXT) \ @@ -1304,7 +1295,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChecksumCheckIntegrityEntry.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChunkedDecoder.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Command.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CompactPeerListProcessor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConsoleStatCalc.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ContentTypeRequestGroupCriteria.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Cookie.Po@am__quote@ @@ -1371,11 +1361,9 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultDiskWriter.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultDiskWriterFactory.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultExtensionMessageFactory.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPeerListProcessor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPeerStorage.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPieceStorage.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultSegmentManFactory.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DelegatingPeerListProcessor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DirectDiskAdaptor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DiskAdaptor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DownloadCommand.Po@am__quote@ diff --git a/src/PeerListProcessor.h b/src/PeerListProcessor.h index 6872e381..82e407c8 100644 --- a/src/PeerListProcessor.h +++ b/src/PeerListProcessor.h @@ -36,30 +36,63 @@ #define _D_PEER_LIST_PROCESSOR_H_ #include "common.h" - -#include - -#include "SharedHandle.h" +#include "a2netcompat.h" +#include "bencode.h" +#include "Peer.h" namespace aria2 { -class Peer; -namespace bencode { -class BDE; -} - class PeerListProcessor { public: - virtual ~PeerListProcessor() {} + template + void extractPeer(const bencode::BDE& peerData, OutputIterator dest) + { + if(peerData.isList()) { + extractPeerFromList(peerData, dest); + } else if(peerData.isString()) { + extractPeerFromCompact(peerData, dest); + } + } - virtual void extractPeer - (std::deque >& peers, const bencode::BDE& peerData) = 0; + template + void extractPeerFromList(const bencode::BDE& peerData, OutputIterator dest) + { + for(bencode::BDE::List::const_iterator itr = peerData.listBegin(); + itr != peerData.listEnd(); ++itr) { + const bencode::BDE& peerDict = *itr; + if(!peerDict.isDict()) { + continue; + } + static const std::string IP = "ip"; + static const std::string PORT("port"); + const bencode::BDE& ip = peerDict[IP]; + const bencode::BDE& port = peerDict[PORT]; + if(!ip.isString() || !port.isInteger() || + !(0 < port.i() && port.i() < 65536)) { + continue; + } + *dest = SharedHandle(new Peer(ip.s(), port.i())); + ++dest; + } + } - virtual bool canHandle(const bencode::BDE& peerData) const = 0; + template + void extractPeerFromCompact(const bencode::BDE& peerData, OutputIterator dest) + { + size_t length = peerData.s().size(); + if(length%6 == 0) { + for(size_t i = 0; i < length; i += 6) { + struct in_addr in; + in.s_addr = *(uint32_t*)(peerData.s().c_str()+i); + std::string ipaddr = inet_ntoa(in); + uint16_t port = ntohs(*(uint16_t*)(peerData.s().c_str()+i+4)); + *dest = SharedHandle(new Peer(ipaddr, port)); + ++dest; + } + } + } }; -typedef SharedHandle PeerListProcessorHandle; - } // namespace aria2 #endif // _D_PEER_LIST_PROCESSOR_H_ diff --git a/src/UTPexExtensionMessage.cc b/src/UTPexExtensionMessage.cc index 9b1890cd..7fa05dcc 100644 --- a/src/UTPexExtensionMessage.cc +++ b/src/UTPexExtensionMessage.cc @@ -37,7 +37,7 @@ #include "Util.h" #include "PeerMessageUtil.h" #include "PeerStorage.h" -#include "CompactPeerListProcessor.h" +#include "PeerListProcessor.h" #include "DlAbortEx.h" #include "message.h" #include "StringFormat.h" @@ -174,14 +174,15 @@ UTPexExtensionMessage::create(const unsigned char* data, size_t len) const bencode::BDE dict = bencode::decode(data+1, len-1); if(dict.isDict()) { - CompactPeerListProcessor proc; + PeerListProcessor proc; const bencode::BDE& added = dict["added"]; if(added.isString()) { - proc.extractPeer(msg->_freshPeers, added); + proc.extractPeerFromCompact(added, std::back_inserter(msg->_freshPeers)); } const bencode::BDE& dropped = dict["dropped"]; if(dropped.isString()) { - proc.extractPeer(msg->_droppedPeers, dropped); + proc.extractPeerFromCompact(dropped, + std::back_inserter(msg->_droppedPeers)); } } return msg; diff --git a/test/Makefile.am b/test/Makefile.am index 0bdfedc6..8c72206d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -114,7 +114,7 @@ aria2c_SOURCES += BtAllowedFastMessageTest.cc\ MockBtMessage.h\ MockBtMessageDispatcher.h\ MockBtMessageFactory.h\ - DefaultPeerListProcessorTest.cc\ + PeerListProcessorTest.cc\ AnnounceListTest.cc\ DefaultPeerStorageTest.cc\ MockPeerStorage.h\ diff --git a/test/Makefile.in b/test/Makefile.in index 0a881e1d..c6c695fa 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -66,7 +66,7 @@ check_PROGRAMS = $(am__EXEEXT_1) @ENABLE_BITTORRENT_TRUE@ MockBtMessage.h\ @ENABLE_BITTORRENT_TRUE@ MockBtMessageDispatcher.h\ @ENABLE_BITTORRENT_TRUE@ MockBtMessageFactory.h\ -@ENABLE_BITTORRENT_TRUE@ DefaultPeerListProcessorTest.cc\ +@ENABLE_BITTORRENT_TRUE@ PeerListProcessorTest.cc\ @ENABLE_BITTORRENT_TRUE@ AnnounceListTest.cc\ @ENABLE_BITTORRENT_TRUE@ DefaultPeerStorageTest.cc\ @ENABLE_BITTORRENT_TRUE@ MockPeerStorage.h\ @@ -211,7 +211,7 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \ DefaultBtContextTest.cc DefaultBtMessageDispatcherTest.cc \ DefaultBtRequestFactoryTest.cc MockBtMessage.h \ MockBtMessageDispatcher.h MockBtMessageFactory.h \ - DefaultPeerListProcessorTest.cc AnnounceListTest.cc \ + PeerListProcessorTest.cc AnnounceListTest.cc \ DefaultPeerStorageTest.cc MockPeerStorage.h \ ByteArrayDiskWriterTest.cc PeerTest.cc \ PeerSessionResourceTest.cc PeerMessageUtilTest.cc \ @@ -275,7 +275,7 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \ @ENABLE_BITTORRENT_TRUE@ DefaultBtContextTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DefaultBtMessageDispatcherTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DefaultBtRequestFactoryTest.$(OBJEXT) \ -@ENABLE_BITTORRENT_TRUE@ DefaultPeerListProcessorTest.$(OBJEXT) \ +@ENABLE_BITTORRENT_TRUE@ PeerListProcessorTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ AnnounceListTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DefaultPeerStorageTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ ByteArrayDiskWriterTest.$(OBJEXT) \ @@ -751,7 +751,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultBtRequestFactoryTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultDiskWriterTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultExtensionMessageFactoryTest.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPeerListProcessorTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPeerStorageTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DefaultPieceStorageTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DirectDiskAdaptorTest.Po@am__quote@ @@ -794,6 +793,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/OptionTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PStringBuildVisitorTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ParameterizedStringParserTest.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerListProcessorTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerMessageUtilTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerSessionResourceTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerTest.Po@am__quote@ diff --git a/test/DefaultPeerListProcessorTest.cc b/test/PeerListProcessorTest.cc similarity index 64% rename from test/DefaultPeerListProcessorTest.cc rename to test/PeerListProcessorTest.cc index 24557d48..9ef63e89 100644 --- a/test/DefaultPeerListProcessorTest.cc +++ b/test/PeerListProcessorTest.cc @@ -1,18 +1,22 @@ -#include "DefaultPeerListProcessor.h" +#include "PeerListProcessor.h" + +#include #include #include "Exception.h" #include "Peer.h" #include "bencode.h" +#include "TimeA2.h" +#include "PeerMessageUtil.h" namespace aria2 { -class DefaultPeerListProcessorTest:public CppUnit::TestFixture { +class PeerListProcessorTest:public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(DefaultPeerListProcessorTest); - CPPUNIT_TEST(testExtractPeer); - CPPUNIT_TEST(testExtract2Peers); + CPPUNIT_TEST_SUITE(PeerListProcessorTest); + CPPUNIT_TEST(testExtractPeerFromList); + CPPUNIT_TEST(testExtract2PeersFromList); CPPUNIT_TEST_SUITE_END(); private: @@ -20,37 +24,35 @@ public: void setUp() { } - void testExtractPeer(); - void testExtract2Peers(); + void testExtractPeerFromList(); + void testExtract2PeersFromList(); }; -CPPUNIT_TEST_SUITE_REGISTRATION( DefaultPeerListProcessorTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( PeerListProcessorTest ); -void DefaultPeerListProcessorTest::testExtractPeer() { - DefaultPeerListProcessor proc; +void PeerListProcessorTest::testExtractPeerFromList() { + PeerListProcessor proc; std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti2006eeee"; const bencode::BDE dict = bencode::decode(peersString); - CPPUNIT_ASSERT(proc.canHandle(dict["peers"])); - std::deque > peers; - proc.extractPeer(peers, dict["peers"]); + proc.extractPeerFromList(dict["peers"], std::back_inserter(peers)); CPPUNIT_ASSERT_EQUAL((size_t)1, peers.size()); SharedHandle peer = *peers.begin(); CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->ipaddr); CPPUNIT_ASSERT_EQUAL((uint16_t)2006, peer->port); } -void DefaultPeerListProcessorTest::testExtract2Peers() { - DefaultPeerListProcessor proc; +void PeerListProcessorTest::testExtract2PeersFromList() { + PeerListProcessor proc; std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti65535eed2:ip11:192.168.0.27:peer id20:aria2-000000000000004:porti2007eeee"; const bencode::BDE dict = bencode::decode(peersString); std::deque > peers; - proc.extractPeer(peers, dict["peers"]); + proc.extractPeerFromList(dict["peers"], std::back_inserter(peers)); CPPUNIT_ASSERT_EQUAL((size_t)2, peers.size()); SharedHandle peer = *peers.begin(); CPPUNIT_ASSERT_EQUAL(std::string("192.168.0.1"), peer->ipaddr);