2006-12-24 06:25:21 +00:00
|
|
|
#include "DefaultBtRequestFactory.h"
|
|
|
|
#include "MockBtMessage.h"
|
|
|
|
#include "MockBtMessageFactory.h"
|
|
|
|
#include "MockBtMessageDispatcher.h"
|
|
|
|
#include "MockBtContext.h"
|
|
|
|
#include "BtRegistry.h"
|
|
|
|
#include "MockPieceStorage.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Peer.h"
|
|
|
|
#include "PeerObject.h"
|
|
|
|
#include "BtMessageReceiver.h"
|
|
|
|
#include "PeerConnection.h"
|
|
|
|
#include "ExtensionMessageFactory.h"
|
|
|
|
#include "FileEntry.h"
|
2008-04-20 00:50:22 +00:00
|
|
|
#include "BtHandshakeMessage.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <algorithm>
|
2006-12-24 06:25:21 +00:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
class DefaultBtRequestFactoryTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(DefaultBtRequestFactoryTest);
|
|
|
|
CPPUNIT_TEST(testAddTargetPiece);
|
|
|
|
CPPUNIT_TEST(testRemoveCompletedPiece);
|
|
|
|
CPPUNIT_TEST(testCreateRequestMessages);
|
|
|
|
CPPUNIT_TEST(testCreateRequestMessages_onEndGame);
|
|
|
|
CPPUNIT_TEST(testRemoveTargetPiece);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<DefaultBtRequestFactory> btRequestFactory;
|
|
|
|
SharedHandle<MockBtContext> btContext;
|
2006-12-24 06:25:21 +00:00
|
|
|
public:
|
|
|
|
void testAddTargetPiece();
|
|
|
|
void testRemoveCompletedPiece();
|
|
|
|
void testCreateRequestMessages();
|
|
|
|
void testCreateRequestMessages_onEndGame();
|
|
|
|
void testRemoveTargetPiece();
|
|
|
|
|
|
|
|
class MockBtRequestMessage : public MockBtMessage {
|
|
|
|
public:
|
2008-03-08 08:04:28 +00:00
|
|
|
size_t index;
|
|
|
|
size_t blockIndex;
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-03-08 08:04:28 +00:00
|
|
|
MockBtRequestMessage(size_t index, size_t blockIndex):index(index), blockIndex(blockIndex) {}
|
2006-12-24 06:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef SharedHandle<MockBtRequestMessage> MockBtRequestMessageHandle;
|
|
|
|
|
|
|
|
class MockBtMessageFactory2 : public MockBtMessageFactory {
|
|
|
|
public:
|
2008-02-08 15:53:45 +00:00
|
|
|
virtual SharedHandle<BtMessage>
|
2008-03-09 12:24:01 +00:00
|
|
|
createRequestMessage(const SharedHandle<Piece>& piece, size_t blockIndex) {
|
2008-04-20 00:50:22 +00:00
|
|
|
return SharedHandle<BtMessage>
|
|
|
|
(new MockBtRequestMessage(piece->getIndex(), blockIndex));
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MockBtMessageDispatcher2 : public MockBtMessageDispatcher {
|
|
|
|
public:
|
2008-03-09 12:24:01 +00:00
|
|
|
virtual bool isOutstandingRequest(size_t index, size_t blockIndex) {
|
2006-12-24 06:25:21 +00:00
|
|
|
return index == 0 && blockIndex == 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
class SortMockBtRequestMessage {
|
|
|
|
public:
|
|
|
|
bool operator()(const SharedHandle<MockBtRequestMessage>& a,
|
|
|
|
const SharedHandle<MockBtRequestMessage>& b) {
|
|
|
|
if(a->index < b->index) {
|
|
|
|
return true;
|
|
|
|
} else if(b->index < a->index) {
|
|
|
|
return false;
|
|
|
|
} else if(a->blockIndex < b->blockIndex) {
|
|
|
|
return true;
|
|
|
|
} else if(b->blockIndex < a->blockIndex) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
void setUp() {
|
2007-10-11 16:58:24 +00:00
|
|
|
BtRegistry::unregisterAll();
|
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
btContext.reset(new MockBtContext());
|
2006-12-24 06:25:21 +00:00
|
|
|
btContext->setInfoHash((const unsigned char*)"12345678901234567890");
|
|
|
|
btContext->setPieceLength(16*1024);
|
|
|
|
btContext->setTotalLength(256*1024);
|
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
2006-12-24 06:25:21 +00:00
|
|
|
BtRegistry::registerPieceStorage(btContext->getInfoHashAsString(),
|
2008-04-20 00:50:22 +00:00
|
|
|
pieceStorage);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<Peer> peer(new Peer("host", 6969));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<PeerObjectCluster> cluster(new PeerObjectCluster());
|
2006-12-24 06:25:21 +00:00
|
|
|
BtRegistry::registerPeerObjectCluster(btContext->getInfoHashAsString(),
|
2008-04-20 00:50:22 +00:00
|
|
|
cluster);
|
|
|
|
SharedHandle<PeerObject> peerObject(new PeerObject());
|
|
|
|
peerObject->btMessageFactory.reset(new MockBtMessageFactory2());
|
2008-02-09 17:14:40 +00:00
|
|
|
PEER_OBJECT_CLUSTER(btContext)->registerHandle(peer->getID(), peerObject);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MockBtMessageDispatcher> dispatcher
|
|
|
|
(new MockBtMessageDispatcher());
|
|
|
|
|
|
|
|
PEER_OBJECT(btContext, peer)->btMessageDispatcher = dispatcher;
|
|
|
|
|
|
|
|
btRequestFactory.reset(new DefaultBtRequestFactory());
|
2006-12-24 06:25:21 +00:00
|
|
|
btRequestFactory->setBtContext(btContext);
|
|
|
|
btRequestFactory->setPeer(peer);
|
2008-04-20 00:50:22 +00:00
|
|
|
btRequestFactory->setBtMessageDispatcher(dispatcher);
|
2007-01-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To decrease CPU usage in bittorrent download, calculation
results in
BitfieldMan were cached and realtime fetching PeerObject was
removed
with WeakHandle introduced. Option values are set to the objects
by setter before download begins.
* src/DefaultBtRequestFactory.cc: Use messageFactory member.
* src/DefaultBtRequestFactory.h
(dispatcher): BtMessageDispatcherHandle ->
BtMessageDispatcherWeakHandle.
(messageFactory): New variable.
(setBtMessageDispatcher): BtMessageDispatcherHandle ->
BtMessageDispatcherWeakHandle.
(setBtMessageFactory): New function.
* src/DefaultBtMessageDispatcher.cc:
(sendMessages): Use maxUploadSpeedLimit instead of fetching the
value
from Option.
(checkRequestSlotAndDoNecessaryThing): Use requestTimeout
instead of
feating the value from Option.
Use messageFactory member.
* src/PeerInteractionCommand.cc
(PeerInteractionCommand): Added maxDownloadSpeedLimit.
Add reverse dependencies to factory object.
Set maxUploadSpeedLimit and requestTimeout and messageFactory to
dispatcher.
Set messageFactory to receiver.
Set keepAliveInterval and maxDownloadSpeedLimit and
messageFactory to
btInteractive.
Set receiver to peerObject.
Set maxDownloadSpeedLimit to this.
(executeInternal): Use maxDownloadSpeedLimit member.
* src/BtChokeMessage.cc
(doReceivedAction): Use dispatcher, requestFactory member.
(onSendComplete): Use dispatcher member.
* src/PeerInteractionCommand.h
(maxDownloadSpeedLimit): New variable.
* src/DefaultBtMessageReceiver.h
(peerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(dispatcher):
BtMessageDispatcherHandle -> BtMessageDispatcherWeakHandle
(messageFactory): New variable.
(setPeerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(getPeerConnection): PeerConnectionHandle ->
PeerConnectionWeakHandle
(setDispatcher):
BtMessageDispatcherHandle -> BtMessageDispatcherWeakHandle
(setBtMessageFactory): New function.
* src/DefaultBtInteractive.cc
(initiateHandshake): Use messageFactory member.
(addBitfieldMessageToQueue): Use messageFactory member.
(addAllowedFastMessageToQueue): Use messageFactory member.
(decideChoking): Use messageFactory member.
(checkHave): Use messageFactory member.
(sendKeepAlive): Use keepAliveInterval, messageFactory member.
(receiveMessages): Use maxDownloadSpeedLimit member.
(decideInterest): Use messageFactory member.
* src/BtRequestMessage.cc
(doReceivedAction): Use messageFactory, dispatcher member.
(onQueued): Use dispatcher member.
* src/BtPieceMessage.cc
(doReceivedAction): Use dispatcher member.
(send): Use peerConnection member.
(onWrongPiece): Use requestFactory member.
(handleChokingEvent): Use messageFactory, dispatcher member.
(handleCancelSendingPieceEvent): Use messageFactory, dispatcher
member.
* src/BtMessageDispatcher.h
(BtMessageDispatcherWeakHandle): New type definition.
* src/SimpleBtMessage.cc
(send): Use peerConnection member.
* src/BtRejectMessage.cc
(doReceivedAction): Use dispatcher member.
* src/DefaultBtMessageDispatcher.h
(Option.h): Removed include.
(messageFactory): New variable.
(option): Removed.
(maxUploadSpeedLimit): New variable.
(requestTimeout): New variable.
(DefaultBtMessageDispatcher): Removed option.
Added maxUploadSpeedLimit, requestTimeout.
(setOption): Removed.
(getOption): Removed.
(setMaxUploadSpeedLimit): New function.
(setRequestTimeout): New function.
(setBtMessageFactory): New function.
* src/DefaultBtInteractive.h
(btMessageReceiver):
BtMessageReceiverHandle -> BtMessageReceiverWeakHandle
(dispatcher):
BtMessageDispatcherHandle -> BtMessageReceiverWeakHandle
(btRequestFactory):
BtRequestFactoryHandle -> BtRequestFactoryWeakHandle
(peerConnection):
PeerConnectionHandle -> PeerConnectionWeakHandle
(messageFactory): New variable.
(option): Removed.
(keepAliveInterval): New variable.
(maxDownloadSpeedLimit): New variable.
(DefaultBtInteractive): Added keepAliveInterval,
maxDownloadSpeedLimit.
(setBtMessageReceiver):
BtMessageReceiverHandle -> BtMessageReceiverWeakHandle
(setDispatcher):
BtMessageDispatcherHandle -> BtMessageReceiverWeakHandle
(setBtRequestFactory):
BtRequestFactoryHandle -> BtRequestFactoryWeakHandle
(setPeerConnection):
PeerConnectionHandle -> PeerConnectionWeakHandle
(setOption): Removed.
(setKeepAliveInterval): New function.
(setMaxDownloadSpeedLimit): New function.
(setBtMessageFactory): New function.
* src/BitfieldMan.h
(cachedNumMissingBlock): New variable.
(cachedNumFilteredBlock): New variable.
(cachedCompletedLength): New variable.
(cachedFilteredComletedLength): New variable.
(cachedFilteredTotalLength): New variable.
(countMissingBlockNow): New function.
(countFilteredBlockNow): New function.
(getFilteredTotalLengthNow): New function.
(getCompletedLengthNow): New function.
(getFilteredCompletedLengthNow): New function.
(updateCache): New function.
* src/AbstractBtMessage.h
(BtMessageDispatcher.h): New include.
(PeerConnection.h): New include.
(BtRequestFactory.h): New include
(BtMessageFactory.h): New include.
(dispatcher): New variable.
(messageFactory): New variable.
(peerConnection: New variable.
(setBtMessageDispatcher): New function.
(setPeerConnection): New function.
(setBtMessageFactory): New function.
(setBtRequestFactory): New function.
* src/DefaultBtMessageFactory.cc
(setCommonProperty): Set dispatcher, requestFactory, this,
peerConnection to msg.
* src/BtRegistry.h
(BT_MESSAGE_RECEIVER): New macro.
* src/PeerConnection.h
(PeerConnectionWeakHandle): New type definition.
* src/BtMessageFactory.h
(BtMessageFactoryWeakHandle): New type definition.
* src/BitfieldMan.cc
(BitfieldMan): Added cachedNumMissingBlock,
cachedNumFilteredBlock,
cachedCompletedLength, cachedFilteredComletedLength,
cachedFilteredTotalLength.
Call updateCache().
(countMissingBlock): Return cachedNumMissingBlock.
(countMissingBlockNow): New function.
(countBlock): Return cachedNumFilteredBlock if filterEnabled is
true.
(countFilteredBlockNow): New function.
(setBit): Call updateCache().
(unsetBit): Call updateCache().
(setBitfield): Call updateCache().
(clearAllBit): Call updateCache().
(setAllBit): Use setBitInternal instead of setBit.
Call updateCache().
(addFilter): Call updateCache().
(enableFilter): Call updateCache().
(disableFilter): Call updateCache().
(clearFilter): Call updateCache().
(getFilteredTotalLength): Return cachedFilteredTotalLength.
(getFilteredTotalLengthNow): New function.
(getCompletedLength): Return cachedCompletedLength.
(getCompletedLengthNow): New function.
(getFilteredCompletedLength): Return
cachedFilteredComletedLength.
(getFilteredCompletedLengthNow): New function.
(updateCache): New function.
* src/BtMessageReceiver.h
(BtMessageReceiverWeakHandle): New type definition.
* src/DefaultBtMessageReceiver.cc
(receiveHandshake): Use messageFactory member.
(sendHandshake): Use messageFactory member.
(receiveMessage): Use messageFactory member.
* src/DefaultBtMessageFactory.h
(dispatcher): New variable.
(requestFactory): New variable.
(peerConnection): New variablle.
(setBtMessageDispatcher): New function.
(setBtRequestFactory): New function.
(setPeerConnection): New function.
* src/SharedHandle.h
(RefCount): New class.
(WeakHandle): New class.
* src/PeerObject.h
(BtMessageReceiver.h): New include.
(PeerObject): Added btMessageReceiver.
(btMessageReceiver): New variable.
* src/Util.cc
(countBit): Simplified.
* src/BtCancelMessage.cc
(doReceivedAction): Use dispatcher member.
* src/BtRequestFactory.h
(BtRequestFactoryWeakHandle): New type definition.
* src/PeerStorage.h
(downloadSpeed): int -> uint32_t
(uploadSpeed): int -> uint32_t
(sessionDownloadLength): long long int -> uint64_t
(sessionUploadLength): long long int -> uint64_t
2007-01-16 15:20:26 +00:00
|
|
|
btRequestFactory->setBtMessageFactory(peerObject->btMessageFactory);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
void tearDown()
|
|
|
|
{
|
|
|
|
BtRegistry::unregisterAll();
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultBtRequestFactoryTest);
|
|
|
|
|
|
|
|
void DefaultBtRequestFactoryTest::testAddTargetPiece() {
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<Piece> piece(new Piece(0, 16*1024));
|
2006-12-24 06:25:21 +00:00
|
|
|
btRequestFactory->addTargetPiece(piece);
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, btRequestFactory->countTargetPiece());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtRequestFactoryTest::testRemoveCompletedPiece() {
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<Piece> piece1(new Piece(0, 16*1024));
|
|
|
|
SharedHandle<Piece> piece2(new Piece(1, 16*1024));
|
2006-12-24 06:25:21 +00:00
|
|
|
piece2->setAllBlock();
|
|
|
|
btRequestFactory->addTargetPiece(piece1);
|
|
|
|
btRequestFactory->addTargetPiece(piece2);
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)2, btRequestFactory->countTargetPiece());
|
2006-12-24 06:25:21 +00:00
|
|
|
btRequestFactory->removeCompletedPiece();
|
2008-03-09 12:24:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, btRequestFactory->countTargetPiece());
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, btRequestFactory->getTargetPieces().front()->getIndex());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtRequestFactoryTest::testCreateRequestMessages() {
|
|
|
|
int PIECE_LENGTH = 16*1024*2;
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<Piece> piece1(new Piece(0, PIECE_LENGTH));
|
|
|
|
SharedHandle<Piece> piece2(new Piece(1, PIECE_LENGTH));
|
2006-12-24 06:25:21 +00:00
|
|
|
btRequestFactory->addTargetPiece(piece1);
|
|
|
|
btRequestFactory->addTargetPiece(piece2);
|
|
|
|
|
2008-05-12 10:54:36 +00:00
|
|
|
std::deque<SharedHandle<BtMessage> > msgs;
|
|
|
|
btRequestFactory->createRequestMessages(msgs, 3);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, msgs.size());
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<SharedHandle<BtMessage> >::iterator itr = msgs.begin();
|
2006-12-24 06:25:21 +00:00
|
|
|
MockBtRequestMessage* msg = (MockBtRequestMessage*)itr->get();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
++itr;
|
|
|
|
msg = (MockBtRequestMessage*)itr->get();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
++itr;
|
|
|
|
msg = (MockBtRequestMessage*)itr->get();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-05-12 10:54:36 +00:00
|
|
|
{
|
|
|
|
std::deque<SharedHandle<BtMessage> > msgs;
|
|
|
|
btRequestFactory->createRequestMessages(msgs, 3);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msgs.size());
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtRequestFactoryTest::testCreateRequestMessages_onEndGame() {
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<MockBtMessageDispatcher2> dispatcher
|
|
|
|
(new MockBtMessageDispatcher2());
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
btRequestFactory->setBtMessageDispatcher(dispatcher);
|
|
|
|
|
|
|
|
int PIECE_LENGTH = 16*1024*2;
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<Piece> piece1(new Piece(0, PIECE_LENGTH));
|
|
|
|
SharedHandle<Piece> piece2(new Piece(1, PIECE_LENGTH));
|
2006-12-24 06:25:21 +00:00
|
|
|
btRequestFactory->addTargetPiece(piece1);
|
|
|
|
btRequestFactory->addTargetPiece(piece2);
|
|
|
|
|
2008-05-12 10:54:36 +00:00
|
|
|
std::deque<SharedHandle<BtMessage> > msgs;
|
|
|
|
btRequestFactory->createRequestMessagesOnEndGame(msgs, 3);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
std::deque<SharedHandle<MockBtRequestMessage> > mmsgs;
|
|
|
|
for(std::deque<SharedHandle<BtMessage> >::iterator i = msgs.begin();
|
|
|
|
i != msgs.end(); ++i) {
|
|
|
|
mmsgs.push_back(dynamic_pointer_cast<MockBtRequestMessage>(*i));
|
|
|
|
}
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
std::sort(mmsgs.begin(), mmsgs.end(), SortMockBtRequestMessage());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)3, mmsgs.size());
|
|
|
|
std::deque<SharedHandle<MockBtRequestMessage> >::iterator itr = mmsgs.begin();
|
|
|
|
MockBtRequestMessage* msg = (*itr).get();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
++itr;
|
2008-04-20 00:50:22 +00:00
|
|
|
msg = (*itr).get();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)0, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
++itr;
|
2008-04-20 00:50:22 +00:00
|
|
|
msg = (*itr).get();
|
2008-03-08 08:04:28 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->index);
|
|
|
|
CPPUNIT_ASSERT_EQUAL((size_t)1, msg->blockIndex);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtRequestFactoryTest::testRemoveTargetPiece() {
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<Piece> piece1(new Piece(0, 16*1024));
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
btRequestFactory->addTargetPiece(piece1);
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT(std::find(btRequestFactory->getTargetPieces().begin(),
|
|
|
|
btRequestFactory->getTargetPieces().end(),
|
|
|
|
piece1) != btRequestFactory->getTargetPieces().end());
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
btRequestFactory->removeTargetPiece(piece1);
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT(std::find(btRequestFactory->getTargetPieces().begin(),
|
|
|
|
btRequestFactory->getTargetPieces().end(),
|
|
|
|
piece1) == btRequestFactory->getTargetPieces().end());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|