Browse Source

some cleanup

pull/106/head
orignal 10 years ago
parent
commit
1408422da9
  1. 12
      RouterInfo.cpp
  2. 8
      RouterInfo.h

12
RouterInfo.cpp

@ -59,7 +59,6 @@ namespace data
{ {
m_RouterIdentity = identity; m_RouterIdentity = identity;
m_IdentHash = m_RouterIdentity.Hash (); m_IdentHash = m_RouterIdentity.Hash ();
UpdateIdentHashBase64 ();
m_Timestamp = i2p::util::GetMillisecondsSinceEpoch (); m_Timestamp = i2p::util::GetMillisecondsSinceEpoch ();
} }
@ -226,7 +225,6 @@ namespace data
} }
CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&m_RouterIdentity, sizeof (m_RouterIdentity)); CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&m_RouterIdentity, sizeof (m_RouterIdentity));
UpdateIdentHashBase64 ();
if (!m_SupportedTransports || !m_Addresses.size() || (UsesIntroducer () && !introducers)) if (!m_SupportedTransports || !m_Addresses.size() || (UsesIntroducer () && !introducers))
SetUnreachable (true); SetUnreachable (true);
@ -279,14 +277,6 @@ namespace data
SetProperty ("caps", caps.c_str ()); SetProperty ("caps", caps.c_str ());
} }
void RouterInfo::UpdateIdentHashBase64 ()
{
size_t l = i2p::data::ByteStreamToBase64 (m_IdentHash, 32, m_IdentHashBase64, 48);
m_IdentHashBase64[l] = 0;
memcpy (m_IdentHashAbbreviation, m_IdentHashBase64, 4);
m_IdentHashAbbreviation[4] = 0;
}
void RouterInfo::WriteToStream (std::ostream& s) void RouterInfo::WriteToStream (std::ostream& s)
{ {
@ -409,7 +399,7 @@ namespace data
if (!m_Buffer) if (!m_Buffer)
{ {
if (LoadFile ()) if (LoadFile ())
LogPrint ("Buffer for ", m_IdentHashAbbreviation, " loaded from file"); LogPrint ("Buffer for ", GetIdentHashAbbreviation (), " loaded from file");
} }
return m_Buffer; return m_Buffer;
} }

8
RouterInfo.h

@ -78,7 +78,7 @@ namespace data
}; };
RouterInfo (const std::string& fullPath); RouterInfo (const std::string& fullPath);
RouterInfo (): m_Buffer (nullptr) { m_IdentHashBase64[0] = 0; m_IdentHashAbbreviation[0] = 0; }; RouterInfo (): m_Buffer (nullptr) { };
RouterInfo (const RouterInfo& ) = default; RouterInfo (const RouterInfo& ) = default;
RouterInfo& operator=(const RouterInfo& ) = default; RouterInfo& operator=(const RouterInfo& ) = default;
RouterInfo (const uint8_t * buf, int len); RouterInfo (const uint8_t * buf, int len);
@ -86,8 +86,8 @@ namespace data
const Identity& GetRouterIdentity () const { return m_RouterIdentity; }; const Identity& GetRouterIdentity () const { return m_RouterIdentity; };
void SetRouterIdentity (const Identity& identity); void SetRouterIdentity (const Identity& identity);
const char * GetIdentHashBase64 () const { return m_IdentHashBase64; }; std::string GetIdentHashBase64 () const { return m_IdentHash.ToBase64 (); };
const char * GetIdentHashAbbreviation () const { return m_IdentHashAbbreviation; }; std::string GetIdentHashAbbreviation () const { return m_IdentHash.ToBase64 ().substr (0, 4); };
uint64_t GetTimestamp () const { return m_Timestamp; }; uint64_t GetTimestamp () const { return m_Timestamp; };
std::vector<Address>& GetAddresses () { return m_Addresses; }; std::vector<Address>& GetAddresses () { return m_Addresses; };
const Address * GetNTCPAddress (bool v4only = true) const; const Address * GetNTCPAddress (bool v4only = true) const;
@ -143,7 +143,6 @@ namespace data
size_t ReadString (char * str, std::istream& s); size_t ReadString (char * str, std::istream& s);
void WriteString (const std::string& str, std::ostream& s); void WriteString (const std::string& str, std::ostream& s);
void ExtractCaps (const char * value); void ExtractCaps (const char * value);
void UpdateIdentHashBase64 ();
const Address * GetAddress (TransportStyle s, bool v4only) const; const Address * GetAddress (TransportStyle s, bool v4only) const;
void UpdateCapsProperty (); void UpdateCapsProperty ();
@ -152,7 +151,6 @@ namespace data
std::string m_FullPath; std::string m_FullPath;
Identity m_RouterIdentity; Identity m_RouterIdentity;
IdentHash m_IdentHash; IdentHash m_IdentHash;
char m_IdentHashBase64[48], m_IdentHashAbbreviation[5];
uint8_t * m_Buffer; uint8_t * m_Buffer;
int m_BufferLen; int m_BufferLen;
uint64_t m_Timestamp; uint64_t m_Timestamp;

Loading…
Cancel
Save