mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
donn't calculate routing keys for routers anymore
This commit is contained in:
parent
030c04de81
commit
09dc649101
@ -544,8 +544,8 @@ namespace util
|
||||
m_Stream->Send ((uint8_t *)m_Buffer, bytes_transferred);
|
||||
Receive ();
|
||||
}
|
||||
else if (ecode != boost::asio::error::operation_aborted)
|
||||
Terminate ();
|
||||
/*else if (ecode != boost::asio::error::operation_aborted)
|
||||
Terminate ();*/
|
||||
}
|
||||
|
||||
void HTTPConnection::RunRequest ()
|
||||
|
20
Identity.cpp
20
Identity.cpp
@ -301,7 +301,7 @@ namespace data
|
||||
dh.GenerateKeyPair(rnd, keys->privateKey, keys->publicKey);
|
||||
}
|
||||
|
||||
RoutingKey CreateRoutingKey (const IdentHash& ident)
|
||||
IdentHash CreateRoutingKey (const IdentHash& ident)
|
||||
{
|
||||
uint8_t buf[41]; // ident + yyyymmdd
|
||||
memcpy (buf, (const uint8_t *)ident, 32);
|
||||
@ -310,26 +310,24 @@ namespace data
|
||||
// WARNING!!! check if it is correct
|
||||
#ifdef _WIN32
|
||||
gmtime_s(&tm, &t);
|
||||
// òóò âîçâðàùàåòñÿ êàêîå-òî çíà÷åíèå sprintf'îì. ìîæåò ñòîèò åãî ïðîâåðÿòü?
|
||||
// http://msdn.microsoft.com/en-us/library/ce3zzk1k.aspx
|
||||
sprintf_s((char *)(buf + 32), 9, "%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday);
|
||||
#else
|
||||
gmtime_r(&t, &tm);
|
||||
// òóò âîçâðàùàåòñÿ êàêîå-òî çíà÷åíèå sprintf'îì. ìîæåò ñòîèò åãî ïðîâåðÿòü?
|
||||
sprintf((char *)(buf + 32), "%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday);
|
||||
#endif
|
||||
RoutingKey key;
|
||||
CryptoPP::SHA256().CalculateDigest(key.hash, buf, 40);
|
||||
IdentHash key;
|
||||
CryptoPP::SHA256().CalculateDigest((uint8_t *)key, buf, 40);
|
||||
return key;
|
||||
}
|
||||
|
||||
XORMetric operator^(const RoutingKey& key1, const RoutingKey& key2)
|
||||
XORMetric operator^(const IdentHash& key1, const IdentHash& key2)
|
||||
{
|
||||
XORMetric m;
|
||||
m.metric_ll[0] = key1.hash_ll[0] ^ key2.hash_ll[0];
|
||||
m.metric_ll[1] = key1.hash_ll[1] ^ key2.hash_ll[1];
|
||||
m.metric_ll[2] = key1.hash_ll[2] ^ key2.hash_ll[2];
|
||||
m.metric_ll[3] = key1.hash_ll[3] ^ key2.hash_ll[3];
|
||||
const uint64_t * hash1 = key1.GetLL (), * hash2 = key2.GetLL ();
|
||||
m.metric_ll[0] = hash1[0] ^ hash2[0];
|
||||
m.metric_ll[1] = hash1[1] ^ hash2[1];
|
||||
m.metric_ll[2] = hash1[2] ^ hash2[2];
|
||||
m.metric_ll[3] = hash1[3] ^ hash2[3];
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
14
Identity.h
14
Identity.h
@ -35,6 +35,8 @@ namespace data
|
||||
operator uint8_t * () { return m_Buf; };
|
||||
operator const uint8_t * () const { return m_Buf; };
|
||||
|
||||
const uint64_t * GetLL () const { return ll; };
|
||||
|
||||
bool operator== (const Tag<sz>& other) const { return !memcmp (m_Buf, other.m_Buf, sz); };
|
||||
bool operator< (const Tag<sz>& other) const { return memcmp (m_Buf, other.m_Buf, sz) < 0; };
|
||||
|
||||
@ -52,7 +54,7 @@ namespace data
|
||||
int l = i2p::data::ByteStreamToBase32 (m_Buf, sz, str, sz*2);
|
||||
str[l] = 0;
|
||||
return std::string (str);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@ -188,12 +190,6 @@ namespace data
|
||||
void CreateRandomDHKeysPair (DHKeysPair * keys); // for transport sessions
|
||||
|
||||
// kademlia
|
||||
union RoutingKey
|
||||
{
|
||||
uint8_t hash[32];
|
||||
uint64_t hash_ll[4];
|
||||
};
|
||||
|
||||
struct XORMetric
|
||||
{
|
||||
union
|
||||
@ -207,8 +203,8 @@ namespace data
|
||||
bool operator< (const XORMetric& other) const { return memcmp (metric, other.metric, 32) < 0; };
|
||||
};
|
||||
|
||||
RoutingKey CreateRoutingKey (const IdentHash& ident);
|
||||
XORMetric operator^(const RoutingKey& key1, const RoutingKey& key2);
|
||||
IdentHash CreateRoutingKey (const IdentHash& ident);
|
||||
XORMetric operator^(const IdentHash& key1, const IdentHash& key2);
|
||||
|
||||
// destination for delivery instuctions
|
||||
class RoutingDestination
|
||||
|
19
NetDb.cpp
19
NetDb.cpp
@ -102,7 +102,7 @@ namespace data
|
||||
|
||||
void NetDb::Run ()
|
||||
{
|
||||
uint32_t lastSave = 0, lastPublish = 0, lastKeyspaceRotation = 0;
|
||||
uint32_t lastSave = 0, lastPublish = 0;
|
||||
m_IsRunning = true;
|
||||
while (m_IsRunning)
|
||||
{
|
||||
@ -158,11 +158,6 @@ namespace data
|
||||
Publish ();
|
||||
lastPublish = ts;
|
||||
}
|
||||
if (ts % 86400 < 60 && ts - lastKeyspaceRotation >= 60) // wihhin 1 minutes since midnight (86400 = 24*3600)
|
||||
{
|
||||
KeyspaceRotation ();
|
||||
lastKeyspaceRotation = ts;
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
@ -863,14 +858,14 @@ namespace data
|
||||
{
|
||||
RouterInfo * r = nullptr;
|
||||
XORMetric minMetric;
|
||||
RoutingKey destKey = CreateRoutingKey (destination);
|
||||
IdentHash destKey = CreateRoutingKey (destination);
|
||||
minMetric.SetMax ();
|
||||
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
|
||||
for (auto it: m_Floodfills)
|
||||
{
|
||||
if (!it->IsUnreachable () && !excluded.count (it->GetIdentHash ()))
|
||||
{
|
||||
XORMetric m = destKey ^ it->GetRoutingKey ();
|
||||
XORMetric m = destKey ^ it->GetIdentHash ();
|
||||
if (m < minMetric)
|
||||
{
|
||||
minMetric = m;
|
||||
@ -910,14 +905,6 @@ namespace data
|
||||
}
|
||||
}
|
||||
|
||||
void NetDb::KeyspaceRotation ()
|
||||
{
|
||||
for (auto it: m_RouterInfos)
|
||||
it.second->UpdateRoutingKey ();
|
||||
LogPrint ("Keyspace rotation complete");
|
||||
Publish ();
|
||||
}
|
||||
|
||||
void NetDb::ManageLeaseSets ()
|
||||
{
|
||||
for (auto it = m_LeaseSets.begin (); it != m_LeaseSets.end ();)
|
||||
|
1
NetDb.h
1
NetDb.h
@ -100,7 +100,6 @@ namespace data
|
||||
void Publish ();
|
||||
void ValidateSubscriptions ();
|
||||
const RouterInfo * GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
|
||||
void KeyspaceRotation ();
|
||||
void ManageLeaseSets ();
|
||||
|
||||
RequestedDestination * CreateRequestedDestination (const IdentHash& dest,
|
||||
|
@ -60,7 +60,6 @@ namespace data
|
||||
m_RouterIdentity = identity;
|
||||
m_IdentHash = m_RouterIdentity.Hash ();
|
||||
UpdateIdentHashBase64 ();
|
||||
UpdateRoutingKey ();
|
||||
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch ();
|
||||
}
|
||||
|
||||
@ -228,7 +227,6 @@ namespace data
|
||||
|
||||
CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&m_RouterIdentity, sizeof (m_RouterIdentity));
|
||||
UpdateIdentHashBase64 ();
|
||||
UpdateRoutingKey ();
|
||||
|
||||
if (!m_SupportedTransports || !m_Addresses.size() || (UsesIntroducer () && !introducers))
|
||||
SetUnreachable (true);
|
||||
@ -289,11 +287,6 @@ namespace data
|
||||
memcpy (m_IdentHashAbbreviation, m_IdentHashBase64, 4);
|
||||
m_IdentHashAbbreviation[4] = 0;
|
||||
}
|
||||
|
||||
void RouterInfo::UpdateRoutingKey ()
|
||||
{
|
||||
memcpy (m_RoutingKey.hash, (const uint8_t *)m_IdentHash, 32);
|
||||
}
|
||||
|
||||
void RouterInfo::WriteToStream (std::ostream& s)
|
||||
{
|
||||
|
@ -92,7 +92,6 @@ namespace data
|
||||
std::vector<Address>& GetAddresses () { return m_Addresses; };
|
||||
const Address * GetNTCPAddress (bool v4only = true) const;
|
||||
const Address * GetSSUAddress (bool v4only = true) const;
|
||||
const RoutingKey& GetRoutingKey () const { return m_RoutingKey; };
|
||||
|
||||
void AddNTCPAddress (const char * host, int port);
|
||||
void AddSSUAddress (const char * host, int port, const uint8_t * key);
|
||||
@ -119,9 +118,7 @@ namespace data
|
||||
const uint8_t * GetBuffer () const { return m_Buffer; };
|
||||
const uint8_t * LoadBuffer (); // load if necessary
|
||||
int GetBufferLen () const { return m_BufferLen; };
|
||||
|
||||
void CreateBuffer (const PrivateKeys& privateKeys);
|
||||
void UpdateRoutingKey ();
|
||||
|
||||
bool IsUpdated () const { return m_IsUpdated; };
|
||||
void SetUpdated (bool updated) { m_IsUpdated = updated; };
|
||||
@ -155,7 +152,6 @@ namespace data
|
||||
std::string m_FullPath;
|
||||
Identity m_RouterIdentity;
|
||||
IdentHash m_IdentHash;
|
||||
RoutingKey m_RoutingKey;
|
||||
char m_IdentHashBase64[48], m_IdentHashAbbreviation[5];
|
||||
uint8_t * m_Buffer;
|
||||
int m_BufferLen;
|
||||
|
Loading…
Reference in New Issue
Block a user