2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Implemented commented code in BtSeederStateChoke
	* src/BtSeederStateChoke.cc
	* src/Peer.cc
	* src/Peer.h
	* src/PeerInteractionCommand.cc
	* src/PeerSessionResource.cc
	* src/PeerSessionResource.h
	* test/MockBtMessageDispatcher.h
	* test/PeerSessionResourceTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-11-03 07:16:25 +00:00
parent 7cf589e784
commit 7818e0e770
9 changed files with 86 additions and 12 deletions

View File

@ -1,3 +1,15 @@
2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented commented code in BtSeederStateChoke
* src/BtSeederStateChoke.cc
* src/Peer.cc
* src/Peer.h
* src/PeerInteractionCommand.cc
* src/PeerSessionResource.cc
* src/PeerSessionResource.h
* test/MockBtMessageDispatcher.h
* test/PeerSessionResourceTest.cc
2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made BtRegistry non-static object. Now DownloadEngine has a reference to

View File

@ -70,14 +70,13 @@ public:
bool operator()(Peer* left, Peer* right) const
{
// TODO Should peer have the reference to message dispatcher?
// size_t leftUpload = BT_MESSAGE_DISPATCHER(_btContext, left)->countOutstandingUpload();
// size_t rightUpload = BT_MESSAGE_DISPATCHER(_btContext, right)->countOutstandingUpload();
// if(leftUpload && !rightUpload) {
// return true;
// } else if(!leftUpload && rightUpload) {
// return false;
// }
size_t leftUpload = left->countOutstandingUpload();
size_t rightUpload = right->countOutstandingUpload();
if(leftUpload && !rightUpload) {
return true;
} else if(!leftUpload && rightUpload) {
return false;
}
const int TIME_FRAME = 20;
if(!left->getLastAmUnchoking().elapsed(TIME_FRAME) &&
left->getLastAmUnchoking().isNewer(right->getLastAmUnchoking())) {

View File

@ -33,13 +33,16 @@
*/
/* copyright --> */
#include "Peer.h"
#include <cstring>
#include <cassert>
#include "Util.h"
#include "PeerSessionResource.h"
#ifdef ENABLE_MESSAGE_DIGEST
# include "MessageDigestHelper.h"
#endif // ENABLE_MESSAGE_DIGEST
#include <cstring>
#include <cassert>
#include "BtMessageDispatcher.h"
namespace aria2 {
@ -476,4 +479,16 @@ void Peer::setFirstContactTime(const Time& time)
_firstContactTime = time;
}
void Peer::setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dpt)
{
assert(_res);
_res->setBtMessageDispatcher(dpt);
}
size_t Peer::countOutstandingUpload() const
{
assert(_res);
return _res->countOutstandingUpload();
}
} // namespace aria2

View File

@ -46,6 +46,7 @@
namespace aria2 {
class PeerSessionResource;
class BtMessageDispatcher;
class Peer {
public:
@ -246,6 +247,10 @@ public:
bool isIncomingPeer() const;
void setIncomingPeer(bool incoming);
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dpt);
size_t countOutstandingUpload() const;
};
typedef SharedHandle<Peer> PeerHandle;

View File

@ -190,6 +190,7 @@ PeerInteractionCommand::PeerInteractionCommand
setUploadLimit(e->option->getAsInt(PREF_MAX_UPLOAD_LIMIT));
peer->allocateSessionResource(_btContext->getPieceLength(),
_btContext->getTotalLength());
peer->setBtMessageDispatcher(dispatcher);
maxDownloadSpeedLimit = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT);

View File

@ -33,10 +33,14 @@
*/
/* copyright --> */
#include "PeerSessionResource.h"
#include <cassert>
#include <algorithm>
#include "BitfieldManFactory.h"
#include "BitfieldMan.h"
#include "A2STR.h"
#include <algorithm>
#include "BtMessageDispatcher.h"
namespace aria2 {
@ -338,4 +342,16 @@ uint64_t PeerSessionResource::getCompletedLength() const
return _bitfieldMan->getCompletedLength();
}
void PeerSessionResource::setBtMessageDispatcher
(const WeakHandle<BtMessageDispatcher>& dpt)
{
_dispatcher = dpt;
}
size_t PeerSessionResource::countOutstandingUpload() const
{
assert(!_dispatcher.isNull());
return _dispatcher->countOutstandingUpload();
}
} // namespace aria2

View File

@ -45,6 +45,7 @@
namespace aria2 {
class BitfieldMan;
class BtMessageDispatcher;
class PeerSessionResource {
private:
@ -78,6 +79,8 @@ private:
Time _lastDownloadUpdate;
Time _lastAmUnchoking;
WeakHandle<BtMessageDispatcher> _dispatcher;
public:
PeerSessionResource(size_t pieceLength, uint64_t totalLength);
@ -185,6 +188,10 @@ public:
const Time& getLastAmUnchoking() const;
uint64_t getCompletedLength() const;
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dpt);
size_t countOutstandingUpload() const;
};
} // namespace aria2

View File

@ -2,8 +2,12 @@
#define _D_MOCK_BT_MESSAGE_DISPATCHER_H_
#include "BtMessageDispatcher.h"
#include <algorithm>
#include "BtMessage.h"
#include "Piece.h"
namespace aria2 {
class MockBtMessageDispatcher : public BtMessageDispatcher {

View File

@ -1,7 +1,10 @@
#include "PeerSessionResource.h"
#include <cppunit/extensions/HelperMacros.h>
#include "MockBtMessageDispatcher.h"
#include "Exception.h"
#include "Util.h"
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
@ -26,6 +29,7 @@ class PeerSessionResourceTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testChokingRequired);
CPPUNIT_TEST(testOptUnchoking);
CPPUNIT_TEST(testShouldBeChoking);
CPPUNIT_TEST(testCountOutstandingRequest);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
@ -50,6 +54,7 @@ public:
void testChokingRequired();
void testOptUnchoking();
void testShouldBeChoking();
void testCountOutstandingRequest();
};
@ -251,4 +256,14 @@ void PeerSessionResourceTest::testShouldBeChoking()
CPPUNIT_ASSERT(!res.shouldBeChoking());
}
void PeerSessionResourceTest::testCountOutstandingRequest()
{
PeerSessionResource res(1024, 1024*1024);
SharedHandle<MockBtMessageDispatcher> dispatcher
(new MockBtMessageDispatcher());
res.setBtMessageDispatcher(dispatcher);
CPPUNIT_ASSERT_EQUAL((size_t)0, res.countOutstandingUpload());
}
} // namespace aria2