60
60
DHTTokenTracker::~DHTTokenTracker() {}
62
std::string DHTTokenTracker::generateToken(const unsigned char* infoHash,
63
const std::string& ipaddr, uint16_t port,
64
const unsigned char* secret) const
62
std::string DHTTokenTracker::generateToken
63
(const unsigned char* infoHash,
64
const std::string& ipaddr, uint16_t port,
65
const unsigned char* secret) const
66
unsigned char src[DHT_ID_LENGTH+6+SECRET_SIZE];
67
if(!bittorrent::createcompact(src+DHT_ID_LENGTH, ipaddr, port)) {
67
unsigned char src[DHT_ID_LENGTH+COMPACT_LEN_IPV6+SECRET_SIZE];
68
memset(src, 0, sizeof(src));
69
int compactlen = bittorrent::packcompact(src+DHT_ID_LENGTH, ipaddr, port);
69
72
(StringFormat("Token generation failed: ipaddr=%s, port=%u",
70
73
ipaddr.c_str(), port).str());
72
75
memcpy(src, infoHash, DHT_ID_LENGTH);
73
memcpy(src+DHT_ID_LENGTH+6, secret, SECRET_SIZE);
76
memcpy(src+DHT_ID_LENGTH+COMPACT_LEN_IPV6, secret, SECRET_SIZE);
74
77
unsigned char md[20];
75
MessageDigestHelper::digest(md, sizeof(md), MessageDigestContext::SHA1, src, sizeof(src));
78
MessageDigestHelper::digest(md, sizeof(md), MessageDigestContext::SHA1,
76
80
return std::string(&md[0], &md[sizeof(md)]);