From 09dc64910150128c57e14b9f7cd4730916782e25 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 14 Oct 2014 10:41:40 -0400 Subject: [PATCH] donn't calculate routing keys for routers anymore --- HTTPServer.cpp | 4 ++-- Identity.cpp | 20 +++++++++----------- Identity.h | 14 +++++--------- NetDb.cpp | 19 +++---------------- NetDb.h | 1 - RouterInfo.cpp | 7 ------- RouterInfo.h | 4 ---- 7 files changed, 19 insertions(+), 50 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 7a94468f..2e7d867d 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -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 () diff --git a/Identity.cpp b/Identity.cpp index f06176a7..2a48cfd5 100644 --- a/Identity.cpp +++ b/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; } } diff --git a/Identity.h b/Identity.h index 4acae83c..290422ea 100644 --- a/Identity.h +++ b/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& other) const { return !memcmp (m_Buf, other.m_Buf, sz); }; bool operator< (const Tag& 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 diff --git a/NetDb.cpp b/NetDb.cpp index 84dd68a5..aa97871c 100644 --- a/NetDb.cpp +++ b/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 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 ();) diff --git a/NetDb.h b/NetDb.h index ab7a74e8..d05b155b 100644 --- a/NetDb.h +++ b/NetDb.h @@ -100,7 +100,6 @@ namespace data void Publish (); void ValidateSubscriptions (); const RouterInfo * GetClosestFloodfill (const IdentHash& destination, const std::set& excluded) const; - void KeyspaceRotation (); void ManageLeaseSets (); RequestedDestination * CreateRequestedDestination (const IdentHash& dest, diff --git a/RouterInfo.cpp b/RouterInfo.cpp index 70b1becf..f6203a1d 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -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) { diff --git a/RouterInfo.h b/RouterInfo.h index 3ac0f52d..669c85bd 100644 --- a/RouterInfo.h +++ b/RouterInfo.h @@ -92,7 +92,6 @@ namespace data std::vector
& 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;