mirror of https://github.com/aria2/aria2
2010-01-17 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Moved generateRandomKey() from bittorrent_helper to util. * src/DHTBucket.cc * src/DHTNode.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/util.cc * src/util.hpull/1/head
parent
b08585ebe2
commit
87b18019b4
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2010-01-17 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Moved generateRandomKey() from bittorrent_helper to util.
|
||||
* src/DHTBucket.cc
|
||||
* src/DHTNode.cc
|
||||
* src/bittorrent_helper.cc
|
||||
* src/bittorrent_helper.h
|
||||
* src/util.cc
|
||||
* src/util.h
|
||||
|
||||
2010-01-17 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Updated doc about GID.
|
||||
|
|
|
@ -74,10 +74,10 @@ DHTBucket::~DHTBucket() {}
|
|||
void DHTBucket::getRandomNodeID(unsigned char* nodeID) const
|
||||
{
|
||||
if(_prefixLength == 0) {
|
||||
bittorrent::generateRandomKey(nodeID);
|
||||
util::generateRandomKey(nodeID);
|
||||
} else {
|
||||
size_t lastByteIndex = (_prefixLength-1)/8;
|
||||
bittorrent::generateRandomKey(nodeID);
|
||||
util::generateRandomKey(nodeID);
|
||||
memcpy(nodeID, _min, lastByteIndex+1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ DHTNode::DHTNode(const unsigned char* id):_port(0), _rtt(0), _condition(1), _las
|
|||
|
||||
void DHTNode::generateID()
|
||||
{
|
||||
bittorrent::generateRandomKey(_id);
|
||||
util::generateRandomKey(_id);
|
||||
}
|
||||
|
||||
bool DHTNode::operator==(const DHTNode& node) const
|
||||
|
|
|
@ -853,13 +853,6 @@ void assertID
|
|||
}
|
||||
}
|
||||
|
||||
void generateRandomKey(unsigned char* key)
|
||||
{
|
||||
unsigned char bytes[40];
|
||||
util::generateRandomData(bytes, sizeof(bytes));
|
||||
MessageDigestHelper::digest(key, 20, MessageDigestContext::SHA1, bytes, sizeof(bytes));
|
||||
}
|
||||
|
||||
BDE parseMagnet(const std::string& magnet)
|
||||
{
|
||||
BDE result;
|
||||
|
|
|
@ -228,8 +228,6 @@ void assertPayloadLengthEqual
|
|||
void assertID
|
||||
(uint8_t expected, const unsigned char* data, const std::string& msgName);
|
||||
|
||||
void generateRandomKey(unsigned char* key);
|
||||
|
||||
// Converts attrs into torrent data. attrs must be a BDE::dict. This
|
||||
// function does not guarantee the returned string is valid torrent
|
||||
// data.
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
#include "A2STR.h"
|
||||
#include "array_fun.h"
|
||||
#include "a2functional.h"
|
||||
#include "MessageDigestHelper.h"
|
||||
|
||||
// For libc6 which doesn't define ULLONG_MAX properly because of broken limits.h
|
||||
#ifndef ULLONG_MAX
|
||||
|
@ -1017,6 +1018,14 @@ std::string fixTaintedBasename(const std::string& src)
|
|||
A2STR::BACK_SLASH_C, A2STR::UNDERSCORE_C);
|
||||
}
|
||||
|
||||
void generateRandomKey(unsigned char* key)
|
||||
{
|
||||
unsigned char bytes[40];
|
||||
generateRandomData(bytes, sizeof(bytes));
|
||||
MessageDigestHelper::digest
|
||||
(key, 20, MessageDigestContext::SHA1, bytes, sizeof(bytes));
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -371,6 +371,10 @@ std::string applyDir(const std::string& dir, const std::string& relPath);
|
|||
// replaces '/' and '\' with '_'.
|
||||
std::string fixTaintedBasename(const std::string& src);
|
||||
|
||||
// Generates 20 bytes random key and store it to the address pointed
|
||||
// by key. Caller must allocate at least 20 bytes for generated key.
|
||||
void generateRandomKey(unsigned char* key);
|
||||
|
||||
} // namespace util
|
||||
|
||||
} // namespace aria2
|
||||
|
|
Loading…
Reference in New Issue