Commit Graph

11 Commits (338e8aca09331d3e7fa4e1e8e1f9d10260986772)

Author SHA1 Message Date
Tatsuhiro Tsujikawa 15582ed8cd 2009-03-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Refactored BtMessage subclasses. BtCancelMessage,
	BtRequestMessage and BtRejectMessage are derived from
	RangeBtMessage class.
	BtAllowedFastMessage, BtHaveMessage and BtSuggestPieceMessage
	are derived from IndexBtMessage class. BtChokeMessage,
	BtHaveAllMessage, BtHaveNoneMessage, BtInterestedMessage,
	BtNotInterestedMessage and BtUnchokeMessage are derived from
	ZeroBtMessage class.
	* src/AbstractBtMessage.cc
	* src/AbstractBtMessage.h
	* src/BtAllowedFastMessage.cc
	* src/BtAllowedFastMessage.h
	* src/BtAllowedFastMessageValidator.h: Removed
	* src/BtBitfieldMessage.cc
	* src/BtBitfieldMessage.h
	* src/BtCancelMessage.cc
	* src/BtCancelMessage.h
	* src/BtCancelMessageValidator.h: Removed
	* src/BtChokeMessage.cc
	* src/BtChokeMessage.h
	* src/BtExtendedMessage.cc
	* src/BtExtendedMessage.h
	* src/BtHandshakeMessage.cc
	* src/BtHandshakeMessage.h
	* src/BtHaveAllMessage.cc
	* src/BtHaveAllMessage.h
	* src/BtHaveMessage.cc
	* src/BtHaveMessage.h
	* src/BtHaveMessageValidator.h: Removed
	* src/BtHaveNoneMessage.cc
	* src/BtHaveNoneMessage.h
	* src/BtInterestedMessage.cc
	* src/BtInterestedMessage.h
	* src/BtKeepAliveMessage.cc
	* src/BtKeepAliveMessage.h
	* src/BtNotInterestedMessage.cc
	* src/BtNotInterestedMessage.h
	* src/BtPieceMessage.cc
	* src/BtPieceMessage.h
	* src/BtPortMessage.cc
	* src/BtPortMessage.h
	* src/BtRejectMessage.cc
	* src/BtRejectMessage.h
	* src/BtRejectMessageValidator.h: Removed
	* src/BtRequestMessage.cc
	* src/BtRequestMessage.h
	* src/BtRequestMessageValidator.h: Removed
	* src/BtSuggestPieceMessage.cc
	* src/BtSuggestPieceMessage.h
	* src/BtSuggestPieceMessageValidator.h: Removed
	* src/BtUnchokeMessage.cc
	* src/BtUnchokeMessage.h
	* src/DefaultBtMessageFactory.cc
	* src/IndexBtMessage.cc
	* src/IndexBtMessage.h
	* src/IndexBtMessageValidator.h
	* src/Makefile.am
	* src/PeerMessageUtil.cc
	* src/PeerMessageUtil.h
	* src/RangeBtMessage.cc
	* src/RangeBtMessage.h
	* src/RangeBtMessageValidator.h
	* src/SimpleBtMessage.cc
	* src/SimpleBtMessage.h
	* src/ZeroBtMessage.cc
	* src/ZeroBtMessage.h
	* test/BtRequestMessageTest.cc
2009-03-12 15:54:43 +00:00
Tatsuhiro Tsujikawa 4e0c03500c 2009-03-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
BtMessage now holds _id attribute.  MESSAGE_LENGTH that is
	declared as non-const previously is now const and defined in
	class definition.
	* src/AbstractBtMessage.cc
	* src/AbstractBtMessage.h
	* src/BtAllowedFastMessage.cc
	* src/BtAllowedFastMessage.h
	* src/BtBitfieldMessage.h
	* src/BtCancelMessage.cc
	* src/BtCancelMessage.h
	* src/BtChokeMessage.cc
	* src/BtChokeMessage.h
	* src/BtExtendedMessage.cc
	* src/BtExtendedMessage.h
	* src/BtHandshakeMessage.cc
	* src/BtHandshakeMessage.h
	* src/BtHaveAllMessage.cc
	* src/BtHaveAllMessage.h
	* src/BtHaveMessage.cc
	* src/BtHaveMessage.h
	* src/BtHaveNoneMessage.cc
	* src/BtHaveNoneMessage.h
	* src/BtInterestedMessage.cc
	* src/BtInterestedMessage.h
	* src/BtKeepAliveMessage.cc
	* src/BtKeepAliveMessage.h
	* src/BtMessage.h
	* src/BtNotInterestedMessage.cc
	* src/BtNotInterestedMessage.h
	* src/BtPieceMessage.h
	* src/BtPortMessage.cc
	* src/BtPortMessage.h
	* src/BtRejectMessage.cc
	* src/BtRejectMessage.h
	* src/BtRequestMessage.cc
	* src/BtRequestMessage.h
	* src/BtSuggestPieceMessage.cc
	* src/BtSuggestPieceMessage.h
	* src/BtUnchokeMessage.cc
	* src/BtUnchokeMessage.h
	* src/SimpleBtMessage.cc
	* src/SimpleBtMessage.h
	* test/MockBtMessage.h
2009-03-11 15:44:04 +00:00
Tatsuhiro Tsujikawa 7cf589e784 2008-11-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made BtRegistry non-static object. Now DownloadEngine has a
	reference to its object.
	* src/AbstractBtMessage.cc
	* src/ActivePeerConnectionCommand.cc
	* src/ActivePeerConnectionCommand.h
	* src/BtContextAwareCommand.cc
	* src/BtContextAwareCommand.h
	* src/BtExtendedMessage.cc
	* src/BtExtendedMessage.h
	* src/BtInterestedMessage.cc
	* src/BtInterestedMessage.h
	* src/BtNotInterestedMessage.cc
	* src/BtNotInterestedMessage.h
	* src/BtRegistry.cc
	* src/BtRegistry.h
	* src/BtSeederStateChoke.cc
	* src/BtSetup.cc
	* src/DHTGetPeersCommand.cc
	* src/DHTGetPeersCommand.h
	* src/DHTPeerAnnounceEntry.cc
	* src/DHTPeerAnnounceEntry.h
	* src/DHTPeerAnnounceStorage.cc
	* src/DHTPeerAnnounceStorage.h
	* src/DHTPeerLookupTask.cc
	* src/DHTPeerLookupTask.h
	* src/DHTSetup.cc
	* src/DHTSetup.h
	* src/DHTTaskFactory.h
	* src/DHTTaskFactoryImpl.cc
	* src/DHTTaskFactoryImpl.h
	* src/DefaultBtAnnounce.cc
	* src/DefaultBtInteractive.cc
	* src/DefaultBtInteractive.h
	* src/DefaultBtMessageDispatcher.cc
	* src/DefaultBtMessageDispatcher.h
	* src/DefaultBtMessageFactory.cc
	* src/DefaultBtMessageFactory.h
	* src/DefaultBtMessageReceiver.cc
	* src/DefaultBtProgressInfoFile.cc
	* src/DefaultBtProgressInfoFile.h
	* src/DefaultBtRequestFactory.cc
	* src/DefaultBtRequestFactory.h
	* src/DefaultExtensionMessageFactory.cc
	* src/DefaultExtensionMessageFactory.h
	* src/DefaultPeerStorage.cc
	* src/DefaultPeerStorage.h
	* src/DownloadEngine.cc
	* src/DownloadEngine.h
	* src/InitiatorMSEHandshakeCommand.cc
	* src/InitiatorMSEHandshakeCommand.h
	* src/MSEHandshake.cc
	* src/MSEHandshake.h
	* src/Makefile.am
	* src/Makefile.in
	* src/PeerChokeCommand.cc
	* src/PeerChokeCommand.h
	* src/PeerInitiateConnectionCommand.cc
	* src/PeerInitiateConnectionCommand.h
	* src/PeerInteractionCommand.cc
	* src/PeerInteractionCommand.h
	* src/PeerObject.h
	* src/PeerReceiveHandshakeCommand.cc
	* src/PeerReceiveHandshakeCommand.h
	* src/ReceiverMSEHandshakeCommand.cc
	* src/RequestGroup.cc
	* src/RequestGroup.h
	* src/RequestGroupMan.cc
	* src/RequestGroupMan.h
	* src/SeedCheckCommand.cc
	* src/SeedCheckCommand.h
	* src/ShareRatioSeedCriteria.h
	* src/SimpleBtMessage.cc
	* src/TrackerWatcherCommand.cc
	* src/TrackerWatcherCommand.h
	* src/UTPexExtensionMessage.cc
	* src/UTPexExtensionMessage.h
	* test/BtCancelMessageTest.cc
	* test/BtChokeMessageTest.cc
	* test/BtExtendedMessageTest.cc
	* test/BtInterestedMessageTest.cc
	* test/BtNotInterestedMessageTest.cc
	* test/BtPieceMessageTest.cc
	* test/BtPortMessageTest.cc
	* test/BtRegistryTest.cc
	* test/BtRejectMessageTest.cc
	* test/BtRequestMessageTest.cc
	* test/DHTPeerAnnounceEntryTest.cc
	* test/DHTPeerAnnounceStorageTest.cc
	* test/DefaultBtMessageDispatcherTest.cc
	* test/DefaultBtMessageFactoryTest.cc
	* test/DefaultBtProgressInfoFileTest.cc
	* test/DefaultBtRequestFactoryTest.cc
	* test/DefaultExtensionMessageFactoryTest.cc
	* test/MSEHandshakeTest.cc
	* test/MockDHTTaskFactory.h
	* test/ShareRatioSeedCriteriaTest.cc
	* test/UTPexExtensionMessageTest.cc
2008-11-03 06:49:02 +00:00
Tatsuhiro Tsujikawa 9c946467c9 2008-10-02 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Replaced '%zu' with '%lu' since mingw32 doesn't recognize '%zu'.
	* src/BtPieceMessage.cc
	* src/DHTPeerAnnounceStorage.cc
	* src/DefaultPieceStorage.cc
	* src/DownloadCommand.cc
	* src/DownloadEngine.cc
	* src/FtpConnection.cc
	* src/PeerConnection.cc
	* src/PeerMessageUtil.cc
	* src/RequestGroup.cc
	* src/RequestGroupMan.cc
	* src/SimpleBtMessage.cc
2008-10-01 15:16:36 +00:00
Tatsuhiro Tsujikawa 4f280af10b 2008-09-28 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed the bug that aria2 may send duplicate data to BitTorrent 
peer if
	whole message data is not sent in one send() call.
	* src/BtPieceMessage.cc
	* src/BtPieceMessage.h
	* src/PeerConnection.cc
	* src/PeerConnection.h
	* src/SimpleBtMessage.cc
	* src/SimpleBtMessage.h
2008-09-28 10:55:17 +00:00
Tatsuhiro Tsujikawa 032c7c2808 2008-03-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
type cleanup for allmost all remaining files.
2008-03-09 12:24:01 +00:00
Tatsuhiro Tsujikawa 1b7c198289 2008-02-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Removed "using namespace std;" from all sources. Appended std:: 
prefix to c++
	standard classes.
	Included string.h where mem* function are used.
2008-02-08 15:53:45 +00:00
Tatsuhiro Tsujikawa 6574e44f88 2007-07-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Converted int's to in32_t. long long int's are also converted to
	int64_t
2007-07-21 08:56:16 +00:00
Tatsuhiro Tsujikawa a1df7a762e 2007-01-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To decrease CPU usage in bittorrent download, calculation 
results in
	BitfieldMan were cached and realtime fetching PeerObject was 
