2006-03-21 14:12:51 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - a simple utility for downloading files faster
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "PeerInteractionCommand.h"
|
|
|
|
#include "PeerInitiateConnectionCommand.h"
|
|
|
|
#include "PeerMessageUtil.h"
|
2006-07-28 14:06:47 +00:00
|
|
|
#include "HandshakeMessage.h"
|
|
|
|
#include "KeepAliveMessage.h"
|
|
|
|
#include "ChokeMessage.h"
|
|
|
|
#include "UnchokeMessage.h"
|
|
|
|
#include "HaveMessage.h"
|
2006-03-21 14:12:51 +00:00
|
|
|
#include "DlAbortEx.h"
|
|
|
|
#include "Util.h"
|
|
|
|
#include "message.h"
|
Added new class SendMessageQueue that includes PendingMessages
and
RequestSlotMan.
* src/SendMessageQueue.h: New class.
* src/SendMessageQueue.cc: New class.
* src/PendingMessage.h: Added new member variable blockIndex and
its
accessors.
(createRequestMessage): Updated.
* src/PendingMessage.cc (createRequestMessage): Updated.
* src/PeerInteractionCommand.cc (executeInternal): Updated with
SendMessageQueue.
(checkLongTimePeerChoking): Updated with SendMessageQueue.
(receiveMessage): Updated with SendMessageQueue.
(deletePendingPieceMessage): Removed.
(getNewPieceAndSendInterest): Updated with SendMessageQueue.
(sendInterest): Updated with SendMessageQueue.
(createRequestPendingMessage): Updated with SendMessageQueue.
(sendMessages): Updated with SendMessageQueue.
(onAbort): Updated with SendMessageQueue.
(keepAlive): Updated with SendMessageQueue.
(beforeSocketCheck): Updated SendMessageQueue.
* src/PeerInteractionCommand (sendMessages): Shuffle
missingBLockIndexes before using it.
Added its own timeout for peer connection.
* src/PeerAbstractCommand.h: Added member variable timeout and
its
setter.
* src/prefs.h: Added PREF_PEER_CONNECTION_TIMEOUT.
* src/PeerInteractionCommand.cc (PeerInteractionCommand):
Added setTimeout() call.
(executeInternal): Added setTimeout() call.
* src/PeerAbstractCommand.cc (PeerAbstractCommand):
Added timeout.
(isTimeoutDetected): Updated.
* src/main.cc (main): Added PREF_PEER_CONNECTION_TIMEOUT entry
to
option.
Added *simple* message flooding checker.
* src/PeerInteractionCommand.cc (executeInternal):
Added detectMessageFlooding() call.
(detectMessageFlooding): New function.
(receiveMessage): Count up CHOKE, UNCHOKE, HAVE message.
(beforeSocketCheck): Added detectMessageFlooding() call.
* src/PeerInteractionCommand.h: Added sendMessageQueue,
chokeUnchokeCount, haveCount, detectMessageFlooding().
Removed deletePendingPieceMessage(), getRequestSlot(),
deleteRequestSlot(), deleteAllRequestSlot().
* src/PeerInteractionCommand.cc (beforeSocketCheck):
Added checkLongTimePeerChoking() call.
* src/RequestSlotMan.h: Renamed deleteTimeoutRequestSlot().
* src/TorrentMan.cc (addPeer): Delete at most MAX_PEER_LIST_SIZE
peers
if duplicate == false.
The parameter "uploaded" and "downloaded" in the tracker request
are
the size since the client sent the "started" event to the
tracker.
* src/TorrentMan.cc (setup): Assigned saved downloaded Size and
uploaded size to preDownloadedSize, preUploadedSize
respectively.
* src/TorrentMan.h: Added preDownloadedSize, preUploadedSize,
getSessionDownloadedSize(), getSessionUploadedSize().
* src/TrackerInitCommand.cc (execute): Use
getSessionDownloadedSize(),
getSessionUploadedSize() instead of getDownloadedSize(),
getUploadedSize().
* src/PendingMessage.cc (processMessage): Do not send request
message
if the peer is choking the client.
* src/TrackerUpdateCommand.cc (execute): Check wtheher
minInterval is
less than interval.
2006-03-28 15:23:51 +00:00
|
|
|
#include "prefs.h"
|
|
|
|
#include <algorithm>
|
2006-03-21 14:12:51 +00:00
|
|
|
|
2006-07-19 17:07:45 +00:00
|
|
|
PeerInteractionCommand::PeerInteractionCommand(int cuid,
|
|
|
|
const PeerHandle& p,
|
2006-03-21 14:12:51 +00:00
|
|
|
TorrentDownloadEngine* e,
|
2006-07-19 17:07:45 +00:00
|
|
|
const SocketHandle& s,
|
|
|
|
int sequence)
|
|
|
|
:PeerAbstractCommand(cuid, p, e, s), sequence(sequence) {
|
2006-03-21 14:12:51 +00:00
|
|
|
if(sequence == INITIATOR_SEND_HANDSHAKE) {
|
2006-07-19 17:07:45 +00:00
|
|
|
disableReadCheckSocket();
|
2006-03-21 14:12:51 +00:00
|
|
|
setWriteCheckSocket(socket);
|
Added new class SendMessageQueue that includes PendingMessages
and
RequestSlotMan.
* src/SendMessageQueue.h: New class.
* src/SendMessageQueue.cc: New class.
* src/PendingMessage.h: Added new member variable blockIndex and
its
accessors.
(createRequestMessage): Updated.
* src/PendingMessage.cc (createRequestMessage): Updated.
* src/PeerInteractionCommand.cc (executeInternal): Updated with
SendMessageQueue.
(checkLongTimePeerChoking): Updated with SendMessageQueue.
(receiveMessage): Updated with SendMessageQueue.
(deletePendingPieceMessage): Removed.
(getNewPieceAndSendInterest): Updated with SendMessageQueue.
(sendInterest): Updated with SendMessageQueue.
(createRequestPendingMessage): Updated with SendMessageQueue.
(sendMessages): Updated with SendMessageQueue.
(onAbort): Updated with SendMessageQueue.
(keepAlive): Updated with SendMessageQueue.
(beforeSocketCheck): Updated SendMessageQueue.
* src/PeerInteractionCommand (sendMessages): Shuffle
missingBLockIndexes before using it.
Added its own timeout for peer connection.
* src/PeerAbstractCommand.h: Added member variable timeout and
its
setter.
* src/prefs.h: Added PREF_PEER_CONNECTION_TIMEOUT.
* src/PeerInteractionCommand.cc (PeerInteractionCommand):
Added setTimeout() call.
(executeInternal): Added setTimeout() call.
* src/PeerAbstractCommand.cc (PeerAbstractCommand):
Added timeout.
(isTimeoutDetected): Updated.
* src/main.cc (main): Added PREF_PEER_CONNECTION_TIMEOUT entry
to
option.
Added *simple* message flooding checker.
* src/PeerInteractionCommand.cc (executeInternal):
Added detectMessageFlooding() call.
(detectMessageFlooding): New function.
(receiveMessage): Count up CHOKE, UNCHOKE, HAVE message.
(beforeSocketCheck): Added detectMessageFlooding() call.
* src/PeerInteractionCommand.h: Added sendMessageQueue,
chokeUnchokeCount, haveCount, detectMessageFlooding().
Removed deletePendingPieceMessage(), getRequestSlot(),
deleteRequestSlot(), deleteAllRequestSlot().
* src/PeerInteractionCommand.cc (beforeSocketCheck):
Added checkLongTimePeerChoking() call.
* src/RequestSlotMan.h: Renamed deleteTimeoutRequestSlot().
* src/TorrentMan.cc (addPeer): Delete at most MAX_PEER_LIST_SIZE
peers
if duplicate == false.
The parameter "uploaded" and "downloaded" in the tracker request
are
the size since the client sent the "started" event to the
tracker.
* src/TorrentMan.cc (setup): Assigned saved downloaded Size and
uploaded size to preDownloadedSize, preUploadedSize
respectively.
* src/TorrentMan.h: Added preDownloadedSize, preUploadedSize,
getSessionDownloadedSize(), getSessionUploadedSize().
* src/TrackerInitCommand.cc (execute): Use
getSessionDownloadedSize(),
getSessionUploadedSize() instead of getDownloadedSize(),
getUploadedSize().
* src/PendingMessage.cc (processMessage): Do not send request
message
if the peer is choking the client.
* src/TrackerUpdateCommand.cc (execute): Check wtheher
minInterval is
less than interval.
2006-03-28 15:23:51 +00:00
|
|
|
setTimeout(e->option->getAsInt(PREF_PEER_CONNECTION_TIMEOUT));
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2006-07-19 17:07:45 +00:00
|
|
|
peerInteraction = new PeerInteraction(cuid, peer, socket, e->option,
|
|
|
|
e->torrentMan);
|
2006-05-10 13:10:51 +00:00
|
|
|
peerInteraction->setUploadLimit(e->option->getAsInt(PREF_UPLOAD_LIMIT));
|
2006-05-18 17:08:29 +00:00
|
|
|
setUploadLimit(e->option->getAsInt(PREF_UPLOAD_LIMIT));
|
Added new class SendMessageQueue that includes PendingMessages
and
RequestSlotMan.
* src/SendMessageQueue.h: New class.
* src/SendMessageQueue.cc: New class.
* src/PendingMessage.h: Added new member variable blockIndex and
its
accessors.
(createRequestMessage): Updated.
* src/PendingMessage.cc (createRequestMessage): Updated.
* src/PeerInteractionCommand.cc (executeInternal): Updated with
SendMessageQueue.
(checkLongTimePeerChoking): Updated with SendMessageQueue.
(receiveMessage): Updated with SendMessageQueue.
(deletePendingPieceMessage): Removed.
(getNewPieceAndSendInterest): Updated with SendMessageQueue.
(sendInterest): Updated with SendMessageQueue.
(createRequestPendingMessage): Updated with SendMessageQueue.
(sendMessages): Updated with SendMessageQueue.
(onAbort): Updated with SendMessageQueue.
(keepAlive): Updated with SendMessageQueue.
(beforeSocketCheck): Updated SendMessageQueue.
* src/PeerInteractionCommand (sendMessages): Shuffle
missingBLockIndexes before using it.
Added its own timeout for peer connection.
* src/PeerAbstractCommand.h: Added member variable timeout and
its
setter.
* src/prefs.h: Added PREF_PEER_CONNECTION_TIMEOUT.
* src/PeerInteractionCommand.cc (PeerInteractionCommand):
Added setTimeout() call.
(executeInternal): Added setTimeout() call.
* src/PeerAbstractCommand.cc (PeerAbstractCommand):
Added timeout.
(isTimeoutDetected): Updated.
* src/main.cc (main): Added PREF_PEER_CONNECTION_TIMEOUT entry
to
option.
Added *simple* message flooding checker.
* src/PeerInteractionCommand.cc (executeInternal):
Added detectMessageFlooding() call.
(detectMessageFlooding): New function.
(receiveMessage): Count up CHOKE, UNCHOKE, HAVE message.
(beforeSocketCheck): Added detectMessageFlooding() call.
* src/PeerInteractionCommand.h: Added sendMessageQueue,
chokeUnchokeCount, haveCount, detectMessageFlooding().
Removed deletePendingPieceMessage(), getRequestSlot(),
deleteRequestSlot(), deleteAllRequestSlot().
* src/PeerInteractionCommand.cc (beforeSocketCheck):
Added checkLongTimePeerChoking() call.
* src/RequestSlotMan.h: Renamed deleteTimeoutRequestSlot().
* src/TorrentMan.cc (addPeer): Delete at most MAX_PEER_LIST_SIZE
peers
if duplicate == false.
The parameter "uploaded" and "downloaded" in the tracker request
are
the size since the client sent the "started" event to the
tracker.
* src/TorrentMan.cc (setup): Assigned saved downloaded Size and
uploaded size to preDownloadedSize, preUploadedSize
respectively.
* src/TorrentMan.h: Added preDownloadedSize, preUploadedSize,
getSessionDownloadedSize(), getSessionUploadedSize().
* src/TrackerInitCommand.cc (execute): Use
getSessionDownloadedSize(),
getSessionUploadedSize() instead of getDownloadedSize(),
getUploadedSize().
* src/PendingMessage.cc (processMessage): Do not send request
message
if the peer is choking the client.
* src/TrackerUpdateCommand.cc (execute): Check wtheher
minInterval is
less than interval.
2006-03-28 15:23:51 +00:00
|
|
|
chokeUnchokeCount = 0;
|
|
|
|
haveCount = 0;
|
2006-04-06 12:52:16 +00:00
|
|
|
keepAliveCount = 0;
|
2006-07-19 17:07:45 +00:00
|
|
|
e->torrentMan->addActivePeer(peer);
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PeerInteractionCommand::~PeerInteractionCommand() {
|
2006-05-10 13:10:51 +00:00
|
|
|
delete peerInteraction;
|
2006-07-19 17:07:45 +00:00
|
|
|
e->torrentMan->deleteActivePeer(peer);
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PeerInteractionCommand::executeInternal() {
|
|
|
|
if(sequence == INITIATOR_SEND_HANDSHAKE) {
|
|
|
|
socket->setBlockingMode();
|
|
|
|
setReadCheckSocket(socket);
|
Added new class SendMessageQueue that includes PendingMessages
and
RequestSlotMan.
* src/SendMessageQueue.h: New class.
* src/SendMessageQueue.cc: New class.
* src/PendingMessage.h: Added new member variable blockIndex and
its
accessors.
(createRequestMessage): Updated.
* src/PendingMessage.cc (createRequestMessage): Updated.
* src/PeerInteractionCommand.cc (executeInternal): Updated with
SendMessageQueue.
(checkLongTimePeerChoking): Updated with SendMessageQueue.
(receiveMessage): Updated with SendMessageQueue.
(deletePendingPieceMessage): Removed.
(getNewPieceAndSendInterest): Updated with SendMessageQueue.
(sendInterest): Updated with SendMessageQueue.
(createRequestPendingMessage): Updated with SendMessageQueue.
(sendMessages): Updated with SendMessageQueue.
(onAbort): Updated with SendMessageQueue.
(keepAlive): Updated with SendMessageQueue.
(beforeSocketCheck): Updated SendMessageQueue.
* src/PeerInteractionCommand (sendMessages): Shuffle
missingBLockIndexes before using it.
Added its own timeout for peer connection.
* src/PeerAbstractCommand.h: Added member variable timeout and
its
setter.
* src/prefs.h: Added PREF_PEER_CONNECTION_TIMEOUT.
* src/PeerInteractionCommand.cc (PeerInteractionCommand):
Added setTimeout() call.
(executeInternal): Added setTimeout() call.
* src/PeerAbstractCommand.cc (PeerAbstractCommand):
Added timeout.
(isTimeoutDetected): Updated.
* src/main.cc (main): Added PREF_PEER_CONNECTION_TIMEOUT entry
to
option.
Added *simple* message flooding checker.
* src/PeerInteractionCommand.cc (executeInternal):
Added detectMessageFlooding() call.
(detectMessageFlooding): New function.
(receiveMessage): Count up CHOKE, UNCHOKE, HAVE message.
(beforeSocketCheck): Added detectMessageFlooding() call.
* src/PeerInteractionCommand.h: Added sendMessageQueue,
chokeUnchokeCount, haveCount, detectMessageFlooding().
Removed deletePendingPieceMessage(), getRequestSlot(),
deleteRequestSlot(), deleteAllRequestSlot().
* src/PeerInteractionCommand.cc (beforeSocketCheck):
Added checkLongTimePeerChoking() call.
* src/RequestSlotMan.h: Renamed deleteTimeoutRequestSlot().
* src/TorrentMan.cc (addPeer): Delete at most MAX_PEER_LIST_SIZE
peers
if duplicate == false.
The parameter "uploaded" and "downloaded" in the tracker request
are
the size since the client sent the "started" event to the
tracker.
* src/TorrentMan.cc (setup): Assigned saved downloaded Size and
uploaded size to preDownloadedSize, preUploadedSize
respectively.
* src/TorrentMan.h: Added preDownloadedSize, preUploadedSize,
getSessionDownloadedSize(), getSessionUploadedSize().
* src/TrackerInitCommand.cc (execute): Use
getSessionDownloadedSize(),
getSessionUploadedSize() instead of getDownloadedSize(),
getUploadedSize().
* src/PendingMessage.cc (processMessage): Do not send request
message
if the peer is choking the client.
* src/TrackerUpdateCommand.cc (execute): Check wtheher
minInterval is
less than interval.
2006-03-28 15:23:51 +00:00
|
|
|
setTimeout(e->option->getAsInt(PREF_TIMEOUT));
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2006-07-19 17:07:45 +00:00
|
|
|
disableWriteCheckSocket();
|
2006-05-18 17:08:29 +00:00
|
|
|
setUploadLimitCheck(false);
|
2006-07-28 14:06:47 +00:00
|
|
|
setNoCheck(false);
|
2006-03-21 14:12:51 +00:00
|
|
|
|
|
|
|
switch(sequence) {
|
|
|
|
case INITIATOR_SEND_HANDSHAKE:
|
2006-05-10 13:10:51 +00:00
|
|
|
peerInteraction->sendHandshake();
|
2006-03-21 14:12:51 +00:00
|
|
|
sequence = INITIATOR_WAIT_HANDSHAKE;
|
|
|
|
break;
|
|
|
|
case INITIATOR_WAIT_HANDSHAKE: {
|
2006-05-18 17:08:29 +00:00
|
|
|
if(peerInteraction->countMessageInQueue() > 0) {
|
|
|
|
peerInteraction->sendMessages(e->getUploadSpeed());
|
|
|
|
if(peerInteraction->countMessageInQueue() > 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-07-28 14:06:47 +00:00
|
|
|
PeerMessageHandle handshakeMessage =
|
2006-07-19 17:07:45 +00:00
|
|
|
peerInteraction->receiveHandshake();
|
2006-07-28 14:06:47 +00:00
|
|
|
if(handshakeMessage.get() == 0) {
|
2006-03-21 14:12:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-07-28 14:06:47 +00:00
|
|
|
peer->setPeerId(((HandshakeMessage*)handshakeMessage.get())->peerId);
|
2006-04-17 16:17:20 +00:00
|
|
|
logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
|
|
|
peer->ipaddr.c_str(), peer->port,
|
|
|
|
handshakeMessage->toString().c_str());
|
2006-06-12 16:55:08 +00:00
|
|
|
haveCheckTime.reset();
|
2006-05-18 17:08:29 +00:00
|
|
|
peerInteraction->sendBitfield();
|
|
|
|
peerInteraction->sendAllowedFast();
|
2006-03-21 14:12:51 +00:00
|
|
|
sequence = WIRED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RECEIVER_WAIT_HANDSHAKE: {
|
2006-07-28 14:06:47 +00:00
|
|
|
PeerMessageHandle handshakeMessage =
|
2006-06-22 15:26:18 +00:00
|
|
|
peerInteraction->receiveHandshake(true);
|
2006-07-28 14:06:47 +00:00
|
|
|
if(handshakeMessage.get() == 0) {
|
2006-03-21 14:12:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-07-28 14:06:47 +00:00
|
|
|
peer->setPeerId(((HandshakeMessage*)handshakeMessage.get())->peerId);
|
2006-04-17 16:17:20 +00:00
|
|
|
logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
|
|
|
peer->ipaddr.c_str(), peer->port,
|
|
|
|
handshakeMessage->toString().c_str());
|
2006-06-12 16:55:08 +00:00
|
|
|
haveCheckTime.reset();
|
2006-05-18 17:08:29 +00:00
|
|
|
peerInteraction->sendBitfield();
|
|
|
|
peerInteraction->sendAllowedFast();
|
2006-03-21 14:12:51 +00:00
|
|
|
sequence = WIRED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WIRED:
|
2006-05-10 13:10:51 +00:00
|
|
|
peerInteraction->syncPiece();
|
2006-03-21 14:12:51 +00:00
|
|
|
decideChoking();
|
2006-07-30 12:58:27 +00:00
|
|
|
|
|
|
|
if(periodicExecPoint.elapsedInMillis(500)) {
|
|
|
|
periodicExecPoint.reset();
|
|
|
|
detectMessageFlooding();
|
|
|
|
peerInteraction->checkRequestSlot();
|
|
|
|
checkHave();
|
|
|
|
sendKeepAlive();
|
|
|
|
}
|
2006-05-24 15:18:58 +00:00
|
|
|
receiveMessages();
|
|
|
|
|
2006-05-18 17:08:29 +00:00
|
|
|
peerInteraction->addRequests();
|
2006-05-10 13:10:51 +00:00
|
|
|
peerInteraction->sendMessages(e->getUploadSpeed());
|
2006-03-21 14:12:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-05-10 13:10:51 +00:00
|
|
|
if(peerInteraction->countMessageInQueue() > 0) {
|
2006-05-18 17:08:29 +00:00
|
|
|
if(peerInteraction->isSendingMessageInProgress()) {
|
|
|
|
setUploadLimitCheck(true);
|
|
|
|
}
|
2006-07-28 14:06:47 +00:00
|
|
|
setNoCheck(true);
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2006-05-09 15:54:14 +00:00
|
|
|
e->commands.push_back(this);
|
2006-03-21 14:12:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-06-12 16:55:08 +00:00
|
|
|
#define FLOODING_CHECK_INTERVAL 5
|
|
|
|
|
Added new class SendMessageQueue that includes PendingMessages
and
RequestSlotMan.
* src/SendMessageQueue.h: New class.
* src/SendMessageQueue.cc: New class.
* src/PendingMessage.h: Added new member variable blockIndex and
its
accessors.
(createRequestMessage): Updated.
* src/PendingMessage.cc (createRequestMessage): Updated.
* src/PeerInteractionCommand.cc (executeInternal): Updated with
SendMessageQueue.
(checkLongTimePeerChoking): Updated with SendMessageQueue.
(receiveMessage): Updated with SendMessageQueue.
(deletePendingPieceMessage): Removed.
(getNewPieceAndSendInterest): Updated with SendMessageQueue.
(sendInterest): Updated with SendMessageQueue.
(createRequestPendingMessage): Updated with SendMessageQueue.
(sendMessages): Updated with SendMessageQueue.
(onAbort): Updated with SendMessageQueue.
(keepAlive): Updated with SendMessageQueue.
(beforeSocketCheck): Updated SendMessageQueue.
* src/PeerInteractionCommand (sendMessages): Shuffle
missingBLockIndexes before using it.
Added its own timeout for peer connection.
* src/PeerAbstractCommand.h: Added member variable timeout and
its
setter.
* src/prefs.h: Added PREF_PEER_CONNECTION_TIMEOUT.
* src/PeerInteractionCommand.cc (PeerInteractionCommand):
Added setTimeout() call.
(executeInternal): Added setTimeout() call.
* src/PeerAbstractCommand.cc (PeerAbstractCommand):
Added timeout.
(isTimeoutDetected): Updated.
* src/main.cc (main): Added PREF_PEER_CONNECTION_TIMEOUT entry
to
option.
Added *simple* message flooding checker.
* src/PeerInteractionCommand.cc (executeInternal):
Added detectMessageFlooding() call.
(detectMessageFlooding): New function.
(receiveMessage): Count up CHOKE, UNCHOKE, HAVE message.
(beforeSocketCheck): Added detectMessageFlooding() call.
* src/PeerInteractionCommand.h: Added sendMessageQueue,
chokeUnchokeCount, haveCount, detectMessageFlooding().
Removed deletePendingPieceMessage(), getRequestSlot(),
deleteRequestSlot(), deleteAllRequestSlot().
* src/PeerInteractionCommand.cc (beforeSocketCheck):
Added checkLongTimePeerChoking() call.
* src/RequestSlotMan.h: Renamed deleteTimeoutRequestSlot().
* src/TorrentMan.cc (addPeer): Delete at most MAX_PEER_LIST_SIZE
peers
if duplicate == false.
The parameter "uploaded" and "downloaded" in the tracker request
are
the size since the client sent the "started" event to the
tracker.
* src/TorrentMan.cc (setup): Assigned saved downloaded Size and
uploaded size to preDownloadedSize, preUploadedSize
respectively.
* src/TorrentMan.h: Added preDownloadedSize, preUploadedSize,
getSessionDownloadedSize(), getSessionUploadedSize().
* src/TrackerInitCommand.cc (execute): Use
getSessionDownloadedSize(),
getSessionUploadedSize() instead of getDownloadedSize(),
getUploadedSize().
* src/PendingMessage.cc (processMessage): Do not send request
message
if the peer is choking the client.
* src/TrackerUpdateCommand.cc (execute): Check wtheher
minInterval is
less than interval.
2006-03-28 15:23:51 +00:00
|
|
|
void PeerInteractionCommand::detectMessageFlooding() {
|
2006-06-12 16:55:08 +00:00
|
|
|
if(freqCheckPoint.elapsed(FLOODING_CHECK_INTERVAL)) {
|
|
|
|
if(chokeUnchokeCount*1.0/FLOODING_CHECK_INTERVAL >= 0.4
|
|
|
|
//|| haveCount*1.0/elapsed >= 20.0
|
|
|
|
|| keepAliveCount*1.0/FLOODING_CHECK_INTERVAL >= 1.0) {
|
|
|
|
throw new DlAbortEx("Flooding detected.");
|
|
|
|
} else {
|
|
|
|
chokeUnchokeCount = 0;
|
|
|
|
haveCount = 0;
|
|
|
|
keepAliveCount = 0;
|
|
|
|
freqCheckPoint.reset();
|
Added new class SendMessageQueue that includes PendingMessages
and
RequestSlotMan.
* src/SendMessageQueue.h: New class.
* src/SendMessageQueue.cc: New class.
* src/PendingMessage.h: Added new member variable blockIndex and
its
accessors.
(createRequestMessage): Updated.
* src/PendingMessage.cc (createRequestMessage): Updated.
* src/PeerInteractionCommand.cc (executeInternal): Updated with
SendMessageQueue.
(checkLongTimePeerChoking): Updated with SendMessageQueue.
(receiveMessage): Updated with SendMessageQueue.
(deletePendingPieceMessage): Removed.
(getNewPieceAndSendInterest): Updated with SendMessageQueue.
(sendInterest): Updated with SendMessageQueue.
(createRequestPendingMessage): Updated with SendMessageQueue.
(sendMessages): Updated with SendMessageQueue.
(onAbort): Updated with SendMessageQueue.
(keepAlive): Updated with SendMessageQueue.
(beforeSocketCheck): Updated SendMessageQueue.
* src/PeerInteractionCommand (sendMessages): Shuffle
missingBLockIndexes before using it.
Added its own timeout for peer connection.
* src/PeerAbstractCommand.h: Added member variable timeout and
its
setter.
* src/prefs.h: Added PREF_PEER_CONNECTION_TIMEOUT.
* src/PeerInteractionCommand.cc (PeerInteractionCommand):
Added setTimeout() call.
(executeInternal): Added setTimeout() call.
* src/PeerAbstractCommand.cc (PeerAbstractCommand):
Added timeout.
(isTimeoutDetected): Updated.
* src/main.cc (main): Added PREF_PEER_CONNECTION_TIMEOUT entry
to
option.
Added *simple* message flooding checker.
* src/PeerInteractionCommand.cc (executeInternal):
Added detectMessageFlooding() call.
(detectMessageFlooding): New function.
(receiveMessage): Count up CHOKE, UNCHOKE, HAVE message.
(beforeSocketCheck): Added detectMessageFlooding() call.
* src/PeerInteractionCommand.h: Added sendMessageQueue,
chokeUnchokeCount, haveCount, detectMessageFlooding().
Removed deletePendingPieceMessage(), getRequestSlot(),
deleteRequestSlot(), deleteAllRequestSlot().
* src/PeerInteractionCommand.cc (beforeSocketCheck):
Added checkLongTimePeerChoking() call.
* src/RequestSlotMan.h: Renamed deleteTimeoutRequestSlot().
* src/TorrentMan.cc (addPeer): Delete at most MAX_PEER_LIST_SIZE
peers
if duplicate == false.
The parameter "uploaded" and "downloaded" in the tracker request
are
the size since the client sent the "started" event to the
tracker.
* src/TorrentMan.cc (setup): Assigned saved downloaded Size and
uploaded size to preDownloadedSize, preUploadedSize
respectively.
* src/TorrentMan.h: Added preDownloadedSize, preUploadedSize,
getSessionDownloadedSize(), getSessionUploadedSize().
* src/TrackerInitCommand.cc (execute): Use
getSessionDownloadedSize(),
getSessionUploadedSize() instead of getDownloadedSize(),
getUploadedSize().
* src/PendingMessage.cc (processMessage): Do not send request
message
if the peer is choking the client.
* src/TrackerUpdateCommand.cc (execute): Check wtheher
minInterval is
less than interval.
2006-03-28 15:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-30 12:58:27 +00:00
|
|
|
/*
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
void PeerInteractionCommand::checkLongTimePeerChoking() {
|
|
|
|
if(e->torrentMan->downloadComplete()) {
|
|
|
|
return;
|
|
|
|
}
|
2006-06-12 16:55:08 +00:00
|
|
|
if(peer->amInterested && peer->peerChoking) {
|
|
|
|
if(chokeCheckPoint.elapsed(MAX_PEER_CHOKING_INTERVAL)) {
|
|
|
|
logger->info("CUID#%d - The peer is choking too long.", cuid);
|
|
|
|
peer->snubbing = true;
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-06-12 16:55:08 +00:00
|
|
|
chokeCheckPoint.reset();
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-30 12:58:27 +00:00
|
|
|
*/
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
|
2006-03-21 14:12:51 +00:00
|
|
|
void PeerInteractionCommand::decideChoking() {
|
2006-04-28 15:55:11 +00:00
|
|
|
if(peer->shouldBeChoking()) {
|
|
|
|
if(!peer->amChoking) {
|
2006-07-28 14:06:47 +00:00
|
|
|
peerInteraction->addMessage(peerInteraction->getPeerMessageFactory()->
|
|
|
|
createChokeMessage());
|
2006-03-24 11:59:18 +00:00
|
|
|
}
|
2006-04-28 15:55:11 +00:00
|
|
|
} else {
|
|
|
|
if(peer->amChoking) {
|
2006-07-28 14:06:47 +00:00
|
|
|
peerInteraction->addMessage(peerInteraction->getPeerMessageFactory()->
|
|
|
|
createUnchokeMessage());
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-24 15:18:58 +00:00
|
|
|
void PeerInteractionCommand::receiveMessages() {
|
|
|
|
for(int i = 0; i < 50; i++) {
|
2006-07-19 17:07:45 +00:00
|
|
|
PeerMessageHandle message = peerInteraction->receiveMessage();
|
|
|
|
if(message.get() == NULL) {
|
2006-05-24 15:18:58 +00:00
|
|
|
return;
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2006-05-24 15:18:58 +00:00
|
|
|
logger->info(MSG_RECEIVE_PEER_MESSAGE, cuid,
|
|
|
|
peer->ipaddr.c_str(), peer->port,
|
|
|
|
message->toString().c_str());
|
|
|
|
// to detect flooding
|
|
|
|
switch(message->getId()) {
|
|
|
|
case KeepAliveMessage::ID:
|
|
|
|
keepAliveCount++;
|
|
|
|
break;
|
|
|
|
case ChokeMessage::ID:
|
|
|
|
if(!peer->peerChoking) {
|
|
|
|
chokeUnchokeCount++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UnchokeMessage::ID:
|
|
|
|
if(peer->peerChoking) {
|
|
|
|
chokeUnchokeCount++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HaveMessage::ID:
|
|
|
|
haveCount++;
|
|
|
|
break;
|
|
|
|
}
|
2006-07-19 17:07:45 +00:00
|
|
|
message->receivedAction();
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO this method removed when PeerBalancerCommand is implemented
|
|
|
|
bool PeerInteractionCommand::prepareForNextPeer(int wait) {
|
|
|
|
if(e->torrentMan->isPeerAvailable()) {
|
2006-07-19 17:07:45 +00:00
|
|
|
PeerHandle peer = e->torrentMan->getPeer();
|
2006-03-21 14:12:51 +00:00
|
|
|
int newCuid = e->torrentMan->getNewCuid();
|
|
|
|
peer->cuid = newCuid;
|
2006-07-19 17:07:45 +00:00
|
|
|
PeerInitiateConnectionCommand* command =
|
|
|
|
new PeerInitiateConnectionCommand(newCuid, peer, e);
|
2006-05-09 15:54:14 +00:00
|
|
|
e->commands.push_back(command);
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PeerInteractionCommand::prepareForRetry(int wait) {
|
2006-05-09 15:54:14 +00:00
|
|
|
e->commands.push_back(this);
|
2006-03-21 14:12:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-03-21 15:21:11 +00:00
|
|
|
|
2006-03-21 14:12:51 +00:00
|
|
|
void PeerInteractionCommand::onAbort(Exception* ex) {
|
2006-05-21 16:19:17 +00:00
|
|
|
peerInteraction->abortAllPieces();
|
2006-03-21 14:12:51 +00:00
|
|
|
PeerAbstractCommand::onAbort(ex);
|
|
|
|
}
|
|
|
|
|
2006-05-26 15:28:19 +00:00
|
|
|
void PeerInteractionCommand::sendKeepAlive() {
|
2006-06-12 16:55:08 +00:00
|
|
|
if(keepAliveCheckPoint.elapsed(KEEP_ALIVE_INTERVAL)) {
|
|
|
|
if(peerInteraction->countMessageInQueue() == 0) {
|
2006-07-28 14:06:47 +00:00
|
|
|
peerInteraction->addMessage(peerInteraction->getPeerMessageFactory()->
|
|
|
|
createKeepAliveMessage());
|
2006-06-12 16:55:08 +00:00
|
|
|
peerInteraction->sendMessages(e->getUploadSpeed());
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2006-06-12 16:55:08 +00:00
|
|
|
keepAliveCheckPoint.reset();
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-26 15:28:19 +00:00
|
|
|
void PeerInteractionCommand::checkHave() {
|
2006-06-12 16:55:08 +00:00
|
|
|
PieceIndexes indexes =
|
|
|
|
e->torrentMan->getAdvertisedPieceIndexes(cuid, haveCheckTime);
|
|
|
|
haveCheckTime.reset();
|
2006-05-26 15:28:19 +00:00
|
|
|
if(indexes.size() >= 20) {
|
|
|
|
if(peer->isFastExtensionEnabled()) {
|
|
|
|
if(e->torrentMan->hasAllPieces()) {
|
2006-07-28 14:06:47 +00:00
|
|
|
peerInteraction->addMessage(peerInteraction->getPeerMessageFactory()->
|
|
|
|
createHaveAllMessage());
|
2006-05-18 17:08:29 +00:00
|
|
|
} else {
|
2006-07-28 14:06:47 +00:00
|
|
|
peerInteraction->addMessage(peerInteraction->getPeerMessageFactory()->
|
|
|
|
createBitfieldMessage());
|
2006-05-18 17:08:29 +00:00
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
} else {
|
2006-07-28 14:06:47 +00:00
|
|
|
peerInteraction->addMessage(peerInteraction->getPeerMessageFactory()->
|
|
|
|
createBitfieldMessage());
|
2006-05-26 15:28:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(PieceIndexes::iterator itr = indexes.begin(); itr != indexes.end(); itr++) {
|
2006-07-28 14:06:47 +00:00
|
|
|
peerInteraction->addMessage(peerInteraction->getPeerMessageFactory()->
|
|
|
|
createHaveMessage(*itr));
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|