From 052aee8f970da20a0eea176a33b145e6aa5ee58a Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 31 Jul 2013 07:50:34 -0700 Subject: [PATCH] Add 'hostid' to server_info * Add json::Value conversion from beast::String * Update rippled-example.cfg --- Notes/VFALCO_LOG.txt | 6 ++++ modules/ripple_app/basics/ripple_BuildInfo.h | 33 ------------------- modules/ripple_app/misc/NetworkOPs.cpp | 20 +++++++++-- modules/ripple_data/crypto/ripple_RFC1751.cpp | 10 +++++- modules/ripple_data/crypto/ripple_RFC1751.h | 9 +++++ modules/ripple_data/ripple_data.h | 1 + modules/ripple_json/json/json_value.cpp | 12 +++++++ modules/ripple_json/json/json_value.h | 1 + rippled-example.cfg | 2 ++ 9 files changed, 58 insertions(+), 36 deletions(-) diff --git a/Notes/VFALCO_LOG.txt b/Notes/VFALCO_LOG.txt index fb0a892f25..6e95e4ea8f 100644 --- a/Notes/VFALCO_LOG.txt +++ b/Notes/VFALCO_LOG.txt @@ -1,5 +1,11 @@ Vinnie Falco's Change Log +2013/07/31 + +- Add "hostname" to server_info output +- Replace "build_version" in server_info with the actual build version +- Remove "client_version" from server_info + 2013/07/30 - Add FatalErrorReporter to main diff --git a/modules/ripple_app/basics/ripple_BuildInfo.h b/modules/ripple_app/basics/ripple_BuildInfo.h index 1a97b85dd1..5aeb4fc933 100644 --- a/modules/ripple_app/basics/ripple_BuildInfo.h +++ b/modules/ripple_app/basics/ripple_BuildInfo.h @@ -107,39 +107,6 @@ struct BuildInfo /** The oldest protocol version we will accept. */ static Protocol const& getMinimumProtocol (); - - //-------------------------------------------------------------------------- - // - // DEPRECATED STUFF - // - - /** Retrieve the build version number. - - This is typically incremented when an official version is publshed - with a list of changes. - - Format is: - - .. - */ - static char const* getBuildVersion () - { - return "0.0.1"; - } - - /** Retrieve the client API version number. - - The client API version is incremented whenever a new feature - or breaking change is made to the websocket / RPC interface. - - Format is: - - - */ - static char const* getClientVersion () - { - return "1"; - } }; #endif diff --git a/modules/ripple_app/misc/NetworkOPs.cpp b/modules/ripple_app/misc/NetworkOPs.cpp index de64b67b3f..25ea4609f5 100644 --- a/modules/ripple_app/misc/NetworkOPs.cpp +++ b/modules/ripple_app/misc/NetworkOPs.cpp @@ -1387,12 +1387,28 @@ Json::Value NetworkOPs::getConsensusInfo () return info; } + Json::Value NetworkOPs::getServerInfo (bool human, bool admin) { Json::Value info = Json::objectValue; - info ["build_version"] = BuildInfo::getBuildVersion (); - info ["client_version"] = BuildInfo::getClientVersion (); + // 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 ["hostid"] = RFC1751::getWordFromBlob (addr.data (), addr.size ()); + } + else + { + // Only admins get the hostname for security reasons + info ["hostid"] = SystemStats::getComputerName(); + } + } + + info ["build_version"] = BuildInfo::getVersionString (); if (getConfig ().TESTNET) info["testnet"] = getConfig ().TESTNET; diff --git a/modules/ripple_data/crypto/ripple_RFC1751.cpp b/modules/ripple_data/crypto/ripple_RFC1751.cpp index 2bab8f2a70..d5e91a041f 100644 --- a/modules/ripple_data/crypto/ripple_RFC1751.cpp +++ b/modules/ripple_data/crypto/ripple_RFC1751.cpp @@ -470,4 +470,12 @@ void RFC1751::getEnglishFromKey (std::string& strHuman, const std::string& strKe strHuman = strFirst + " " + strSecond; } -// vim:ts=4 +String RFC1751::getWordFromBlob (void const* data, size_t bytes) +{ + uint32 hash; + + Murmur::Hash (data, bytes, 0, &hash); + + return s_dictionary [hash % (sizeof (s_dictionary) / sizeof (s_dictionary [0]))]; +} + diff --git a/modules/ripple_data/crypto/ripple_RFC1751.h b/modules/ripple_data/crypto/ripple_RFC1751.h index 3a612b410d..1f83d5d3f5 100644 --- a/modules/ripple_data/crypto/ripple_RFC1751.h +++ b/modules/ripple_data/crypto/ripple_RFC1751.h @@ -14,6 +14,15 @@ public: static void getEnglishFromKey (std::string& strHuman, const std::string& strKey); + /** Chooses a single dictionary word from the data. + + This is not particularly secure but it can be useful to provide + a unique name for something given a GUID or fixed data. We use + it to turn the pubkey_node into an easily remembered and identified + 4 character string. + */ + static String getWordFromBlob (void const* data, size_t bytes); + private: static unsigned long extract (char* s, int start, int length); static void btoe (std::string& strHuman, const std::string& strData); diff --git a/modules/ripple_data/ripple_data.h b/modules/ripple_data/ripple_data.h index 82fd48c93c..c24302cf87 100644 --- a/modules/ripple_data/ripple_data.h +++ b/modules/ripple_data/ripple_data.h @@ -33,6 +33,7 @@ namespace ripple #include "crypto/ripple_CBigNum.h" #include "crypto/ripple_Base58.h" // VFALCO TODO Can be moved to .cpp if we clean up setAlphabet stuff #include "crypto/ripple_Base58Data.h" +#include "crypto/ripple_RFC1751.h" #include "protocol/ripple_FieldNames.h" #include "protocol/ripple_HashPrefix.h" diff --git a/modules/ripple_json/json/json_value.cpp b/modules/ripple_json/json/json_value.cpp index 4e732fac7f..43c4237ea2 100644 --- a/modules/ripple_json/json/json_value.cpp +++ b/modules/ripple_json/json/json_value.cpp @@ -377,6 +377,18 @@ Value::Value ( const std::string& value ) value_.string_ = valueAllocator ()->duplicateStringValue ( value.c_str (), (unsigned int)value.length () ); +} +Value::Value (beast::String const& beastString) + : type_ ( stringValue ) + , allocated_ ( true ) + , comments_ ( 0 ) +# ifdef JSON_VALUE_USE_INTERNAL_MAP + , itemIsUsed_ ( 0 ) +#endif +{ + value_.string_ = valueAllocator ()->duplicateStringValue ( beastString.toStdString ().c_str (), + (unsigned int)beastString.length () ); + } Value::Value ( const StaticString& value ) diff --git a/modules/ripple_json/json/json_value.h b/modules/ripple_json/json/json_value.h index 204da7d590..d24f6bbf1c 100644 --- a/modules/ripple_json/json/json_value.h +++ b/modules/ripple_json/json/json_value.h @@ -193,6 +193,7 @@ public: */ Value ( const StaticString& value ); Value ( const std::string& value ); + Value (beast::String const& beastString); # ifdef JSON_USE_CPPTL Value ( const CppTL::ConstString& value ); # endif diff --git a/rippled-example.cfg b/rippled-example.cfg index bca5916b0c..aacc9fac13 100644 --- a/rippled-example.cfg +++ b/rippled-example.cfg @@ -108,6 +108,8 @@ # # [rpc_admin_allow] # Specify an list of IP addresses allowed to have admin access. One per line. +# If you want to test the output of non-admin commands add this section and +# just put an ip address not under your control. # # Defaults to 127.0.0.1. #