/* */ #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) { _uploadLengthAtStartup = length; } void setListenPort(uint16_t port) { _port = port; } uint16_t getListenPort() const { return _port; } bool isHalt() const { return _halt; } void setHalt(bool halt) { _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_