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
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
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
|
|
|
*
|
|
|
|
* 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-09-21 15:31:24 +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.
|
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
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "TrackerWatcherCommand.h"
|
2008-11-03 06:49:02 +00:00
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "DownloadEngine.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "BtAnnounce.h"
|
|
|
|
#include "BtRuntime.h"
|
|
|
|
#include "PieceStorage.h"
|
|
|
|
#include "PeerStorage.h"
|
|
|
|
#include "Peer.h"
|
2006-06-18 09:23:25 +00:00
|
|
|
#include "prefs.h"
|
2007-07-20 17:06:21 +00:00
|
|
|
#include "message.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "ByteArrayDiskWriterFactory.h"
|
|
|
|
#include "RecoverableException.h"
|
|
|
|
#include "PeerInitiateConnectionCommand.h"
|
|
|
|
#include "DiskAdaptor.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "RequestGroup.h"
|
|
|
|
#include "Option.h"
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
#include "DlAbortEx.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Logger.h"
|
2010-11-20 08:21:36 +00:00
|
|
|
#include "LogFactory.h"
|
2008-05-13 14:15:23 +00:00
|
|
|
#include "A2STR.h"
|
2008-05-17 09:15:14 +00:00
|
|
|
#include "SocketCore.h"
|
2008-11-23 15:00:44 +00:00
|
|
|
#include "Request.h"
|
2009-02-01 03:24:02 +00:00
|
|
|
#include "AnnounceTier.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
|
|
|
#include "bittorrent_helper.h"
|
2010-01-11 15:35:12 +00:00
|
|
|
#include "a2functional.h"
|
2010-03-21 07:05:49 +00:00
|
|
|
#include "util.h"
|
2010-11-20 08:21:36 +00:00
|
|
|
#include "fmt.h"
|
2013-02-24 15:56:49 +00:00
|
|
|
#include "UDPTrackerRequest.h"
|
|
|
|
#include "UDPTrackerClient.h"
|
|
|
|
#include "BtRegistry.h"
|
|
|
|
#include "NameResolveCommand.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
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
|
|
|
|
2013-07-06 11:58:09 +00:00
|
|
|
HTTPAnnRequest::HTTPAnnRequest(std::unique_ptr<RequestGroup> rg)
|
|
|
|
: rg_{std::move(rg)}
|
2013-02-24 15:56:49 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
HTTPAnnRequest::~HTTPAnnRequest()
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool HTTPAnnRequest::stopped() const
|
|
|
|
{
|
|
|
|
return rg_->getNumCommand() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HTTPAnnRequest::success() const
|
|
|
|
{
|
|
|
|
return rg_->downloadFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPAnnRequest::stop(DownloadEngine* e)
|
|
|
|
{
|
|
|
|
rg_->setForceHaltRequested(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HTTPAnnRequest::issue(DownloadEngine* e)
|
|
|
|
{
|
|
|
|
try {
|
2013-06-23 12:55:52 +00:00
|
|
|
std::vector<std::unique_ptr<Command>> commands;
|
|
|
|
rg_->createInitialCommand(commands, e);
|
|
|
|
e->addCommand(std::move(commands));
|
2013-02-24 15:56:49 +00:00
|
|
|
e->setNoWait(true);
|
|
|
|
A2_LOG_DEBUG("added tracker request command");
|
|
|
|
return true;
|
|
|
|
} catch(RecoverableException& ex) {
|
|
|
|
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, ex);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HTTPAnnRequest::processResponse
|
2013-06-21 16:10:38 +00:00
|
|
|
(const std::shared_ptr<BtAnnounce>& btAnnounce)
|
2013-02-24 15:56:49 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
std::stringstream strm;
|
|
|
|
unsigned char data[2048];
|
|
|
|
rg_->getPieceStorage()->getDiskAdaptor()->openFile();
|
|
|
|
while(1) {
|
|
|
|
ssize_t dataLength = rg_->getPieceStorage()->
|
|
|
|
getDiskAdaptor()->readData(data, sizeof(data), strm.tellp());
|
|
|
|
if(dataLength == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
strm.write(reinterpret_cast<const char*>(data), dataLength);
|
|
|
|
}
|
|
|
|
std::string res = strm.str();
|
|
|
|
btAnnounce->processAnnounceResponse
|
|
|
|
(reinterpret_cast<const unsigned char*>(res.c_str()), res.size());
|
|
|
|
return true;
|
|
|
|
} catch(RecoverableException& e) {
|
|
|
|
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
UDPAnnRequest::UDPAnnRequest(const std::shared_ptr<UDPTrackerRequest>& req)
|
2013-02-24 15:56:49 +00:00
|
|
|
: req_(req)
|
|
|
|
{}
|
|
|
|
|
|
|
|
UDPAnnRequest::~UDPAnnRequest()
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool UDPAnnRequest::stopped() const
|
|
|
|
{
|
|
|
|
return !req_ || req_->state == UDPT_STA_COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UDPAnnRequest::success() const
|
|
|
|
{
|
|
|
|
return req_ && req_->state == UDPT_STA_COMPLETE &&
|
|
|
|
req_->error == UDPT_ERR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UDPAnnRequest::stop(DownloadEngine* e)
|
|
|
|
{
|
|
|
|
if(req_) {
|
|
|
|
req_.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UDPAnnRequest::issue(DownloadEngine* e)
|
|
|
|
{
|
|
|
|
if(req_) {
|
2013-06-23 12:55:52 +00:00
|
|
|
e->addCommand(make_unique<NameResolveCommand>(e->newCUID(), e, req_));
|
2013-02-24 15:56:49 +00:00
|
|
|
e->setNoWait(true);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UDPAnnRequest::processResponse
|
2013-06-21 16:10:38 +00:00
|
|
|
(const std::shared_ptr<BtAnnounce>& btAnnounce)
|
2013-02-24 15:56:49 +00:00
|
|
|
{
|
|
|
|
if(req_) {
|
|
|
|
btAnnounce->processUDPTrackerResponse(req_);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
TrackerWatcherCommand::TrackerWatcherCommand
|
2010-11-20 08:21:36 +00:00
|
|
|
(cuid_t cuid, RequestGroup* requestGroup, DownloadEngine* e)
|
|
|
|
: Command(cuid),
|
|
|
|
requestGroup_(requestGroup),
|
2013-02-24 15:56:49 +00:00
|
|
|
e_(e),
|
|
|
|
udpTrackerClient_(e_->getBtRegistry()->getUDPTrackerClient())
|
2009-04-23 15:00:09 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
requestGroup_->increaseNumCommand();
|
2013-02-24 15:56:49 +00:00
|
|
|
if(udpTrackerClient_) {
|
|
|
|
udpTrackerClient_->increaseWatchers();
|
|
|
|
}
|
2009-04-23 15:00:09 +00:00
|
|
|
}
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
|
2009-04-23 15:00:09 +00:00
|
|
|
TrackerWatcherCommand::~TrackerWatcherCommand()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
requestGroup_->decreaseNumCommand();
|
2013-02-24 15:56:49 +00:00
|
|
|
if(udpTrackerClient_) {
|
|
|
|
udpTrackerClient_->decreaseWatchers();
|
|
|
|
}
|
2009-04-23 15:00:09 +00:00
|
|
|
}
|
2006-10-20 13:20:50 +00:00
|
|
|
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
bool TrackerWatcherCommand::execute() {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(requestGroup_->isForceHaltRequested()) {
|
2013-02-24 15:56:49 +00:00
|
|
|
if(!trackerRequest_) {
|
2007-12-07 13:33:59 +00:00
|
|
|
return true;
|
2013-02-24 15:56:49 +00:00
|
|
|
} else if(trackerRequest_->stopped() ||
|
|
|
|
trackerRequest_->success()) {
|
2007-12-07 13:33:59 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2013-02-24 15:56:49 +00:00
|
|
|
trackerRequest_->stop(e_);
|
2011-05-15 14:35:06 +00:00
|
|
|
e_->setRefreshInterval(0);
|
2013-06-23 12:55:52 +00:00
|
|
|
e_->addCommand(std::unique_ptr<Command>(this));
|
2007-12-07 13:33:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(btAnnounce_->noMoreAnnounce()) {
|
2010-11-20 08:21:36 +00:00
|
|
|
A2_LOG_DEBUG("no more announce");
|
2006-10-20 13:20:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-02-24 15:56:49 +00:00
|
|
|
if(!trackerRequest_) {
|
|
|
|
trackerRequest_ = createAnnounce(e_);
|
|
|
|
if(trackerRequest_) {
|
|
|
|
trackerRequest_->issue(e_);
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
2013-02-24 15:56:49 +00:00
|
|
|
} else if(trackerRequest_->stopped()) {
|
2012-09-02 08:43:26 +00:00
|
|
|
// We really want to make sure that tracker request has finished
|
|
|
|
// by checking getNumCommand() == 0. Because we reset
|
|
|
|
// trackerRequestGroup_, if it is still used in other Command, we
|
|
|
|
// will get Segmentation fault.
|
2013-02-24 15:56:49 +00:00
|
|
|
if(trackerRequest_->success()) {
|
|
|
|
if(trackerRequest_->processResponse(btAnnounce_)) {
|
2012-09-07 12:45:36 +00:00
|
|
|
btAnnounce_->announceSuccess();
|
|
|
|
btAnnounce_->resetAnnounce();
|
2013-02-24 15:56:49 +00:00
|
|
|
addConnection();
|
|
|
|
} else {
|
2012-09-07 12:45:36 +00:00
|
|
|
btAnnounce_->announceFailure();
|
|
|
|
if(btAnnounce_->isAllAnnounceFailed()) {
|
|
|
|
btAnnounce_->resetAnnounce();
|
|
|
|
}
|
|
|
|
}
|
2013-02-24 15:56:49 +00:00
|
|
|
trackerRequest_.reset();
|
2012-09-07 12:45:36 +00:00
|
|
|
} else {
|
|
|
|
// handle errors here
|
|
|
|
btAnnounce_->announceFailure(); // inside it, trackers = 0.
|
2013-02-24 15:56:49 +00:00
|
|
|
trackerRequest_.reset();
|
2010-06-21 13:51:56 +00:00
|
|
|
if(btAnnounce_->isAllAnnounceFailed()) {
|
|
|
|
btAnnounce_->resetAnnounce();
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2006-10-20 13:20:50 +00:00
|
|
|
}
|
2013-06-23 12:55:52 +00:00
|
|
|
e_->addCommand(std::unique_ptr<Command>(this));
|
2006-10-20 13:20:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-24 15:56:49 +00:00
|
|
|
void TrackerWatcherCommand::addConnection()
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
while(!btRuntime_->isHalt() && btRuntime_->lessThanMinPeers()) {
|
2013-01-26 08:50:06 +00:00
|
|
|
if(!peerStorage_->isPeerAvailable()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cuid_t ncuid = e_->newCUID();
|
2013-06-21 16:10:38 +00:00
|
|
|
std::shared_ptr<Peer> peer = peerStorage_->checkoutPeer(ncuid);
|
2013-01-26 08:50:06 +00:00
|
|
|
// sanity check
|
2010-11-12 12:48:48 +00:00
|
|
|
if(!peer) {
|
2007-10-11 16:58:24 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-06-23 12:55:52 +00:00
|
|
|
auto command = make_unique<PeerInitiateConnectionCommand>
|
|
|
|
(ncuid, requestGroup_, peer, e_, btRuntime_);
|
2010-06-21 13:51:56 +00:00
|
|
|
command->setPeerStorage(peerStorage_);
|
|
|
|
command->setPieceStorage(pieceStorage_);
|
2013-06-23 12:55:52 +00:00
|
|
|
e_->addCommand(std::move(command));
|
2012-06-25 13:43:33 +00:00
|
|
|
A2_LOG_DEBUG(fmt("CUID#%" PRId64 " - Adding new command CUID#%" PRId64 "",
|
2011-11-13 11:55:06 +00:00
|
|
|
getCuid(), peer->usedBy()));
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-22 16:55:56 +00:00
|
|
|
|
2013-07-06 11:58:09 +00:00
|
|
|
std::unique_ptr<AnnRequest>
|
2013-02-24 15:56:49 +00:00
|
|
|
TrackerWatcherCommand::createAnnounce(DownloadEngine* e)
|
|
|
|
{
|
|
|
|
while(!btAnnounce_->isAllAnnounceFailed() &&
|
|
|
|
btAnnounce_->isAnnounceReady()) {
|
|
|
|
std::string uri = btAnnounce_->getAnnounceUrl();
|
|
|
|
uri_split_result res;
|
|
|
|
memset(&res, 0, sizeof(res));
|
|
|
|
if(uri_split(&res, uri.c_str()) == 0) {
|
|
|
|
// Without UDP tracker support, send it to normal tracker flow
|
|
|
|
// and make it fail.
|
2013-07-06 11:58:09 +00:00
|
|
|
std::unique_ptr<AnnRequest> treq;
|
2013-02-24 15:56:49 +00:00
|
|
|
if(udpTrackerClient_ &&
|
|
|
|
uri::getFieldString(res, USR_SCHEME, uri.c_str()) == "udp") {
|
|
|
|
uint16_t localPort;
|
|
|
|
localPort = e->getBtRegistry()->getUdpPort();
|
|
|
|
treq = createUDPAnnRequest
|
|
|
|
(uri::getFieldString(res, USR_HOST, uri.c_str()), res.port,
|
|
|
|
localPort);
|
|
|
|
} else {
|
|
|
|
treq = createHTTPAnnRequest(btAnnounce_->getAnnounceUrl());
|
|
|
|
}
|
|
|
|
btAnnounce_->announceStart(); // inside it, trackers++.
|
2013-07-06 11:58:09 +00:00
|
|
|
return treq;
|
2013-02-24 15:56:49 +00:00
|
|
|
} else {
|
|
|
|
btAnnounce_->announceFailure();
|
|
|
|
}
|
2006-10-18 14:57:00 +00:00
|
|
|
}
|
2013-02-24 15:56:49 +00:00
|
|
|
if(btAnnounce_->isAllAnnounceFailed()) {
|
|
|
|
btAnnounce_->resetAnnounce();
|
|
|
|
}
|
2013-07-06 11:58:09 +00:00
|
|
|
return nullptr;
|
2013-02-24 15:56:49 +00:00
|
|
|
}
|
|
|
|
|
2013-07-06 11:58:09 +00:00
|
|
|
std::unique_ptr<AnnRequest>
|
2013-02-24 15:56:49 +00:00
|
|
|
TrackerWatcherCommand::createUDPAnnRequest(const std::string& host,
|
|
|
|
uint16_t port,
|
|
|
|
uint16_t localPort)
|
|
|
|
{
|
2013-07-06 11:58:09 +00:00
|
|
|
return make_unique<UDPAnnRequest>
|
|
|
|
(btAnnounce_->createUDPTrackerRequest(host, port, localPort));
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
}
|
2006-10-18 14:57:00 +00:00
|
|
|
|
2010-10-30 16:02:15 +00:00
|
|
|
namespace {
|
|
|
|
bool backupTrackerIsAvailable
|
2013-06-21 16:10:38 +00:00
|
|
|
(const std::shared_ptr<DownloadContext>& context)
|
2009-02-01 03:24:02 +00:00
|
|
|
{
|
2013-06-22 15:59:55 +00:00
|
|
|
auto torrentAttrs = bittorrent::getTorrentAttrs(context);
|
2010-06-18 14:47:09 +00:00
|
|
|
if(torrentAttrs->announceList.size() >= 2) {
|
2009-02-01 03:24:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-06-18 14:47:09 +00:00
|
|
|
if(torrentAttrs->announceList.empty()) {
|
2009-02-01 03:24:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-06-18 14:47:09 +00:00
|
|
|
if(torrentAttrs->announceList[0].size() >= 2) {
|
2009-02-01 03:24:02 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2010-10-30 16:02:15 +00:00
|
|
|
} // namespace
|
2009-02-01 03:24:02 +00:00
|
|
|
|
2013-07-06 11:58:09 +00:00
|
|
|
std::unique_ptr<AnnRequest>
|
2013-02-24 15:56:49 +00:00
|
|
|
TrackerWatcherCommand::createHTTPAnnRequest(const std::string& uri)
|
2007-03-21 10:19:23 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> uris;
|
2007-10-11 16:58:24 +00:00
|
|
|
uris.push_back(uri);
|
2013-07-06 11:58:09 +00:00
|
|
|
auto option = util::copy(getOption());
|
|
|
|
auto rg = make_unique<RequestGroup>(GroupId::create(), option);
|
2010-06-21 13:51:56 +00:00
|
|
|
if(backupTrackerIsAvailable(requestGroup_->getDownloadContext())) {
|
2010-11-20 08:21:36 +00:00
|
|
|
A2_LOG_DEBUG("This is multi-tracker announce.");
|
2009-02-01 03:24:02 +00:00
|
|
|
} else {
|
2010-11-20 08:21:36 +00:00
|
|
|
A2_LOG_DEBUG("This is single-tracker announce.");
|
2009-02-01 03:24:02 +00:00
|
|
|
}
|
2010-07-14 11:39:05 +00:00
|
|
|
rg->setNumConcurrentCommand(1);
|
2010-03-30 14:17:16 +00:00
|
|
|
// If backup tracker is available, try 2 times for each tracker
|
|
|
|
// and if they all fails, then try next one.
|
2011-10-25 12:44:04 +00:00
|
|
|
option->put(PREF_MAX_TRIES, "2");
|
2009-07-04 14:32:53 +00:00
|
|
|
// TODO When dry-run mode becomes available in BitTorrent, set
|
|
|
|
// PREF_DRY_RUN=false too.
|
2011-10-25 12:44:04 +00:00
|
|
|
option->put(PREF_USE_HEAD, A2_V_FALSE);
|
2010-03-30 14:17:16 +00:00
|
|
|
// Setting tracker timeouts
|
2011-10-25 12:44:04 +00:00
|
|
|
rg->setTimeout(option->getAsInt(PREF_BT_TRACKER_TIMEOUT));
|
|
|
|
option->put(PREF_CONNECT_TIMEOUT,
|
|
|
|
option->get(PREF_BT_TRACKER_CONNECT_TIMEOUT));
|
|
|
|
option->put(PREF_REUSE_URI, A2_V_FALSE);
|
|
|
|
option->put(PREF_SELECT_LEAST_USED_HOST, A2_V_FALSE);
|
2013-07-06 11:58:09 +00:00
|
|
|
auto dctx = std::make_shared<DownloadContext>
|
|
|
|
(option->getAsInt(PREF_PIECE_LENGTH),
|
|
|
|
0,
|
|
|
|
"[tracker.announce]");
|
2009-06-23 15:35:45 +00:00
|
|
|
dctx->getFileEntries().front()->setUris(uris);
|
2007-10-11 16:58:24 +00:00
|
|
|
rg->setDownloadContext(dctx);
|
2013-07-06 11:58:09 +00:00
|
|
|
auto dwf = std::make_shared<ByteArrayDiskWriterFactory>();
|
2008-04-20 00:50:22 +00:00
|
|
|
rg->setDiskWriterFactory(dwf);
|
2007-10-11 16:58:24 +00:00
|
|
|
rg->setFileAllocationEnabled(false);
|
|
|
|
rg->setPreLocalFileCheckEnabled(false);
|
2012-09-01 11:53:38 +00:00
|
|
|
// Clearing pre- and post handler is not needed because the
|
|
|
|
// RequestGroup is not handled by RequestGroupMan.
|
2012-08-31 15:53:30 +00:00
|
|
|
rg->clearPreDownloadHandler();
|
|
|
|
rg->clearPostDownloadHandler();
|
2012-09-22 14:19:41 +00:00
|
|
|
dctx->setAcceptMetalink(false);
|
2012-12-16 07:00:18 +00:00
|
|
|
A2_LOG_INFO(fmt("Creating tracker request group GID#%s",
|
|
|
|
GroupId::toHex(rg->getGID()).c_str()));
|
2013-07-06 11:58:09 +00:00
|
|
|
return make_unique<HTTPAnnRequest>(std::move(rg));
|
2006-10-18 14:57:00 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-11-03 06:49:02 +00:00
|
|
|
void TrackerWatcherCommand::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 TrackerWatcherCommand::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
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerWatcherCommand::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 TrackerWatcherCommand::setBtAnnounce
|
2013-06-21 16:10:38 +00:00
|
|
|
(const std::shared_ptr<BtAnnounce>& btAnnounce)
|
2008-11-03 06:49:02 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
btAnnounce_ = btAnnounce;
|
2008-11-03 06:49:02 +00:00
|
|
|
}
|
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
const std::shared_ptr<Option>& TrackerWatcherCommand::getOption() const
|
2009-05-08 16:41:21 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return requestGroup_->getOption();
|
2009-05-08 16:41:21 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|