summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--src/DHTBucket.cc4
-rw-r--r--src/DHTNode.cc2
-rw-r--r--src/bittorrent_helper.cc7
-rw-r--r--src/bittorrent_helper.h2
-rw-r--r--src/util.cc9
-rw-r--r--src/util.h4
7 files changed, 26 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index cc746dc2..636a86f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
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.
* doc/aria2c.1.txt
diff --git a/src/DHTBucket.cc b/src/DHTBucket.cc
index 96e21918..527c7751 100644
--- a/src/DHTBucket.cc
+++ b/src/DHTBucket.cc
@@ -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);
}
}
diff --git a/src/DHTNode.cc b/src/DHTNode.cc
index 0cca4902..ac20f84e 100644
--- a/src/DHTNode.cc
+++ b/src/DHTNode.cc
@@ -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
diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc
index fe2365f7..6e76de8f 100644
--- a/src/bittorrent_helper.cc
+++ b/src/bittorrent_helper.cc
@@ -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;
diff --git a/src/bittorrent_helper.h b/src/bittorrent_helper.h
index d08962b8..e0b3fcf8 100644
--- a/src/bittorrent_helper.h
+++ b/src/bittorrent_helper.h
@@ -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.
diff --git a/src/util.cc b/src/util.cc
index bd0ebc52..a6395a17 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -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
diff --git a/src/util.h b/src/util.h
index 83fa0943..a57a84e5 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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