Browse Source

moved save to file to RI

pull/81/head
orignal 10 years ago
parent
commit
ad65e52ce0
  1. 2
      I2NPProtocol.cpp
  2. 3
      NetDb.cpp
  3. 3
      RouterContext.cpp
  4. 10
      RouterInfo.cpp
  5. 9
      RouterInfo.h

2
I2NPProtocol.cpp

@ -200,7 +200,7 @@ namespace i2p
msg->replyToken = 0; msg->replyToken = 0;
CryptoPP::Gzip compressor; CryptoPP::Gzip compressor;
compressor.Put ((uint8_t *)context.GetRouterInfo ().GetBuffer (), context.GetRouterInfo ().GetBufferLen ()); compressor.Put (context.GetRouterInfo ().GetBuffer (), context.GetRouterInfo ().GetBufferLen ());
compressor.MessageEnd(); compressor.MessageEnd();
// WARNING!!! MaxRetrievable() return uint64_t. Åñòü ïîäîçðåíèå, ÷òî ÷òî-òî íå òàê // WARNING!!! MaxRetrievable() return uint64_t. Åñòü ïîäîçðåíèå, ÷òî ÷òî-òî íå òàê
int size = compressor.MaxRetrievable (); int size = compressor.MaxRetrievable ();

3
NetDb.cpp

@ -307,8 +307,7 @@ namespace data
{ {
if (it.second->IsUpdated ()) if (it.second->IsUpdated ())
{ {
std::ofstream r (GetFilePath(fullDirectory, it.second), std::ofstream::binary); it.second->SaveToFile (GetFilePath(fullDirectory, it.second));
r.write ((char *)it.second->GetBuffer (), it.second->GetBufferLen ());
it.second->SetUpdated (false); it.second->SetUpdated (false);
count++; count++;
} }

3
RouterContext.cpp

@ -92,7 +92,6 @@ namespace i2p
fk.write ((char *)&m_Keys, sizeof (m_Keys)); fk.write ((char *)&m_Keys, sizeof (m_Keys));
} }
std::ofstream fi (i2p::util::filesystem::GetFullPath (ROUTER_INFO).c_str (), std::ofstream::binary | std::ofstream::out); m_RouterInfo.SaveToFile (i2p::util::filesystem::GetFullPath (ROUTER_INFO));
fi.write ((char *)m_RouterInfo.GetBuffer (), m_RouterInfo.GetBufferLen ());
} }
} }

10
RouterInfo.cpp

@ -53,7 +53,7 @@ namespace data
return; return;
} }
s.seekg(0, std::ios::beg); s.seekg(0, std::ios::beg);
s.read(m_Buffer,m_BufferLen); s.read((char *)m_Buffer, m_BufferLen);
ReadFromBuffer (); ReadFromBuffer ();
} }
else else
@ -62,7 +62,7 @@ namespace data
void RouterInfo::ReadFromBuffer () void RouterInfo::ReadFromBuffer ()
{ {
std::stringstream str (std::string (m_Buffer, m_BufferLen)); std::stringstream str (std::string ((char *)m_Buffer, m_BufferLen));
ReadFromStream (str); ReadFromStream (str);
// verify signature // verify signature
CryptoPP::DSA::PublicKey pubKey; CryptoPP::DSA::PublicKey pubKey;
@ -322,6 +322,12 @@ namespace data
i2p::context.Sign ((uint8_t *)m_Buffer, m_BufferLen, (uint8_t *)m_Buffer + m_BufferLen); i2p::context.Sign ((uint8_t *)m_Buffer, m_BufferLen, (uint8_t *)m_Buffer + m_BufferLen);
m_BufferLen += 40; m_BufferLen += 40;
} }
void RouterInfo::SaveToFile (const std::string& fullPath)
{
std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out);
f.write ((char *)m_Buffer, m_BufferLen);
}
size_t RouterInfo::ReadString (char * str, std::istream& s) size_t RouterInfo::ReadString (char * str, std::istream& s)
{ {

9
RouterInfo.h

@ -13,6 +13,7 @@ namespace i2p
{ {
namespace data namespace data
{ {
const int MAX_RI_BUFFER_SIZE = 2048;
class RouterInfo: public RoutingDestination class RouterInfo: public RoutingDestination
{ {
public: public:
@ -95,14 +96,16 @@ namespace data
void SetUnreachable (bool unreachable) { m_IsUnreachable = unreachable; }; void SetUnreachable (bool unreachable) { m_IsUnreachable = unreachable; };
bool IsUnreachable () const { return m_IsUnreachable; }; bool IsUnreachable () const { return m_IsUnreachable; };
const uint8_t * GetBuffer () const { return m_Buffer; };
int GetBufferLen () const { return m_BufferLen; };
void CreateBuffer (); void CreateBuffer ();
void UpdateRoutingKey (); void UpdateRoutingKey ();
const char * GetBuffer () const { return m_Buffer; };
int GetBufferLen () const { return m_BufferLen; };
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; };
void SaveToFile (const std::string& fullPath);
// implements RoutingDestination // implements RoutingDestination
const IdentHash& GetIdentHash () const { return m_IdentHash; }; const IdentHash& GetIdentHash () const { return m_IdentHash; };
@ -127,7 +130,7 @@ namespace data
IdentHash m_IdentHash; IdentHash m_IdentHash;
RoutingKey m_RoutingKey; RoutingKey m_RoutingKey;
char m_IdentHashBase64[48], m_IdentHashAbbreviation[5]; char m_IdentHashBase64[48], m_IdentHashAbbreviation[5];
char m_Buffer[2048]; uint8_t m_Buffer[MAX_RI_BUFFER_SIZE];
int m_BufferLen; int m_BufferLen;
uint64_t m_Timestamp; uint64_t m_Timestamp;
std::vector<Address> m_Addresses; std::vector<Address> m_Addresses;

Loading…
Cancel
Save