mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
kademlia
This commit is contained in:
parent
4f9a977022
commit
4f1f08b805
6 changed files with 78 additions and 0 deletions
27
Identity.cpp
27
Identity.cpp
|
@ -1,3 +1,5 @@
|
|||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <cryptopp/sha.h>
|
||||
#include <cryptopp/osrng.h>
|
||||
#include <cryptopp/dh.h>
|
||||
|
@ -43,5 +45,30 @@ namespace data
|
|||
|
||||
return keys;
|
||||
}
|
||||
|
||||
RoutingKey CreateRoutingKey (const IdentHash& ident)
|
||||
{
|
||||
uint8_t buf[41]; // ident + yyyymmdd
|
||||
memcpy (buf, (const uint8_t *)ident, 32);
|
||||
time_t t = time (nullptr);
|
||||
struct tm tm;
|
||||
gmtime_r (&t, &tm);
|
||||
sprintf ((char *)(buf + 32),"%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday);
|
||||
|
||||
RoutingKey key;
|
||||
CryptoPP::SHA256().CalculateDigest(key.hash, buf, 40);
|
||||
return key;
|
||||
}
|
||||
|
||||
XORMetric operator^(const RoutingKey& key1, const RoutingKey& key2)
|
||||
{
|
||||
// TODO: implementation depends on CPU
|
||||
XORMetric m;
|
||||
((uint64_t *)m.metric)[0] = ((uint64_t *)key1.hash)[0] ^ ((uint64_t *)key2.hash)[0];
|
||||
((uint64_t *)m.metric)[1] = ((uint64_t *)key1.hash)[1] ^ ((uint64_t *)key2.hash)[1];
|
||||
((uint64_t *)m.metric)[2] = ((uint64_t *)key1.hash)[2] ^ ((uint64_t *)key2.hash)[2];
|
||||
((uint64_t *)m.metric)[3] = ((uint64_t *)key1.hash)[3] ^ ((uint64_t *)key2.hash)[3];
|
||||
return m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue