mirror of https://github.com/aria2/aria2
2010-06-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Renamed member variables * src/BtHandshakeMessage.cc * src/BtHandshakeMessage.hpull/1/head
parent
0901dfcfc1
commit
b33d679618
|
@ -1,3 +1,9 @@
|
|||
2010-06-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Renamed member variables
|
||||
* src/BtHandshakeMessage.cc
|
||||
* src/BtHandshakeMessage.h
|
||||
|
||||
2010-06-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Renamed member variables
|
||||
|
|
|
@ -57,44 +57,44 @@ BtHandshakeMessage::BtHandshakeMessage(const unsigned char* infoHash,
|
|||
SimpleBtMessage(ID, NAME)
|
||||
{
|
||||
init();
|
||||
memcpy(this->infoHash, infoHash, INFO_HASH_LENGTH);
|
||||
memcpy(this->peerId, peerId, PEER_ID_LENGTH);
|
||||
memcpy(_infoHash, infoHash, INFO_HASH_LENGTH);
|
||||
memcpy(_peerId, peerId, PEER_ID_LENGTH);
|
||||
}
|
||||
|
||||
void BtHandshakeMessage::init() {
|
||||
this->pstrlen = 19;
|
||||
pstr = new unsigned char[PSTR_LENGTH];
|
||||
reserved = new unsigned char[RESERVED_LENGTH];
|
||||
infoHash = new unsigned char[INFO_HASH_LENGTH];
|
||||
peerId = new unsigned char[PEER_ID_LENGTH];
|
||||
memcpy(this->pstr, BT_PSTR, PSTR_LENGTH);
|
||||
memset(this->reserved, 0, RESERVED_LENGTH);
|
||||
_pstrlen = 19;
|
||||
_pstr = new unsigned char[PSTR_LENGTH];
|
||||
_reserved = new unsigned char[RESERVED_LENGTH];
|
||||
_infoHash = new unsigned char[INFO_HASH_LENGTH];
|
||||
_peerId = new unsigned char[PEER_ID_LENGTH];
|
||||
memcpy(_pstr, BT_PSTR, PSTR_LENGTH);
|
||||
memset(_reserved, 0, RESERVED_LENGTH);
|
||||
// fast extension
|
||||
this->reserved[7] |= 0x04;
|
||||
_reserved[7] |= 0x04;
|
||||
// extended messaging
|
||||
this->reserved[5] |= 0x10;
|
||||
_reserved[5] |= 0x10;
|
||||
}
|
||||
|
||||
SharedHandle<BtHandshakeMessage>
|
||||
BtHandshakeMessage::create(const unsigned char* data, size_t dataLength)
|
||||
{
|
||||
SharedHandle<BtHandshakeMessage> message(new BtHandshakeMessage());
|
||||
message->pstrlen = data[0];
|
||||
memcpy(message->pstr, &data[1], PSTR_LENGTH);
|
||||
memcpy(message->reserved, &data[20], RESERVED_LENGTH);
|
||||
memcpy(message->infoHash, &data[28], INFO_HASH_LENGTH);
|
||||
memcpy(message->peerId, &data[48], PEER_ID_LENGTH);
|
||||
message->_pstrlen = data[0];
|
||||
memcpy(message->_pstr, &data[1], PSTR_LENGTH);
|
||||
memcpy(message->_reserved, &data[20], RESERVED_LENGTH);
|
||||
memcpy(message->_infoHash, &data[28], INFO_HASH_LENGTH);
|
||||
memcpy(message->_peerId, &data[48], PEER_ID_LENGTH);
|
||||
return message;
|
||||
}
|
||||
|
||||
unsigned char* BtHandshakeMessage::createMessage()
|
||||
{
|
||||
unsigned char* msg = new unsigned char[MESSAGE_LENGTH];
|
||||
msg[0] = pstrlen;
|
||||
memcpy(msg+1, pstr, PSTR_LENGTH);
|
||||
memcpy(msg+20, reserved, RESERVED_LENGTH);
|
||||
memcpy(msg+28, infoHash, INFO_HASH_LENGTH);
|
||||
memcpy(msg+48, peerId, PEER_ID_LENGTH);
|
||||
msg[0] = _pstrlen;
|
||||
memcpy(msg+1, _pstr, PSTR_LENGTH);
|
||||
memcpy(msg+20, _reserved, RESERVED_LENGTH);
|
||||
memcpy(msg+28, _infoHash, INFO_HASH_LENGTH);
|
||||
memcpy(msg+48, _peerId, PEER_ID_LENGTH);
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
@ -104,33 +104,33 @@ size_t BtHandshakeMessage::getMessageLength() {
|
|||
|
||||
std::string BtHandshakeMessage::toString() const {
|
||||
return strconcat(NAME, " peerId=",
|
||||
util::percentEncode(peerId, PEER_ID_LENGTH),
|
||||
util::percentEncode(_peerId, PEER_ID_LENGTH),
|
||||
", reserved=",
|
||||
util::toHex(reserved, RESERVED_LENGTH));
|
||||
util::toHex(_reserved, RESERVED_LENGTH));
|
||||
}
|
||||
|
||||
bool BtHandshakeMessage::isFastExtensionSupported() const {
|
||||
return reserved[7]&0x04;
|
||||
return _reserved[7]&0x04;
|
||||
}
|
||||
|
||||
bool BtHandshakeMessage::isExtendedMessagingEnabled() const
|
||||
{
|
||||
return reserved[5]&0x10;
|
||||
return _reserved[5]&0x10;
|
||||
}
|
||||
|
||||
bool BtHandshakeMessage::isDHTEnabled() const
|
||||
{
|
||||
return reserved[7]&0x01;
|
||||
return _reserved[7]&0x01;
|
||||
}
|
||||
|
||||
void BtHandshakeMessage::setInfoHash(const unsigned char* infoHash)
|
||||
{
|
||||
memcpy(this->infoHash, infoHash, INFO_HASH_LENGTH);
|
||||
memcpy(_infoHash, infoHash, INFO_HASH_LENGTH);
|
||||
}
|
||||
|
||||
void BtHandshakeMessage::setPeerId(const unsigned char* peerId)
|
||||
{
|
||||
memcpy(this->peerId, peerId, PEER_ID_LENGTH);
|
||||
memcpy(_peerId, peerId, PEER_ID_LENGTH);
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -46,11 +46,11 @@ public:
|
|||
static const size_t RESERVED_LENGTH = 8;
|
||||
static const size_t MESSAGE_LENGTH = 68;
|
||||
private:
|
||||
uint8_t pstrlen;
|
||||
unsigned char* pstr;
|
||||
unsigned char* reserved;
|
||||
unsigned char* infoHash;
|
||||
unsigned char* peerId;
|
||||
uint8_t _pstrlen;
|
||||
unsigned char* _pstr;
|
||||
unsigned char* _reserved;
|
||||
unsigned char* _infoHash;
|
||||
unsigned char* _peerId;
|
||||
void init();
|
||||
public:
|
||||
BtHandshakeMessage();
|
||||
|
@ -64,10 +64,10 @@ public:
|
|||
create(const unsigned char* data, size_t dataLength);
|
||||
|
||||
virtual ~BtHandshakeMessage() {
|
||||
delete [] pstr;
|
||||
delete [] reserved;
|
||||
delete [] infoHash;
|
||||
delete [] peerId;
|
||||
delete [] _pstr;
|
||||
delete [] _reserved;
|
||||
delete [] _infoHash;
|
||||
delete [] _peerId;
|
||||
}
|
||||
|
||||
static const uint8_t ID = INT8_MAX;
|
||||
|
@ -91,32 +91,32 @@ public:
|
|||
void setDHTEnabled(bool enabled)
|
||||
{
|
||||
if(enabled) {
|
||||
this->reserved[7] |= 0x01;
|
||||
_reserved[7] |= 0x01;
|
||||
} else {
|
||||
this->reserved[7] &= ~0x01;
|
||||
_reserved[7] &= ~0x01;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t getPstrlen() const {
|
||||
return pstrlen;
|
||||
return _pstrlen;
|
||||
}
|
||||
|
||||
const unsigned char* getPstr() const {
|
||||
return pstr;
|
||||
return _pstr;
|
||||
}
|
||||
|
||||
const unsigned char* getReserved() const {
|
||||
return reserved;
|
||||
return _reserved;
|
||||
}
|
||||
|
||||
const unsigned char* getInfoHash() const {
|
||||
return infoHash;
|
||||
return _infoHash;
|
||||
}
|
||||
|
||||
void setInfoHash(const unsigned char* infoHash);
|
||||
|
||||
const unsigned char* getPeerId() const {
|
||||
return peerId;
|
||||
return _peerId;
|
||||
}
|
||||
|
||||
void setPeerId(const unsigned char* peerId);
|
||||
|
|
Loading…
Reference in New Issue