/* */ #ifndef _D_BT_RUNTIME_H_ #define _D_BT_RUNTIME_H_ #include "common.h" #include "BtConstants.h" namespace aria2 { class BtRuntime { private: uint64_t uploadLengthAtStartup; uint16_t port; bool halt; unsigned int connections; bool _ready; // Maximum number of peers to hold connections at the same time. // 0 means unlimited. unsigned int _maxPeers; // Minimum number of peers. This value is used for getting more peers from // tracker. 0 means always the number of peers is under minimum. unsigned int _minPeers; static const unsigned int DEFAULT_MIN_PEERS = 40; public: BtRuntime(): uploadLengthAtStartup(0), port(0), halt(false), connections(0), _ready(false), _maxPeers(DEFAULT_MAX_PEERS), _minPeers(DEFAULT_MIN_PEERS) {} ~BtRuntime() {} uint64_t getUploadLengthAtStartup() const { return uploadLengthAtStartup; } void setUploadLengthAtStartup(uint64_t length) { this->uploadLengthAtStartup = length; } void setListenPort(uint16_t port) { this->port = port; } uint16_t getListenPort() const { return port; } bool isHalt() const { return halt; } void setHalt(bool halt) { this->halt = halt; } unsigned int getConnections() const { return connections; } void increaseConnections() { connections++; } void decreaseConnections() { connections--; } bool lessThanMaxPeers() const { return _maxPeers == 0 || connections < _maxPeers; } bool lessThanMinPeers() const { return _minPeers == 0 || connections < _minPeers; } bool lessThanEqMinPeers() const { return _minPeers == 0 || connections <= _minPeers; } bool ready() { return _ready; } void setReady(bool go) { _ready = go; } void setMaxPeers(unsigned int maxPeers) { _maxPeers = maxPeers; _minPeers = static_cast(maxPeers*0.8); if(_minPeers == 0 && maxPeers != 0) { _minPeers = maxPeers; } } unsigned int getMaxPeers() const { return _maxPeers; } static const unsigned int DEFAULT_MAX_PEERS = 55; }; typedef SharedHandle BtRuntimeHandle; } // namespace aria2 #endif // _D_BT_RUNTIME_H_