Browse Source

don't load non-reachable routers

pull/93/head
orignal 10 years ago
parent
commit
3961fdc2e1
  1. 14
      NetDb.cpp
  2. 8
      RouterInfo.cpp

14
NetDb.cpp

@ -267,16 +267,26 @@ namespace data
for (boost::filesystem::directory_iterator it1 (it->path ()); it1 != end; ++it1) for (boost::filesystem::directory_iterator it1 (it->path ()); it1 != end; ++it1)
{ {
#if BOOST_VERSION > 10500 #if BOOST_VERSION > 10500
RouterInfo * r = new RouterInfo (it1->path().string()); const std::string& fullPath = it1->path().string();
#else #else
RouterInfo * r = new RouterInfo(it1->path()); const std::string& fullPath = it1->path();
#endif #endif
RouterInfo * r = new RouterInfo(fullPath);
if (!r->IsUnreachable ())
{
r->DeleteBuffer (); r->DeleteBuffer ();
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);
numRouters++; numRouters++;
} }
else
{
if (boost::filesystem::exists (fullPath))
boost::filesystem::remove (fullPath);
delete r;
}
}
} }
} }
LogPrint (numRouters, " routers loaded"); LogPrint (numRouters, " routers loaded");

8
RouterInfo.cpp

@ -118,8 +118,10 @@ namespace data
// read addresses // read addresses
uint8_t numAddresses; uint8_t numAddresses;
s.read ((char *)&numAddresses, sizeof (numAddresses)); s.read ((char *)&numAddresses, sizeof (numAddresses));
bool introducers = false;
for (int i = 0; i < numAddresses; i++) for (int i = 0; i < numAddresses; i++)
{ {
bool isValidAddress = true;
Address address; Address address;
s.read ((char *)&address.cost, sizeof (address.cost)); s.read ((char *)&address.cost, sizeof (address.cost));
s.read ((char *)&address.date, sizeof (address.date)); s.read ((char *)&address.date, sizeof (address.date));
@ -149,7 +151,7 @@ namespace data
{ {
// TODO: we should try to resolve address here // TODO: we should try to resolve address here
LogPrint ("Unexpected address ", value); LogPrint ("Unexpected address ", value);
SetUnreachable (true); isValidAddress = false;
} }
else else
{ {
@ -169,6 +171,7 @@ namespace data
else if (key[0] == 'i') else if (key[0] == 'i')
{ {
// introducers // introducers
introducers = true;
size_t l = strlen(key); size_t l = strlen(key);
unsigned char index = key[l-1] - '0'; // TODO: unsigned char index = key[l-1] - '0'; // TODO:
key[l-1] = 0; key[l-1] = 0;
@ -188,6 +191,7 @@ namespace data
Base64ToByteStream (value, strlen (value), introducer.iKey, 32); Base64ToByteStream (value, strlen (value), introducer.iKey, 32);
} }
} }
if (isValidAddress)
m_Addresses.push_back(address); m_Addresses.push_back(address);
} }
// read peers // read peers
@ -222,7 +226,7 @@ namespace data
UpdateIdentHashBase64 (); UpdateIdentHashBase64 ();
UpdateRoutingKey (); UpdateRoutingKey ();
if (!m_SupportedTransports) if (!m_SupportedTransports || !m_Addresses.size() || (UsesIntroducer () && !introducers))
SetUnreachable (true); SetUnreachable (true);
} }

Loading…
Cancel
Save