From 1408422da9da45405e271380d9842965a00ec78f Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 25 Oct 2014 22:23:28 -0400 Subject: [PATCH] some cleanup --- RouterInfo.cpp | 12 +----------- RouterInfo.h | 8 +++----- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/RouterInfo.cpp b/RouterInfo.cpp index 0793e996..c88ae02c 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -59,7 +59,6 @@ namespace data { m_RouterIdentity = identity; m_IdentHash = m_RouterIdentity.Hash (); - UpdateIdentHashBase64 (); m_Timestamp = i2p::util::GetMillisecondsSinceEpoch (); } @@ -226,7 +225,6 @@ namespace data } CryptoPP::SHA256().CalculateDigest(m_IdentHash, (uint8_t *)&m_RouterIdentity, sizeof (m_RouterIdentity)); - UpdateIdentHashBase64 (); if (!m_SupportedTransports || !m_Addresses.size() || (UsesIntroducer () && !introducers)) SetUnreachable (true); @@ -279,14 +277,6 @@ namespace data 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) { @@ -409,7 +399,7 @@ namespace data if (!m_Buffer) { if (LoadFile ()) - LogPrint ("Buffer for ", m_IdentHashAbbreviation, " loaded from file"); + LogPrint ("Buffer for ", GetIdentHashAbbreviation (), " loaded from file"); } return m_Buffer; } diff --git a/RouterInfo.h b/RouterInfo.h index 669c85bd..a4ccb159 100644 --- a/RouterInfo.h +++ b/RouterInfo.h @@ -78,7 +78,7 @@ namespace data }; 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& operator=(const RouterInfo& ) = default; RouterInfo (const uint8_t * buf, int len); @@ -86,8 +86,8 @@ namespace data const Identity& GetRouterIdentity () const { return m_RouterIdentity; }; void SetRouterIdentity (const Identity& identity); - const char * GetIdentHashBase64 () const { return m_IdentHashBase64; }; - const char * GetIdentHashAbbreviation () const { return m_IdentHashAbbreviation; }; + std::string GetIdentHashBase64 () const { return m_IdentHash.ToBase64 (); }; + std::string GetIdentHashAbbreviation () const { return m_IdentHash.ToBase64 ().substr (0, 4); }; uint64_t GetTimestamp () const { return m_Timestamp; }; std::vector
& GetAddresses () { return m_Addresses; }; const Address * GetNTCPAddress (bool v4only = true) const; @@ -143,7 +143,6 @@ namespace data size_t ReadString (char * str, std::istream& s); void WriteString (const std::string& str, std::ostream& s); void ExtractCaps (const char * value); - void UpdateIdentHashBase64 (); const Address * GetAddress (TransportStyle s, bool v4only) const; void UpdateCapsProperty (); @@ -152,7 +151,6 @@ namespace data std::string m_FullPath; Identity m_RouterIdentity; IdentHash m_IdentHash; - char m_IdentHashBase64[48], m_IdentHashAbbreviation[5]; uint8_t * m_Buffer; int m_BufferLen; uint64_t m_Timestamp;