/* */ #ifndef D_BT_LEECHER_STATE_CHOKE_H #define D_BT_LEECHER_STATE_CHOKE_H #include "common.h" #include #include "SharedHandle.h" #include "TimerA2.h" namespace aria2 { class Peer; class BtLeecherStateChoke { private: int round_; Timer lastRound_; class PeerEntry { private: SharedHandle peer_; unsigned int downloadSpeed_; bool regularUnchoker_; public: PeerEntry(const SharedHandle& peer); PeerEntry(const PeerEntry& c); ~PeerEntry(); PeerEntry& operator=(const PeerEntry& c); bool operator<(const PeerEntry& rhs) const; void swap(PeerEntry& c); const SharedHandle& getPeer() const; unsigned int getDownloadSpeed() const; bool isRegularUnchoker() const; bool isSnubbing() const; void enableChokingRequired(); void disableChokingRequired(); void enableOptUnchoking(); void disableOptUnchoking(); }; void plannedOptimisticUnchoke(std::vector& peerEntries); void regularUnchoke(std::vector& peerEntries); class PeerFilter { private: bool amChoking_; bool peerInterested_; public: PeerFilter(bool amChoking, bool peerInterested): amChoking_(amChoking), peerInterested_(peerInterested) {} bool operator()(const PeerEntry& peerEntry) const; }; class BtLeecherStateChokeGenPeerEntry { public: PeerEntry operator()(const SharedHandle& peer) const { return PeerEntry(peer); } }; public: BtLeecherStateChoke(); ~BtLeecherStateChoke(); void executeChoke(const std::vector >& peerSet); const Timer& getLastRound() const; friend void swap(PeerEntry& a, PeerEntry& b); friend void std::swap(PeerEntry& a, PeerEntry& b); }; void swap (BtLeecherStateChoke::PeerEntry& a, BtLeecherStateChoke::PeerEntry& b); } // namespace aria2 namespace std { template<> void swap (aria2::BtLeecherStateChoke::PeerEntry& a, aria2::BtLeecherStateChoke::PeerEntry& b); } // namespace std #endif // D_BT_LEECHER_STATE_CHOKE_H