mirror of https://github.com/aria2/aria2
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.ccpull/1/head
parent
7cf589e784
commit
7818e0e770
12
ChangeLog
12
ChangeLog
|
@ -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>
|
2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Made BtRegistry non-static object. Now DownloadEngine has a reference to
|
Made BtRegistry non-static object. Now DownloadEngine has a reference to
|
||||||
|
|
|
@ -70,14 +70,13 @@ public:
|
||||||
|
|
||||||
bool operator()(Peer* left, Peer* right) const
|
bool operator()(Peer* left, Peer* right) const
|
||||||
{
|
{
|
||||||
// TODO Should peer have the reference to message dispatcher?
|
size_t leftUpload = left->countOutstandingUpload();
|
||||||
// size_t leftUpload = BT_MESSAGE_DISPATCHER(_btContext, left)->countOutstandingUpload();
|
size_t rightUpload = right->countOutstandingUpload();
|
||||||
// size_t rightUpload = BT_MESSAGE_DISPATCHER(_btContext, right)->countOutstandingUpload();
|
if(leftUpload && !rightUpload) {
|
||||||
// if(leftUpload && !rightUpload) {
|
return true;
|
||||||
// return true;
|
} else if(!leftUpload && rightUpload) {
|
||||||
// } else if(!leftUpload && rightUpload) {
|
return false;
|
||||||
// return false;
|
}
|
||||||
// }
|
|
||||||
const int TIME_FRAME = 20;
|
const int TIME_FRAME = 20;
|
||||||
if(!left->getLastAmUnchoking().elapsed(TIME_FRAME) &&
|
if(!left->getLastAmUnchoking().elapsed(TIME_FRAME) &&
|
||||||
left->getLastAmUnchoking().isNewer(right->getLastAmUnchoking())) {
|
left->getLastAmUnchoking().isNewer(right->getLastAmUnchoking())) {
|
||||||
|
|
19
src/Peer.cc
19
src/Peer.cc
|
@ -33,13 +33,16 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "PeerSessionResource.h"
|
#include "PeerSessionResource.h"
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
# include "MessageDigestHelper.h"
|
# include "MessageDigestHelper.h"
|
||||||
#endif // ENABLE_MESSAGE_DIGEST
|
#endif // ENABLE_MESSAGE_DIGEST
|
||||||
#include <cstring>
|
#include "BtMessageDispatcher.h"
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -476,4 +479,16 @@ void Peer::setFirstContactTime(const Time& time)
|
||||||
_firstContactTime = 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
|
} // namespace aria2
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class PeerSessionResource;
|
class PeerSessionResource;
|
||||||
|
class BtMessageDispatcher;
|
||||||
|
|
||||||
class Peer {
|
class Peer {
|
||||||
public:
|
public:
|
||||||
|
@ -246,6 +247,10 @@ public:
|
||||||
bool isIncomingPeer() const;
|
bool isIncomingPeer() const;
|
||||||
|
|
||||||
void setIncomingPeer(bool incoming);
|
void setIncomingPeer(bool incoming);
|
||||||
|
|
||||||
|
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dpt);
|
||||||
|
|
||||||
|
size_t countOutstandingUpload() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<Peer> PeerHandle;
|
typedef SharedHandle<Peer> PeerHandle;
|
||||||
|
|
|
@ -190,6 +190,7 @@ PeerInteractionCommand::PeerInteractionCommand
|
||||||
setUploadLimit(e->option->getAsInt(PREF_MAX_UPLOAD_LIMIT));
|
setUploadLimit(e->option->getAsInt(PREF_MAX_UPLOAD_LIMIT));
|
||||||
peer->allocateSessionResource(_btContext->getPieceLength(),
|
peer->allocateSessionResource(_btContext->getPieceLength(),
|
||||||
_btContext->getTotalLength());
|
_btContext->getTotalLength());
|
||||||
|
peer->setBtMessageDispatcher(dispatcher);
|
||||||
|
|
||||||
maxDownloadSpeedLimit = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT);
|
maxDownloadSpeedLimit = e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT);
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,14 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "PeerSessionResource.h"
|
#include "PeerSessionResource.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "BitfieldManFactory.h"
|
#include "BitfieldManFactory.h"
|
||||||
#include "BitfieldMan.h"
|
#include "BitfieldMan.h"
|
||||||
#include "A2STR.h"
|
#include "A2STR.h"
|
||||||
#include <algorithm>
|
#include "BtMessageDispatcher.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -338,4 +342,16 @@ uint64_t PeerSessionResource::getCompletedLength() const
|
||||||
return _bitfieldMan->getCompletedLength();
|
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
|
} // namespace aria2
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class BitfieldMan;
|
class BitfieldMan;
|
||||||
|
class BtMessageDispatcher;
|
||||||
|
|
||||||
class PeerSessionResource {
|
class PeerSessionResource {
|
||||||
private:
|
private:
|
||||||
|
@ -78,6 +79,8 @@ private:
|
||||||
Time _lastDownloadUpdate;
|
Time _lastDownloadUpdate;
|
||||||
|
|
||||||
Time _lastAmUnchoking;
|
Time _lastAmUnchoking;
|
||||||
|
|
||||||
|
WeakHandle<BtMessageDispatcher> _dispatcher;
|
||||||
public:
|
public:
|
||||||
PeerSessionResource(size_t pieceLength, uint64_t totalLength);
|
PeerSessionResource(size_t pieceLength, uint64_t totalLength);
|
||||||
|
|
||||||
|
@ -185,6 +188,10 @@ public:
|
||||||
const Time& getLastAmUnchoking() const;
|
const Time& getLastAmUnchoking() const;
|
||||||
|
|
||||||
uint64_t getCompletedLength() const;
|
uint64_t getCompletedLength() const;
|
||||||
|
|
||||||
|
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dpt);
|
||||||
|
|
||||||
|
size_t countOutstandingUpload() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -2,8 +2,12 @@
|
||||||
#define _D_MOCK_BT_MESSAGE_DISPATCHER_H_
|
#define _D_MOCK_BT_MESSAGE_DISPATCHER_H_
|
||||||
|
|
||||||
#include "BtMessageDispatcher.h"
|
#include "BtMessageDispatcher.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "BtMessage.h"
|
||||||
|
#include "Piece.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class MockBtMessageDispatcher : public BtMessageDispatcher {
|
class MockBtMessageDispatcher : public BtMessageDispatcher {
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
#include "PeerSessionResource.h"
|
#include "PeerSessionResource.h"
|
||||||
|
|
||||||
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
|
#include "MockBtMessageDispatcher.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -26,6 +29,7 @@ class PeerSessionResourceTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testChokingRequired);
|
CPPUNIT_TEST(testChokingRequired);
|
||||||
CPPUNIT_TEST(testOptUnchoking);
|
CPPUNIT_TEST(testOptUnchoking);
|
||||||
CPPUNIT_TEST(testShouldBeChoking);
|
CPPUNIT_TEST(testShouldBeChoking);
|
||||||
|
CPPUNIT_TEST(testCountOutstandingRequest);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
public:
|
public:
|
||||||
void setUp() {}
|
void setUp() {}
|
||||||
|
@ -50,6 +54,7 @@ public:
|
||||||
void testChokingRequired();
|
void testChokingRequired();
|
||||||
void testOptUnchoking();
|
void testOptUnchoking();
|
||||||
void testShouldBeChoking();
|
void testShouldBeChoking();
|
||||||
|
void testCountOutstandingRequest();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -251,4 +256,14 @@ void PeerSessionResourceTest::testShouldBeChoking()
|
||||||
CPPUNIT_ASSERT(!res.shouldBeChoking());
|
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
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue