2006-12-24 06:25:21 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - The high speed download utility
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-12-24 06:25:21 +00:00
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "DefaultBtInteractive.h"
|
2008-11-03 06:49:02 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
2010-02-28 12:30:11 +00:00
|
|
|
#include <vector>
|
2008-11-03 06:49:02 +00:00
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
#include "prefs.h"
|
|
|
|
#include "message.h"
|
|
|
|
#include "BtHandshakeMessage.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2006-12-24 06:25:21 +00:00
|
|
|
#include "BtKeepAliveMessage.h"
|
|
|
|
#include "BtChokeMessage.h"
|
|
|
|
#include "BtUnchokeMessage.h"
|
2007-06-20 14:43:34 +00:00
|
|
|
#include "BtRequestMessage.h"
|
|
|
|
#include "BtPieceMessage.h"
|
2013-06-30 07:55:15 +00:00
|
|
|
#include "BtPortMessage.h"
|
|
|
|
#include "BtInterestedMessage.h"
|
|
|
|
#include "BtNotInterestedMessage.h"
|
|
|
|
#include "BtHaveMessage.h"
|
|
|
|
#include "BtHaveAllMessage.h"
|
|
|
|
#include "BtBitfieldMessage.h"
|
|
|
|
#include "BtHaveNoneMessage.h"
|
|
|
|
#include "BtAllowedFastMessage.h"
|
2006-12-24 06:25:21 +00:00
|
|
|
#include "DlAbortEx.h"
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
#include "BtExtendedMessage.h"
|
|
|
|
#include "HandshakeExtensionMessage.h"
|
|
|
|
#include "UTPexExtensionMessage.h"
|
|
|
|
#include "DefaultExtensionMessageFactory.h"
|
2009-04-25 10:48:00 +00:00
|
|
|
#include "ExtensionMessageRegistry.h"
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
#include "DHTNode.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Peer.h"
|
|
|
|
#include "Piece.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "PieceStorage.h"
|
|
|
|
#include "PeerStorage.h"
|
|
|
|
#include "BtRuntime.h"
|
|
|
|
#include "BtMessageReceiver.h"
|
|
|
|
#include "BtMessageDispatcher.h"
|
|
|
|
#include "BtMessageFactory.h"
|
|
|
|
#include "BtRequestFactory.h"
|
2010-06-13 11:00:43 +00:00
|
|
|
#include "PeerConnection.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Logger.h"
|
|
|
|
#include "LogFactory.h"
|
2010-11-20 08:21:36 +00:00
|
|
|
#include "fmt.h"
|
2008-09-28 05:07:52 +00:00
|
|
|
#include "RequestGroup.h"
|
2009-02-28 11:48:26 +00:00
|
|
|
#include "RequestGroupMan.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "bittorrent_helper.h"
|
2009-11-23 13:17:48 +00:00
|
|
|
#include "UTMetadataRequestFactory.h"
|
|
|
|
#include "UTMetadataRequestTracker.h"
|
2010-03-06 08:29:53 +00:00
|
|
|
#include "wallclock.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
DefaultBtInteractive::DefaultBtInteractive
|
2013-06-21 16:10:38 +00:00
|
|
|
(const std::shared_ptr<DownloadContext>& downloadContext,
|
|
|
|
const std::shared_ptr<Peer>& peer)
|
2012-10-29 14:09:16 +00:00
|
|
|
: cuid_(0),
|
|
|
|
downloadContext_(downloadContext),
|
2010-11-20 08:21:36 +00:00
|
|
|
peer_(peer),
|
|
|
|
metadataGetMode_(false),
|
|
|
|
localNode_(0),
|
|
|
|
allowedFastSetSize_(10),
|
2011-08-09 16:17:28 +00:00
|
|
|
haveTimer_(global::wallclock()),
|
|
|
|
keepAliveTimer_(global::wallclock()),
|
|
|
|
floodingTimer_(global::wallclock()),
|
|
|
|
inactiveTimer_(global::wallclock()),
|
|
|
|
pexTimer_(global::wallclock()),
|
|
|
|
perSecTimer_(global::wallclock()),
|
2010-11-20 08:21:36 +00:00
|
|
|
keepAliveInterval_(120),
|
|
|
|
utPexEnabled_(false),
|
|
|
|
dhtEnabled_(false),
|
|
|
|
numReceivedMessage_(0),
|
|
|
|
maxOutstandingRequest_(DEFAULT_MAX_OUTSTANDING_REQUEST),
|
2012-10-29 14:39:13 +00:00
|
|
|
requestGroupMan_(0),
|
2013-01-14 09:11:31 +00:00
|
|
|
tcpPort_(0),
|
2013-01-15 14:50:12 +00:00
|
|
|
haveLastSent_(global::wallclock())
|
2008-02-08 15:53:45 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
DefaultBtInteractive::~DefaultBtInteractive() {}
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
void DefaultBtInteractive::initiateHandshake() {
|
2013-06-30 07:55:15 +00:00
|
|
|
dispatcher_->addMessageToQueue
|
|
|
|
(messageFactory_->createHandshakeMessage
|
|
|
|
(bittorrent::getInfoHash(downloadContext_),
|
|
|
|
bittorrent::getStaticPeerId()));
|
2010-06-21 13:51:56 +00:00
|
|
|
dispatcher_->sendMessages();
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2013-07-04 13:35:41 +00:00
|
|
|
std::unique_ptr<BtHandshakeMessage> DefaultBtInteractive::receiveHandshake
|
|
|
|
(bool quickReply) {
|
|
|
|
auto message = btMessageReceiver_->receiveHandshake(quickReply);
|
2010-11-12 12:48:48 +00:00
|
|
|
if(!message) {
|
2013-07-04 12:44:09 +00:00
|
|
|
return nullptr;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
2009-06-28 10:37:15 +00:00
|
|
|
if(memcmp(message->getPeerId(), bittorrent::getStaticPeerId(),
|
2010-01-05 16:01:46 +00:00
|
|
|
PEER_ID_LENGTH) == 0) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX
|
2012-06-25 13:43:33 +00:00
|
|
|
(fmt("CUID#%" PRId64 " - Drop connection from the same Peer ID",
|
2010-11-20 12:12:06 +00:00
|
|
|
cuid_));
|
2008-06-08 10:27:57 +00:00
|
|
|
}
|
2013-07-04 13:35:41 +00:00
|
|
|
for(auto& peer : peerStorage_->getUsedPeers()) {
|
|
|
|
if(peer->isActive() &&
|
|
|
|
memcmp(peer->getPeerId(), message->getPeerId(), PEER_ID_LENGTH) == 0) {
|
2010-03-30 13:05:53 +00:00
|
|
|
throw DL_ABORT_EX
|
2012-06-25 13:43:33 +00:00
|
|
|
(fmt("CUID#%" PRId64 " - Same Peer ID has been already seen.",
|
2010-11-20 12:12:06 +00:00
|
|
|
cuid_));
|
2010-03-30 13:05:53 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-08 10:27:57 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
peer_->setPeerId(message->getPeerId());
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
if(message->isFastExtensionSupported()) {
|
2010-06-21 13:51:56 +00:00
|
|
|
peer_->setFastExtensionEnabled(true);
|
2010-11-20 12:12:06 +00:00
|
|
|
A2_LOG_INFO(fmt(MSG_FAST_EXTENSION_ENABLED, cuid_));
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
if(message->isExtendedMessagingEnabled()) {
|
2010-06-21 13:51:56 +00:00
|
|
|
peer_->setExtendedMessagingEnabled(true);
|
|
|
|
if(!utPexEnabled_) {
|
2012-09-26 13:02:48 +00:00
|
|
|
extensionMessageRegistry_->removeExtension
|
|
|
|
(ExtensionMessageRegistry::UT_PEX);
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
}
|
2010-11-20 12:12:06 +00:00
|
|
|
A2_LOG_INFO(fmt(MSG_EXTENDED_MESSAGING_ENABLED, cuid_));
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
if(message->isDHTEnabled()) {
|
2010-06-21 13:51:56 +00:00
|
|
|
peer_->setDHTEnabled(true);
|
2010-11-20 12:12:06 +00:00
|
|
|
A2_LOG_INFO(fmt(MSG_DHT_ENABLED_PEER, cuid_));
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
2010-11-20 12:12:06 +00:00
|
|
|
A2_LOG_INFO(fmt(MSG_RECEIVE_PEER_MESSAGE, cuid_,
|
2010-11-20 08:21:36 +00:00
|
|
|
peer_->getIPAddress().c_str(), peer_->getPort(),
|
|
|
|
message->toString().c_str()));
|
2008-02-08 15:53:45 +00:00
|
|
|
return message;
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2013-07-04 13:35:41 +00:00
|
|
|
std::unique_ptr<BtHandshakeMessage>
|
|
|
|
DefaultBtInteractive::receiveAndSendHandshake()
|
|
|
|
{
|
2006-12-24 06:25:21 +00:00
|
|
|
return receiveHandshake(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::doPostHandshakeProcessing() {
|
2010-04-11 08:28:22 +00:00
|
|
|
// Set time 0 to haveTimer to cache http/ftp download piece completion
|
2010-06-21 13:51:56 +00:00
|
|
|
haveTimer_.reset(0);
|
2011-08-09 16:17:28 +00:00
|
|
|
keepAliveTimer_ = global::wallclock();
|
|
|
|
floodingTimer_ = global::wallclock();
|
2010-06-21 13:51:56 +00:00
|
|
|
pexTimer_.reset(0);
|
|
|
|
if(peer_->isExtendedMessagingEnabled()) {
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
addHandshakeExtendedMessageToQueue();
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(!metadataGetMode_) {
|
2009-11-23 13:17:48 +00:00
|
|
|
addBitfieldMessageToQueue();
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(peer_->isDHTEnabled() && dhtEnabled_) {
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
addPortMessageToQueue();
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(!metadataGetMode_) {
|
2009-11-23 13:17:48 +00:00
|
|
|
addAllowedFastMessageToQueue();
|
|
|
|
}
|
2007-01-11 16:32:31 +00:00
|
|
|
sendPendingMessage();
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
void DefaultBtInteractive::addPortMessageToQueue()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
dispatcher_->addMessageToQueue
|
|
|
|
(messageFactory_->createPortMessage(localNode_->getPort()));
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
}
|
|
|
|
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
void DefaultBtInteractive::addHandshakeExtendedMessageToQueue()
|
|
|
|
{
|
2013-07-01 12:42:51 +00:00
|
|
|
auto m = make_unique<HandshakeExtensionMessage>();
|
2012-09-24 14:20:43 +00:00
|
|
|
m->setClientVersion("aria2/" PACKAGE_VERSION);
|
2011-07-21 14:42:41 +00:00
|
|
|
m->setTCPPort(tcpPort_);
|
2010-06-21 13:51:56 +00:00
|
|
|
m->setExtensions(extensionMessageRegistry_->getExtensions());
|
2013-06-22 15:59:55 +00:00
|
|
|
auto attrs = bittorrent::getTorrentAttrs(downloadContext_);
|
2010-06-18 14:47:09 +00:00
|
|
|
if(!attrs->metadata.empty()) {
|
|
|
|
m->setMetadataSize(attrs->metadataSize);
|
2009-11-20 15:42:25 +00:00
|
|
|
}
|
2013-07-01 12:42:51 +00:00
|
|
|
dispatcher_->addMessageToQueue
|
|
|
|
(messageFactory_->createBtExtendedMessage(std::move(m)));
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
}
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
void DefaultBtInteractive::addBitfieldMessageToQueue() {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(peer_->isFastExtensionEnabled()) {
|
|
|
|
if(pieceStorage_->allDownloadFinished()) {
|
|
|
|
dispatcher_->addMessageToQueue(messageFactory_->createHaveAllMessage());
|
|
|
|
} else if(pieceStorage_->getCompletedLength() > 0) {
|
|
|
|
dispatcher_->addMessageToQueue(messageFactory_->createBitfieldMessage());
|
2006-12-24 06:25:21 +00:00
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
dispatcher_->addMessageToQueue(messageFactory_->createHaveNoneMessage());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(pieceStorage_->getCompletedLength() > 0) {
|
|
|
|
dispatcher_->addMessageToQueue(messageFactory_->createBitfieldMessage());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::addAllowedFastMessageToQueue() {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(peer_->isFastExtensionEnabled()) {
|
2009-06-28 10:37:15 +00:00
|
|
|
std::vector<size_t> fastSet;
|
2010-06-21 13:51:56 +00:00
|
|
|
bittorrent::computeFastSet(fastSet, peer_->getIPAddress(),
|
|
|
|
downloadContext_->getNumPieces(),
|
|
|
|
bittorrent::getInfoHash(downloadContext_),
|
|
|
|
allowedFastSetSize_);
|
2010-02-28 16:04:52 +00:00
|
|
|
for(std::vector<size_t>::const_iterator itr = fastSet.begin(),
|
|
|
|
eoi = fastSet.end(); itr != eoi; ++itr) {
|
2010-06-21 13:51:56 +00:00
|
|
|
dispatcher_->addMessageToQueue
|
|
|
|
(messageFactory_->createAllowedFastMessage(*itr));
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::decideChoking() {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(peer_->shouldBeChoking()) {
|
|
|
|
if(!peer_->amChoking()) {
|
|
|
|
dispatcher_->addMessageToQueue(messageFactory_->createChokeMessage());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(peer_->amChoking()) {
|
|
|
|
dispatcher_->addMessageToQueue(messageFactory_->createUnchokeMessage());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::checkHave() {
|
2013-01-14 09:11:31 +00:00
|
|
|
const size_t MIN_HAVE_PACK_SIZE = 20;
|
|
|
|
const time_t MAX_HAVE_DELAY_SEC = 10;
|
|
|
|
pieceStorage_->getAdvertisedPieceIndexes(haveIndexes_, cuid_, haveTimer_);
|
2011-08-09 16:17:28 +00:00
|
|
|
haveTimer_ = global::wallclock();
|
2013-01-14 09:11:31 +00:00
|
|
|
if(haveIndexes_.size() >= MIN_HAVE_PACK_SIZE) {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(peer_->isFastExtensionEnabled() &&
|
|
|
|
pieceStorage_->allDownloadFinished()) {
|
|
|
|
dispatcher_->addMessageToQueue(messageFactory_->createHaveAllMessage());
|
2006-12-24 06:25:21 +00:00
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
dispatcher_->addMessageToQueue(messageFactory_->createBitfieldMessage());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
2013-01-14 09:11:31 +00:00
|
|
|
haveIndexes_.clear();
|
2006-12-24 06:25:21 +00:00
|
|
|
} else {
|
2013-01-14 09:11:31 +00:00
|
|
|
if(haveIndexes_.size() >= MIN_HAVE_PACK_SIZE ||
|
|
|
|
haveLastSent_.difference(global::wallclock()) >= MAX_HAVE_DELAY_SEC) {
|
|
|
|
haveLastSent_ = global::wallclock();
|
|
|
|
for(std::vector<size_t>::const_iterator itr = haveIndexes_.begin(),
|
|
|
|
eoi = haveIndexes_.end(); itr != eoi; ++itr) {
|
|
|
|
dispatcher_->addMessageToQueue(messageFactory_->
|
|
|
|
createHaveMessage(*itr));
|
|
|
|
}
|
|
|
|
haveIndexes_.clear();
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::sendKeepAlive() {
|
2011-08-09 16:17:28 +00:00
|
|
|
if(keepAliveTimer_.difference(global::wallclock()) >= keepAliveInterval_) {
|
2010-06-21 13:51:56 +00:00
|
|
|
dispatcher_->addMessageToQueue(messageFactory_->createKeepAliveMessage());
|
|
|
|
dispatcher_->sendMessages();
|
2011-08-09 16:17:28 +00:00
|
|
|
keepAliveTimer_ = global::wallclock();
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 18:27:28 +00:00
|
|
|
size_t DefaultBtInteractive::receiveMessages() {
|
2010-06-21 13:51:56 +00:00
|
|
|
size_t countOldOutstandingRequest = dispatcher_->countOutstandingRequest();
|
2008-02-08 18:27:28 +00:00
|
|
|
size_t msgcount = 0;
|
2012-06-25 12:37:55 +00:00
|
|
|
while(1) {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(requestGroupMan_->doesOverallDownloadSpeedExceed() ||
|
|
|
|
downloadContext_->getOwnerRequestGroup()->doesDownloadSpeedExceed()) {
|
2009-02-28 11:48:26 +00:00
|
|
|
break;
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
2013-07-04 13:35:41 +00:00
|
|
|
auto message = btMessageReceiver_->receiveMessage();
|
2010-11-12 12:48:48 +00:00
|
|
|
if(!message) {
|
2006-12-24 06:25:21 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-08 18:27:28 +00:00
|
|
|
++msgcount;
|
2010-11-20 08:21:36 +00:00
|
|
|
A2_LOG_INFO(fmt(MSG_RECEIVE_PEER_MESSAGE,
|
2010-11-20 12:12:06 +00:00
|
|
|
cuid_,
|
2010-11-20 08:21:36 +00:00
|
|
|
peer_->getIPAddress().c_str(), peer_->getPort(),
|
|
|
|
message->toString().c_str()));
|
2006-12-24 06:25:21 +00:00
|
|
|
message->doReceivedAction();
|
|
|
|
|
|
|
|
switch(message->getId()) {
|
|
|
|
case BtChokeMessage::ID:
|
2010-06-21 13:51:56 +00:00
|
|
|
if(!peer_->peerChoking()) {
|
|
|
|
floodingStat_.incChokeUnchokeCount();
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BtUnchokeMessage::ID:
|
2010-06-21 13:51:56 +00:00
|
|
|
if(peer_->peerChoking()) {
|
|
|
|
floodingStat_.incChokeUnchokeCount();
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-03-19 13:42:10 +00:00
|
|
|
case BtRequestMessage::ID:
|
2013-06-30 07:55:15 +00:00
|
|
|
case BtPieceMessage::ID:
|
2011-08-09 16:17:28 +00:00
|
|
|
inactiveTimer_ = global::wallclock();
|
2007-06-20 14:43:34 +00:00
|
|
|
break;
|
2013-06-30 07:55:15 +00:00
|
|
|
case BtKeepAliveMessage::ID:
|
|
|
|
floodingStat_.incKeepAliveCount();
|
|
|
|
break;
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-14 15:02:40 +00:00
|
|
|
|
2013-01-15 14:50:12 +00:00
|
|
|
if(!pieceStorage_->isEndGame() &&
|
|
|
|
countOldOutstandingRequest > dispatcher_->countOutstandingRequest() &&
|
|
|
|
(countOldOutstandingRequest - dispatcher_->countOutstandingRequest())*4 >=
|
|
|
|
maxOutstandingRequest_) {
|
|
|
|
maxOutstandingRequest_ =
|
|
|
|
std::min((size_t)UB_MAX_OUTSTANDING_REQUEST,
|
|
|
|
maxOutstandingRequest_*2);
|
2009-11-18 12:22:03 +00:00
|
|
|
}
|
2008-02-08 18:27:28 +00:00
|
|
|
return msgcount;
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::decideInterest() {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(pieceStorage_->hasMissingPiece(peer_)) {
|
|
|
|
if(!peer_->amInterested()) {
|
2010-11-20 12:12:06 +00:00
|
|
|
A2_LOG_DEBUG(fmt(MSG_PEER_INTERESTED, cuid_));
|
2010-06-21 13:51:56 +00:00
|
|
|
dispatcher_->
|
|
|
|
addMessageToQueue(messageFactory_->createInterestedMessage());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(peer_->amInterested()) {
|
2010-11-20 12:12:06 +00:00
|
|
|
A2_LOG_DEBUG(fmt(MSG_PEER_NOT_INTERESTED, cuid_));
|
2010-06-21 13:51:56 +00:00
|
|
|
dispatcher_->
|
|
|
|
addMessageToQueue(messageFactory_->createNotInterestedMessage());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-17 11:43:29 +00:00
|
|
|
void DefaultBtInteractive::fillPiece(size_t maxMissingBlock) {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(pieceStorage_->hasMissingPiece(peer_)) {
|
|
|
|
size_t numMissingBlock = btRequestFactory_->countMissingBlock();
|
2010-08-29 08:53:19 +00:00
|
|
|
if(numMissingBlock >= maxMissingBlock) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
size_t diffMissingBlock = maxMissingBlock-numMissingBlock;
|
2013-06-21 16:10:38 +00:00
|
|
|
std::vector<std::shared_ptr<Piece> > pieces;
|
2010-06-21 13:51:56 +00:00
|
|
|
if(peer_->peerChoking()) {
|
|
|
|
if(peer_->isFastExtensionEnabled()) {
|
2010-08-29 08:53:19 +00:00
|
|
|
if(pieceStorage_->isEndGame()) {
|
|
|
|
pieceStorage_->getMissingFastPiece
|
2013-06-30 07:55:15 +00:00
|
|
|
(pieces, diffMissingBlock, peer_,
|
|
|
|
btRequestFactory_->getTargetPieceIndexes(), cuid_);
|
2010-08-29 08:53:19 +00:00
|
|
|
} else {
|
|
|
|
pieces.reserve(diffMissingBlock);
|
2011-07-15 15:58:41 +00:00
|
|
|
pieceStorage_->getMissingFastPiece
|
|
|
|
(pieces, diffMissingBlock, peer_, cuid_);
|
2010-01-05 16:01:46 +00:00
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-08-29 08:53:19 +00:00
|
|
|
if(pieceStorage_->isEndGame()) {
|
|
|
|
pieceStorage_->getMissingPiece
|
2013-06-30 07:55:15 +00:00
|
|
|
(pieces, diffMissingBlock, peer_,
|
|
|
|
btRequestFactory_->getTargetPieceIndexes(), cuid_);
|
2012-10-01 14:52:22 +00:00
|
|
|
} else {
|
2010-08-29 08:53:19 +00:00
|
|
|
pieces.reserve(diffMissingBlock);
|
2011-07-15 15:58:41 +00:00
|
|
|
pieceStorage_->getMissingPiece(pieces, diffMissingBlock, peer_, cuid_);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-21 16:10:38 +00:00
|
|
|
for(std::vector<std::shared_ptr<Piece> >::const_iterator i =
|
2010-08-29 08:53:19 +00:00
|
|
|
pieces.begin(), eoi = pieces.end(); i != eoi; ++i) {
|
|
|
|
btRequestFactory_->addTargetPiece(*i);
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::addRequests() {
|
2010-08-26 14:49:40 +00:00
|
|
|
if(!pieceStorage_->isEndGame() && !pieceStorage_->hasMissingUnusedPiece()) {
|
|
|
|
pieceStorage_->enterEndGame();
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
fillPiece(maxOutstandingRequest_);
|
2008-03-09 12:24:01 +00:00
|
|
|
size_t reqNumToCreate =
|
2010-06-21 13:51:56 +00:00
|
|
|
maxOutstandingRequest_ <= dispatcher_->countOutstandingRequest() ?
|
|
|
|
0 : maxOutstandingRequest_-dispatcher_->countOutstandingRequest();
|
2013-01-14 09:11:31 +00:00
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
if(reqNumToCreate > 0) {
|
2013-06-30 07:55:15 +00:00
|
|
|
auto requests =
|
|
|
|
btRequestFactory_->createRequestMessages(reqNumToCreate,
|
|
|
|
pieceStorage_->isEndGame());
|
|
|
|
for(auto& i : requests) {
|
|
|
|
dispatcher_->addMessageToQueue(std::move(i));
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::cancelAllPiece() {
|
2010-06-21 13:51:56 +00:00
|
|
|
btRequestFactory_->removeAllTargetPiece();
|
|
|
|
if(metadataGetMode_ && downloadContext_->getTotalLength() > 0) {
|
2009-11-23 13:17:48 +00:00
|
|
|
std::vector<size_t> metadataRequests =
|
2010-06-21 13:51:56 +00:00
|
|
|
utMetadataRequestTracker_->getAllTrackedIndex();
|
2010-02-28 16:04:52 +00:00
|
|
|
for(std::vector<size_t>::const_iterator i = metadataRequests.begin(),
|
|
|
|
eoi = metadataRequests.end(); i != eoi; ++i) {
|
2010-11-20 08:21:36 +00:00
|
|
|
A2_LOG_DEBUG(fmt("Cancel metadata: piece=%lu",
|
|
|
|
static_cast<unsigned long>(*i)));
|
2011-07-15 15:58:41 +00:00
|
|
|
pieceStorage_->cancelPiece(pieceStorage_->getPiece(*i), cuid_);
|
2009-11-23 13:17:48 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::sendPendingMessage() {
|
2010-06-21 13:51:56 +00:00
|
|
|
dispatcher_->sendMessages();
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::detectMessageFlooding() {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(floodingTimer_.
|
2011-08-09 16:17:28 +00:00
|
|
|
difference(global::wallclock()) >= FLOODING_CHECK_INTERVAL) {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(floodingStat_.getChokeUnchokeCount() >= 2 ||
|
|
|
|
floodingStat_.getKeepAliveCount() >= 2) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(EX_FLOODING_DETECTED);
|
2006-12-24 06:25:21 +00:00
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
floodingStat_.reset();
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
2011-08-09 16:17:28 +00:00
|
|
|
floodingTimer_ = global::wallclock();
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-20 14:43:34 +00:00
|
|
|
void DefaultBtInteractive::checkActiveInteraction()
|
|
|
|
{
|
2011-08-09 16:17:28 +00:00
|
|
|
time_t inactiveTime = inactiveTimer_.difference(global::wallclock());
|
2008-03-05 15:31:09 +00:00
|
|
|
// To allow aria2 to accept mutially interested peer, disconnect unintersted
|
|
|
|
// peer.
|
|
|
|
{
|
2009-06-06 12:33:07 +00:00
|
|
|
const time_t interval = 30;
|
2010-06-21 13:51:56 +00:00
|
|
|
if(!peer_->amInterested() && !peer_->peerInterested() &&
|
2010-03-06 08:29:53 +00:00
|
|
|
inactiveTime >= interval) {
|
2010-08-04 15:00:38 +00:00
|
|
|
peer_->setDisconnectedGracefully(true);
|
2008-03-05 15:31:09 +00:00
|
|
|
// TODO change the message
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX
|
2010-11-20 09:36:14 +00:00
|
|
|
(fmt("Disconnect peer because we are not interested each other"
|
|
|
|
" after %ld second(s).",
|
|
|
|
static_cast<long int>(interval)));
|
2008-03-05 15:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Since the peers which are *just* connected and do nothing to improve
|
|
|
|
// mutual download progress are completely waste of resources, those peers
|
|
|
|
// are disconnected in a certain time period.
|
|
|
|
{
|
2009-10-06 12:56:15 +00:00
|
|
|
const time_t interval = 60;
|
2010-03-06 08:29:53 +00:00
|
|
|
if(inactiveTime >= interval) {
|
2010-08-04 15:00:38 +00:00
|
|
|
peer_->setDisconnectedGracefully(true);
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX
|
2010-11-20 09:36:14 +00:00
|
|
|
(fmt(EX_DROP_INACTIVE_CONNECTION,
|
|
|
|
static_cast<long int>(interval)));
|
2008-03-05 15:31:09 +00:00
|
|
|
}
|
2007-06-20 14:43:34 +00:00
|
|
|
}
|
2011-01-06 15:20:10 +00:00
|
|
|
// If both of us are seeders, drop connection.
|
|
|
|
if(peer_->isSeeder() && pieceStorage_->downloadFinished()) {
|
|
|
|
throw DL_ABORT_EX(MSG_GOOD_BYE_SEEDER);
|
|
|
|
}
|
2007-06-20 14:43:34 +00:00
|
|
|
}
|
|
|
|
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
void DefaultBtInteractive::addPeerExchangeMessage()
|
|
|
|
{
|
2013-07-01 12:42:51 +00:00
|
|
|
if(pexTimer_.difference(global::wallclock()) >=
|
|
|
|
UTPexExtensionMessage::DEFAULT_INTERVAL) {
|
|
|
|
auto m = make_unique<UTPexExtensionMessage>
|
|
|
|
(peer_->getExtensionMessageID(ExtensionMessageRegistry::UT_PEX));
|
|
|
|
auto& usedPeers = peerStorage_->getUsedPeers();
|
|
|
|
for(auto i = std::begin(usedPeers), eoi = std::end(usedPeers);
|
2010-08-04 12:25:46 +00:00
|
|
|
i != eoi && !m->freshPeersAreFull(); ++i) {
|
2013-01-26 09:36:09 +00:00
|
|
|
if((*i)->isActive() && peer_->getIPAddress() != (*i)->getIPAddress()) {
|
2010-08-04 12:25:46 +00:00
|
|
|
m->addFreshPeer(*i);
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-01 12:42:51 +00:00
|
|
|
auto& droppedPeers = peerStorage_->getDroppedPeers();
|
|
|
|
for(auto i = std::begin(droppedPeers), eoi = std::end(droppedPeers);
|
|
|
|
i != eoi && !m->droppedPeersAreFull(); ++i) {
|
2010-08-04 12:25:46 +00:00
|
|
|
if(peer_->getIPAddress() != (*i)->getIPAddress()) {
|
|
|
|
m->addDroppedPeer(*i);
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-30 07:55:15 +00:00
|
|
|
dispatcher_->addMessageToQueue
|
2013-07-01 12:42:51 +00:00
|
|
|
(messageFactory_->createBtExtendedMessage(std::move(m)));
|
2011-08-09 16:17:28 +00:00
|
|
|
pexTimer_ = global::wallclock();
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
void DefaultBtInteractive::doInteractionProcessing() {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(metadataGetMode_) {
|
2009-11-23 13:17:48 +00:00
|
|
|
sendKeepAlive();
|
2010-06-21 13:51:56 +00:00
|
|
|
numReceivedMessage_ = receiveMessages();
|
2009-11-23 13:17:48 +00:00
|
|
|
// PieceStorage is re-initialized with metadata_size in
|
|
|
|
// HandshakeExtensionMessage::doReceivedAction().
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_ =
|
|
|
|
downloadContext_->getOwnerRequestGroup()->getPieceStorage();
|
2012-09-26 13:02:48 +00:00
|
|
|
if(peer_->getExtensionMessageID(ExtensionMessageRegistry::UT_METADATA) &&
|
2010-06-21 13:51:56 +00:00
|
|
|
downloadContext_->getTotalLength() > 0) {
|
|
|
|
size_t num = utMetadataRequestTracker_->avail();
|
2009-11-23 13:17:48 +00:00
|
|
|
if(num > 0) {
|
2013-06-30 07:55:15 +00:00
|
|
|
auto requests =
|
2013-07-01 12:42:51 +00:00
|
|
|
utMetadataRequestFactory_->create(num, pieceStorage_.get());
|
2013-06-30 07:55:15 +00:00
|
|
|
for(auto& i : requests) {
|
|
|
|
dispatcher_->addMessageToQueue(std::move(i));
|
|
|
|
}
|
2009-11-23 13:17:48 +00:00
|
|
|
}
|
2011-08-09 16:17:28 +00:00
|
|
|
if(perSecTimer_.difference(global::wallclock()) >= 1) {
|
|
|
|
perSecTimer_ = global::wallclock();
|
2010-01-05 16:01:46 +00:00
|
|
|
// Drop timeout request after queuing message to give a chance
|
|
|
|
// to other connection to request piece.
|
2013-07-01 12:42:51 +00:00
|
|
|
auto indexes = utMetadataRequestTracker_->removeTimeoutEntry();
|
|
|
|
for(auto idx : indexes) {
|
|
|
|
pieceStorage_->cancelPiece(pieceStorage_->getPiece(idx), cuid_);
|
2010-01-05 16:01:46 +00:00
|
|
|
}
|
2009-11-23 13:17:48 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(pieceStorage_->downloadFinished()) {
|
|
|
|
downloadContext_->getOwnerRequestGroup()->setForceHaltRequested
|
2010-01-05 16:01:46 +00:00
|
|
|
(true, RequestGroup::NONE);
|
2009-12-04 12:48:54 +00:00
|
|
|
}
|
2009-11-23 13:17:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
checkActiveInteraction();
|
|
|
|
decideChoking();
|
|
|
|
detectMessageFlooding();
|
2011-08-09 16:17:28 +00:00
|
|
|
if(perSecTimer_.difference(global::wallclock()) >= 1) {
|
|
|
|
perSecTimer_ = global::wallclock();
|
2010-06-21 13:51:56 +00:00
|
|
|
dispatcher_->checkRequestSlotAndDoNecessaryThing();
|
2009-11-23 13:17:48 +00:00
|
|
|
}
|
|
|
|
checkHave();
|
|
|
|
sendKeepAlive();
|
2010-06-21 13:51:56 +00:00
|
|
|
numReceivedMessage_ = receiveMessages();
|
|
|
|
btRequestFactory_->removeCompletedPiece();
|
2009-11-23 13:17:48 +00:00
|
|
|
decideInterest();
|
2010-06-21 13:51:56 +00:00
|
|
|
if(!pieceStorage_->downloadFinished()) {
|
2009-11-23 13:17:48 +00:00
|
|
|
addRequests();
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
2012-09-26 13:02:48 +00:00
|
|
|
if(peer_->getExtensionMessageID(ExtensionMessageRegistry::UT_PEX) &&
|
|
|
|
utPexEnabled_) {
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
addPeerExchangeMessage();
|
|
|
|
}
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
sendPendingMessage();
|
|
|
|
}
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
|
2010-11-12 12:48:48 +00:00
|
|
|
void DefaultBtInteractive::setLocalNode(DHTNode* node)
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
localNode_ = node;
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
size_t DefaultBtInteractive::countPendingMessage()
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return dispatcher_->countMessageInQueue();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
bool DefaultBtInteractive::isSendingMessageInProgress()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return dispatcher_->isSendingInProgress();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 18:27:28 +00:00
|
|
|
size_t DefaultBtInteractive::countReceivedMessageInIteration() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return numReceivedMessage_;
|
2008-02-08 18:27:28 +00:00
|
|
|
}
|
|
|
|
|
2008-02-28 14:27:00 +00:00
|
|
|
size_t DefaultBtInteractive::countOutstandingRequest()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(metadataGetMode_) {
|
|
|
|
return utMetadataRequestTracker_->count();
|
2009-11-23 13:17:48 +00:00
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
return dispatcher_->countOutstandingRequest();
|
2009-11-23 13:17:48 +00:00
|
|
|
}
|
2008-02-28 14:27:00 +00:00
|
|
|
}
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
void DefaultBtInteractive::setBtRuntime
|
2013-06-21 16:10:38 +00:00
|
|
|
(const std::shared_ptr<BtRuntime>& btRuntime)
|
2008-11-03 06:49:02 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
btRuntime_ = btRuntime;
|
2008-11-03 06:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::setPieceStorage
|
2013-06-21 16:10:38 +00:00
|
|
|
(const std::shared_ptr<PieceStorage>& pieceStorage)
|
2008-11-03 06:49:02 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
pieceStorage_ = pieceStorage;
|
2008-11-03 06:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::setPeerStorage
|
2013-06-21 16:10:38 +00:00
|
|
|
(const std::shared_ptr<PeerStorage>& peerStorage)
|
2008-11-03 06:49:02 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
peerStorage_ = peerStorage;
|
2008-11-03 06:49:02 +00:00
|
|
|
}
|
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
void DefaultBtInteractive::setPeer(const std::shared_ptr<Peer>& peer)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
peer_ = peer;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
void DefaultBtInteractive::setBtMessageReceiver
|
2013-07-06 12:12:55 +00:00
|
|
|
(std::unique_ptr<BtMessageReceiver> receiver)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2013-07-06 12:12:55 +00:00
|
|
|
btMessageReceiver_ = std::move(receiver);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
void DefaultBtInteractive::setDispatcher
|
2013-07-06 12:12:55 +00:00
|
|
|
(std::unique_ptr<BtMessageDispatcher> dispatcher)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2013-07-06 12:12:55 +00:00
|
|
|
dispatcher_ = std::move(dispatcher);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
void DefaultBtInteractive::setBtRequestFactory
|
2013-07-06 12:12:55 +00:00
|
|
|
(std::unique_ptr<BtRequestFactory> factory)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2013-07-06 12:12:55 +00:00
|
|
|
btRequestFactory_ = std::move(factory);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 11:00:43 +00:00
|
|
|
void DefaultBtInteractive::setPeerConnection
|
2013-07-06 12:12:55 +00:00
|
|
|
(std::unique_ptr<PeerConnection> peerConnection)
|
2010-06-13 11:00:43 +00:00
|
|
|
{
|
2013-07-06 12:12:55 +00:00
|
|
|
peerConnection_ = std::move(peerConnection);
|
2010-06-13 11:00:43 +00:00
|
|
|
}
|
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
void DefaultBtInteractive::setExtensionMessageFactory
|
2013-07-01 12:42:51 +00:00
|
|
|
(std::unique_ptr<ExtensionMessageFactory> factory)
|
2008-11-03 06:49:02 +00:00
|
|
|
{
|
2013-07-01 12:42:51 +00:00
|
|
|
extensionMessageFactory_ = std::move(factory);
|
2008-11-03 06:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::setBtMessageFactory
|
2013-07-06 12:12:55 +00:00
|
|
|
(std::unique_ptr<BtMessageFactory> factory)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2013-07-06 12:12:55 +00:00
|
|
|
messageFactory_ = std::move(factory);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2010-11-12 12:48:48 +00:00
|
|
|
void DefaultBtInteractive::setRequestGroupMan(RequestGroupMan* rgman)
|
2009-02-28 11:48:26 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
requestGroupMan_ = rgman;
|
2009-02-28 11:48:26 +00:00
|
|
|
}
|
|
|
|
|
2013-07-06 12:12:55 +00:00
|
|
|
void DefaultBtInteractive::setExtensionMessageRegistry
|
|
|
|
(std::unique_ptr<ExtensionMessageRegistry> registry)
|
|
|
|
{
|
|
|
|
extensionMessageRegistry_ = std::move(registry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::setUTMetadataRequestTracker
|
|
|
|
(std::unique_ptr<UTMetadataRequestTracker> tracker)
|
|
|
|
{
|
|
|
|
utMetadataRequestTracker_ = std::move(tracker);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtInteractive::setUTMetadataRequestFactory
|
|
|
|
(std::unique_ptr<UTMetadataRequestFactory> factory)
|
|
|
|
{
|
|
|
|
utMetadataRequestFactory_ = std::move(factory);
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|