removed
	with WeakHandle introduced. Option values are set to the objects
	by setter before download begins.

	* src/DefaultBtRequestFactory.cc: Use messageFactory member.
	* src/DefaultBtRequestFactory.h
	(dispatcher): BtMessageDispatcherHandle ->
	BtMessageDispatcherWeakHandle.
	(messageFactory): New variable.
	(setBtMessageDispatcher): BtMessageDispatcherHandle ->
	BtMessageDispatcherWeakHandle.
	(setBtMessageFactory): New function.
	* src/DefaultBtMessageDispatcher.cc:
	(sendMessages): Use maxUploadSpeedLimit instead of fetching the 
value
	from Option.
	(checkRequestSlotAndDoNecessaryThing): Use requestTimeout 
instead of
	feating the value from Option.
	Use messageFactory member.
	* src/PeerInteractionCommand.cc
	(PeerInteractionCommand): Added maxDownloadSpeedLimit.
	Add reverse dependencies to factory object.
	Set maxUploadSpeedLimit and requestTimeout and messageFactory to
	dispatcher.
	Set messageFactory to receiver.
	Set keepAliveInterval and maxDownloadSpeedLimit and 
messageFactory to
	btInteractive.
	Set receiver to peerObject.
	Set maxDownloadSpeedLimit to this.
	(executeInternal): Use maxDownloadSpeedLimit member.
	* src/BtChokeMessage.cc
	(doReceivedAction): Use dispatcher, requestFactory member.
	(onSendComplete): Use dispatcher member.
	* src/PeerInteractionCommand.h
	(maxDownloadSpeedLimit): New variable.
	* src/DefaultBtMessageReceiver.h
	(peerConnection): PeerConnectionHandle -> 
PeerConnectionWeakHandle
	(dispatcher):
	BtMessageDispatcherHandle -> BtMessageDispatcherWeakHandle
	(messageFactory): New variable.
	(setPeerConnection): PeerConnectionHandle -> 
PeerConnectionWeakHandle
	(getPeerConnection): PeerConnectionHandle -> 
PeerConnectionWeakHandle
	(setDispatcher):
	BtMessageDispatcherHandle -> BtMessageDispatcherWeakHandle
	(setBtMessageFactory): New function.
	* src/DefaultBtInteractive.cc
	(initiateHandshake): Use messageFactory member.
	(addBitfieldMessageToQueue): Use messageFactory member.
	(addAllowedFastMessageToQueue): Use messageFactory member.
	(decideChoking): Use messageFactory member.
	(checkHave): Use messageFactory member.
	(sendKeepAlive): Use keepAliveInterval, messageFactory member.
	(receiveMessages): Use maxDownloadSpeedLimit member.
	(decideInterest): Use messageFactory member.
	* src/BtRequestMessage.cc
	(doReceivedAction): Use messageFactory, dispatcher member.
	(onQueued): Use dispatcher member.
	* src/BtPieceMessage.cc
	(doReceivedAction): Use dispatcher member.
	(send): Use peerConnection member.
	(onWrongPiece): Use requestFactory member.
	(handleChokingEvent): Use messageFactory, dispatcher member.
	(handleCancelSendingPieceEvent): Use messageFactory, dispatcher 
member.
	* src/BtMessageDispatcher.h
	(BtMessageDispatcherWeakHandle): New type definition.
	* src/SimpleBtMessage.cc
	(send): Use peerConnection member.
	* src/BtRejectMessage.cc
	(doReceivedAction): Use dispatcher member.
	* src/DefaultBtMessageDispatcher.h
	(Option.h): Removed include.
	(messageFactory): New variable.
	(option): Removed.
	(maxUploadSpeedLimit): New variable.
	(requestTimeout): New variable.
	(DefaultBtMessageDispatcher): Removed option.
	Added maxUploadSpeedLimit, requestTimeout.
	(setOption): Removed.
	(getOption): Removed.
	(setMaxUploadSpeedLimit): New function.
	(setRequestTimeout): New function.
	(setBtMessageFactory): New function.
	* src/DefaultBtInteractive.h
	(btMessageReceiver):
	BtMessageReceiverHandle -> BtMessageReceiverWeakHandle
	(dispatcher):
	BtMessageDispatcherHandle -> BtMessageReceiverWeakHandle
	(btRequestFactory):
	BtRequestFactoryHandle -> BtRequestFactoryWeakHandle
	(peerConnection):
	PeerConnectionHandle -> PeerConnectionWeakHandle
	(messageFactory): New variable.
	(option): Removed.
	(keepAliveInterval): New variable.
	(maxDownloadSpeedLimit): New variable.
	(DefaultBtInteractive): Added keepAliveInterval, 
