mirror of https://github.com/aria2/aria2
* src/PeerChokeCommand.cc
(optUnchokingPeer): Updated according to the changes in Peer. (ResetDelta): Removed. (UploadFaster): Updated according to the changes in Peer. (DownloadFaster): Updated according to the changes in Peer. (execute): I clarify the meaning of "upload" and "download" here. "upload" means the transfer from localhost to remote host. "download" means the transfer from remote host to localhost. Based on this rule, I swapped orderByUploadRate and orderByDownloadRate. * src/PeerInteractionCommand.cc (PeerInteraction): Removed peerInteraction->setUploadLImit(). (executeInternal): Removed the argument of peerInteraction->sendMessages(). (receiveMessages): Rewritten download speed limit. (sendKeepAlive): Removed peerInteraction->sendMessages(). * src/HttpResponseCommand.cc (handleDefaultEncoding): If file size is unknown in torrent request, do not call segmentMan->initBitfield() here. Disabled persistent connection feature in torrent request. * src/UrlRequestInfo.h (UrlRequestInfo): Removed const qualifier from option. * src/TorrentMan.h (TransferStat): New class. (deltaDownloadLength): Removed. (deltaUploadLength): Removed. (addDeltaDownloadLength): Removed. (getDeltaDownloadLength): Removed. (resetDeltaDownloadLength): Removed. (addDeltaUploadLength): Removed. (getDeltaUploadLength): Removed. (resetDeltaUploadLength): Removed. (addActivePeer): Added peer->activate(). (deleteActivePeer): Added peer->deactivate(). (calculateStat): New function. * src/TorrentMan.cc (TorrentMan): Removed deltaDownloadLength and deltaUploadLength. (calculateStat): New function. * src/PeerInteraction.h (uploadLimit): Removed. (option): New variable. (setUploadLimit): Removed. (getUploadSpeed): Removed. (sendMessages): Removed the argument "currentUploadSpeed". * src/PeerInteraction.cc (prefs.h): Included. (PeerInteraction): Removed uploadLimit. Added option. (sendMessages): Rewritten upload speed limit. (sendHandshake): Removed the argument from sendMessages(). (sendBitfield): Removed the argument from sendMessages(). * src/PeerAbstractCommand.cc (execute): Commented out the portion of upload limit. (onAbort): Removed peer->resetStatus(). * src/TorrentRequestInfo.cc (timeoutSpecified): Declared extern. (execute): Set timeout to 180 if timeout is not specified by. command-line. * src/PieceMessage.cc (receivedAction): Added peer->updateDownloadLength(). Removed peer->addPeerUpload(). Removed torrentMan->addDeltaDownloadLength(). (send): Added peer->updateUploadLength(). Removed peer->addPeerDownload(). Removed torrentMan->addDeltaUploadLength(). * src/main.cc (timeoutSpecified): New variable. (main): Set timeoutSpecified to false. If the command-line option "--upload-limit" is specified, then timeoutSpecified is set to true. This option will remain in the next release, but be deprecated in the future release. * src/TorrentRequestInfo.h (TorrentRequestInfo): Removed const qualifier from op. * src/PeerStat.h (uploadSpeed): New variable. (PeerStat): Added default value to cuid. (calculateUploadSpeed): New function. (updateUploadLength): New function. (getMaxUploadSpeed): New function. (getAvgUploadSpeed): New function. (reset): Added uploadSpeed. Set status to IDLE. * src/TorrentDownloadEngine.h (cp): Declared as Time. (sessionDownloadLengthArray): Removed. (sessionUploadLengthArray): Removed. (currentCp): Removed. (lastCalcStat): New variable (lastElapsed): Removed. (sessionDownloadLength): Removed. (calculateStat): New function. * src/TorrentDownloadEngine.cc (initStatistics): Removed lastElapsed, cp[], sessionDownloadLengthArray[], sessionUploadLengthArray[], currentCp, sessionDownloadLength. Added cp.reset() and lastCalcStat.reset(). (calculateSpeed): Changed the name of the argument. (calculateStatistics): Rewritten. (calculateStat): New function. * src/Peer.h (PeerStat.h): Included. (peerUpload): Removed. (peerDownload): Removed. (peerStat): New variable. (sessionUploadLength): New variable. (sessionDownloadLength): New variable. (deltaUpload): Removed. (deltaDownload): Removed. (resetStatus): Made private. (Peer): Added sessionUploadLength, sessionDownloadLength. Removed peerUpload, peerDownload. (updateUploadLength): New function. (addDeltaUpload): Removed. (updateDownloadLength): New function. (resetDeltaUpload): Removed. (getDeltaUpload): Removed. (addDeltaDownload): Removed. (calculateUploadSpeed): New function. (resetDeltaDownload): Removed. (getDeltaDownload): Removed. (calculateDownloadSpeed): New function. (getSessionUploadLength): New function. (getSessionDownloadLength): New function. (activate): New function. (deactivate): New function. (addPeerUpload): Removed. (setPeerUpload): Removed. (getPeerUpload): Removed. (addPeerDownload): Removed. (setPeerDownload): Removed. (getPeerDownload): Removed. * src/Peer.cc (resetStatus): Removed resetDeltaUpload() and resetDeltaDownload(). * src/MetalinkRequestInfo.h (MetalinkRequestInfo): Removed const qualifier from op. * src/RequestInfo.h (op): Removed const qualifier. (RequestInfo): Removed const qualifier from op.pull/1/head
parent
65e0ffe6ca
commit
8b8325cafc
153
ChangeLog
153
ChangeLog
|
@ -63,6 +63,159 @@
|
||||||
(STARTUP_IDLE_TIME): Removed.
|
(STARTUP_IDLE_TIME): Removed.
|
||||||
(executeInternal): Use PREF_STARTUP_IDLE_TIME.
|
(executeInternal): Use PREF_STARTUP_IDLE_TIME.
|
||||||
|
|
||||||
|
* src/PeerChokeCommand.cc
|
||||||
|
(optUnchokingPeer): Updated according to the changes in Peer.
|
||||||
|
(ResetDelta): Removed.
|
||||||
|
(UploadFaster): Updated according to the changes in Peer.
|
||||||
|
(DownloadFaster): Updated according to the changes in Peer.
|
||||||
|
(execute): I clarify the meaning of "upload" and "download" here.
|
||||||
|
"upload" means the transfer from localhost to remote host.
|
||||||
|
"download" means the transfer from remote host to localhost.
|
||||||
|
Based on this rule, I swapped orderByUploadRate and
|
||||||
|
orderByDownloadRate.
|
||||||
|
|
||||||
|
* src/PeerInteractionCommand.cc
|
||||||
|
(PeerInteraction): Removed peerInteraction->setUploadLImit().
|
||||||
|
(executeInternal): Removed the argument of
|
||||||
|
peerInteraction->sendMessages().
|
||||||
|
(receiveMessages): Rewritten download speed limit.
|
||||||
|
(sendKeepAlive): Removed peerInteraction->sendMessages().
|
||||||
|
|
||||||
|
* src/HttpResponseCommand.cc
|
||||||
|
(handleDefaultEncoding): If file size is unknown in torrent request,
|
||||||
|
do not call segmentMan->initBitfield() here.
|
||||||
|
Disabled persistent connection feature in torrent request.
|
||||||
|
|
||||||
|
* src/UrlRequestInfo.h
|
||||||
|
(UrlRequestInfo): Removed const qualifier from option.
|
||||||
|
|
||||||
|
* src/TorrentMan.h
|
||||||
|
(TransferStat): New class.
|
||||||
|
(deltaDownloadLength): Removed.
|
||||||
|
(deltaUploadLength): Removed.
|
||||||
|
(addDeltaDownloadLength): Removed.
|
||||||
|
(getDeltaDownloadLength): Removed.
|
||||||
|
(resetDeltaDownloadLength): Removed.
|
||||||
|
(addDeltaUploadLength): Removed.
|
||||||
|
(getDeltaUploadLength): Removed.
|
||||||
|
(resetDeltaUploadLength): Removed.
|
||||||
|
(addActivePeer): Added peer->activate().
|
||||||
|
(deleteActivePeer): Added peer->deactivate().
|
||||||
|
(calculateStat): New function.
|
||||||
|
* src/TorrentMan.cc
|
||||||
|
(TorrentMan): Removed deltaDownloadLength and deltaUploadLength.
|
||||||
|
(calculateStat): New function.
|
||||||
|
|
||||||
|
* src/PeerInteraction.h
|
||||||
|
(uploadLimit): Removed.
|
||||||
|
(option): New variable.
|
||||||
|
(setUploadLimit): Removed.
|
||||||
|
(getUploadSpeed): Removed.
|
||||||
|
(sendMessages): Removed the argument "currentUploadSpeed".
|
||||||
|
* src/PeerInteraction.cc
|
||||||
|
(prefs.h): Included.
|
||||||
|
(PeerInteraction): Removed uploadLimit. Added option.
|
||||||
|
(sendMessages): Rewritten upload speed limit.
|
||||||
|
(sendHandshake): Removed the argument from sendMessages().
|
||||||
|
(sendBitfield): Removed the argument from sendMessages().
|
||||||
|
|
||||||
|
* src/PeerAbstractCommand.cc
|
||||||
|
(execute): Commented out the portion of upload limit.
|
||||||
|
(onAbort): Removed peer->resetStatus().
|
||||||
|
|
||||||
|
* src/TorrentRequestInfo.cc
|
||||||
|
(timeoutSpecified): Declared extern.
|
||||||
|
(execute): Set timeout to 180 if timeout is not specified by.
|
||||||
|
command-line.
|
||||||
|
|
||||||
|
* src/PieceMessage.cc
|
||||||
|
(receivedAction): Added peer->updateDownloadLength().
|
||||||
|
Removed peer->addPeerUpload().
|
||||||
|
Removed torrentMan->addDeltaDownloadLength().
|
||||||
|
(send): Added peer->updateUploadLength().
|
||||||
|
Removed peer->addPeerDownload().
|
||||||
|
Removed torrentMan->addDeltaUploadLength().
|
||||||
|
|
||||||
|
* src/main.cc
|
||||||
|
(timeoutSpecified): New variable.
|
||||||
|
(main): Set timeoutSpecified to false.
|
||||||
|
If the command-line option "--upload-limit" is specified, then
|
||||||
|
timeoutSpecified is set to true. This option will remain in the next
|
||||||
|
release, but be deprecated in the future release.
|
||||||
|
|
||||||
|
* src/TorrentRequestInfo.h
|
||||||
|
(TorrentRequestInfo): Removed const qualifier from op.
|
||||||
|
|
||||||
|
* src/PeerStat.h
|
||||||
|
(uploadSpeed): New variable.
|
||||||
|
(PeerStat): Added default value to cuid.
|
||||||
|
(calculateUploadSpeed): New function.
|
||||||
|
(updateUploadLength): New function.
|
||||||
|
(getMaxUploadSpeed): New function.
|
||||||
|
(getAvgUploadSpeed): New function.
|
||||||
|
(reset): Added uploadSpeed. Set status to IDLE.
|
||||||
|
|
||||||
|
* src/TorrentDownloadEngine.h
|
||||||
|
(cp): Declared as Time.
|
||||||
|
(sessionDownloadLengthArray): Removed.
|
||||||
|
(sessionUploadLengthArray): Removed.
|
||||||
|
(currentCp): Removed.
|
||||||
|
(lastCalcStat): New variable
|
||||||
|
(lastElapsed): Removed.
|
||||||
|
(sessionDownloadLength): Removed.
|
||||||
|
(calculateStat): New function.
|
||||||
|
* src/TorrentDownloadEngine.cc
|
||||||
|
(initStatistics): Removed lastElapsed, cp[],
|
||||||
|
sessionDownloadLengthArray[], sessionUploadLengthArray[],
|
||||||
|
currentCp, sessionDownloadLength.
|
||||||
|
Added cp.reset() and lastCalcStat.reset().
|
||||||
|
(calculateSpeed): Changed the name of the argument.
|
||||||
|
(calculateStatistics): Rewritten.
|
||||||
|
(calculateStat): New function.
|
||||||
|
|
||||||
|
* src/Peer.h
|
||||||
|
(PeerStat.h): Included.
|
||||||
|
(peerUpload): Removed.
|
||||||
|
(peerDownload): Removed.
|
||||||
|
(peerStat): New variable.
|
||||||
|
(sessionUploadLength): New variable.
|
||||||
|
(sessionDownloadLength): New variable.
|
||||||
|
(deltaUpload): Removed.
|
||||||
|
(deltaDownload): Removed.
|
||||||
|
(resetStatus): Made private.
|
||||||
|
(Peer): Added sessionUploadLength, sessionDownloadLength.
|
||||||
|
Removed peerUpload, peerDownload.
|
||||||
|
(updateUploadLength): New function.
|
||||||
|
(addDeltaUpload): Removed.
|
||||||
|
(updateDownloadLength): New function.
|
||||||
|
(resetDeltaUpload): Removed.
|
||||||
|
(getDeltaUpload): Removed.
|
||||||
|
(addDeltaDownload): Removed.
|
||||||
|
(calculateUploadSpeed): New function.
|
||||||
|
(resetDeltaDownload): Removed.
|
||||||
|
(getDeltaDownload): Removed.
|
||||||
|
(calculateDownloadSpeed): New function.
|
||||||
|
(getSessionUploadLength): New function.
|
||||||
|
(getSessionDownloadLength): New function.
|
||||||
|
(activate): New function.
|
||||||
|
(deactivate): New function.
|
||||||
|
(addPeerUpload): Removed.
|
||||||
|
(setPeerUpload): Removed.
|
||||||
|
(getPeerUpload): Removed.
|
||||||
|
(addPeerDownload): Removed.
|
||||||
|
(setPeerDownload): Removed.
|
||||||
|
(getPeerDownload): Removed.
|
||||||
|
|
||||||
|
* src/Peer.cc
|
||||||
|
(resetStatus): Removed resetDeltaUpload() and resetDeltaDownload().
|
||||||
|
|
||||||
|
* src/MetalinkRequestInfo.h
|
||||||
|
(MetalinkRequestInfo): Removed const qualifier from op.
|
||||||
|
|
||||||
|
* src/RequestInfo.h
|
||||||
|
(op): Removed const qualifier.
|
||||||
|
(RequestInfo): Removed const qualifier from op.
|
||||||
|
|
||||||
2006-09-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2006-09-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
To rewrite segment download mechanism for HTTP/FTP download.
|
To rewrite segment download mechanism for HTTP/FTP download.
|
||||||
|
|
3
TODO
3
TODO
|
@ -21,5 +21,4 @@
|
||||||
0.8.0
|
0.8.0
|
||||||
|
|
||||||
* Add a statement for the permission to link with OpenSSL.
|
* Add a statement for the permission to link with OpenSSL.
|
||||||
* Add upload speed limit command-line option(not tested for torrent yet).
|
* Add command-line options: max-speed-limit, max-upload-limit.
|
||||||
|
|
|
@ -118,8 +118,12 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpHeader& headers) {
|
||||||
if(req->isTorrent) {
|
if(req->isTorrent) {
|
||||||
long long int size = headers.getFirstAsLLInt("Content-Length");
|
long long int size = headers.getFirstAsLLInt("Content-Length");
|
||||||
e->segmentMan->totalSize = size;
|
e->segmentMan->totalSize = size;
|
||||||
|
if(size > 0) {
|
||||||
e->segmentMan->initBitfield(e->option->getAsInt(PREF_SEGMENT_SIZE),
|
e->segmentMan->initBitfield(e->option->getAsInt(PREF_SEGMENT_SIZE),
|
||||||
e->segmentMan->totalSize);
|
e->segmentMan->totalSize);
|
||||||
|
}
|
||||||
|
// disable keep-alive
|
||||||
|
req->setKeepAlive(false);
|
||||||
e->segmentMan->isSplittable = false;
|
e->segmentMan->isSplittable = false;
|
||||||
e->segmentMan->downloadStarted = true;
|
e->segmentMan->downloadStarted = true;
|
||||||
e->segmentMan->diskWriter->initAndOpenFile("/tmp/aria2"+Util::itos(getpid()));
|
e->segmentMan->diskWriter->initAndOpenFile("/tmp/aria2"+Util::itos(getpid()));
|
||||||
|
|
|
@ -28,7 +28,7 @@ class MetalinkRequestInfo : public RequestInfo {
|
||||||
private:
|
private:
|
||||||
string metalinkFile;
|
string metalinkFile;
|
||||||
public:
|
public:
|
||||||
MetalinkRequestInfo(const string& metalinkFile, const Option* op):
|
MetalinkRequestInfo(const string& metalinkFile, Option* op):
|
||||||
RequestInfo(op),
|
RequestInfo(op),
|
||||||
metalinkFile(metalinkFile) {}
|
metalinkFile(metalinkFile) {}
|
||||||
virtual ~MetalinkRequestInfo() {}
|
virtual ~MetalinkRequestInfo() {}
|
||||||
|
|
|
@ -55,14 +55,13 @@ void Peer::resetStatus() {
|
||||||
amInterested = false;
|
amInterested = false;
|
||||||
peerChoking = true;
|
peerChoking = true;
|
||||||
peerInterested = false;
|
peerInterested = false;
|
||||||
resetDeltaUpload();
|
|
||||||
resetDeltaDownload();
|
|
||||||
chokingRequired = true;
|
chokingRequired = true;
|
||||||
optUnchoking = false;
|
optUnchoking = false;
|
||||||
snubbing = false;
|
snubbing = false;
|
||||||
fastExtensionEnabled = false;
|
fastExtensionEnabled = false;
|
||||||
latency = DEFAULT_LATENCY;
|
latency = DEFAULT_LATENCY;
|
||||||
fastSet.clear();
|
fastSet.clear();
|
||||||
|
peerStat.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Peer::isInFastSet(int index) const {
|
bool Peer::isInFastSet(int index) const {
|
||||||
|
|
82
src/Peer.h
82
src/Peer.h
|
@ -25,6 +25,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "BitfieldMan.h"
|
#include "BitfieldMan.h"
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
|
#include "PeerStat.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -56,23 +57,26 @@ private:
|
||||||
bool fastExtensionEnabled;
|
bool fastExtensionEnabled;
|
||||||
// allowed fast indexes that peer has sent by Allowed Fast message
|
// allowed fast indexes that peer has sent by Allowed Fast message
|
||||||
Integers fastSet;
|
Integers fastSet;
|
||||||
long long int peerUpload;
|
PeerStat peerStat;
|
||||||
long long int peerDownload;
|
long long int sessionUploadLength;
|
||||||
|
long long int sessionDownloadLength;
|
||||||
int pieceLength;
|
int pieceLength;
|
||||||
int deltaUpload;
|
|
||||||
int deltaDownload;
|
|
||||||
int latency;
|
int latency;
|
||||||
|
|
||||||
|
void resetStatus();
|
||||||
public:
|
public:
|
||||||
Peer(string ipaddr, int port, int pieceLength, long long int totalLength)
|
Peer(string ipaddr, int port, int pieceLength, long long int totalLength)
|
||||||
:entryId(0), ipaddr(ipaddr), port(port), error(0),
|
:entryId(0), ipaddr(ipaddr), port(port), error(0),
|
||||||
peerUpload(0), peerDownload(0), pieceLength(pieceLength)
|
sessionUploadLength(0), sessionDownloadLength(0),
|
||||||
|
pieceLength(pieceLength)
|
||||||
{
|
{
|
||||||
resetStatus();
|
resetStatus();
|
||||||
this->bitfield = new BitfieldMan(pieceLength, totalLength);
|
this->bitfield = new BitfieldMan(pieceLength, totalLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
Peer():entryId(0), ipaddr(""), port(0), bitfield(0),
|
Peer():entryId(0), ipaddr(""), port(0), bitfield(0),
|
||||||
peerUpload(0), peerDownload(0), pieceLength(0)
|
sessionUploadLength(0), sessionDownloadLength(0),
|
||||||
|
pieceLength(0)
|
||||||
{
|
{
|
||||||
resetStatus();
|
resetStatus();
|
||||||
}
|
}
|
||||||
|
@ -91,19 +95,51 @@ public:
|
||||||
return !(*this == p);
|
return !(*this == p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetStatus();
|
void updateUploadLength(int bytes) {
|
||||||
|
peerStat.updateUploadLength(bytes);
|
||||||
void addDeltaUpload(int length) {
|
sessionUploadLength += bytes;
|
||||||
this->deltaUpload += length;
|
|
||||||
}
|
}
|
||||||
void resetDeltaUpload() { this->deltaUpload = 0; }
|
|
||||||
int getDeltaUpload() const { return this->deltaUpload; }
|
|
||||||
|
|
||||||
void addDeltaDownload(int length) {
|
void updateDownloadLength(int bytes) {
|
||||||
this->deltaDownload += length;
|
peerStat.updateDownloadLength(bytes);
|
||||||
|
sessionDownloadLength += bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the transfer rate from localhost to remote host.
|
||||||
|
*/
|
||||||
|
int calculateUploadSpeed() {
|
||||||
|
return peerStat.calculateUploadSpeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the transfer rate from remote host to localhost.
|
||||||
|
*/
|
||||||
|
int calculateDownloadSpeed() {
|
||||||
|
return peerStat.calculateDownloadSpeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of bytes uploaded to the remote host.
|
||||||
|
*/
|
||||||
|
long long int getSessionUploadLength() const {
|
||||||
|
return sessionUploadLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of bytes downloaded from the remote host.
|
||||||
|
*/
|
||||||
|
long long int getSessionDownloadLength() const {
|
||||||
|
return sessionDownloadLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
void activate() {
|
||||||
|
peerStat.downloadStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void deactivate() {
|
||||||
|
peerStat.downloadStop();
|
||||||
}
|
}
|
||||||
void resetDeltaDownload() { this->deltaDownload = 0; }
|
|
||||||
int getDeltaDownload() const { return this->deltaDownload; }
|
|
||||||
|
|
||||||
void setPeerId(const char* peerId) {
|
void setPeerId(const char* peerId) {
|
||||||
memcpy(this->peerId, peerId, PEER_ID_LENGTH);
|
memcpy(this->peerId, peerId, PEER_ID_LENGTH);
|
||||||
|
@ -123,20 +159,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void updateBitfield(int index, int operation);
|
void updateBitfield(int index, int operation);
|
||||||
|
|
||||||
void addPeerUpload(int size) {
|
|
||||||
peerUpload += size;
|
|
||||||
addDeltaUpload(size);
|
|
||||||
}
|
|
||||||
void setPeerUpload(long long int size) { peerUpload = size; }
|
|
||||||
long long int getPeerUpload() const { return peerUpload; }
|
|
||||||
|
|
||||||
void addPeerDownload(int size) {
|
|
||||||
peerDownload += size;
|
|
||||||
addDeltaDownload(size);
|
|
||||||
}
|
|
||||||
void setPeerDownload(long long int size) { peerDownload = size; }
|
|
||||||
long long int getPeerDownload() const { return peerDownload; }
|
|
||||||
|
|
||||||
void setFastExtensionEnabled(bool enabled) {
|
void setFastExtensionEnabled(bool enabled) {
|
||||||
fastExtensionEnabled = enabled;
|
fastExtensionEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,10 @@ bool PeerAbstractCommand::execute() {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if(noCheck ||
|
if(noCheck ||
|
||||||
|
/*
|
||||||
uploadLimitCheck && (uploadLimit == 0 ||
|
uploadLimitCheck && (uploadLimit == 0 ||
|
||||||
e->getUploadSpeed() <= uploadLimit*1024) ||
|
e->getUploadSpeed() <= uploadLimit*1024) ||
|
||||||
|
*/
|
||||||
checkSocketIsReadable && readCheckTarget->isReadable(0) ||
|
checkSocketIsReadable && readCheckTarget->isReadable(0) ||
|
||||||
checkSocketIsWritable && writeCheckTarget->isWritable(0)) {
|
checkSocketIsWritable && writeCheckTarget->isWritable(0)) {
|
||||||
checkPoint.reset();
|
checkPoint.reset();
|
||||||
|
@ -61,8 +63,10 @@ bool PeerAbstractCommand::execute() {
|
||||||
return executeInternal();
|
return executeInternal();
|
||||||
} catch(Exception* err) {
|
} catch(Exception* err) {
|
||||||
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid);
|
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid);
|
||||||
|
logger->debug("CUID#%d - Peer %s:%d banned.",
|
||||||
|
cuid, peer->ipaddr.c_str(), peer->port);
|
||||||
onAbort(err);
|
onAbort(err);
|
||||||
delete(err);
|
delete err;
|
||||||
return prepareForNextPeer(0);
|
return prepareForNextPeer(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,8 +86,6 @@ void PeerAbstractCommand::onAbort(Exception* ex) {
|
||||||
} else {
|
} else {
|
||||||
peer->error += MAX_PEER_ERROR;
|
peer->error += MAX_PEER_ERROR;
|
||||||
}
|
}
|
||||||
peer->resetStatus();
|
|
||||||
logger->debug("CUID#%d - Peer %s:%d banned.", cuid, peer->ipaddr.c_str(), peer->port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerAbstractCommand::disableReadCheckSocket() {
|
void PeerAbstractCommand::disableReadCheckSocket() {
|
||||||
|
|
|
@ -45,27 +45,18 @@ void PeerChokeCommand::optUnchokingPeer(Peers& peers) const {
|
||||||
if(optUnchokCount > 0 && !peer->snubbing) {
|
if(optUnchokCount > 0 && !peer->snubbing) {
|
||||||
optUnchokCount--;
|
optUnchokCount--;
|
||||||
peer->optUnchoking = true;
|
peer->optUnchoking = true;
|
||||||
logger->debug("opt, unchoking %s, delta=%d",
|
logger->debug("opt, unchoking %s, download speed=%d",
|
||||||
peer->ipaddr.c_str(), peer->getDeltaUpload());
|
peer->ipaddr.c_str(), peer->calculateDownloadSpeed());
|
||||||
} else {
|
} else {
|
||||||
peer->optUnchoking = false;
|
peer->optUnchoking = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ResetDelta {
|
|
||||||
public:
|
|
||||||
ResetDelta() {}
|
|
||||||
void operator()(PeerHandle& peer) {
|
|
||||||
peer->resetDeltaUpload();
|
|
||||||
peer->resetDeltaDownload();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class UploadFaster {
|
class UploadFaster {
|
||||||
public:
|
public:
|
||||||
bool operator() (const PeerHandle& left, const PeerHandle& right) const {
|
bool operator() (const PeerHandle& left, const PeerHandle& right) const {
|
||||||
return left->getDeltaUpload() > right->getDeltaUpload();
|
return left->calculateUploadSpeed() > right->calculateUploadSpeed();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -76,7 +67,7 @@ void PeerChokeCommand::orderByUploadRate(Peers& peers) const {
|
||||||
class DownloadFaster {
|
class DownloadFaster {
|
||||||
public:
|
public:
|
||||||
bool operator() (const PeerHandle& left, const PeerHandle& right) const {
|
bool operator() (const PeerHandle& left, const PeerHandle& right) const {
|
||||||
return left->getDeltaDownload() > right->getDeltaDownload();
|
return left->calculateDownloadSpeed() > right->calculateDownloadSpeed();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -93,9 +84,9 @@ bool PeerChokeCommand::execute() {
|
||||||
Peers peers = e->torrentMan->getActivePeers();
|
Peers peers = e->torrentMan->getActivePeers();
|
||||||
for_each(peers.begin(), peers.end(), ChokePeer());
|
for_each(peers.begin(), peers.end(), ChokePeer());
|
||||||
if(e->torrentMan->downloadComplete()) {
|
if(e->torrentMan->downloadComplete()) {
|
||||||
orderByDownloadRate(peers);
|
|
||||||
} else {
|
|
||||||
orderByUploadRate(peers);
|
orderByUploadRate(peers);
|
||||||
|
} else {
|
||||||
|
orderByDownloadRate(peers);
|
||||||
}
|
}
|
||||||
int unchokingCount = 4;//peers.size() >= 4 ? 4 : peers.size();
|
int unchokingCount = 4;//peers.size() >= 4 ? 4 : peers.size();
|
||||||
for(Peers::iterator itr = peers.begin(); itr != peers.end() && unchokingCount > 0; ) {
|
for(Peers::iterator itr = peers.begin(); itr != peers.end() && unchokingCount > 0; ) {
|
||||||
|
@ -105,10 +96,15 @@ bool PeerChokeCommand::execute() {
|
||||||
peer->chokingRequired = false;
|
peer->chokingRequired = false;
|
||||||
peer->optUnchoking = false;
|
peer->optUnchoking = false;
|
||||||
itr = peers.erase(itr);
|
itr = peers.erase(itr);
|
||||||
logger->debug("cat01, unchoking %s, delta=%d",
|
if(e->torrentMan->downloadComplete()) {
|
||||||
|
logger->debug("cat01, unchoking %s, upload speed=%d",
|
||||||
peer->ipaddr.c_str(),
|
peer->ipaddr.c_str(),
|
||||||
e->torrentMan->downloadComplete() ?
|
peer->calculateUploadSpeed());
|
||||||
peer->getDeltaDownload() : peer->getDeltaUpload());
|
} else {
|
||||||
|
logger->debug("cat01, unchoking %s, download speed=%d",
|
||||||
|
peer->ipaddr.c_str(),
|
||||||
|
peer->calculateDownloadSpeed());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
itr++;
|
itr++;
|
||||||
}
|
}
|
||||||
|
@ -119,10 +115,15 @@ bool PeerChokeCommand::execute() {
|
||||||
peer->chokingRequired = false;
|
peer->chokingRequired = false;
|
||||||
peer->optUnchoking = false;
|
peer->optUnchoking = false;
|
||||||
itr = peers.erase(itr);
|
itr = peers.erase(itr);
|
||||||
logger->debug("cat02, unchoking %s, delta=%d",
|
if(e->torrentMan->downloadComplete()) {
|
||||||
|
logger->debug("cat01, unchoking %s, upload speed=%d",
|
||||||
peer->ipaddr.c_str(),
|
peer->ipaddr.c_str(),
|
||||||
e->torrentMan->downloadComplete() ?
|
peer->calculateUploadSpeed());
|
||||||
peer->getDeltaDownload() : peer->getDeltaUpload());
|
} else {
|
||||||
|
logger->debug("cat01, unchoking %s, download speed=%d",
|
||||||
|
peer->ipaddr.c_str(),
|
||||||
|
peer->calculateDownloadSpeed());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
itr++;
|
itr++;
|
||||||
|
@ -133,9 +134,6 @@ bool PeerChokeCommand::execute() {
|
||||||
rotate = 0;
|
rotate = 0;
|
||||||
}
|
}
|
||||||
rotate++;
|
rotate++;
|
||||||
for_each(e->torrentMan->getActivePeers().begin(),
|
|
||||||
e->torrentMan->getActivePeers().end(),
|
|
||||||
ResetDelta());
|
|
||||||
}
|
}
|
||||||
e->commands.push_back(this);
|
e->commands.push_back(this);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "KeepAliveMessage.h"
|
#include "KeepAliveMessage.h"
|
||||||
#include "PeerMessageUtil.h"
|
#include "PeerMessageUtil.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "prefs.h"
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
PeerInteraction::PeerInteraction(int cuid,
|
PeerInteraction::PeerInteraction(int cuid,
|
||||||
|
@ -33,7 +34,7 @@ PeerInteraction::PeerInteraction(int cuid,
|
||||||
const Option* op,
|
const Option* op,
|
||||||
TorrentMan* torrentMan)
|
TorrentMan* torrentMan)
|
||||||
:cuid(cuid),
|
:cuid(cuid),
|
||||||
uploadLimit(0),
|
option(op),
|
||||||
torrentMan(torrentMan),
|
torrentMan(torrentMan),
|
||||||
peer(peer),
|
peer(peer),
|
||||||
quickReplied(false) {
|
quickReplied(false) {
|
||||||
|
@ -57,22 +58,26 @@ bool PeerInteraction::isSendingMessageInProgress() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerInteraction::sendMessages(int uploadSpeed) {
|
void PeerInteraction::sendMessages() {
|
||||||
MessageQueue tempQueue;
|
MessageQueue tempQueue;
|
||||||
|
int uploadLimit = option->getAsInt(PREF_UPLOAD_LIMIT);
|
||||||
while(messageQueue.size() > 0) {
|
while(messageQueue.size() > 0) {
|
||||||
PeerMessageHandle msg = messageQueue.front();
|
PeerMessageHandle msg = messageQueue.front();
|
||||||
messageQueue.pop_front();
|
messageQueue.pop_front();
|
||||||
if(uploadLimit != 0 && uploadLimit*1024 <= uploadSpeed &&
|
if(uploadLimit > 0) {
|
||||||
|
TransferStat stat = torrentMan->calculateStat();
|
||||||
|
if(uploadLimit < stat.uploadSpeed &&
|
||||||
msg->isUploading() && !msg->isInProgress()) {
|
msg->isUploading() && !msg->isInProgress()) {
|
||||||
tempQueue.push_back(msg);
|
tempQueue.push_back(msg);
|
||||||
} else {
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
msg->send();
|
msg->send();
|
||||||
if(msg->isInProgress()) {
|
if(msg->isInProgress()) {
|
||||||
messageQueue.push_front(msg);
|
messageQueue.push_front(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
copy(tempQueue.begin(), tempQueue.end(), back_inserter(messageQueue));
|
copy(tempQueue.begin(), tempQueue.end(), back_inserter(messageQueue));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,7 +370,7 @@ void PeerInteraction::sendHandshake() {
|
||||||
peerMessageFactory->createHandshakeMessage(torrentMan->getInfoHash(),
|
peerMessageFactory->createHandshakeMessage(torrentMan->getInfoHash(),
|
||||||
torrentMan->peerId.c_str());
|
torrentMan->peerId.c_str());
|
||||||
addMessage(handle);
|
addMessage(handle);
|
||||||
sendMessages(0);
|
sendMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerInteraction::sendBitfield() {
|
void PeerInteraction::sendBitfield() {
|
||||||
|
@ -382,7 +387,7 @@ void PeerInteraction::sendBitfield() {
|
||||||
addMessage(peerMessageFactory->createBitfieldMessage());
|
addMessage(peerMessageFactory->createBitfieldMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendMessages(0);
|
sendMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerInteraction::sendAllowedFast() {
|
void PeerInteraction::sendAllowedFast() {
|
||||||
|
|
|
@ -39,8 +39,7 @@ private:
|
||||||
int cuid;
|
int cuid;
|
||||||
RequestSlots requestSlots;
|
RequestSlots requestSlots;
|
||||||
MessageQueue messageQueue;
|
MessageQueue messageQueue;
|
||||||
// upload speed limit(byte/sec)
|
const Option* option;
|
||||||
int uploadLimit;
|
|
||||||
TorrentMan* torrentMan;
|
TorrentMan* torrentMan;
|
||||||
PeerConnection* peerConnection;
|
PeerConnection* peerConnection;
|
||||||
PeerHandle peer;
|
PeerHandle peer;
|
||||||
|
@ -77,9 +76,6 @@ public:
|
||||||
|
|
||||||
int countMessageInQueue() const;
|
int countMessageInQueue() const;
|
||||||
|
|
||||||
void setUploadLimit(int uploadLimit) { this->uploadLimit = uploadLimit; }
|
|
||||||
int getUploadLimit() const { return this->uploadLimit; }
|
|
||||||
|
|
||||||
TorrentMan* getTorrentMan() const { return torrentMan; }
|
TorrentMan* getTorrentMan() const { return torrentMan; }
|
||||||
PeerConnection* getPeerConnection() const { return peerConnection; }
|
PeerConnection* getPeerConnection() const { return peerConnection; }
|
||||||
// If this object has nullPiece, then return false, otherwise true
|
// If this object has nullPiece, then return false, otherwise true
|
||||||
|
@ -95,7 +91,7 @@ public:
|
||||||
void syncPiece();
|
void syncPiece();
|
||||||
void updatePiece();
|
void updatePiece();
|
||||||
void addRequests();
|
void addRequests();
|
||||||
void sendMessages(int currentUploadSpeed);
|
void sendMessages();
|
||||||
void sendHandshake();
|
void sendHandshake();
|
||||||
void sendBitfield();
|
void sendBitfield();
|
||||||
void sendAllowedFast();
|
void sendAllowedFast();
|
||||||
|
|
|
@ -46,7 +46,6 @@ PeerInteractionCommand::PeerInteractionCommand(int cuid,
|
||||||
}
|
}
|
||||||
peerInteraction = new PeerInteraction(cuid, peer, socket, e->option,
|
peerInteraction = new PeerInteraction(cuid, peer, socket, e->option,
|
||||||
e->torrentMan);
|
e->torrentMan);
|
||||||
peerInteraction->setUploadLimit(e->option->getAsInt(PREF_UPLOAD_LIMIT));
|
|
||||||
setUploadLimit(e->option->getAsInt(PREF_UPLOAD_LIMIT));
|
setUploadLimit(e->option->getAsInt(PREF_UPLOAD_LIMIT));
|
||||||
chokeUnchokeCount = 0;
|
chokeUnchokeCount = 0;
|
||||||
haveCount = 0;
|
haveCount = 0;
|
||||||
|
@ -78,7 +77,7 @@ bool PeerInteractionCommand::executeInternal() {
|
||||||
break;
|
break;
|
||||||
case INITIATOR_WAIT_HANDSHAKE: {
|
case INITIATOR_WAIT_HANDSHAKE: {
|
||||||
if(peerInteraction->countMessageInQueue() > 0) {
|
if(peerInteraction->countMessageInQueue() > 0) {
|
||||||
peerInteraction->sendMessages(e->getUploadSpeed());
|
peerInteraction->sendMessages();
|
||||||
if(peerInteraction->countMessageInQueue() > 0) {
|
if(peerInteraction->countMessageInQueue() > 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +128,7 @@ bool PeerInteractionCommand::executeInternal() {
|
||||||
|
|
||||||
peerInteraction->addRequests();
|
peerInteraction->addRequests();
|
||||||
|
|
||||||
peerInteraction->sendMessages(e->getUploadSpeed());
|
peerInteraction->sendMessages();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(peerInteraction->countMessageInQueue() > 0) {
|
if(peerInteraction->countMessageInQueue() > 0) {
|
||||||
|
@ -192,11 +191,14 @@ void PeerInteractionCommand::decideChoking() {
|
||||||
void PeerInteractionCommand::receiveMessages() {
|
void PeerInteractionCommand::receiveMessages() {
|
||||||
for(int i = 0; i < 50; i++) {
|
for(int i = 0; i < 50; i++) {
|
||||||
int maxSpeedLimit = e->option->getAsInt(PREF_MAX_SPEED_LIMIT);
|
int maxSpeedLimit = e->option->getAsInt(PREF_MAX_SPEED_LIMIT);
|
||||||
if(maxSpeedLimit > 0 && maxSpeedLimit < e->getDownloadSpeed()) {
|
if(maxSpeedLimit > 0) {
|
||||||
|
TransferStat stat = e->torrentMan->calculateStat();
|
||||||
|
if(maxSpeedLimit < stat.downloadSpeed) {
|
||||||
disableReadCheckSocket();
|
disableReadCheckSocket();
|
||||||
setNoCheck(true);
|
setNoCheck(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PeerMessageHandle message = peerInteraction->receiveMessage();
|
PeerMessageHandle message = peerInteraction->receiveMessage();
|
||||||
if(message.get() == NULL) {
|
if(message.get() == NULL) {
|
||||||
|
@ -256,7 +258,7 @@ void PeerInteractionCommand::sendKeepAlive() {
|
||||||
if(peerInteraction->countMessageInQueue() == 0) {
|
if(peerInteraction->countMessageInQueue() == 0) {
|
||||||
peerInteraction->addMessage(peerInteraction->getPeerMessageFactory()->
|
peerInteraction->addMessage(peerInteraction->getPeerMessageFactory()->
|
||||||
createKeepAliveMessage());
|
createKeepAliveMessage());
|
||||||
peerInteraction->sendMessages(e->getUploadSpeed());
|
peerInteraction->sendMessages();
|
||||||
}
|
}
|
||||||
keepAliveCheckPoint.reset();
|
keepAliveCheckPoint.reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,12 @@ public:
|
||||||
private:
|
private:
|
||||||
int cuid;
|
int cuid;
|
||||||
SpeedCalc downloadSpeed;
|
SpeedCalc downloadSpeed;
|
||||||
|
SpeedCalc uploadSpeed;
|
||||||
Time downloadStartTime;
|
Time downloadStartTime;
|
||||||
STATUS status;
|
STATUS status;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PeerStat(int cuid):cuid(cuid), status(IDLE) {}
|
PeerStat(int cuid = 0):cuid(cuid), status(IDLE) {}
|
||||||
|
|
||||||
~PeerStat() {}
|
~PeerStat() {}
|
||||||
|
|
||||||
|
@ -51,21 +52,39 @@ public:
|
||||||
return downloadSpeed.calculateSpeed();
|
return downloadSpeed.calculateSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int calculateUploadSpeed() {
|
||||||
|
return uploadSpeed.calculateSpeed();
|
||||||
|
}
|
||||||
|
|
||||||
void updateDownloadLength(int bytes) {
|
void updateDownloadLength(int bytes) {
|
||||||
downloadSpeed.update(bytes);
|
downloadSpeed.update(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateUploadLength(int bytes) {
|
||||||
|
uploadSpeed.update(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
int getMaxDownloadSpeed() const {
|
int getMaxDownloadSpeed() const {
|
||||||
return downloadSpeed.getMaxSpeed();
|
return downloadSpeed.getMaxSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getMaxUploadSpeed() const {
|
||||||
|
return uploadSpeed.getMaxSpeed();
|
||||||
|
}
|
||||||
|
|
||||||
int getAvgDownloadSpeed() const {
|
int getAvgDownloadSpeed() const {
|
||||||
return downloadSpeed.getAvgSpeed();
|
return downloadSpeed.getAvgSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getAvgUploadSpeed() const {
|
||||||
|
return uploadSpeed.getAvgSpeed();
|
||||||
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
downloadSpeed.reset();
|
downloadSpeed.reset();
|
||||||
|
uploadSpeed.reset();
|
||||||
downloadStartTime.reset();
|
downloadStartTime.reset();
|
||||||
|
status = IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void downloadStart() {
|
void downloadStart() {
|
||||||
|
|
|
@ -56,7 +56,7 @@ void PieceMessage::receivedAction() {
|
||||||
RequestSlot slot = peerInteraction->getCorrespondingRequestSlot(index,
|
RequestSlot slot = peerInteraction->getCorrespondingRequestSlot(index,
|
||||||
begin,
|
begin,
|
||||||
blockLength);
|
blockLength);
|
||||||
peer->addPeerUpload(blockLength);
|
peer->updateDownloadLength(blockLength);
|
||||||
if(!RequestSlot::isNull(slot) &&
|
if(!RequestSlot::isNull(slot) &&
|
||||||
peerInteraction->hasDownloadPiece(slot.getIndex())) {
|
peerInteraction->hasDownloadPiece(slot.getIndex())) {
|
||||||
peer->snubbing = false;
|
peer->snubbing = false;
|
||||||
|
@ -75,7 +75,6 @@ void PieceMessage::receivedAction() {
|
||||||
torrentMan->updatePiece(piece);
|
torrentMan->updatePiece(piece);
|
||||||
logger->debug("CUID#%d - Setting piece block index=%d",
|
logger->debug("CUID#%d - Setting piece block index=%d",
|
||||||
cuid, slot.getBlockIndex());
|
cuid, slot.getBlockIndex());
|
||||||
torrentMan->addDeltaDownloadLength(blockLength);
|
|
||||||
if(piece.pieceComplete()) {
|
if(piece.pieceComplete()) {
|
||||||
if(checkPieceHash(piece)) {
|
if(checkPieceHash(piece)) {
|
||||||
onGotNewPiece(piece);
|
onGotNewPiece(piece);
|
||||||
|
@ -139,9 +138,8 @@ void PieceMessage::send() {
|
||||||
((long long int)index)*pieceLength+begin+blockLength-leftDataLength;
|
((long long int)index)*pieceLength+begin+blockLength-leftDataLength;
|
||||||
int writtenLength =
|
int writtenLength =
|
||||||
sendPieceData(pieceDataOffset, leftDataLength);
|
sendPieceData(pieceDataOffset, leftDataLength);
|
||||||
peer->addPeerDownload(writtenLength);
|
peer->updateUploadLength(writtenLength);
|
||||||
torrentMan->addUploadLength(writtenLength);
|
torrentMan->addUploadLength(writtenLength);
|
||||||
torrentMan->addDeltaUploadLength(writtenLength);
|
|
||||||
if(writtenLength != leftDataLength) {
|
if(writtenLength != leftDataLength) {
|
||||||
inProgress = true;
|
inProgress = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public:
|
||||||
|
|
||||||
class RequestInfo {
|
class RequestInfo {
|
||||||
protected:
|
protected:
|
||||||
const Option* op;
|
Option* op;
|
||||||
const Logger* logger;
|
const Logger* logger;
|
||||||
Checksum checksum;
|
Checksum checksum;
|
||||||
FileInfo fileInfo;
|
FileInfo fileInfo;
|
||||||
|
@ -94,7 +94,7 @@ protected:
|
||||||
"aria2 will resume download if the transfer is restarted."));
|
"aria2 will resume download if the transfer is restarted."));
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
RequestInfo(const Option* op):
|
RequestInfo(Option* op):
|
||||||
op(op),
|
op(op),
|
||||||
fail(false)
|
fail(false)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,18 +43,11 @@ void TorrentDownloadEngine::onEndOfRun() {
|
||||||
void TorrentDownloadEngine::initStatistics() {
|
void TorrentDownloadEngine::initStatistics() {
|
||||||
downloadSpeed = 0;
|
downloadSpeed = 0;
|
||||||
uploadSpeed = 0;
|
uploadSpeed = 0;
|
||||||
lastElapsed = 0;
|
cp.reset();
|
||||||
cp[0].reset();
|
lastCalcStat.reset();
|
||||||
cp[1].reset();
|
|
||||||
startup.reset();
|
startup.reset();
|
||||||
sessionDownloadLengthArray[0] = 0;
|
|
||||||
sessionDownloadLengthArray[1] = 0;
|
|
||||||
sessionUploadLengthArray[0] = 0;
|
|
||||||
sessionUploadLengthArray[1] = 0;
|
|
||||||
currentCp = 0;
|
|
||||||
eta = 0;
|
eta = 0;
|
||||||
avgSpeed = 0;
|
avgSpeed = 0;
|
||||||
sessionDownloadLength = 0;
|
|
||||||
downloadLength = 0;
|
downloadLength = 0;
|
||||||
totalLength = 0;
|
totalLength = 0;
|
||||||
if(torrentMan->isSelectiveDownloadingMode()) {
|
if(torrentMan->isSelectiveDownloadingMode()) {
|
||||||
|
@ -63,25 +56,24 @@ void TorrentDownloadEngine::initStatistics() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int TorrentDownloadEngine::calculateSpeed(long long int sessionLength, int elapsed) {
|
int TorrentDownloadEngine::calculateSpeed(long long int length, int elapsed) {
|
||||||
int nowSpeed = (int)(sessionLength/elapsed);
|
int nowSpeed = (int)(length/elapsed);
|
||||||
return nowSpeed;
|
return nowSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TorrentDownloadEngine::calculateStat() {
|
||||||
|
TransferStat stat = torrentMan->calculateStat();
|
||||||
|
downloadSpeed = stat.downloadSpeed;
|
||||||
|
uploadSpeed = stat.uploadSpeed;
|
||||||
|
avgSpeed = calculateSpeed(stat.sessionDownloadLength, startup.difference());
|
||||||
|
if(avgSpeed < 0) {
|
||||||
|
avgSpeed = 0;
|
||||||
|
} else if(avgSpeed != 0) {
|
||||||
|
eta = (totalLength-downloadLength)/avgSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TorrentDownloadEngine::calculateStatistics() {
|
void TorrentDownloadEngine::calculateStatistics() {
|
||||||
int elapsed = cp[currentCp].difference();
|
|
||||||
|
|
||||||
sessionDownloadLengthArray[0] += torrentMan->getDeltaDownloadLength();
|
|
||||||
sessionUploadLengthArray[0] += torrentMan->getDeltaUploadLength();
|
|
||||||
sessionDownloadLengthArray[1] += torrentMan->getDeltaDownloadLength();
|
|
||||||
sessionUploadLengthArray[1] += torrentMan->getDeltaUploadLength();
|
|
||||||
|
|
||||||
sessionDownloadLength += torrentMan->getDeltaDownloadLength();
|
|
||||||
|
|
||||||
|
|
||||||
torrentMan->resetDeltaDownloadLength();
|
|
||||||
torrentMan->resetDeltaUploadLength();
|
|
||||||
|
|
||||||
if(torrentMan->isSelectiveDownloadingMode()) {
|
if(torrentMan->isSelectiveDownloadingMode()) {
|
||||||
downloadLength = torrentMan->getDownloadLength()-selectedDownloadLengthDiff;
|
downloadLength = torrentMan->getDownloadLength()-selectedDownloadLengthDiff;
|
||||||
totalLength = selectedTotalLength;
|
totalLength = selectedTotalLength;
|
||||||
|
@ -90,32 +82,13 @@ void TorrentDownloadEngine::calculateStatistics() {
|
||||||
totalLength = torrentMan->getTotalLength();
|
totalLength = torrentMan->getTotalLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(elapsed > 0) {
|
Time now;
|
||||||
downloadSpeed = calculateSpeed(sessionDownloadLengthArray[currentCp], elapsed);
|
if(now.getTimeInMillis()-lastCalcStat.getTimeInMillis() >= 1000) {
|
||||||
uploadSpeed = calculateSpeed(sessionUploadLengthArray[currentCp], elapsed);
|
calculateStat();
|
||||||
|
lastCalcStat = now;
|
||||||
}
|
}
|
||||||
|
if(cp.difference() >= 1) {
|
||||||
if(elapsed-lastElapsed >= 1) {
|
|
||||||
int elapsedFromStartup = startup.difference();
|
|
||||||
if(elapsedFromStartup > 0) {
|
|
||||||
avgSpeed = calculateSpeed(sessionDownloadLength,
|
|
||||||
elapsedFromStartup);
|
|
||||||
}
|
|
||||||
if(avgSpeed < 0) {
|
|
||||||
avgSpeed = 0;
|
|
||||||
} else if(avgSpeed != 0) {
|
|
||||||
eta = (totalLength-downloadLength)/avgSpeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendStatistics();
|
sendStatistics();
|
||||||
lastElapsed = elapsed;
|
cp.reset();
|
||||||
}
|
|
||||||
|
|
||||||
if(elapsed > 15) {
|
|
||||||
sessionDownloadLengthArray[currentCp] = 0;
|
|
||||||
sessionUploadLengthArray[currentCp] = 0;
|
|
||||||
cp[currentCp].reset();
|
|
||||||
lastElapsed = 0;
|
|
||||||
currentCp = currentCp ? 0 : 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,20 +33,14 @@ private:
|
||||||
void initStatistics();
|
void initStatistics();
|
||||||
void calculateStatistics();
|
void calculateStatistics();
|
||||||
protected:
|
protected:
|
||||||
Time cp[2];
|
Time cp;
|
||||||
long long int sessionDownloadLengthArray[2];
|
Time lastCalcStat;
|
||||||
long long int sessionUploadLengthArray[2];
|
|
||||||
int currentCp;
|
|
||||||
|
|
||||||
int downloadSpeed;
|
int downloadSpeed;
|
||||||
int uploadSpeed;
|
int uploadSpeed;
|
||||||
int lastElapsed;
|
|
||||||
long long int selectedDownloadLengthDiff;
|
long long int selectedDownloadLengthDiff;
|
||||||
long long int selectedTotalLength;
|
long long int selectedTotalLength;
|
||||||
// The time when startup
|
// The time when startup
|
||||||
Time startup;
|
Time startup;
|
||||||
// The number of bytes downloaded since startup
|
|
||||||
long long int sessionDownloadLength;
|
|
||||||
// The average speed(bytes per second) since startup
|
// The average speed(bytes per second) since startup
|
||||||
int avgSpeed;
|
int avgSpeed;
|
||||||
// The estimated remaining time to complete the download.
|
// The estimated remaining time to complete the download.
|
||||||
|
@ -55,6 +49,8 @@ protected:
|
||||||
long long int totalLength;
|
long long int totalLength;
|
||||||
|
|
||||||
int calculateSpeed(long long int sessionLength, int elapsed);
|
int calculateSpeed(long long int sessionLength, int elapsed);
|
||||||
|
void calculateStat();
|
||||||
|
|
||||||
virtual void onEndOfRun();
|
virtual void onEndOfRun();
|
||||||
virtual void sendStatistics() = 0;
|
virtual void sendStatistics() = 0;
|
||||||
public:
|
public:
|
||||||
|
@ -64,10 +60,6 @@ public:
|
||||||
TorrentMan* torrentMan;
|
TorrentMan* torrentMan;
|
||||||
|
|
||||||
bool isFilenameFixed() const { return filenameFixed; }
|
bool isFilenameFixed() const { return filenameFixed; }
|
||||||
|
|
||||||
// returns uploading speed in byte/sec.
|
|
||||||
int getUploadSpeed() const { return uploadSpeed; }
|
|
||||||
int getDownloadSpeed() const { return downloadSpeed; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _D_TORRENT_DOWNLOAD_ENGINE_H_
|
#endif // _D_TORRENT_DOWNLOAD_ENGINE_H_
|
||||||
|
|
|
@ -50,8 +50,6 @@ TorrentMan::TorrentMan():bitfield(0),
|
||||||
uploadLength(0),
|
uploadLength(0),
|
||||||
preDownloadLength(0),
|
preDownloadLength(0),
|
||||||
preUploadLength(0),
|
preUploadLength(0),
|
||||||
deltaDownloadLength(0),
|
|
||||||
deltaUploadLength(0),
|
|
||||||
storeDir("."),
|
storeDir("."),
|
||||||
setupComplete(false),
|
setupComplete(false),
|
||||||
halt(false),
|
halt(false),
|
||||||
|
@ -710,3 +708,15 @@ TorrentMan::removeAdvertisedPiece(int elapsed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TransferStat TorrentMan::calculateStat() {
|
||||||
|
TransferStat stat;
|
||||||
|
for(Peers::iterator itr = activePeers.begin();
|
||||||
|
itr != activePeers.end(); itr++) {
|
||||||
|
PeerHandle& peer = *itr;
|
||||||
|
stat.downloadSpeed += peer->calculateDownloadSpeed();
|
||||||
|
stat.uploadSpeed += peer->calculateUploadSpeed();
|
||||||
|
stat.sessionDownloadLength += peer->getSessionDownloadLength();
|
||||||
|
stat.sessionUploadLength += peer->getSessionUploadLength();
|
||||||
|
}
|
||||||
|
return stat;
|
||||||
|
}
|
||||||
|
|
|
@ -51,6 +51,17 @@ using namespace std;
|
||||||
#define END_GAME_PIECE_NUM 20
|
#define END_GAME_PIECE_NUM 20
|
||||||
#define MAX_PEER_ERROR 5
|
#define MAX_PEER_ERROR 5
|
||||||
|
|
||||||
|
class TransferStat {
|
||||||
|
public:
|
||||||
|
int downloadSpeed;
|
||||||
|
int uploadSpeed;
|
||||||
|
long long int sessionDownloadLength;
|
||||||
|
long long int sessionUploadLength;
|
||||||
|
public:
|
||||||
|
TransferStat():downloadSpeed(0), uploadSpeed(0),
|
||||||
|
sessionDownloadLength(0), sessionUploadLength(0) {}
|
||||||
|
};
|
||||||
|
|
||||||
class HaveEntry {
|
class HaveEntry {
|
||||||
public:
|
public:
|
||||||
int cuid;
|
int cuid;
|
||||||
|
@ -79,8 +90,6 @@ private:
|
||||||
long long int uploadLength;
|
long long int uploadLength;
|
||||||
long long int preDownloadLength;
|
long long int preDownloadLength;
|
||||||
long long int preUploadLength;
|
long long int preUploadLength;
|
||||||
int deltaDownloadLength;
|
|
||||||
int deltaUploadLength;
|
|
||||||
int fileMode;
|
int fileMode;
|
||||||
string storeDir;
|
string storeDir;
|
||||||
int port;
|
int port;
|
||||||
|
@ -199,14 +208,6 @@ public:
|
||||||
long long int getTotalLength() const { return totalLength; }
|
long long int getTotalLength() const { return totalLength; }
|
||||||
void setTotalLength(long long int length) { totalLength = length; }
|
void setTotalLength(long long int length) { totalLength = length; }
|
||||||
|
|
||||||
void addDeltaDownloadLength(int length) { deltaDownloadLength += length; }
|
|
||||||
int getDeltaDownloadLength() const { return deltaDownloadLength; }
|
|
||||||
void resetDeltaDownloadLength() { deltaDownloadLength = 0; }
|
|
||||||
|
|
||||||
void addDeltaUploadLength(int length) { deltaUploadLength += length; }
|
|
||||||
int getDeltaUploadLength() const { return deltaUploadLength; }
|
|
||||||
void resetDeltaUploadLength() { deltaUploadLength = 0; }
|
|
||||||
|
|
||||||
void addDownloadLength(int deltaLength) { downloadLength += deltaLength; }
|
void addDownloadLength(int deltaLength) { downloadLength += deltaLength; }
|
||||||
long long int getDownloadLength() const { return downloadLength; }
|
long long int getDownloadLength() const { return downloadLength; }
|
||||||
void setDownloadLength(long long int length) { downloadLength = length; }
|
void setDownloadLength(long long int length) { downloadLength = length; }
|
||||||
|
@ -263,6 +264,7 @@ public:
|
||||||
void onDownloadComplete();
|
void onDownloadComplete();
|
||||||
|
|
||||||
void addActivePeer(const PeerHandle& peer) {
|
void addActivePeer(const PeerHandle& peer) {
|
||||||
|
peer->activate();
|
||||||
activePeers.push_back(peer);
|
activePeers.push_back(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,6 +273,7 @@ public:
|
||||||
void deleteActivePeer(const PeerHandle& peer) {
|
void deleteActivePeer(const PeerHandle& peer) {
|
||||||
Peers::iterator itr = find(activePeers.begin(), activePeers.end(), peer);
|
Peers::iterator itr = find(activePeers.begin(), activePeers.end(), peer);
|
||||||
if(itr != activePeers.end()) {
|
if(itr != activePeers.end()) {
|
||||||
|
peer->deactivate();
|
||||||
activePeers.erase(itr);
|
activePeers.erase(itr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -284,6 +287,8 @@ public:
|
||||||
SINGLE,
|
SINGLE,
|
||||||
MULTI
|
MULTI
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TransferStat calculateStat();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _D_TORRENT_MAN_H_
|
#endif // _D_TORRENT_MAN_H_
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
extern RequestInfo* requestInfo;
|
extern RequestInfo* requestInfo;
|
||||||
extern void setSignalHander(int signal, void (*handler)(int), int flags);
|
extern void setSignalHander(int signal, void (*handler)(int), int flags);
|
||||||
|
extern bool timeoutSpecified;
|
||||||
|
|
||||||
void torrentHandler(int signal) {
|
void torrentHandler(int signal) {
|
||||||
((TorrentDownloadEngine*)requestInfo->getDownloadEngine())->
|
((TorrentDownloadEngine*)requestInfo->getDownloadEngine())->
|
||||||
|
@ -37,6 +38,9 @@ RequestInfo* TorrentRequestInfo::execute() {
|
||||||
showFileEntry();
|
showFileEntry();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if(!timeoutSpecified) {
|
||||||
|
op->put(PREF_TIMEOUT, "180");
|
||||||
|
}
|
||||||
e = DownloadEngineFactory::newTorrentConsoleEngine(op,
|
e = DownloadEngineFactory::newTorrentConsoleEngine(op,
|
||||||
torrentFile,
|
torrentFile,
|
||||||
targetFiles);
|
targetFiles);
|
||||||
|
|
|
@ -33,7 +33,7 @@ private:
|
||||||
|
|
||||||
void showFileEntry();
|
void showFileEntry();
|
||||||
public:
|
public:
|
||||||
TorrentRequestInfo(const string& torrentFile, const Option* op):
|
TorrentRequestInfo(const string& torrentFile, Option* op):
|
||||||
RequestInfo(op),
|
RequestInfo(op),
|
||||||
torrentFile(torrentFile),
|
torrentFile(torrentFile),
|
||||||
e(0) {}
|
e(0) {}
|
||||||
|
|
|
@ -35,7 +35,7 @@ private:
|
||||||
Requests& reserved,
|
Requests& reserved,
|
||||||
int maxConnections) const;
|
int maxConnections) const;
|
||||||
public:
|
public:
|
||||||
UrlRequestInfo(const Strings& urls, int maxConnections, const Option* op):
|
UrlRequestInfo(const Strings& urls, int maxConnections, Option* op):
|
||||||
RequestInfo(op),
|
RequestInfo(op),
|
||||||
urls(urls),
|
urls(urls),
|
||||||
maxConnections(maxConnections),
|
maxConnections(maxConnections),
|
||||||
|
|
|
@ -60,6 +60,7 @@ extern int optind, opterr, optopt;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
RequestInfo* requestInfo;
|
RequestInfo* requestInfo;
|
||||||
|
bool timeoutSpecified;
|
||||||
|
|
||||||
void setSignalHander(int signal, void (*handler)(int), int flags) {
|
void setSignalHander(int signal, void (*handler)(int), int flags) {
|
||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
|
@ -265,6 +266,8 @@ int main(int argc, char* argv[]) {
|
||||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||||
textdomain (PACKAGE);
|
textdomain (PACKAGE);
|
||||||
#endif // ENABLE_NLS
|
#endif // ENABLE_NLS
|
||||||
|
timeoutSpecified = false;
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
Option* op = new Option();
|
Option* op = new Option();
|
||||||
op->put(PREF_STDOUT_LOG, V_FALSE);
|
op->put(PREF_STDOUT_LOG, V_FALSE);
|
||||||
|
@ -492,7 +495,7 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 20: {
|
case 20: {
|
||||||
int uploadSpeed = (int)strtol(optarg, NULL, 10);
|
int uploadSpeed = strtol(optarg, NULL, 10)*1024;
|
||||||
if(0 > uploadSpeed) {
|
if(0 > uploadSpeed) {
|
||||||
cerr << _("upload-limit must be greater than or equal to 0.") << endl;
|
cerr << _("upload-limit must be greater than or equal to 0.") << endl;
|
||||||
showUsage();
|
showUsage();
|
||||||
|
@ -587,6 +590,7 @@ int main(int argc, char* argv[]) {
|
||||||
int timeout = (int)strtol(optarg, NULL, 10);
|
int timeout = (int)strtol(optarg, NULL, 10);
|
||||||
if(1 <= timeout && timeout <= 600) {
|
if(1 <= timeout && timeout <= 600) {
|
||||||
op->put(PREF_TIMEOUT, Util::itos(timeout));
|
op->put(PREF_TIMEOUT, Util::itos(timeout));
|
||||||
|
timeoutSpecified = true;
|
||||||
} else {
|
} else {
|
||||||
cerr << _("timeout must be between 1 and 600") << endl;
|
cerr << _("timeout must be between 1 and 600") << endl;
|
||||||
showUsage();
|
showUsage();
|
||||||
|
|
Loading…
Reference in New Issue