Browse Source

don't store full path with RouterInfo

pull/1696/head
orignal 3 years ago
parent
commit
48131f4597
  1. 3
      libi2pd/NetDb.cpp
  2. 26
      libi2pd/RouterInfo.cpp
  3. 8
      libi2pd/RouterInfo.h

3
libi2pd/NetDb.cpp

@ -963,7 +963,8 @@ namespace data @@ -963,7 +963,8 @@ namespace data
if (router)
{
LogPrint (eLogDebug, "NetDb: requested RouterInfo ", key, " found");
router->LoadBuffer ();
if (!router->GetBuffer ())
router->LoadBuffer (m_Storage.Path (router->GetIdentHashBase64 ()));
if (router->GetBuffer ())
replyMsg = CreateDatabaseStoreMsg (router);
}

26
libi2pd/RouterInfo.cpp

@ -35,12 +35,12 @@ namespace data @@ -35,12 +35,12 @@ namespace data
}
RouterInfo::RouterInfo (const std::string& fullPath):
m_FullPath (fullPath), m_IsUpdated (false), m_IsUnreachable (false),
m_SupportedTransports (0), m_ReachableTransports (0), m_Caps (0), m_Version (0)
m_IsUpdated (false), m_IsUnreachable (false), m_SupportedTransports (0),
m_ReachableTransports (0), m_Caps (0), m_Version (0)
{
m_Addresses = boost::make_shared<Addresses>(); // create empty list
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE];
ReadFromFile ();
ReadFromFile (fullPath);
}
RouterInfo::RouterInfo (const uint8_t * buf, int len):
@ -113,16 +113,16 @@ namespace data @@ -113,16 +113,16 @@ namespace data
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch ();
}
bool RouterInfo::LoadFile ()
bool RouterInfo::LoadFile (const std::string& fullPath)
{
std::ifstream s(m_FullPath, std::ifstream::binary);
std::ifstream s(fullPath, std::ifstream::binary);
if (s.is_open ())
{
s.seekg (0,std::ios::end);
m_BufferLen = s.tellg ();
if (m_BufferLen < 40 || m_BufferLen > MAX_RI_BUFFER_SIZE)
{
LogPrint(eLogError, "RouterInfo: File", m_FullPath, " is malformed");
LogPrint(eLogError, "RouterInfo: File", fullPath, " is malformed");
return false;
}
s.seekg(0, std::ios::beg);
@ -131,15 +131,15 @@ namespace data @@ -131,15 +131,15 @@ namespace data
}
else
{
LogPrint (eLogError, "RouterInfo: Can't open file ", m_FullPath);
LogPrint (eLogError, "RouterInfo: Can't open file ", fullPath);
return false;
}
return true;
}
void RouterInfo::ReadFromFile ()
void RouterInfo::ReadFromFile (const std::string& fullPath)
{
if (LoadFile ())
if (LoadFile (fullPath))
ReadFromBuffer (false);
else
m_IsUnreachable = true;
@ -748,11 +748,11 @@ namespace data @@ -748,11 +748,11 @@ namespace data
return bufbe64toh (buf + size) > m_Timestamp;
}
const uint8_t * RouterInfo::LoadBuffer ()
const uint8_t * RouterInfo::LoadBuffer (const std::string& fullPath)
{
if (!m_Buffer)
{
if (LoadFile ())
if (LoadFile (fullPath))
LogPrint (eLogDebug, "RouterInfo: Buffer for ", GetIdentHashAbbreviation (GetIdentHash ()), " loaded from file");
}
return m_Buffer;
@ -783,8 +783,8 @@ namespace data @@ -783,8 +783,8 @@ namespace data
bool RouterInfo::SaveToFile (const std::string& fullPath)
{
m_FullPath = fullPath;
if (!m_Buffer) {
if (!m_Buffer)
{
LogPrint (eLogError, "RouterInfo: Can't save, m_Buffer == NULL");
return false;
}

8
libi2pd/RouterInfo.h

@ -226,7 +226,7 @@ namespace data @@ -226,7 +226,7 @@ namespace data
bool IsUnreachable () const { return m_IsUnreachable; };
const uint8_t * GetBuffer () const { return m_Buffer; };
const uint8_t * LoadBuffer (); // load if necessary
const uint8_t * LoadBuffer (const std::string& fullPath); // load if necessary
int GetBufferLen () const { return m_BufferLen; };
void CreateBuffer (const PrivateKeys& privateKeys);
@ -252,8 +252,8 @@ namespace data @@ -252,8 +252,8 @@ namespace data
private:
bool LoadFile ();
void ReadFromFile ();
bool LoadFile (const std::string& fullPath);
void ReadFromFile (const std::string& fullPath);
void ReadFromStream (std::istream& s);
void ReadFromBuffer (bool verifySignature);
void WriteToStream (std::ostream& s) const;
@ -267,7 +267,7 @@ namespace data @@ -267,7 +267,7 @@ namespace data
private:
std::string m_FullPath, m_Family;
std::string m_Family;
std::shared_ptr<const IdentityEx> m_RouterIdentity;
uint8_t * m_Buffer;
size_t m_BufferLen;

Loading…
Cancel
Save