diff --git a/Builds/QtCreator/rippled.pro b/Builds/QtCreator/rippled.pro
index 527446f41..cd9790388 100644
--- a/Builds/QtCreator/rippled.pro
+++ b/Builds/QtCreator/rippled.pro
@@ -71,7 +71,6 @@ SOURCES += \
../../src/ripple/peerfinder/ripple_peerfinder.cpp \
../../src/ripple/radmap/ripple_radmap.cpp \
../../src/ripple/resource/ripple_resource.cpp \
- ../../src/ripple/rpc/ripple_rpc.cpp \
../../src/ripple/sitefiles/ripple_sitefiles.cpp \
../../src/ripple/sslutil/ripple_sslutil.cpp \
../../src/ripple/testoverlay/ripple_testoverlay.cpp \
@@ -96,6 +95,7 @@ SOURCES += \
../../src/ripple_data/ripple_data.cpp \
../../src/ripple_hyperleveldb/ripple_hyperleveldb.cpp \
../../src/ripple_leveldb/ripple_leveldb.cpp \
+ ../../src/ripple_rpc/ripple_rpc.cpp \
../../src/ripple_net/ripple_net.cpp \
../../src/ripple_websocket/ripple_websocket.cpp
diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj
index 2819f25f1..7547a91f5 100644
--- a/Builds/VisualStudio2013/RippleD.vcxproj
+++ b/Builds/VisualStudio2013/RippleD.vcxproj
@@ -72,6 +72,12 @@
true
+
+ true
+ true
+ true
+ true
+
true
true
@@ -623,31 +629,6 @@
true
true
-
- true
- true
- true
- true
-
-
- true
- true
- true
- true
-
-
- true
- true
- true
- true
-
-
- true
- true
- true
- true
-
-
true
true
@@ -705,12 +686,6 @@
true
true
-
- true
- true
- true
- true
-
true
true
@@ -1850,6 +1825,25 @@
true
true
+
+ true
+ true
+ true
+ true
+
+
+ true
+ true
+ true
+ true
+
+
+ true
+ true
+ true
+ true
+
+
true
true
@@ -2227,6 +2221,7 @@
+
@@ -2379,12 +2374,6 @@
-
-
-
-
-
-
@@ -2417,7 +2406,6 @@
-
@@ -2641,6 +2629,11 @@
+
+
+
+
+
@@ -2757,8 +2750,6 @@
-
-
@@ -2771,6 +2762,8 @@
+
+
diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters
index f4d87bced..c8b993948 100644
--- a/Builds/VisualStudio2013/RippleD.vcxproj.filters
+++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters
@@ -187,12 +187,6 @@
{071582fa-cf16-4e41-8791-613cfe00eef8}
-
- {7abb5fcf-8793-45d0-95db-0cf448198765}
-
-
- {005e1f40-38ac-4904-af7c-4a018c5662f4}
-
{98e572a2-c89a-4ab7-b1d5-7687786e48dd}
@@ -202,9 +196,6 @@
{386ebc1c-0cbe-43a6-b48e-ac3c503da0ee}
-
- {95c93134-7e8d-47ec-9649-4a8d5d97ce12}
-
{a3a2d1ec-d731-42df-9397-40a561c6809a}
@@ -307,6 +298,15 @@
{c429638b-4572-44e4-a48a-c18fdd094ae1}
+
+ {21125570-1733-47a2-8f20-1d4c1f2bf2d1}
+
+
+ {acdb25ae-4985-483b-ad85-94e06aec7eab}
+
+
+ {b86f01de-f924-4584-bb22-d70280b224f3}
+
@@ -1029,9 +1029,6 @@
[2] Old Ripple\ripple_app\main
-
- [1] Ripple\rpc
-
[1] Ripple\http
@@ -1044,15 +1041,6 @@
[1] Ripple\http\impl
-
- [1] Ripple\rpc\impl
-
-
- [1] Ripple\rpc\impl
-
-
- [1] Ripple\rpc\impl
-
[1] Ripple\http\impl
@@ -1113,6 +1101,12 @@
[1] Ripple\types\impl
+
+ [1] Ripple\peerfinder\impl
+
+
+ [1] Ripple\peerfinder\impl
+
[1] Ripple\resource
@@ -1410,9 +1404,6 @@
[2] Old Ripple\ripple_data\protocol
-
- [1] Ripple\rpc\impl
-
[2] Old Ripple\ripple_app\paths
@@ -1464,6 +1455,21 @@
[1] Ripple\peerfinder\sim
+
+ [2] Old Ripple\ripple_rpc
+
+
+ [2] Old Ripple\ripple_rpc\impl
+
+
+ [2] Old Ripple\ripple_rpc\impl
+
+
+ [2] Old Ripple\ripple_rpc\impl
+
+
+ [1] Ripple\json\impl
+
@@ -2328,9 +2334,6 @@
[2] Old Ripple\ripple_app\main
-
- [1] Ripple\rpc
-
[1] Ripple\http
@@ -2361,18 +2364,6 @@
[1] Ripple\http\impl
-
- [1] Ripple\rpc\api
-
-
- [1] Ripple\rpc\api
-
-
- [1] Ripple\rpc\api
-
-
- [1] Ripple\rpc\impl
-
[1] Ripple\types
@@ -2487,6 +2478,27 @@
[1] Ripple\types\api
+
+ [1] Ripple\peerfinder\impl
+
+
+ [1] Ripple\peerfinder\impl
+
+
+ [1] Ripple\peerfinder\impl
+
+
+ [1] Ripple\peerfinder\impl
+
+
+ [1] Ripple\peerfinder\impl
+
+
+ [1] Ripple\peerfinder\impl
+
+
+ [1] Ripple\peerfinder\impl
+
[1] Ripple\resource
@@ -2877,9 +2889,6 @@
[2] Old Ripple\ripple_data\protocol
-
- [1] Ripple\rpc\api
-
[2] Old Ripple\ripple_app\paths
@@ -3021,6 +3030,24 @@
[1] Ripple\peerfinder\sim
+
+ [2] Old Ripple\ripple_rpc
+
+
+ [2] Old Ripple\ripple_rpc\api
+
+
+ [2] Old Ripple\ripple_rpc\api
+
+
+ [2] Old Ripple\ripple_rpc\api
+
+
+ [2] Old Ripple\ripple_rpc\impl
+
+
+ [1] Ripple\json\api
+
@@ -3109,12 +3136,6 @@
[1] Ripple\json
-
- [1] Ripple\rpc
-
-
- [1] Ripple\rpc
-
[1] Ripple\sitefiles
@@ -3142,6 +3163,12 @@
[1] Ripple\radmap
+
+ [2] Old Ripple\ripple_rpc
+
+
+ [2] Old Ripple\ripple_rpc
+
diff --git a/SConstruct b/SConstruct
index 90fde8937..cfcec345d 100644
--- a/SConstruct
+++ b/SConstruct
@@ -169,7 +169,6 @@ COMPILED_FILES.extend([
'src/ripple/radmap/ripple_radmap.cpp',
'src/ripple/resource/ripple_resource.cpp',
'src/ripple/rocksdb/ripple_rocksdb.cpp',
- 'src/ripple/rpc/ripple_rpc.cpp',
'src/ripple/sitefiles/ripple_sitefiles.cpp',
'src/ripple/sslutil/ripple_sslutil.cpp',
'src/ripple/testoverlay/ripple_testoverlay.cpp',
@@ -197,6 +196,7 @@ COMPILED_FILES.extend([
'src/ripple_hyperleveldb/ripple_hyperleveldb.cpp',
'src/ripple_leveldb/ripple_leveldb.cpp',
'src/ripple_net/ripple_net.cpp',
+ 'src/ripple_rpc/ripple_rpc.cpp',
'src/ripple_websocket/ripple_websocket.cpp'
])
diff --git a/src/BeastConfig.h b/src/BeastConfig.h
index 6454c619e..278740b04 100644
--- a/src/BeastConfig.h
+++ b/src/BeastConfig.h
@@ -192,11 +192,4 @@
#define RIPPLE_USE_PEERFINDER 0
#endif
-// Here temporarily
-// Controls whether or not the new RPC::Manager logic will be
-// used to invoke RPC commands before they pass to the original code.
-#ifndef RIPPLE_USE_RPC_SERVICE_MANAGER
-#define RIPPLE_USE_RPC_SERVICE_MANAGER 0
-#endif
-
#endif
diff --git a/src/ripple/types/api/JsonPropertyStream.h b/src/ripple/json/api/JsonPropertyStream.h
similarity index 73%
rename from src/ripple/types/api/JsonPropertyStream.h
rename to src/ripple/json/api/JsonPropertyStream.h
index 92d66188c..039ad7e3e 100644
--- a/src/ripple/types/api/JsonPropertyStream.h
+++ b/src/ripple/json/api/JsonPropertyStream.h
@@ -20,10 +20,12 @@
#ifndef RIPPLE_JSONPROPERTYSTREAM_H_INCLUDED
#define RIPPLE_JSONPROPERTYSTREAM_H_INCLUDED
+#include "../beast/beast/utility/PropertyStream.h"
+
namespace ripple {
/** A PropertyStream::Sink which produces a Json::Value. */
-class JsonPropertyStream : public PropertyStream
+class JsonPropertyStream : public beast::PropertyStream
{
public:
Json::Value m_top;
@@ -38,15 +40,25 @@ 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, short value);
+ void add (std::string const& key, unsigned short value);
+ void add (std::string const& key, int value);
+ void add (std::string const& key, unsigned int value);
+ void add (std::string const& key, long value);
+ void add (std::string const& key, float v);
void add (std::string const& key, double 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 (short value);
+ void add (unsigned short value);
+ void add (int value);
+ void add (unsigned int value);
+ void add (long value);
+ void add (float v);
+ void add (double v);
void add (std::string const& v);
};
diff --git a/src/ripple/types/impl/JsonPropertyStream.cpp b/src/ripple/json/impl/JsonPropertyStream.cpp
similarity index 72%
rename from src/ripple/types/impl/JsonPropertyStream.cpp
rename to src/ripple/json/impl/JsonPropertyStream.cpp
index 485da459f..5615c26bc 100644
--- a/src/ripple/types/impl/JsonPropertyStream.cpp
+++ b/src/ripple/json/impl/JsonPropertyStream.cpp
@@ -52,12 +52,32 @@ void JsonPropertyStream::map_end ()
m_stack.pop_back ();
}
-void JsonPropertyStream::add (std::string const& key, int32 v)
+void JsonPropertyStream::add (std::string const& key, short v)
{
(*m_stack.back())[key] = v;
}
-void JsonPropertyStream::add (std::string const& key, uint32 v)
+void JsonPropertyStream::add (std::string const& key, unsigned short v)
+{
+ (*m_stack.back())[key] = v;
+}
+
+void JsonPropertyStream::add (std::string const& key, int v)
+{
+ (*m_stack.back())[key] = v;
+}
+
+void JsonPropertyStream::add (std::string const& key, unsigned int v)
+{
+ (*m_stack.back())[key] = v;
+}
+
+void JsonPropertyStream::add (std::string const& key, long v)
+{
+ (*m_stack.back())[key] = int(v);
+}
+
+void JsonPropertyStream::add (std::string const& key, float v)
{
(*m_stack.back())[key] = v;
}
@@ -93,12 +113,37 @@ void JsonPropertyStream::array_end ()
m_stack.pop_back ();
}
-void JsonPropertyStream::add (int32 v)
+void JsonPropertyStream::add (short v)
{
m_stack.back()->append (v);
}
-void JsonPropertyStream::add (uint32 v)
+void JsonPropertyStream::add (unsigned short v)
+{
+ m_stack.back()->append (v);
+}
+
+void JsonPropertyStream::add (int v)
+{
+ m_stack.back()->append (v);
+}
+
+void JsonPropertyStream::add (unsigned int v)
+{
+ m_stack.back()->append (v);
+}
+
+void JsonPropertyStream::add (long v)
+{
+ m_stack.back()->append (int (v));
+}
+
+void JsonPropertyStream::add (float v)
+{
+ m_stack.back()->append (v);
+}
+
+void JsonPropertyStream::add (double v)
{
m_stack.back()->append (v);
}
diff --git a/src/ripple/json/ripple_json.cpp b/src/ripple/json/ripple_json.cpp
index d8557ef11..0e185b858 100644
--- a/src/ripple/json/ripple_json.cpp
+++ b/src/ripple/json/ripple_json.cpp
@@ -47,3 +47,5 @@
#include "impl/json_writer.cpp"
#include "impl/Tests.cpp"
+
+#include "impl/JsonPropertyStream.cpp"
diff --git a/src/ripple/json/ripple_json.h b/src/ripple/json/ripple_json.h
index d31e72716..ddc813565 100644
--- a/src/ripple/json/ripple_json.h
+++ b/src/ripple/json/ripple_json.h
@@ -48,4 +48,6 @@
#include "api/json_reader.h"
#include "api/json_writer.h"
+#include "api/JsonPropertyStream.h"
+
#endif
diff --git a/src/ripple/resource/api/Charge.h b/src/ripple/resource/api/Charge.h
index c6a7b3e04..945195126 100644
--- a/src/ripple/resource/api/Charge.h
+++ b/src/ripple/resource/api/Charge.h
@@ -21,6 +21,7 @@
#define RIPPLE_RESOURCE_CHARGE_H_INCLUDED
#include
+#include
namespace ripple {
namespace Resource {
diff --git a/src/ripple/rpc/api/Manager.h b/src/ripple/rpc/api/Manager.h
deleted file mode 100644
index 8bc39b492..000000000
--- a/src/ripple/rpc/api/Manager.h
+++ /dev/null
@@ -1,78 +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_RPC_MANAGER_H_INCLUDED
-#define RIPPLE_RPC_MANAGER_H_INCLUDED
-
-#include "../../../beast/beast/utility/Journal.h"
-
-#include "Handler.h"
-#include "Service.h"
-
-namespace ripple {
-using namespace beast;
-
-namespace RPC {
-
-/** Manages a collection of Service interface objects. */
-class Manager
-{
-public:
- static Manager* New (Journal journal);
-
- virtual ~Manager() { }
-
- /** Add a service.
- The list of commands that the service handles is enumerated and
- added to the manager's dispatch table.
- Thread safety:
- Safe to call from any thread.
- May only be called once for a given service.
- */
- virtual void add (Service& service) = 0;
-
- /** Add a subclass of Service and return the original pointer.
- This is provided as a convenient so that RPCService objects may
- be added from ctor-initializer lists.
- */
- template
- Derived* add (Derived* derived)
- {
- add (*(static_cast (derived)));
- return derived;
- }
-
- /** Execute an RPC command synchronously.
- On return, if result.first == `true` then result.second will
- have the Json return value from the call of the handler.
- */
- virtual std::pair call (
- std::string const& method, Json::Value const& args) = 0;
-
- /** Returns the Handler for the specified method, or nullptr.
- Thread safety:
- Safe to call from any threads.
- */
- virtual Handler const* find (std::string const& method) = 0;
-};
-
-}
-}
-
-#endif
diff --git a/src/ripple/rpc/impl/ManagerImpl.h b/src/ripple/rpc/impl/ManagerImpl.h
deleted file mode 100644
index a86551583..000000000
--- a/src/ripple/rpc/impl/ManagerImpl.h
+++ /dev/null
@@ -1,98 +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_RPC_MANAGERIMPL_H_INCLUDED
-#define RIPPLE_RPC_MANAGERIMPL_H_INCLUDED
-
-namespace ripple {
-namespace RPC {
-
-class ManagerImpl : public Manager
-{
-public:
- // The type of map we use to look up by function name.
- //
- typedef boost::unordered_map MapType;
-
- //--------------------------------------------------------------------------
-
- explicit ManagerImpl (Journal journal)
- : m_journal (journal)
- {
- }
-
- ~ManagerImpl()
- {
- }
-
- void add (Service& service)
- {
- Handlers const& handlers (service.handlers());
-
- SharedState::Access state (m_state);
-
- for (Handlers::const_iterator iter (handlers.begin());
- iter != handlers.end(); ++iter)
- {
- Handler const& handler (*iter);
- std::pair result (
- state->table.emplace (handler.method(), handler));
- if (!result.second)
- m_journal.error << "duplicate method '" << handler.method() << "'";
- }
- }
-
- std::pair call (
- std::string const& method, Json::Value const& args)
- {
- Handler const* handler (find (method));
- if (! handler)
- return std::make_pair (false, Json::Value());
- return std::make_pair (true, (*handler)(args));
- }
-
- Handler const* find (std::string const& method)
- {
- Handler const* handler (nullptr);
- // Peform lookup on the method to retrieve handler
- SharedState::Access state (m_state);
- MapType::iterator iter (state->table.find (method));
- if (iter != state->table.end())
- handler = &iter->second;
- else
- m_journal.debug << "method '" << method << "' not found.";
- return handler;
- }
-
-private:
- struct State
- {
- MapType table;
- };
-
- typedef SharedData SharedState;
-
- Journal m_journal;
- SharedState m_state;
-};
-
-}
-}
-
-#endif
diff --git a/src/ripple/types/ripple_types.cpp b/src/ripple/types/ripple_types.cpp
index 8b33328c5..d3e1211bf 100644
--- a/src/ripple/types/ripple_types.cpp
+++ b/src/ripple/types/ripple_types.cpp
@@ -46,6 +46,5 @@
#include "impl/UInt256.cpp"
#include "impl/RippleIdentifierTests.cpp"
#include "impl/RippleAssets.cpp"
-#include "impl/JsonPropertyStream.cpp"
diff --git a/src/ripple/types/ripple_types.h b/src/ripple/types/ripple_types.h
index 2b7523431..ad44e96ae 100644
--- a/src/ripple/types/ripple_types.h
+++ b/src/ripple/types/ripple_types.h
@@ -68,6 +68,5 @@ using namespace beast;
# include "api/SimpleIdentifier.h"
#include "api/RippleLedgerHash.h"
#include "api/RipplePublicKeyHash.h"
-#include "api/JsonPropertyStream.h"
#endif
diff --git a/src/ripple/validators/ripple_validators.h b/src/ripple/validators/ripple_validators.h
index 22cf2bc61..6fb687fbb 100644
--- a/src/ripple/validators/ripple_validators.h
+++ b/src/ripple/validators/ripple_validators.h
@@ -24,7 +24,6 @@
#include "beast/beast/http/URL.h"
-#include "../ripple/rpc/ripple_rpc.h"
#include "../ripple/types/ripple_types.h"
# include "api/Types.h"
diff --git a/src/ripple_app/main/Application.cpp b/src/ripple_app/main/Application.cpp
index e58dae77e..40d1f93eb 100644
--- a/src/ripple_app/main/Application.cpp
+++ b/src/ripple_app/main/Application.cpp
@@ -18,6 +18,8 @@
//==============================================================================
#include "../ripple/common/seconds_clock.h"
+#include "../ripple_rpc/api/Manager.h"
+
#include "Tuning.h"
namespace ripple {
@@ -52,6 +54,8 @@ class ResourceManagerLog;
template <> char const* LogPartition::getPartitionName () { return "ResourceManager"; }
class PathRequestLog;
template <> char const* LogPartition::getPartitionName () { return "PathRequest"; }
+class RPCManagerLog;
+template <> char const* LogPartition::getPartitionName () { return "RPCManager"; }
template <> char const* LogPartition::getPartitionName () { return "Collector"; }
@@ -111,7 +115,6 @@ public:
std::unique_ptr m_collectorManager;
std::unique_ptr m_resourceManager;
- std::unique_ptr m_rpcServiceManager;
std::unique_ptr m_fullBelowCache;
// These are Stoppable-related
@@ -119,6 +122,7 @@ public:
std::unique_ptr m_jobQueue;
IoServicePool m_mainIoPool;
std::unique_ptr m_siteFiles;
+ std::unique_ptr m_rpcManager;
// VFALCO TODO Make OrderBookDB abstract
OrderBookDB m_orderBookDB;
std::unique_ptr m_pathRequests;
@@ -126,9 +130,7 @@ public:
std::unique_ptr m_networkOPs;
std::unique_ptr m_deprecatedUNL;
std::unique_ptr m_rpcHTTPServer;
-#if ! RIPPLE_USE_RPC_SERVICE_MANAGER
RPCServerHandler m_rpcServerHandler;
-#endif
std::unique_ptr m_nodeStore;
std::unique_ptr m_sntpClient;
std::unique_ptr m_inboundLedgers;
@@ -224,9 +226,6 @@ public:
m_collectorManager->collector(),
LogPartition::getJournal ()))
- , m_rpcServiceManager (RPC::Manager::New (
- LogPartition::getJournal ()))
-
, m_fullBelowCache (std::make_unique (
"full_below", get_seconds_clock (), m_collectorManager->collector (),
fullBelowTargetSize, fullBelowExpirationSeconds))
@@ -252,6 +251,8 @@ public:
, m_siteFiles (SiteFiles::Manager::New (
*this, LogPartition::getJournal ()))
+ , m_rpcManager (RPC::make_Manager (LogPartition::getJournal ()))
+
, m_orderBookDB (*m_jobQueue)
, m_pathRequests ( new PathRequests (
@@ -270,9 +271,8 @@ public:
, m_rpcHTTPServer (RPCHTTPServer::New (*m_networkOPs,
LogPartition::getJournal (), *m_jobQueue, *m_networkOPs, *m_resourceManager))
-#if ! RIPPLE_USE_RPC_SERVICE_MANAGER
, m_rpcServerHandler (*m_networkOPs, *m_resourceManager) // passive object, not a Service
-#endif
+
, m_nodeStore (m_nodeStoreManager->make_Database ("NodeStore.main", m_nodeStoreScheduler,
LogPartition::getJournal (),
getConfig ().nodeDatabase, getConfig ().ephemeralNodeDatabase))
@@ -341,11 +341,6 @@ public:
return *m_collectorManager;
}
- RPC::Manager& getRPCServiceManager()
- {
- return *m_rpcServiceManager;
- }
-
FullBelowCache& getFullBelowCache ()
{
return *m_fullBelowCache;
@@ -356,6 +351,11 @@ public:
return *m_jobQueue;
}
+ RPC::Manager& getRPCManager ()
+ {
+ return *m_rpcManager;
+ }
+
SiteFiles::Manager& getSiteFiles()
{
return *m_siteFiles;
@@ -757,10 +757,6 @@ public:
//
// Allow RPC connections.
//
-#if RIPPLE_USE_RPC_SERVICE_MANAGER
- m_rpcHTTPServer->setup (m_journal);
-
-#else
if (! getConfig ().getRpcIP().empty () && getConfig ().getRpcPort() != 0)
{
try
@@ -780,7 +776,6 @@ public:
{
m_journal.info << "RPC interface: disabled";
}
-#endif
//
// Begin connecting to network.
diff --git a/src/ripple_app/main/Application.h b/src/ripple_app/main/Application.h
index fbd1c2c9b..56dc5b107 100644
--- a/src/ripple_app/main/Application.h
+++ b/src/ripple_app/main/Application.h
@@ -82,9 +82,9 @@ public:
virtual boost::asio::io_service& getIOService () = 0;
virtual CollectorManager& getCollectorManager () = 0;
- virtual RPC::Manager& getRPCServiceManager() = 0;
virtual FullBelowCache& getFullBelowCache () = 0;
virtual JobQueue& getJobQueue () = 0;
+ virtual RPC::Manager& getRPCManager () = 0;
virtual SiteFiles::Manager& getSiteFiles () = 0;
virtual NodeCache& getTempNodeCache () = 0;
virtual SLECache& getSLECache () = 0;
diff --git a/src/ripple_app/ripple_app.cpp b/src/ripple_app/ripple_app.cpp
index 048a19374..b5545123a 100644
--- a/src/ripple_app/ripple_app.cpp
+++ b/src/ripple_app/ripple_app.cpp
@@ -29,6 +29,7 @@
#include "ripple_app.h"
#include "../ripple_net/ripple_net.h"
+#include "../ripple_rpc/ripple_rpc.h"
#include "../ripple_websocket/ripple_websocket.h"
// This .cpp will end up including all of the public header
@@ -37,7 +38,6 @@
#include "../ripple/common/seconds_clock.h"
#include "../ripple/http/ripple_http.h"
#include "../ripple/resource/ripple_resource.h"
-#include "../ripple/rpc/ripple_rpc.h"
#include "../ripple/sitefiles/ripple_sitefiles.h"
#include "../ripple/validators/ripple_validators.h"
diff --git a/src/ripple_app/ripple_app_pt8.cpp b/src/ripple_app/ripple_app_pt8.cpp
index d3484c2b9..e66c1243b 100644
--- a/src/ripple_app/ripple_app_pt8.cpp
+++ b/src/ripple_app/ripple_app_pt8.cpp
@@ -26,7 +26,7 @@
#pragma warning (disable: 4309) // truncation of constant value
#endif
-#include "../ripple/rpc/api/ErrorCodes.h"
+#include "../ripple_rpc/api/ErrorCodes.h"
namespace ripple
{
diff --git a/src/ripple_app/rpc/RPCHandler.cpp b/src/ripple_app/rpc/RPCHandler.cpp
index 5675dfd08..e4e308f51 100644
--- a/src/ripple_app/rpc/RPCHandler.cpp
+++ b/src/ripple_app/rpc/RPCHandler.cpp
@@ -4110,16 +4110,7 @@ Json::Value RPCHandler::doRpcCommand (const std::string& strMethod, Json::Value
// Provide the JSON-RPC method as the field "command" in the request.
params["command"] = strMethod;
- Json::Value jvResult;
-#if RIPPLE_USE_RPC_SERVICE_MANAGER
- std::pair result (getApp().
- getRPCServiceManager().call (strMethod, params));
- if (result.first)
- jvResult = result.second;
- else
-#endif
- jvResult = doCommand (params, iRole, loadType);
-
+ Json::Value jvResult = doCommand (params, iRole, loadType);
// Always report "status". On an error report the request as received.
if (jvResult.isMember ("error"))
diff --git a/src/ripple_app/rpc/RPCServerHandler.cpp b/src/ripple_app/rpc/RPCServerHandler.cpp
index 65a86d1e6..1e135fb03 100644
--- a/src/ripple_app/rpc/RPCServerHandler.cpp
+++ b/src/ripple_app/rpc/RPCServerHandler.cpp
@@ -38,20 +38,20 @@ bool RPCServerHandler::isAuthorized (
std::string RPCServerHandler::processRequest (std::string const& request, IPAddress const& remoteIPAddress)
{
- Json::Value jvRequest;
+ Json::Value jsonRequest;
{
Json::Reader reader;
if ((request.size() > 1000000) ||
- ! reader.parse (request, jvRequest) ||
- jvRequest.isNull () ||
- ! jvRequest.isObject ())
+ ! reader.parse (request, jsonRequest) ||
+ jsonRequest.isNull () ||
+ ! jsonRequest.isObject ())
{
return createResponse (400, "Unable to parse request");
}
}
- Config::Role const role (getConfig ().getAdminRole (jvRequest, remoteIPAddress));
+ Config::Role const role (getConfig ().getAdminRole (jsonRequest, remoteIPAddress));
Resource::Consumer usage;
@@ -67,9 +67,9 @@ std::string RPCServerHandler::processRequest (std::string const& request, IPAddr
//
// VFALCO NOTE Except that "id" isn't included in the following errors...
//
- Json::Value const id = jvRequest ["id"];
+ Json::Value const& id = jsonRequest ["id"];
- Json::Value const method = jvRequest ["method"];
+ Json::Value const& method = jsonRequest ["method"];
if (method.isNull ())
{
@@ -82,17 +82,14 @@ std::string RPCServerHandler::processRequest (std::string const& request, IPAddr
std::string strMethod = method.asString ();
- // Parse params
- Json::Value params = jvRequest ["params"];
+ if (jsonRequest["params"].isNull())
+ jsonRequest["params"] = Json::Value (Json::arrayValue);
- if (params.isNull ())
- {
- params = Json::Value (Json::arrayValue);
- }
- else if (!params.isArray ())
- {
+ // Parse params
+ Json::Value& params = jsonRequest ["params"];
+
+ if (!params.isArray ())
return HTTPReply (400, "params unparseable");
- }
// VFALCO TODO Shouldn't we handle this earlier?
//
@@ -113,16 +110,28 @@ std::string RPCServerHandler::processRequest (std::string const& request, IPAddr
}
std::string response;
-
+
WriteLog (lsDEBUG, RPCServer) << "Query: " << strMethod << params;
+ RPC::Request req (LogPartition::getJournal (),
+ strMethod, params, getApp ());
+
+ // VFALCO Try processing the command using the new code
+ if (getApp().getRPCManager().dispatch (req))
+ {
+ usage.charge (req.fee);
+ WriteLog (lsDEBUG, RPCServer) << "Reply: " << req.result;
+ return createResponse (200,
+ JSONRPCReply (req.result, Json::Value (), id));
+ }
+
+ // legacy dispatcher
+
RPCHandler rpcHandler (&m_networkOPs);
+ Json::Value const result = rpcHandler.doRpcCommand (
+ strMethod, params, role, req.fee);
- Resource::Charge loadType = Resource::feeReferenceRPC;
-
- Json::Value const result = rpcHandler.doRpcCommand (strMethod, params, role, loadType);
-
- usage.charge (loadType);
+ usage.charge (req.fee);
WriteLog (lsDEBUG, RPCServer) << "Reply: " << result;
diff --git a/src/ripple_data/ripple_data.cpp b/src/ripple_data/ripple_data.cpp
index 2c4ca57b7..42c981c48 100644
--- a/src/ripple_data/ripple_data.cpp
+++ b/src/ripple_data/ripple_data.cpp
@@ -44,7 +44,7 @@
#include
#include "../ripple/sslutil/ripple_sslutil.h"
-#include "../ripple/rpc/api/ErrorCodes.h"
+#include "../ripple_rpc/api/ErrorCodes.h"
// VFALCO TODO fix these warnings!
#if BEAST_MSVC
diff --git a/src/ripple_net/ripple_net.cpp b/src/ripple_net/ripple_net.cpp
index 82114af82..ffd164513 100644
--- a/src/ripple_net/ripple_net.cpp
+++ b/src/ripple_net/ripple_net.cpp
@@ -46,7 +46,7 @@
// directly (instead of th emodule header). The corresponding .cpp
// still uses the unity style inclusion.
//
-#include "../ripple/rpc/api/ErrorCodes.h"
+#include "../ripple_rpc/api/ErrorCodes.h"
namespace ripple
{
diff --git a/src/ripple/rpc/README.md b/src/ripple_rpc/README.md
similarity index 100%
rename from src/ripple/rpc/README.md
rename to src/ripple_rpc/README.md
diff --git a/src/ripple/rpc/TODO.md b/src/ripple_rpc/TODO.md
similarity index 100%
rename from src/ripple/rpc/TODO.md
rename to src/ripple_rpc/TODO.md
diff --git a/src/ripple/rpc/api/ErrorCodes.h b/src/ripple_rpc/api/ErrorCodes.h
similarity index 99%
rename from src/ripple/rpc/api/ErrorCodes.h
rename to src/ripple_rpc/api/ErrorCodes.h
index 1d66c0c5a..b28a3481d 100644
--- a/src/ripple/rpc/api/ErrorCodes.h
+++ b/src/ripple_rpc/api/ErrorCodes.h
@@ -20,6 +20,8 @@
#ifndef RIPPLE_RPC_ERRORCODES_H_INCLUDED
#define RIPPLE_RPC_ERRORCODES_H_INCLUDED
+#include "../../ripple/json/ripple_json.h"
+
namespace ripple {
// VFALCO NOTE These are outside the RPC namespace
diff --git a/src/ripple/rpc/impl/Manager.cpp b/src/ripple_rpc/api/Manager.h
similarity index 56%
rename from src/ripple/rpc/impl/Manager.cpp
rename to src/ripple_rpc/api/Manager.h
index c0a16846c..3e0121d8c 100644
--- a/src/ripple/rpc/impl/Manager.cpp
+++ b/src/ripple_rpc/api/Manager.h
@@ -17,13 +17,47 @@
*/
//==============================================================================
+#ifndef RIPPLE_RPC_MANAGER_H_INCLUDED
+#define RIPPLE_RPC_MANAGER_H_INCLUDED
+
+#include "Request.h"
+
namespace ripple {
namespace RPC {
-Manager* Manager::New (Journal journal)
+/** Processes RPC commands. */
+class Manager
{
- return new ManagerImpl (journal);
-}
+public:
+ typedef std::function handler_type;
+
+ virtual ~Manager () = 0;
+
+ /** Add a handler for the specified JSON-RPC command. */
+ /** @{ */
+ template
+ void add (std::string const& method)
+ {
+ add (method, handler_type (
+ [](Request& req)
+ {
+ Handler h;
+ h (req);
+ }));
+ }
+
+ virtual void add (std::string const& method, handler_type&& handler) = 0;
+ /** @} */
+
+ /** Dispatch the JSON-RPC request.
+ @return `true` If the command was found.
+ */
+ virtual bool dispatch (Request& req) = 0;
+};
+
+std::unique_ptr make_Manager (Journal journal);
}
}
+
+#endif
diff --git a/src/ripple/rpc/api/Service.h b/src/ripple_rpc/api/Request.h
similarity index 54%
rename from src/ripple/rpc/api/Service.h
rename to src/ripple_rpc/api/Request.h
index b5331f4da..c970f24ed 100644
--- a/src/ripple/rpc/api/Service.h
+++ b/src/ripple_rpc/api/Request.h
@@ -17,43 +17,52 @@
*/
//==============================================================================
-#ifndef RIPPLE_RPC_SERVCE_H_INCLUDED
-#define RIPPLE_RPC_SERVCE_H_INCLUDED
+#ifndef RIPPLE_RPC_REQUEST_H_INCLUDED
+#define RIPPLE_RPC_REQUEST_H_INCLUDED
+
+#include "../ripple/json/ripple_json.h"
+#include "../ripple/resource/ripple_resource.h"
-#include "Handler.h"
namespace ripple {
+
+class Application; // forward declare
+
namespace RPC {
-/** Interface for abstacting RPC commands processing. */
-class Service : public Uncopyable
+struct Request
{
-public:
- /** Create the service.
- Derived classes will usually call add() repeatedly from their
- constructor to fill in the list of handlers prior to Manager::add.
- */
- Service ();
-
- virtual ~Service ();
-
- /** Returns the handlers associated with this service. */
- Handlers const& handlers() const;
-
- /** Add a handler for the specified method.
- Adding a handler after the service is already associated with a
- Manager results in undefined behavior.
- Thread safety:
- May not be called concurrently.
- */
- template
- void addRPCHandler (std::string const& method, Function function)
+ explicit Request (Journal journal_,
+ std::string const& method_, Json::Value& params_,
+ Application& app_)
+ : journal (journal_)
+ , method (method_)
+ , params (params_)
+ , fee (Resource::feeReferenceRPC)
+ , app (app_)
{
- m_handlers.push_back (Handler (method, function));
}
+ // [in] The Journal for logging
+ Journal journal;
+
+ // [in] The JSON-RPC method
+ std::string method;
+
+ // [in] The complete JSON-RPC request
+ Json::Value params;
+
+ // [in, out] The resource cost for the command
+ Resource::Charge fee;
+
+ // [out] The JSON-RPC response
+ Json::Value result;
+
+ // [in] The Application instance
+ Application& app;
+
private:
- Handlers m_handlers;
+ Request& operator= (Request const&);
};
}
diff --git a/src/ripple/rpc/impl/Service.cpp b/src/ripple_rpc/impl/Command.h
similarity index 87%
rename from src/ripple/rpc/impl/Service.cpp
rename to src/ripple_rpc/impl/Command.h
index 08c45ae75..b136f31e7 100644
--- a/src/ripple/rpc/impl/Service.cpp
+++ b/src/ripple_rpc/impl/Command.h
@@ -17,21 +17,19 @@
*/
//==============================================================================
+#ifndef RIPPLE_RPC_COMMAND_H_INCLUDED
+#define RIPPLE_RPC_COMMAND_H_INCLUDED
+
namespace ripple {
namespace RPC {
-Service::Service ()
+/** Base class common to all RPC commands. */
+class Command
{
-}
-
-Service::~Service ()
-{
-}
-
-Handlers const& Service::handlers() const
-{
- return m_handlers;
-}
+public:
+};
}
}
+
+#endif
diff --git a/src/ripple/rpc/impl/Handler.cpp b/src/ripple_rpc/impl/DoPrint.h
similarity index 71%
rename from src/ripple/rpc/impl/Handler.cpp
rename to src/ripple_rpc/impl/DoPrint.h
index e612a6aaa..10682cc46 100644
--- a/src/ripple/rpc/impl/Handler.cpp
+++ b/src/ripple_rpc/impl/DoPrint.h
@@ -20,28 +20,27 @@
namespace ripple {
namespace RPC {
-Handler::Handler (Handler const& other)
- : m_method (other.m_method)
- , m_function (other.m_function)
+class DoPrint
{
-}
+public:
+ void operator() (Request& req)
+ {
+ JsonPropertyStream stream;
-Handler& Handler::operator= (Handler const& other)
-{
- m_method = other.m_method;
- m_function = other.m_function;
- return *this;
-}
+ if (req.params.isObject() &&
+ req.params["params"].isArray() &&
+ req.params["params"][0u].isString ())
+ {
+ req.app.write (stream, req.params["params"][0u].asString());
+ }
+ else
+ {
+ req.app.write (stream);
+ }
-std::string const& Handler::method() const
-{
- return m_method;
-}
-
-Json::Value Handler::operator() (Json::Value const& args) const
-{
- return m_function (args);
-}
+ req.result = stream.top();
+ }
+};
}
}
diff --git a/src/ripple/rpc/impl/ErrorCodes.cpp b/src/ripple_rpc/impl/ErrorCodes.cpp
similarity index 94%
rename from src/ripple/rpc/impl/ErrorCodes.cpp
rename to src/ripple_rpc/impl/ErrorCodes.cpp
index 61fec983e..33c1118a0 100644
--- a/src/ripple/rpc/impl/ErrorCodes.cpp
+++ b/src/ripple_rpc/impl/ErrorCodes.cpp
@@ -17,6 +17,23 @@
*/
//==============================================================================
+#include
+#include
+
+#include "../api/ErrorCodes.h"
+
+namespace std {
+
+template <>
+struct hash
+{
+ std::size_t operator() (ripple::error_code_i value) const
+ {
+ return value;
+ }
+};
+
+}
namespace ripple {
namespace RPC {
@@ -25,7 +42,7 @@ namespace detail {
class ErrorCategory
{
public:
- typedef boost::unordered_map Map;
+ typedef std::unordered_map Map;
ErrorCategory ()
: m_unknown (rpcUNKNOWN, "unknown", "An unknown error code.")
@@ -108,10 +125,11 @@ private:
std::string const& message)
{
std::pair result (
- m_map.emplace (boost::unordered::piecewise_construct,
- boost::make_tuple (code), boost::make_tuple (
+ m_map.emplace (std::piecewise_construct,
+ std::make_tuple (code), std::make_tuple (
code, token, message)));
- check_postcondition (result.second);
+ if (! result.second)
+ throw std::invalid_argument ("duplicate error code");
}
private:
diff --git a/src/ripple/rpc/api/Handler.h b/src/ripple_rpc/impl/Manager.cpp
similarity index 51%
rename from src/ripple/rpc/api/Handler.h
rename to src/ripple_rpc/impl/Manager.cpp
index 76df42ffc..be2ff9bb0 100644
--- a/src/ripple/rpc/api/Handler.h
+++ b/src/ripple_rpc/impl/Manager.cpp
@@ -17,49 +17,59 @@
*/
//==============================================================================
-#ifndef RIPPLE_RPC_HANDLER_H_INCLUDED
-#define RIPPLE_RPC_HANDLER_H_INCLUDED
+#include "beast/beast/make_unique.h"
-#include
+#include "../api/Manager.h"
+
+#include "DoPrint.h"
namespace ripple {
-using namespace beast;
-
namespace RPC {
-/** An invokable handler for a particular RPC method. */
-class Handler
+class ManagerImp : public Manager
{
public:
- /** Create a handler with the specified method and function. */
- template // allocator
- Handler (std::string const& method_, Function function)
- : m_method (method_)
- , m_function (function)
+ typedef std::unordered_map Map;
+
+ Journal m_journal;
+ Map m_map;
+
+ ManagerImp (Journal journal)
+ : m_journal (journal)
{
}
- Handler (Handler const& other);
- Handler& operator= (Handler const& other);
+ void add (std::string const& method, handler_type&& handler)
+ {
+ std::pair result (m_map.emplace (
+ std::piecewise_construct, std::make_tuple (method),
+ std::make_tuple (std::move (handler))));
+ }
- /** Returns the method called when this handler is invoked. */
- std::string const& method() const;
-
- /** Synchronously invoke the method on the associated service.
- Thread safety:
- Determined by the owner.
- */
- Json::Value operator() (Json::Value const& args) const;
-
-private:
- std::string m_method;
- SharedFunction m_function;
+ bool dispatch (Request& req)
+ {
+ Map::const_iterator const iter (m_map.find (req.method));
+ if (iter == m_map.end())
+ return false;
+ iter->second (req);
+ return true;
+ }
};
-/** The type of container that holds a set of Handler objects. */
-typedef std::vector Handlers;
+//------------------------------------------------------------------------------
+
+Manager::~Manager ()
+{
+}
+
+std::unique_ptr make_Manager (Journal journal)
+{
+ std::unique_ptr m (std::make_unique (journal));
+
+ m->add ("print");
+
+ return m;
+}
}
}
-
-#endif
diff --git a/src/ripple/rpc/ripple_rpc.cpp b/src/ripple_rpc/ripple_rpc.cpp
similarity index 86%
rename from src/ripple/rpc/ripple_rpc.cpp
rename to src/ripple_rpc/ripple_rpc.cpp
index f6195d4a8..30113c251 100644
--- a/src/ripple/rpc/ripple_rpc.cpp
+++ b/src/ripple_rpc/ripple_rpc.cpp
@@ -21,11 +21,12 @@
#include "ripple_rpc.h"
-#include "beast/modules/beast_core/system/BeforeBoost.h"
-#include
+#include "beast/modules/beast_core/beast_core.h" // for UnitTest
+
+// Unfortunate but necessary since RPC handlers can literally do anything
+#include "../ripple_app/ripple_app.h"
#include "impl/ErrorCodes.cpp"
-# include "impl/ManagerImpl.h"
#include "impl/Manager.cpp"
-#include "impl/Handler.cpp"
-#include "impl/Service.cpp"
+
+
diff --git a/src/ripple/rpc/ripple_rpc.h b/src/ripple_rpc/ripple_rpc.h
similarity index 89%
rename from src/ripple/rpc/ripple_rpc.h
rename to src/ripple_rpc/ripple_rpc.h
index 12aeabc69..82ebf4656 100644
--- a/src/ripple/rpc/ripple_rpc.h
+++ b/src/ripple_rpc/ripple_rpc.h
@@ -20,13 +20,10 @@
#ifndef RIPPLE_RPC_H_INCLUDED
#define RIPPLE_RPC_H_INCLUDED
-#include "beast/modules/beast_core/beast_core.h"
+//#include "beast/modules/beast_core/beast_core.h"
-#include "../json/ripple_json.h"
-
-# include "api/Handler.h"
-# include "api/Service.h"
-#include "api/Manager.h"
#include "api/ErrorCodes.h"
+#include "api/Manager.h"
+#include "api/Request.h"
#endif