New pathfinder API work.

This commit is contained in:
JoelKatz
2013-04-29 16:42:26 -07:00
parent d6ecc65aad
commit 24bb7a2016
3 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
#ifndef _PFREQUEST__H
#define _PFREQUEST__H
#include <set>
#include <vector>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include "../json/value.h"
#include "uint256.h"
#include "RippleAddress.h"
#include "SerializedTypes.h"
// A pathfinding request submitted by a client
// The request issuer must maintain a strong pointer
class Ledger;
class InfoSub;
class STAmount;
class PFRequest
{
public:
typedef boost::weak_ptr<PFRequest> wptr;
typedef boost::shared_ptr<PFRequest> pointer;
typedef const pointer& ref;
typedef std::pair<uint160, uint160> currIssuer_t;
protected:
boost::weak_ptr<InfoSub> wpSubscriber; // Who this request came from
Json::Value jvStatus; // Last result
// Client request parameters
RippleAddress raSrcAccount;
RippleAddress raDstAccount;
STAmount saDstAmount;
std::set<currIssuer_t> sciSourceCurrencies;
std::vector<Json::Value> vjvBridges;
// Track all requests
static std::set<wptr> sRequests;
static boost::recursive_mutex sLock;
public:
PFRequest(const boost::shared_ptr<InfoSub>& subscriber, Json::Value request);
~PFRequest();
Json::Value create(const Json::Value&);
Json::Value close(const Json::Value&);
Json::Value status(const Json::Value&);
void update();
static void updateAll(const boost::shared_ptr<Ledger> &);
};
#endif

View File

@@ -1166,6 +1166,30 @@ Json::Value RPCHandler::doRandom(Json::Value jvRequest, int& cost, ScopedLock& M
}
}
Json::Value RPCHandler::doPathFind(Json::Value jvRequest, int& cost, ScopedLock& MasterLockHolder)
{
if (!jvRequest.isMember("subcommand") || !jvRequest["subcommand"].isString())
return rpcError(rpcINVALID_PARAMS);
std::string sSubCommand = jvRequest["subcommand"].asString();
if (sSubCommand == "create")
{
// WRITEME
}
if (sSubCommand == "close")
{
// WRITEME
}
if (sSubCommand == "status")
{
// WRITEME
}
return rpcError(rpcINVALID_PARAMS);
}
// TODO:
// - Add support for specifying non-endpoint issuer.
// - Return fully expanded path with proof.
@@ -3292,6 +3316,7 @@ Json::Value RPCHandler::doCommand(const Json::Value& jvRequest, int iRole, int &
// { "nickname_info", &RPCHandler::doNicknameInfo, false, optCurrent },
{ "owner_info", &RPCHandler::doOwnerInfo, false, optCurrent },
{ "peers", &RPCHandler::doPeers, true, optNone },
{ "path_find", &RPCHandler::doPathFind, false, optCurrent },
{ "ping", &RPCHandler::doPing, false, optNone },
// { "profile", &RPCHandler::doProfile, false, optCurrent },
{ "random", &RPCHandler::doRandom, false, optNone },

View File

@@ -69,6 +69,7 @@ class RPCHandler
Json::Value doNicknameInfo(Json::Value params, int& cost, ScopedLock& mlh);
Json::Value doOwnerInfo(Json::Value params, int& cost, ScopedLock& mlh);
Json::Value doPeers(Json::Value params, int& cost, ScopedLock& mlh);
Json::Value doPathFind(Json::Value params, int& cost, ScopedLock& mlh);
Json::Value doPing(Json::Value params, int& cost, ScopedLock& mlh);
Json::Value doProfile(Json::Value params, int& cost, ScopedLock& mlh);
Json::Value doRandom(Json::Value jvRequest, int& cost, ScopedLock& mlh);