mirror of https://github.com/aria2/aria2
* src/SuggestPieceMessage.h: Removed.
* src/PortMessage.h: Removed. * src/SuggestPieceMessage.h: Removed. * src/KeepAliveMessage.h: Removed. * src/HandshakeMessage.h: Removed. * src/PeerInteraction.h: Removed. * src/UnchokeMessage.h: Removed. * src/PieceMessage.h: Removed. * src/RequestMessage.h: Removed. * src/InterestedMessage.h: Removed. * src/HaveMessage.h: Removed. * src/CancelMessage.h: Removed. * src/RejectMessage.h: Removed. * src/AllowedFastMessage.h: Removed. * src/HaveNoneMessage.h: Removed. * src/SimplePeerMessage.h: Removed. * src/HaveAllMessage.h: Removed. * src/BitfieldMessage.h: Removed. * src/PeerMessageFactory.h: Removed. * src/NotInterestedMessage.h: Removed. * src/ChokeMessage.h: Removed. * src/PeerMessage.h: Removed.pull/1/head
parent
9c3e8fbd9c
commit
708b9f4a3d
24
ChangeLog
24
ChangeLog
|
@ -55,7 +55,29 @@
|
|||
* src/DefaultBtMessageFactory.h: New class.
|
||||
* src/PeerObject.h: New class.
|
||||
* src/BtRequestFactory.h: New class.
|
||||
|
||||
* src/SuggestPieceMessage.h: Removed.
|
||||
* src/PortMessage.h: Removed.
|
||||
* src/SuggestPieceMessage.h: Removed.
|
||||
* src/KeepAliveMessage.h: Removed.
|
||||
* src/HandshakeMessage.h: Removed.
|
||||
* src/PeerInteraction.h: Removed.
|
||||
* src/UnchokeMessage.h: Removed.
|
||||
* src/PieceMessage.h: Removed.
|
||||
* src/RequestMessage.h: Removed.
|
||||
* src/InterestedMessage.h: Removed.
|
||||
* src/HaveMessage.h: Removed.
|
||||
* src/CancelMessage.h: Removed.
|
||||
* src/RejectMessage.h: Removed.
|
||||
* src/AllowedFastMessage.h: Removed.
|
||||
* src/HaveNoneMessage.h: Removed.
|
||||
* src/SimplePeerMessage.h: Removed.
|
||||
* src/HaveAllMessage.h: Removed.
|
||||
* src/BitfieldMessage.h: Removed.
|
||||
* src/PeerMessageFactory.h: Removed.
|
||||
* src/NotInterestedMessage.h: Removed.
|
||||
* src/ChokeMessage.h: Removed.
|
||||
* src/PeerMessage.h: Removed.
|
||||
|
||||
2006-12-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
To know root cause of exception:
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "AllowedFastMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
AllowedFastMessage* AllowedFastMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 5) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "allowed fast", dataLength, 5);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "allowed fast", ID);
|
||||
}
|
||||
AllowedFastMessage* allowedFastMessage = new AllowedFastMessage();
|
||||
allowedFastMessage->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
return allowedFastMessage;
|
||||
}
|
||||
|
||||
void AllowedFastMessage::receivedAction() {
|
||||
if(!peer->isFastExtensionEnabled()) {
|
||||
throw new DlAbortEx("%s received while fast extension is disabled",
|
||||
toString().c_str());
|
||||
}
|
||||
peer->addFastSetIndex(index);
|
||||
}
|
||||
|
||||
const char* AllowedFastMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 5, 4bytes
|
||||
* id --- 17, 1byte
|
||||
* piece index --- index, 4bytes
|
||||
* total: 9bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, ID);
|
||||
PeerMessageUtil::setIntParam(&msg[5], index);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int AllowedFastMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void AllowedFastMessage::onSendComplete() {
|
||||
peerInteraction->addFastSetIndex(index);
|
||||
}
|
||||
|
||||
void AllowedFastMessage::check() const {
|
||||
PeerMessageUtil::checkIndex(index, pieces);
|
||||
}
|
||||
|
||||
string AllowedFastMessage::toString() const {
|
||||
return "allowed fast index="+Util::itos(index);
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_ALLOWED_FAST_MESSAGE_H_
|
||||
#define _D_ALLOWED_FAST_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class AllowedFastMessage : public SimplePeerMessage {
|
||||
private:
|
||||
int index;
|
||||
// for check
|
||||
int pieces;
|
||||
char msg[9];
|
||||
protected:
|
||||
virtual void onSendComplete();
|
||||
public:
|
||||
AllowedFastMessage(int index = 0)
|
||||
:SimplePeerMessage(),
|
||||
index(index),
|
||||
pieces(0) {}
|
||||
|
||||
virtual ~AllowedFastMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 17
|
||||
};
|
||||
|
||||
void setIndex(int index) {
|
||||
this->index = index;
|
||||
}
|
||||
int getIndex() const { return index; }
|
||||
|
||||
void setPieces(int pieces) {
|
||||
this->pieces = pieces;
|
||||
}
|
||||
int getPieces() const { return pieces;}
|
||||
|
||||
static AllowedFastMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual void check() const;
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
||||
#endif // _D_ALLOWED_FAST_MESSAGE_H_
|
|
@ -1,96 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "BitfieldMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
void BitfieldMessage::setBitfield(const unsigned char* bitfield, int bitfieldLength) {
|
||||
if(this->bitfield != NULL) {
|
||||
delete [] this->bitfield;
|
||||
}
|
||||
this->bitfieldLength = bitfieldLength;
|
||||
this->bitfield = new unsigned char[this->bitfieldLength];
|
||||
memcpy(this->bitfield, bitfield, this->bitfieldLength);
|
||||
}
|
||||
|
||||
BitfieldMessage* BitfieldMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength <= 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be greater than %d", "bitfield", dataLength, 1);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "bitfield", ID);
|
||||
}
|
||||
BitfieldMessage* bitfieldMessage = new BitfieldMessage();
|
||||
bitfieldMessage->setBitfield((unsigned char*)data+1, dataLength-1);
|
||||
return bitfieldMessage;
|
||||
}
|
||||
|
||||
void BitfieldMessage::receivedAction() {
|
||||
peer->setBitfield(bitfield, bitfieldLength);
|
||||
}
|
||||
|
||||
const char* BitfieldMessage::getMessage() {
|
||||
if(!inProgress && msg == NULL) {
|
||||
/**
|
||||
* len --- 1+bitfieldLength, 4bytes
|
||||
* id --- 5, 1byte
|
||||
* bitfield --- bitfield, len bytes
|
||||
* total: 5+len bytes
|
||||
*/
|
||||
msgLength = 5+bitfieldLength;
|
||||
msg = new char[msgLength];
|
||||
PeerMessageUtil::createPeerMessageString(msg, msgLength,
|
||||
1+bitfieldLength, ID);
|
||||
memcpy(msg+5, bitfield, bitfieldLength);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int BitfieldMessage::getMessageLength() {
|
||||
getMessage();
|
||||
return msgLength;
|
||||
}
|
||||
|
||||
void BitfieldMessage::check() const {
|
||||
PeerMessageUtil::checkBitfield(bitfield, bitfieldLength, pieces);
|
||||
}
|
||||
|
||||
string BitfieldMessage::toString() const {
|
||||
return "bitfield "+Util::toHex(bitfield, bitfieldLength);
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_BITFIELD_MESSAGE_H_
|
||||
#define _D_BITFIELD_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class BitfieldMessage : public SimplePeerMessage {
|
||||
private:
|
||||
unsigned char* bitfield;
|
||||
int bitfieldLength;
|
||||
// for check
|
||||
int pieces;
|
||||
|
||||
char* msg;
|
||||
int msgLength;
|
||||
|
||||
void init() {
|
||||
bitfield = 0;
|
||||
bitfieldLength = 0;
|
||||
pieces = 0;
|
||||
msg = 0;
|
||||
msgLength = 0;
|
||||
}
|
||||
public:
|
||||
BitfieldMessage()
|
||||
:SimplePeerMessage()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
BitfieldMessage(const unsigned char* bitfield,
|
||||
int bitfieldLength)
|
||||
:SimplePeerMessage()
|
||||
{
|
||||
init();
|
||||
setBitfield(bitfield, bitfieldLength);
|
||||
}
|
||||
|
||||
virtual ~BitfieldMessage() {
|
||||
if(bitfield != NULL) {
|
||||
delete [] bitfield;
|
||||
}
|
||||
if(msg != NULL) {
|
||||
delete [] msg;
|
||||
}
|
||||
}
|
||||
|
||||
enum ID_t {
|
||||
ID = 5
|
||||
};
|
||||
|
||||
void setBitfield(const unsigned char* bitfield, int bitfieldLength);
|
||||
const unsigned char* getBitfield() const { return bitfield; }
|
||||
|
||||
int getBitfieldLength() const { return bitfieldLength; }
|
||||
|
||||
void setPieces(int pieces) {
|
||||
this->pieces = pieces;
|
||||
}
|
||||
int getPieces() const { return pieces;}
|
||||
|
||||
static BitfieldMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual void check() const;
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
||||
#endif // _D_BITFIELD_MESSAGE_H_
|
|
@ -57,7 +57,7 @@ void BtHandshakeMessage::init() {
|
|||
reserved = new unsigned char[RESERVED_LENGTH];
|
||||
infoHash = new unsigned char[INFO_HASH_LENGTH];
|
||||
peerId = new unsigned char[PEER_ID_LENGTH];
|
||||
memcpy(this->pstr, PSTR, PSTR_LENGTH);
|
||||
memcpy(this->pstr, BT_PSTR, PSTR_LENGTH);
|
||||
memset(this->reserved, 0, RESERVED_LENGTH);
|
||||
// fast extension
|
||||
this->reserved[7] |= 0x04;
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
*/
|
||||
/* copyright --> */
|
||||
#include "BtRequestMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
*/
|
||||
/* copyright --> */
|
||||
#include "BtSuggestPieceMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "CancelMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
CancelMessage* CancelMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 13) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "cancel", dataLength, 13);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "cancel", ID);
|
||||
}
|
||||
CancelMessage* cancelMessage = new CancelMessage();
|
||||
cancelMessage->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
cancelMessage->setBegin(PeerMessageUtil::getIntParam(data, 5));
|
||||
cancelMessage->setLength(PeerMessageUtil::getIntParam(data, 9));
|
||||
return cancelMessage;
|
||||
}
|
||||
|
||||
void CancelMessage::receivedAction() {
|
||||
peerInteraction->rejectPieceMessageInQueue(index, begin, length);
|
||||
}
|
||||
|
||||
const char* CancelMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 13, 4bytes
|
||||
* id --- 8, 1byte
|
||||
* index --- index, 4bytes
|
||||
* begin --- begin, 4bytes
|
||||
* length -- length, 4bytes
|
||||
* total: 17bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 13, ID);
|
||||
PeerMessageUtil::setIntParam(&msg[5], index);
|
||||
PeerMessageUtil::setIntParam(&msg[9], begin);
|
||||
PeerMessageUtil::setIntParam(&msg[13], length);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int CancelMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void CancelMessage::check() const {
|
||||
PeerMessageUtil::checkIndex(index, pieces);
|
||||
PeerMessageUtil::checkBegin(begin, pieceLength);
|
||||
PeerMessageUtil::checkLength(length);
|
||||
PeerMessageUtil::checkRange(begin, length, pieceLength);
|
||||
}
|
||||
|
||||
string CancelMessage::toString() const {
|
||||
return "cancel index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||
", length="+Util::itos(length);
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_CANCEL_MESSAGE_H_
|
||||
#define _D_CANCEL_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class CancelMessage : public SimplePeerMessage {
|
||||
private:
|
||||
int index;
|
||||
int begin;
|
||||
int length;
|
||||
// for check
|
||||
int pieces;
|
||||
int pieceLength;
|
||||
|
||||
char msg[17];
|
||||
public:
|
||||
CancelMessage(int index = 0, int begin = 0, int length = 0)
|
||||
:SimplePeerMessage(),
|
||||
index(index),
|
||||
begin(begin),
|
||||
length(length),
|
||||
pieces(0),
|
||||
pieceLength(0) {}
|
||||
|
||||
virtual ~CancelMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 8
|
||||
};
|
||||
|
||||
int getIndex() const { return index; }
|
||||
void setIndex(int index) { this->index = index; }
|
||||
int getBegin() const { return begin; }
|
||||
void setBegin(int begin) { this->begin = begin; }
|
||||
int getLength() const { return length; }
|
||||
void setLength(int length) { this->length = length; }
|
||||
|
||||
void setPieces(int pieces) {
|
||||
this->pieces = pieces;
|
||||
}
|
||||
int getPieces() const { return pieces;}
|
||||
|
||||
void setPieceLength(int pieceLength) {
|
||||
this->pieceLength = pieceLength;
|
||||
}
|
||||
int getPieceLength() const { return pieceLength;}
|
||||
|
||||
static CancelMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual void check() const;
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
||||
#endif // _D_CANCEL_MESSAGE_H_
|
|
@ -1,86 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "ChokeMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "message.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
ChokeMessage* ChokeMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "choke", dataLength, 1);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "choke", ID);
|
||||
}
|
||||
ChokeMessage* chokeMessage = new ChokeMessage();
|
||||
return chokeMessage;
|
||||
}
|
||||
|
||||
void ChokeMessage::receivedAction() {
|
||||
peer->peerChoking = true;
|
||||
peerInteraction->onChoked();
|
||||
}
|
||||
|
||||
bool ChokeMessage::sendPredicate() const {
|
||||
return !peer->amChoking;
|
||||
}
|
||||
|
||||
const char* ChokeMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 1, 4bytes
|
||||
* id --- 0, 1byte
|
||||
* total: 5bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, ID);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int ChokeMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void ChokeMessage::onSendComplete() {
|
||||
peer->amChoking = true;
|
||||
peerInteraction->rejectAllPieceMessageInQueue();
|
||||
}
|
||||
|
||||
string ChokeMessage::toString() const {
|
||||
return "choke";
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_CHOKE_MESSAGE_H_
|
||||
#define _D_CHOKE_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class ChokeMessage : public SimplePeerMessage {
|
||||
private:
|
||||
char msg[5];
|
||||
protected:
|
||||
virtual bool sendPredicate() const;
|
||||
virtual void onSendComplete();
|
||||
public:
|
||||
ChokeMessage():SimplePeerMessage() {}
|
||||
virtual ~ChokeMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 0
|
||||
};
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual string toString() const;
|
||||
|
||||
static ChokeMessage* create(const char* data, int dataLength);
|
||||
};
|
||||
|
||||
#endif // _D_CHOKE_MESSAGE_H_
|
|
@ -1,100 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "HandshakeMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
|
||||
HandshakeMessage::HandshakeMessage() {
|
||||
init();
|
||||
}
|
||||
|
||||
HandshakeMessage::HandshakeMessage(const unsigned char* infoHash,
|
||||
const char* peerId)
|
||||
{
|
||||
init();
|
||||
memcpy(this->infoHash, infoHash, INFO_HASH_LENGTH);
|
||||
memcpy(this->peerId, peerId, PEER_ID_LENGTH);
|
||||
}
|
||||
|
||||
void HandshakeMessage::init() {
|
||||
this->pstrlen = 19;
|
||||
this->pstr = PSTR;
|
||||
memset(this->reserved, 0, sizeof(this->reserved));
|
||||
// fast extension
|
||||
this->reserved[7] |= 0x04;
|
||||
}
|
||||
|
||||
HandshakeMessage* HandshakeMessage::create(const char* data, int dataLength) {
|
||||
HandshakeMessage* message = new HandshakeMessage();
|
||||
message->pstrlen = data[0];
|
||||
char pstrTemp[20];
|
||||
memcpy(pstrTemp, &data[1], sizeof(pstrTemp)-1);
|
||||
pstrTemp[sizeof(pstrTemp)-1] = '\0';
|
||||
message->pstr = pstrTemp;
|
||||
memcpy(message->reserved, &data[20], 8);
|
||||
memcpy(message->infoHash, &data[28], 20);
|
||||
memcpy(message->peerId, &data[48], 20);
|
||||
return message;
|
||||
}
|
||||
|
||||
const char* HandshakeMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
msg[0] = pstrlen;
|
||||
memcpy(msg+1, pstr.c_str(), pstr.size());
|
||||
memcpy(msg+20, reserved, 8);
|
||||
memcpy(msg+28, infoHash, 20);
|
||||
memcpy(msg+48, peerId, 20);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int HandshakeMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
string HandshakeMessage::toString() const {
|
||||
return "handshake peerId="+
|
||||
Util::urlencode((unsigned char*)peerId, sizeof(peerId))+
|
||||
" reserved="+Util::toHex(reserved, sizeof(reserved));
|
||||
}
|
||||
|
||||
void HandshakeMessage::check() const {
|
||||
PeerMessageUtil::checkHandshake(this, btContext->getInfoHash());
|
||||
}
|
||||
|
||||
bool HandshakeMessage::isFastExtensionSupported() const {
|
||||
return reserved[7]&0x04;
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_HANDSHAKE_MESSAGE_H_
|
||||
#define _D_HANDSHAKE_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
#define PSTR "BitTorrent protocol"
|
||||
#define HANDSHAKE_MESSAGE_LENGTH 68
|
||||
|
||||
class HandshakeMessage : public SimplePeerMessage {
|
||||
private:
|
||||
char msg[HANDSHAKE_MESSAGE_LENGTH];
|
||||
void init();
|
||||
public:
|
||||
char pstrlen;
|
||||
string pstr;
|
||||
unsigned char reserved[8];
|
||||
unsigned char infoHash[INFO_HASH_LENGTH];
|
||||
char peerId[PEER_ID_LENGTH];
|
||||
public:
|
||||
HandshakeMessage();
|
||||
HandshakeMessage(const unsigned char* infoHash, const char* peerId);
|
||||
|
||||
static HandshakeMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual ~HandshakeMessage() {}
|
||||
|
||||
virtual int getId() const { return 999; }
|
||||
virtual void receivedAction() {};
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual void check() const;
|
||||
virtual string toString() const;
|
||||
|
||||
bool isFastExtensionSupported() const;
|
||||
};
|
||||
|
||||
#endif // _D_HANDSHAKE_MESSAGE_H_
|
|
@ -1,85 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "HaveAllMessage.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
|
||||
HaveAllMessage::HaveAllMessage() {}
|
||||
|
||||
HaveAllMessage::~HaveAllMessage() {}
|
||||
|
||||
HaveAllMessage* HaveAllMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "have all", dataLength, 1);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "have all", ID);
|
||||
}
|
||||
HaveAllMessage* haveAllMessage = new HaveAllMessage();
|
||||
return haveAllMessage;
|
||||
}
|
||||
|
||||
void HaveAllMessage::receivedAction() {
|
||||
if(!peer->isFastExtensionEnabled()) {
|
||||
throw new DlAbortEx("%s received while fast extension is disabled",
|
||||
toString().c_str());
|
||||
}
|
||||
peer->setAllBitfield();
|
||||
}
|
||||
|
||||
const char* HaveAllMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 1, 4bytes
|
||||
* id --- 14, 1byte
|
||||
* total: 5bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, ID);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int HaveAllMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void HaveAllMessage::check() const {}
|
||||
|
||||
string HaveAllMessage::toString() const {
|
||||
return "have all";
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_HAVE_ALL_MESSAGE_H_
|
||||
#define _D_HAVE_ALL_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class HaveAllMessage : public SimplePeerMessage {
|
||||
private:
|
||||
char msg[5];
|
||||
public:
|
||||
HaveAllMessage();
|
||||
virtual ~HaveAllMessage();
|
||||
|
||||
enum ID_t {
|
||||
ID = 14
|
||||
};
|
||||
|
||||
static HaveAllMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual void check() const;
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
||||
#endif // _D_HAVE_ALL_MESSAGE_H_
|
|
@ -1,87 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "HaveMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
HaveMessage* HaveMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 5) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "have", dataLength, 5);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "have", ID);
|
||||
}
|
||||
HaveMessage* haveMessage = new HaveMessage();
|
||||
haveMessage->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
return haveMessage;
|
||||
}
|
||||
|
||||
void HaveMessage::receivedAction() {
|
||||
peer->updateBitfield(index, 1);
|
||||
}
|
||||
|
||||
bool HaveMessage::sendPredicate() const {
|
||||
return !peer->hasPiece(index);
|
||||
}
|
||||
|
||||
const char* HaveMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 5, 4bytes
|
||||
* id --- 4, 1byte
|
||||
* piece index --- index, 4bytes
|
||||
* total: 9bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, ID);
|
||||
PeerMessageUtil::setIntParam(&msg[5], index);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int HaveMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void HaveMessage::check() const {
|
||||
PeerMessageUtil::checkIndex(index, pieces);
|
||||
}
|
||||
|
||||
string HaveMessage::toString() const {
|
||||
return "have index="+Util::itos(index);
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_HAVE_MESSAGE_H_
|
||||
#define _D_HAVE_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class HaveMessage : public SimplePeerMessage {
|
||||
private:
|
||||
int index;
|
||||
// for check
|
||||
int pieces;
|
||||
char msg[9];
|
||||
protected:
|
||||
virtual bool sendPredicate() const;
|
||||
public:
|
||||
HaveMessage(int index = 0)
|
||||
:SimplePeerMessage(),
|
||||
index(index),
|
||||
pieces(0) {}
|
||||
|
||||
virtual ~HaveMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 4
|
||||
};
|
||||
|
||||
void setIndex(int index) {
|
||||
this->index = index;
|
||||
}
|
||||
int getIndex() const { return index; }
|
||||
|
||||
void setPieces(int pieces) {
|
||||
this->pieces = pieces;
|
||||
}
|
||||
int getPieces() const { return pieces;}
|
||||
|
||||
static HaveMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual void check() const;
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
||||
#endif // _D_HAVE_MESSAGE_H_
|
|
@ -1,84 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "HaveNoneMessage.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
|
||||
HaveNoneMessage::HaveNoneMessage() {}
|
||||
|
||||
HaveNoneMessage::~HaveNoneMessage() {}
|
||||
|
||||
HaveNoneMessage* HaveNoneMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "have none", dataLength, 1);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "have none", ID);
|
||||
}
|
||||
HaveNoneMessage* haveNoneMessage = new HaveNoneMessage();
|
||||
return haveNoneMessage;
|
||||
}
|
||||
|
||||
void HaveNoneMessage::receivedAction() {
|
||||
if(!peer->isFastExtensionEnabled()) {
|
||||
throw new DlAbortEx("%s received while fast extension is disabled",
|
||||
toString().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
const char* HaveNoneMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 1, 4bytes
|
||||
* id --- 15, 1byte
|
||||
* total: 5bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, ID);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int HaveNoneMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void HaveNoneMessage::check() const {}
|
||||
|
||||
string HaveNoneMessage::toString() const {
|
||||
return "have none";
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_HAVE_NONE_MESSAGE_H_
|
||||
#define _D_HAVE_NONE_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class HaveNoneMessage : public SimplePeerMessage {
|
||||
private:
|
||||
char msg[5];
|
||||
public:
|
||||
HaveNoneMessage();
|
||||
virtual ~HaveNoneMessage();
|
||||
|
||||
enum ID_t {
|
||||
ID = 15
|
||||
};
|
||||
|
||||
static HaveNoneMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual void check() const;
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
||||
#endif // _D_HAVE_NONE_MESSAGE_H_
|
|
@ -1,83 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "InterestedMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
InterestedMessage* InterestedMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "interested", dataLength, 1);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "interested", ID);
|
||||
}
|
||||
InterestedMessage* interestedMessage = new InterestedMessage();
|
||||
return interestedMessage;
|
||||
}
|
||||
|
||||
void InterestedMessage::receivedAction() {
|
||||
peer->peerInterested = true;
|
||||
}
|
||||
|
||||
bool InterestedMessage::sendPredicate() const {
|
||||
return !peer->amInterested;
|
||||
}
|
||||
|
||||
const char* InterestedMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 1, 4bytes
|
||||
* id --- 2, 1byte
|
||||
* total: 5bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, ID);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int InterestedMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void InterestedMessage::onSendComplete() {
|
||||
peer->amInterested = true;
|
||||
}
|
||||
|
||||
string InterestedMessage::toString() const {
|
||||
return "interested";
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_INTERESTED_MESSAGE_H_
|
||||
#define _D_INTERESTED_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class InterestedMessage : public SimplePeerMessage {
|
||||
private:
|
||||
char msg[5];
|
||||
protected:
|
||||
virtual bool sendPredicate() const;
|
||||
virtual void onSendComplete();
|
||||
public:
|
||||
InterestedMessage():SimplePeerMessage() {}
|
||||
virtual ~InterestedMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 2
|
||||
};
|
||||
|
||||
static InterestedMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
||||
#endif // _D_INTERESTED_MESSAGE_H_
|
|
@ -1,51 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "KeepAliveMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
|
||||
const char* KeepAliveMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 0, 4bytes
|
||||
* total: 4bytes
|
||||
*/
|
||||
memset(msg, 0, sizeof(msg));
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int KeepAliveMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_KEEP_ALIVE_MESSAGE_H_
|
||||
#define _D_KEEP_ALIVE_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class KeepAliveMessage : public SimplePeerMessage {
|
||||
private:
|
||||
char msg[4];
|
||||
public:
|
||||
KeepAliveMessage():SimplePeerMessage() {}
|
||||
virtual ~KeepAliveMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 99
|
||||
};
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction() {}
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual string toString() const {
|
||||
return "keep alive";
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _D_KEEP_ALIVE_MESSAGE_H_
|
|
@ -83,14 +83,11 @@ SRCS += MetaEntry.h\
|
|||
TorrentDownloadEngine.cc TorrentDownloadEngine.h\
|
||||
TorrentConsoleDownloadEngine.cc TorrentConsoleDownloadEngine.h\
|
||||
PeerListenCommand.cc PeerListenCommand.h\
|
||||
PeerMessage.cc PeerMessage.h\
|
||||
HandshakeMessage.cc HandshakeMessage.h\
|
||||
Piece.cc Piece.h\
|
||||
RequestSlot.cc RequestSlot.h\
|
||||
TorrentAutoSaveCommand.cc TorrentAutoSaveCommand.h\
|
||||
Directory.cc Directory.h\
|
||||
TrackerWatcherCommand.cc TrackerWatcherCommand.h\
|
||||
PeerInteraction.cc PeerInteraction.h\
|
||||
MultiDiskWriter.cc MultiDiskWriter.h\
|
||||
DiskAdaptor.cc DiskAdaptor.h\
|
||||
CopyDiskAdaptor.cc CopyDiskAdaptor.h\
|
||||
|
@ -100,24 +97,6 @@ SRCS += MetaEntry.h\
|
|||
TrackerUpdateCommand.cc TrackerUpdateCommand.h\
|
||||
ByteArrayDiskWriter.cc ByteArrayDiskWriter.h\
|
||||
PeerChokeCommand.cc PeerChokeCommand.h\
|
||||
ChokeMessage.cc ChokeMessage.h\
|
||||
UnchokeMessage.cc UnchokeMessage.h\
|
||||
InterestedMessage.cc InterestedMessage.h\
|
||||
NotInterestedMessage.cc NotInterestedMessage.h\
|
||||
HaveMessage.cc HaveMessage.h\
|
||||
BitfieldMessage.cc BitfieldMessage.h\
|
||||
RequestMessage.cc RequestMessage.h\
|
||||
PieceMessage.cc PieceMessage.h\
|
||||
CancelMessage.cc CancelMessage.h\
|
||||
KeepAliveMessage.cc KeepAliveMessage.h\
|
||||
PortMessage.cc PortMessage.h\
|
||||
HaveAllMessage.cc HaveAllMessage.h\
|
||||
HaveNoneMessage.cc HaveNoneMessage.h\
|
||||
RejectMessage.cc RejectMessage.h\
|
||||
AllowedFastMessage.cc AllowedFastMessage.h\
|
||||
SuggestPieceMessage.cc SuggestPieceMessage.h\
|
||||
SimplePeerMessage.cc SimplePeerMessage.h\
|
||||
PeerMessageFactory.cc PeerMessageFactory.h\
|
||||
HaveEraseCommand.cc HaveEraseCommand.h\
|
||||
TorrentRequestInfo.cc TorrentRequestInfo.h\
|
||||
SeedCriteria.h\
|
||||
|
@ -135,7 +114,6 @@ SRCS += MetaEntry.h\
|
|||
DefaultBtContext.cc DefaultBtContext.h\
|
||||
PieceStorage.h\
|
||||
DefaultPieceStorage.cc DefaultPieceStorage.h\
|
||||
PeerService.h\
|
||||
DefaultPeerStorage.cc DefaultPeerStorage.h\
|
||||
BtAnnounce.h\
|
||||
DefaultBtAnnounce.cc DefaultBtAnnounce.h\
|
||||
|
|
141
src/Makefile.in
141
src/Makefile.in
|
@ -38,6 +38,7 @@ POST_UNINSTALL = :
|
|||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
bin_PROGRAMS = aria2c$(EXEEXT)
|
||||
# debug_new.cpp
|
||||
@ENABLE_ASYNC_DNS_TRUE@am__append_1 = NameResolver.cc NameResolver.h
|
||||
@ENABLE_BITTORRENT_TRUE@am__append_2 = MetaEntry.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ Data.cc Data.h\
|
||||
|
@ -55,14 +56,11 @@ bin_PROGRAMS = aria2c$(EXEEXT)
|
|||
@ENABLE_BITTORRENT_TRUE@ TorrentDownloadEngine.cc TorrentDownloadEngine.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ TorrentConsoleDownloadEngine.cc TorrentConsoleDownloadEngine.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerListenCommand.cc PeerListenCommand.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerMessage.cc PeerMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ HandshakeMessage.cc HandshakeMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ Piece.cc Piece.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ RequestSlot.cc RequestSlot.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ TorrentAutoSaveCommand.cc TorrentAutoSaveCommand.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ Directory.cc Directory.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ TrackerWatcherCommand.cc TrackerWatcherCommand.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerInteraction.cc PeerInteraction.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ MultiDiskWriter.cc MultiDiskWriter.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ DiskAdaptor.cc DiskAdaptor.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ CopyDiskAdaptor.cc CopyDiskAdaptor.h\
|
||||
|
@ -72,24 +70,6 @@ bin_PROGRAMS = aria2c$(EXEEXT)
|
|||
@ENABLE_BITTORRENT_TRUE@ TrackerUpdateCommand.cc TrackerUpdateCommand.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ ByteArrayDiskWriter.cc ByteArrayDiskWriter.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerChokeCommand.cc PeerChokeCommand.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ ChokeMessage.cc ChokeMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ UnchokeMessage.cc UnchokeMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ InterestedMessage.cc InterestedMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ NotInterestedMessage.cc NotInterestedMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ HaveMessage.cc HaveMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ BitfieldMessage.cc BitfieldMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ RequestMessage.cc RequestMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PieceMessage.cc PieceMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ CancelMessage.cc CancelMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ KeepAliveMessage.cc KeepAliveMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PortMessage.cc PortMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ HaveAllMessage.cc HaveAllMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ HaveNoneMessage.cc HaveNoneMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ RejectMessage.cc RejectMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ AllowedFastMessage.cc AllowedFastMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ SuggestPieceMessage.cc SuggestPieceMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ SimplePeerMessage.cc SimplePeerMessage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerMessageFactory.cc PeerMessageFactory.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ HaveEraseCommand.cc HaveEraseCommand.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ TorrentRequestInfo.cc TorrentRequestInfo.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ SeedCriteria.h\
|
||||
|
@ -107,7 +87,6 @@ bin_PROGRAMS = aria2c$(EXEEXT)
|
|||
@ENABLE_BITTORRENT_TRUE@ DefaultBtContext.cc DefaultBtContext.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PieceStorage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ DefaultPieceStorage.cc DefaultPieceStorage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerService.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ DefaultPeerStorage.cc DefaultPeerStorage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ BtAnnounce.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ DefaultBtAnnounce.cc DefaultBtAnnounce.h\
|
||||
|
@ -231,44 +210,29 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
|||
UrlRequestInfo.h SpeedCalc.cc SpeedCalc.h PeerStat.h \
|
||||
BitfieldMan.cc BitfieldMan.h BitfieldManFactory.cc \
|
||||
BitfieldManFactory.h Randomizer.h SimpleRandomizer.cc \
|
||||
SimpleRandomizer.h debug_new.cpp NameResolver.cc \
|
||||
NameResolver.h MetaEntry.h Data.cc Data.h Dictionary.cc \
|
||||
Dictionary.h List.cc List.h MetaFileUtil.cc MetaFileUtil.h \
|
||||
MetaEntryVisitor.h ShaVisitor.cc ShaVisitor.h \
|
||||
PeerConnection.cc PeerConnection.h PeerMessageUtil.cc \
|
||||
PeerMessageUtil.h PeerAbstractCommand.cc PeerAbstractCommand.h \
|
||||
PeerInitiateConnectionCommand.cc \
|
||||
SimpleRandomizer.h NameResolver.cc NameResolver.h MetaEntry.h \
|
||||
Data.cc Data.h Dictionary.cc Dictionary.h List.cc List.h \
|
||||
MetaFileUtil.cc MetaFileUtil.h MetaEntryVisitor.h \
|
||||
ShaVisitor.cc ShaVisitor.h PeerConnection.cc PeerConnection.h \
|
||||
PeerMessageUtil.cc PeerMessageUtil.h PeerAbstractCommand.cc \
|
||||
PeerAbstractCommand.h PeerInitiateConnectionCommand.cc \
|
||||
PeerInitiateConnectionCommand.h PeerInteractionCommand.cc \
|
||||
PeerInteractionCommand.h Peer.cc Peer.h \
|
||||
TorrentDownloadEngine.cc TorrentDownloadEngine.h \
|
||||
TorrentConsoleDownloadEngine.cc TorrentConsoleDownloadEngine.h \
|
||||
PeerListenCommand.cc PeerListenCommand.h PeerMessage.cc \
|
||||
PeerMessage.h HandshakeMessage.cc HandshakeMessage.h Piece.cc \
|
||||
Piece.h RequestSlot.cc RequestSlot.h TorrentAutoSaveCommand.cc \
|
||||
PeerListenCommand.cc PeerListenCommand.h Piece.cc Piece.h \
|
||||
RequestSlot.cc RequestSlot.h TorrentAutoSaveCommand.cc \
|
||||
TorrentAutoSaveCommand.h Directory.cc Directory.h \
|
||||
TrackerWatcherCommand.cc TrackerWatcherCommand.h \
|
||||
PeerInteraction.cc PeerInteraction.h MultiDiskWriter.cc \
|
||||
MultiDiskWriter.h DiskAdaptor.cc DiskAdaptor.h \
|
||||
CopyDiskAdaptor.cc CopyDiskAdaptor.h DirectDiskAdaptor.cc \
|
||||
DirectDiskAdaptor.h MultiDiskAdaptor.cc MultiDiskAdaptor.h \
|
||||
FileEntry.cc FileEntry.h TrackerUpdateCommand.cc \
|
||||
TrackerUpdateCommand.h ByteArrayDiskWriter.cc \
|
||||
ByteArrayDiskWriter.h PeerChokeCommand.cc PeerChokeCommand.h \
|
||||
ChokeMessage.cc ChokeMessage.h UnchokeMessage.cc \
|
||||
UnchokeMessage.h InterestedMessage.cc InterestedMessage.h \
|
||||
NotInterestedMessage.cc NotInterestedMessage.h HaveMessage.cc \
|
||||
HaveMessage.h BitfieldMessage.cc BitfieldMessage.h \
|
||||
RequestMessage.cc RequestMessage.h PieceMessage.cc \
|
||||
PieceMessage.h CancelMessage.cc CancelMessage.h \
|
||||
KeepAliveMessage.cc KeepAliveMessage.h PortMessage.cc \
|
||||
PortMessage.h HaveAllMessage.cc HaveAllMessage.h \
|
||||
HaveNoneMessage.cc HaveNoneMessage.h RejectMessage.cc \
|
||||
RejectMessage.h AllowedFastMessage.cc AllowedFastMessage.h \
|
||||
SuggestPieceMessage.cc SuggestPieceMessage.h \
|
||||
SimplePeerMessage.cc SimplePeerMessage.h PeerMessageFactory.cc \
|
||||
PeerMessageFactory.h HaveEraseCommand.cc HaveEraseCommand.h \
|
||||
TorrentRequestInfo.cc TorrentRequestInfo.h SeedCriteria.h \
|
||||
TimeSeedCriteria.h ShareRatioSeedCriteria.h \
|
||||
MultiDiskWriter.cc MultiDiskWriter.h DiskAdaptor.cc \
|
||||
DiskAdaptor.h CopyDiskAdaptor.cc CopyDiskAdaptor.h \
|
||||
DirectDiskAdaptor.cc DirectDiskAdaptor.h MultiDiskAdaptor.cc \
|
||||
MultiDiskAdaptor.h FileEntry.cc FileEntry.h \
|
||||
TrackerUpdateCommand.cc TrackerUpdateCommand.h \
|
||||
ByteArrayDiskWriter.cc ByteArrayDiskWriter.h \
|
||||
PeerChokeCommand.cc PeerChokeCommand.h HaveEraseCommand.cc \
|
||||
HaveEraseCommand.h TorrentRequestInfo.cc TorrentRequestInfo.h \
|
||||
SeedCriteria.h TimeSeedCriteria.h ShareRatioSeedCriteria.h \
|
||||
UnionSeedCriteria.h SeedCheckCommand.cc SeedCheckCommand.h \
|
||||
PeerListProcessor.h DefaultPeerListProcessor.cc \
|
||||
DefaultPeerListProcessor.h CompactPeerListProcessor.cc \
|
||||
|
@ -276,7 +240,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
|||
DelegatingPeerListProcessor.h AnnounceTier.h AnnounceList.h \
|
||||
AnnounceList.cc BtContext.h DefaultBtContext.cc \
|
||||
DefaultBtContext.h PieceStorage.h DefaultPieceStorage.cc \
|
||||
DefaultPieceStorage.h PeerService.h DefaultPeerStorage.cc \
|
||||
DefaultPieceStorage.h DefaultPeerStorage.cc \
|
||||
DefaultPeerStorage.h BtAnnounce.h DefaultBtAnnounce.cc \
|
||||
DefaultBtAnnounce.h BtRegistry.cc BtRegistry.h BtRuntime.h \
|
||||
BtProgressInfoFile.h DefaultBtProgressInfoFile.cc \
|
||||
|
@ -329,13 +293,10 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
|||
@ENABLE_BITTORRENT_TRUE@ TorrentDownloadEngine.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ TorrentConsoleDownloadEngine.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerListenCommand.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ HandshakeMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ Piece.$(OBJEXT) RequestSlot.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ TorrentAutoSaveCommand.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ Directory.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ TrackerWatcherCommand.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerInteraction.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ MultiDiskWriter.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ DiskAdaptor.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ CopyDiskAdaptor.$(OBJEXT) \
|
||||
|
@ -345,24 +306,6 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
|||
@ENABLE_BITTORRENT_TRUE@ TrackerUpdateCommand.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ ByteArrayDiskWriter.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerChokeCommand.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ ChokeMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ UnchokeMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ InterestedMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ NotInterestedMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ HaveMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ BitfieldMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ RequestMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PieceMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ CancelMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ KeepAliveMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PortMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ HaveAllMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ HaveNoneMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ RejectMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ AllowedFastMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ SuggestPieceMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ SimplePeerMessage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerMessageFactory.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ HaveEraseCommand.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ TorrentRequestInfo.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ SeedCheckCommand.$(OBJEXT) \
|
||||
|
@ -429,8 +372,8 @@ am__objects_4 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
|
|||
FeatureConfig.$(OBJEXT) DownloadEngineFactory.$(OBJEXT) \
|
||||
UrlRequestInfo.$(OBJEXT) SpeedCalc.$(OBJEXT) \
|
||||
BitfieldMan.$(OBJEXT) BitfieldManFactory.$(OBJEXT) \
|
||||
SimpleRandomizer.$(OBJEXT) debug_new.$(OBJEXT) \
|
||||
$(am__objects_1) $(am__objects_2) $(am__objects_3)
|
||||
SimpleRandomizer.$(OBJEXT) $(am__objects_1) $(am__objects_2) \
|
||||
$(am__objects_3)
|
||||
am_libaria2c_a_OBJECTS = $(am__objects_4)
|
||||
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
|
||||
am__installdirs = "$(DESTDIR)$(bindir)"
|
||||
|
@ -634,8 +577,8 @@ SRCS = Socket.h SocketCore.cc SocketCore.h Command.cc Command.h \
|
|||
UrlRequestInfo.h SpeedCalc.cc SpeedCalc.h PeerStat.h \
|
||||
BitfieldMan.cc BitfieldMan.h BitfieldManFactory.cc \
|
||||
BitfieldManFactory.h Randomizer.h SimpleRandomizer.cc \
|
||||
SimpleRandomizer.h debug_new.cpp $(am__append_1) \
|
||||
$(am__append_2) $(am__append_3)
|
||||
SimpleRandomizer.h $(am__append_1) $(am__append_2) \
|
||||
$(am__append_3)
|
||||
noinst_LIBRARIES = libaria2c.a
|
||||
libaria2c_a_SOURCES = $(SRCS)
|
||||
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
|
||||
|
@ -652,7 +595,7 @@ AM_CPPFLAGS = -Wall\
|
|||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .cc .cpp .o .obj
|
||||
.SUFFIXES: .cc .o .obj
|
||||
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
|
@ -725,12 +668,10 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/alloca.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractDiskWriter.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AllowedFastMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AnnounceList.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldMan.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldManFactory.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtAllowedFastMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtBitfieldMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtCancelMessage.Po@am__quote@
|
||||
|
@ -751,8 +692,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtSuggestPieceMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtUnchokeMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ByteArrayDiskWriter.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CancelMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChokeMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChunkedEncoding.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Command.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CompactPeerListProcessor.Po@am__quote@
|
||||
|
@ -789,11 +728,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FtpNegotiationCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FtpTunnelRequestCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FtpTunnelResponseCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HandshakeMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HaveAllMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HaveEraseCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HaveMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HaveNoneMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HttpConnection.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HttpDownloadCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HttpHeader.Po@am__quote@
|
||||
|
@ -803,8 +738,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HttpRequestCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HttpResponseCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/InitiateConnectionCommandFactory.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/InterestedMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/KeepAliveMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/List.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LogFactory.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MetaFileUtil.Po@am__quote@
|
||||
|
@ -815,26 +748,18 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MultiDiskAdaptor.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MultiDiskWriter.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NameResolver.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NotInterestedMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Option.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Peer.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerAbstractCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerChokeCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerConnection.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerInitiateConnectionCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerInteraction.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerInteractionCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerListenCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerMessageFactory.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerMessageUtil.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Piece.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PieceMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PortMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PreAllocationDiskWriter.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RejectMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Request.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestSlot.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SeedCheckCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Segment.Po@am__quote@
|
||||
|
@ -842,12 +767,10 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ShaVisitor.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleBtMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleLogger.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimplePeerMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SimpleRandomizer.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SleepCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SocketCore.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SpeedCalc.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SuggestPieceMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TimeA2.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentAutoSaveCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentConsoleDownloadEngine.Po@am__quote@
|
||||
|
@ -855,11 +778,9 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TorrentRequestInfo.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TrackerUpdateCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/TrackerWatcherCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UnchokeMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UrlRequestInfo.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Util.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Xml2MetalinkProcessor.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/debug_new.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
|
||||
|
||||
.cc.o:
|
||||
|
@ -875,20 +796,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
|
||||
.cpp.o:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
|
||||
|
||||
.cpp.obj:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
uninstall-info-am:
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "NotInterestedMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
NotInterestedMessage* NotInterestedMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "not interested", dataLength, 1);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "not interested", ID);
|
||||
}
|
||||
NotInterestedMessage* notInterestedMessage = new NotInterestedMessage();
|
||||
return notInterestedMessage;
|
||||
}
|
||||
|
||||
void NotInterestedMessage::receivedAction() {
|
||||
peer->peerInterested = false;
|
||||
}
|
||||
|
||||
bool NotInterestedMessage::sendPredicate() const {
|
||||
return peer->amInterested;
|
||||
}
|
||||
|
||||
const char* NotInterestedMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 1, 4bytes
|
||||
* id --- 3, 1byte
|
||||
* total: 5bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, ID);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int NotInterestedMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void NotInterestedMessage::onSendComplete() {
|
||||
peer->amInterested = false;
|
||||
}
|
||||
|
||||
string NotInterestedMessage::toString() const {
|
||||
return "not interested";
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_NOT_INTERESTED_MESSAGE_H_
|
||||
#define _D_NOT_INTERESTED_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class NotInterestedMessage : public SimplePeerMessage {
|
||||
private:
|
||||
char msg[5];
|
||||
protected:
|
||||
virtual bool sendPredicate() const;
|
||||
virtual void onSendComplete();
|
||||
public:
|
||||
NotInterestedMessage():SimplePeerMessage() {}
|
||||
virtual ~NotInterestedMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 3
|
||||
};
|
||||
|
||||
static NotInterestedMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
||||
#endif // _D_NOT_INTERESTED_MESSAGE_H_
|
|
@ -1,453 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "PeerInteraction.h"
|
||||
#include "LogFactory.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "KeepAliveMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "prefs.h"
|
||||
#include "BtRegistry.h"
|
||||
#include <netinet/in.h>
|
||||
|
||||
PeerInteraction::PeerInteraction(int cuid,
|
||||
const PeerHandle& peer,
|
||||
const SocketHandle& socket,
|
||||
const Option* op,
|
||||
const BtContextHandle& btContext)
|
||||
:cuid(cuid),
|
||||
option(op),
|
||||
btContext(btContext),
|
||||
peerStorage(PEER_STORAGE(btContext)),
|
||||
pieceStorage(PIECE_STORAGE(btContext)),
|
||||
btAnnounce(BT_ANNOUNCE(btContext)),
|
||||
peer(peer),
|
||||
quickReplied(false) {
|
||||
peerConnection = new PeerConnection(cuid, socket, op);
|
||||
peerMessageFactory = new PeerMessageFactory(cuid, btContext, this, peer);
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
||||
|
||||
PeerInteraction::~PeerInteraction() {
|
||||
delete peerConnection;
|
||||
delete peerMessageFactory;
|
||||
}
|
||||
|
||||
bool PeerInteraction::isSendingMessageInProgress() const {
|
||||
if(messageQueue.size() > 0) {
|
||||
const PeerMessageHandle& peerMessage = messageQueue.front();
|
||||
if(peerMessage->isInProgress()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PeerInteraction::sendMessages() {
|
||||
MessageQueue tempQueue;
|
||||
int uploadLimit = option->getAsInt(PREF_MAX_UPLOAD_LIMIT);
|
||||
while(messageQueue.size() > 0) {
|
||||
PeerMessageHandle msg = messageQueue.front();
|
||||
messageQueue.pop_front();
|
||||
if(uploadLimit > 0) {
|
||||
TransferStat stat = peerStorage->calculateStat();
|
||||
if(uploadLimit < stat.uploadSpeed &&
|
||||
msg->isUploading() && !msg->isInProgress()) {
|
||||
tempQueue.push_back(msg);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
msg->send();
|
||||
if(msg->isInProgress()) {
|
||||
messageQueue.push_front(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
copy(tempQueue.begin(), tempQueue.end(), back_inserter(messageQueue));
|
||||
}
|
||||
|
||||
void PeerInteraction::addMessage(const PeerMessageHandle& peerMessage) {
|
||||
peerMessage->onPush();
|
||||
messageQueue.push_back(peerMessage);
|
||||
}
|
||||
|
||||
void PeerInteraction::addRequestSlot(const RequestSlot& requestSlot) {
|
||||
requestSlots.push_back(requestSlot);
|
||||
}
|
||||
|
||||
void PeerInteraction::rejectAllPieceMessageInQueue() {
|
||||
int size = messageQueue.size();
|
||||
for(int i = 0; i < size; i++) {
|
||||
messageQueue.at(i)->onChoked();
|
||||
}
|
||||
}
|
||||
|
||||
void PeerInteraction::rejectPieceMessageInQueue(int index, int begin, int length) {
|
||||
int size = messageQueue.size();
|
||||
for(int i = 0; i < size; i++) {
|
||||
messageQueue.at(i)->onCanceled(index, begin, length);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerInteraction::onChoked() {
|
||||
for(Pieces::iterator itr = pieces.begin(); itr != pieces.end();) {
|
||||
PieceHandle& piece = *itr;
|
||||
if(!peer->isInFastSet(piece->getIndex())) {
|
||||
abortPiece(piece);
|
||||
itr = pieces.erase(itr);
|
||||
} else {
|
||||
itr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PeerInteraction::abortAllPieces() {
|
||||
for(Pieces::iterator itr = pieces.begin(); itr != pieces.end();) {
|
||||
abortPiece(*itr);
|
||||
itr = pieces.erase(itr);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerInteraction::abortPiece(const PieceHandle& piece) {
|
||||
if(!piece.isNull()) {
|
||||
int size = messageQueue.size();
|
||||
for(int i = 0; i < size; i++) {
|
||||
messageQueue.at(i)->onAbortPiece(piece);
|
||||
}
|
||||
for(RequestSlots::iterator itr = requestSlots.begin();
|
||||
itr != requestSlots.end();) {
|
||||
if(itr->getIndex() == piece->getIndex()) {
|
||||
logger->debug("CUID#%d - Deleting request slot blockIndex=%d"
|
||||
" because piece was canceled",
|
||||
cuid,
|
||||
itr->getBlockIndex());
|
||||
piece->cancelBlock(itr->getBlockIndex());
|
||||
itr = requestSlots.erase(itr);
|
||||
} else {
|
||||
itr++;
|
||||
}
|
||||
}
|
||||
pieceStorage->cancelPiece(piece);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PeerInteraction::deleteRequestSlot(const RequestSlot& requestSlot) {
|
||||
RequestSlots::iterator itr = find(requestSlots.begin(), requestSlots.end(),
|
||||
requestSlot);
|
||||
if(itr != requestSlots.end()) {
|
||||
requestSlots.erase(itr);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerInteraction::checkRequestSlot() {
|
||||
for(RequestSlots::iterator itr = requestSlots.begin();
|
||||
itr != requestSlots.end();) {
|
||||
RequestSlot& slot = *itr;
|
||||
if(slot.isTimeout(REQUEST_TIME_OUT)) {
|
||||
logger->debug("CUID#%d - Deleting request slot blockIndex=%d"
|
||||
" because of time out",
|
||||
cuid,
|
||||
slot.getBlockIndex());
|
||||
PieceHandle piece = getDownloadPiece(slot.getIndex());
|
||||
piece->cancelBlock(slot.getBlockIndex());
|
||||
itr = requestSlots.erase(itr);
|
||||
peer->snubbing = true;
|
||||
} else {
|
||||
PieceHandle piece = getDownloadPiece(slot.getIndex());
|
||||
if(piece->hasBlock(slot.getBlockIndex()) ||
|
||||
pieceStorage->hasPiece(piece->getIndex())) {
|
||||
logger->debug("CUID#%d - Deleting request slot blockIndex=%d because"
|
||||
" the block has been acquired.", cuid,
|
||||
slot.getBlockIndex());
|
||||
addMessage(peerMessageFactory->createCancelMessage(slot.getIndex(),
|
||||
slot.getBegin(),
|
||||
slot.getLength()));
|
||||
itr = requestSlots.erase(itr);
|
||||
} else {
|
||||
itr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
updatePiece();
|
||||
}
|
||||
|
||||
bool PeerInteraction::isInRequestSlot(int index, int blockIndex) const {
|
||||
for(RequestSlots::const_iterator itr = requestSlots.begin();
|
||||
itr != requestSlots.end(); itr++) {
|
||||
const RequestSlot& slot = *itr;
|
||||
if(slot.getIndex() == index && slot.getBlockIndex() == blockIndex) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RequestSlot PeerInteraction::getCorrespondingRequestSlot(int index,
|
||||
int begin,
|
||||
int length) const {
|
||||
for(RequestSlots::const_iterator itr = requestSlots.begin();
|
||||
itr != requestSlots.end(); itr++) {
|
||||
const RequestSlot& slot = *itr;
|
||||
if(slot.getIndex() == index &&
|
||||
slot.getBegin() == begin &&
|
||||
slot.getLength() == length) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return RequestSlot::nullSlot;
|
||||
}
|
||||
|
||||
int PeerInteraction::countMessageInQueue() const {
|
||||
return messageQueue.size();
|
||||
}
|
||||
|
||||
int PeerInteraction::countRequestSlot() const {
|
||||
return requestSlots.size();
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerInteraction::receiveHandshake(bool quickReply) {
|
||||
char msg[HANDSHAKE_MESSAGE_LENGTH];
|
||||
int msgLength = HANDSHAKE_MESSAGE_LENGTH;
|
||||
bool retval = peerConnection->receiveHandshake(msg, msgLength);
|
||||
// To handle tracker's NAT-checking feature
|
||||
if(!quickReplied && quickReply && msgLength >= 48) {
|
||||
quickReplied = true;
|
||||
// check info_hash
|
||||
if(memcmp(btContext->getInfoHash(), &msg[28], INFO_HASH_LENGTH) == 0) {
|
||||
sendHandshake();
|
||||
}
|
||||
}
|
||||
if(!retval) {
|
||||
return NULL;
|
||||
}
|
||||
PeerMessageHandle handshakeMessage(peerMessageFactory->createHandshakeMessage(msg, msgLength));
|
||||
handshakeMessage->check();
|
||||
if(((HandshakeMessage*)handshakeMessage.get())->isFastExtensionSupported()) {
|
||||
peer->setFastExtensionEnabled(true);
|
||||
logger->info("CUID#%d - Fast extension enabled.", cuid);
|
||||
}
|
||||
return handshakeMessage;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerInteraction::receiveMessage() {
|
||||
char msg[MAX_PAYLOAD_LEN];
|
||||
int msgLength = 0;
|
||||
if(!peerConnection->receiveMessage(msg, msgLength)) {
|
||||
return NULL;
|
||||
}
|
||||
PeerMessageHandle peerMessage =
|
||||
peerMessageFactory->createPeerMessage(msg, msgLength);
|
||||
peerMessage->check();
|
||||
return peerMessage;
|
||||
}
|
||||
|
||||
void PeerInteraction::syncPiece() {
|
||||
/*
|
||||
for(Pieces::iterator itr = pieces.begin(); itr != pieces.end(); itr++) {
|
||||
pieceStorage->syncPiece(*itr);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void PeerInteraction::updatePiece() {
|
||||
/*
|
||||
for(Pieces::iterator itr = pieces.begin(); itr != pieces.end(); itr++) {
|
||||
pieceStorage->updatePiece(*itr);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void PeerInteraction::getNewPieceAndSendInterest(int pieceNum) {
|
||||
if(pieces.empty() && !pieceStorage->hasMissingPiece(peer)) {
|
||||
if(peer->amInterested) {
|
||||
logger->debug("CUID#%d - Not interested in the peer", cuid);
|
||||
addMessage(peerMessageFactory->createNotInterestedMessage());
|
||||
}
|
||||
} else {
|
||||
if(peer->peerChoking) {
|
||||
onChoked();
|
||||
if(peer->isFastExtensionEnabled()) {
|
||||
while((int)pieces.size() < pieceNum) {
|
||||
PieceHandle piece = pieceStorage->getMissingFastPiece(peer);
|
||||
if(piece.isNull()) {
|
||||
break;
|
||||
} else {
|
||||
pieces.push_back(piece);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while((int)pieces.size() < pieceNum) {
|
||||
PieceHandle piece = pieceStorage->getMissingPiece(peer);
|
||||
if(piece.isNull()) {
|
||||
break;
|
||||
} else {
|
||||
pieces.push_back(piece);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!peer->amInterested) {
|
||||
logger->debug("CUID#%d - Interested in the peer", cuid);
|
||||
addMessage(peerMessageFactory->createInterestedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PeerInteraction::addRequests() {
|
||||
// Abort downloading of completed piece.
|
||||
for(Pieces::iterator itr = pieces.begin(); itr != pieces.end();) {
|
||||
PieceHandle& piece = *itr;
|
||||
if(piece->pieceComplete()) {
|
||||
abortPiece(piece);
|
||||
itr = pieces.erase(itr);
|
||||
} else {
|
||||
itr++;
|
||||
}
|
||||
}
|
||||
int MAX_PENDING_REQUEST;
|
||||
if(peer->getLatency() < 500) {
|
||||
MAX_PENDING_REQUEST = 24;
|
||||
} else if(peer->getLatency() < 1500) {
|
||||
MAX_PENDING_REQUEST = 12;
|
||||
} else {
|
||||
MAX_PENDING_REQUEST = 6;
|
||||
}
|
||||
int pieceNum;
|
||||
if(pieceStorage->isEndGame()) {
|
||||
pieceNum = 1;
|
||||
} else {
|
||||
int blocks = DIV_FLOOR(btContext->getPieceLength(), BLOCK_LENGTH);
|
||||
pieceNum = DIV_FLOOR(MAX_PENDING_REQUEST, blocks);
|
||||
}
|
||||
getNewPieceAndSendInterest(pieceNum);
|
||||
for(Pieces::iterator itr = pieces.begin(); itr != pieces.end(); itr++) {
|
||||
PieceHandle& piece = *itr;
|
||||
if(pieceStorage->isEndGame()) {
|
||||
BlockIndexes missingBlockIndexes = piece->getAllMissingBlockIndexes();
|
||||
random_shuffle(missingBlockIndexes.begin(), missingBlockIndexes.end());
|
||||
int count = countRequestSlot();
|
||||
for(BlockIndexes::const_iterator bitr = missingBlockIndexes.begin();
|
||||
bitr != missingBlockIndexes.end() && count < MAX_PENDING_REQUEST;
|
||||
bitr++) {
|
||||
int blockIndex = *bitr;
|
||||
if(!isInRequestSlot(piece->getIndex(), blockIndex)) {
|
||||
addMessage(peerMessageFactory->createRequestMessage(piece,
|
||||
blockIndex));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while(countRequestSlot() < MAX_PENDING_REQUEST) {
|
||||
int blockIndex = piece->getMissingUnusedBlockIndex();
|
||||
if(blockIndex == -1) {
|
||||
break;
|
||||
}
|
||||
addMessage(peerMessageFactory->createRequestMessage(piece,
|
||||
blockIndex));
|
||||
}
|
||||
}
|
||||
if(countRequestSlot() >= MAX_PENDING_REQUEST) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
updatePiece();
|
||||
}
|
||||
|
||||
void PeerInteraction::sendHandshake() {
|
||||
PeerMessageHandle handle =
|
||||
peerMessageFactory->createHandshakeMessage(btContext->getInfoHash(),
|
||||
(const char*)btContext->getPeerId());
|
||||
addMessage(handle);
|
||||
sendMessages();
|
||||
}
|
||||
|
||||
void PeerInteraction::sendBitfield() {
|
||||
if(peer->isFastExtensionEnabled()) {
|
||||
if(pieceStorage->downloadFinished()) {
|
||||
addMessage(peerMessageFactory->createHaveAllMessage());
|
||||
} else if(pieceStorage->getCompletedLength() > 0) {
|
||||
addMessage(peerMessageFactory->createBitfieldMessage());
|
||||
} else {
|
||||
addMessage(peerMessageFactory->createHaveNoneMessage());
|
||||
}
|
||||
} else {
|
||||
if(pieceStorage->getCompletedLength() > 0) {
|
||||
addMessage(peerMessageFactory->createBitfieldMessage());
|
||||
}
|
||||
}
|
||||
sendMessages();
|
||||
}
|
||||
|
||||
void PeerInteraction::sendAllowedFast() {
|
||||
if(peer->isFastExtensionEnabled()) {
|
||||
Integers fastSet = Util::computeFastSet(peer->ipaddr,
|
||||
btContext->getInfoHash(),
|
||||
btContext->getNumPieces(),
|
||||
ALLOWED_FAST_SET_SIZE);
|
||||
for(Integers::const_iterator itr = fastSet.begin();
|
||||
itr != fastSet.end(); itr++) {
|
||||
addMessage(peerMessageFactory->createAllowedFastMessage(*itr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PieceHandle PeerInteraction::getDownloadPiece(int index) {
|
||||
for(Pieces::iterator itr = pieces.begin(); itr != pieces.end(); itr++) {
|
||||
if((*itr)->getIndex() == index) {
|
||||
return *itr;
|
||||
}
|
||||
}
|
||||
throw new DlAbortEx("No such piece index=%d", index);
|
||||
}
|
||||
|
||||
bool PeerInteraction::hasDownloadPiece(int index) const {
|
||||
for(Pieces::const_iterator itr = pieces.begin(); itr != pieces.end(); itr++) {
|
||||
if((*itr)->getIndex() == index) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PeerInteraction::isInFastSet(int index) const {
|
||||
return find(fastSet.begin(), fastSet.end(), index) != fastSet.end();
|
||||
}
|
||||
|
||||
void PeerInteraction::addFastSetIndex(int index) {
|
||||
if(!isInFastSet(index)) {
|
||||
fastSet.push_back(index);
|
||||
}
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_PEER_INTERACTION_H_
|
||||
#define _D_PEER_INTERACTION_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "PeerConnection.h"
|
||||
#include "PeerMessageFactory.h"
|
||||
#include "RequestSlot.h"
|
||||
#include "SharedHandle.h"
|
||||
#include "BtContext.h"
|
||||
#include "PeerStorage.h"
|
||||
#include "PieceStorage.h"
|
||||
#include "BtAnnounce.h"
|
||||
|
||||
#define REQUEST_TIME_OUT 60
|
||||
#define ALLOWED_FAST_SET_SIZE 10
|
||||
|
||||
typedef deque<PeerMessageHandle> MessageQueue;
|
||||
|
||||
class PeerInteraction {
|
||||
private:
|
||||
int cuid;
|
||||
RequestSlots requestSlots;
|
||||
MessageQueue messageQueue;
|
||||
const Option* option;
|
||||
BtContextHandle btContext;
|
||||
PeerStorageHandle peerStorage;
|
||||
PieceStorageHandle pieceStorage;
|
||||
BtAnnounceHandle btAnnounce;
|
||||
PeerConnection* peerConnection;
|
||||
PeerHandle peer;
|
||||
Pieces pieces;
|
||||
PeerMessageFactory* peerMessageFactory;
|
||||
// allowed fast piece indexes that local client has sent
|
||||
Integers fastSet;
|
||||
bool quickReplied;
|
||||
const Logger* logger;
|
||||
|
||||
void getNewPieceAndSendInterest(int pieceNum);
|
||||
int countRequestSlot() const;
|
||||
public:
|
||||
PeerInteraction(int cuid,
|
||||
const PeerHandle& peer,
|
||||
const SocketHandle& socket,
|
||||
const Option* op,
|
||||
const BtContextHandle& btContext);
|
||||
~PeerInteraction();
|
||||
|
||||
void addMessage(const PeerMessageHandle& peerMessage);
|
||||
void addRequestSlot(const RequestSlot& requestSlot);
|
||||
void rejectPieceMessageInQueue(int index, int begin, int length);
|
||||
void rejectAllPieceMessageInQueue();
|
||||
void onChoked();
|
||||
void abortPiece(const PieceHandle& piece);
|
||||
void abortAllPieces();
|
||||
|
||||
bool isSendingMessageInProgress() const;
|
||||
void deleteRequestSlot(const RequestSlot& requestSlot);
|
||||
void checkRequestSlot();
|
||||
RequestSlot getCorrespondingRequestSlot(int index, int begin, int length) const;
|
||||
bool isInRequestSlot(int index, int blockIndex) const;
|
||||
|
||||
int countMessageInQueue() const;
|
||||
|
||||
PeerConnection* getPeerConnection() const { return peerConnection; }
|
||||
|
||||
// If this object has nullPiece, then return false, otherwise true
|
||||
bool hasDownloadPiece(int index) const;
|
||||
|
||||
// If the piece which this object has is nullPiece, then throws an exception.
|
||||
// So before calling this function, call hasDownloadPiece and make sure
|
||||
// this has valid piece, not nullPiece.
|
||||
PieceHandle getDownloadPiece(int index);
|
||||
|
||||
bool isInFastSet(int index) const;
|
||||
|
||||
void addFastSetIndex(int index);
|
||||
|
||||
void syncPiece();
|
||||
void updatePiece();
|
||||
void addRequests();
|
||||
void sendMessages();
|
||||
void sendHandshake();
|
||||
void sendBitfield();
|
||||
void sendAllowedFast();
|
||||
|
||||
PeerMessageHandle receiveMessage();
|
||||
PeerMessageHandle receiveHandshake(bool quickReply = false);
|
||||
|
||||
const PeerMessageFactory* getPeerMessageFactory() const {
|
||||
return peerMessageFactory;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _D_PEER_INTERACTION_H_
|
|
@ -1,48 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "PeerMessage.h"
|
||||
#include "LogFactory.h"
|
||||
|
||||
PeerMessage::PeerMessage()
|
||||
:inProgress(false),
|
||||
invalidate(false),
|
||||
uploading(false),
|
||||
peer(0),
|
||||
btContext(0),
|
||||
peerStorage(0),
|
||||
pieceStorage(0)
|
||||
{
|
||||
logger = LogFactory::getInstance();
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_PEER_MESSAGE_H_
|
||||
#define _D_PEER_MESSAGE_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "Logger.h"
|
||||
#include "Peer.h"
|
||||
#include "Piece.h"
|
||||
#include "BtContext.h"
|
||||
#include "PeerStorage.h"
|
||||
#include "PieceStorage.h"
|
||||
#include "BtRegistry.h"
|
||||
#include <string>
|
||||
|
||||
class PeerInteraction;
|
||||
|
||||
class PeerMessage {
|
||||
protected:
|
||||
bool inProgress;
|
||||
bool invalidate;
|
||||
bool uploading;
|
||||
int cuid;
|
||||
PeerHandle peer;
|
||||
PeerInteraction* peerInteraction;
|
||||
const Logger* logger;
|
||||
BtContextHandle btContext;
|
||||
PeerStorageHandle peerStorage;
|
||||
PieceStorageHandle pieceStorage;
|
||||
public:
|
||||
PeerMessage();
|
||||
|
||||
virtual ~PeerMessage() {}
|
||||
|
||||
bool isInProgress() const { return inProgress; }
|
||||
bool isInvalidate() const { return invalidate; }
|
||||
bool isUploading() const { return uploading; }
|
||||
|
||||
int getCuid() const { return cuid; }
|
||||
|
||||
void setCuid(int cuid) {
|
||||
this->cuid = cuid;
|
||||
}
|
||||
|
||||
PeerHandle getPeer() const { return this->peer; }
|
||||
|
||||
void setPeer(const PeerHandle& peer) {
|
||||
this->peer = peer;
|
||||
}
|
||||
|
||||
PeerInteraction* getPeerInteraction() const { return peerInteraction; }
|
||||
|
||||
void setPeerInteraction(PeerInteraction* peerInteraction) {
|
||||
this->peerInteraction = peerInteraction;
|
||||
}
|
||||
|
||||
void setBtContext(const BtContextHandle& btContext) {
|
||||
this->btContext = btContext;
|
||||
pieceStorage = PIECE_STORAGE(btContext);
|
||||
peerStorage = PEER_STORAGE(btContext);
|
||||
}
|
||||
|
||||
virtual int getId() const = 0;
|
||||
virtual void receivedAction() = 0;
|
||||
virtual void send() = 0;
|
||||
virtual void check() const {}
|
||||
virtual string toString() const = 0;
|
||||
virtual void onPush() {}
|
||||
virtual void onChoked() {}
|
||||
virtual void onCanceled(int index, int begin, int blockLength) {}
|
||||
virtual void onAbortPiece(const PieceHandle& piece) {}
|
||||
};
|
||||
|
||||
typedef SharedHandle<PeerMessage> PeerMessageHandle;
|
||||
|
||||
#endif // _D_PEER_MESSAGE_H_
|
|
@ -1,281 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "PeerMessageFactory.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "ChokeMessage.h"
|
||||
#include "UnchokeMessage.h"
|
||||
#include "InterestedMessage.h"
|
||||
#include "NotInterestedMessage.h"
|
||||
#include "HaveMessage.h"
|
||||
#include "BitfieldMessage.h"
|
||||
#include "RequestMessage.h"
|
||||
#include "CancelMessage.h"
|
||||
#include "PieceMessage.h"
|
||||
#include "HandshakeMessage.h"
|
||||
#include "KeepAliveMessage.h"
|
||||
#include "PortMessage.h"
|
||||
#include "HaveAllMessage.h"
|
||||
#include "HaveNoneMessage.h"
|
||||
#include "RejectMessage.h"
|
||||
#include "AllowedFastMessage.h"
|
||||
#include "SuggestPieceMessage.h"
|
||||
#include "RequestSlot.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "BtRegistry.h"
|
||||
#include "PeerInteraction.h"
|
||||
|
||||
PeerMessageFactory::PeerMessageFactory(int cuid,
|
||||
const BtContextHandle& btContext,
|
||||
PeerInteraction* peerInteraction,
|
||||
const PeerHandle& peer)
|
||||
:cuid(cuid),
|
||||
btContext(btContext),
|
||||
pieceStorage(PIECE_STORAGE(btContext)),
|
||||
peerInteraction(peerInteraction),
|
||||
peer(peer) {}
|
||||
|
||||
PeerMessageFactory::~PeerMessageFactory() {}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createPeerMessage(const char* msg, int msgLength) const {
|
||||
PeerMessage* peerMessage;
|
||||
if(msgLength == 0) {
|
||||
// keep-alive
|
||||
peerMessage = new KeepAliveMessage();
|
||||
} else {
|
||||
int id = PeerMessageUtil::getId(msg);
|
||||
switch(id) {
|
||||
case ChokeMessage::ID:
|
||||
peerMessage = ChokeMessage::create(msg, msgLength);
|
||||
break;
|
||||
case UnchokeMessage::ID:
|
||||
peerMessage = UnchokeMessage::create(msg, msgLength);
|
||||
break;
|
||||
case InterestedMessage::ID:
|
||||
peerMessage = InterestedMessage::create(msg, msgLength);
|
||||
break;
|
||||
case NotInterestedMessage::ID:
|
||||
peerMessage = NotInterestedMessage::create(msg, msgLength);
|
||||
break;
|
||||
case HaveMessage::ID:
|
||||
peerMessage = HaveMessage::create(msg, msgLength);
|
||||
((HaveMessage*)peerMessage)->setPieces(btContext->getNumPieces());
|
||||
break;
|
||||
case BitfieldMessage::ID:
|
||||
peerMessage = BitfieldMessage::create(msg, msgLength);
|
||||
((BitfieldMessage*)peerMessage)->setPieces(btContext->getNumPieces());
|
||||
break;
|
||||
case RequestMessage::ID:
|
||||
peerMessage = RequestMessage::create(msg, msgLength);
|
||||
((RequestMessage*)peerMessage)->setPieces(btContext->getNumPieces());
|
||||
((RequestMessage*)peerMessage)->setPieceLength(pieceStorage->getPieceLength(((RequestMessage*)peerMessage)->getIndex()));
|
||||
break;
|
||||
case CancelMessage::ID:
|
||||
peerMessage = CancelMessage::create(msg, msgLength);
|
||||
((CancelMessage*)peerMessage)->setPieces(btContext->getNumPieces());
|
||||
((CancelMessage*)peerMessage)->setPieceLength(pieceStorage->getPieceLength(((CancelMessage*)peerMessage)->getIndex()));
|
||||
break;
|
||||
case PieceMessage::ID:
|
||||
peerMessage = PieceMessage::create(msg, msgLength);
|
||||
((PieceMessage*)peerMessage)->setPieces(btContext->getNumPieces());
|
||||
((PieceMessage*)peerMessage)->setPieceLength(pieceStorage->getPieceLength(((PieceMessage*)peerMessage)->getIndex()));
|
||||
break;
|
||||
case PortMessage::ID:
|
||||
peerMessage = PortMessage::create(msg, msgLength);
|
||||
break;
|
||||
case HaveAllMessage::ID:
|
||||
peerMessage = HaveAllMessage::create(msg, msgLength);
|
||||
break;
|
||||
case HaveNoneMessage::ID:
|
||||
peerMessage = HaveNoneMessage::create(msg, msgLength);
|
||||
break;
|
||||
case RejectMessage::ID:
|
||||
peerMessage = RejectMessage::create(msg, msgLength);
|
||||
((RejectMessage*)peerMessage)->setPieces(btContext->getNumPieces());
|
||||
((RejectMessage*)peerMessage)->setPieceLength(pieceStorage->getPieceLength(((RejectMessage*)peerMessage)->getIndex()));
|
||||
break;
|
||||
case SuggestPieceMessage::ID:
|
||||
peerMessage = SuggestPieceMessage::create(msg, msgLength);
|
||||
((SuggestPieceMessage*)peerMessage)->setPieces(btContext->getNumPieces());
|
||||
break;
|
||||
case AllowedFastMessage::ID:
|
||||
peerMessage = AllowedFastMessage::create(msg, msgLength);
|
||||
((AllowedFastMessage*)peerMessage)->setPieces(btContext->getNumPieces());
|
||||
break;
|
||||
default:
|
||||
throw new DlAbortEx("Invalid message id. id = %d", id);
|
||||
}
|
||||
}
|
||||
PeerMessageHandle handle = PeerMessageHandle(peerMessage);
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle
|
||||
PeerMessageFactory::createHandshakeMessage(const char* msg, int msgLength) const
|
||||
{
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(HandshakeMessage::create(msg, msgLength));
|
||||
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle
|
||||
PeerMessageFactory::createHandshakeMessage(const unsigned char* infoHash,
|
||||
const char* peerId) const
|
||||
{
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new HandshakeMessage(infoHash, peerId));
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
void
|
||||
PeerMessageFactory::setPeerMessageCommonProperty(PeerMessageHandle& peerMessage) const
|
||||
{
|
||||
peerMessage->setPeer(peer);
|
||||
peerMessage->setCuid(cuid);
|
||||
peerMessage->setPeerInteraction(peerInteraction);
|
||||
peerMessage->setBtContext(btContext);
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createRequestMessage(const PieceHandle& piece,
|
||||
int blockIndex) const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new RequestMessage(piece->getIndex(),
|
||||
blockIndex*piece->getBlockLength(),
|
||||
piece->getBlockLength(blockIndex),
|
||||
blockIndex));
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createCancelMessage(int index,
|
||||
int begin,
|
||||
int length) const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new CancelMessage(index, begin, length));
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createPieceMessage(int index,
|
||||
int begin,
|
||||
int length) const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new PieceMessage(index, begin, length));
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createHaveMessage(int index) const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new HaveMessage(index));
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createChokeMessage() const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new ChokeMessage());
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createUnchokeMessage() const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new UnchokeMessage());
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createInterestedMessage() const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new InterestedMessage());
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createNotInterestedMessage() const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new NotInterestedMessage());
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createBitfieldMessage() const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new BitfieldMessage(pieceStorage->getBitfield(),
|
||||
pieceStorage->getBitfieldLength()));
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createKeepAliveMessage() const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new KeepAliveMessage());
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createHaveAllMessage() const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new HaveAllMessage());
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createHaveNoneMessage() const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new HaveNoneMessage());
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createRejectMessage(int index,
|
||||
int begin,
|
||||
int length) const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new RejectMessage(index, begin, length));
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
PeerMessageHandle PeerMessageFactory::createAllowedFastMessage(int index) const {
|
||||
PeerMessageHandle handle =
|
||||
PeerMessageHandle(new AllowedFastMessage(index));
|
||||
setPeerMessageCommonProperty(handle);
|
||||
return handle;
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_PEER_MESSAGE_FACTORY_H_
|
||||
#define _D_PEER_MESSAGE_FACTORY_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "PeerMessage.h"
|
||||
#include "HandshakeMessage.h"
|
||||
#include "BtContext.h"
|
||||
#include "PieceStorage.h"
|
||||
|
||||
class PeerInteraction;
|
||||
|
||||
class PeerMessageFactory {
|
||||
private:
|
||||
int cuid;
|
||||
BtContextHandle btContext;
|
||||
PieceStorageHandle pieceStorage;
|
||||
PeerInteraction* peerInteraction;
|
||||
PeerHandle peer;
|
||||
|
||||
void setPeerMessageCommonProperty(PeerMessageHandle& peerMessage) const;
|
||||
public:
|
||||
PeerMessageFactory(int cuid,
|
||||
const BtContextHandle& btContext,
|
||||
PeerInteraction* peerInteraction,
|
||||
const PeerHandle& peer);
|
||||
|
||||
~PeerMessageFactory();
|
||||
|
||||
PeerMessageHandle
|
||||
createPeerMessage(const char* msg, int msgLength) const;
|
||||
|
||||
PeerMessageHandle
|
||||
createHandshakeMessage(const char* msg,
|
||||
int msgLength) const;
|
||||
|
||||
PeerMessageHandle
|
||||
createHandshakeMessage(const unsigned char* infoHash,
|
||||
const char* peerId) const;
|
||||
|
||||
PeerMessageHandle createRequestMessage(const PieceHandle& piece,
|
||||
int blockIndex) const;
|
||||
PeerMessageHandle createCancelMessage(int index, int begin, int length) const;
|
||||
PeerMessageHandle createPieceMessage(int index, int begin, int length) const;
|
||||
PeerMessageHandle createHaveMessage(int index) const;
|
||||
PeerMessageHandle createChokeMessage() const;
|
||||
PeerMessageHandle createUnchokeMessage() const;
|
||||
PeerMessageHandle createInterestedMessage() const;
|
||||
PeerMessageHandle createNotInterestedMessage() const;
|
||||
PeerMessageHandle createBitfieldMessage() const;
|
||||
PeerMessageHandle createKeepAliveMessage() const;
|
||||
PeerMessageHandle createHaveAllMessage() const;
|
||||
PeerMessageHandle createHaveNoneMessage() const;
|
||||
PeerMessageHandle createRejectMessage(int index, int begin, int length) const;
|
||||
PeerMessageHandle createAllowedFastMessage(int index) const;
|
||||
};
|
||||
|
||||
#endif // _D_PEER_MESSAGE_FACTORY_H_
|
|
@ -106,21 +106,6 @@ void PeerMessageUtil::checkBitfield(const unsigned char* bitfield,
|
|||
}
|
||||
}
|
||||
|
||||
void PeerMessageUtil::checkHandshake(const HandshakeMessage* message, const unsigned char* infoHash) {
|
||||
if(message->pstrlen != 19) {
|
||||
throw new DlAbortEx("invalid handshake pstrlen = %d", (int)message->pstrlen);
|
||||
}
|
||||
if(message->pstr != PSTR) {
|
||||
throw new DlAbortEx("invalid handshake pstr");
|
||||
}
|
||||
string myInfoHash = Util::toHex(infoHash, 20);
|
||||
string peerInfoHash = Util::toHex(message->infoHash, 20);
|
||||
if(myInfoHash != peerInfoHash) {
|
||||
throw new DlAbortEx("invalid handshake info hash: expected:%s, actual:%s",
|
||||
myInfoHash.c_str(), peerInfoHash.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void PeerMessageUtil::setIntParam(unsigned char* dest, uint32_t param) {
|
||||
uint32_t nParam = htonl(param);
|
||||
memcpy(dest, &nParam, sizeof(uint32_t));
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
#define _D_PEER_MESSAGE_UTIL_H_
|
||||
|
||||
#include "common.h"
|
||||
#include "HandshakeMessage.h"
|
||||
|
||||
#define MAX_BLOCK_LENGTH (128*1024)
|
||||
|
||||
|
@ -82,9 +81,6 @@ public:
|
|||
checkBitfield((unsigned char*)bitfield, bitfieldLength, pieces);
|
||||
}
|
||||
|
||||
static void checkHandshake(const HandshakeMessage* message,
|
||||
const unsigned char* infoHash);
|
||||
|
||||
static void createPeerMessageString(unsigned char* msg,
|
||||
uint32_t msgLength,
|
||||
uint32_t payloadLength,
|
||||
|
|
|
@ -1,281 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "PieceMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "Util.h"
|
||||
#include "message.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
void PieceMessage::setBlock(const char* block, int blockLength) {
|
||||
if(this->block != NULL) {
|
||||
delete [] this->block;
|
||||
}
|
||||
this->blockLength = blockLength;
|
||||
this->block = new char[this->blockLength];
|
||||
memcpy(this->block, block, this->blockLength);
|
||||
}
|
||||
|
||||
PieceMessage* PieceMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength <= 9) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be greater than %d", "piece", dataLength, 9);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "piece", ID);
|
||||
}
|
||||
PieceMessage* pieceMessage = new PieceMessage();
|
||||
pieceMessage->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
pieceMessage->setBegin(PeerMessageUtil::getIntParam(data, 5));
|
||||
pieceMessage->setBlock(data+9, dataLength-9);
|
||||
return pieceMessage;
|
||||
}
|
||||
|
||||
void PieceMessage::receivedAction() {
|
||||
RequestSlot slot = peerInteraction->getCorrespondingRequestSlot(index,
|
||||
begin,
|
||||
blockLength);
|
||||
peer->updateDownloadLength(blockLength);
|
||||
if(!RequestSlot::isNull(slot) &&
|
||||
peerInteraction->hasDownloadPiece(slot.getIndex())) {
|
||||
peer->snubbing = false;
|
||||
//logger->debug("CUID#%d - Latency=%d", cuid, slot.getLatencyInMillis());
|
||||
peer->updateLatency(slot.getLatencyInMillis());
|
||||
PieceHandle piece = peerInteraction->getDownloadPiece(slot.getIndex());
|
||||
long long int offset =
|
||||
((long long int)index)*btContext->getPieceLength()+begin;
|
||||
logger->debug("CUID#%d - Writing the block length=%d, offset=%lld",
|
||||
cuid, blockLength, offset);
|
||||
pieceStorage->getDiskAdaptor()->writeData(block,
|
||||
blockLength,
|
||||
offset);
|
||||
piece->completeBlock(slot.getBlockIndex());
|
||||
peerInteraction->deleteRequestSlot(slot);
|
||||
//pieceStorage->updatePiece(piece);
|
||||
logger->debug("CUID#%d - Setting piece block index=%d",
|
||||
cuid, slot.getBlockIndex());
|
||||
if(piece->pieceComplete()) {
|
||||
if(checkPieceHash(piece)) {
|
||||
onGotNewPiece(piece);
|
||||
} else {
|
||||
onGotWrongPiece(piece);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char* PieceMessage::getMessageHeader() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 9+blockLength, 4bytes
|
||||
* id --- 7, 1byte
|
||||
* index --- index, 4bytes
|
||||
* begin --- begin, 4bytes
|
||||
* total: 13bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msgHeader, sizeof(msgHeader),
|
||||
9+blockLength, ID);
|
||||
PeerMessageUtil::setIntParam(&msgHeader[5], index);
|
||||
PeerMessageUtil::setIntParam(&msgHeader[9], begin);
|
||||
}
|
||||
return msgHeader;
|
||||
}
|
||||
|
||||
int PieceMessage::getMessageHeaderLength() {
|
||||
return sizeof(msgHeader);
|
||||
}
|
||||
|
||||
void PieceMessage::send() {
|
||||
if(invalidate) {
|
||||
return;
|
||||
}
|
||||
PeerConnection* peerConnection = peerInteraction->getPeerConnection();
|
||||
if(!headerSent) {
|
||||
if(!inProgress) {
|
||||
logger->info(MSG_SEND_PEER_MESSAGE,
|
||||
cuid, peer->ipaddr.c_str(), peer->port,
|
||||
toString().c_str());
|
||||
getMessageHeader();
|
||||
leftDataLength = getMessageHeaderLength();
|
||||
inProgress = true;
|
||||
}
|
||||
int writtenLength
|
||||
= peerConnection->sendMessage(msgHeader+getMessageHeaderLength()-leftDataLength,
|
||||
leftDataLength);
|
||||
if(writtenLength == leftDataLength) {
|
||||
headerSent = true;
|
||||
leftDataLength = blockLength;
|
||||
} else {
|
||||
leftDataLength -= writtenLength;
|
||||
}
|
||||
}
|
||||
if(headerSent) {
|
||||
inProgress = false;
|
||||
long long int pieceDataOffset =
|
||||
((long long int)index)*btContext->getPieceLength()+begin+blockLength-leftDataLength;
|
||||
int writtenLength =
|
||||
sendPieceData(pieceDataOffset, leftDataLength);
|
||||
peer->updateUploadLength(writtenLength);
|
||||
if(writtenLength != leftDataLength) {
|
||||
inProgress = true;
|
||||
}
|
||||
leftDataLength -= writtenLength;
|
||||
}
|
||||
}
|
||||
|
||||
int PieceMessage::sendPieceData(long long int offset, int length) const {
|
||||
int BUF_SIZE = 256;
|
||||
char buf[BUF_SIZE];
|
||||
int iteration = length/BUF_SIZE;
|
||||
int writtenLength = 0;
|
||||
PeerConnection* peerConnection = peerInteraction->getPeerConnection();
|
||||
for(int i = 0; i < iteration; i++) {
|
||||
if(pieceStorage->getDiskAdaptor()->readData(buf, BUF_SIZE, offset+i*BUF_SIZE) < BUF_SIZE) {
|
||||
throw new DlAbortEx("Failed to read data from disk.");
|
||||
}
|
||||
int ws = peerConnection->sendMessage(buf, BUF_SIZE);
|
||||
writtenLength += ws;
|
||||
if(ws != BUF_SIZE) {
|
||||
//logger->debug("CUID#%d - %d bytes written", cuid, writtenLength);
|
||||
return writtenLength;
|
||||
}
|
||||
}
|
||||
|
||||
int rem = length%BUF_SIZE;
|
||||
if(rem > 0) {
|
||||
if(pieceStorage->getDiskAdaptor()->readData(buf, rem, offset+iteration*BUF_SIZE) < rem) {
|
||||
throw new DlAbortEx("Failed to read data from disk.");
|
||||
}
|
||||
int ws = peerConnection->sendMessage(buf, rem);
|
||||
writtenLength += ws;
|
||||
}
|
||||
//logger->debug("CUID#%d - %d bytes written", cuid, writtenLength);
|
||||
return writtenLength;
|
||||
}
|
||||
|
||||
void PieceMessage::check() const {
|
||||
PeerMessageUtil::checkIndex(index, pieces);
|
||||
PeerMessageUtil::checkBegin(begin, pieceLength);
|
||||
}
|
||||
|
||||
string PieceMessage::toString() const {
|
||||
return "piece index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||
", length="+Util::itos(blockLength);
|
||||
}
|
||||
|
||||
bool PieceMessage::checkPieceHash(const PieceHandle& piece) {
|
||||
long long int offset =
|
||||
((long long int)piece->getIndex())*btContext->getPieceLength();
|
||||
return pieceStorage->getDiskAdaptor()->sha1Sum(offset, piece->getLength()) ==
|
||||
btContext->getPieceHash(piece->getIndex());
|
||||
}
|
||||
|
||||
void PieceMessage::onGotNewPiece(const PieceHandle& piece) {
|
||||
logger->info(MSG_GOT_NEW_PIECE, cuid, piece->getIndex());
|
||||
pieceStorage->completePiece(piece);
|
||||
pieceStorage->advertisePiece(cuid, piece->getIndex());
|
||||
}
|
||||
|
||||
void PieceMessage::onGotWrongPiece(const PieceHandle& piece) {
|
||||
logger->error(MSG_GOT_WRONG_PIECE, cuid, piece->getIndex());
|
||||
erasePieceOnDisk(piece);
|
||||
piece->clearAllBlock();
|
||||
//pieceStorage->updatePiece(piece);
|
||||
peerInteraction->abortPiece(piece);
|
||||
}
|
||||
|
||||
void PieceMessage::erasePieceOnDisk(const PieceHandle& piece) {
|
||||
int BUFSIZE = 4096;
|
||||
char buf[BUFSIZE];
|
||||
memset(buf, 0, BUFSIZE);
|
||||
long long int offset =
|
||||
((long long int)piece->getIndex())*btContext->getPieceLength();
|
||||
for(int i = 0; i < piece->getLength()/BUFSIZE; i++) {
|
||||
pieceStorage->getDiskAdaptor()->writeData(buf, BUFSIZE, offset);
|
||||
offset += BUFSIZE;
|
||||
}
|
||||
int r = piece->getLength()%BUFSIZE;
|
||||
if(r > 0) {
|
||||
pieceStorage->getDiskAdaptor()->writeData(buf, r, offset);
|
||||
}
|
||||
}
|
||||
|
||||
PeerMessageHandle PieceMessage::createRejectMessage(int index,
|
||||
int begin,
|
||||
int blockLength) const {
|
||||
return peerInteraction->getPeerMessageFactory()->
|
||||
createRejectMessage(index,
|
||||
begin,
|
||||
blockLength);
|
||||
}
|
||||
|
||||
void PieceMessage::onChoked() {
|
||||
if(!invalidate &&
|
||||
!inProgress &&
|
||||
!peerInteraction->isInFastSet(index)) {
|
||||
logger->debug("CUID#%d - Reject piece message in queue because"
|
||||
" the peer has been choked. index=%d, begin=%d, length=%d",
|
||||
cuid,
|
||||
index,
|
||||
begin,
|
||||
blockLength);
|
||||
|
||||
if(peer->isFastExtensionEnabled()) {
|
||||
peerInteraction->addMessage(createRejectMessage(index,
|
||||
begin,
|
||||
blockLength));
|
||||
}
|
||||
invalidate = true;
|
||||
}
|
||||
}
|
||||
|
||||
void PieceMessage::onCanceled(int index, int begin, int blockLength) {
|
||||
if(!invalidate &&
|
||||
!inProgress &&
|
||||
this->index == index &&
|
||||
this->begin == begin &&
|
||||
this->blockLength == blockLength) {
|
||||
logger->debug("CUID#%d - Reject piece message in queue because cancel"
|
||||
" message received. index=%d, begin=%d, length=%d",
|
||||
cuid, index, begin, blockLength);
|
||||
if(peer->isFastExtensionEnabled()) {
|
||||
peerInteraction->addMessage(createRejectMessage(index,
|
||||
begin,
|
||||
blockLength));
|
||||
}
|
||||
invalidate = true;
|
||||
}
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_PIECE_MESSAGE_H_
|
||||
#define _D_PIECE_MESSAGE_H_
|
||||
|
||||
#include "PeerMessage.h"
|
||||
|
||||
class PieceMessage : public PeerMessage {
|
||||
private:
|
||||
int index;
|
||||
int begin;
|
||||
char* block;
|
||||
int blockLength;
|
||||
int leftDataLength;
|
||||
bool headerSent;
|
||||
int pendingCount;
|
||||
// for check
|
||||
int pieces;
|
||||
int pieceLength;
|
||||
|
||||
char msgHeader[13];
|
||||
|
||||
bool checkPieceHash(const PieceHandle& piece);
|
||||
void onGotNewPiece(const PieceHandle& piece);
|
||||
void onGotWrongPiece(const PieceHandle& piece);
|
||||
void erasePieceOnDisk(const PieceHandle& piece);
|
||||
int sendPieceData(long long int offset, int length) const;
|
||||
PeerMessageHandle createRejectMessage(int index, int begin, int blockLength) const;
|
||||
public:
|
||||
PieceMessage(int index = 0, int begin = 0, int blockLength = 0)
|
||||
:PeerMessage(),
|
||||
index(index),
|
||||
begin(begin),
|
||||
block(0),
|
||||
blockLength(blockLength),
|
||||
leftDataLength(0),
|
||||
headerSent(false),
|
||||
pendingCount(0),
|
||||
pieces(0),
|
||||
pieceLength(0)
|
||||
{
|
||||
uploading = true;
|
||||
}
|
||||
|
||||
virtual ~PieceMessage() {
|
||||
delete [] block;
|
||||
}
|
||||
|
||||
enum ID_t {
|
||||
ID = 7
|
||||
};
|
||||
|
||||
int getIndex() const { return index; }
|
||||
void setIndex(int index) { this->index = index; }
|
||||
int getBegin() const { return begin; }
|
||||
void setBegin(int begin) { this->begin = begin; }
|
||||
const char* getBlock() const { return block; }
|
||||
void setBlock(const char* block, int blockLength);
|
||||
int getBlockLength() const { return blockLength; }
|
||||
void setBlockLength(int blockLength) { this->blockLength = blockLength; }
|
||||
|
||||
void setPieces(int pieces) {
|
||||
this->pieces = pieces;
|
||||
}
|
||||
int getPieces() const { return pieces;}
|
||||
|
||||
void setPieceLength(int pieceLength) {
|
||||
this->pieceLength = pieceLength;
|
||||
}
|
||||
int getPieceLength() const { return pieceLength;}
|
||||
|
||||
void incrementPendingCount() { pendingCount++; }
|
||||
bool isPendingCountMax() const { return pendingCount > 2; }
|
||||
|
||||
static PieceMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessageHeader();
|
||||
virtual int getMessageHeaderLength();
|
||||
virtual void send();
|
||||
virtual void check() const;
|
||||
virtual string toString() const;
|
||||
virtual void onChoked();
|
||||
virtual void onCanceled(int index, int begin, int blockLength);
|
||||
};
|
||||
|
||||
#endif // _D_PIECE_MESSAGE_H_
|
|
@ -1,51 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "PortMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
PortMessage* PortMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 3) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "port", dataLength, 3);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "piece", ID);
|
||||
}
|
||||
PortMessage* portMessage = new PortMessage();
|
||||
portMessage->setPort(PeerMessageUtil::getShortIntParam(data, 1));
|
||||
return portMessage;
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_PORT_MESSAGE_H_
|
||||
#define _D_PORT_MESSAGE_H_
|
||||
|
||||
#include "PeerMessage.h"
|
||||
|
||||
class PortMessage : public PeerMessage {
|
||||
private:
|
||||
int port;
|
||||
public:
|
||||
PortMessage():PeerMessage() {}
|
||||
virtual ~PortMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 9
|
||||
};
|
||||
|
||||
int getPort() const { return port; }
|
||||
void setPort(int port) { this->port = port; }
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
|
||||
static PortMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual void receivedAction() {
|
||||
logger->info("DHT is not supported yet.");
|
||||
}
|
||||
virtual void send() {}
|
||||
virtual string toString() const {
|
||||
return "port";
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _D_PORT_MESSAGE_H_
|
|
@ -1,106 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "RejectMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
RejectMessage* RejectMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 13) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "reject", dataLength, 13);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "reject", ID);
|
||||
}
|
||||
RejectMessage* rejectMessage = new RejectMessage();
|
||||
rejectMessage->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
rejectMessage->setBegin(PeerMessageUtil::getIntParam(data, 5));
|
||||
rejectMessage->setLength(PeerMessageUtil::getIntParam(data, 9));
|
||||
return rejectMessage;
|
||||
}
|
||||
|
||||
void RejectMessage::receivedAction() {
|
||||
if(!peer->isFastExtensionEnabled()) {
|
||||
throw new DlAbortEx("%s received while fast extension is disabled",
|
||||
toString().c_str());
|
||||
}
|
||||
// TODO Current implementation does not close a connection even if
|
||||
// a request for this reject message is never sent.
|
||||
RequestSlot slot =
|
||||
peerInteraction->getCorrespondingRequestSlot(index, begin, length);
|
||||
if(RequestSlot::isNull(slot)) {
|
||||
//throw new DlAbortEx("reject recieved, but it is not in the request slots.");
|
||||
} else {
|
||||
peerInteraction->deleteRequestSlot(slot);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const char* RejectMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 13, 4bytes
|
||||
* id --- 16, 1byte
|
||||
* index --- index, 4bytes
|
||||
* begin --- begin, 4bytes
|
||||
* length -- length, 4bytes
|
||||
* total: 17bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 13, ID);
|
||||
PeerMessageUtil::setIntParam(&msg[5], index);
|
||||
PeerMessageUtil::setIntParam(&msg[9], begin);
|
||||
PeerMessageUtil::setIntParam(&msg[13], length);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int RejectMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void RejectMessage::check() const {
|
||||
PeerMessageUtil::checkIndex(index, pieces);
|
||||
PeerMessageUtil::checkBegin(begin, pieceLength);
|
||||
PeerMessageUtil::checkLength(length);
|
||||
PeerMessageUtil::checkRange(begin, length, pieceLength);
|
||||
}
|
||||
|
||||
string RejectMessage::toString() const {
|
||||
return "reject index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||
", length="+Util::itos(length);
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_REJECT_MESSAGE_H_
|
||||
#define _D_REJECT_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class RejectMessage : public SimplePeerMessage {
|
||||
private:
|
||||
int index;
|
||||
int begin;
|
||||
int length;
|
||||
// for check
|
||||
int pieces;
|
||||
int pieceLength;
|
||||
|
||||
char msg[17];
|
||||
public:
|
||||
RejectMessage(int index = 0, int begin = 0, int length = 0)
|
||||
:SimplePeerMessage(),
|
||||
index(index),
|
||||
begin(begin),
|
||||
length(length),
|
||||
pieces(0),
|
||||
pieceLength(0) {}
|
||||
|
||||
virtual ~RejectMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 16
|
||||
};
|
||||
|
||||
int getIndex() const { return index; }
|
||||
void setIndex(int index) { this->index = index; }
|
||||
int getBegin() const { return begin; }
|
||||
void setBegin(int begin) { this->begin = begin; }
|
||||
int getLength() const { return length; }
|
||||
void setLength(int length) { this->length = length; }
|
||||
|
||||
void setPieces(int pieces) {
|
||||
this->pieces = pieces;
|
||||
}
|
||||
int getPieces() const { return pieces;}
|
||||
|
||||
void setPieceLength(int pieceLength) {
|
||||
this->pieceLength = pieceLength;
|
||||
}
|
||||
int getPieceLength() const { return pieceLength;}
|
||||
|
||||
static RejectMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual void check() const;
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
||||
#endif // _D_REJECT_MESSAGE_H_
|
|
@ -1,116 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "RequestMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
RequestMessage* RequestMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 13) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "request", dataLength, 13);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "request", ID);
|
||||
}
|
||||
RequestMessage* requestMessage = new RequestMessage();
|
||||
requestMessage->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
requestMessage->setBegin(PeerMessageUtil::getIntParam(data, 5));
|
||||
requestMessage->setLength(PeerMessageUtil::getIntParam(data, 9));
|
||||
return requestMessage;
|
||||
}
|
||||
|
||||
void RequestMessage::receivedAction() {
|
||||
if(pieceStorage->hasPiece(index) &&
|
||||
(!peer->amChoking ||
|
||||
peer->amChoking && peerInteraction->isInFastSet(index))) {
|
||||
peerInteraction->addMessage(peerInteraction->getPeerMessageFactory()->
|
||||
createPieceMessage(index, begin, length));
|
||||
} else {
|
||||
if(peer->isFastExtensionEnabled()) {
|
||||
peerInteraction->addMessage(peerInteraction->getPeerMessageFactory()->
|
||||
createRejectMessage(index, begin, length));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char* RequestMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 13, 4bytes
|
||||
* id --- 6, 1byte
|
||||
* index --- index, 4bytes
|
||||
* begin --- begin, 4bytes
|
||||
* length --- length, 4bytes
|
||||
* total: 17bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 13, ID);
|
||||
PeerMessageUtil::setIntParam(&msg[5], index);
|
||||
PeerMessageUtil::setIntParam(&msg[9], begin);
|
||||
PeerMessageUtil::setIntParam(&msg[13], length);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int RequestMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void RequestMessage::check() const {
|
||||
PeerMessageUtil::checkIndex(index, pieces);
|
||||
PeerMessageUtil::checkBegin(begin, pieceLength);
|
||||
PeerMessageUtil::checkLength(length);
|
||||
PeerMessageUtil::checkRange(begin, length, pieceLength);
|
||||
}
|
||||
|
||||
string RequestMessage::toString() const {
|
||||
return "request index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||
", length="+Util::itos(length);
|
||||
}
|
||||
|
||||
void RequestMessage::onPush() {
|
||||
RequestSlot requestSlot(index, begin, length, blockIndex);
|
||||
peerInteraction->addRequestSlot(requestSlot);
|
||||
}
|
||||
|
||||
void RequestMessage::onAbortPiece(const Piece& piece) {
|
||||
if(!invalidate &&
|
||||
!inProgress &&
|
||||
this->index == piece.getIndex()) {
|
||||
invalidate = true;
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_REQUEST_MESSAGE_H_
|
||||
#define _D_REQUEST_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class RequestMessage : public SimplePeerMessage {
|
||||
private:
|
||||
int index;
|
||||
int begin;
|
||||
int length;
|
||||
int blockIndex;
|
||||
// for check
|
||||
int pieces;
|
||||
int pieceLength;
|
||||
|
||||
char msg[17];
|
||||
public:
|
||||
RequestMessage(int index = 0, int begin = 0, int length = 0,
|
||||
int blockIndex = 0)
|
||||
:SimplePeerMessage(),
|
||||
index(index),
|
||||
begin(begin),
|
||||
length(length),
|
||||
blockIndex(blockIndex),
|
||||
pieces(0),
|
||||
pieceLength(0) {}
|
||||
|
||||
virtual ~RequestMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 6
|
||||
};
|
||||
|
||||
int getIndex() const { return index; }
|
||||
void setIndex(int index) { this->index = index; }
|
||||
int getBegin() const { return begin; }
|
||||
void setBegin(int begin) { this->begin = begin; }
|
||||
int getLength() const { return length; }
|
||||
void setLength(int length) { this->length = length; }
|
||||
int getBlockIndex() const { return blockIndex; }
|
||||
void setBlockIndex(int blockIndex) { this->blockIndex = blockIndex; }
|
||||
|
||||
void setPieces(int pieces) {
|
||||
this->pieces = pieces;
|
||||
}
|
||||
int getPieces() const { return pieces;}
|
||||
|
||||
void setPieceLength(int pieceLength) {
|
||||
this->pieceLength = pieceLength;
|
||||
}
|
||||
int getPieceLength() const { return pieceLength;}
|
||||
|
||||
static RequestMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual void check() const;
|
||||
virtual string toString() const;
|
||||
virtual void onPush();
|
||||
virtual void onAbortPiece(const Piece& piece);
|
||||
};
|
||||
|
||||
#endif // _D_REQUEST_MESSAGE_H_
|
|
@ -1,64 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "SimplePeerMessage.h"
|
||||
#include "message.h"
|
||||
#include "PeerInteraction.h"
|
||||
|
||||
SimplePeerMessage::SimplePeerMessage():leftDataLength(0) {}
|
||||
|
||||
SimplePeerMessage::~SimplePeerMessage() {}
|
||||
|
||||
void SimplePeerMessage::send() {
|
||||
if(invalidate) {
|
||||
return;
|
||||
}
|
||||
if(sendPredicate() || inProgress) {
|
||||
const char* msg = getMessage();
|
||||
int msgLength = getMessageLength();
|
||||
if(!inProgress) {
|
||||
logger->info(MSG_SEND_PEER_MESSAGE,
|
||||
cuid, peer->ipaddr.c_str(), peer->port, toString().c_str());
|
||||
leftDataLength = getMessageLength();
|
||||
}
|
||||
inProgress = false;
|
||||
int writtenLength = peerInteraction->getPeerConnection()->sendMessage(msg+msgLength-leftDataLength, leftDataLength);
|
||||
if(writtenLength == leftDataLength) {
|
||||
onSendComplete();
|
||||
} else {
|
||||
leftDataLength -= writtenLength;
|
||||
inProgress = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_SIMPLE_PEER_MESSAGE_H_
|
||||
#define _D_SIMPLE_PEER_MESSAGE_H_
|
||||
|
||||
#include "PeerMessage.h"
|
||||
|
||||
class SimplePeerMessage : public PeerMessage {
|
||||
private:
|
||||
int leftDataLength;
|
||||
protected:
|
||||
virtual bool sendPredicate() const { return true; };
|
||||
virtual void onSendComplete() {};
|
||||
public:
|
||||
SimplePeerMessage();
|
||||
virtual ~SimplePeerMessage();
|
||||
|
||||
virtual void send();
|
||||
virtual const char* getMessage() = 0;
|
||||
virtual int getMessageLength() = 0;
|
||||
};
|
||||
|
||||
#endif // _D_SIMPLE_PEER_MESSAGE_H_
|
|
@ -1,83 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "SuggestPieceMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "Util.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
SuggestPieceMessage* SuggestPieceMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 5) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "suggest piece", dataLength, 5);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "suggest piece", ID);
|
||||
}
|
||||
SuggestPieceMessage* suggestPieceMessage = new SuggestPieceMessage();
|
||||
suggestPieceMessage->setIndex(PeerMessageUtil::getIntParam(data, 1));
|
||||
return suggestPieceMessage;
|
||||
}
|
||||
|
||||
void SuggestPieceMessage::receivedAction() {
|
||||
// TODO Current implementation ignores this message.
|
||||
}
|
||||
|
||||
const char* SuggestPieceMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 5, 4bytes
|
||||
* id --- 13, 1byte
|
||||
* piece index --- index, 4bytes
|
||||
* total: 9bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, ID);
|
||||
PeerMessageUtil::setIntParam(&msg[5], index);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int SuggestPieceMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void SuggestPieceMessage::check() const {
|
||||
PeerMessageUtil::checkIndex(index, pieces);
|
||||
}
|
||||
|
||||
string SuggestPieceMessage::toString() const {
|
||||
return "suggest piece index="+Util::itos(index);
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_SUGGEST_PIECE_MESSAGE_H_
|
||||
#define _D_SUGGEST_PIECE_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class SuggestPieceMessage : public SimplePeerMessage {
|
||||
private:
|
||||
int index;
|
||||
// for check
|
||||
int pieces;
|
||||
char msg[9];
|
||||
public:
|
||||
SuggestPieceMessage():SimplePeerMessage(), index(0), pieces(0) {}
|
||||
|
||||
virtual ~SuggestPieceMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 13
|
||||
};
|
||||
|
||||
void setIndex(int index) {
|
||||
this->index = index;
|
||||
}
|
||||
int getIndex() const { return index; }
|
||||
|
||||
void setPieces(int pieces) {
|
||||
this->pieces = pieces;
|
||||
}
|
||||
int getPieces() const { return pieces;}
|
||||
|
||||
static SuggestPieceMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual void check() const;
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
||||
#endif // _D_SUGGEST_PIECE_MESSAGE_H_
|
|
@ -1,83 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "UnchokeMessage.h"
|
||||
#include "PeerInteraction.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include "DlAbortEx.h"
|
||||
|
||||
UnchokeMessage* UnchokeMessage::create(const char* data, int dataLength) {
|
||||
if(dataLength != 1) {
|
||||
throw new DlAbortEx("invalid payload size for %s, size = %d. It should be %d", "unchoke", dataLength, 1);
|
||||
}
|
||||
int id = PeerMessageUtil::getId(data);
|
||||
if(id != ID) {
|
||||
throw new DlAbortEx("invalid ID=%d for %s. It should be %d.",
|
||||
id, "unchoke", ID);
|
||||
}
|
||||
UnchokeMessage* unchokeMessage = new UnchokeMessage();
|
||||
return unchokeMessage;
|
||||
}
|
||||
|
||||
void UnchokeMessage::receivedAction() {
|
||||
peer->peerChoking = false;
|
||||
}
|
||||
|
||||
bool UnchokeMessage::sendPredicate() const {
|
||||
return peer->amChoking;
|
||||
}
|
||||
|
||||
const char* UnchokeMessage::getMessage() {
|
||||
if(!inProgress) {
|
||||
/**
|
||||
* len --- 1, 4bytes
|
||||
* id --- 1, 1byte
|
||||
* total: 5bytes
|
||||
*/
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, ID);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
int UnchokeMessage::getMessageLength() {
|
||||
return sizeof(msg);
|
||||
}
|
||||
|
||||
void UnchokeMessage::onSendComplete() {
|
||||
peer->amChoking = false;
|
||||
}
|
||||
|
||||
string UnchokeMessage::toString() const {
|
||||
return "unchoke";
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_UNCHOKE_MESSAGE_H_
|
||||
#define _D_UNCHOKE_MESSAGE_H_
|
||||
|
||||
#include "SimplePeerMessage.h"
|
||||
|
||||
class UnchokeMessage : public SimplePeerMessage {
|
||||
private:
|
||||
char msg[5];
|
||||
protected:
|
||||
virtual bool sendPredicate() const;
|
||||
virtual void onSendComplete();
|
||||
public:
|
||||
UnchokeMessage():SimplePeerMessage() {}
|
||||
virtual ~UnchokeMessage() {}
|
||||
|
||||
enum ID_t {
|
||||
ID = 1
|
||||
};
|
||||
|
||||
static UnchokeMessage* create(const char* data, int dataLength);
|
||||
|
||||
virtual int getId() const { return ID; }
|
||||
virtual void receivedAction();
|
||||
virtual const char* getMessage();
|
||||
virtual int getMessageLength();
|
||||
virtual string toString() const;
|
||||
};
|
||||
|
||||
#endif // _D_UNCHOKE_MESSAGE_H_
|
|
@ -1,59 +0,0 @@
|
|||
#include "AllowedFastMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class AllowedFastMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(AllowedFastMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(AllowedFastMessageTest);
|
||||
|
||||
void AllowedFastMessageTest::testCreate() {
|
||||
char msg[9];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, 17);
|
||||
PeerMessageUtil::setIntParam(&msg[5], 12345);
|
||||
AllowedFastMessage* pm = AllowedFastMessage::create(&msg[4], 5);
|
||||
CPPUNIT_ASSERT_EQUAL(17, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[10];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 6, 17);
|
||||
AllowedFastMessage::create(&msg[4], 6);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[9];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, 18);
|
||||
AllowedFastMessage::create(&msg[4], 5);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void AllowedFastMessageTest::testGetMessage() {
|
||||
AllowedFastMessage msg;
|
||||
msg.setIndex(12345);
|
||||
char data[9];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 5, 17);
|
||||
PeerMessageUtil::setIntParam(&data[5], 12345);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 9) == 0);
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
#include "BitfieldMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class BitfieldMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(BitfieldMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(BitfieldMessageTest);
|
||||
|
||||
void BitfieldMessageTest::testCreate() {
|
||||
char msg[5+2];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 3, 5);
|
||||
unsigned char bitfield[2];
|
||||
memset(bitfield, 0xff, sizeof(bitfield));
|
||||
memcpy(&msg[5], bitfield, sizeof(bitfield));
|
||||
BitfieldMessage* pm = BitfieldMessage::create(&msg[4], 3);
|
||||
CPPUNIT_ASSERT_EQUAL(5, pm->getId());
|
||||
CPPUNIT_ASSERT(memcmp(bitfield, pm->getBitfield(), sizeof(bitfield)) == 0);
|
||||
CPPUNIT_ASSERT_EQUAL(2, pm->getBitfieldLength());
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 5);
|
||||
BitfieldMessage::create(&msg[4], 1);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[5+2];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 3, 6);
|
||||
BitfieldMessage::create(&msg[4], 3);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void BitfieldMessageTest::testGetMessage() {
|
||||
BitfieldMessage msg;
|
||||
unsigned char bitfield[2];
|
||||
memset(bitfield, 0xff, sizeof(bitfield));
|
||||
msg.setBitfield(bitfield, sizeof(bitfield));
|
||||
char data[5+2];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 3, 5);
|
||||
memcpy(&data[5], bitfield, sizeof(bitfield));
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 7) == 0);
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
#include "CancelMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CancelMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(CancelMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(CancelMessageTest);
|
||||
|
||||
void CancelMessageTest::testCreate() {
|
||||
char msg[17];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 13, 8);
|
||||
PeerMessageUtil::setIntParam(&msg[5], 12345);
|
||||
PeerMessageUtil::setIntParam(&msg[9], 256);
|
||||
PeerMessageUtil::setIntParam(&msg[13], 1024);
|
||||
CancelMessage* pm = CancelMessage::create(&msg[4], 13);
|
||||
CPPUNIT_ASSERT_EQUAL(8, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
|
||||
CPPUNIT_ASSERT_EQUAL(1024, pm->getLength());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[18];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 14, 8);
|
||||
CancelMessage::create(&msg[4], 14);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[17];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 13, 9);
|
||||
CancelMessage::create(&msg[4], 13);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void CancelMessageTest::testGetMessage() {
|
||||
CancelMessage msg;
|
||||
msg.setIndex(12345);
|
||||
msg.setBegin(256);
|
||||
msg.setLength(1024);
|
||||
char data[17];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 13, 8);
|
||||
PeerMessageUtil::setIntParam(&data[5], 12345);
|
||||
PeerMessageUtil::setIntParam(&data[9], 256);
|
||||
PeerMessageUtil::setIntParam(&data[13], 1024);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 17) == 0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#include "ChokeMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class ChokeMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(ChokeMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(ChokeMessageTest);
|
||||
|
||||
void ChokeMessageTest::testCreate() {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 0);
|
||||
PeerMessage* pm = ChokeMessage::create(&msg[4], 1);
|
||||
CPPUNIT_ASSERT_EQUAL(0, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[6];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 2, 0);
|
||||
ChokeMessage::create(&msg[4], 2);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 1);
|
||||
ChokeMessage::create(&msg[4], 1);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void ChokeMessageTest::testGetMessage() {
|
||||
ChokeMessage msg;
|
||||
char data[5];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 1, 0);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 5) == 0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#include "HaveAllMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class HaveAllMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(HaveAllMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(HaveAllMessageTest);
|
||||
|
||||
void HaveAllMessageTest::testCreate() {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 14);
|
||||
PeerMessage* pm = HaveAllMessage::create(&msg[4], 1);
|
||||
CPPUNIT_ASSERT_EQUAL(14, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[6];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 2, 14);
|
||||
HaveAllMessage::create(&msg[4], 2);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 15);
|
||||
HaveAllMessage::create(&msg[4], 1);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void HaveAllMessageTest::testGetMessage() {
|
||||
HaveAllMessage msg;
|
||||
char data[5];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 1, 14);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 5) == 0);
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
#include "HaveMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class HaveMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(HaveMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(HaveMessageTest);
|
||||
|
||||
void HaveMessageTest::testCreate() {
|
||||
char msg[9];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, 4);
|
||||
PeerMessageUtil::setIntParam(&msg[5], 12345);
|
||||
HaveMessage* pm = HaveMessage::create(&msg[4], 5);
|
||||
CPPUNIT_ASSERT_EQUAL(4, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[10];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 6, 4);
|
||||
HaveMessage::create(&msg[4], 2);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[9];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, 5);
|
||||
HaveMessage::create(&msg[4], 1);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void HaveMessageTest::testGetMessage() {
|
||||
HaveMessage msg;
|
||||
msg.setIndex(12345);
|
||||
char data[9];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 5, 4);
|
||||
PeerMessageUtil::setIntParam(&data[5], 12345);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 9) == 0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#include "HaveNoneMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class HaveNoneMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(HaveNoneMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(HaveNoneMessageTest);
|
||||
|
||||
void HaveNoneMessageTest::testCreate() {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 15);
|
||||
PeerMessage* pm = HaveNoneMessage::create(&msg[4], 1);
|
||||
CPPUNIT_ASSERT_EQUAL(15, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[6];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 2, 15);
|
||||
HaveNoneMessage::create(&msg[4], 2);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 16);
|
||||
HaveNoneMessage::create(&msg[4], 1);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void HaveNoneMessageTest::testGetMessage() {
|
||||
HaveNoneMessage msg;
|
||||
char data[5];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 1, 15);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 5) == 0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#include "InterestedMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class InterestedMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(InterestedMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(InterestedMessageTest);
|
||||
|
||||
void InterestedMessageTest::testCreate() {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 2);
|
||||
PeerMessage* pm = InterestedMessage::create(&msg[4], 1);
|
||||
CPPUNIT_ASSERT_EQUAL(2, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[6];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 2, 2);
|
||||
InterestedMessage::create(&msg[4], 2);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 3);
|
||||
InterestedMessage::create(&msg[4], 1);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void InterestedMessageTest::testGetMessage() {
|
||||
InterestedMessage msg;
|
||||
char data[5];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 1, 2);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 5) == 0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#include "NotInterestedMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class NotInterestedMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(NotInterestedMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(NotInterestedMessageTest);
|
||||
|
||||
void NotInterestedMessageTest::testCreate() {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 3);
|
||||
PeerMessage* pm = NotInterestedMessage::create(&msg[4], 1);
|
||||
CPPUNIT_ASSERT_EQUAL(3, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[6];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 2, 3);
|
||||
NotInterestedMessage::create(&msg[4], 2);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 4);
|
||||
NotInterestedMessage::create(&msg[4], 1);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void NotInterestedMessageTest::testGetMessage() {
|
||||
NotInterestedMessage msg;
|
||||
char data[5];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 1, 3);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 5) == 0);
|
||||
}
|
|
@ -1,14 +1,5 @@
|
|||
#include "PeerMessageUtil.h"
|
||||
#include "UnchokeMessage.h"
|
||||
#include "InterestedMessage.h"
|
||||
#include "NotInterestedMessage.h"
|
||||
#include "HaveMessage.h"
|
||||
#include "BitfieldMessage.h"
|
||||
#include "RequestMessage.h"
|
||||
#include "PieceMessage.h"
|
||||
#include "CancelMessage.h"
|
||||
#include <netinet/in.h>
|
||||
#include <string>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
@ -16,9 +7,6 @@ using namespace std;
|
|||
class PeerMessageUtilTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(PeerMessageUtilTest);
|
||||
CPPUNIT_TEST(testCheckIntegrityHave);
|
||||
CPPUNIT_TEST(testCheckIntegrityBitfield);
|
||||
CPPUNIT_TEST(testCheckIntegrityRequest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
|
@ -26,18 +14,6 @@ public:
|
|||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreatePeerMessageUnchoke();
|
||||
void testCreatePeerMessageInterested();
|
||||
void testCreatePeerMessageNotInterested();
|
||||
void testCreatePeerMessageHave();
|
||||
void testCreatePeerMessageBitfield();
|
||||
void testCreatePeerMessageRequest();
|
||||
void testCreatePeerMessagePiece();
|
||||
void testCreatePeerMessageCancel();
|
||||
void testCreatePortMessage();
|
||||
void testCheckIntegrityHave();
|
||||
void testCheckIntegrityBitfield();
|
||||
void testCheckIntegrityRequest();
|
||||
};
|
||||
|
||||
|
||||
|
@ -58,117 +34,3 @@ void createNLengthMessage(char* msg, int msgLen, int payloadLen, int id) {
|
|||
setIntParam(msg, payloadLen);
|
||||
msg[4] = (char)id;
|
||||
}
|
||||
|
||||
void PeerMessageUtilTest::testCheckIntegrityHave() {
|
||||
HaveMessage* pm = new HaveMessage();
|
||||
pm->setIndex(119);
|
||||
pm->setPieces(120);
|
||||
try {
|
||||
pm->check();
|
||||
} catch(Exception* ex) {
|
||||
cerr << ex->getMsg() << endl;
|
||||
CPPUNIT_FAIL("");
|
||||
}
|
||||
|
||||
pm->setIndex(120);
|
||||
try {
|
||||
pm->check();
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {}
|
||||
}
|
||||
|
||||
|
||||
void PeerMessageUtilTest::testCheckIntegrityBitfield() {
|
||||
BitfieldMessage* pm = new BitfieldMessage();
|
||||
int bitfieldLength = 15;
|
||||
unsigned char* bitfield = new unsigned char[bitfieldLength];
|
||||
memset(bitfield, 0xff, bitfieldLength);
|
||||
pm->setBitfield(bitfield, bitfieldLength);
|
||||
pm->setPieces(120);
|
||||
try {
|
||||
pm->check();
|
||||
} catch(Exception* ex) {
|
||||
cerr << ex->getMsg() << endl;
|
||||
CPPUNIT_FAIL("");
|
||||
}
|
||||
delete [] bitfield;
|
||||
bitfieldLength = 16;
|
||||
bitfield = new unsigned char[bitfieldLength];
|
||||
memset(bitfield, 0xff, bitfieldLength);
|
||||
pm->setBitfield(bitfield, bitfieldLength);
|
||||
try {
|
||||
pm->check();
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(Exception* ex) {
|
||||
}
|
||||
delete [] bitfield;
|
||||
bitfieldLength = 14;
|
||||
bitfield = new unsigned char[bitfieldLength];
|
||||
memset(bitfield, 0xff, bitfieldLength);
|
||||
pm->setBitfield(bitfield, bitfieldLength);
|
||||
try {
|
||||
pm->check();
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(Exception* ex) {
|
||||
}
|
||||
delete [] bitfield;
|
||||
bitfieldLength = 15;
|
||||
bitfield = new unsigned char[bitfieldLength];
|
||||
memset(bitfield, 0xff, bitfieldLength);
|
||||
bitfield[bitfieldLength-1] &= 0xfe;
|
||||
pm->setBitfield(bitfield, bitfieldLength);
|
||||
pm->setPieces(119);
|
||||
try {
|
||||
pm->check();
|
||||
} catch(Exception* ex) {
|
||||
cerr << ex->getMsg() << endl;
|
||||
CPPUNIT_FAIL("");
|
||||
}
|
||||
delete [] bitfield;
|
||||
bitfieldLength = 15;
|
||||
bitfield = new unsigned char[bitfieldLength];
|
||||
memset(bitfield, 0xff, bitfieldLength);
|
||||
pm->setBitfield(bitfield, bitfieldLength);
|
||||
try {
|
||||
pm->check();
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(Exception* ex) {
|
||||
}
|
||||
delete [] bitfield;
|
||||
}
|
||||
|
||||
void PeerMessageUtilTest::testCheckIntegrityRequest() {
|
||||
RequestMessage* pm = new RequestMessage();
|
||||
pm->setIndex(119);
|
||||
pm->setBegin(0);
|
||||
pm->setLength(16*1024);
|
||||
pm->setPieces(120);
|
||||
pm->setPieceLength(256*1024);
|
||||
try {
|
||||
pm->check();
|
||||
} catch(Exception* ex) {
|
||||
cerr << ex->getMsg() << endl;
|
||||
CPPUNIT_FAIL("");
|
||||
}
|
||||
|
||||
pm->setBegin(256*1024);
|
||||
pm->setLength(16*1024);
|
||||
try {
|
||||
pm->check();
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(Exception* ex) {}
|
||||
|
||||
pm->setBegin(0);
|
||||
pm->setLength(256*1024);
|
||||
try {
|
||||
pm->check();
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(Exception* ex) {}
|
||||
|
||||
pm->setBegin(0);
|
||||
pm->setLength(5);
|
||||
try {
|
||||
pm->check();
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(Exception* ex) {}
|
||||
}
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
#include "PieceMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class PieceMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(PieceMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessageHeader);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessageHeader();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(PieceMessageTest);
|
||||
|
||||
void PieceMessageTest::testCreate() {
|
||||
char msg[13+2];
|
||||
char data[2];
|
||||
memset(data, 0xff, sizeof(data));
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 11, 7);
|
||||
PeerMessageUtil::setIntParam(&msg[5], 12345);
|
||||
PeerMessageUtil::setIntParam(&msg[9], 256);
|
||||
memcpy(&msg[13], data, sizeof(data));
|
||||
PieceMessage* pm = PieceMessage::create(&msg[4], 11);
|
||||
CPPUNIT_ASSERT_EQUAL(7, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
|
||||
CPPUNIT_ASSERT(memcmp(data, pm->getBlock(), sizeof(data)) == 0);
|
||||
CPPUNIT_ASSERT_EQUAL(2, pm->getBlockLength());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[13];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 9, 7);
|
||||
PieceMessage::create(&msg[4], 9);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[13+2];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 11, 8);
|
||||
PieceMessage::create(&msg[4], 11);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void PieceMessageTest::testGetMessageHeader() {
|
||||
PieceMessage msg;
|
||||
msg.setIndex(12345);
|
||||
msg.setBegin(256);
|
||||
msg.setBlockLength(1024);
|
||||
char data[13];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 9+1024, 7);
|
||||
PeerMessageUtil::setIntParam(&data[5], 12345);
|
||||
PeerMessageUtil::setIntParam(&data[9], 256);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessageHeader(), data, 13) == 0);
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
#include "RejectMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class RejectMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(RejectMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(RejectMessageTest);
|
||||
|
||||
void RejectMessageTest::testCreate() {
|
||||
char msg[17];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 13, 16);
|
||||
PeerMessageUtil::setIntParam(&msg[5], 12345);
|
||||
PeerMessageUtil::setIntParam(&msg[9], 256);
|
||||
PeerMessageUtil::setIntParam(&msg[13], 1024);
|
||||
RejectMessage* pm = RejectMessage::create(&msg[4], 13);
|
||||
CPPUNIT_ASSERT_EQUAL(16, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
|
||||
CPPUNIT_ASSERT_EQUAL(1024, pm->getLength());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[18];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 14, 16);
|
||||
RejectMessage::create(&msg[4], 14);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[17];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 13, 17);
|
||||
RejectMessage::create(&msg[4], 13);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void RejectMessageTest::testGetMessage() {
|
||||
RejectMessage msg;
|
||||
msg.setIndex(12345);
|
||||
msg.setBegin(256);
|
||||
msg.setLength(1024);
|
||||
char data[17];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 13, 16);
|
||||
PeerMessageUtil::setIntParam(&data[5], 12345);
|
||||
PeerMessageUtil::setIntParam(&data[9], 256);
|
||||
PeerMessageUtil::setIntParam(&data[13], 1024);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 17) == 0);
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
#include "RequestMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class RequestMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(RequestMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(RequestMessageTest);
|
||||
|
||||
void RequestMessageTest::testCreate() {
|
||||
char msg[17];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 13, 6);
|
||||
PeerMessageUtil::setIntParam(&msg[5], 12345);
|
||||
PeerMessageUtil::setIntParam(&msg[9], 256);
|
||||
PeerMessageUtil::setIntParam(&msg[13], 1024);
|
||||
RequestMessage* pm = RequestMessage::create(&msg[4], 13);
|
||||
CPPUNIT_ASSERT_EQUAL(6, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex());
|
||||
CPPUNIT_ASSERT_EQUAL(256, pm->getBegin());
|
||||
CPPUNIT_ASSERT_EQUAL(1024, pm->getLength());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[18];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 14, 6);
|
||||
RequestMessage::create(&msg[4], 14);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[17];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 13, 7);
|
||||
RequestMessage::create(&msg[4], 13);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void RequestMessageTest::testGetMessage() {
|
||||
RequestMessage msg;
|
||||
msg.setIndex(12345);
|
||||
msg.setBegin(256);
|
||||
msg.setLength(1024);
|
||||
char data[17];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 13, 6);
|
||||
PeerMessageUtil::setIntParam(&data[5], 12345);
|
||||
PeerMessageUtil::setIntParam(&data[9], 256);
|
||||
PeerMessageUtil::setIntParam(&data[13], 1024);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 17) == 0);
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
#include "SuggestPieceMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class SuggestPieceMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(SuggestPieceMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(SuggestPieceMessageTest);
|
||||
|
||||
void SuggestPieceMessageTest::testCreate() {
|
||||
char msg[9];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, 13);
|
||||
PeerMessageUtil::setIntParam(&msg[5], 12345);
|
||||
SuggestPieceMessage* pm = SuggestPieceMessage::create(&msg[4], 5);
|
||||
CPPUNIT_ASSERT_EQUAL(13, pm->getId());
|
||||
CPPUNIT_ASSERT_EQUAL(12345, pm->getIndex());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[10];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 6, 13);
|
||||
SuggestPieceMessage::create(&msg[4], 2);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[9];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 5, 14);
|
||||
SuggestPieceMessage::create(&msg[4], 1);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void SuggestPieceMessageTest::testGetMessage() {
|
||||
SuggestPieceMessage msg;
|
||||
msg.setIndex(12345);
|
||||
char data[9];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 5, 13);
|
||||
PeerMessageUtil::setIntParam(&data[5], 12345);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 9) == 0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#include "UnchokeMessage.h"
|
||||
#include "PeerMessageUtil.h"
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class UnchokeMessageTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(UnchokeMessageTest);
|
||||
CPPUNIT_TEST(testCreate);
|
||||
CPPUNIT_TEST(testGetMessage);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
private:
|
||||
|
||||
public:
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
void testCreate();
|
||||
void testGetMessage();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(UnchokeMessageTest);
|
||||
|
||||
void UnchokeMessageTest::testCreate() {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 1);
|
||||
PeerMessage* pm = UnchokeMessage::create(&msg[4], 1);
|
||||
CPPUNIT_ASSERT_EQUAL(1, pm->getId());
|
||||
|
||||
// case: payload size is wrong
|
||||
try {
|
||||
char msg[6];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 2, 1);
|
||||
UnchokeMessage::create(&msg[4], 2);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
// case: id is wrong
|
||||
try {
|
||||
char msg[5];
|
||||
PeerMessageUtil::createPeerMessageString(msg, sizeof(msg), 1, 2);
|
||||
UnchokeMessage::create(&msg[4], 1);
|
||||
CPPUNIT_FAIL("exception must be threw.");
|
||||
} catch(...) {
|
||||
}
|
||||
}
|
||||
|
||||
void UnchokeMessageTest::testGetMessage() {
|
||||
UnchokeMessage msg;
|
||||
char data[5];
|
||||
PeerMessageUtil::createPeerMessageString(data, sizeof(data), 1, 1);
|
||||
CPPUNIT_ASSERT(memcmp(msg.getMessage(), data, 5) == 0);
|
||||
}
|
Loading…
Reference in New Issue