|
|
@ -155,44 +155,40 @@ namespace data |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NetDb::AddRouterInfo (uint8_t * buf, int len) |
|
|
|
void NetDb::AddRouterInfo (const IdentHash& ident, uint8_t * buf, int len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
RouterInfo * r = new RouterInfo (buf, len); |
|
|
|
DeleteRequestedDestination (ident); |
|
|
|
DeleteRequestedDestination (r->GetIdentHash ()); |
|
|
|
auto it = m_RouterInfos.find(ident); |
|
|
|
auto it = m_RouterInfos.find(r->GetIdentHash ()); |
|
|
|
|
|
|
|
if (it != m_RouterInfos.end ()) |
|
|
|
if (it != m_RouterInfos.end ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (r->GetTimestamp () > it->second->GetTimestamp ()) |
|
|
|
auto ts = it->second->GetTimestamp (); |
|
|
|
{ |
|
|
|
it->second->Update (buf, len); |
|
|
|
|
|
|
|
if (it->second->GetTimestamp () > ts) |
|
|
|
LogPrint ("RouterInfo updated"); |
|
|
|
LogPrint ("RouterInfo updated"); |
|
|
|
*(it->second) = *r; // we can't replace pointer because it's used by tunnels
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
delete r; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("New RouterInfo added"); |
|
|
|
LogPrint ("New RouterInfo added"); |
|
|
|
|
|
|
|
RouterInfo * r = new RouterInfo (buf, len); |
|
|
|
m_RouterInfos[r->GetIdentHash ()] = r; |
|
|
|
m_RouterInfos[r->GetIdentHash ()] = r; |
|
|
|
if (r->IsFloodfill ()) |
|
|
|
if (r->IsFloodfill ()) |
|
|
|
m_Floodfills.push_back (r); |
|
|
|
m_Floodfills.push_back (r); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NetDb::AddLeaseSet (uint8_t * buf, int len) |
|
|
|
void NetDb::AddLeaseSet (const IdentHash& ident, uint8_t * buf, int len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LeaseSet * l = new LeaseSet (buf, len); |
|
|
|
DeleteRequestedDestination (ident); |
|
|
|
DeleteRequestedDestination (l->GetIdentHash ()); |
|
|
|
auto it = m_LeaseSets.find(ident); |
|
|
|
auto it = m_LeaseSets.find(l->GetIdentHash ()); |
|
|
|
|
|
|
|
if (it != m_LeaseSets.end ()) |
|
|
|
if (it != m_LeaseSets.end ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
it->second->Update (buf, len); |
|
|
|
LogPrint ("LeaseSet updated"); |
|
|
|
LogPrint ("LeaseSet updated"); |
|
|
|
*(it->second) = *l; // we can't replace pointer because it's used by streams
|
|
|
|
|
|
|
|
delete l; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("New LeaseSet added"); |
|
|
|
LogPrint ("New LeaseSet added"); |
|
|
|
m_LeaseSets[l->GetIdentHash ()] = l; |
|
|
|
m_LeaseSets[ident] = new LeaseSet (buf, len); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -395,7 +391,7 @@ namespace data |
|
|
|
if (msg->type) |
|
|
|
if (msg->type) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint ("LeaseSet"); |
|
|
|
LogPrint ("LeaseSet"); |
|
|
|
AddLeaseSet (buf + offset, len - offset); |
|
|
|
AddLeaseSet (msg->key, buf + offset, len - offset); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
@ -413,7 +409,7 @@ namespace data |
|
|
|
uint8_t uncompressed[2048]; |
|
|
|
uint8_t uncompressed[2048]; |
|
|
|
size_t uncomressedSize = decompressor.MaxRetrievable (); |
|
|
|
size_t uncomressedSize = decompressor.MaxRetrievable (); |
|
|
|
decompressor.Get (uncompressed, uncomressedSize); |
|
|
|
decompressor.Get (uncompressed, uncomressedSize); |
|
|
|
AddRouterInfo (uncompressed, uncomressedSize); |
|
|
|
AddRouterInfo (msg->key, uncompressed, uncomressedSize); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|