/* */ #ifndef _D_BT_HANDSHAKE_MESSAGE_H_ #define _D_BT_HANDSHAKE_MESSAGE_H_ #include "SimpleBtMessage.h" namespace aria2 { class BtHandshakeMessage : public SimpleBtMessage { public: static const int32_t PSTR_LENGTH = 19; static const unsigned char* BT_PSTR; static const int32_t RESERVED_LENGTH = 8; static const int32_t MESSAGE_LENGTH = 68; private: int8_t pstrlen; unsigned char* pstr; unsigned char* reserved; unsigned char* infoHash; unsigned char* peerId; unsigned char* msg; void init(); public: BtHandshakeMessage(); /** * infoHash must be 20 byte length. * peerId must be 20 byte length. */ BtHandshakeMessage(const unsigned char* infoHash, const unsigned char* peerId); static SharedHandle create(const unsigned char* data, int32_t dataLength); virtual ~BtHandshakeMessage() { delete [] msg; delete [] pstr; delete [] reserved; delete [] infoHash; delete [] peerId; } static const int8_t ID = INT8_MAX; virtual int8_t getId() { return ID; } virtual void doReceivedAction() {}; virtual const unsigned char* getMessage(); virtual int32_t getMessageLength(); virtual std::string toString() const; bool isFastExtensionSupported() const; bool isExtendedMessagingEnabled() const; bool isDHTEnabled() const; void setDHTEnabled(bool enabled) { if(enabled) { this->reserved[7] |= 0x01; } else { this->reserved[7] &= ~0x01; } } int8_t getPstrlen() const { return pstrlen; } const unsigned char* getPstr() const { return pstr; } const unsigned char* getReserved() const { return reserved; } const unsigned char* getInfoHash() const { return infoHash; } void setInfoHash(const unsigned char* infoHash); const unsigned char* getPeerId() const { return peerId; } void setPeerId(const unsigned char* peerId); }; } // namespace aria2 #endif // _D_HANDSHAKE_MESSAGE_H_