mirror of
https://github.com/aria2/aria2.git
synced 2025-04-05 13:37:40 +03:00
2009-11-23 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed ut_metadata data handling. Implemented UTMetadataDataExtensionMessage::doReceivedAction(). Initialize PeerStorage in HandshakeExtensionMessage::doReceivedAction() when metadata_size is received. * src/DefaultExtensionMessageFactory.cc * src/DefaultExtensionMessageFactory.h * src/HandshakeExtensionMessage.cc * src/HandshakeExtensionMessage.h * src/UTMetadataDataExtensionMessage.cc * src/UTMetadataDataExtensionMessage.h * src/UTMetadataRequestExtensionMessage.cc * src/UTMetadataRequestFactory.cc * src/UTMetadataRequestFactory.h * src/UTMetadataRequestTracker.cc * src/UTMetadataRequestTracker.h * test/DefaultExtensionMessageFactoryTest.cc * test/HandshakeExtensionMessageTest.cc * test/MockBtMessage.h * test/UTMetadataDataExtensionMessageTest.cc * test/UTMetadataRequestExtensionMessageTest.cc * test/UTMetadataRequestFactoryTest.cc * test/UTMetadataRequestTrackerTest.cc * test/extension_message_test_helper.h
This commit is contained in:
parent
b563621dd1
commit
c1730aeea9
20 changed files with 813 additions and 64 deletions
|
@ -5,6 +5,17 @@
|
|||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
#include "BtConstants.h"
|
||||
#include "PieceStorage.h"
|
||||
#include "DownloadContext.h"
|
||||
#include "BtRuntime.h"
|
||||
#include "DirectDiskAdaptor.h"
|
||||
#include "ByteArrayDiskWriter.h"
|
||||
#include "BDE.h"
|
||||
#include "DownloadContext.h"
|
||||
#include "MockPieceStorage.h"
|
||||
#include "UTMetadataRequestTracker.h"
|
||||
#include "bittorrent_helper.h"
|
||||
#include "MessageDigestHelper.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -41,7 +52,7 @@ void UTMetadataDataExtensionMessageTest::testGetBencodedData()
|
|||
msg.setTotalSize(data.size());
|
||||
msg.setData(data);
|
||||
CPPUNIT_ASSERT_EQUAL
|
||||
(std::string("d8:msg_typei1e5:piecei1e10:total_sizei16384ee16384:")+data,
|
||||
(std::string("d8:msg_typei1e5:piecei1e10:total_sizei16384ee")+data,
|
||||
msg.getBencodedData());
|
||||
}
|
||||
|
||||
|
@ -55,6 +66,52 @@ void UTMetadataDataExtensionMessageTest::testToString()
|
|||
|
||||
void UTMetadataDataExtensionMessageTest::testDoReceivedAction()
|
||||
{
|
||||
SharedHandle<DirectDiskAdaptor> diskAdaptor(new DirectDiskAdaptor());
|
||||
SharedHandle<ByteArrayDiskWriter> diskWriter(new ByteArrayDiskWriter());
|
||||
diskAdaptor->setDiskWriter(diskWriter);
|
||||
SharedHandle<MockPieceStorage> pieceStorage(new MockPieceStorage());
|
||||
pieceStorage->setDiskAdaptor(diskAdaptor);
|
||||
SharedHandle<BtRuntime> btRuntime(new BtRuntime());
|
||||
SharedHandle<UTMetadataRequestTracker> tracker
|
||||
(new UTMetadataRequestTracker());
|
||||
SharedHandle<DownloadContext> dctx(new DownloadContext());
|
||||
BDE attrs = BDE::dict();
|
||||
|
||||
std::string piece0 = std::string(METADATA_PIECE_SIZE, '0');
|
||||
std::string piece1 = std::string(METADATA_PIECE_SIZE, '1');
|
||||
std::string metadata = piece0+piece1;
|
||||
|
||||
unsigned char infoHash[INFO_HASH_LENGTH];
|
||||
MessageDigestHelper::digest(infoHash, INFO_HASH_LENGTH,
|
||||
MessageDigestContext::SHA1,
|
||||
metadata.data(), metadata.size());
|
||||
attrs[bittorrent::INFO_HASH] = std::string(&infoHash[0], &infoHash[20]);
|
||||
|
||||
dctx->setAttribute(bittorrent::BITTORRENT, attrs);
|
||||
|
||||
UTMetadataDataExtensionMessage m(1);
|
||||
m.setPieceStorage(pieceStorage);
|
||||
m.setBtRuntime(btRuntime);
|
||||
m.setUTMetadataRequestTracker(tracker);
|
||||
m.setDownloadContext(dctx);
|
||||
|
||||
m.setIndex(1);
|
||||
m.setData(piece1);
|
||||
|
||||
tracker->add(1);
|
||||
m.doReceivedAction();
|
||||
CPPUNIT_ASSERT(!tracker->tracks(1));
|
||||
|
||||
pieceStorage->setDownloadFinished(true);
|
||||
// If piece is not tracked, it is ignored.
|
||||
m.setIndex(0);
|
||||
m.setData(piece0);
|
||||
m.doReceivedAction();
|
||||
CPPUNIT_ASSERT(!btRuntime->isHalt());
|
||||
|
||||
tracker->add(0);
|
||||
m.doReceivedAction();
|
||||
CPPUNIT_ASSERT(btRuntime->isHalt());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue