aria2/src/PeerInteractionCommand.h

88 lines
2.8 KiB
C
Raw Normal View History

2006-03-21 14:12:51 +00:00
/* <!-- copyright */
/*
* aria2 - The high speed download utility
2006-03-21 14:12:51 +00:00
*
* 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.
2006-03-21 14:12:51 +00:00
*/
/* copyright --> */
#ifndef _D_PEER_INTERACTION_COMMAND_H_
#define _D_PEER_INTERACTION_COMMAND_H_
#include "PeerAbstractCommand.h"
#include "PeerConnection.h"
#include "PeerInteraction.h"
#include "TimeA2.h"
2006-03-21 14:12:51 +00:00
using namespace std;
2006-06-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add Time class which represents a specific instant in time and its precision is microseconds. Time checking procedures were rewritten using this object. * src/Time.h: New class. * src/Time.cc: New class. * src/AbstractCommand.h (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (checkPoint): Changed the type to Time. (timeout): New variable. (setTimeout): New function. * src/AbstractCommand.cc (AbstractCommand): Removed the initialization of checkPoint. Added the initialization of timeout. (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (execute): Use checkPoint.reset() and checkPoint.elapsed(). * src/PeerChokeCommand.h (checkPoint): Changed the type to Time. * src/PeerChokeCommand.cc (PeerChokeCommand): Removed the initialization of checkPoint. (execute): Rewritten using Time object. * src/TrackerWatcherCommand.h (checkPoint): Changed the type to Time. * src/TrackerWatcherCommand.cc (TrackerWatcherCommand): Removed the initialization of checkPoint. (execute): Rewritten. * src/ConsoleDownloadEngine.h (cp): Changed the type to Time. (startup): Changed the type to Time. * src/ConsoleDownloadEngine.cc (initStatistics): Use cp.reset(), startup.reset(). (calculateStatistics): Rewritten using Time object. * src/PeerAbstractCommand.h (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (checkPoint): Changed the type to Time. * src/PeerAbstractCommand.cc (PeerAbstractCommand): Removed the initialization of checkPoint. (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (execute): Use checkPoint.reset() and checkPoint.elapsed(). * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed the initializations of struct timeval variables. * src/PeerInteractionCommand.h (keepAliveCheckPoint): Changed the type to Time. (chokeCheckPoint): Changed the type to Time. (freqCheckPoint): Changed the type to Time. (haveCheckTime): Changed the type to Time. * src/PeerInteractionCommand.cc (executeInternal): Rewritten using Time object. (detectMessageFlooding): Rewritten using Time object. (checkLongTimePeerChoking): Rewritten using Time object. (sendKeepAlive): Rewritten using Time object. (checkHave): Rewritten using Time object. * src/SleepCommand.h (checkPoint): Changed the type to Time. * src/SleepCommand.cc (SleepCommand): Removed the initialization of checkPoint. (execute): Rewritten using Time object. * src/TorrentAutoSaveCommand.h (checkPoint): Changed the type to Time. * src/TorrentAutoSaveCommand.cc (TorrentAutoSaveCommand): Removed the initialization of checkPoint. (execute): Rewritten. * src/DownloadCommand.h (sw): Changed the type to Time. * src/DownloadCommand.cc (DownloadCommand): Removed the initialization of sw. (executeInternal): Rewritten. * src/RequestSlot.h (dispatchedTime): Changed the type to Time. * src/RequestSlot.cc (RequestSlot): Removed the call to setDispatchedTime(). (setDispatchedTime): Rewirtten. (isTimeout): Rewritten. (getLatencyInMillis): Rewritten. * src/TorrentDownloadEngine.h (cp): Changed the type to Time[2]. (startup): Changed the type to Time. * src/TorrentDownloadEngine.cc (initStatistics): Rewritten. (calculateStatistics): Rewritten. * src/DownloadEngine.cc (run): Rewritten. To detect all attempts to connect to the tracker are failed: * src/AbstractCommand.cc (execute): Increment e->segmentMan->errors if a command aborted. * src/SegmentMan.h (errors): New variable. * src/SegmentMan.cc (SegmentMan): Added the initialization of errors. (init): Added the initialization of errors. * src/TrackerWatcherCommand.cc (execute): If e->segmentMan->errors > 0 then assume that the tracker request was failed. To handle snubbed peers: * src/PeerChokeCommand.cc (optUnchokingPeer): Snubbed peers don't get unchoked. (execute): Snubbed peers don't get unchoked. * src/PeerInteraction.h (REQUEST_TIME_OUT): Changed the value from 120 to 60. * src/PeerInteraction.cc (checkRequestSlot): A peer get marked as "snubbed" if it doesn't send back the requested 16k block in 60 seconds. * src/PieceMessage.cc (receivedAction): A peer's snubbed state is cleard if it sends the requested 16k block in 60 seconds. * src/Peer.h (snubbing): New variable. * src/Peer.cc (resetStatus): Added snubbed = false. To fix the bug that causes have message is not sent: * src/PeerInteractionCommand.cc (~PeerInteractionCommand): Removed e->torrentMan->unadvertisePiece(). (FLOODING_CHECK_INTERVAL): New definition(temporal). (detectMessageFlooding): Use FLOODING_CHECK_INTERVAL. * src/TorrentMan.h (HaveEntry): New class. (advertisePiece): Rewritten. (getAdvertisedPieceIndexes): Rewritten. (Haves): Changed the type. (getAdvertisedPieceIndexes): Added an argument. Others: * src/TorrentMan.h (DEFAULT_ANNOUNCE_INTERVAL): Changed the value to 1800. (DEFAULT_ANNOUNCE_MIN_INTERVAL): Changed the value to 1800. * src/TorrentMan.cc (getPeer): Don't check the number of connections here. (setupInternal1): Changed peerId. * src/PeerInteractionCommand.h (KEEP_ALIVE_INTERVAL): New definition. (sendKeepAlive): Use KEEP_ALIVE_INTERVAL. * src/main.cc (main): SA_ONESHOT was replaced with SA_RESETHAND. * src/DownloadEngine.h: Removed unnecessary header includes.
2006-06-12 16:55:08 +00:00
#define MAX_PEER_CHOKING_INTERVAL (1*60)
#define KEEP_ALIVE_INTERVAL 120
2006-03-31 16:17:52 +00:00
2006-03-21 14:12:51 +00:00
class PeerInteractionCommand : public PeerAbstractCommand {
private:
int sequence;
PeerInteraction* peerInteraction;
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
2006-06-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add Time class which represents a specific instant in time and its precision is microseconds. Time checking procedures were rewritten using this object. * src/Time.h: New class. * src/Time.cc: New class. * src/AbstractCommand.h (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (checkPoint): Changed the type to Time. (timeout): New variable. (setTimeout): New function. * src/AbstractCommand.cc (AbstractCommand): Removed the initialization of checkPoint. Added the initialization of timeout. (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (execute): Use checkPoint.reset() and checkPoint.elapsed(). * src/PeerChokeCommand.h (checkPoint): Changed the type to Time. * src/PeerChokeCommand.cc (PeerChokeCommand): Removed the initialization of checkPoint. (execute): Rewritten using Time object. * src/TrackerWatcherCommand.h (checkPoint): Changed the type to Time. * src/TrackerWatcherCommand.cc (TrackerWatcherCommand): Removed the initialization of checkPoint. (execute): Rewritten. * src/ConsoleDownloadEngine.h (cp): Changed the type to Time. (startup): Changed the type to Time. * src/ConsoleDownloadEngine.cc (initStatistics): Use cp.reset(), startup.reset(). (calculateStatistics): Rewritten using Time object. * src/PeerAbstractCommand.h (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (checkPoint): Changed the type to Time. * src/PeerAbstractCommand.cc (PeerAbstractCommand): Removed the initialization of checkPoint. (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (execute): Use checkPoint.reset() and checkPoint.elapsed(). * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed the initializations of struct timeval variables. * src/PeerInteractionCommand.h (keepAliveCheckPoint): Changed the type to Time. (chokeCheckPoint): Changed the type to Time. (freqCheckPoint): Changed the type to Time. (haveCheckTime): Changed the type to Time. * src/PeerInteractionCommand.cc (executeInternal): Rewritten using Time object. (detectMessageFlooding): Rewritten using Time object. (checkLongTimePeerChoking): Rewritten using Time object. (sendKeepAlive): Rewritten using Time object. (checkHave): Rewritten using Time object. * src/SleepCommand.h (checkPoint): Changed the type to Time. * src/SleepCommand.cc (SleepCommand): Removed the initialization of checkPoint. (execute): Rewritten using Time object. * src/TorrentAutoSaveCommand.h (checkPoint): Changed the type to Time. * src/TorrentAutoSaveCommand.cc (TorrentAutoSaveCommand): Removed the initialization of checkPoint. (execute): Rewritten. * src/DownloadCommand.h (sw): Changed the type to Time. * src/DownloadCommand.cc (DownloadCommand): Removed the initialization of sw. (executeInternal): Rewritten. * src/RequestSlot.h (dispatchedTime): Changed the type to Time. * src/RequestSlot.cc (RequestSlot): Removed the call to setDispatchedTime(). (setDispatchedTime): Rewirtten. (isTimeout): Rewritten. (getLatencyInMillis): Rewritten. * src/TorrentDownloadEngine.h (cp): Changed the type to Time[2]. (startup): Changed the type to Time. * src/TorrentDownloadEngine.cc (initStatistics): Rewritten. (calculateStatistics): Rewritten. * src/DownloadEngine.cc (run): Rewritten. To detect all attempts to connect to the tracker are failed: * src/AbstractCommand.cc (execute): Increment e->segmentMan->errors if a command aborted. * src/SegmentMan.h (errors): New variable. * src/SegmentMan.cc (SegmentMan): Added the initialization of errors. (init): Added the initialization of errors. * src/TrackerWatcherCommand.cc (execute): If e->segmentMan->errors > 0 then assume that the tracker request was failed. To handle snubbed peers: * src/PeerChokeCommand.cc (optUnchokingPeer): Snubbed peers don't get unchoked. (execute): Snubbed peers don't get unchoked. * src/PeerInteraction.h (REQUEST_TIME_OUT): Changed the value from 120 to 60. * src/PeerInteraction.cc (checkRequestSlot): A peer get marked as "snubbed" if it doesn't send back the requested 16k block in 60 seconds. * src/PieceMessage.cc (receivedAction): A peer's snubbed state is cleard if it sends the requested 16k block in 60 seconds. * src/Peer.h (snubbing): New variable. * src/Peer.cc (resetStatus): Added snubbed = false. To fix the bug that causes have message is not sent: * src/PeerInteractionCommand.cc (~PeerInteractionCommand): Removed e->torrentMan->unadvertisePiece(). (FLOODING_CHECK_INTERVAL): New definition(temporal). (detectMessageFlooding): Use FLOODING_CHECK_INTERVAL. * src/TorrentMan.h (HaveEntry): New class. (advertisePiece): Rewritten. (getAdvertisedPieceIndexes): Rewritten. (Haves): Changed the type. (getAdvertisedPieceIndexes): Added an argument. Others: * src/TorrentMan.h (DEFAULT_ANNOUNCE_INTERVAL): Changed the value to 1800. (DEFAULT_ANNOUNCE_MIN_INTERVAL): Changed the value to 1800. * src/TorrentMan.cc (getPeer): Don't check the number of connections here. (setupInternal1): Changed peerId. * src/PeerInteractionCommand.h (KEEP_ALIVE_INTERVAL): New definition. (sendKeepAlive): Use KEEP_ALIVE_INTERVAL. * src/main.cc (main): SA_ONESHOT was replaced with SA_RESETHAND. * src/DownloadEngine.h: Removed unnecessary header includes.
2006-06-12 16:55:08 +00:00
Time keepAliveCheckPoint;
2006-07-30 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> * src/TorrentMan.h: (advertisePiece): Updated doc. (getAdvertisedPieceIndexes): Updated doc. (removeAdvertisedPiece); New function. * src/TorrentMan.cc (FindElapsedHave): New function object. (removeAdvertisedPiece): New function. * src/HaveEraseCommand.h: New class. * src/HaveEraseCommand.cc: New class. * src/FeatureConfig.h: New class. * src/FeatureConfig.cc: New class. * src/Request.h (defaultPorts): Removed. * src/Request.cc (FeatureConfig.h): Included. (Request): Removed the statements related to defaultPorts. (parseUrl): Removed metalinkEnabled. Use FeatureConfig instead. A default port number is now retrieved from FeatureConfig. * src/main.cc (HaveEraseCommand.h): Included. (showVersion): Added the output of feature list. (main): Added HaveEraseCommand to command queue in BitTorrent downloading. * src/PeerInteractionCommand.h (chokeCheckPoint): Commented out. (periodicExecPoint): New variable. * src/PeerInteractionCommand.cc (executeInternal): Following methods are now called in at least every 0.5 seconds to reduce CPU usage: detectMessageFlooding(), peerInteraction->checkRequestSlot(), checkHave(), sendKeepAlive(). (checkLongTimePeerChoking): Commented out. * src/BitfieldMan.h (getNthBitIndex): Changed the method signature. (getMissingIndexRandomly): Changed the method signature. * src/BitfieldMan.cc (getNthBitIndex): Rewritten (getMissingIndexRandomly): Rewritten. (hasMissingPiece): Rewritten. (getMissingIndex): Refactored. (getMissingUnusedIndex); Refactored. (getMissingIndex): Refactored.
2006-07-30 12:58:27 +00:00
//Time chokeCheckPoint;
2006-06-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To add Time class which represents a specific instant in time and its precision is microseconds. Time checking procedures were rewritten using this object. * src/Time.h: New class. * src/Time.cc: New class. * src/AbstractCommand.h (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (checkPoint): Changed the type to Time. (timeout): New variable. (setTimeout): New function. * src/AbstractCommand.cc (AbstractCommand): Removed the initialization of checkPoint. Added the initialization of timeout. (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (execute): Use checkPoint.reset() and checkPoint.elapsed(). * src/PeerChokeCommand.h (checkPoint): Changed the type to Time. * src/PeerChokeCommand.cc (PeerChokeCommand): Removed the initialization of checkPoint. (execute): Rewritten using Time object. * src/TrackerWatcherCommand.h (checkPoint): Changed the type to Time. * src/TrackerWatcherCommand.cc (TrackerWatcherCommand): Removed the initialization of checkPoint. (execute): Rewritten. * src/ConsoleDownloadEngine.h (cp): Changed the type to Time. (startup): Changed the type to Time. * src/ConsoleDownloadEngine.cc (initStatistics): Use cp.reset(), startup.reset(). (calculateStatistics): Rewritten using Time object. * src/PeerAbstractCommand.h (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (checkPoint): Changed the type to Time. * src/PeerAbstractCommand.cc (PeerAbstractCommand): Removed the initialization of checkPoint. (updateCheckPoint): Removed. (isTimeoutDetected): Removed. (execute): Use checkPoint.reset() and checkPoint.elapsed(). * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed the initializations of struct timeval variables. * src/PeerInteractionCommand.h (keepAliveCheckPoint): Changed the type to Time. (chokeCheckPoint): Changed the type to Time. (freqCheckPoint): Changed the type to Time. (haveCheckTime): Changed the type to Time. * src/PeerInteractionCommand.cc (executeInternal): Rewritten using Time object. (detectMessageFlooding): Rewritten using Time object. (checkLongTimePeerChoking): Rewritten using Time object. (sendKeepAlive): Rewritten using Time object. (checkHave): Rewritten using Time object. * src/SleepCommand.h (checkPoint): Changed the type to Time. * src/SleepCommand.cc (SleepCommand): Removed the initialization of checkPoint. (execute): Rewritten using Time object. * src/TorrentAutoSaveCommand.h (checkPoint): Changed the type to Time. * src/TorrentAutoSaveCommand.cc (TorrentAutoSaveCommand): Removed the initialization of checkPoint. (execute): Rewritten. * src/DownloadCommand.h (sw): Changed the type to Time. * src/DownloadCommand.cc (DownloadCommand): Removed the initialization of sw. (executeInternal): Rewritten. * src/RequestSlot.h (dispatchedTime): Changed the type to Time. * src/RequestSlot.cc (RequestSlot): Removed the call to setDispatchedTime(). (setDispatchedTime): Rewirtten. (isTimeout): Rewritten. (getLatencyInMillis): Rewritten. * src/TorrentDownloadEngine.h (cp): Changed the type to Time[2]. (startup): Changed the type to Time. * src/TorrentDownloadEngine.cc (initStatistics): Rewritten. (calculateStatistics): Rewritten. * src/DownloadEngine.cc (run): Rewritten. To detect all attempts to connect to the tracker are failed: * src/AbstractCommand.cc (execute): Increment e->segmentMan->errors if a command aborted. * src/SegmentMan.h (errors): New variable. * src/SegmentMan.cc (SegmentMan): Added the initialization of errors. (init): Added the initialization of errors. * src/TrackerWatcherCommand.cc (execute): If e->segmentMan->errors > 0 then assume that the tracker request was failed. To handle snubbed peers: * src/PeerChokeCommand.cc (optUnchokingPeer): Snubbed peers don't get unchoked. (execute): Snubbed peers don't get unchoked. * src/PeerInteraction.h (REQUEST_TIME_OUT): Changed the value from 120 to 60. * src/PeerInteraction.cc (checkRequestSlot): A peer get marked as "snubbed" if it doesn't send back the requested 16k block in 60 seconds. * src/PieceMessage.cc (receivedAction): A peer's snubbed state is cleard if it sends the requested 16k block in 60 seconds. * src/Peer.h (snubbing): New variable. * src/Peer.cc (resetStatus): Added snubbed = false. To fix the bug that causes have message is not sent: * src/PeerInteractionCommand.cc (~PeerInteractionCommand): Removed e->torrentMan->unadvertisePiece(). (FLOODING_CHECK_INTERVAL): New definition(temporal). (detectMessageFlooding): Use FLOODING_CHECK_INTERVAL. * src/TorrentMan.h (HaveEntry): New class. (advertisePiece): Rewritten. (getAdvertisedPieceIndexes): Rewritten. (Haves): Changed the type. (getAdvertisedPieceIndexes): Added an argument. Others: * src/TorrentMan.h (DEFAULT_ANNOUNCE_INTERVAL): Changed the value to 1800. (DEFAULT_ANNOUNCE_MIN_INTERVAL): Changed the value to 1800. * src/TorrentMan.cc (getPeer): Don't check the number of connections here. (setupInternal1): Changed peerId. * src/PeerInteractionCommand.h (KEEP_ALIVE_INTERVAL): New definition. (sendKeepAlive): Use KEEP_ALIVE_INTERVAL. * src/main.cc (main): SA_ONESHOT was replaced with SA_RESETHAND. * src/DownloadEngine.h: Removed unnecessary header includes.
2006-06-12 16:55:08 +00:00
Time freqCheckPoint;
Time haveCheckTime;
2006-07-30 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> * src/TorrentMan.h: (advertisePiece): Updated doc. (getAdvertisedPieceIndexes): Updated doc. (removeAdvertisedPiece); New function. * src/TorrentMan.cc (FindElapsedHave): New function object. (removeAdvertisedPiece): New function. * src/HaveEraseCommand.h: New class. * src/HaveEraseCommand.cc: New class. * src/FeatureConfig.h: New class. * src/FeatureConfig.cc: New class. * src/Request.h (defaultPorts): Removed. * src/Request.cc (FeatureConfig.h): Included. (Request): Removed the statements related to defaultPorts. (parseUrl): Removed metalinkEnabled. Use FeatureConfig instead. A default port number is now retrieved from FeatureConfig. * src/main.cc (HaveEraseCommand.h): Included. (showVersion): Added the output of feature list. (main): Added HaveEraseCommand to command queue in BitTorrent downloading. * src/PeerInteractionCommand.h (chokeCheckPoint): Commented out. (periodicExecPoint): New variable. * src/PeerInteractionCommand.cc (executeInternal): Following methods are now called in at least every 0.5 seconds to reduce CPU usage: detectMessageFlooding(), peerInteraction->checkRequestSlot(), checkHave(), sendKeepAlive(). (checkLongTimePeerChoking): Commented out. * src/BitfieldMan.h (getNthBitIndex): Changed the method signature. (getMissingIndexRandomly): Changed the method signature. * src/BitfieldMan.cc (getNthBitIndex): Rewritten (getMissingIndexRandomly): Rewritten. (hasMissingPiece): Rewritten. (getMissingIndex): Refactored. (getMissingUnusedIndex); Refactored. (getMissingIndex): Refactored.
2006-07-30 12:58:27 +00:00
Time periodicExecPoint;
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
int chokeUnchokeCount;
int haveCount;
2006-04-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To print ETA: * src/TorrentDownloadEngine.cc (afterEachIteration): Added download completion handling when dealing with TorrentMan::isPartialDownloadingMode() == true. * src/TorrentDownloadEngine.h (onPartialDownloadingCompletes): New function. * src/TorrentConsoleDownloadEngine.h (startup): New variable. (sessionDownloadLength): New variable. (avgSpeed): New variable. (eta): New variable. * src/TorrentConsoleDownloadEngine.cc (initStatistics): Initialized new variables: eta, avgSpeed, startup. (calculateSpeed): Calculate average speed and ETA. (printStatistics): Added ETA. * src/Util.h (secfmt): New function. * src/Util.cc (secfmt): New function. 2006-04-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To detect "keep alive" flooding: * src/PeerInteractionCommand.h (keepAliveCount): New variable * src/PeerInteractionCommand.cc (Constructor): Initialized new variable: keepAliveCount. (detectMessageFlooding): Added "keep alive" flooding detection. (receiveMessage): Increase keepAliveCount when "keep alive" message received. To add the ability to download only specified files in multi-file torrent: * src/BitfieldMan.h (filterBitfield): New variable. (filterEnabled): New variable. (setFilterBit): New function. (enableFilter): New function. (disableFilter): New function. (isFilterEnabled): New function. (getFilteredTotalLength): New function. (getCompletedLength): New function. * src/BitfieldMan.cc (Constructor): Initialized new variable: filterBitfield, filterEnabled. (CopyConstructor): Added filterBitfield and filterEnabled. (operator==): Added filterBitfield and filterEnabled. (Destructor): Added filterBitfield. (getMissingIndex): Use filterBitfield. (getMissingUnusedIndex): Use filterBitfield. (getFirstMissingUnusedIndex): Use filterBitfield. (getFirstMissingUnusedIndex): Use filterBitfield. (getAllMissingIndexes): Use filterBitfield. (countMissingBlock): Use filterBitfield. (countBlock): Use filterBitfield. (setBitInternal): Added new argument on. (setUseBit): Use setBitInternal. (unsetUseBit): Use setBitInternal. (setBit): Use setBitInternal. (unsetBit): Use setBitInternal. (isAllBitSet): Use filterBitfield. (setFilterBit): New function. (addFilter): New function. (enableFilter): New function. (disableFilter): New function. (clearFilter): New function. (isFilterEnabled): New function. (getFilteredTotalLength): New function. (getCompletedLength): New function. * src/TorrentMan.h [FileEntry](Constructor): Updated signature. Initalized newly added variables. [FileEntry](offset): New variable. [FileEntry](extracted): New variable. [FileEntry](requested): New variable. (readFileEntry): New function. (option): New variable. (splitMultiFile): Removed const qualifier. (fixFilename): Removed const qualifier. (readFileEntryFromMetaInfoFile): New function. (finishPartialDownloadingMode): New function. (isPartialDownloadingMode): New function. (setFileEntriesToDownload): New function. (getCompletedLength): New function. (getPartialTotalLength): New function. * src/TorrentMan.cc (readFileEntry): New function. (setup): Use readFileEntry. If no-preallocation option is specified, use DefaultDiskWriter. (readFileEntryFromMetaInfoFile): New function. (fixFilename): Removed const qualifier. (splitMultiFile): Removed const qualifier. (setFileEntriesToDownload): New function. (isPartialDownloadingMode): New function. (finishPartialDownloadingMode): New function. (getCompletedLength): New function. (getPartialTotalLength): New function. * src/TorrentConsoleDownloadEngine.h (partialDownloadLengthDiff): New variable. (partialTotalLength): New variable. (downloadLength): New variable. (totalLength): New variable. * src/TorrentConsoleDownloadEngine.cc (onPartialDownloadingCompletes): Added log. (initStatistics): Initialized new variables: partialDownloadLengthDiff, partialTotalLength, downloadLength, totalLength. (calculate): Calculate downloadLength and totalLength. * src/prefs.h :New definition PREF_NO_PREALLOCATION * src/main.cc (addCommand): Changed argument signature. (main): Added new variable: args. Added new option "torrent-show-files" "no-preallocation". Usage is not updated yet. 2006-04-02 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> * src/PeerMessage.cc (setBitfield): Fixed invalid memory de-allocation.
2006-04-06 12:52:16 +00:00
int keepAliveCount;
2006-05-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To attempt to handle EINTR: * src/SocketCore.cc (isReadable): Added EINTR handling. (isWritable): Added EINTR handling. To improve the performance: * src/AbstractCommand.cc (isTimeoutDetected): Use Util::difftvsec() instead of Util::difftv(). * src/PeerInteractionCommand.h (receiveMessage): Renamed as receiveMessages(). (receiveMessages): New function. * src/PeerInteractionCommand.cc (executeInternal): receiveMessage loop is moved to new receiveMessages () function. detectMessageFlooding() is moved here. (detectMessageFlooding): Use Util::difftvsec() instead of Util::difftv (). The flooding detection for have message is comment out. (checkLongTimePeerChoking): Use Util::difftvsec() instead of Util::difftv(). (receiveMessage): Renamed as receiveMessages(). (receiveMessages): New function. (keepAlive): Use Util::difftvsec() instead of Util::difftv(). (beforeSocketCheck): Commented out checkLongTimePeerChoking(). * src/SleepCommand.cc (execute): Use Util::difftvsec() instead of Util::difftv(). * src/BitfieldMan.h (getNthBitIndex): New function. (hasMissingPiece): New function. (getAllMissingIndexes): New function. * src/BitfieldMan.cc (countSetBit): Rewritten. (getNthBitIndex): New function. (getMissingIndexRandomly): Rewritten. (hasMissingPiece): New function. (getAllMissingIndexes): New function. * src/TorrentMan.cc (hasMissingPiece): New function. (deleteUsedPiece): Rewritten using STL. * src/PeerInteraction.cc (getNewPieceAndSendInterest): Use TorrentMan::hasMissingPiece(), which is a little bit faster then TorrentMan::getMissingPieceIndex(). (addRequests): Updated the number of pending requests. * src/PeerAbstractCommand.cc (isTimeoutDetected): Use Util::difftvsec() instead of Util::difftv(). (execute): Returns true if TorrentMan::isHalt() is true. Corrected the condition of upload limit checking. * src/Util.h (countBit): New function. * src/Util.cc (nbits): New variable. (countBit): New function. * src/DownloadEngine.h (SockCmdMap): New type definition. (waitData): Added an argument. (addSocket): Added an argument. (addSocketForReadCheck): Added an argument. (addSocketForWriteCheck): Added an argument. * src/DownloadEngine.cc (run): Executes only commands whose sockets are ready to read or write. All commands are executed in every 1 second. (waitData): Calls select() again if it returned EINTR. (addSocket): Saves socket and command object pair to the map. (deleteSocket): Deletes socket and command object pair from the map. (addSocketForReadCheck): Added an argument. (addSocketForWriteCheck): Added an argument. * src/DownloadCommand.cc (executeInternal): Use Util::difftvsec() instead of Util::difftv(). To send "event=stopped" to the tracker when the application finishes: * src/PeerChokeCommand.h (checkPoint): New variable. * src/PeerChokeCommand.cc (PeerChokeCommand): Added the initialization of checkPoint. (execute): The interval check is now done by checkPoint, not SleepCommand. Return true if TorrentMan::isHalt() is true. * src/TorrentMan.h (halt): New function. (hasMissingPiece): New function. (isHalt): New function. (setHalt): New function. * src/TorrentMan.cc (TorrentMan): Added the initialization of halt. * src/TorrentAutoSaveCommand.h (checkPoint): New variable. * src/PeerListenCommand.cc (execute): Returns true if TorrentMan::isHalt() is true. * src/main.cc (setSignalHander): Added flags argument. (torrentHandler): Just calls TorrentMan::setHalt(true) and returns. (main): Set SA_ONESHOT flag of the signal hander of SIGINT and SIGTERM. Removed printDownloadAbortMessage() after torrent downloading loop. * src/TorrentAutoSaveCommand.cc (TorrentAutoSaveCommand): Added the initialization of checkPoint. (execute): Returns true if TorrentMan::isHalt() is true. The interval check is now done by checkPoint, not SleepCommand. * src/TrackerWatcherCommand.cc (execute): If TorrentMan::isHalt(), then create a tracker request with event=stopped. * src/TrackerUpdateCommand.cc (prepareForRetry): Do not use SleepCommand here. (execute): Returns true if TorrentMan::isHalt() is true. Others: * src/TorrentMan.cc (getMissingPieceIndex): Updated log message. * src/PeerInteraction.cc (createPeerMessag): Updated log message.
2006-05-24 15:18:58 +00:00
void receiveMessages();
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 detectMessageFlooding();
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 checkLongTimePeerChoking();
2006-03-21 14:12:51 +00:00
void detectTimeoutAndDuplicateBlock();
void decideChoking();
2006-05-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> * src/PeerAbstractCommand.h (beforeSocketCheck): Removed. * src/PeerAbstractCommand.cc Modified in order to call executeInternal() even if socket check and upload limit check fail. * src/PeerInteractionCommand.h (keepAlive): Removed. (sendKeepAlive): New function. (checkHave): New function. (beforeSocketCheck): Removed. * src/PeerInteractionCommand.cc (executeInternal): Use peerInteraction->checkRequestSlot(). Added calls to checkHave() and sendKeepAlive(). (keepAlive): Renamed to sendKeepAlive(). (sendKeepAlive): New function. (beforeSocketCheck): Removed. (checkHave): New function. * src/BitfieldMan.cc (getMissingIndex): Don't call getMissingIndexRandomly() if max is 0. (getMissingUnusedIndex): Don't call getMissingIndexRandomly() if max is 0. (getMissingIndex): Dont't call getMissingIndexRandomly() if max is 0. * src/TorrentMan.h (UsedPieces): Removed. (Pieces): New type definition. * src/Piece.h: Updated doc. * src/Peer.h (totalLength): Removed. * src/Peer.cc (updateLatency): Fixed the latency calculation. * src/TorrentMan.cc (addPeer): Call deleteOldErrorPeers() only if peers.size() is higher than or equal to MAX_PEER_LIST_SIZE. If duplicate is false and peer.size() >= MAX_PEER_LIST_SIZE, then return false. (deleteOldErrorPeers): Rewritten. (deleteUsedPiece): Fixed the miss use of STL remove. * src/PeerInteraction.h (Pieces): Removed. (deleteTimeoutRequestSlot): Removed. (deleteCompletedRequestSlot): Removed. (checkRequestSlot): New function. * src/PeerInteraction.cc (deleteTimeoutRequestSlot): Merged to checkRequestSlot(). (deleteCompletedRequestSlot): Merged to checkRequestSlot(). (checkRequestSlot): New function. * src/DownloadEngine.cc (run): Clear activeSockets before calling waitData(). (waitData): Removed a call to activeSockets.clear().
2006-05-26 15:28:19 +00:00
void sendKeepAlive();
void checkHave();
2006-03-21 14:12:51 +00:00
protected:
bool executeInternal();
bool prepareForRetry(int wait);
bool prepareForNextPeer(int wait);
void onAbort(Exception* ex);
public:
2006-07-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> * src/SharedHandle.h: New class. To wrap Socket, Command, PeerMessage and Peer with SharedHandle: * src/HttpResponseCommand.h (HttpResponseCommand): Wrapped Socket. * src/SocketCore.h (operator==): New function. (operator!=): New function. (operator<): New function. (getSockfd): New function. (isOpen): New function. (writeData): New function. * src/SocketCore.cc (operator==): New function. (operator!=): New function. (operator<): New function. * src/AbstractCommand.h (socket): Changed its type to SocketHandle. (setReadCheckSocket): Replaced Socket with SocketHandle. (setWriteCheckSocket): Replaced Socket with SocketHandle. (disableReadCheckSocket): New function. (disableWriteCheckSocket): New function. (readCheckTarget): Changed its type to SocketHandle. (writeCheckTarget): Changed its type to SocketHandle. (AbstractCommand): Replaced Socket with SocketHandle. * src/AbstractCommand.cc (AbstractCommand): Replaced Socket with SocketHandle. (~AbstractCommand): Removed the deallocation for Socket object. (disableReadCheckSocket): New function. (setReadCheckSocket): Replaced Socket with SocketHandle. (disableWriteCheckSocket): New function. (setWriteCheckSocket): Replaced Socket with SocketHandle. * src/HttpDownloadCommand.cc (DownloadCommand): Replaced Socket with SocketHandle. * src/PeerAbstractCommand.h (socket): Changed its type to SocketHandle. (peer): Changed its type to PeerHandle. (setReadCheckSocket): Replaced Socket with SocketHandle. (setWriteCheckSocket): Replaced Socket with SocketHandle. (disableReadCheckSocket): New function. (disableWriteCheckSocket): New function. (readCheckTarget): Changed its type to SocketHandle. (writeCheckTarget): Changed its type to SocketHandle. (PeerAbstractCommand): Replaced Socket with SocketHandle. Replaced Peer with PeerHandle. * src/HttpRequestCommand.cc (HttpRequestCommand): Replaced Socket with SocketHandle. Use disableReadCheckSocket. * src/PeerInitiateConnectionCommand.h (PeerInitiateConnectionCommand): Replaced Peer with PeerHandle. * src/PeerChokeCommand.cc (UploadFaster::operator()): Replaced Peer with PeerHandle. (DownloadFaster::operator()): Replaced Peer with PeerHandle. (execute): Use PeerHandle. * src/PeerConnection.h (HandshakeMessage.h): Removed include of HandshakeMessage.h. (socket): Changed its type to SocketHandle. (PeerConnection): Replaced Socket with SocketHandle. * src/PeerConnection.cc (PeerConnection): Replaced Socket with SocketHandle. * src/PeerInteractionCommand.h (PeerInteractionCommand): Replaced socket with SocketHandle. Replaced Peer with PeerHandle. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Replaced Socket with SocketHandle. Replaced Peer with PeerHandle. (executeInternal): Use disableWriteCheckSocket. Use HandshakeMessageHandle. (receiveMessages): Use PeerMessageHandle. (prepareForNextPeer): Use PeerHandle. * src/HttpProxyRequestCommand.h (HttpProxyRequestCommand): Replaced Socket with SocketHandle. * src/HttpResponseCommand.cc (HttpResponseCommand): Replaced Socket with SocketHandle. * src/TorrentMan.cc (nullPeer): Added external reference. (~TorrentMan): Removed the deallocation of the elements of peers. (addPeer): Rewritten. (isPeerAvailable): Use nullPeer. (deleteOldpeers): Replaced with deleteErrorPeer. (deleteErrorPeer): New function. (getPeer): Use PeerHandle and nullPeer. (hasMissingPiece): Replaced Peer with PeerHandle. (getMissingPieceIndex): Replaced Peer with PeerHandle. (getMissingFastPieceIndex): Replaced Peer with PeerHandle. (getMissingFastPiece): Replaced Peer with PeerHandle. (getMissingPiece): Replaced Peer with PeerHandle. * src/FtpNegotiateCommand.cc (FtpNegotiationCommand): Replaced Peer with PeerHandle. (~FtpNegotiationCommand): Removed the deallocation of Sockets. (recvGreeting): Use disableWriteCheckSocket. (recvPasv): Removed the allocation of Socket. Use disableReadCheckSocket. (sendRestPasv): Use disableWriteCheckSocket. (recvRetr): Changed assertion. * src/PeerInteraction.h (SharedHandle.h): Included SharedHandle.h. (PeerMessageHandle): New type definition. (HandshakeMessageHandle): New type definition. (MessageQueue): Changed. Now its element is of type PeerMessageHandle. (peer): Changed its type to PeerHandle. (createHandshakeMessage): Replaced HandshakeMessage with HandshakeMessageHandle. (createPeerMessage): Replaced PeerMessageHandle with PeerMessage. (PeerInteraction): Replaced Peer with PeerHandle. Replaced Socket with SocketHandle. (addMessage): Replaced PeerMessage with PeerMessageHandle. (receiveMessage): Replaced PeerMessage with PeerMessageHandle. (receiveHandshake): Replaced HandshakeMessage with HandshakeMessageHandle. * src/PeerInteraction.cc (PeerInteraction): Replaced Peer with PeerHandle. Replaced Socket with SocketHandle. (~PeerInteraction): Removed the deallocation of the elements of messageQueue. (MsgPushBack::operator()): Replaced PeerMessage with PeerMessageHandle. (isSendingMessageInProgress): Replaced PeerMessage with PeerMessageHandle. (sendMessages): Use PeerMessageHandle. Removed try-catch block. (addMessage): Replaced PeerMessage with PeerMessageHandle. (rejectAllPieceMessageInQueue): Use PeerMessageHandle. (rejectPieceMessageInQueue): Use PeerMessageHandle. (abortPiece): Use PeerMessageHandle. (receiveHandshake): Replaced HandshakeMessage with HandshakeMessageHandle. Removed try-catch block. (createHandshakeMessage): Replaced HandshakeMessage with HandshakeMessageHandle. (receiveMessage): Replaced PeerMessage with PeerMessageHandle. Removed try-catch block. (createPeerMessage): Replaced PeerMessage with PeerMessageHandle. * src/HttpProxyResponseCommand.cc (HttpProxyRequestCommand): Replaced Socket with SocketHandle. * src/FtpTunnelResponseCommand.h (FtpTunnelResponseCommand): Replaced Socket with SocketHandle. * src/HttpConnection.cc (HttpConnection): Replaced Socket with SocketHandle. * src/PeerAbstractCommand.cc (PeerAbstractCommand): Replaced Socket with SocketHandle. (~PeerAbstractCommand): Removed the deallocation of socket. Use disableReadCheckSocket, disableWriteCheckSocket. (disableReadCheckSocket): New function. (setReadCheckSocket): Replaced Socket with SocketHandle. (disableWriteCheckSocket): New function. (setWriteCheckSocket): Replaced Socket with SocketHandle. * src/InitiateConnectionCommandFactory.h: Corrected indentation. * src/FtpTunnelRequestCommand.cc (FtpTunnelRequestCommand): Replaced Socket with SocketHandle. (~FtpTunnelRequestCommand): Corrected indentation. * src/DownloadCommand.h (DownloadCommand): Replaced Socket with SocketHandle. * src/PeerListenCommand.cc (PeerListenCommand): Removed the initialization of socket. (~PeerListenCommand): Removed the deallocation of socket. (bindPort): Use SocketHandle. (execute): Use SocketHandle and PeerHandle. * src/FtpDowndloadCommand.cc (FtpDownloadCommand): Replaced Socket with SocketHandle. (~FtpDownloadCommand): Removed the deallocation of ctrlSocket. * src/main.cc (main): Corrected indentation. * src/HttpInitiateConnectionCommand.cc (HttpInitiateConnectionCommand): Replaced Socket with SocketHandle. (executeInternal): Removed the allocation of socket. * src/HttpRequestCommand.h (HttpRequestCommand): Replaced Socket with SocketHandle. * src/FtpNegotiationCommand.h (dataSocket): Changed its type to SocketHandle. (serverSocket): Changed its type to SocketHandle. (FtpNegotiationCommand): Replaced Socket with SocketHandle. * src/TorrentMan.h (MAX_PEER_UPDATE): Removed. (MAX_PEERS): New definition. (Peers): The element is now of type PeerHandle. (addPeer): Replaced Peer with PeerHandle. Removed 'duplicate' argument. (getPeer): Replaced Peer with PeerHandle. (deleteOldErrorPeers): Removed. (deleteErrorPeer): New function. (hasMissingPiece): Replaced Peer with PeerHandle. (getMissingPieceIndex): Replaced Peer with PeerHandle. (getMissingPiece): Replaced Peer with PeerHandle. (getMissingFastPieceIndex): Replaced Peer with PeerHandle. (getMissingFastPiece): Replaced Peer with PeerHandle. (addActivePeer): Replaced Peer with PeerHandle. (deleteActivePeer): Replaced Peer with PeerHandle. Added a check for the return value of find. * src/FtpTunnelResponseCommand.cc (FtpTunnelResponseCommand): Replaced Socket with SocketHandle. * src/FtpInitiateConnectionCommand.cc (executeInternal): Removed the allocation of socket. * src/DownloadEngine.h (Sockets): An element is now of type SocketHandle. (SockCmdMap): A key is of type SocketHandle, a value is of type int. (CommandUuids): New type definition. (rsockets): Changed its type to SockCmdMap. (wsockets): Changed its type to SockCmdMap. (addSocket): Rewritten. (deleteSocket): Rewritten. (addSocketForReadCheck): Rewritten. (deleteSocketForReadCheck): Rewritten. (addSocketForWriteCheck): Rewritten. (deleteSocketForWriteCheck): Rewritten. (PairFind): New template class. * src/HttpDownloadCommand.h (HttpDownloadCommand): Replaced Socket with SocketHandle. * src/FtpConnection.cc (FtpConnection): Replaced Socket with SocketHandle. (sendPort): Removed the allocation of serverSocket. Removed try-catch block. * src/InitiateConnectionCommandFactory.cc (DlAbortEx.h): Included DlAbortEx.h. (createInitiateConnectionCommand): Throw exception if the protocol of requested URI is not supported. * src/Peer.cc (nullPeer): Changed its type to PeerHandle. (operator==): New function. (operator!=): New function. * src/Peer.h (SharedHandle.h): Included SharedHandle.h. (operator==): New function. (operator!=): New function. (Peer): Added the default constructor. Use resetStatus() to initialize member variables. (nullPeer): Removed. * src/TrackerUpdateCommand.cc (execute): Brushed up using SharedHandle. Replaced MAX_PEER_UPDATE with MIN_PEERS. * src/PeerListenCommand.h (socket): Changed its type to SocketHandle. * src/Command.h (CommandUuid): New type definition. (uuid): New variable. (uuidGen): New variable. (Command): Added the initialization of uuid. (getUuid): New function. * src/Socket.h (Socket): Removed. (SocketHandle): New type definition. * src/DownloadEngine.h (FindCommand): New function object. (run): The portion of socket check was rewritten. (SetDescriptor): New function object. (AccumulateActiveCommandUuid): New function object. (waitData): Rewritten. (addSocket): Rewritten. (deleteSocket): Rewritten. (addSocketForReadCheck): Rewritten. (addSocketForWriteCheck): Rewritten. (deleteSocketForReadCheck): Rewritten. (deleteSocketForWriteCheck): Rewritten. * src/HttpProxyResponseCommand.h (HttpProxyResponseCommand): Replaced Socket with SocketHandle. * src/HttpConnection.h (socket): Changed its type to SocketHandle. (HttpConnection): Replaced Socket with SocketHandle. * src/PeerInitiateConnectionCommand.cc (PeerInitiateConnectionCommand): Replaced Peer with PeerHandle. (executeInternal): Removed the allocation of socket. (prepareForNextPeer): Use PeerHandle. * src/PeerMessage.h (peer): Changed its type to PeerHandle. (getPeer): Replaced Peer with PeerHandle. (setPeer): Replaced Peer with PeerHandle. * src/DownloadCommand.cc (DownloadCommand): Replaced Socket with SocketHandle. * src/FtpConnection.h (socket): Changed its type to SocketHandle. (FtpConnection): Replaced Socket with SocketHandle. (sendPort); Replaced Socket with SocketHandle. * src/FtpDowndloadCommand.h (ctrlSocket): Changed its type to SocketHandle. (FtpDownloadCommand): Replaced Socket with SocketHandle. * src/HttpProxyRequestCommand.cc (HttpProxyRequestCommand): Replaced Socket with SocketHandle. * src/FtpTunnelRequestCommand.h (FtpTunnelRequestCommand): Replaced Socket with SocketHandle. etc * src/PeerChokeCommand.h (setAllPeerChoked): Removed. (setAllPeerResetDelta): Removed. * src/PeerChokeCommand.cc (setAllPeerChoked): Removed. (ChokePeer): New function object. (setAllPeerResetDelta): Removed. (ResetDelta): New function object. (orderByDownloadRate): Fixed a bug: use DowloadFaster, not UploadFaster (execute): Show download speed when the local node is a seeder. setAllPeerChoked and setAllPeerResetDelta were rewritten using STL. * src/TrackerWatcherCommand.h (MIN_PEERS): Removed. * src/TorrentMan.cc (getPeer): Replaced MAX_PEER_UPDATE with MIN_PEERS.
2006-07-19 17:07:45 +00:00
PeerInteractionCommand(int cuid, const PeerHandle& peer,
TorrentDownloadEngine* e,
const SocketHandle& s, int sequence);
2006-03-21 14:12:51 +00:00
~PeerInteractionCommand();
enum Seq {
INITIATOR_SEND_HANDSHAKE,
INITIATOR_WAIT_HANDSHAKE,
RECEIVER_SEND_HANDSHAKE,
RECEIVER_WAIT_HANDSHAKE,
WIRED};
};
#endif // _D_PEER_INTERACTION_COMMAND_H_