2006-03-21 14:12:51 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-03-21 14:12:51 +00:00
|
|
|
*
|
|
|
|
* 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
|
2006-09-21 15:31:24 +00:00
|
|
|
* 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.
|
2006-03-21 14:12:51 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "BitfieldMan.h"
|
2006-05-24 15:18:58 +00:00
|
|
|
#include "Util.h"
|
2006-03-21 14:12:51 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
BitfieldMan::BitfieldMan(uint32_t blockLength, uint64_t totalLength)
|
2006-04-06 12:52:16 +00:00
|
|
|
:blockLength(blockLength), totalLength(totalLength), filterBitfield(0),
|
2006-12-24 06:25:21 +00:00
|
|
|
filterEnabled(false), randomizer(0) {
|
2006-03-21 14:12:51 +00:00
|
|
|
if(blockLength > 0 && totalLength > 0) {
|
|
|
|
blocks = totalLength/blockLength+(totalLength%blockLength ? 1 : 0);
|
|
|
|
bitfieldLength = blocks/8+(blocks%8 ? 1 : 0);
|
|
|
|
bitfield = new unsigned char[bitfieldLength];
|
|
|
|
useBitfield = new unsigned char[bitfieldLength];
|
|
|
|
memset(bitfield, 0, bitfieldLength);
|
|
|
|
memset(useBitfield, 0, bitfieldLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
BitfieldMan::BitfieldMan(const BitfieldMan& bitfieldMan):randomizer(0) {
|
2006-03-21 14:12:51 +00:00
|
|
|
blockLength = bitfieldMan.blockLength;
|
|
|
|
totalLength = bitfieldMan.totalLength;
|
|
|
|
blocks = bitfieldMan.blocks;
|
|
|
|
bitfieldLength = bitfieldMan.bitfieldLength;
|
|
|
|
bitfield = new unsigned char[bitfieldLength];
|
|
|
|
useBitfield = new unsigned char[bitfieldLength];
|
|
|
|
memcpy(bitfield, bitfieldMan.bitfield, bitfieldLength);
|
|
|
|
memcpy(useBitfield, bitfieldMan.useBitfield, bitfieldLength);
|
2006-04-06 12:52:16 +00:00
|
|
|
filterEnabled = bitfieldMan.filterEnabled;
|
|
|
|
if(bitfieldMan.filterBitfield) {
|
|
|
|
filterBitfield = new unsigned char[bitfieldLength];
|
|
|
|
memcpy(filterBitfield, bitfieldMan.filterBitfield, bitfieldLength);
|
|
|
|
} else {
|
|
|
|
filterBitfield = 0;
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
this->randomizer = bitfieldMan.randomizer;
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BitfieldMan::~BitfieldMan() {
|
|
|
|
delete [] bitfield;
|
|
|
|
delete [] useBitfield;
|
2006-12-24 15:55:59 +00:00
|
|
|
delete [] filterBitfield;
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
uint32_t BitfieldMan::countSetBit(const unsigned char* bitfield, uint32_t len) const {
|
|
|
|
uint32_t count = 0;
|
|
|
|
uint32_t size = sizeof(uint32_t);
|
|
|
|
for(uint32_t i = 0; i < len/size; i++) {
|
|
|
|
count += Util::countBit(*(uint32_t*)&bitfield[i*size]);
|
2006-05-24 15:18:58 +00:00
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = len-len%size; i < len; i++) {
|
|
|
|
count += Util::countBit((uint32_t)bitfield[i]);
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t BitfieldMan::getNthBitIndex(const unsigned char bitfield, uint32_t nth) const {
|
|
|
|
int32_t index = -1;
|
2006-07-30 12:58:27 +00:00
|
|
|
for(int bs = 7; bs >= 0; bs--) {
|
|
|
|
unsigned char mask = 1 << bs;
|
|
|
|
if(bitfield & mask) {
|
|
|
|
nth--;
|
|
|
|
if(nth == 0) {
|
|
|
|
index = 7-bs;
|
|
|
|
break;
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t
|
2006-07-30 12:58:27 +00:00
|
|
|
BitfieldMan::getMissingIndexRandomly(const unsigned char* bitfield,
|
2006-12-24 15:55:59 +00:00
|
|
|
uint32_t bitfieldLength) const
|
2006-07-30 12:58:27 +00:00
|
|
|
{
|
2006-12-24 15:55:59 +00:00
|
|
|
uint32_t byte = (int32_t)(((double)bitfieldLength)*
|
|
|
|
randomizer->getRandomNumber()/
|
|
|
|
(randomizer->getMaxRandomNumber()+1.0));
|
2006-05-24 15:18:58 +00:00
|
|
|
|
2006-09-19 14:52:59 +00:00
|
|
|
unsigned char lastMask = 0;
|
2007-01-08 00:13:25 +00:00
|
|
|
// the number of bytes in the last byte of bitfield
|
2006-12-24 15:55:59 +00:00
|
|
|
uint32_t lastByteLength = totalLength%(blockLength*8);
|
2007-01-08 00:13:25 +00:00
|
|
|
// the number of block in the last byte of bitfield
|
2006-12-24 15:55:59 +00:00
|
|
|
uint32_t lastBlockCount = DIV_FLOOR(lastByteLength, blockLength);
|
|
|
|
for(uint32_t i = 0; i < lastBlockCount; i++) {
|
2006-09-19 14:52:59 +00:00
|
|
|
lastMask >>= 1;
|
|
|
|
lastMask |= 0x80;
|
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-09-19 14:52:59 +00:00
|
|
|
unsigned char mask;
|
|
|
|
if(byte == bitfieldLength-1) {
|
|
|
|
mask = lastMask;
|
|
|
|
} else {
|
|
|
|
mask = 0xff;
|
|
|
|
}
|
2006-07-30 12:58:27 +00:00
|
|
|
if(bitfield[byte]&mask) {
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t index = byte*8+getNthBitIndex(bitfield[byte], 1);
|
2006-07-30 12:58:27 +00:00
|
|
|
return index;
|
2006-05-24 15:18:58 +00:00
|
|
|
}
|
2006-07-30 12:58:27 +00:00
|
|
|
byte++;
|
|
|
|
if(byte == bitfieldLength) {
|
|
|
|
byte = 0;
|
2006-05-24 15:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
bool BitfieldMan::hasMissingPiece(const unsigned char* peerBitfield, uint32_t length) const {
|
2006-05-24 15:18:58 +00:00
|
|
|
if(bitfieldLength != length) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-07-30 12:58:27 +00:00
|
|
|
bool retval = false;
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-07-30 12:58:27 +00:00
|
|
|
unsigned char temp = peerBitfield[i] & ~bitfield[i];
|
2006-05-24 15:18:58 +00:00
|
|
|
if(filterEnabled) {
|
2006-07-30 12:58:27 +00:00
|
|
|
temp &= filterBitfield[i];
|
2006-05-24 15:18:58 +00:00
|
|
|
}
|
2006-07-30 12:58:27 +00:00
|
|
|
if(temp&0xff) {
|
2006-05-24 15:18:58 +00:00
|
|
|
retval = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t BitfieldMan::getMissingIndex(const unsigned char* peerBitfield, uint32_t length) const {
|
2006-03-21 14:12:51 +00:00
|
|
|
if(bitfieldLength != length) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
unsigned char* tempBitfield = new unsigned char[bitfieldLength];
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-03-21 14:12:51 +00:00
|
|
|
tempBitfield[i] = peerBitfield[i] & ~bitfield[i];
|
2006-04-06 12:52:16 +00:00
|
|
|
if(filterEnabled) {
|
|
|
|
tempBitfield[i] &= filterBitfield[i];
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t index = getMissingIndexRandomly(tempBitfield, bitfieldLength);
|
2006-03-23 10:47:25 +00:00
|
|
|
delete [] tempBitfield;
|
2006-03-21 14:12:51 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t BitfieldMan::getMissingUnusedIndex(const unsigned char* peerBitfield, uint32_t length) const {
|
2006-03-21 14:12:51 +00:00
|
|
|
if(bitfieldLength != length) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
unsigned char* tempBitfield = new unsigned char[bitfieldLength];
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-03-21 14:12:51 +00:00
|
|
|
tempBitfield[i] = peerBitfield[i] & ~bitfield[i] & ~useBitfield[i];
|
2006-04-06 12:52:16 +00:00
|
|
|
if(filterEnabled) {
|
|
|
|
tempBitfield[i] &= filterBitfield[i];
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t index = getMissingIndexRandomly(tempBitfield, bitfieldLength);
|
2006-03-23 10:47:25 +00:00
|
|
|
delete [] tempBitfield;
|
2006-03-21 14:12:51 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t BitfieldMan::getFirstMissingUnusedIndex(const unsigned char* peerBitfield, uint32_t length) const {
|
2006-03-21 14:12:51 +00:00
|
|
|
if(bitfieldLength != length) {
|
|
|
|
return -1;
|
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-03-21 14:12:51 +00:00
|
|
|
unsigned char bit = peerBitfield[i] & ~bitfield[i] & ~useBitfield[i];
|
2006-04-06 12:52:16 +00:00
|
|
|
if(filterEnabled) {
|
|
|
|
bit &= filterBitfield[i];
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
for(int bs = 7; bs >= 0 && i*8+7-bs < blocks; bs--) {
|
|
|
|
unsigned char mask = 1 << bs;
|
|
|
|
if(bit & mask) {
|
|
|
|
return i*8+7-bs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t BitfieldMan::getFirstMissingUnusedIndex() const {
|
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-03-21 14:12:51 +00:00
|
|
|
unsigned char bit = ~bitfield[i] & ~useBitfield[i];
|
2006-04-06 12:52:16 +00:00
|
|
|
if(filterEnabled) {
|
|
|
|
bit &= filterBitfield[i];
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
for(int bs = 7; bs >= 0 && i*8+7-bs < blocks; bs--) {
|
|
|
|
unsigned char mask = 1 << bs;
|
|
|
|
if(bit & mask) {
|
|
|
|
return i*8+7-bs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t BitfieldMan::getMissingIndex() const {
|
2006-05-21 16:19:17 +00:00
|
|
|
unsigned char* tempBitfield = new unsigned char[bitfieldLength];
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-05-21 16:19:17 +00:00
|
|
|
tempBitfield[i] = ~bitfield[i];
|
|
|
|
if(filterEnabled) {
|
|
|
|
tempBitfield[i] &= filterBitfield[i];
|
|
|
|
}
|
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t index = getMissingIndexRandomly(tempBitfield, bitfieldLength);
|
2006-05-21 16:19:17 +00:00
|
|
|
delete [] tempBitfield;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t BitfieldMan::getMissingUnusedIndex() const {
|
2006-09-19 14:52:59 +00:00
|
|
|
unsigned char* tempBitfield = new unsigned char[bitfieldLength];
|
|
|
|
memset(tempBitfield, 0xff, bitfieldLength);
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t index = getMissingUnusedIndex(tempBitfield, bitfieldLength);
|
2006-09-19 14:52:59 +00:00
|
|
|
delete [] tempBitfield;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
// [startIndex, endIndex)
|
|
|
|
class Range {
|
|
|
|
public:
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t startIndex;
|
|
|
|
int32_t endIndex;
|
|
|
|
Range(int32_t startIndex = 0, int32_t endIndex = 0):startIndex(startIndex),
|
|
|
|
endIndex(endIndex) {}
|
2006-09-19 14:52:59 +00:00
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
uint32_t getSize() const {
|
2006-09-19 14:52:59 +00:00
|
|
|
return endIndex-startIndex;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t getMidIndex() const {
|
2006-09-19 14:52:59 +00:00
|
|
|
return (endIndex-startIndex)/2+startIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const Range& range) const {
|
|
|
|
return getSize() < range.getSize();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t BitfieldMan::getStartIndex(int32_t index) const {
|
|
|
|
while(index < (int32_t)blocks &&
|
2006-09-19 14:52:59 +00:00
|
|
|
(isUseBitSet(index) || isBitSet(index))) {
|
|
|
|
index++;
|
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
if((int32_t)blocks <= index) {
|
2006-09-19 14:52:59 +00:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t BitfieldMan::getEndIndex(int32_t index) const {
|
|
|
|
while(index < (int32_t)blocks &&
|
2006-09-19 14:52:59 +00:00
|
|
|
(!isUseBitSet(index) && !isBitSet(index))) {
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t BitfieldMan::getSparseMissingUnusedIndex() const {
|
2006-09-19 14:52:59 +00:00
|
|
|
Range maxRange;
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t index = 0;
|
|
|
|
uint32_t blocks = countBlock();
|
2006-09-19 14:52:59 +00:00
|
|
|
Range currentRange;
|
2006-12-24 15:55:59 +00:00
|
|
|
while(index < (int32_t)blocks) {
|
2006-09-19 14:52:59 +00:00
|
|
|
currentRange.startIndex = getStartIndex(index);
|
|
|
|
if(currentRange.startIndex == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
currentRange.endIndex = getEndIndex(currentRange.startIndex);
|
|
|
|
if(maxRange < currentRange) {
|
|
|
|
maxRange = currentRange;
|
|
|
|
}
|
|
|
|
index = currentRange.endIndex;
|
|
|
|
}
|
|
|
|
if(maxRange.getSize()) {
|
|
|
|
if(maxRange.startIndex == 0) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return maxRange.getMidIndex();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-22 16:21:11 +00:00
|
|
|
BlockIndexes BitfieldMan::getAllMissingIndexes() const {
|
|
|
|
BlockIndexes missingIndexes;
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-03-21 14:12:51 +00:00
|
|
|
unsigned char bit = ~bitfield[i];
|
2006-04-06 12:52:16 +00:00
|
|
|
if(filterEnabled) {
|
|
|
|
bit &= filterBitfield[i];
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
for(int bs = 7; bs >= 0 && i*8+7-bs < blocks; bs--) {
|
|
|
|
unsigned char mask = 1 << bs;
|
|
|
|
if(bit & mask) {
|
|
|
|
missingIndexes.push_back(i*8+7-bs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return missingIndexes;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
BlockIndexes BitfieldMan::getAllMissingIndexes(const unsigned char* peerBitfield, uint32_t peerBitfieldLength) const {
|
2006-05-24 15:18:58 +00:00
|
|
|
BlockIndexes missingIndexes;
|
|
|
|
if(bitfieldLength != peerBitfieldLength) {
|
|
|
|
return missingIndexes;
|
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-05-24 15:18:58 +00:00
|
|
|
unsigned char bit = peerBitfield[i] & ~bitfield[i];
|
|
|
|
if(filterEnabled) {
|
|
|
|
bit &= filterBitfield[i];
|
|
|
|
}
|
|
|
|
for(int bs = 7; bs >= 0 && i*8+7-bs < blocks; bs--) {
|
|
|
|
unsigned char mask = 1 << bs;
|
|
|
|
if(bit & mask) {
|
|
|
|
missingIndexes.push_back(i*8+7-bs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return missingIndexes;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
uint32_t BitfieldMan::countMissingBlock() const {
|
2006-04-06 12:52:16 +00:00
|
|
|
if(filterEnabled) {
|
|
|
|
unsigned char* temp = new unsigned char[bitfieldLength];
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-04-06 12:52:16 +00:00
|
|
|
temp[i] = bitfield[i]&filterBitfield[i];
|
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
uint32_t count = countSetBit(filterBitfield, bitfieldLength)-
|
2006-04-06 12:52:16 +00:00
|
|
|
countSetBit(temp, bitfieldLength);
|
|
|
|
delete [] temp;
|
|
|
|
return count;
|
|
|
|
} else {
|
|
|
|
return blocks-countSetBit(bitfield, bitfieldLength);
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
uint32_t BitfieldMan::countBlock() const {
|
2006-04-06 12:52:16 +00:00
|
|
|
if(filterEnabled) {
|
|
|
|
return countSetBit(filterBitfield, bitfieldLength);
|
|
|
|
} else {
|
|
|
|
return blocks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
bool BitfieldMan::setBitInternal(unsigned char* bitfield, int32_t index, bool on) {
|
|
|
|
if((int32_t)blocks <= index) { return false; }
|
2006-03-21 14:12:51 +00:00
|
|
|
unsigned char mask = 128 >> index%8;
|
2006-04-06 12:52:16 +00:00
|
|
|
if(on) {
|
|
|
|
bitfield[index/8] |= mask;
|
|
|
|
} else {
|
|
|
|
bitfield[index/8] &= ~mask;
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
bool BitfieldMan::setUseBit(int32_t index) {
|
2006-04-06 12:52:16 +00:00
|
|
|
return setBitInternal(useBitfield, index, true);
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
bool BitfieldMan::unsetUseBit(int32_t index) {
|
2006-04-06 12:52:16 +00:00
|
|
|
return setBitInternal(useBitfield, index, false);
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
bool BitfieldMan::setBit(int32_t index) {
|
2006-04-06 12:52:16 +00:00
|
|
|
return setBitInternal(bitfield, index, true);
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2006-04-06 12:52:16 +00:00
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
bool BitfieldMan::unsetBit(int32_t index) {
|
2006-04-06 12:52:16 +00:00
|
|
|
return setBitInternal(bitfield, index, false);
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BitfieldMan::isAllBitSet() const {
|
2006-04-06 12:52:16 +00:00
|
|
|
if(filterEnabled) {
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-04-06 12:52:16 +00:00
|
|
|
if((bitfield[i]&filterBitfield[i]) != filterBitfield[i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength-1; i++) {
|
2006-04-06 12:52:16 +00:00
|
|
|
if(bitfield[i] != 0xff) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unsigned char b = ~((128 >> (blocks-1)%8)-1);
|
|
|
|
if(bitfield[bitfieldLength-1] != b) {
|
2006-03-21 14:12:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-04-06 12:52:16 +00:00
|
|
|
return true;
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
bool BitfieldMan::isBitSetInternal(const unsigned char* bitfield, int32_t index) const {
|
|
|
|
if(index < 0 || (int32_t)blocks <= index) { return false; }
|
2006-03-21 14:12:51 +00:00
|
|
|
unsigned char mask = 128 >> index%8;
|
|
|
|
return (bitfield[index/8] & mask) != 0;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
bool BitfieldMan::isBitSet(int32_t index) const {
|
2006-03-21 14:12:51 +00:00
|
|
|
return isBitSetInternal(bitfield, index);
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
bool BitfieldMan::isUseBitSet(int32_t index) const {
|
2006-03-21 14:12:51 +00:00
|
|
|
return isBitSetInternal(useBitfield, index);
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
void BitfieldMan::setBitfield(const unsigned char* bitfield, uint32_t bitfieldLength) {
|
2006-03-21 14:12:51 +00:00
|
|
|
if(this->bitfieldLength != bitfieldLength) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(this->bitfield, bitfield, this->bitfieldLength);
|
|
|
|
memset(this->useBitfield, 0, this->bitfieldLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldMan::clearAllBit() {
|
|
|
|
memset(this->bitfield, 0, this->bitfieldLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldMan::setAllBit() {
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < blocks; i++) {
|
2006-03-21 14:12:51 +00:00
|
|
|
setBit(i);
|
|
|
|
}
|
|
|
|
}
|
2006-04-06 12:52:16 +00:00
|
|
|
|
2006-09-19 14:52:59 +00:00
|
|
|
void BitfieldMan::clearAllUseBit() {
|
|
|
|
memset(this->useBitfield, 0, this->bitfieldLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldMan::setAllUseBit() {
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < blocks; i++) {
|
2006-09-19 14:52:59 +00:00
|
|
|
setUseBit(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
bool BitfieldMan::setFilterBit(int32_t index) {
|
2006-04-06 12:52:16 +00:00
|
|
|
return setBitInternal(filterBitfield, index, true);
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
void BitfieldMan::addFilter(int64_t offset, uint64_t length) {
|
2006-04-06 12:52:16 +00:00
|
|
|
if(!filterBitfield) {
|
|
|
|
filterBitfield = new unsigned char[bitfieldLength];
|
|
|
|
memset(filterBitfield, 0, bitfieldLength);
|
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
int32_t startBlock = offset/blockLength;
|
|
|
|
int32_t endBlock = (offset+length-1)/blockLength;
|
|
|
|
for(int i = startBlock; i <= endBlock && i < (int32_t)blocks; i++) {
|
2006-04-06 12:52:16 +00:00
|
|
|
setFilterBit(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldMan::enableFilter() {
|
|
|
|
filterEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldMan::disableFilter() {
|
|
|
|
filterEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BitfieldMan::clearFilter() {
|
|
|
|
if(filterBitfield) {
|
|
|
|
delete [] filterBitfield;
|
|
|
|
filterBitfield = 0;
|
|
|
|
}
|
|
|
|
filterEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BitfieldMan::isFilterEnabled() const {
|
|
|
|
return filterEnabled;
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
uint64_t BitfieldMan::getFilteredTotalLength() const {
|
2006-04-06 12:52:16 +00:00
|
|
|
if(!filterBitfield) {
|
|
|
|
return 0;
|
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
uint32_t filteredBlocks = countSetBit(filterBitfield, bitfieldLength);
|
2006-04-06 12:52:16 +00:00
|
|
|
if(filteredBlocks == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(isBitSetInternal(filterBitfield, blocks-1)) {
|
2006-12-24 15:55:59 +00:00
|
|
|
return ((uint64_t)filteredBlocks-1)*blockLength+getLastBlockLength();
|
2006-04-06 12:52:16 +00:00
|
|
|
} else {
|
2006-12-24 15:55:59 +00:00
|
|
|
return ((uint64_t)filteredBlocks)*blockLength;
|
2006-04-06 12:52:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
uint64_t BitfieldMan::getCompletedLength(bool useFilter) const {
|
2006-04-06 12:52:16 +00:00
|
|
|
unsigned char* temp = new unsigned char[bitfieldLength];
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
if(useFilter) {
|
2006-12-24 15:55:59 +00:00
|
|
|
for(uint32_t i = 0; i < bitfieldLength; i++) {
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
temp[i] = bitfield[i];
|
|
|
|
if(filterEnabled) {
|
|
|
|
temp[i] &= filterBitfield[i];
|
|
|
|
}
|
2006-04-06 12:52:16 +00:00
|
|
|
}
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
} else {
|
|
|
|
memcpy(temp, bitfield, bitfieldLength);
|
2006-04-06 12:52:16 +00:00
|
|
|
}
|
2006-12-24 15:55:59 +00:00
|
|
|
uint32_t completedBlocks = countSetBit(temp, bitfieldLength);
|
|
|
|
uint64_t completedLength = 0;
|
2006-04-06 12:52:16 +00:00
|
|
|
if(completedBlocks == 0) {
|
|
|
|
completedLength = 0;
|
|
|
|
} else {
|
|
|
|
if(isBitSetInternal(temp, blocks-1)) {
|
2006-12-24 15:55:59 +00:00
|
|
|
completedLength = ((uint64_t)completedBlocks-1)*blockLength+getLastBlockLength();
|
2006-04-06 12:52:16 +00:00
|
|
|
} else {
|
2006-12-24 15:55:59 +00:00
|
|
|
completedLength = ((uint64_t)completedBlocks)*blockLength;
|
2006-04-06 12:52:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delete [] temp;
|
|
|
|
return completedLength;
|
|
|
|
}
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
uint64_t BitfieldMan::getCompletedLength() const {
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
return getCompletedLength(false);
|
|
|
|
}
|
|
|
|
|
2006-12-24 15:55:59 +00:00
|
|
|
uint64_t BitfieldMan::getFilteredCompletedLength() const {
|
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To divide TorrentMan into 6 classes: BtContext, BtRuntime,
PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile
* src/TrackerWatcherComand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.cc: Use pieceStorage, btRuntime
* src/PeerAbstractCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerAbstractCommand.cc: Use btRuntime.
* src/BtContextAwareCommand.h: New class.
* src/FileEntry.h: Added accessor methods for following
variables.
(path): Made private.
(length): Made private.
(offset): Made private.
(extracted): Made private.
(requested): Made private.
(FileEntries): New definition.
(FileEntryHandle): New definition.
* src/FileEntry.cc: New file.
* src/HaveEraseCommand.h: Made subclass of
BtContextAwareCommand.
* src/HaveEraseCommand.cc: Use btRuntime, pieceStorage.
* src/PeerChokeCommand.h: Made subclass of
BtContextAwareCommand.
* src/PeerChokeCommand.cc: Use btRuntime, peerStorage,
pieceStorage.
* src/PieceStorage.h: New file.
* src/PeerInteractionCommand.h: Use btContext.
* src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage,
btRuntime.
* src/DefaultBtProgressInfoFile.h: New file.
* src/DefaultBtProgressInfoFile.cc: New file.
* src/File.cc
(Util.h): New include.
(mkdirs): New function.
* src/MultiDiskAdaptor.h
(mkdir): New function.
* src/PeerListProcessor.h
(Peers): Removed.
* src/PeerInteraction.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(btAnnounce): New variable.
(getTorrentMan): Removed.
(getBtContext): New function.
* src/PeerInteraction.cc: Use btContext, peerStorage,
pieceStorage,
btAnnounce.
* src/HandshakeMessage.h
(TorrentMan.h): Removed.
* src/HandshakeMessage.cc: Use btContext.
* src/DefaultBtAnnounce.cc: New file.
* src/MultiDiskWriter.cc: Use the accessor methods of FileEntry.
* src/DefaultPieceStorage.cc: New file.
* src/DefaultBtContext.h: New file.
* src/TorrentRequestInfo.cc: Use btContext, pieceStorage.
Use the accessor methods of FileEntry.
* src/CookieBox.cc: Updated to use Util::slice().
* src/PieceMessage.cc: Use btContext, pieceStorage.
* src/common.h (SharedHandle.h): New include.
* src/PeerMessage.cc (PeerMessage): Added btContext,
peerStorage,
pieceStorage.
* src/TorrentAutoSaveCommand.h: Made subclass of
BtContextAwareCommand.
* src/DiskAdaptor.h
(topDir): Removed.
(getFileEntryFromPath): Changed the return type to
FileEntryHandle.
(setTopDir): Removed.
(getTopDir): Removed.
* src/BtContext.h: New file.
* src/DefaultPeerStorage.h: New file.
* src/PieceMessage.h (TorrentMan.h): Removed.
* src/RequestMessage.h (TorrentMan.h): Removed.
* src/TorrentDownloadEngine.h
(uploadLength): New variable.
(btContext): New variable.
(btRuntime): New variable.
(pieceStorage): New variable.
(peerStorage): New variable.
(btAnnounce): New variable.
(btProgressInfoFile): New variable.
(torrentMan): Removed.
(setBtContext): New function.
* src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime,
pieceStorage,
peerStorage, btAnnounce, btProgressInfoFile.
* src/Piece.h
(toString): New function.
(Pieces): New type definition.
* src/Peer.h
(active): New variable.
(Peer): Added active.
(activate): Set active to true.
(deactivate): Set active to false.
(isActive): New function.
(Peers): New type definition.
* src/DirectDiskAdaptor.cc
(getFilePath): Use the accessor methods of FileEntry.
* src/TorrentConsoleDownloadEngine.h
(afterEachIteration): New function.
* src/TorrentConsoleDownloadEngine.cc
(haltRequested): New variable.
(sendStatistics): Use pieceStorage, btRuntime.
(afterEachIteration): New function.
* src/AnnounceList: AnnounceTier->AnnounceTierHandle.
* src/Directry.h
(Directory): New function.
(DirectoryHandle): New type definition.
* src/BtProgressInfoFile.h: New file.
* src/RequestMessage.cc: Use pieceStorage.
* src/BtRuntime.h: New file.
* src/DefaultBtContext.cc: New file.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/BitfieldMan.h
(getCompletedLength): New function(private).
(getCompletedLength): New function.
(getFilteredCompletedLength): New function.
* src/MultiDiskAdaptor.cc
(mkdir): New function.
(openFile): Call mkdir().
(initAndOpenFile): Call mkdir().
* src/CancelMessage.h
(TorrentMan.h): Removed.
* src/RejectMessage.h
(TorrentMan.h): Removed.
* src/DownloadEngineFactory.cc
(DefaultPieceStorage.h): New include.
(DefaultPeerStorage.h): New include.
(DefaultBtAnnounce.h): New include.
(DefaultBtProgressInfoFile.h): New include.
(newTorrentConsoleEngine): Rewritten.
* src/ShareRatioSeedCriteria.h
(torrentMan): Removed.
(btContext): New variable.
(peerStorage): New variable.
(btRuntime): New variable.
(evaluate): Use btContext, btRuntime, peerStorage.
* src/AnnounceTier.h: New file.
* src/BtAnnounce.h: New file.
* src/BtRegistry.h: New file.
* src/PeerInitiateConnectionCommand.h: Added btContext.
* src/PeerConnection.h (TorrentMan.h): Removed.
* src/PeerMessageFactory.cc: Use btContext, pieceStorage.
* src/Util.h
(slice): Added an argument.
* src/Util.cc
(slice): Added an argument to control whether trim is made or
not.
* src/PeerStorage.h: New file.
* src/BtRegistry.cc: New file.
* src/TrackerUpdateCommand.h: Made subclass of
BtContextAwareCommand.
* src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry.
* src/MultiDiskWriter.h: FileEntry -> FileEntryHandle
* src/PeerListenCommand.cc: Use btRuntime, peerStorage,
btContext.
* src/TorrentRequestInfo.h
(e): Removed.
(showFileEntry): Added an argument.
(getDownloadEngine): Return 0.
* src/DefaultBtAnnounce.h: New file.
* src/TorrentAutoSaveCommand.cc: Use btRuntime,
btProgressInfoFile.
* src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce,
* src/PeerMessageFactory.h
(btContext): New variable.
(pieceStorage): New variable.
* src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage,
btContext,
btAnnounce.
* src/DiskAdaptor.cc
(DiskAdaptor): Removed topDir.
(~DiskAdaptor): Removed topDir.
* src/PeerListenCommand.h: Made subclass of
BtContextAwareCommand.
* src/SeedCheckCommand.h: Made subclass of
BtContextAwareCommand.
* src/File.h (mkdirs): New function.
* src/DefaultPeerStorage): New file.
* src/DownloadEngineFactory.h
(newTorrentConsoleEngine): Use btContext.
* src/BtContextAwareCommand.cc: New file.
* src/PeerInitiateConnectionCommand.cc: Use btRuntime,
peerStorage.
* src/PeerMessage.h
(btContext): New variable.
(peerStorage): New variable.
(pieceStorage): New variable.
(setBtContext): New function.
* src/Directry.cc
(Directory): New function.
(createDir): Do nothing if name.size() == 0.
* src/AnnounceList.h
(AnnounceTier): Removed.
(AnnounceTiers): Removed.
* src/DefaultPieceStorage.h: New file.
* src/Piece.cc (toString): New function.
To fix typo:
* src/main.cc (showVersion): Fixed typo.
To fix compile warning:
* src/DelegatingPeerListProcessor.cc
(canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
|
|
|
return getCompletedLength(true);
|
|
|
|
}
|