mirror of https://github.com/aria2/aria2
renamed TorrentMan::totalSize to TorrentMan::totalLength and added its
accessors.pull/1/head
parent
180153592d
commit
f02143579b
|
@ -342,7 +342,7 @@ PeerMessage* PeerConnection::receiveMessage() {
|
||||||
PeerMessage* peerMessage = PeerMessageUtil::createPeerMessage(resbuf, currentPayloadLength);
|
PeerMessage* peerMessage = PeerMessageUtil::createPeerMessage(resbuf, currentPayloadLength);
|
||||||
try {
|
try {
|
||||||
PeerMessageUtil::checkIntegrity(peerMessage, torrentMan->pieceLength,
|
PeerMessageUtil::checkIntegrity(peerMessage, torrentMan->pieceLength,
|
||||||
torrentMan->pieces, torrentMan->totalSize);
|
torrentMan->pieces, torrentMan->getTotalLength());
|
||||||
} catch(Exception* e) {
|
} catch(Exception* e) {
|
||||||
delete peerMessage;
|
delete peerMessage;
|
||||||
throw;
|
throw;
|
||||||
|
|
|
@ -67,7 +67,7 @@ bool PeerListenCommand::execute() {
|
||||||
e->torrentMan->connections < MAX_PEERS) {
|
e->torrentMan->connections < MAX_PEERS) {
|
||||||
Peer* peer = new Peer(peerInfo.first, peerInfo.second,
|
Peer* peer = new Peer(peerInfo.first, peerInfo.second,
|
||||||
e->torrentMan->pieceLength,
|
e->torrentMan->pieceLength,
|
||||||
e->torrentMan->totalSize);
|
e->torrentMan->getTotalLength());
|
||||||
if(e->torrentMan->addPeer(peer, true)) {
|
if(e->torrentMan->addPeer(peer, true)) {
|
||||||
int newCuid = e->torrentMan->getNewCuid();
|
int newCuid = e->torrentMan->getNewCuid();
|
||||||
peer->cuid = newCuid;
|
peer->cuid = newCuid;
|
||||||
|
|
|
@ -134,14 +134,14 @@ void PeerMessageUtil::checkBegin(const PeerMessage* message, int pieceLength) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerMessageUtil::checkPieceOffset(const PeerMessage* message, int pieceLength, int pieces, long long int totalSize) {
|
void PeerMessageUtil::checkPieceOffset(const PeerMessage* message, int pieceLength, int pieces, long long int totalLength) {
|
||||||
if(!(0 <= message->getBegin() && 0 < message->getLength())) {
|
if(!(0 <= message->getBegin() && 0 < message->getLength())) {
|
||||||
throw new DlAbortEx("invalid offset, begin = %d, length = %d", message->getBegin(), message->getLength());
|
throw new DlAbortEx("invalid offset, begin = %d, length = %d", message->getBegin(), message->getLength());
|
||||||
}
|
}
|
||||||
int offset = message->getBegin()+message->getLength();
|
int offset = message->getBegin()+message->getLength();
|
||||||
int currentPieceLength;
|
int currentPieceLength;
|
||||||
if(message->getIndex()+1 == pieces) {
|
if(message->getIndex()+1 == pieces) {
|
||||||
currentPieceLength = pieceLength-(pieces*pieceLength-totalSize);
|
currentPieceLength = pieceLength-(pieces*pieceLength-totalLength);
|
||||||
} else {
|
} else {
|
||||||
currentPieceLength = pieceLength;
|
currentPieceLength = pieceLength;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ void PeerMessageUtil::checkBitfield(const PeerMessage* message, int pieces) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerMessageUtil::checkIntegrity(const PeerMessage* message, int pieceLength, int pieces, long long int totalSize) {
|
void PeerMessageUtil::checkIntegrity(const PeerMessage* message, int pieceLength, int pieces, long long int totalLength) {
|
||||||
// 0 <= index < pieces
|
// 0 <= index < pieces
|
||||||
// 0 <= begin < pieceLength
|
// 0 <= begin < pieceLength
|
||||||
// 0 < begin+length <= pieceLength
|
// 0 < begin+length <= pieceLength
|
||||||
|
@ -192,7 +192,7 @@ void PeerMessageUtil::checkIntegrity(const PeerMessage* message, int pieceLength
|
||||||
checkIndex(message, pieces);
|
checkIndex(message, pieces);
|
||||||
checkBegin(message, pieceLength);
|
checkBegin(message, pieceLength);
|
||||||
checkLength(message);
|
checkLength(message);
|
||||||
checkPieceOffset(message, pieceLength, pieces, totalSize);
|
checkPieceOffset(message, pieceLength, pieces, totalLength);
|
||||||
break;
|
break;
|
||||||
case PeerMessage::PIECE:
|
case PeerMessage::PIECE:
|
||||||
checkIndex(message, pieces);
|
checkIndex(message, pieces);
|
||||||
|
|
|
@ -39,11 +39,11 @@ private:
|
||||||
static void checkIndex(const PeerMessage* message, int pieces);
|
static void checkIndex(const PeerMessage* message, int pieces);
|
||||||
static void checkBegin(const PeerMessage* message, int pieceLength);
|
static void checkBegin(const PeerMessage* message, int pieceLength);
|
||||||
static void checkLength(const PeerMessage* message);
|
static void checkLength(const PeerMessage* message);
|
||||||
static void checkPieceOffset(const PeerMessage* message, int pieceLength, int pieces, long long int totalSize);
|
static void checkPieceOffset(const PeerMessage* message, int pieceLength, int pieces, long long int totalLength);
|
||||||
static void checkBitfield(const PeerMessage* message, int pieces);
|
static void checkBitfield(const PeerMessage* message, int pieces);
|
||||||
public:
|
public:
|
||||||
static PeerMessage* createPeerMessage(const char* msg, int len);
|
static PeerMessage* createPeerMessage(const char* msg, int len);
|
||||||
static void checkIntegrity(const PeerMessage* message, int pieceLength, int pieces, long long int totalSize);
|
static void checkIntegrity(const PeerMessage* message, int pieceLength, int pieces, long long int totalLength);
|
||||||
static HandshakeMessage* createHandshakeMessage(const char* msg);
|
static HandshakeMessage* createHandshakeMessage(const char* msg);
|
||||||
static void checkHandshake(const HandshakeMessage* message, const unsigned char* infoHash);
|
static void checkHandshake(const HandshakeMessage* message, const unsigned char* infoHash);
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,9 +34,9 @@ void TorrentConsoleDownloadEngine::printStatistics() {
|
||||||
} else {
|
} else {
|
||||||
printf("%s/%sB %d%% DW:%.2f",
|
printf("%s/%sB %d%% DW:%.2f",
|
||||||
Util::llitos(torrentMan->getDownloadLength(), true).c_str(),
|
Util::llitos(torrentMan->getDownloadLength(), true).c_str(),
|
||||||
Util::llitos(torrentMan->totalSize, true).c_str(),
|
Util::llitos(torrentMan->getTotalLength(), true).c_str(),
|
||||||
(torrentMan->totalSize == 0 ?
|
(torrentMan->getTotalLength() == 0 ?
|
||||||
0 : (int)((torrentMan->getDownloadLength()*100)/torrentMan->totalSize)),
|
0 : (int)((torrentMan->getDownloadLength()*100)/torrentMan->getTotalLength())),
|
||||||
downloadSpeed/1000.0);
|
downloadSpeed/1000.0);
|
||||||
}
|
}
|
||||||
printf(" UP:%.2f(%s) %dpeers",
|
printf(" UP:%.2f(%s) %dpeers",
|
||||||
|
|
|
@ -281,7 +281,7 @@ void TorrentMan::initBitfield() {
|
||||||
if(bitfield != NULL) {
|
if(bitfield != NULL) {
|
||||||
delete bitfield;
|
delete bitfield;
|
||||||
}
|
}
|
||||||
bitfield = new BitfieldMan(pieceLength, totalSize);
|
bitfield = new BitfieldMan(pieceLength, totalLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentMan::setBitfield(unsigned char* bitfield, int bitfieldLength) {
|
void TorrentMan::setBitfield(unsigned char* bitfield, int bitfieldLength) {
|
||||||
|
@ -325,7 +325,7 @@ void TorrentMan::setup(string metaInfoFile) {
|
||||||
// single-file mode;
|
// single-file mode;
|
||||||
setFileMode(SINGLE);
|
setFileMode(SINGLE);
|
||||||
Data* length = (Data*)infoDic->get("length");
|
Data* length = (Data*)infoDic->get("length");
|
||||||
totalSize = length->toLLInt();
|
totalLength = length->toLLInt();
|
||||||
} else {
|
} else {
|
||||||
long long int length = 0;
|
long long int length = 0;
|
||||||
// multi-file mode
|
// multi-file mode
|
||||||
|
@ -353,11 +353,11 @@ void TorrentMan::setup(string metaInfoFile) {
|
||||||
FileEntry fileEntry(filePath, lengthData->toLLInt());
|
FileEntry fileEntry(filePath, lengthData->toLLInt());
|
||||||
multiFileEntries.push_back(fileEntry);
|
multiFileEntries.push_back(fileEntry);
|
||||||
}
|
}
|
||||||
totalSize = length;
|
totalLength = length;
|
||||||
}
|
}
|
||||||
announce = ((Data*)topDic->get("announce"))->toString();
|
announce = ((Data*)topDic->get("announce"))->toString();
|
||||||
pieceLength = ((Data*)infoDic->get("piece length"))->toInt();
|
pieceLength = ((Data*)infoDic->get("piece length"))->toInt();
|
||||||
pieces = totalSize/pieceLength+(totalSize%pieceLength ? 1 : 0);
|
pieces = totalLength/pieceLength+(totalLength%pieceLength ? 1 : 0);
|
||||||
Data* piecesHashData = (Data*)infoDic->get("pieces");
|
Data* piecesHashData = (Data*)infoDic->get("pieces");
|
||||||
if(piecesHashData->getLen() != pieces*20) {
|
if(piecesHashData->getLen() != pieces*20) {
|
||||||
throw new DlAbortEx("the number of pieces is wrong.");
|
throw new DlAbortEx("the number of pieces is wrong.");
|
||||||
|
@ -371,7 +371,7 @@ void TorrentMan::setup(string metaInfoFile) {
|
||||||
initBitfield();
|
initBitfield();
|
||||||
delete topDic;
|
delete topDic;
|
||||||
|
|
||||||
diskWriter = new PreAllocationDiskWriter(totalSize);
|
diskWriter = new PreAllocationDiskWriter(totalLength);
|
||||||
if(segmentFileExists()) {
|
if(segmentFileExists()) {
|
||||||
load();
|
load();
|
||||||
diskWriter->openExistingFile(getTempFilePath());
|
diskWriter->openExistingFile(getTempFilePath());
|
||||||
|
|
|
@ -73,6 +73,7 @@ private:
|
||||||
deque<string> pieceHashes;
|
deque<string> pieceHashes;
|
||||||
int peerEntryIdCounter;
|
int peerEntryIdCounter;
|
||||||
int cuidCounter;
|
int cuidCounter;
|
||||||
|
long long int totalLength;
|
||||||
long long int downloadLength;
|
long long int downloadLength;
|
||||||
long long int uploadLength;
|
long long int uploadLength;
|
||||||
long long int preDownloadLength;
|
long long int preDownloadLength;
|
||||||
|
@ -99,7 +100,6 @@ private:
|
||||||
public:
|
public:
|
||||||
int pieceLength;
|
int pieceLength;
|
||||||
int pieces;
|
int pieces;
|
||||||
long long int totalSize;
|
|
||||||
string peerId;
|
string peerId;
|
||||||
string announce;
|
string announce;
|
||||||
string trackerId;
|
string trackerId;
|
||||||
|
@ -173,6 +173,9 @@ public:
|
||||||
haves.erase(cuid);
|
haves.erase(cuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long long int getTotalLength() const { return totalLength; }
|
||||||
|
void setTotalLength(long long int length) { totalLength = length; }
|
||||||
|
|
||||||
void addDeltaDownload(int size) { deltaDownload += size; }
|
void addDeltaDownload(int size) { deltaDownload += size; }
|
||||||
int getDeltaDownload() const { return deltaDownload; }
|
int getDeltaDownload() const { return deltaDownload; }
|
||||||
void resetDeltaDownload() { deltaDownload = 0; }
|
void resetDeltaDownload() { deltaDownload = 0; }
|
||||||
|
|
|
@ -59,8 +59,8 @@ bool TrackerInitCommand::execute() {
|
||||||
"port="+Util::itos(e->torrentMan->getPort())+"&"+
|
"port="+Util::itos(e->torrentMan->getPort())+"&"+
|
||||||
"uploaded="+Util::llitos(e->torrentMan->getSessionUploadedSize())+"&"+
|
"uploaded="+Util::llitos(e->torrentMan->getSessionUploadedSize())+"&"+
|
||||||
"downloaded="+Util::llitos(e->torrentMan->getSessionDownloadedSize())+"&"+
|
"downloaded="+Util::llitos(e->torrentMan->getSessionDownloadedSize())+"&"+
|
||||||
"left="+(e->torrentMan->totalSize-e->torrentMan->getDownloadLength() <= 0
|
"left="+(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength() <= 0
|
||||||
? "0" : Util::llitos(e->torrentMan->totalSize-e->torrentMan->getDownloadLength()))+"&"+
|
? "0" : Util::llitos(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength()))+"&"+
|
||||||
"compact=1";
|
"compact=1";
|
||||||
if(!event.empty()) {
|
if(!event.empty()) {
|
||||||
url += string("&")+"event="+event;
|
url += string("&")+"event="+event;
|
||||||
|
|
|
@ -88,7 +88,7 @@ bool TrackerUpdateCommand::execute() {
|
||||||
snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d",
|
snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d",
|
||||||
ipaddr1, ipaddr2, ipaddr3, ipaddr4);
|
ipaddr1, ipaddr2, ipaddr3, ipaddr4);
|
||||||
Peer* peer = new Peer(ipaddr, port, e->torrentMan->pieceLength,
|
Peer* peer = new Peer(ipaddr, port, e->torrentMan->pieceLength,
|
||||||
e->torrentMan->totalSize);
|
e->torrentMan->getTotalLength());
|
||||||
if(e->torrentMan->addPeer(peer)) {
|
if(e->torrentMan->addPeer(peer)) {
|
||||||
e->logger->debug("CUID#%d - adding peer %s:%d", cuid,
|
e->logger->debug("CUID#%d - adding peer %s:%d", cuid,
|
||||||
peer->ipaddr.c_str(), peer->port);
|
peer->ipaddr.c_str(), peer->port);
|
||||||
|
|
Loading…
Reference in New Issue