mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
don't store full path with RouterInfo
This commit is contained in:
parent
49e8cf89d8
commit
48131f4597
@ -963,7 +963,8 @@ namespace data
|
|||||||
if (router)
|
if (router)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "NetDb: requested RouterInfo ", key, " found");
|
LogPrint (eLogDebug, "NetDb: requested RouterInfo ", key, " found");
|
||||||
router->LoadBuffer ();
|
if (!router->GetBuffer ())
|
||||||
|
router->LoadBuffer (m_Storage.Path (router->GetIdentHashBase64 ()));
|
||||||
if (router->GetBuffer ())
|
if (router->GetBuffer ())
|
||||||
replyMsg = CreateDatabaseStoreMsg (router);
|
replyMsg = CreateDatabaseStoreMsg (router);
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,12 @@ namespace data
|
|||||||
}
|
}
|
||||||
|
|
||||||
RouterInfo::RouterInfo (const std::string& fullPath):
|
RouterInfo::RouterInfo (const std::string& fullPath):
|
||||||
m_FullPath (fullPath), m_IsUpdated (false), m_IsUnreachable (false),
|
m_IsUpdated (false), m_IsUnreachable (false), m_SupportedTransports (0),
|
||||||
m_SupportedTransports (0), m_ReachableTransports (0), m_Caps (0), m_Version (0)
|
m_ReachableTransports (0), m_Caps (0), m_Version (0)
|
||||||
{
|
{
|
||||||
m_Addresses = boost::make_shared<Addresses>(); // create empty list
|
m_Addresses = boost::make_shared<Addresses>(); // create empty list
|
||||||
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE];
|
m_Buffer = new uint8_t[MAX_RI_BUFFER_SIZE];
|
||||||
ReadFromFile ();
|
ReadFromFile (fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
RouterInfo::RouterInfo (const uint8_t * buf, int len):
|
RouterInfo::RouterInfo (const uint8_t * buf, int len):
|
||||||
@ -113,16 +113,16 @@ namespace data
|
|||||||
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch ();
|
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 ())
|
if (s.is_open ())
|
||||||
{
|
{
|
||||||
s.seekg (0,std::ios::end);
|
s.seekg (0,std::ios::end);
|
||||||
m_BufferLen = s.tellg ();
|
m_BufferLen = s.tellg ();
|
||||||
if (m_BufferLen < 40 || m_BufferLen > MAX_RI_BUFFER_SIZE)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
s.seekg(0, std::ios::beg);
|
s.seekg(0, std::ios::beg);
|
||||||
@ -131,15 +131,15 @@ namespace data
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "RouterInfo: Can't open file ", m_FullPath);
|
LogPrint (eLogError, "RouterInfo: Can't open file ", fullPath);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterInfo::ReadFromFile ()
|
void RouterInfo::ReadFromFile (const std::string& fullPath)
|
||||||
{
|
{
|
||||||
if (LoadFile ())
|
if (LoadFile (fullPath))
|
||||||
ReadFromBuffer (false);
|
ReadFromBuffer (false);
|
||||||
else
|
else
|
||||||
m_IsUnreachable = true;
|
m_IsUnreachable = true;
|
||||||
@ -748,11 +748,11 @@ namespace data
|
|||||||
return bufbe64toh (buf + size) > m_Timestamp;
|
return bufbe64toh (buf + size) > m_Timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t * RouterInfo::LoadBuffer ()
|
const uint8_t * RouterInfo::LoadBuffer (const std::string& fullPath)
|
||||||
{
|
{
|
||||||
if (!m_Buffer)
|
if (!m_Buffer)
|
||||||
{
|
{
|
||||||
if (LoadFile ())
|
if (LoadFile (fullPath))
|
||||||
LogPrint (eLogDebug, "RouterInfo: Buffer for ", GetIdentHashAbbreviation (GetIdentHash ()), " loaded from file");
|
LogPrint (eLogDebug, "RouterInfo: Buffer for ", GetIdentHashAbbreviation (GetIdentHash ()), " loaded from file");
|
||||||
}
|
}
|
||||||
return m_Buffer;
|
return m_Buffer;
|
||||||
@ -783,8 +783,8 @@ namespace data
|
|||||||
|
|
||||||
bool RouterInfo::SaveToFile (const std::string& fullPath)
|
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");
|
LogPrint (eLogError, "RouterInfo: Can't save, m_Buffer == NULL");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ namespace data
|
|||||||
bool IsUnreachable () const { return m_IsUnreachable; };
|
bool IsUnreachable () const { return m_IsUnreachable; };
|
||||||
|
|
||||||
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 (const std::string& fullPath); // 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);
|
||||||
|
|
||||||
@ -252,8 +252,8 @@ namespace data
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool LoadFile ();
|
bool LoadFile (const std::string& fullPath);
|
||||||
void ReadFromFile ();
|
void ReadFromFile (const std::string& fullPath);
|
||||||
void ReadFromStream (std::istream& s);
|
void ReadFromStream (std::istream& s);
|
||||||
void ReadFromBuffer (bool verifySignature);
|
void ReadFromBuffer (bool verifySignature);
|
||||||
void WriteToStream (std::ostream& s) const;
|
void WriteToStream (std::ostream& s) const;
|
||||||
@ -267,7 +267,7 @@ namespace data
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string m_FullPath, m_Family;
|
std::string m_Family;
|
||||||
std::shared_ptr<const IdentityEx> m_RouterIdentity;
|
std::shared_ptr<const IdentityEx> m_RouterIdentity;
|
||||||
uint8_t * m_Buffer;
|
uint8_t * m_Buffer;
|
||||||
size_t m_BufferLen;
|
size_t m_BufferLen;
|
||||||
|
Loading…
Reference in New Issue
Block a user