mirror of https://github.com/aria2/aria2
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Type clarification * src/PeerSessionResource.{h, cc} * src/DefaultPieceStorage.{h, cc} * src/Peer.{h, cc} * test/PeerSessionResourceTest.cc Use div function * src/BtPieceMessage.cc (erasePieceOnDisk)pull/1/head
parent
2555098ecd
commit
ca3f6e57f3
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Type clarification
|
||||||
|
* src/PeerSessionResource.{h, cc}
|
||||||
|
* src/DefaultPieceStorage.{h, cc}
|
||||||
|
* src/Peer.{h, cc}
|
||||||
|
* test/PeerSessionResourceTest.cc
|
||||||
|
|
||||||
|
Use div function
|
||||||
|
* src/BtPieceMessage.cc (erasePieceOnDisk)
|
||||||
|
|
||||||
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-03-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Type clarification
|
Type clarification
|
||||||
|
|
|
@ -223,18 +223,17 @@ void BtPieceMessage::onWrongPiece(const PieceHandle& piece) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtPieceMessage::erasePieceOnDisk(const PieceHandle& piece) {
|
void BtPieceMessage::erasePieceOnDisk(const PieceHandle& piece) {
|
||||||
int32_t BUFSIZE = 4096;
|
size_t BUFSIZE = 4096;
|
||||||
unsigned char buf[BUFSIZE];
|
unsigned char buf[BUFSIZE];
|
||||||
memset(buf, 0, BUFSIZE);
|
memset(buf, 0, BUFSIZE);
|
||||||
int64_t offset =
|
off_t offset = (off_t)piece->getIndex()*btContext->getPieceLength();
|
||||||
((int64_t)piece->getIndex())*btContext->getPieceLength();
|
div_t res = div(piece->getLength(), BUFSIZE);
|
||||||
for(int32_t i = 0; i < piece->getLength()/BUFSIZE; i++) {
|
for(int i = 0; i < res.quot; i++) {
|
||||||
pieceStorage->getDiskAdaptor()->writeData(buf, BUFSIZE, offset);
|
pieceStorage->getDiskAdaptor()->writeData(buf, BUFSIZE, offset);
|
||||||
offset += BUFSIZE;
|
offset += BUFSIZE;
|
||||||
}
|
}
|
||||||
int32_t r = piece->getLength()%BUFSIZE;
|
if(res.rem > 0) {
|
||||||
if(r > 0) {
|
pieceStorage->getDiskAdaptor()->writeData(buf, res.rem, offset);
|
||||||
pieceStorage->getDiskAdaptor()->writeData(buf, r, offset);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ bool DefaultPieceStorage::getMissingFastPieceIndex(size_t& index,
|
||||||
if(peer->isFastExtensionEnabled() && peer->countPeerAllowedIndexSet() > 0) {
|
if(peer->isFastExtensionEnabled() && peer->countPeerAllowedIndexSet() > 0) {
|
||||||
BitfieldMan tempBitfield(bitfieldMan->getBlockLength(),
|
BitfieldMan tempBitfield(bitfieldMan->getBlockLength(),
|
||||||
bitfieldMan->getTotalLength());
|
bitfieldMan->getTotalLength());
|
||||||
for(std::deque<int32_t>::const_iterator itr = peer->getPeerAllowedIndexSet().begin();
|
for(std::deque<size_t>::const_iterator itr = peer->getPeerAllowedIndexSet().begin();
|
||||||
itr != peer->getPeerAllowedIndexSet().end(); itr++) {
|
itr != peer->getPeerAllowedIndexSet().end(); itr++) {
|
||||||
if(!bitfieldMan->isBitSet(index) && peer->hasPiece(*itr)) {
|
if(!bitfieldMan->isBitSet(index) && peer->hasPiece(*itr)) {
|
||||||
tempBitfield.setBit(*itr);
|
tempBitfield.setBit(*itr);
|
||||||
|
|
|
@ -60,7 +60,7 @@ public:
|
||||||
|
|
||||||
int32_t getCuid() const { return cuid; }
|
int32_t getCuid() const { return cuid; }
|
||||||
|
|
||||||
int32_t getIndex() const { return index; }
|
size_t getIndex() const { return index; }
|
||||||
|
|
||||||
const Time& getRegisteredTime() const { return registeredTime; }
|
const Time& getRegisteredTime() const { return registeredTime; }
|
||||||
};
|
};
|
||||||
|
|
40
src/Peer.cc
40
src/Peer.cc
|
@ -96,7 +96,7 @@ bool Peer::unused() const
|
||||||
return _cuid == 0;
|
return _cuid == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::allocateSessionResource(int32_t pieceLength, int64_t totalLength)
|
void Peer::allocateSessionResource(size_t pieceLength, uint64_t totalLength)
|
||||||
{
|
{
|
||||||
delete _res;
|
delete _res;
|
||||||
_res = new PeerSessionResource(pieceLength, totalLength);
|
_res = new PeerSessionResource(pieceLength, totalLength);
|
||||||
|
@ -218,13 +218,13 @@ void Peer::snubbing(bool b)
|
||||||
_res->snubbing(b);
|
_res->snubbing(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::updateUploadLength(int32_t bytes)
|
void Peer::updateUploadLength(size_t bytes)
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
_res->updateUploadLength(bytes);
|
_res->updateUploadLength(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::updateDownloadLength(int32_t bytes)
|
void Peer::updateDownloadLength(size_t bytes)
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
_res->updateDownloadLength(bytes);
|
_res->updateDownloadLength(bytes);
|
||||||
|
@ -238,49 +238,49 @@ void Peer::updateSeeder()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::updateBitfield(int32_t index, int32_t operation) {
|
void Peer::updateBitfield(size_t index, int operation) {
|
||||||
assert(_res);
|
assert(_res);
|
||||||
_res->updateBitfield(index, operation);
|
_res->updateBitfield(index, operation);
|
||||||
updateSeeder();
|
updateSeeder();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Peer::calculateUploadSpeed()
|
unsigned int Peer::calculateUploadSpeed()
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->getPeerStat().calculateUploadSpeed();
|
return _res->getPeerStat().calculateUploadSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Peer::calculateUploadSpeed(const struct timeval& now)
|
unsigned int Peer::calculateUploadSpeed(const struct timeval& now)
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->getPeerStat().calculateUploadSpeed(now);
|
return _res->getPeerStat().calculateUploadSpeed(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Peer::calculateDownloadSpeed()
|
unsigned int Peer::calculateDownloadSpeed()
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->getPeerStat().calculateDownloadSpeed();
|
return _res->getPeerStat().calculateDownloadSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Peer::calculateDownloadSpeed(const struct timeval& now)
|
unsigned int Peer::calculateDownloadSpeed(const struct timeval& now)
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->getPeerStat().calculateDownloadSpeed(now);
|
return _res->getPeerStat().calculateDownloadSpeed(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t Peer::getSessionUploadLength() const
|
uint64_t Peer::getSessionUploadLength() const
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->uploadLength();
|
return _res->uploadLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t Peer::getSessionDownloadLength() const
|
uint64_t Peer::getSessionDownloadLength() const
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->downloadLength();
|
return _res->downloadLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::setBitfield(const unsigned char* bitfield, int32_t bitfieldLength)
|
void Peer::setBitfield(const unsigned char* bitfield, size_t bitfieldLength)
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
_res->setBitfield(bitfield, bitfieldLength);
|
_res->setBitfield(bitfield, bitfieldLength);
|
||||||
|
@ -293,7 +293,7 @@ const unsigned char* Peer::getBitfield() const
|
||||||
return _res->getBitfield();
|
return _res->getBitfield();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Peer::getBitfieldLength() const
|
size_t Peer::getBitfieldLength() const
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->getBitfieldLength();
|
return _res->getBitfieldLength();
|
||||||
|
@ -304,7 +304,7 @@ bool Peer::shouldBeChoking() const {
|
||||||
return _res->shouldBeChoking();
|
return _res->shouldBeChoking();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Peer::hasPiece(int32_t index) const {
|
bool Peer::hasPiece(size_t index) const {
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->hasPiece(index);
|
return _res->hasPiece(index);
|
||||||
}
|
}
|
||||||
|
@ -327,31 +327,31 @@ size_t Peer::countPeerAllowedIndexSet() const
|
||||||
return _res->peerAllowedIndexSet().size();
|
return _res->peerAllowedIndexSet().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::deque<int32_t>& Peer::getPeerAllowedIndexSet() const
|
const std::deque<size_t>& Peer::getPeerAllowedIndexSet() const
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->peerAllowedIndexSet();
|
return _res->peerAllowedIndexSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Peer::isInPeerAllowedIndexSet(int32_t index) const
|
bool Peer::isInPeerAllowedIndexSet(size_t index) const
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->peerAllowedIndexSetContains(index);
|
return _res->peerAllowedIndexSetContains(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::addPeerAllowedIndex(int32_t index)
|
void Peer::addPeerAllowedIndex(size_t index)
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
_res->addPeerAllowedIndex(index);
|
_res->addPeerAllowedIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Peer::isInAmAllowedIndexSet(int32_t index) const
|
bool Peer::isInAmAllowedIndexSet(size_t index) const
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->amAllowedIndexSetContains(index);
|
return _res->amAllowedIndexSetContains(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::addAmAllowedIndex(int32_t index)
|
void Peer::addAmAllowedIndex(size_t index)
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
_res->addAmAllowedIndex(index);
|
_res->addAmAllowedIndex(index);
|
||||||
|
@ -363,13 +363,13 @@ void Peer::setAllBitfield() {
|
||||||
_seeder = true;
|
_seeder = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peer::updateLatency(int32_t latency)
|
void Peer::updateLatency(unsigned int latency)
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
_res->updateLatency(latency);
|
_res->updateLatency(latency);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t Peer::getLatency() const
|
unsigned int Peer::getLatency() const
|
||||||
{
|
{
|
||||||
assert(_res);
|
assert(_res);
|
||||||
return _res->latency();
|
return _res->latency();
|
||||||
|
|
40
src/Peer.h
40
src/Peer.h
|
@ -105,7 +105,7 @@ public:
|
||||||
|
|
||||||
bool isGood() const;
|
bool isGood() const;
|
||||||
|
|
||||||
void allocateSessionResource(int32_t pieceLength, int64_t totalLength);
|
void allocateSessionResource(size_t pieceLength, uint64_t totalLength);
|
||||||
|
|
||||||
void releaseSessionResource();
|
void releaseSessionResource();
|
||||||
|
|
||||||
|
@ -152,39 +152,39 @@ public:
|
||||||
|
|
||||||
void snubbing(bool b);
|
void snubbing(bool b);
|
||||||
|
|
||||||
void updateUploadLength(int32_t bytes);
|
void updateUploadLength(size_t bytes);
|
||||||
|
|
||||||
void updateDownloadLength(int32_t bytes);
|
void updateDownloadLength(size_t bytes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the transfer rate from localhost to remote host.
|
* Returns the transfer rate from localhost to remote host.
|
||||||
*/
|
*/
|
||||||
int32_t calculateUploadSpeed();
|
unsigned int calculateUploadSpeed();
|
||||||
|
|
||||||
int32_t calculateUploadSpeed(const struct timeval& now);
|
unsigned int calculateUploadSpeed(const struct timeval& now);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the transfer rate from remote host to localhost.
|
* Returns the transfer rate from remote host to localhost.
|
||||||
*/
|
*/
|
||||||
int32_t calculateDownloadSpeed();
|
unsigned int calculateDownloadSpeed();
|
||||||
|
|
||||||
int32_t calculateDownloadSpeed(const struct timeval& now);
|
unsigned int calculateDownloadSpeed(const struct timeval& now);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of bytes uploaded to the remote host.
|
* Returns the number of bytes uploaded to the remote host.
|
||||||
*/
|
*/
|
||||||
int64_t getSessionUploadLength() const;
|
uint64_t getSessionUploadLength() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of bytes downloaded from the remote host.
|
* Returns the number of bytes downloaded from the remote host.
|
||||||
*/
|
*/
|
||||||
int64_t getSessionDownloadLength() const;
|
uint64_t getSessionDownloadLength() const;
|
||||||
|
|
||||||
void setBitfield(const unsigned char* bitfield, int32_t bitfieldLength);
|
void setBitfield(const unsigned char* bitfield, size_t bitfieldLength);
|
||||||
|
|
||||||
const unsigned char* getBitfield() const;
|
const unsigned char* getBitfield() const;
|
||||||
|
|
||||||
int32_t getBitfieldLength() const;
|
size_t getBitfieldLength() const;
|
||||||
|
|
||||||
void setAllBitfield();
|
void setAllBitfield();
|
||||||
|
|
||||||
|
@ -192,23 +192,23 @@ public:
|
||||||
* operation = 1: set index-th bit to 1
|
* operation = 1: set index-th bit to 1
|
||||||
* operation = 0: set index-th bit to 0
|
* operation = 0: set index-th bit to 0
|
||||||
*/
|
*/
|
||||||
void updateBitfield(int32_t index, int32_t operation);
|
void updateBitfield(size_t index, int operation);
|
||||||
|
|
||||||
void setFastExtensionEnabled(bool enabled);
|
void setFastExtensionEnabled(bool enabled);
|
||||||
|
|
||||||
bool isFastExtensionEnabled() const;
|
bool isFastExtensionEnabled() const;
|
||||||
|
|
||||||
void addPeerAllowedIndex(int32_t index);
|
void addPeerAllowedIndex(size_t index);
|
||||||
|
|
||||||
bool isInPeerAllowedIndexSet(int32_t index) const;
|
bool isInPeerAllowedIndexSet(size_t index) const;
|
||||||
|
|
||||||
size_t countPeerAllowedIndexSet() const;
|
size_t countPeerAllowedIndexSet() const;
|
||||||
|
|
||||||
const std::deque<int32_t>& getPeerAllowedIndexSet() const;
|
const std::deque<size_t>& getPeerAllowedIndexSet() const;
|
||||||
|
|
||||||
void addAmAllowedIndex(int32_t index);
|
void addAmAllowedIndex(size_t index);
|
||||||
|
|
||||||
bool isInAmAllowedIndexSet(int32_t index) const;
|
bool isInAmAllowedIndexSet(size_t index) const;
|
||||||
|
|
||||||
void setExtendedMessagingEnabled(bool enabled);
|
void setExtendedMessagingEnabled(bool enabled);
|
||||||
|
|
||||||
|
@ -220,11 +220,11 @@ public:
|
||||||
|
|
||||||
bool shouldBeChoking() const;
|
bool shouldBeChoking() const;
|
||||||
|
|
||||||
bool hasPiece(int32_t index) const;
|
bool hasPiece(size_t index) const;
|
||||||
|
|
||||||
void updateLatency(int32_t latency);
|
void updateLatency(unsigned int latency);
|
||||||
|
|
||||||
int32_t getLatency() const;
|
unsigned int getLatency() const;
|
||||||
|
|
||||||
uint8_t getExtensionMessageID(const std::string& name) const;
|
uint8_t getExtensionMessageID(const std::string& name) const;
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
PeerSessionResource::PeerSessionResource(int32_t pieceLength, int64_t totalLength):
|
PeerSessionResource::PeerSessionResource(size_t pieceLength, uint64_t totalLength):
|
||||||
_amChoking(true),
|
_amChoking(true),
|
||||||
_amInterested(false),
|
_amInterested(false),
|
||||||
_peerChoking(true),
|
_peerChoking(true),
|
||||||
|
@ -144,7 +144,7 @@ bool PeerSessionResource::hasAllPieces() const
|
||||||
return _bitfieldMan->isAllBitSet();
|
return _bitfieldMan->isAllBitSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerSessionResource::updateBitfield(int32_t index, int32_t operation)
|
void PeerSessionResource::updateBitfield(size_t index, int operation)
|
||||||
{
|
{
|
||||||
if(operation == 1) {
|
if(operation == 1) {
|
||||||
_bitfieldMan->setBit(index);
|
_bitfieldMan->setBit(index);
|
||||||
|
@ -168,7 +168,7 @@ size_t PeerSessionResource::getBitfieldLength() const
|
||||||
return _bitfieldMan->getBitfieldLength();
|
return _bitfieldMan->getBitfieldLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerSessionResource::hasPiece(int32_t index) const
|
bool PeerSessionResource::hasPiece(size_t index) const
|
||||||
{
|
{
|
||||||
return _bitfieldMan->isBitSet(index);
|
return _bitfieldMan->isBitSet(index);
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ void PeerSessionResource::fastExtensionEnabled(bool b)
|
||||||
_fastExtensionEnabled = b;
|
_fastExtensionEnabled = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::deque<int32_t>& PeerSessionResource::peerAllowedIndexSet() const
|
const std::deque<size_t>& PeerSessionResource::peerAllowedIndexSet() const
|
||||||
{
|
{
|
||||||
return _peerAllowedIndexSet;
|
return _peerAllowedIndexSet;
|
||||||
}
|
}
|
||||||
|
@ -199,31 +199,31 @@ bool PeerSessionResource::indexIncluded(const std::deque<T>& c, T index) const
|
||||||
return std::find(c.begin(), c.end(), index) != c.end();
|
return std::find(c.begin(), c.end(), index) != c.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerSessionResource::addPeerAllowedIndex(int32_t index)
|
void PeerSessionResource::addPeerAllowedIndex(size_t index)
|
||||||
{
|
{
|
||||||
if(!indexIncluded(_peerAllowedIndexSet, index)) {
|
if(!indexIncluded(_peerAllowedIndexSet, index)) {
|
||||||
_peerAllowedIndexSet.push_back(index);
|
_peerAllowedIndexSet.push_back(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerSessionResource::peerAllowedIndexSetContains(int32_t index) const
|
bool PeerSessionResource::peerAllowedIndexSetContains(size_t index) const
|
||||||
{
|
{
|
||||||
return indexIncluded(_peerAllowedIndexSet, index);
|
return indexIncluded(_peerAllowedIndexSet, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::deque<int32_t>& PeerSessionResource::amAllowedIndexSet() const
|
const std::deque<size_t>& PeerSessionResource::amAllowedIndexSet() const
|
||||||
{
|
{
|
||||||
return _amAllowedIndexSet;
|
return _amAllowedIndexSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerSessionResource::addAmAllowedIndex(int32_t index)
|
void PeerSessionResource::addAmAllowedIndex(size_t index)
|
||||||
{
|
{
|
||||||
if(!indexIncluded(_amAllowedIndexSet, index)) {
|
if(!indexIncluded(_amAllowedIndexSet, index)) {
|
||||||
_amAllowedIndexSet.push_back(index);
|
_amAllowedIndexSet.push_back(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerSessionResource::amAllowedIndexSetContains(int32_t index) const
|
bool PeerSessionResource::amAllowedIndexSetContains(size_t index) const
|
||||||
{
|
{
|
||||||
return indexIncluded(_amAllowedIndexSet, index);
|
return indexIncluded(_amAllowedIndexSet, index);
|
||||||
}
|
}
|
||||||
|
@ -281,33 +281,33 @@ PeerStat& PeerSessionResource::getPeerStat()
|
||||||
return _peerStat;
|
return _peerStat;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t PeerSessionResource::latency() const
|
unsigned int PeerSessionResource::latency() const
|
||||||
{
|
{
|
||||||
return _latency;
|
return _latency;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerSessionResource::updateLatency(int32_t latency)
|
void PeerSessionResource::updateLatency(unsigned int latency)
|
||||||
{
|
{
|
||||||
_latency = _latency*0.2+latency*0.8;
|
_latency = _latency*0.2+latency*0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t PeerSessionResource::uploadLength() const
|
uint64_t PeerSessionResource::uploadLength() const
|
||||||
{
|
{
|
||||||
return _uploadLength;
|
return _uploadLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerSessionResource::updateUploadLength(int32_t bytes)
|
void PeerSessionResource::updateUploadLength(size_t bytes)
|
||||||
{
|
{
|
||||||
_peerStat.updateUploadLength(bytes);
|
_peerStat.updateUploadLength(bytes);
|
||||||
_uploadLength += bytes;
|
_uploadLength += bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t PeerSessionResource::downloadLength() const
|
uint64_t PeerSessionResource::downloadLength() const
|
||||||
{
|
{
|
||||||
return _downloadLength;
|
return _downloadLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerSessionResource::updateDownloadLength(int32_t bytes)
|
void PeerSessionResource::updateDownloadLength(size_t bytes)
|
||||||
{
|
{
|
||||||
_peerStat.updateDownloadLength(bytes);
|
_peerStat.updateDownloadLength(bytes);
|
||||||
_downloadLength += bytes;
|
_downloadLength += bytes;
|
||||||
|
|
|
@ -65,21 +65,21 @@ private:
|
||||||
BitfieldMan* _bitfieldMan;
|
BitfieldMan* _bitfieldMan;
|
||||||
bool _fastExtensionEnabled;
|
bool _fastExtensionEnabled;
|
||||||
// fast index set which a peer has sent to localhost.
|
// fast index set which a peer has sent to localhost.
|
||||||
std::deque<int32_t> _peerAllowedIndexSet;
|
std::deque<size_t> _peerAllowedIndexSet;
|
||||||
// fast index set which localhost has sent to a peer.
|
// fast index set which localhost has sent to a peer.
|
||||||
std::deque<int32_t> _amAllowedIndexSet;
|
std::deque<size_t> _amAllowedIndexSet;
|
||||||
bool _extendedMessagingEnabled;
|
bool _extendedMessagingEnabled;
|
||||||
Extensions _extensions;
|
Extensions _extensions;
|
||||||
bool _dhtEnabled;
|
bool _dhtEnabled;
|
||||||
PeerStat _peerStat;
|
PeerStat _peerStat;
|
||||||
int32_t _latency;
|
unsigned int _latency;
|
||||||
int64_t _uploadLength;
|
uint64_t _uploadLength;
|
||||||
int64_t _downloadLength;
|
uint64_t _downloadLength;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool indexIncluded(const std::deque<T>& c, T index) const;
|
bool indexIncluded(const std::deque<T>& c, T index) const;
|
||||||
public:
|
public:
|
||||||
PeerSessionResource(int32_t pieceLength, int64_t totalLength);
|
PeerSessionResource(size_t pieceLength, uint64_t totalLength);
|
||||||
|
|
||||||
~PeerSessionResource();
|
~PeerSessionResource();
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ public:
|
||||||
|
|
||||||
bool hasAllPieces() const;
|
bool hasAllPieces() const;
|
||||||
|
|
||||||
void updateBitfield(int32_t index, int32_t operation);
|
void updateBitfield(size_t index, int operation);
|
||||||
|
|
||||||
void setBitfield(const unsigned char* bitfield, size_t bitfieldLength);
|
void setBitfield(const unsigned char* bitfield, size_t bitfieldLength);
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ public:
|
||||||
|
|
||||||
size_t getBitfieldLength() const;
|
size_t getBitfieldLength() const;
|
||||||
|
|
||||||
bool hasPiece(int32_t index) const;
|
bool hasPiece(size_t index) const;
|
||||||
|
|
||||||
void markSeeder();
|
void markSeeder();
|
||||||
|
|
||||||
|
@ -139,18 +139,18 @@ public:
|
||||||
void fastExtensionEnabled(bool b);
|
void fastExtensionEnabled(bool b);
|
||||||
|
|
||||||
// fast index set which a peer has sent to localhost.
|
// fast index set which a peer has sent to localhost.
|
||||||
const std::deque<int32_t>& peerAllowedIndexSet() const;
|
const std::deque<size_t>& peerAllowedIndexSet() const;
|
||||||
|
|
||||||
void addPeerAllowedIndex(int32_t index);
|
void addPeerAllowedIndex(size_t index);
|
||||||
|
|
||||||
bool peerAllowedIndexSetContains(int32_t index) const;
|
bool peerAllowedIndexSetContains(size_t index) const;
|
||||||
|
|
||||||
// fast index set which localhost has sent to a peer.
|
// fast index set which localhost has sent to a peer.
|
||||||
const std::deque<int32_t>& amAllowedIndexSet() const;
|
const std::deque<size_t>& amAllowedIndexSet() const;
|
||||||
|
|
||||||
void addAmAllowedIndex(int32_t index);
|
void addAmAllowedIndex(size_t index);
|
||||||
|
|
||||||
bool amAllowedIndexSetContains(int32_t index) const;
|
bool amAllowedIndexSetContains(size_t index) const;
|
||||||
|
|
||||||
bool extendedMessagingEnabled() const;
|
bool extendedMessagingEnabled() const;
|
||||||
|
|
||||||
|
@ -168,17 +168,17 @@ public:
|
||||||
|
|
||||||
PeerStat& getPeerStat();
|
PeerStat& getPeerStat();
|
||||||
|
|
||||||
int32_t latency() const;
|
unsigned int latency() const;
|
||||||
|
|
||||||
void updateLatency(int32_t l);
|
void updateLatency(unsigned int latency);
|
||||||
|
|
||||||
int64_t uploadLength() const;
|
uint64_t uploadLength() const;
|
||||||
|
|
||||||
void updateUploadLength(int32_t bytes);
|
void updateUploadLength(size_t bytes);
|
||||||
|
|
||||||
int64_t downloadLength() const;
|
uint64_t downloadLength() const;
|
||||||
|
|
||||||
void updateDownloadLength(int32_t bytes);
|
void updateDownloadLength(size_t bytes);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -103,29 +103,29 @@ void PeerSessionResourceTest::testUpdateUploadLength()
|
||||||
{
|
{
|
||||||
PeerSessionResource res(1024, 1024*1024);
|
PeerSessionResource res(1024, 1024*1024);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)0, res.uploadLength());
|
CPPUNIT_ASSERT_EQUAL(0ULL, res.uploadLength());
|
||||||
res.updateUploadLength(100);
|
res.updateUploadLength(100);
|
||||||
res.updateUploadLength(200);
|
res.updateUploadLength(200);
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)300, res.uploadLength());
|
CPPUNIT_ASSERT_EQUAL(300ULL, res.uploadLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerSessionResourceTest::testUpdateDownloadLength()
|
void PeerSessionResourceTest::testUpdateDownloadLength()
|
||||||
{
|
{
|
||||||
PeerSessionResource res(1024, 1024*1024);
|
PeerSessionResource res(1024, 1024*1024);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)0, res.downloadLength());
|
CPPUNIT_ASSERT_EQUAL(0ULL, res.downloadLength());
|
||||||
res.updateDownloadLength(100);
|
res.updateDownloadLength(100);
|
||||||
res.updateDownloadLength(200);
|
res.updateDownloadLength(200);
|
||||||
CPPUNIT_ASSERT_EQUAL((int64_t)300, res.downloadLength());
|
CPPUNIT_ASSERT_EQUAL(300ULL, res.downloadLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerSessionResourceTest::testUpdateLatency()
|
void PeerSessionResourceTest::testUpdateLatency()
|
||||||
{
|
{
|
||||||
PeerSessionResource res(1024, 1024*1024);
|
PeerSessionResource res(1024, 1024*1024);
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL(1500, res.latency());
|
CPPUNIT_ASSERT_EQUAL((unsigned int)1500, res.latency());
|
||||||
res.updateLatency(1000);
|
res.updateLatency(1000);
|
||||||
CPPUNIT_ASSERT_EQUAL(1100, res.latency());
|
CPPUNIT_ASSERT_EQUAL((unsigned int)1100, res.latency());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerSessionResourceTest::testExtendedMessageEnabled()
|
void PeerSessionResourceTest::testExtendedMessageEnabled()
|
||||||
|
|
Loading…
Reference in New Issue