* src/PeerInteractionCommand.h

(checkInactiveConnection): Removed.
	* src/PeerInteractionCommand.cc
	(executeInternal): Removed following function calls:
	detectMessageFlooding(), checkLongTimePeerChoking and
	checkInactiveConnection().
	(checkInactiveConnection): Removed.
	(detectMessageFlooding): Removed function call to
	checkInactiveConnection().

	* src/PeerMessageUtil.h
	(createChokeMessage): New function. Overload.
	(createUnchokeMessage): New function. Overload.
	(createInterestedMessage): New function. Overload.
	(createNotInterestedMessage): New function. Overload.
	(createHaveMessage): New function. Overload.
	(createBitfieldMessage): New function. Overload.
	(createRequestMessage): New function. Overload.
	(createCancelMessage): New function. Overload.
	(createPieceMessage): New function. Overload.
	(createKeepAliveMessage): New function. Overload.
	* src/PeerMessageUtil.cc
	(createChokeMessage): New function. Overload.
	(createUnchokeMessage): New function. Overload.
	(createInterestedMessage): New function. Overload.
	(createNotInterestedMessage): New function. Overload.
	(createHaveMessage): New function. Overload.
	(createBitfieldMessage): New function. Overload.
	(createRequestMessage): New function. Overload.
	(createCancelMessage): New function. Overload.
	(createPieceMessage): New function. Overload.
	(createKeepAliveMessage): New function. Overload.

	* src/SendMessageQueue.cc
	(createRequestMessage): Use PeerMessageUtil.
	(createCancelMessage): Use PeerMessageUtil.
	(createPieceMessage): Use PeerMessageUtil.
	(createHaveMessage): Use PeerMessageUtil.
	(createChokeMessage): Use PeerMessageUtil.
	(createUnchokeMessage): Use PeerMessageUtil.
	(createInterestedMessage): Use PeerMessageUtil.
	(createNotInterestedMessage): Use PeerMessageUtil.
	(createBitfieldMessage): Use PeerMessageUtil.
	(createKeepAliveMessage): Use PeerMessageUtil.
pull/1/head
Tatsuhiro Tsujikawa 2006-05-10 12:30:26 +00:00
parent ebfdbefb7f
commit ef6c1d53a3
7 changed files with 147 additions and 39 deletions

View File

@ -1,3 +1,50 @@
2006-05-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/PeerInteractionCommand.h
(checkInactiveConnection): Removed.
* src/PeerInteractionCommand.cc
(executeInternal): Removed following function calls:
detectMessageFlooding(), checkLongTimePeerChoking and
checkInactiveConnection().
(checkInactiveConnection): Removed.
(detectMessageFlooding): Removed function call to
checkInactiveConnection().
* src/PeerMessageUtil.h
(createChokeMessage): New function. Overload.
(createUnchokeMessage): New function. Overload.
(createInterestedMessage): New function. Overload.
(createNotInterestedMessage): New function. Overload.
(createHaveMessage): New function. Overload.
(createBitfieldMessage): New function. Overload.
(createRequestMessage): New function. Overload.
(createCancelMessage): New function. Overload.
(createPieceMessage): New function. Overload.
(createKeepAliveMessage): New function. Overload.
* src/PeerMessageUtil.cc
(createChokeMessage): New function. Overload.
(createUnchokeMessage): New function. Overload.
(createInterestedMessage): New function. Overload.
(createNotInterestedMessage): New function. Overload.
(createHaveMessage): New function. Overload.
(createBitfieldMessage): New function. Overload.
(createRequestMessage): New function. Overload.
(createCancelMessage): New function. Overload.
(createPieceMessage): New function. Overload.
(createKeepAliveMessage): New function. Overload.
* src/SendMessageQueue.cc
(createRequestMessage): Use PeerMessageUtil.
(createCancelMessage): Use PeerMessageUtil.
(createPieceMessage): Use PeerMessageUtil.
(createHaveMessage): Use PeerMessageUtil.
(createChokeMessage): Use PeerMessageUtil.
(createUnchokeMessage): Use PeerMessageUtil.
(createInterestedMessage): Use PeerMessageUtil.
(createNotInterestedMessage): Use PeerMessageUtil.
(createBitfieldMessage): Use PeerMessageUtil.
(createKeepAliveMessage): Use PeerMessageUtil.
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Each peer message has its own class.

1
TODO
View File

@ -15,3 +15,4 @@
* Add Message stream encryption support
* Add announce-list support
* Add fast extension
* Refacturing HttpConnection and FtpConnection

View File

@ -105,9 +105,6 @@ bool PeerInteractionCommand::executeInternal() {
break;
}
case WIRED:
detectMessageFlooding();
checkLongTimePeerChoking();
checkInactiveConnection();
sendMessageQueue->syncPiece();
decideChoking();
for(int i = 0; i < 10; i++) {
@ -128,16 +125,6 @@ bool PeerInteractionCommand::executeInternal() {
return false;
}
void PeerInteractionCommand::checkInactiveConnection() {
if((!peer->amInterested && !peer->peerInterested &&
e->torrentMan->connections >= MAX_PEER_LIST_SIZE) ||
(!peer->amInterested && e->torrentMan->connections >= MAX_PEER_LIST_SIZE &&
e->torrentMan->isEndGame())) {
throw new DlAbortEx("marked as inactive connection.");
}
}
void PeerInteractionCommand::detectMessageFlooding() {
struct timeval now;
gettimeofday(&now, NULL);
@ -271,7 +258,6 @@ void PeerInteractionCommand::beforeSocketCheck() {
e->torrentMan->unadvertisePiece(cuid);
detectMessageFlooding();
checkLongTimePeerChoking();
checkInactiveConnection();
PieceIndexes indexes = e->torrentMan->getAdvertisedPieceIndexes(cuid);
if(indexes.size() >= 20) {

View File

@ -44,7 +44,6 @@ private:
void receiveMessage();
void detectMessageFlooding();
void checkLongTimePeerChoking();
void checkInactiveConnection();
void detectTimeoutAndDuplicateBlock();
void decideChoking();
void keepAlive();

View File

@ -132,6 +132,70 @@ PortMessage* PeerMessageUtil::createPortMessage(const char* msg, int len) {
return portMessage;
}
RequestMessage* PeerMessageUtil::createRequestMessage(int index,
int begin,
int length,
int blockIndex) {
RequestMessage* msg = new RequestMessage();
msg->setIndex(index);
msg->setBegin(begin);
msg->setLength(length);
msg->setBlockIndex(blockIndex);
return msg;
}
CancelMessage* PeerMessageUtil::createCancelMessage(int index, int begin, int length) {
CancelMessage* msg = new CancelMessage();
msg->setIndex(index);
msg->setBegin(begin);
msg->setLength(length);
return msg;
}
PieceMessage* PeerMessageUtil::createPieceMessage(int index, int begin, int length) {
PieceMessage* msg = new PieceMessage();
msg->setIndex(index);
msg->setBegin(begin);
msg->setBlockLength(length);
return msg;
}
HaveMessage* PeerMessageUtil::createHaveMessage(int index) {
HaveMessage* msg = new HaveMessage();
msg->setIndex(index);
return msg;
}
ChokeMessage* PeerMessageUtil::createChokeMessage() {
ChokeMessage* msg = new ChokeMessage();
return msg;
}
UnchokeMessage* PeerMessageUtil::createUnchokeMessage() {
UnchokeMessage* msg = new UnchokeMessage();
return msg;
}
InterestedMessage* PeerMessageUtil::createInterestedMessage() {
InterestedMessage* msg = new InterestedMessage();
return msg;
}
NotInterestedMessage* PeerMessageUtil::createNotInterestedMessage() {
NotInterestedMessage* msg = new NotInterestedMessage();
return msg;
}
BitfieldMessage* PeerMessageUtil::createBitfieldMessage() {
BitfieldMessage* msg = new BitfieldMessage();
return msg;
}
KeepAliveMessage* PeerMessageUtil::createKeepAliveMessage() {
KeepAliveMessage* msg = new KeepAliveMessage();
return msg;
}
void PeerMessageUtil::checkIndex(int index, int pieces) {
if(!(0 <= index && index < pieces)) {
throw new DlAbortEx("invalid index = %d", index);

View File

@ -50,7 +50,8 @@ public:
static ChokeMessage* createChokeMessage(const char* msg, int len);
static UnchokeMessage* createUnchokeMessage(const char* msg, int len);
static InterestedMessage* createInterestedMessage(const char* msg, int len);
static NotInterestedMessage* createNotInterestedMessage(const char* msg, int len);
static NotInterestedMessage* createNotInterestedMessage(const char* msg,
int len);
static HaveMessage* createHaveMessage(const char* msg, int len);
static BitfieldMessage* createBitfieldMessage(const char* msg, int len);
static RequestMessage* createRequestMessage(const char* msg, int len);
@ -58,14 +59,29 @@ public:
static PieceMessage* createPieceMessage(const char* msg, int len);
static PortMessage* createPortMessage(const char* msg, int len);
static ChokeMessage* createChokeMessage();
static UnchokeMessage* createUnchokeMessage();
static InterestedMessage* createInterestedMessage();
static NotInterestedMessage* createNotInterestedMessage();
static HaveMessage* createHaveMessage(int index);
static BitfieldMessage* createBitfieldMessage();
static RequestMessage* createRequestMessage(int index, int begin,
int length, int blockIndex);
static CancelMessage* createCancelMessage(int index, int begin, int length);
static PieceMessage* createPieceMessage(int index, int begin, int length);
static KeepAliveMessage* createKeepAliveMessage();
static void checkIndex(int index, int pieces);
static void checkBegin(int begin, int pieceLength);
static void checkLength(int length);
static void checkRange(int begin, int length, int pieceLength);
static void checkBitfield(const unsigned char* bitfield, int bitfieldLength, int pieces);
static void checkBitfield(const unsigned char* bitfield,
int bitfieldLength,
int pieces);
static HandshakeMessage* createHandshakeMessage(const char* msg, int length);
static void checkHandshake(const HandshakeMessage* message, const unsigned char* infoHash);
static void checkHandshake(const HandshakeMessage* message,
const unsigned char* infoHash);
};
#endif // _D_PEER_MESSAGE_UTIL_H_

View File

@ -395,72 +395,67 @@ void SendMessageQueue::setPeerMessageCommonProperty(PeerMessage* peerMessage) {
}
RequestMessage* SendMessageQueue::createRequestMessage(int blockIndex) {
RequestMessage* msg = new RequestMessage();
RequestMessage* msg =
PeerMessageUtil::createRequestMessage(piece.getIndex(),
blockIndex*piece.getBlockLength(),
piece.getBlockLength(blockIndex),
blockIndex);
setPeerMessageCommonProperty(msg);
msg->setIndex(piece.getIndex());
msg->setBegin(blockIndex*piece.getBlockLength());
msg->setLength(piece.getBlockLength(blockIndex));
msg->setBlockIndex(blockIndex);
return msg;
}
CancelMessage* SendMessageQueue::createCancelMessage(int index, int begin, int length) {
CancelMessage* msg = new CancelMessage();
CancelMessage* msg =
PeerMessageUtil::createCancelMessage(index, begin, length);
setPeerMessageCommonProperty(msg);
msg->setIndex(index);
msg->setBegin(begin);
msg->setLength(length);
return msg;
}
PieceMessage* SendMessageQueue::createPieceMessage(int index, int begin, int length) {
PieceMessage* msg = new PieceMessage();
PieceMessage* msg =
PeerMessageUtil::createPieceMessage(index, begin, length);
setPeerMessageCommonProperty(msg);
msg->setIndex(index);
msg->setBegin(begin);
msg->setBlockLength(length);
return msg;
}
HaveMessage* SendMessageQueue::createHaveMessage(int index) {
HaveMessage* msg = new HaveMessage();
HaveMessage* msg = PeerMessageUtil::createHaveMessage(index);
setPeerMessageCommonProperty(msg);
msg->setIndex(index);
return msg;
}
ChokeMessage* SendMessageQueue::createChokeMessage() {
ChokeMessage* msg = new ChokeMessage();
ChokeMessage* msg = PeerMessageUtil::createChokeMessage();
setPeerMessageCommonProperty(msg);
return msg;
}
UnchokeMessage* SendMessageQueue::createUnchokeMessage() {
UnchokeMessage* msg = new UnchokeMessage();
UnchokeMessage* msg = PeerMessageUtil::createUnchokeMessage();
setPeerMessageCommonProperty(msg);
return msg;
}
InterestedMessage* SendMessageQueue::createInterestedMessage() {
InterestedMessage* msg = new InterestedMessage();
InterestedMessage* msg = PeerMessageUtil::createInterestedMessage();
setPeerMessageCommonProperty(msg);
return msg;
}
NotInterestedMessage* SendMessageQueue::createNotInterestedMessage() {
NotInterestedMessage* msg = new NotInterestedMessage();
NotInterestedMessage* msg = PeerMessageUtil::createNotInterestedMessage();
setPeerMessageCommonProperty(msg);
return msg;
}
BitfieldMessage* SendMessageQueue::createBitfieldMessage() {
BitfieldMessage* msg = new BitfieldMessage();
BitfieldMessage* msg = PeerMessageUtil::createBitfieldMessage();
setPeerMessageCommonProperty(msg);
return msg;
}
KeepAliveMessage* SendMessageQueue::createKeepAliveMessage() {
KeepAliveMessage* msg = new KeepAliveMessage();
KeepAliveMessage* msg = PeerMessageUtil::createKeepAliveMessage();
setPeerMessageCommonProperty(msg);
return msg;
}