diff --git a/src/PeerConnection.cc b/src/PeerConnection.cc index 1a14810d..4010a34f 100644 --- a/src/PeerConnection.cc +++ b/src/PeerConnection.cc @@ -342,7 +342,7 @@ PeerMessage* PeerConnection::receiveMessage() { PeerMessage* peerMessage = PeerMessageUtil::createPeerMessage(resbuf, currentPayloadLength); try { PeerMessageUtil::checkIntegrity(peerMessage, torrentMan->pieceLength, - torrentMan->pieces, torrentMan->totalSize); + torrentMan->pieces, torrentMan->getTotalLength()); } catch(Exception* e) { delete peerMessage; throw; diff --git a/src/PeerListenCommand.cc b/src/PeerListenCommand.cc index eb666b70..65573a77 100644 --- a/src/PeerListenCommand.cc +++ b/src/PeerListenCommand.cc @@ -67,7 +67,7 @@ bool PeerListenCommand::execute() { e->torrentMan->connections < MAX_PEERS) { Peer* peer = new Peer(peerInfo.first, peerInfo.second, e->torrentMan->pieceLength, - e->torrentMan->totalSize); + e->torrentMan->getTotalLength()); if(e->torrentMan->addPeer(peer, true)) { int newCuid = e->torrentMan->getNewCuid(); peer->cuid = newCuid; diff --git a/src/PeerMessageUtil.cc b/src/PeerMessageUtil.cc index 4f0f67e0..0585866a 100644 --- a/src/PeerMessageUtil.cc +++ b/src/PeerMessageUtil.cc @@ -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())) { throw new DlAbortEx("invalid offset, begin = %d, length = %d", message->getBegin(), message->getLength()); } int offset = message->getBegin()+message->getLength(); int currentPieceLength; if(message->getIndex()+1 == pieces) { - currentPieceLength = pieceLength-(pieces*pieceLength-totalSize); + currentPieceLength = pieceLength-(pieces*pieceLength-totalLength); } else { 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 <= begin < pieceLength // 0 < begin+length <= pieceLength @@ -192,7 +192,7 @@ void PeerMessageUtil::checkIntegrity(const PeerMessage* message, int pieceLength checkIndex(message, pieces); checkBegin(message, pieceLength); checkLength(message); - checkPieceOffset(message, pieceLength, pieces, totalSize); + checkPieceOffset(message, pieceLength, pieces, totalLength); break; case PeerMessage::PIECE: checkIndex(message, pieces); diff --git a/src/PeerMessageUtil.h b/src/PeerMessageUtil.h index 23e07358..47e74049 100644 --- a/src/PeerMessageUtil.h +++ b/src/PeerMessageUtil.h @@ -39,11 +39,11 @@ private: static void checkIndex(const PeerMessage* message, int pieces); static void checkBegin(const PeerMessage* message, int pieceLength); 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); public: 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 void checkHandshake(const HandshakeMessage* message, const unsigned char* infoHash); }; diff --git a/src/TorrentConsoleDownloadEngine.cc b/src/TorrentConsoleDownloadEngine.cc index 5cee357f..e459549b 100644 --- a/src/TorrentConsoleDownloadEngine.cc +++ b/src/TorrentConsoleDownloadEngine.cc @@ -34,9 +34,9 @@ void TorrentConsoleDownloadEngine::printStatistics() { } else { printf("%s/%sB %d%% DW:%.2f", Util::llitos(torrentMan->getDownloadLength(), true).c_str(), - Util::llitos(torrentMan->totalSize, true).c_str(), - (torrentMan->totalSize == 0 ? - 0 : (int)((torrentMan->getDownloadLength()*100)/torrentMan->totalSize)), + Util::llitos(torrentMan->getTotalLength(), true).c_str(), + (torrentMan->getTotalLength() == 0 ? + 0 : (int)((torrentMan->getDownloadLength()*100)/torrentMan->getTotalLength())), downloadSpeed/1000.0); } printf(" UP:%.2f(%s) %dpeers", diff --git a/src/TorrentMan.cc b/src/TorrentMan.cc index ae28745a..7a3ea911 100644 --- a/src/TorrentMan.cc +++ b/src/TorrentMan.cc @@ -281,7 +281,7 @@ void TorrentMan::initBitfield() { if(bitfield != NULL) { delete bitfield; } - bitfield = new BitfieldMan(pieceLength, totalSize); + bitfield = new BitfieldMan(pieceLength, totalLength); } void TorrentMan::setBitfield(unsigned char* bitfield, int bitfieldLength) { @@ -325,7 +325,7 @@ void TorrentMan::setup(string metaInfoFile) { // single-file mode; setFileMode(SINGLE); Data* length = (Data*)infoDic->get("length"); - totalSize = length->toLLInt(); + totalLength = length->toLLInt(); } else { long long int length = 0; // multi-file mode @@ -353,11 +353,11 @@ void TorrentMan::setup(string metaInfoFile) { FileEntry fileEntry(filePath, lengthData->toLLInt()); multiFileEntries.push_back(fileEntry); } - totalSize = length; + totalLength = length; } announce = ((Data*)topDic->get("announce"))->toString(); 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"); if(piecesHashData->getLen() != pieces*20) { throw new DlAbortEx("the number of pieces is wrong."); @@ -371,7 +371,7 @@ void TorrentMan::setup(string metaInfoFile) { initBitfield(); delete topDic; - diskWriter = new PreAllocationDiskWriter(totalSize); + diskWriter = new PreAllocationDiskWriter(totalLength); if(segmentFileExists()) { load(); diskWriter->openExistingFile(getTempFilePath()); diff --git a/src/TorrentMan.h b/src/TorrentMan.h index ff2def6f..84798a50 100644 --- a/src/TorrentMan.h +++ b/src/TorrentMan.h @@ -73,6 +73,7 @@ private: deque pieceHashes; int peerEntryIdCounter; int cuidCounter; + long long int totalLength; long long int downloadLength; long long int uploadLength; long long int preDownloadLength; @@ -99,7 +100,6 @@ private: public: int pieceLength; int pieces; - long long int totalSize; string peerId; string announce; string trackerId; @@ -173,6 +173,9 @@ public: haves.erase(cuid); } + long long int getTotalLength() const { return totalLength; } + void setTotalLength(long long int length) { totalLength = length; } + void addDeltaDownload(int size) { deltaDownload += size; } int getDeltaDownload() const { return deltaDownload; } void resetDeltaDownload() { deltaDownload = 0; } diff --git a/src/TrackerInitCommand.cc b/src/TrackerInitCommand.cc index 79a53e87..130c5a26 100644 --- a/src/TrackerInitCommand.cc +++ b/src/TrackerInitCommand.cc @@ -59,8 +59,8 @@ bool TrackerInitCommand::execute() { "port="+Util::itos(e->torrentMan->getPort())+"&"+ "uploaded="+Util::llitos(e->torrentMan->getSessionUploadedSize())+"&"+ "downloaded="+Util::llitos(e->torrentMan->getSessionDownloadedSize())+"&"+ - "left="+(e->torrentMan->totalSize-e->torrentMan->getDownloadLength() <= 0 - ? "0" : Util::llitos(e->torrentMan->totalSize-e->torrentMan->getDownloadLength()))+"&"+ + "left="+(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength() <= 0 + ? "0" : Util::llitos(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength()))+"&"+ "compact=1"; if(!event.empty()) { url += string("&")+"event="+event; diff --git a/src/TrackerUpdateCommand.cc b/src/TrackerUpdateCommand.cc index e9c33a0b..c5b1f001 100644 --- a/src/TrackerUpdateCommand.cc +++ b/src/TrackerUpdateCommand.cc @@ -88,7 +88,7 @@ bool TrackerUpdateCommand::execute() { snprintf(ipaddr, sizeof(ipaddr), "%d.%d.%d.%d", ipaddr1, ipaddr2, ipaddr3, ipaddr4); Peer* peer = new Peer(ipaddr, port, e->torrentMan->pieceLength, - e->torrentMan->totalSize); + e->torrentMan->getTotalLength()); if(e->torrentMan->addPeer(peer)) { e->logger->debug("CUID#%d - adding peer %s:%d", cuid, peer->ipaddr.c_str(), peer->port);