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 "Peer.h"
|
2006-12-24 06:25:21 +00:00
|
|
|
#include "Util.h"
|
2008-02-09 17:14:40 +00:00
|
|
|
#include "PeerSessionResource.h"
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
# include "MessageDigestHelper.h"
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-02-08 15:53:45 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
namespace aria2 {
|
2006-03-21 14:12:51 +00:00
|
|
|
|
2007-12-26 14:26:55 +00:00
|
|
|
#define BAD_CONDITION_INTERVAL 10
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
Peer::Peer(std::string ipaddr, uint16_t port):
|
2006-12-24 06:25:21 +00:00
|
|
|
ipaddr(ipaddr),
|
|
|
|
port(port),
|
2007-03-27 16:16:44 +00:00
|
|
|
_badConditionStartTime(0),
|
2008-02-09 17:14:40 +00:00
|
|
|
_seeder(false),
|
|
|
|
_res(0)
|
2006-12-24 06:25:21 +00:00
|
|
|
{
|
|
|
|
resetStatus();
|
2008-02-24 09:43:31 +00:00
|
|
|
std::string idSeed = ipaddr+":"+Util::uitos(port);
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
id = MessageDigestHelper::digestString("sha1", idSeed);
|
2007-11-14 10:10:38 +00:00
|
|
|
#else
|
|
|
|
id = idSeed;
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
Peer::~Peer()
|
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
releaseSessionResource();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Peer::operator==(const Peer& p)
|
|
|
|
{
|
|
|
|
return id == p.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Peer::operator!=(const Peer& p)
|
|
|
|
{
|
|
|
|
return !(*this == p);
|
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
const std::string& Peer::getID() const
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
return id;
|
2007-12-26 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::usedBy(int32_t cuid)
|
2007-12-26 14:26:55 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
_cuid = cuid;
|
2007-12-26 14:26:55 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
int32_t Peer::usedBy() const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
return _cuid;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
bool Peer::unused() const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
return _cuid == 0;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::allocateSessionResource(int32_t pieceLength, int64_t totalLength)
|
2007-12-26 14:26:55 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
delete _res;
|
|
|
|
_res = new PeerSessionResource(pieceLength, totalLength);
|
|
|
|
_res->getPeerStat().downloadStart();
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::releaseSessionResource()
|
|
|
|
{
|
|
|
|
delete _res;
|
|
|
|
_res = 0;
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
bool Peer::isActive() const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
return _res != 0;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::setPeerId(const unsigned char* peerId)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
memcpy(_peerId, peerId, PEER_ID_LENGTH);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
const unsigned char* Peer::getPeerId() const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
return _peerId;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::resetStatus() {
|
|
|
|
_cuid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Peer::amChoking() const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->amChoking();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::amChoking(bool b) const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
_res->amChoking(b);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
// localhost is interested in this peer
|
|
|
|
bool Peer::amInterested() const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->amInterested();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::amInterested(bool b) const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
_res->amInterested(b);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
// this peer is choking localhost
|
|
|
|
bool Peer::peerChoking() const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->peerChoking();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::peerChoking(bool b) const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
_res->peerChoking(b);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
// this peer is interested in localhost
|
|
|
|
bool Peer::peerInterested() const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->peerInterested();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::peerInterested(bool b)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
_res->peerInterested(b);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
// this peer should be choked
|
|
|
|
bool Peer::chokingRequired() const
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->chokingRequired();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Peer::chokingRequired(bool b)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
_res->chokingRequired(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
// this peer is eligible for unchoking optionally.
|
|
|
|
bool Peer::optUnchoking() const
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->optUnchoking();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Peer::optUnchoking(bool b)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
_res->optUnchoking(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
// this peer is snubbing.
|
|
|
|
bool Peer::snubbing() const
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->snubbing();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Peer::snubbing(bool b)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
_res->snubbing(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Peer::updateUploadLength(int32_t bytes)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
_res->updateUploadLength(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Peer::updateDownloadLength(int32_t bytes)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
_res->updateDownloadLength(bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Peer::updateSeeder()
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
if(_res->hasAllPieces()) {
|
|
|
|
_seeder = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Peer::updateBitfield(int32_t index, int32_t operation) {
|
|
|
|
assert(_res);
|
|
|
|
_res->updateBitfield(index, operation);
|
|
|
|
updateSeeder();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Peer::calculateUploadSpeed()
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->getPeerStat().calculateUploadSpeed();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Peer::calculateUploadSpeed(const struct timeval& now)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->getPeerStat().calculateUploadSpeed(now);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Peer::calculateDownloadSpeed()
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->getPeerStat().calculateDownloadSpeed();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Peer::calculateDownloadSpeed(const struct timeval& now)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->getPeerStat().calculateDownloadSpeed(now);
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t Peer::getSessionUploadLength() const
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->uploadLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t Peer::getSessionDownloadLength() const
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->downloadLength();
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void Peer::setBitfield(const unsigned char* bitfield, int32_t bitfieldLength)
|
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
_res->setBitfield(bitfield, bitfieldLength);
|
2008-02-08 15:53:45 +00:00
|
|
|
updateSeeder();
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned char* Peer::getBitfield() const
|
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->getBitfield();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Peer::getBitfieldLength() const
|
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->getBitfieldLength();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2006-04-28 15:55:11 +00:00
|
|
|
bool Peer::shouldBeChoking() const {
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->shouldBeChoking();
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2006-03-23 10:47:25 +00:00
|
|
|
|
2007-07-21 08:56:16 +00:00
|
|
|
bool Peer::hasPiece(int32_t index) const {
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->hasPiece(index);
|
2006-05-18 17:08:29 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void Peer::setFastExtensionEnabled(bool enabled)
|
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->fastExtensionEnabled(enabled);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Peer::isFastExtensionEnabled() const
|
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->fastExtensionEnabled();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
size_t Peer::countPeerAllowedIndexSet() const
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->peerAllowedIndexSet().size();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::deque<int32_t>& Peer::getPeerAllowedIndexSet() const
|
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->peerAllowedIndexSet();
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
bool Peer::isInPeerAllowedIndexSet(int32_t index) const
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->peerAllowedIndexSetContains(index);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::addPeerAllowedIndex(int32_t index)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
_res->addPeerAllowedIndex(index);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
bool Peer::isInAmAllowedIndexSet(int32_t index) const
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->amAllowedIndexSetContains(index);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::addAmAllowedIndex(int32_t index)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
_res->addAmAllowedIndex(index);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2006-05-18 17:08:29 +00:00
|
|
|
void Peer::setAllBitfield() {
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
_res->markSeeder();
|
2007-12-26 14:26:55 +00:00
|
|
|
_seeder = true;
|
2006-04-28 15:55:11 +00:00
|
|
|
}
|
2006-05-21 16:19:17 +00:00
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
void Peer::updateLatency(int32_t latency)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
_res->updateLatency(latency);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Peer::getLatency() const
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->latency();
|
2006-05-21 16:19:17 +00:00
|
|
|
}
|
2007-03-27 16:16:44 +00:00
|
|
|
|
|
|
|
void Peer::startBadCondition()
|
|
|
|
{
|
|
|
|
_badConditionStartTime.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Peer::isGood() const
|
|
|
|
{
|
2007-12-26 14:26:55 +00:00
|
|
|
return _badConditionStartTime.elapsed(BAD_CONDITION_INTERVAL);
|
2007-03-27 16:16:44 +00:00
|
|
|
}
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
uint8_t Peer::getExtensionMessageID(const std::string& name) const
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->getExtensionMessageID(name);
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
}
|
|
|
|
|
2008-02-09 17:14:40 +00:00
|
|
|
std::string Peer::getExtensionName(uint8_t id) const
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
return _res->getExtensionName(id);
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void Peer::setExtension(const std::string& name, uint8_t id)
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
{
|
2008-02-09 17:14:40 +00:00
|
|
|
assert(_res);
|
|
|
|
_res->addExtension(name, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Peer::setExtendedMessagingEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
_res->extendedMessagingEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Peer::isExtendedMessagingEnabled() const
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->extendedMessagingEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Peer::setDHTEnabled(bool enabled)
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
_res->dhtEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Peer::isDHTEnabled() const
|
|
|
|
{
|
|
|
|
assert(_res);
|
|
|
|
return _res->dhtEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Peer::isSeeder() const
|
|
|
|
{
|
|
|
|
return _seeder;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Time& Peer::getFirstContactTime() const
|
|
|
|
{
|
|
|
|
return _firstContactTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Time& Peer::getBadConditionStartTime() const
|
|
|
|
{
|
|
|
|
return _badConditionStartTime;
|
2007-12-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added uTorrent compatible Peer Exchange.
* src/BencodeVisitor.{h, cc}
* test/BencodeVisitorTest.cc
* src/BtConstants.h
* src/BtContext.h: Added 'private' flag.
* src/BtExtendedMessage.{h, cc}
* test/BtExtendedMessageTest.cc
* src/BtHandshakeMessage.{h, cc}: Set extended messaging bit in
reserved field.
* test/BtHandshakeMessageTest.cc
* src/BtMessageFactory.h
* src/BtRegistry.h
* src/BtRuntime.h: This class holds default extension message
IDs for
aria2. By default, aria2 uses ID 8 for ut_pex.
* src/DefaultBtContext.cc
* src/DefaultBtInteractive.{h, cc}: This class holds
_utPexEnabled.
When it is true, aria2 enables ut_pex. This value is set by
PeerInteractionCommand.
* src/DefaultBtMessageFactory.{h, cc}
* test/DefaultBtMessageFactoryTest.cc
* src/DefaultBtMessageReceiver.cc: Moved the code of fast
extension
handling to DefaultBtInteractive class.
* src/DefaultExtensionMessageFactory.{h, cc}
* test/DefaultExtensionMessageFactoryTest.cc
* src/DefaultPeerStorage.cc: Returns false if a peer is already
in
the container(peers and incomingPeers. The equality is
determined by
Peer::id).
* test/DefaultPeerStorageTest.cc
* src/ExtensionMessage.h
* test/MockExtensionMessage.h
* src/ExtensionMessageFactory.h
* test/MockExtensionMessageFactory.h
* src/HandshakeExtensionMessage.{h, cc}
* test/HandshakeExtensionMessageTest.cc
* src/MetaEntry.h
* src/Peer.{h, cc}
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc: Evaluate the return value
of
addIncomingPeer.
* src/PeerMessageUtil.{h, cc}
* src/PeerObject.h
* src/UTPexExtensionMessage.{h, cc}
* test/UTPexExtensionMessageTest.cc
* src/message.h
* src/prefs.h
Fixed the bug that returns incomplete data when it contains null
character. A convenient constructor was also added.
* src/Data.{h, cc}
Rewritten.
* src/CompactPeerListProcessor.cc
Fixed typos.
* src/message.h
* src/MetaFileUtil.cc
2007-12-22 03:57:55 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|