Browse Source

donn't calculate routing keys for routers anymore

pull/102/head
orignal 10 years ago
parent
commit
09dc649101
  1. 4
      HTTPServer.cpp
  2. 20
      Identity.cpp
  3. 14
      Identity.h
  4. 19
      NetDb.cpp
  5. 1
      NetDb.h
  6. 7
      RouterInfo.cpp
  7. 4
      RouterInfo.h

4
HTTPServer.cpp

@ -544,8 +544,8 @@ namespace util
m_Stream->Send ((uint8_t *)m_Buffer, bytes_transferred); m_Stream->Send ((uint8_t *)m_Buffer, bytes_transferred);
Receive (); Receive ();
} }
else if (ecode != boost::asio::error::operation_aborted) /*else if (ecode != boost::asio::error::operation_aborted)
Terminate (); Terminate ();*/
} }
void HTTPConnection::RunRequest () void HTTPConnection::RunRequest ()

20
Identity.cpp

@ -301,7 +301,7 @@ namespace data
dh.GenerateKeyPair(rnd, keys->privateKey, keys->publicKey); dh.GenerateKeyPair(rnd, keys->privateKey, keys->publicKey);
} }
RoutingKey CreateRoutingKey (const IdentHash& ident) IdentHash CreateRoutingKey (const IdentHash& ident)
{ {
uint8_t buf[41]; // ident + yyyymmdd uint8_t buf[41]; // ident + yyyymmdd
memcpy (buf, (const uint8_t *)ident, 32); memcpy (buf, (const uint8_t *)ident, 32);
@ -310,26 +310,24 @@ namespace data
// WARNING!!! check if it is correct // WARNING!!! check if it is correct
#ifdef _WIN32 #ifdef _WIN32
gmtime_s(&tm, &t); 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); sprintf_s((char *)(buf + 32), 9, "%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday);
#else #else
gmtime_r(&t, &tm); gmtime_r(&t, &tm);
// òóò âîçâðàùàåòñÿ êàêîå-òî çíà÷åíèå sprintf'îì. ìîæåò ñòîèò åãî ïðîâåðÿòü?
sprintf((char *)(buf + 32), "%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday); sprintf((char *)(buf + 32), "%4i%2i%2i", tm.tm_year, tm.tm_mon, tm.tm_mday);
#endif #endif
RoutingKey key; IdentHash key;
CryptoPP::SHA256().CalculateDigest(key.hash, buf, 40); CryptoPP::SHA256().CalculateDigest((uint8_t *)key, buf, 40);
return key; return key;
} }
XORMetric operator^(const RoutingKey& key1, const RoutingKey& key2) XORMetric operator^(const IdentHash& key1, const IdentHash& key2)
{ {
XORMetric m; XORMetric m;
m.metric_ll[0] = key1.hash_ll[0] ^ key2.hash_ll[0]; const uint64_t * hash1 = key1.GetLL (), * hash2 = key2.GetLL ();
m.metric_ll[1] = key1.hash_ll[1] ^ key2.hash_ll[1]; m.metric_ll[0] = hash1[0] ^ hash2[0];
m.metric_ll[2] = key1.hash_ll[2] ^ key2.hash_ll[2]; m.metric_ll[1] = hash1[1] ^ hash2[1];
m.metric_ll[3] = key1.hash_ll[3] ^ key2.hash_ll[3]; m.metric_ll[2] = hash1[2] ^ hash2[2];
m.metric_ll[3] = hash1[3] ^ hash2[3];
return m; return m;
} }
} }

14
Identity.h

@ -35,6 +35,8 @@ namespace data
operator uint8_t * () { return m_Buf; }; operator uint8_t * () { return m_Buf; };
operator const uint8_t * () const { 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); };
bool operator< (const Tag<sz>& other) const { return memcmp (m_Buf, other.m_Buf, sz) < 0; }; 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); int l = i2p::data::ByteStreamToBase32 (m_Buf, sz, str, sz*2);
str[l] = 0; str[l] = 0;
return std::string (str); return std::string (str);
} }
private: private:
@ -188,12 +190,6 @@ namespace data
void CreateRandomDHKeysPair (DHKeysPair * keys); // for transport sessions void CreateRandomDHKeysPair (DHKeysPair * keys); // for transport sessions
// kademlia // kademlia
union RoutingKey
{
uint8_t hash[32];
uint64_t hash_ll[4];
};
struct XORMetric struct XORMetric
{ {
union union
@ -207,8 +203,8 @@ namespace data
bool operator< (const XORMetric& other) const { return memcmp (metric, other.metric, 32) < 0; }; bool operator< (const XORMetric& other) const { return memcmp (metric, other.metric, 32) < 0; };
}; };
RoutingKey CreateRoutingKey (const IdentHash& ident); IdentHash CreateRoutingKey (const IdentHash& ident);
XORMetric operator^(const RoutingKey& key1, const RoutingKey& key2); XORMetric operator^(const IdentHash& key1, const IdentHash& key2);
// destination for delivery instuctions // destination for delivery instuctions
class RoutingDestination class RoutingDestination

19
NetDb.cpp

