Remove sole use of beast::MurmurHash

This commit is contained in:
Nik Bougalis
2014-11-07 12:41:50 -08:00
parent 68e46e406a
commit b7b744de94
6 changed files with 35 additions and 50 deletions

View File

@@ -279,9 +279,6 @@
<ClCompile Include="..\..\src\beast\beast\crypto\Crypto.unity.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\beast\beast\crypto\impl\MurmurHash.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\beast\beast\crypto\impl\Sha256.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
@@ -290,8 +287,6 @@
</ClCompile>
<ClInclude Include="..\..\src\beast\beast\crypto\impl\sha2\sha2.h">
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\crypto\MurmurHash.h">
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\crypto\Sha256.h">
</ClInclude>
<ClCompile Include="..\..\src\beast\beast\crypto\tests\base64.test.cpp">

View File

@@ -780,9 +780,6 @@
<ClCompile Include="..\..\src\beast\beast\crypto\Crypto.unity.cpp">
<Filter>beast\crypto</Filter>
</ClCompile>
<ClCompile Include="..\..\src\beast\beast\crypto\impl\MurmurHash.cpp">
<Filter>beast\crypto\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\beast\beast\crypto\impl\Sha256.cpp">
<Filter>beast\crypto\impl</Filter>
</ClCompile>
@@ -792,9 +789,6 @@
<ClInclude Include="..\..\src\beast\beast\crypto\impl\sha2\sha2.h">
<Filter>beast\crypto\impl\sha2</Filter>
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\crypto\MurmurHash.h">
<Filter>beast\crypto</Filter>
</ClInclude>
<ClInclude Include="..\..\src\beast\beast\crypto\Sha256.h">
<Filter>beast\crypto</Filter>
</ClInclude>

View File

@@ -506,6 +506,8 @@ private:
void pubServer ();
std::string getHostId (bool forAdmin);
private:
clock_type& m_clock;
@@ -581,6 +583,19 @@ private:
};
//------------------------------------------------------------------------------
std::string
NetworkOPsImp::getHostId (bool forAdmin)
{
if (forAdmin)
return beast::SystemStats::getComputerName ();
// For non-admin uses we hash the node ID into a single RFC1751 word:
// (this could be cached instead of recalculated every time)
Blob const& addr (getApp ().getLocalCredentials ().getNodePublic ().
getNodePublic ());
return RFC1751::getWordFromBlob (addr.data (), addr.size ());
}
void NetworkOPsImp::setStateTimer ()
{
@@ -2344,22 +2359,7 @@ Json::Value NetworkOPsImp::getServerInfo (bool human, bool admin)
// hostid: unique string describing the machine
if (human)
{
if (! admin)
{
// For a non admin connection, hash the node ID into a single
// RFC1751 word.
Blob const& addr (getApp().getLocalCredentials ().getNodePublic ().
getNodePublic ());
info [jss::hostid] = RFC1751::getWordFromBlob (
addr.data (), addr.size ());
}
else
{
// Only admins get the hostname for security reasons
info [jss::hostid] = beast::SystemStats::getComputerName();
}
}
info [jss::hostid] = getHostId (admin);
info [jss::build_version] = BuildInfo::getVersionString ();
@@ -2999,23 +2999,10 @@ bool NetworkOPsImp::subServer (InfoSub::ref isrListener, Json::Value& jvResult,
jvResult[jss::server_status] = strOperatingMode ();
jvResult[jss::load_base] = getApp().getFeeTrack ().getLoadBase ();
jvResult[jss::load_factor] = getApp().getFeeTrack ().getLoadFactor ();
jvResult [jss::hostid] = getHostId (admin);
jvResult[jss::pubkey_node] = getApp ().getLocalCredentials ().
getNodePublic ().humanNodePublic ();
if (! admin)
{
// For a non admin connection, hash the node ID into a single RFC1751 word
Blob const& addr (getApp ().getLocalCredentials ().getNodePublic ().
getNodePublic ());
jvResult[jss::hostid] = RFC1751::getWordFromBlob (addr.data (),
addr.size ());
}
else
{
// Only admins get the hostname for security reasons
jvResult[jss::hostid] = beast::SystemStats::getComputerName ();
}
ScopedLockType sl (mLock);
return mSubServer.emplace (isrListener->getSeq (), isrListener).second;
}

View File

@@ -39,7 +39,7 @@ public:
it to turn the pubkey_node into an easily remembered and identified
4 character string.
*/
static std::string getWordFromBlob (void const* data, size_t bytes);
static std::string getWordFromBlob (void const* blob, size_t bytes);
private:
static unsigned long extract (char const* s, int start, int length);

View File

@@ -18,7 +18,6 @@
//==============================================================================
#include <ripple/crypto/RFC1751.h>
#include <beast/crypto/MurmurHash.h>
#include <boost/algorithm/string.hpp>
#include <boost/range/adaptor/copied.hpp>
#include <boost/foreach.hpp>
@@ -482,14 +481,25 @@ void RFC1751::getEnglishFromKey (std::string& strHuman, std::string const& strKe
strHuman = strFirst + " " + strSecond;
}
std::string RFC1751::getWordFromBlob (void const* data, size_t bytes)
std::string
RFC1751::getWordFromBlob (void const* blob, size_t bytes)
{
std::uint32_t hash;
// This is a simple implementation of the Jenkins one-at-a-time hash
// algorithm:
// http://en.wikipedia.org/wiki/Jenkins_hash_function#one-at-a-time
unsigned char const* data = static_cast<unsigned char const*>(blob);
std::uint32_t hash = 0;
// VFALCO Murmur is deprecated and since this does not need to be
// cryptographically secure we should just replace it with something
// else and remove Murmur from beast.
beast::Murmur::Hash (data, bytes, 0, &hash);
for (size_t i = 0; i < bytes; ++i)
{
hash += data[i];
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return s_dictionary [hash % (sizeof (s_dictionary) / sizeof (s_dictionary [0]))];
}

View File

@@ -20,7 +20,6 @@
#ifndef RIPPLE_TYPES_IDENTIFIERSTORAGE_H_INCLUDED
#define RIPPLE_TYPES_IDENTIFIERSTORAGE_H_INCLUDED
#include <beast/crypto/MurmurHash.h>
#include <beast/container/hardened_hash.h>
#include <array>
#include <cassert>