maxDownloadSpeedLimit.
	(setBtMessageReceiver):
	BtMessageReceiverHandle -> BtMessageReceiverWeakHandle
	(setDispatcher):
	BtMessageDispatcherHandle -> BtMessageReceiverWeakHandle
	(setBtRequestFactory):
	BtRequestFactoryHandle -> BtRequestFactoryWeakHandle
	(setPeerConnection):
	PeerConnectionHandle -> PeerConnectionWeakHandle
	(setOption): Removed.
	(setKeepAliveInterval): New function.
	(setMaxDownloadSpeedLimit): New function.
	(setBtMessageFactory): New function.
	* src/BitfieldMan.h
	(cachedNumMissingBlock): New variable.
	(cachedNumFilteredBlock): New variable.
	(cachedCompletedLength): New variable.
	(cachedFilteredComletedLength): New variable.
	(cachedFilteredTotalLength): New variable.
	(countMissingBlockNow): New function.
	(countFilteredBlockNow): New function.
	(getFilteredTotalLengthNow): New function.
	(getCompletedLengthNow): New function.
	(getFilteredCompletedLengthNow): New function.
	(updateCache): New function.
	* src/AbstractBtMessage.h
	(BtMessageDispatcher.h): New include.
	(PeerConnection.h): New include.
	(BtRequestFactory.h): New include
	(BtMessageFactory.h): New include.
	(dispatcher): New variable.
	(messageFactory): New variable.
	(peerConnection: New variable.
	(setBtMessageDispatcher): New function.
	(setPeerConnection): New function.
	(setBtMessageFactory): New function.
	(setBtRequestFactory): New function.
	* src/DefaultBtMessageFactory.cc
	(setCommonProperty): Set dispatcher, requestFactory, this,
	peerConnection to msg.
	* src/BtRegistry.h
	(BT_MESSAGE_RECEIVER): New macro.
	* src/PeerConnection.h
	(PeerConnectionWeakHandle): New type definition.
	* src/BtMessageFactory.h
	(BtMessageFactoryWeakHandle): New type definition.
	* src/BitfieldMan.cc
	(BitfieldMan): Added cachedNumMissingBlock, 
cachedNumFilteredBlock,
	cachedCompletedLength, cachedFilteredComletedLength,
	cachedFilteredTotalLength.
	Call updateCache().
	(countMissingBlock): Return cachedNumMissingBlock.
	(countMissingBlockNow): New function.
	(countBlock): Return cachedNumFilteredBlock if filterEnabled is 
true.
	(countFilteredBlockNow): New function.
	(setBit): Call updateCache().
	(unsetBit): Call updateCache().
	(setBitfield): Call updateCache().
	(clearAllBit): Call updateCache().
	(setAllBit): Use setBitInternal instead of setBit.
	Call updateCache().
	(addFilter): Call updateCache().
	(enableFilter): Call updateCache().
	(disableFilter): Call updateCache().
	(clearFilter): Call updateCache().
	(getFilteredTotalLength): Return cachedFilteredTotalLength.
	(getFilteredTotalLengthNow): New function.
	(getCompletedLength): Return cachedCompletedLength.
	(getCompletedLengthNow): New function.
	(getFilteredCompletedLength): Return 
cachedFilteredComletedLength.
	(getFilteredCompletedLengthNow): New function.
	(updateCache): New function.
	* src/BtMessageReceiver.h
	(BtMessageReceiverWeakHandle): New type definition.
	* src/DefaultBtMessageReceiver.cc
	(receiveHandshake): Use messageFactory member.
	(sendHandshake): Use messageFactory member.
	(receiveMessage): Use messageFactory member.
	* src/DefaultBtMessageFactory.h
	(dispatcher): New variable.
	(requestFactory): New variable.
	(peerConnection): New variablle.
	(setBtMessageDispatcher): New function.
	(setBtRequestFactory): New function.
	(setPeerConnection): New function.
	* src/SharedHandle.h
	(RefCount): New class.
	(WeakHandle): New class.
	* src/PeerObject.h
	(BtMessageReceiver.h): New include.
	(PeerObject): Added btMessageReceiver.
	(btMessageReceiver): New variable.
	* src/Util.cc
	(countBit): Simplified.
	* src/BtCancelMessage.cc
	(doReceivedAction): Use dispatcher member.
	* src/BtRequestFactory.h
	(BtRequestFactoryWeakHandle): New type definition.
	
	* src/PeerStorage.h
	(downloadSpeed): int -> uint32_t
	(uploadSpeed): int -> uint32_t
	(sessionDownloadLength): long long int -> uint64_t
	(sessionUploadLength): long long int -> uint64_t
2007-01-16 15:20:26 +00:00
Tatsuhiro Tsujikawa a413cb50f7 2006-12-24 15:55:59 +00:00
Tatsuhiro Tsujikawa 9c3e8fbd9c 2006-12-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten a portion of bittorrent implementation:
	
	* src/BtMessageValidator.h: New class.
	* src/BtBitfieldMessageValidator.h: New class.
	* src/BtHandshakeMessageValidator.h: New class.
	* src/BtRequestMessageValidator.h: New class.
	* src/BtSuggestPieceMessageValidator.h: New class.
	* src/BtAllowedFastMessageValidator.h: New class.
	* src/BtRejectMessageValidator.h: New class.
	* src/BtCancelMessageValidator.h: New class.
	* src/BtPieceMessageValidator.h: New class.
	* src/BtHaveMessageValidator.h: New class.
	* src/BtEventListener.h: New class.
	* src/AbstractBtEventListener.h: New class.
	* src/BtEvent.h: New class.
	* src/BtChokingEvent.h: New class.
	* src/BtChokedEvent.h: New class.
	* src/BtCancelSendingPieceEvent.h: New class.
	* src/BtAbortOutstandingRequestEvent.h: New class.
	* src/Randomizer.h: New class.
	* src/SimpleRandomizer.h: New class.
	* src/BtMessage.h: New class.
	* src/AbstractBtMessage.h: New class.
	* src/SimpleBtMessage.h: New class.
	* src/BtHaveMessage.h: New class.
	* src/BtInterestedMessage.h: New class.
	* src/BtAllowedFastMessage.h: New class.
	* src/BtUnchokeMessage.h: New class.
	* src/BtCancelMessage.h: New class.
	* src/BtNotInterestedMessage.h: New class.
	* src/BtChokeMessage.h: New class.
	* src/BtHaveNoneMessage.h: New class.
	* src/BtHandshakeMessage.h: New class.
	* src/BtSuggestPieceMessage.h: New class.
	* src/BtHaveMessage.h: New class.
	* src/BtPieceMessage.h: New class.
	* src/BtHaveAllMessage.h: New class.
	* src/BtKeepAliveMessage.h: New class.
	* src/BtPortMessage.h: New class.
	* src/BtRejectMessage.h: New class.
	* src/BtBitfieldMessage.h: New class.
	* src/BtRequestMessage.h: New class.
	* src/DefaultBtRequestFactory.h: New class.
	* src/DefaultBtMessageReceiver.h: New class.
	* src/BtInteractive.h: New class.
	* src/BtMessageDispatcher.h: New class.
	* src/DefaultBtMessageDispatcher.h: New class.
	* src/DefaultBtInteractive.h: New class.
	* src/BitfieldManFactory.h: New class.
	* src/HandleRegistry.h: New class.
	* src/BtMessageFactory.h: New class.
	* src/BtMessageReceiver.h: New class.
	* src/DefaultBtMessageFactory.h: New class.
	* src/PeerObject.h: New class.
	* src/BtRequestFactory.h: New class.
2006-12-24 06:25:21 +00:00