@ -102,7 +102,7 @@ namespace data
void NetDb::Run () void NetDb::Run ()
{ {
uint32_t lastSave = 0, lastPublish = 0, lastKeyspaceRotation = 0; uint32_t lastSave = 0, lastPublish = 0;
m_IsRunning = true; m_IsRunning = true;
while (m_IsRunning) while (m_IsRunning)
{ {
@ -158,11 +158,6 @@ namespace data
Publish (); Publish ();
lastPublish = ts; lastPublish = ts;
} }
if (ts % 86400 < 60 && ts - lastKeyspaceRotation >= 60) // wihhin 1 minutes since midnight (86400 = 24*3600)
{
KeyspaceRotation ();
lastKeyspaceRotation = ts;
}
} }
catch (std::exception& ex) catch (std::exception& ex)
{ {
@ -863,14 +858,14 @@ namespace data
{ {
RouterInfo * r = nullptr; RouterInfo * r = nullptr;
XORMetric minMetric; XORMetric minMetric;
RoutingKey destKey = CreateRoutingKey (destination); IdentHash destKey = CreateRoutingKey (destination);
minMetric.SetMax (); minMetric.SetMax ();
std::unique_lock<std::mutex> l(m_FloodfillsMutex); std::unique_lock<std::mutex> l(m_FloodfillsMutex);
for (auto it: m_Floodfills) for (auto it: m_Floodfills)
{ {
if (!it->IsUnreachable () && !excluded.count (it->GetIdentHash ())) if (!it->IsUnreachable () && !excluded.count (it->GetIdentHash ()))
{ {
XORMetric m = destKey ^ it->GetRoutingKey (); XORMetric m = destKey ^ it->GetIdentHash ();
if (m < minMetric) if (m < minMetric)
{ {
minMetric = m; 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 () void NetDb::ManageLeaseSets ()
{ {
for (auto it = m_LeaseSets.begin (); it != m_LeaseSets.end ();) for (auto it = m_LeaseSets.begin (); it != m_LeaseSets.end ();)

1
NetDb.h

@ -100,7 +100,6 @@ namespace data
void Publish (); void Publish ();
void ValidateSubscriptions (); void ValidateSubscriptions ();
const RouterInfo * GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const; const RouterInfo * GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
void KeyspaceRotation ();
void ManageLeaseSets (); void ManageLeaseSets ();
RequestedDestination * CreateRequestedDestination (const IdentHash& dest, RequestedDestination * CreateRequestedDestination (const IdentHash& dest,

7
RouterInfo.cpp

@ -60,7 +60,6 @@ namespace data
m_RouterIdentity = identity; m_RouterIdentity = identity;
m_IdentHash = m_RouterIdentity.Hash (); m_IdentHash = m_RouterIdentity.Hash ();
UpdateIdentHashBase64 (); UpdateIdentHashBase64 ();
UpdateRoutingKey ();
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch (); m_Timestamp = i2p::util::GetMillisecondsSinceEpoch ();
} }
@ -228,7 +227,6 @@ namespace data
CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&m_RouterIdentity, sizeof (m_RouterIdentity)); CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&m_RouterIdentity, sizeof (m_RouterIdentity));
UpdateIdentHashBase64 (); UpdateIdentHashBase64 ();
UpdateRoutingKey ();
if (!m_SupportedTransports || !m_Addresses.size() || (UsesIntroducer () && !introducers)) if (!m_SupportedTransports || !m_Addresses.size() || (UsesIntroducer () && !introducers))
SetUnreachable (true); SetUnreachable (true);
@ -289,11 +287,6 @@ namespace data
memcpy (m_IdentHashAbbreviation, m_IdentHashBase64, 4); memcpy (m_IdentHashAbbreviation, m_IdentHashBase64, 4);
m_IdentHashAbbreviation[4] = 0; m_IdentHashAbbreviation[4] = 0;
} }
void RouterInfo::UpdateRoutingKey ()
{
memcpy (m_RoutingKey.hash, (const uint8_t *)m_IdentHash, 32);
}
void RouterInfo::WriteToStream (std::ostream& s) void RouterInfo::WriteToStream (std::ostream& s)
{ {

4
RouterInfo.h

@ -92,7 +92,6 @@ namespace data
std::vector<Address>& GetAddresses () { return m_Addresses; }; std::vector<Address>& GetAddresses () { return m_Addresses; };
const Address * GetNTCPAddress (bool v4only = true) const; const Address * GetNTCPAddress (bool v4only = true) const;
const Address * GetSSUAddress (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 AddNTCPAddress (const char * host, int port);
void AddSSUAddress (const char * host, int port, const uint8_t * key); 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 * GetBuffer () const { return m_Buffer; };
const uint8_t * LoadBuffer (); // load if necessary const uint8_t * LoadBuffer (); // load if necessary
int GetBufferLen () const { return m_BufferLen; }; int GetBufferLen () const { return m_BufferLen; };
void CreateBuffer (const PrivateKeys& privateKeys); void CreateBuffer (const PrivateKeys& privateKeys);
void UpdateRoutingKey ();
bool IsUpdated () const { return m_IsUpdated; }; bool IsUpdated () const { return m_IsUpdated; };
void SetUpdated (bool updated) { m_IsUpdated = updated; }; void SetUpdated (bool updated) { m_IsUpdated = updated; };
@ -155,7 +152,6 @@ namespace data
std::string m_FullPath; std::string m_FullPath;
Identity m_RouterIdentity; Identity m_RouterIdentity;
IdentHash m_IdentHash; IdentHash m_IdentHash;
RoutingKey m_RoutingKey;
char m_IdentHashBase64[48], m_IdentHashAbbreviation[5]; char m_IdentHashBase64[48], m_IdentHashAbbreviation[5];
uint8_t * m_Buffer; uint8_t * m_Buffer;
int m_BufferLen; int m_BufferLen;

Loading…
Cancel
Save