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