/* */ #ifndef _D_DHT_BUCKET_H_ #define _D_DHT_BUCKET_H_ #include "common.h" #include "SharedHandle.h" #include "DHTConstants.h" #include "TimeA2.h" #include #include namespace aria2 { class DHTNode; class Logger; class DHTBucket { private: size_t _prefixLength; // this bucket contains nodes of distance between [_min, _max](inclusive). unsigned char _min[DHT_ID_LENGTH]; unsigned char _max[DHT_ID_LENGTH]; SharedHandle _localNode; // sorted in ascending order std::deque > _nodes; // a replacement cache. The maximum size is specified by CACHE_SIZE. // This is sorted by last time seen. std::deque > _cachedNodes; Time _lastUpdated; Logger* _logger; bool isInRange(const unsigned char* nodeID, const unsigned char* max, const unsigned char* min) const; public: DHTBucket(const SharedHandle& localNode); DHTBucket(size_t prefixLength, const unsigned char* max, const unsigned char* min, const SharedHandle& localNode); ~DHTBucket(); static const size_t K = 8; static const size_t CACHE_SIZE = 2; void getRandomNodeID(unsigned char* nodeID) const; SharedHandle split(); bool isInRange(const SharedHandle& node) const; bool isInRange(const unsigned char* nodeID) const; bool addNode(const SharedHandle& node); void cacheNode(const SharedHandle& node); bool splitAllowed() const; size_t getPrefixLength() const { return _prefixLength; } const unsigned char* getMaxID() const { return _max; } const unsigned char* getMinID() const { return _min; } size_t countNode() const; const std::deque >& getNodes() const; void getGoodNodes(std::deque >& nodes) const; void dropNode(const SharedHandle& node); void moveToHead(const SharedHandle& node); void moveToTail(const SharedHandle& node); bool contains(const SharedHandle& node) const; SharedHandle getNode(const unsigned char* nodeID, const std::string& ipaddr, uint16_t port) const; bool operator==(const DHTBucket& bucket) const; bool needsRefresh() const; void notifyUpdate(); bool containsQuestionableNode() const; SharedHandle getLRUQuestionableNode() const; const std::deque >& getCachedNodes() const; }; } // namespace aria2 #endif // _D_DHT_BUCKET_H_