2007-04-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Connect to a peer actively when download speed is lower than 
specified
	speed in torrent download:
	* src/ActivePeerConnectionCommand.h: New class.
pull/1/head
Tatsuhiro Tsujikawa 2007-04-03 10:52:31 +00:00
parent 5377be3680
commit f030408d8e
6 changed files with 165 additions and 3 deletions

View File

@ -1,3 +1,9 @@
2007-04-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Connect to a peer actively when download speed is lower than specified
speed in torrent download:
* src/ActivePeerConnectionCommand.h: New class.
2007-03-29 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2007-03-29 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/HttpRequest.cc (createRequest): url-encode user-agent * src/HttpRequest.cc (createRequest): url-encode user-agent

View File

@ -0,0 +1,68 @@
/* <!-- 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "ActivePeerConnectionCommand.h"
#include "PeerInitiateConnectionCommand.h"
bool ActivePeerConnectionCommand::execute() {
if(btRuntime->isHalt()) {
return true;
}
if(checkPoint.elapsed(interval)) {
checkPoint.reset();
TransferStat tstat = peerStorage->calculateStat();
if(tstat.getDownloadSpeed() < _lowestSpeedLimit) {
for(int i = 0; i < _numNewConnection && peerStorage->isPeerAvailable(); ++i) {
PeerHandle peer = peerStorage->getUnusedPeer();
connectToPeer(peer);
}
}
}
e->commands.push_back(this);
return false;
}
void ActivePeerConnectionCommand::connectToPeer(const PeerHandle& peer)
{
if(peer.isNull()) {
return;
}
peer->cuid = btRuntime->getNewCuid();
PeerInitiateConnectionCommand* command =
new PeerInitiateConnectionCommand(peer->cuid, peer, e, btContext);
e->commands.push_back(command);
logger->info("CUID#%d - Active Connect to the peer %s",
cuid, peer->ipaddr.c_str());
}

View File

@ -0,0 +1,78 @@
/* <!-- 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#ifndef _D_ACTIVE_PEER_CONNECTION_COMMAND_H_
#define _D_ACTIVE_PEER_CONNECTION_COMMAND_H_
#include "BtContextAwareCommand.h"
#include "TorrentDownloadEngine.h"
#include "TimeA2.h"
class ActivePeerConnectionCommand : public BtContextAwareCommand {
private:
int32_t interval; // UNIT: sec
TorrentDownloadEngine* e;
Time checkPoint;
int32_t _lowestSpeedLimit; // UNIT: byte/sec
int32_t _numNewConnection; // the number of the connection to establish.
public:
ActivePeerConnectionCommand(int cuid,
TorrentDownloadEngine* e,
const BtContextHandle& btContext,
int32_t interval)
:BtContextAwareCommand(cuid, btContext),
interval(interval),
e(e),
_lowestSpeedLimit(20*1024),
_numNewConnection(5)
{}
virtual ~ActivePeerConnectionCommand() {}
virtual bool execute();
void connectToPeer(const PeerHandle& peer);
void setLowestSpeedLimit(int32_t speed)
{
_lowestSpeedLimit = speed;
}
void setNumNewConnection(int32_t numNewConnection)
{
_numNewConnection = numNewConnection;
}
};
#endif // _D_ACTIVE_PEER_CONNECTION_COMMAND_H_

View File

@ -48,6 +48,7 @@
# include "SeedCheckCommand.h" # include "SeedCheckCommand.h"
# include "PeerChokeCommand.h" # include "PeerChokeCommand.h"
# include "HaveEraseCommand.h" # include "HaveEraseCommand.h"
# include "ActivePeerConnectionCommand.h"
# include "UnionSeedCriteria.h" # include "UnionSeedCriteria.h"
# include "TimeSeedCriteria.h" # include "TimeSeedCriteria.h"
# include "ShareRatioSeedCriteria.h" # include "ShareRatioSeedCriteria.h"
@ -173,6 +174,10 @@ DownloadEngineFactory::newTorrentConsoleEngine(const BtContextHandle& btContext,
te, te,
btContext, btContext,
10)); 10));
te->commands.push_back(new ActivePeerConnectionCommand(btRuntime->getNewCuid(),
te,
btContext,
30));
SharedHandle<UnionSeedCriteria> unionCri = new UnionSeedCriteria(); SharedHandle<UnionSeedCriteria> unionCri = new UnionSeedCriteria();
if(op->defined(PREF_SEED_TIME)) { if(op->defined(PREF_SEED_TIME)) {

View File

@ -186,7 +186,8 @@ SRCS += MetaEntry.h\
BtChokingEvent.h\ BtChokingEvent.h\
BtInteractive.h\ BtInteractive.h\
DefaultBtInteractive.cc DefaultBtInteractive.h\ DefaultBtInteractive.cc DefaultBtInteractive.h\
PeerObject.h PeerObject.h\
ActivePeerConnectionCommand.cc ActivePeerConnectionCommand.h
endif # ENABLE_BITTORRENT endif # ENABLE_BITTORRENT
if ENABLE_METALINK if ENABLE_METALINK

View File

@ -140,7 +140,8 @@ bin_PROGRAMS = aria2c$(EXEEXT)
@ENABLE_BITTORRENT_TRUE@ BtChokingEvent.h\ @ENABLE_BITTORRENT_TRUE@ BtChokingEvent.h\
@ENABLE_BITTORRENT_TRUE@ BtInteractive.h\ @ENABLE_BITTORRENT_TRUE@ BtInteractive.h\
@ENABLE_BITTORRENT_TRUE@ DefaultBtInteractive.cc DefaultBtInteractive.h\ @ENABLE_BITTORRENT_TRUE@ DefaultBtInteractive.cc DefaultBtInteractive.h\
@ENABLE_BITTORRENT_TRUE@ PeerObject.h @ENABLE_BITTORRENT_TRUE@ PeerObject.h\
@ENABLE_BITTORRENT_TRUE@ ActivePeerConnectionCommand.cc ActivePeerConnectionCommand.h
@ENABLE_METALINK_TRUE@am__append_2 = Metalinker.cc Metalinker.h\ @ENABLE_METALINK_TRUE@am__append_2 = Metalinker.cc Metalinker.h\
@ENABLE_METALINK_TRUE@ MetalinkEntry.cc MetalinkEntry.h\ @ENABLE_METALINK_TRUE@ MetalinkEntry.cc MetalinkEntry.h\
@ -288,6 +289,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
BtCancelSendingPieceEvent.h BtAbortOutstandingRequestEvent.h \ BtCancelSendingPieceEvent.h BtAbortOutstandingRequestEvent.h \
BtChokedEvent.h BtChokingEvent.h BtInteractive.h \ BtChokedEvent.h BtChokingEvent.h BtInteractive.h \
DefaultBtInteractive.cc DefaultBtInteractive.h PeerObject.h \ DefaultBtInteractive.cc DefaultBtInteractive.h PeerObject.h \
ActivePeerConnectionCommand.cc ActivePeerConnectionCommand.h \
Metalinker.cc Metalinker.h MetalinkEntry.cc MetalinkEntry.h \ Metalinker.cc Metalinker.h MetalinkEntry.cc MetalinkEntry.h \
MetalinkResource.cc MetalinkResource.h MetalinkProcessor.h \ MetalinkResource.cc MetalinkResource.h MetalinkProcessor.h \
Xml2MetalinkProcessor.cc Xml2MetalinkProcessor.h \ Xml2MetalinkProcessor.cc Xml2MetalinkProcessor.h \
@ -355,7 +357,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
@ENABLE_BITTORRENT_TRUE@ DefaultBtMessageDispatcher.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DefaultBtMessageDispatcher.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ DefaultBtMessageReceiver.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DefaultBtMessageReceiver.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ DefaultBtRequestFactory.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DefaultBtRequestFactory.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ DefaultBtInteractive.$(OBJEXT) @ENABLE_BITTORRENT_TRUE@ DefaultBtInteractive.$(OBJEXT) \
@ENABLE_BITTORRENT_TRUE@ ActivePeerConnectionCommand.$(OBJEXT)
@ENABLE_METALINK_TRUE@am__objects_2 = Metalinker.$(OBJEXT) \ @ENABLE_METALINK_TRUE@am__objects_2 = Metalinker.$(OBJEXT) \
@ENABLE_METALINK_TRUE@ MetalinkEntry.$(OBJEXT) \ @ENABLE_METALINK_TRUE@ MetalinkEntry.$(OBJEXT) \
@ENABLE_METALINK_TRUE@ MetalinkResource.$(OBJEXT) \ @ENABLE_METALINK_TRUE@ MetalinkResource.$(OBJEXT) \
@ -704,6 +707,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractProxyRequestCommand.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractProxyRequestCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractProxyResponseCommand.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractProxyResponseCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractSingleDiskAdaptor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AbstractSingleDiskAdaptor.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ActivePeerConnectionCommand.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AnnounceList.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AnnounceList.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfig.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfig.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64.Po@am__quote@