summaryrefslogtreecommitdiff
path: root/src/DHTTokenTracker.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-08-03 11:44:24 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-08-03 11:44:24 +0000
commit2bd5020f81bc8c9995590209d0bf024147c8a51a (patch)
tree3cc93c71179570c7a4889a25f64f56d3c8820c84 /src/DHTTokenTracker.cc
parent939a372727b2f27e683a23ac38928b82de550376 (diff)
2010-08-03 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added bittorrent::packcompact() which replaces bittorrent::createcompact() and supports IPv6 addresses. Rewritten bittorrent::unpackcompact() and bittorrent::extractPeer() to support IPv6 addresses. Fixed added.f flags in ut_pex. * src/BtConstants.h * src/DHTFindNodeReplyMessage.cc * src/DHTGetPeersReplyMessage.cc * src/DHTMessageFactoryImpl.cc * src/DHTRoutingTableDeserializer.cc * src/DHTRoutingTableSerializer.cc * src/DHTTokenTracker.cc * src/DefaultBtAnnounce.cc * src/UTPexExtensionMessage.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * test/BittorrentHelperTest.cc * test/DHTFindNodeReplyMessageTest.cc * test/DHTGetPeersReplyMessageTest.cc * test/DHTMessageFactoryImplTest.cc * test/DHTRoutingTableSerializerTest.cc * test/DefaultExtensionMessageFactoryTest.cc * test/UTPexExtensionMessageTest.cc
Diffstat (limited to 'src/DHTTokenTracker.cc')
-rw-r--r--src/DHTTokenTracker.cc18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/DHTTokenTracker.cc b/src/DHTTokenTracker.cc
index 6583e69e..209e3c27 100644
--- a/src/DHTTokenTracker.cc
+++ b/src/DHTTokenTracker.cc
@@ -59,20 +59,24 @@ DHTTokenTracker::DHTTokenTracker(const unsigned char* initialSecret)
DHTTokenTracker::~DHTTokenTracker() {}
-std::string DHTTokenTracker::generateToken(const unsigned char* infoHash,
- const std::string& ipaddr, uint16_t port,
- const unsigned char* secret) const
+std::string DHTTokenTracker::generateToken
+(const unsigned char* infoHash,
+ const std::string& ipaddr, uint16_t port,
+ const unsigned char* secret) const
{
- unsigned char src[DHT_ID_LENGTH+6+SECRET_SIZE];
- if(!bittorrent::createcompact(src+DHT_ID_LENGTH, ipaddr, port)) {
+ unsigned char src[DHT_ID_LENGTH+COMPACT_LEN_IPV6+SECRET_SIZE];
+ memset(src, 0, sizeof(src));
+ int compactlen = bittorrent::packcompact(src+DHT_ID_LENGTH, ipaddr, port);
+ if(compactlen == 0) {
throw DL_ABORT_EX
(StringFormat("Token generation failed: ipaddr=%s, port=%u",
ipaddr.c_str(), port).str());
}
memcpy(src, infoHash, DHT_ID_LENGTH);
- memcpy(src+DHT_ID_LENGTH+6, secret, SECRET_SIZE);
+ memcpy(src+DHT_ID_LENGTH+COMPACT_LEN_IPV6, secret, SECRET_SIZE);
unsigned char md[20];
- MessageDigestHelper::digest(md, sizeof(md), MessageDigestContext::SHA1, src, sizeof(src));
+ MessageDigestHelper::digest(md, sizeof(md), MessageDigestContext::SHA1,
+ src, sizeof(src));
return std::string(&md[0], &md[sizeof(md)]);
}