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 "BitfieldManFactory.h"
|
|
|
|
#include "Util.h"
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
# include "MessageDigestHelper.h"
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2006-03-21 14:12:51 +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
|
|
|
Peer::Peer(string ipaddr, uint16_t port, int32_t pieceLength, int64_t totalLength):
|
2006-12-24 06:25:21 +00:00
|
|
|
ipaddr(ipaddr),
|
|
|
|
port(port),
|
|
|
|
sessionUploadLength(0),
|
|
|
|
sessionDownloadLength(0),
|
|
|
|
pieceLength(pieceLength),
|
2007-03-27 16:16:44 +00:00
|
|
|
active(false),
|
|
|
|
_badConditionStartTime(0),
|
|
|
|
_badConditionInterval(10)
|
2006-12-24 06:25:21 +00:00
|
|
|
{
|
|
|
|
resetStatus();
|
2007-02-12 12:05:55 +00:00
|
|
|
this->bitfield = BitfieldManFactory::getFactoryInstance()->
|
2006-12-24 06:25:21 +00:00
|
|
|
createBitfieldMan(pieceLength, totalLength);
|
|
|
|
string idSeed = ipaddr+":"+Util::itos(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
|
|
|
}
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void Peer::reconfigure(int32_t pieceLength, int64_t totalLength)
|
|
|
|
{
|
|
|
|
delete bitfield;
|
|
|
|
this->pieceLength = pieceLength;
|
|
|
|
this->bitfield = BitfieldManFactory::getFactoryInstance()->
|
|
|
|
createBitfieldMan(this->pieceLength, totalLength);
|
|
|
|
}
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
/*
|
|
|
|
Peer::Peer():entryId(0), ipaddr(""), port(0), bitfield(0),
|
|
|
|
sessionUploadLength(0), sessionDownloadLength(0),
|
|
|
|
pieceLength(0)
|
|
|
|
{
|
|
|
|
resetStatus();
|
|
|
|
}
|
|
|
|
*/
|
2006-03-21 14:12:51 +00:00
|
|
|
|
2007-07-21 08:56:16 +00:00
|
|
|
void Peer::updateBitfield(int32_t index, int32_t operation) {
|
2006-03-21 14:12:51 +00:00
|
|
|
if(operation == 1) {
|
|
|
|
bitfield->setBit(index);
|
|
|
|
} else if(operation == 0) {
|
|
|
|
bitfield->unsetBit(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define THRESHOLD 1024*1024*2
|
|
|
|
|
2006-04-28 15:55:11 +00:00
|
|
|
bool Peer::shouldBeChoking() const {
|
|
|
|
if(optUnchoking) {
|
2006-03-21 14:12:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-04-28 15:55:11 +00:00
|
|
|
return chokingRequired;
|
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 {
|
2006-03-23 10:47:25 +00:00
|
|
|
return bitfield->isBitSet(index);
|
|
|
|
}
|
2006-03-31 13:58:22 +00:00
|
|
|
|
|
|
|
bool Peer::isSeeder() const {
|
|
|
|
return bitfield->isAllBitSet();
|
|
|
|
}
|
2006-04-28 15:55:11 +00:00
|
|
|
|
|
|
|
void Peer::resetStatus() {
|
|
|
|
tryCount = 0;
|
|
|
|
cuid = 0;
|
|
|
|
amChoking = true;
|
|
|
|
amInterested = false;
|
|
|
|
peerChoking = true;
|
|
|
|
peerInterested = false;
|
|
|
|
chokingRequired = true;
|
|
|
|
optUnchoking = false;
|
2006-06-12 16:55:08 +00:00
|
|
|
snubbing = false;
|
2006-05-18 17:08:29 +00:00
|
|
|
fastExtensionEnabled = false;
|
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
|
|
|
_extendedMessagingEnabled = false;
|
|
|
|
_extensions.clear();
|
2006-05-21 16:19:17 +00:00
|
|
|
latency = DEFAULT_LATENCY;
|
2006-12-24 06:25:21 +00:00
|
|
|
peerAllowedIndexSet.clear();
|
|
|
|
amAllowedIndexSet.clear();
|
* src/PeerChokeCommand.cc
(optUnchokingPeer): Updated according to the changes in Peer.
(ResetDelta): Removed.
(UploadFaster): Updated according to the changes in Peer.
(DownloadFaster): Updated according to the changes in Peer.
(execute): I clarify the meaning of "upload" and "download"
here.
"upload" means the transfer from localhost to remote host.
"download" means the transfer from remote host to localhost.
Based on this rule, I swapped orderByUploadRate and
orderByDownloadRate.
* src/PeerInteractionCommand.cc
(PeerInteraction): Removed peerInteraction->setUploadLImit().
(executeInternal): Removed the argument of
peerInteraction->sendMessages().
(receiveMessages): Rewritten download speed limit.
(sendKeepAlive): Removed peerInteraction->sendMessages().
* src/HttpResponseCommand.cc
(handleDefaultEncoding): If file size is unknown in torrent
request,
do not call segmentMan->initBitfield() here.
Disabled persistent connection feature in torrent request.
* src/UrlRequestInfo.h
(UrlRequestInfo): Removed const qualifier from option.
* src/TorrentMan.h
(TransferStat): New class.
(deltaDownloadLength): Removed.
(deltaUploadLength): Removed.
(addDeltaDownloadLength): Removed.
(getDeltaDownloadLength): Removed.
(resetDeltaDownloadLength): Removed.
(addDeltaUploadLength): Removed.
(getDeltaUploadLength): Removed.
(resetDeltaUploadLength): Removed.
(addActivePeer): Added peer->activate().
(deleteActivePeer): Added peer->deactivate().
(calculateStat): New function.
* src/TorrentMan.cc
(TorrentMan): Removed deltaDownloadLength and deltaUploadLength.
(calculateStat): New function.
* src/PeerInteraction.h
(uploadLimit): Removed.
(option): New variable.
(setUploadLimit): Removed.
(getUploadSpeed): Removed.
(sendMessages): Removed the argument "currentUploadSpeed".
* src/PeerInteraction.cc
(prefs.h): Included.
(PeerInteraction): Removed uploadLimit. Added option.
(sendMessages): Rewritten upload speed limit.
(sendHandshake): Removed the argument from sendMessages().
(sendBitfield): Removed the argument from sendMessages().
* src/PeerAbstractCommand.cc
(execute): Commented out the portion of upload limit.
(onAbort): Removed peer->resetStatus().
* src/TorrentRequestInfo.cc
(timeoutSpecified): Declared extern.
(execute): Set timeout to 180 if timeout is not specified by.
command-line.
* src/PieceMessage.cc
(receivedAction): Added peer->updateDownloadLength().
Removed peer->addPeerUpload().
Removed torrentMan->addDeltaDownloadLength().
(send): Added peer->updateUploadLength().
Removed peer->addPeerDownload().
Removed torrentMan->addDeltaUploadLength().
* src/main.cc
(timeoutSpecified): New variable.
(main): Set timeoutSpecified to false.
If the command-line option "--upload-limit" is specified, then
timeoutSpecified is set to true. This option will remain in the
next
release, but be deprecated in the future release.
* src/TorrentRequestInfo.h
(TorrentRequestInfo): Removed const qualifier from op.
* src/PeerStat.h
(uploadSpeed): New variable.
(PeerStat): Added default value to cuid.
(calculateUploadSpeed): New function.
(updateUploadLength): New function.
(getMaxUploadSpeed): New function.
(getAvgUploadSpeed): New function.
(reset): Added uploadSpeed. Set status to IDLE.
* src/TorrentDownloadEngine.h
(cp): Declared as Time.
(sessionDownloadLengthArray): Removed.
(sessionUploadLengthArray): Removed.
(currentCp): Removed.
(lastCalcStat): New variable
(lastElapsed): Removed.
(sessionDownloadLength): Removed.
(calculateStat): New function.
* src/TorrentDownloadEngine.cc
(initStatistics): Removed lastElapsed, cp[],
sessionDownloadLengthArray[], sessionUploadLengthArray[],
currentCp, sessionDownloadLength.
Added cp.reset() and lastCalcStat.reset().
(calculateSpeed): Changed the name of the argument.
(calculateStatistics): Rewritten.
(calculateStat): New function.
* src/Peer.h
(PeerStat.h): Included.
(peerUpload): Removed.
(peerDownload): Removed.
(peerStat): New variable.
(sessionUploadLength): New variable.
(sessionDownloadLength): New variable.
(deltaUpload): Removed.
(deltaDownload): Removed.
(resetStatus): Made private.
(Peer): Added sessionUploadLength, sessionDownloadLength.
Removed peerUpload, peerDownload.
(updateUploadLength): New function.
(addDeltaUpload): Removed.
(updateDownloadLength): New function.
(resetDeltaUpload): Removed.
(getDeltaUpload): Removed.
(addDeltaDownload): Removed.
(calculateUploadSpeed): New function.
(resetDeltaDownload): Removed.
(getDeltaDownload): Removed.
(calculateDownloadSpeed): New function.
(getSessionUploadLength): New function.
(getSessionDownloadLength): New function.
(activate): New function.
(deactivate): New function.
(addPeerUpload): Removed.
(setPeerUpload): Removed.
(getPeerUpload): Removed.
(addPeerDownload): Removed.
(setPeerDownload): Removed.
(getPeerDownload): Removed.
* src/Peer.cc
(resetStatus): Removed resetDeltaUpload() and
resetDeltaDownload().
* src/MetalinkRequestInfo.h
(MetalinkRequestInfo): Removed const qualifier from op.
* src/RequestInfo.h
(op): Removed const qualifier.
(RequestInfo): Removed const qualifier from op.
2006-09-21 13:49:06 +00:00
|
|
|
peerStat.reset();
|
2006-05-18 17:08:29 +00:00
|
|
|
}
|
|
|
|
|
2007-07-21 08:56:16 +00:00
|
|
|
bool Peer::isInPeerAllowedIndexSet(int32_t index) const {
|
2006-12-24 06:25:21 +00:00
|
|
|
return find(peerAllowedIndexSet.begin(), peerAllowedIndexSet.end(),
|
|
|
|
index) != peerAllowedIndexSet.end();
|
|
|
|
}
|
|
|
|
|
2007-07-21 08:56:16 +00:00
|
|
|
void Peer::addPeerAllowedIndex(int32_t index) {
|
2006-12-24 06:25:21 +00:00
|
|
|
if(!isInPeerAllowedIndexSet(index)) {
|
|
|
|
peerAllowedIndexSet.push_back(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-21 08:56:16 +00:00
|
|
|
bool Peer::isInAmAllowedIndexSet(int32_t index) const {
|
2006-12-24 06:25:21 +00:00
|
|
|
return find(amAllowedIndexSet.begin(), amAllowedIndexSet.end(),
|
|
|
|
index) != amAllowedIndexSet.end();
|
|
|
|
}
|
|
|
|
|
2007-07-21 08:56:16 +00:00
|
|
|
void Peer::addAmAllowedIndex(int32_t index) {
|
2006-12-24 06:25:21 +00:00
|
|
|
if(!isInAmAllowedIndexSet(index)) {
|
|
|
|
amAllowedIndexSet.push_back(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-18 17:08:29 +00:00
|
|
|
void Peer::setAllBitfield() {
|
|
|
|
bitfield->setAllBit();
|
2006-04-28 15:55:11 +00:00
|
|
|
}
|
2006-05-21 16:19:17 +00:00
|
|
|
|
2007-07-21 08:56:16 +00:00
|
|
|
void Peer::updateLatency(int32_t latency) {
|
2006-05-26 15:28:19 +00:00
|
|
|
this->latency = (this->latency*20+latency*80)/200;
|
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
|
|
|
|
{
|
|
|
|
return _badConditionStartTime.elapsed(_badConditionInterval);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
uint8_t Peer::getExtensionMessageID(const string& name)
|
|
|
|
{
|
|
|
|
Extensions::const_iterator itr = _extensions.find(name);
|
|
|
|
if(itr == _extensions.end()) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return (*itr).second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string Peer::getExtensionName(uint8_t id)
|
|
|
|
{
|
|
|
|
for(Extensions::const_iterator itr = _extensions.begin();
|
|
|
|
itr != _extensions.end(); ++itr) {
|
|
|
|
const Extensions::value_type& p = *itr;
|
|
|
|
if(p.second == id) {
|
|
|
|
return p.first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void Peer::setExtension(const string& name, uint8_t id)
|
|
|
|
{
|
|
|
|
_extensions[name] = id;
|
|
|
|
}
|