mirror of https://github.com/aria2/aria2
2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Execute choking algorithm when BtInterestedMessage arrives from unchoked peer. * src/BtInterestedMessage.cc * src/BtInterestedMessage.h * src/DefaultBtMessageFactory.cc * test/BtInterestedMessageTest.cc * test/MockPeerStorage.hpull/1/head
parent
8fab0ff216
commit
6d01f8f94f
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Execute choking algorithm when BtInterestedMessage arrives from
|
||||||
|
unchoked peer.
|
||||||
|
* src/BtInterestedMessage.cc
|
||||||
|
* src/BtInterestedMessage.h
|
||||||
|
* src/DefaultBtMessageFactory.cc
|
||||||
|
* test/BtInterestedMessageTest.cc
|
||||||
|
* test/MockPeerStorage.h
|
||||||
|
|
||||||
2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
AuthConfigFactory is now part of DownloadEngine.
|
AuthConfigFactory is now part of DownloadEngine.
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
#include "BtContext.h"
|
#include "BtContext.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
|
#include "PeerStorage.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -58,6 +59,9 @@ BtInterestedMessageHandle BtInterestedMessage::create(const unsigned char* data,
|
||||||
|
|
||||||
void BtInterestedMessage::doReceivedAction() {
|
void BtInterestedMessage::doReceivedAction() {
|
||||||
peer->peerInterested(true);
|
peer->peerInterested(true);
|
||||||
|
if(!peer->amChoking()) {
|
||||||
|
_peerStorage->executeChoke();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BtInterestedMessage::sendPredicate() const {
|
bool BtInterestedMessage::sendPredicate() const {
|
||||||
|
@ -92,4 +96,10 @@ std::string BtInterestedMessage::toString() const {
|
||||||
return INTERESTED;
|
return INTERESTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BtInterestedMessage::setPeerStorage
|
||||||
|
(const SharedHandle<PeerStorage>& peerStorage)
|
||||||
|
{
|
||||||
|
_peerStorage = peerStorage;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
class PeerStorage;
|
||||||
class BtInterestedMessage;
|
class BtInterestedMessage;
|
||||||
|
|
||||||
typedef SharedHandle<BtInterestedMessage> BtInterestedMessageHandle;
|
typedef SharedHandle<BtInterestedMessage> BtInterestedMessageHandle;
|
||||||
|
@ -47,6 +48,8 @@ class BtInterestedMessage : public SimpleBtMessage {
|
||||||
private:
|
private:
|
||||||
unsigned char* msg;
|
unsigned char* msg;
|
||||||
|
|
||||||
|
SharedHandle<PeerStorage> _peerStorage;
|
||||||
|
|
||||||
static size_t MESSAGE_LENGTH;
|
static size_t MESSAGE_LENGTH;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -73,6 +76,8 @@ public:
|
||||||
virtual bool sendPredicate() const;
|
virtual bool sendPredicate() const;
|
||||||
|
|
||||||
virtual void onSendComplete();
|
virtual void onSendComplete();
|
||||||
|
|
||||||
|
void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -96,7 +96,12 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
|
||||||
msg = BtUnchokeMessage::create(data, dataLength);
|
msg = BtUnchokeMessage::create(data, dataLength);
|
||||||
break;
|
break;
|
||||||
case BtInterestedMessage::ID:
|
case BtInterestedMessage::ID:
|
||||||
msg = BtInterestedMessage::create(data, dataLength);
|
{
|
||||||
|
SharedHandle<BtInterestedMessage> m =
|
||||||
|
BtInterestedMessage::create(data, dataLength);
|
||||||
|
m->setPeerStorage(_peerStorage);
|
||||||
|
msg = m;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case BtNotInterestedMessage::ID:
|
case BtNotInterestedMessage::ID:
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "PeerMessageUtil.h"
|
#include "PeerMessageUtil.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
|
#include "MockPeerStorage.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -18,12 +19,7 @@ class BtInterestedMessageTest:public CppUnit::TestFixture {
|
||||||
CPPUNIT_TEST(testOnSendComplete);
|
CPPUNIT_TEST(testOnSendComplete);
|
||||||
CPPUNIT_TEST(testToString);
|
CPPUNIT_TEST(testToString);
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
private:
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setUp() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void testCreate();
|
void testCreate();
|
||||||
void testGetMessage();
|
void testGetMessage();
|
||||||
void testDoReceivedAction();
|
void testDoReceivedAction();
|
||||||
|
@ -71,9 +67,18 @@ void BtInterestedMessageTest::testDoReceivedAction() {
|
||||||
peer->allocateSessionResource(1024, 1024*1024);
|
peer->allocateSessionResource(1024, 1024*1024);
|
||||||
msg.setPeer(peer);
|
msg.setPeer(peer);
|
||||||
|
|
||||||
|
SharedHandle<MockPeerStorage> peerStorage(new MockPeerStorage());
|
||||||
|
|
||||||
|
msg.setPeerStorage(peerStorage);
|
||||||
|
|
||||||
CPPUNIT_ASSERT(!peer->peerInterested());
|
CPPUNIT_ASSERT(!peer->peerInterested());
|
||||||
msg.doReceivedAction();
|
msg.doReceivedAction();
|
||||||
CPPUNIT_ASSERT(peer->peerInterested());
|
CPPUNIT_ASSERT(peer->peerInterested());
|
||||||
|
CPPUNIT_ASSERT_EQUAL(0, peerStorage->getNumChokeExecuted());
|
||||||
|
|
||||||
|
peer->amChoking(false);
|
||||||
|
msg.doReceivedAction();
|
||||||
|
CPPUNIT_ASSERT_EQUAL(1, peerStorage->getNumChokeExecuted());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtInterestedMessageTest::testOnSendComplete() {
|
void BtInterestedMessageTest::testOnSendComplete() {
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
#define _D_MOCK_PEER_STORAGE_H_
|
#define _D_MOCK_PEER_STORAGE_H_
|
||||||
|
|
||||||
#include "PeerStorage.h"
|
#include "PeerStorage.h"
|
||||||
#include "Peer.h"
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "Peer.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class MockPeerStorage : public PeerStorage {
|
class MockPeerStorage : public PeerStorage {
|
||||||
|
@ -12,8 +14,9 @@ private:
|
||||||
TransferStat stat;
|
TransferStat stat;
|
||||||
std::deque<SharedHandle<Peer> > peers;
|
std::deque<SharedHandle<Peer> > peers;
|
||||||
std::deque<SharedHandle<Peer> > activePeers;
|
std::deque<SharedHandle<Peer> > activePeers;
|
||||||
|
int _numChokeExecuted;
|
||||||
public:
|
public:
|
||||||
MockPeerStorage() {}
|
MockPeerStorage():_numChokeExecuted(0) {}
|
||||||
virtual ~MockPeerStorage() {}
|
virtual ~MockPeerStorage() {}
|
||||||
|
|
||||||
virtual bool addPeer(const SharedHandle<Peer>& peer) {
|
virtual bool addPeer(const SharedHandle<Peer>& peer) {
|
||||||
|
@ -63,7 +66,15 @@ public:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void executeChoke() {}
|
virtual void executeChoke()
|
||||||
|
{
|
||||||
|
++_numChokeExecuted;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getNumChokeExecuted() const
|
||||||
|
{
|
||||||
|
return _numChokeExecuted;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _D_MOCK_PEER_STORAGE_H_
|
#endif // _D_MOCK_PEER_STORAGE_H_
|
||||||
|
|
Loading…
Reference in New Issue