xrpld
Loading...
Searching...
No Matches
Connect.cpp
1#include <xrpld/app/main/Application.h>
2#include <xrpld/core/Config.h>
3#include <xrpld/overlay/Overlay.h>
4#include <xrpld/rpc/Context.h>
5#include <xrpld/rpc/detail/Handler.h>
6
7#include <xrpl/beast/net/IPEndpoint.h>
8#include <xrpl/json/json_value.h>
9#include <xrpl/protocol/ErrorCodes.h>
10#include <xrpl/protocol/RPCErr.h>
11#include <xrpl/protocol/SystemParameters.h>
12#include <xrpl/protocol/jss.h>
13
14#include <string>
15
16namespace xrpl {
17
18// {
19// ip: <string>,
20// port: <number>
21// }
22// XXX Might allow domain for manual connections.
23json::Value
25{
26 if (context.app.config().standalone())
27 {
29 }
30
31 if (!context.params.isMember(jss::ip))
32 return RPC::missingFieldError(jss::ip);
33
34 if (context.params.isMember(jss::port) &&
35 !context.params[jss::port].isConvertibleTo(json::ValueType::Int))
36 {
38 }
39
40 int iPort = 0;
41
42 if (context.params.isMember(jss::port))
43 {
44 iPort = context.params[jss::port].asInt();
45 }
46 else
47 {
48 iPort = kDefaultPeerPort;
49 }
50
51 auto const ipStr = context.params[jss::ip].asString();
52 auto ip = beast::IP::Endpoint::fromString(ipStr);
53
54 if (!isUnspecified(ip))
55 context.app.getOverlay().connect(ip.atPort(iPort));
56
58 "attempting connection to IP:" + ipStr + " port: " + std::to_string(iPort));
59}
60
61} // namespace xrpl
static Endpoint fromString(std::string const &s)
bool isConvertibleTo(ValueType other) const
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
Int asInt() const
virtual Config & config()=0
bool standalone() const
Definition Config.h:316
virtual void connect(beast::IP::Endpoint const &address)=0
Establish a peer connection to the specified endpoint.
virtual Overlay & getOverlay()=0
@ Int
signed integer value
Definition json_value.h:20
json::Value makeError(ErrorCodeI code)
Returns a new json object that reflects the error code.
json::Value makeObjectValue(Value const &value, json::StaticString const &field=jss::message)
Return a json::ValueType::Object with a single entry.
Definition Handler.h:45
json::Value missingFieldError(std::string const &name)
Definition ErrorCodes.h:231
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ RpcNotSynced
Definition ErrorCodes.h:49
@ RpcInvalidParams
Definition ErrorCodes.h:66
json::Value doConnect(RPC::JsonContext &context)
Definition Connect.cpp:24
json::Value rpcError(ErrorCodeI iError)
Definition RPCErr.cpp:13
Application & app
Definition Context.h:21
json::Value params
Definition Context.h:43
T to_string(T... args)