diff --git a/src/BtInterestedMessage.cc b/src/BtInterestedMessage.cc index bbf3a6ac..0b919251 100644 --- a/src/BtInterestedMessage.cc +++ b/src/BtInterestedMessage.cc @@ -69,29 +69,6 @@ void BtInterestedMessage::doReceivedAction() } } -bool BtInterestedMessage::sendPredicate() const -{ - return !getPeer()->amInterested(); -} - -namespace { -struct ThisProgressUpdate : public ProgressUpdate { - ThisProgressUpdate(std::shared_ptr peer) : peer(std::move(peer)) {} - virtual void update(size_t length, bool complete) CXX11_OVERRIDE - { - if (complete) { - peer->amInterested(true); - } - } - std::shared_ptr peer; -}; -} // namespace - -std::unique_ptr BtInterestedMessage::getProgressUpdate() -{ - return make_unique(getPeer()); -} - void BtInterestedMessage::setPeerStorage(PeerStorage* peerStorage) { peerStorage_ = peerStorage; diff --git a/src/BtInterestedMessage.h b/src/BtInterestedMessage.h index 31d898e7..d1c2332b 100644 --- a/src/BtInterestedMessage.h +++ b/src/BtInterestedMessage.h @@ -59,10 +59,6 @@ public: virtual void doReceivedAction() CXX11_OVERRIDE; - virtual bool sendPredicate() const CXX11_OVERRIDE; - - virtual std::unique_ptr getProgressUpdate() CXX11_OVERRIDE; - void setPeerStorage(PeerStorage* peerStorage); }; diff --git a/src/BtNotInterestedMessage.cc b/src/BtNotInterestedMessage.cc index 45c39de1..530826c5 100644 --- a/src/BtNotInterestedMessage.cc +++ b/src/BtNotInterestedMessage.cc @@ -65,29 +65,6 @@ void BtNotInterestedMessage::doReceivedAction() } } -bool BtNotInterestedMessage::sendPredicate() const -{ - return getPeer()->amInterested(); -} - -namespace { -struct ThisProgressUpdate : public ProgressUpdate { - ThisProgressUpdate(std::shared_ptr peer) : peer(std::move(peer)) {} - virtual void update(size_t length, bool complete) CXX11_OVERRIDE - { - if (complete) { - peer->amInterested(false); - } - } - std::shared_ptr peer; -}; -} // namespace - -std::unique_ptr BtNotInterestedMessage::getProgressUpdate() -{ - return make_unique(getPeer()); -} - void BtNotInterestedMessage::setPeerStorage(PeerStorage* peerStorage) { peerStorage_ = peerStorage; diff --git a/src/BtNotInterestedMessage.h b/src/BtNotInterestedMessage.h index ae958bf5..0d5ed25c 100644 --- a/src/BtNotInterestedMessage.h +++ b/src/BtNotInterestedMessage.h @@ -59,10 +59,6 @@ public: virtual void doReceivedAction() CXX11_OVERRIDE; - virtual bool sendPredicate() const CXX11_OVERRIDE; - - virtual std::unique_ptr getProgressUpdate() CXX11_OVERRIDE; - void setPeerStorage(PeerStorage* peerStorage); }; diff --git a/src/DefaultBtInteractive.cc b/src/DefaultBtInteractive.cc index d3e6d0a4..ead26393 100644 --- a/src/DefaultBtInteractive.cc +++ b/src/DefaultBtInteractive.cc @@ -363,6 +363,7 @@ void DefaultBtInteractive::decideInterest() if (pieceStorage_->hasMissingPiece(peer_)) { if (!peer_->amInterested()) { A2_LOG_DEBUG(fmt(MSG_PEER_INTERESTED, cuid_)); + peer_->amInterested(true); dispatcher_->addMessageToQueue( messageFactory_->createInterestedMessage()); } @@ -370,6 +371,7 @@ void DefaultBtInteractive::decideInterest() else { if (peer_->amInterested()) { A2_LOG_DEBUG(fmt(MSG_PEER_NOT_INTERESTED, cuid_)); + peer_->amInterested(false); dispatcher_->addMessageToQueue( messageFactory_->createNotInterestedMessage()); } diff --git a/test/BtInterestedMessageTest.cc b/test/BtInterestedMessageTest.cc index 732aa1a1..7d1805f8 100644 --- a/test/BtInterestedMessageTest.cc +++ b/test/BtInterestedMessageTest.cc @@ -17,7 +17,6 @@ class BtInterestedMessageTest : public CppUnit::TestFixture { CPPUNIT_TEST(testCreate); CPPUNIT_TEST(testCreateMessage); CPPUNIT_TEST(testDoReceivedAction); - CPPUNIT_TEST(testOnSendComplete); CPPUNIT_TEST(testToString); CPPUNIT_TEST_SUITE_END(); @@ -25,7 +24,6 @@ public: void testCreate(); void testCreateMessage(); void testDoReceivedAction(); - void testOnSendComplete(); void testToString(); }; @@ -90,18 +88,6 @@ void BtInterestedMessageTest::testDoReceivedAction() CPPUNIT_ASSERT_EQUAL(1, peerStorage->getNumChokeExecuted()); } -void BtInterestedMessageTest::testOnSendComplete() -{ - BtInterestedMessage msg; - std::shared_ptr peer(new Peer("host", 6969)); - peer->allocateSessionResource(1_k, 1_m); - msg.setPeer(peer); - CPPUNIT_ASSERT(!peer->amInterested()); - std::shared_ptr pu(msg.getProgressUpdate()); - pu->update(0, true); - CPPUNIT_ASSERT(peer->amInterested()); -} - void BtInterestedMessageTest::testToString() { BtInterestedMessage msg; diff --git a/test/BtNotInterestedMessageTest.cc b/test/BtNotInterestedMessageTest.cc index 88d233c2..0c74c971 100644 --- a/test/BtNotInterestedMessageTest.cc +++ b/test/BtNotInterestedMessageTest.cc @@ -17,7 +17,6 @@ class BtNotInterestedMessageTest : public CppUnit::TestFixture { CPPUNIT_TEST(testCreate); CPPUNIT_TEST(testCreateMessage); CPPUNIT_TEST(testDoReceivedAction); - CPPUNIT_TEST(testOnSendComplete); CPPUNIT_TEST(testToString); CPPUNIT_TEST_SUITE_END(); @@ -25,7 +24,6 @@ public: void testCreate(); void testCreateMessage(); void testDoReceivedAction(); - void testOnSendComplete(); void testToString(); }; @@ -91,19 +89,6 @@ void BtNotInterestedMessageTest::testDoReceivedAction() CPPUNIT_ASSERT_EQUAL(1, peerStorage->getNumChokeExecuted()); } -void BtNotInterestedMessageTest::testOnSendComplete() -{ - std::shared_ptr peer(new Peer("host", 6969)); - peer->allocateSessionResource(1_k, 1_m); - peer->amInterested(true); - BtNotInterestedMessage msg; - msg.setPeer(peer); - CPPUNIT_ASSERT(peer->amInterested()); - std::shared_ptr pu(msg.getProgressUpdate()); - pu->update(0, true); - CPPUNIT_ASSERT(!peer->amInterested()); -} - void BtNotInterestedMessageTest::testToString() { BtNotInterestedMessage msg;