mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add PropertyStream for server state introspection
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_JSONPROPERTYSTREAMSINK_H_INCLUDED
|
||||
#define RIPPLE_JSONPROPERTYSTREAMSINK_H_INCLUDED
|
||||
|
||||
#include "beast/beast/utility/PropertyStream.h"
|
||||
|
||||
//#include "json_value.h" // ??
|
||||
|
||||
namespace ripple {
|
||||
using namespace beast;
|
||||
|
||||
/** A PropertyStream::Sink which produces a Json::Value. */
|
||||
class JsonPropertyStreamSink : public PropertyStream::Sink
|
||||
{
|
||||
public:
|
||||
explicit JsonPropertyStreamSink (Json::Value& root)
|
||||
{
|
||||
m_stack.push_back (&root);
|
||||
}
|
||||
|
||||
void begin_object (std::string const& key)
|
||||
{
|
||||
m_stack.push_back (&((*m_stack.back())[key] = Json::objectValue));
|
||||
}
|
||||
|
||||
void end_object ()
|
||||
{
|
||||
m_stack.pop_back ();
|
||||
}
|
||||
|
||||
void write (std::string const& key, int32 v)
|
||||
{
|
||||
(*m_stack.back())[key] = v;
|
||||
}
|
||||
|
||||
void write (std::string const& key, uint32 v)
|
||||
{
|
||||
(*m_stack.back())[key] = v;
|
||||
}
|
||||
|
||||
void write (std::string const& key, std::string const& v)
|
||||
{
|
||||
(*m_stack.back())[key] = v;
|
||||
}
|
||||
|
||||
void begin_array (std::string const& key)
|
||||
{
|
||||
m_stack.push_back (&((*m_stack.back())[key] = Json::arrayValue));
|
||||
}
|
||||
|
||||
void end_array ()
|
||||
{
|
||||
m_stack.pop_back ();
|
||||
}
|
||||
|
||||
void write (int32 v)
|
||||
{
|
||||
m_stack.back()->append (v);
|
||||
}
|
||||
|
||||
void write (uint32 v)
|
||||
{
|
||||
m_stack.back()->append (v);
|
||||
}
|
||||
|
||||
void write (std::string const& v)
|
||||
{
|
||||
m_stack.back()->append (v);
|
||||
}
|
||||
|
||||
private:
|
||||
Json::Value m_value;
|
||||
std::vector <Json::Value*> m_stack;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,15 +20,6 @@
|
||||
|
||||
#include "BeastConfig.h"
|
||||
|
||||
#include "beast/modules/beast_core/beast_core.h"
|
||||
|
||||
#include "ripple_json.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
// For json/
|
||||
//
|
||||
#ifdef JSON_USE_CPPTL
|
||||
@@ -38,6 +29,15 @@
|
||||
#include "impl/json_batchallocator.h"
|
||||
#endif
|
||||
|
||||
#include "beast/modules/beast_core/beast_core.h"
|
||||
|
||||
#include "ripple_json.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#define JSON_ASSERT_UNREACHABLE assert( false )
|
||||
#define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw
|
||||
#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message );
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
|
||||
#include "beast/beast/Config.h"
|
||||
|
||||
#include "beast/beast/strings/String.h"
|
||||
#include "beast/beast/utility/PropertyStream.h"
|
||||
|
||||
#include <deque>
|
||||
#include <stack>
|
||||
#include <vector>
|
||||
@@ -45,6 +48,4 @@
|
||||
#include "api/json_reader.h"
|
||||
#include "api/json_writer.h"
|
||||
|
||||
#include "api/JsonPropertyStreamSink.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -317,22 +317,20 @@ public:
|
||||
// PropertyStream
|
||||
//
|
||||
|
||||
void onWrite (PropertyStream stream)
|
||||
void onWrite (PropertyStream::Map& map)
|
||||
{
|
||||
SerializedContext::Scope scope (m_context);
|
||||
|
||||
// VFALCO NOTE this is not thread safe (yet)
|
||||
|
||||
stream ["peers"] = m_logic.m_slots.peerCount;
|
||||
stream ["in"] = m_logic.m_slots.inboundCount;
|
||||
stream ["out"] = m_logic.m_slots.outboundCount;
|
||||
stream ["out_desired"] = m_logic.m_slots.outDesired;
|
||||
stream ["in_avail"] = m_logic.m_slots.inboundSlots;
|
||||
stream ["in_max"] = m_logic.m_slots.inboundSlotsMaximum;
|
||||
stream ["minutes"] = m_logic.m_slots.uptimeMinutes();
|
||||
stream ["round"] = m_logic.m_slots.roundUpwards();
|
||||
stream ["cache"] = uint32(m_logic.m_cache.size());
|
||||
stream ["legacy"] = uint32(m_logic.m_legacyCache.size());
|
||||
map ["peers"] = m_logic.m_slots.peerCount;
|
||||
map ["in"] = m_logic.m_slots.inboundCount;
|
||||
map ["out"] = m_logic.m_slots.outboundCount;
|
||||
map ["out_desired"] = m_logic.m_slots.outDesired;
|
||||
map ["in_avail"] = m_logic.m_slots.inboundSlots;
|
||||
map ["in_max"] = m_logic.m_slots.inboundSlotsMaximum;
|
||||
map ["minutes"] = m_logic.m_slots.uptimeMinutes();
|
||||
map ["round"] = m_logic.m_slots.roundUpwards();
|
||||
map ["cache"] = uint32(m_logic.m_cache.size());
|
||||
map ["legacy"] = uint32(m_logic.m_legacyCache.size());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
55
src/ripple/types/api/JsonPropertyStream.h
Normal file
55
src/ripple/types/api/JsonPropertyStream.h
Normal file
@@ -0,0 +1,55 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_JSONPROPERTYSTREAM_H_INCLUDED
|
||||
#define RIPPLE_JSONPROPERTYSTREAM_H_INCLUDED
|
||||
|
||||
namespace ripple {
|
||||
|
||||
/** A PropertyStream::Sink which produces a Json::Value. */
|
||||
class JsonPropertyStream : public PropertyStream
|
||||
{
|
||||
public:
|
||||
Json::Value m_top;
|
||||
std::vector <Json::Value*> m_stack;
|
||||
|
||||
public:
|
||||
JsonPropertyStream ();
|
||||
Json::Value const& top() const;
|
||||
|
||||
protected:
|
||||
|
||||
void map_begin ();
|
||||
void map_begin (std::string const& key);
|
||||
void map_end ();
|
||||
void add (std::string const& key, int32 v);
|
||||
void add (std::string const& key, uint32 v);
|
||||
void add (std::string const& key, std::string const& v);
|
||||
void array_begin ();
|
||||
void array_begin (std::string const& key);
|
||||
void array_end ();
|
||||
void add (int32 v);
|
||||
void add (uint32 v);
|
||||
void add (std::string const& v);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
107
src/ripple/types/impl/JsonPropertyStream.cpp
Normal file
107
src/ripple/types/impl/JsonPropertyStream.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace ripple {
|
||||
|
||||
JsonPropertyStream::JsonPropertyStream ()
|
||||
: m_top (Json::objectValue)
|
||||
{
|
||||
m_stack.reserve (64);
|
||||
m_stack.push_back (&m_top);
|
||||
}
|
||||
|
||||
Json::Value const& JsonPropertyStream::top() const
|
||||
{
|
||||
return m_top;
|
||||
}
|
||||
|
||||
void JsonPropertyStream::map_begin ()
|
||||
{
|
||||
// top is array
|
||||
Json::Value& top (*m_stack.back());
|
||||
Json::Value& map (top.append (Json::objectValue));
|
||||
m_stack.push_back (&map);
|
||||
}
|
||||
|
||||
void JsonPropertyStream::map_begin (std::string const& key)
|
||||
{
|
||||
// top is a map
|
||||
Json::Value& top (*m_stack.back());
|
||||
Json::Value& map (top [key] = Json::objectValue);
|
||||
m_stack.push_back (&map);
|
||||
}
|
||||
|
||||
void JsonPropertyStream::map_end ()
|
||||
{
|
||||
m_stack.pop_back ();
|
||||
}
|
||||
|
||||
void JsonPropertyStream::add (std::string const& key, int32 v)
|
||||
{
|
||||
(*m_stack.back())[key] = v;
|
||||
}
|
||||
|
||||
void JsonPropertyStream::add (std::string const& key, uint32 v)
|
||||
{
|
||||
(*m_stack.back())[key] = v;
|
||||
}
|
||||
|
||||
void JsonPropertyStream::add (std::string const& key, std::string const& v)
|
||||
{
|
||||
(*m_stack.back())[key] = v;
|
||||
}
|
||||
|
||||
void JsonPropertyStream::array_begin ()
|
||||
{
|
||||
// top is array
|
||||
Json::Value& top (*m_stack.back());
|
||||
Json::Value& vec (top.append (Json::arrayValue));
|
||||
m_stack.push_back (&vec);
|
||||
}
|
||||
|
||||
void JsonPropertyStream::array_begin (std::string const& key)
|
||||
{
|
||||
// top is a map
|
||||
Json::Value& top (*m_stack.back());
|
||||
Json::Value& vec (top [key] = Json::arrayValue);
|
||||
m_stack.push_back (&vec);
|
||||
}
|
||||
|
||||
void JsonPropertyStream::array_end ()
|
||||
{
|
||||
m_stack.pop_back ();
|
||||
}
|
||||
|
||||
void JsonPropertyStream::add (int32 v)
|
||||
{
|
||||
m_stack.back()->append (v);
|
||||
}
|
||||
|
||||
void JsonPropertyStream::add (uint32 v)
|
||||
{
|
||||
m_stack.back()->append (v);
|
||||
}
|
||||
|
||||
void JsonPropertyStream::add (std::string const& v)
|
||||
{
|
||||
m_stack.back()->append (v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,3 +39,4 @@
|
||||
#include "impl/UInt160.cpp"
|
||||
#include "impl/UInt256.cpp"
|
||||
#include "impl/RippleIdentifierTests.cpp"
|
||||
#include "impl/JsonPropertyStream.cpp"
|
||||
|
||||
@@ -17,10 +17,11 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
|
||||
#ifndef RIPPLE_TYPES_H_INCLUDED
|
||||
#define RIPPLE_TYPES_H_INCLUDED
|
||||
|
||||
#include "../json/ripple_json.h"
|
||||
|
||||
#include "beast/modules/beast_core/beast_core.h"
|
||||
#include "beast/modules/beast_crypto/beast_crypto.h" // for UnsignedInteger, Remove ASAP!
|
||||
|
||||
@@ -66,5 +67,6 @@ using namespace beast;
|
||||
# include "api/SimpleIdentifier.h"
|
||||
#include "api/RippleLedgerHash.h"
|
||||
#include "api/RipplePublicKeyHash.h"
|
||||
#include "api/JsonPropertyStream.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -139,6 +139,11 @@ public:
|
||||
DeadlineTimer m_checkTimer;
|
||||
ServiceQueue m_queue;
|
||||
|
||||
typedef ScopedWrapperContext <
|
||||
RecursiveMutex, RecursiveMutex::ScopedLockType> Context;
|
||||
|
||||
Context m_context;
|
||||
|
||||
// True if we should call check on idle.
|
||||
// This gets set to false once we make it through the whole list.
|
||||
//
|
||||
@@ -289,25 +294,28 @@ public:
|
||||
// PropertyStream
|
||||
//
|
||||
|
||||
void writeSources (PropertyStream stream)
|
||||
void onWrite (PropertyStream::Map& map)
|
||||
{
|
||||
PropertyStream::ScopedArray sources ("sources", stream);
|
||||
Context::Scope scope (m_context);
|
||||
|
||||
map ["trusted"] = uint32 (
|
||||
m_logic.m_chosenList ?
|
||||
m_logic.m_chosenList->size() : 0);
|
||||
|
||||
for (Logic::SourceTable::const_iterator iter (m_logic.m_sources.begin());
|
||||
iter != m_logic.m_sources.end(); ++iter)
|
||||
{
|
||||
stream.append (iter->source->name().toStdString());
|
||||
PropertyStream::Set items ("sources", map);
|
||||
for (Logic::SourceTable::const_iterator iter (m_logic.m_sources.begin());
|
||||
iter != m_logic.m_sources.end(); ++iter)
|
||||
items.add (iter->source->name().toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
void onWrite (PropertyStream stream)
|
||||
{
|
||||
// VFALCO NOTE this is not thread safe (yet)
|
||||
|
||||
stream ["trusted"] = uint32 (
|
||||
m_logic.m_chosenList ? m_logic.m_chosenList->size() : 0);
|
||||
|
||||
writeSources (stream);
|
||||
{
|
||||
PropertyStream::Set items ("validators", map);
|
||||
for (Logic::ValidatorTable::iterator iter (m_logic.m_validators.begin());
|
||||
iter != m_logic.m_validators.end(); ++iter)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "beast/beast/threads/ScopedWrapperContext.h"
|
||||
#include "beast/modules/beast_asio/beast_asio.h"
|
||||
#include "beast/modules/beast_sqdb/beast_sqdb.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user