renamed TorrentMan::totalSize to TorrentMan::totalLength and added its

accessors.
pull/1/head
Tatsuhiro Tsujikawa 2006-03-31 15:27:21 +00:00
parent 180153592d
commit f02143579b
9 changed files with 23 additions and 20 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);
};

View File

@ -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",

View File

@ -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());

View File

@ -73,6 +73,7 @@ private:
deque<string> 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; }

View File

@ -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;

View File

@ -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);