rippled
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/protocol/ErrorCodes.h>
8#include <xrpl/protocol/RPCErr.h>
9#include <xrpl/protocol/SystemParameters.h>
10#include <xrpl/protocol/jss.h>
11
12namespace ripple {
13
14// {
15// ip: <string>,
16// port: <number>
17// }
18// XXX Might allow domain for manual connections.
21{
22 if (context.app.config().standalone())
23 {
25 }
26
27 if (!context.params.isMember(jss::ip))
28 return RPC::missing_field_error(jss::ip);
29
30 if (context.params.isMember(jss::port) &&
31 !context.params[jss::port].isConvertibleTo(Json::intValue))
32 {
34 }
35
36 int iPort;
37
38 if (context.params.isMember(jss::port))
39 iPort = context.params[jss::port].asInt();
40 else
41 iPort = DEFAULT_PEER_PORT;
42
43 auto const ip_str = context.params[jss::ip].asString();
44 auto ip = beast::IP::Endpoint::from_string(ip_str);
45
46 if (!is_unspecified(ip))
47 context.app.overlay().connect(ip.at_port(iPort));
48
50 "attempting connection to IP:" + ip_str +
51 " port: " + std::to_string(iPort));
52}
53
54} // namespace ripple
Represents a JSON value.
Definition json_value.h:131
Int asInt() 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.
bool isConvertibleTo(ValueType other) const
static Endpoint from_string(std::string const &s)
virtual Config & config()=0
virtual Overlay & overlay()=0
bool standalone() const
Definition Config.h:317
virtual void connect(beast::IP::Endpoint const &address)=0
Establish a peer connection to the specified endpoint.
@ intValue
signed integer value
Definition json_value.h:21
Json::Value make_error(error_code_i 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::objectValue with a single entry.
Definition Handler.h:47
Json::Value missing_field_error(std::string const &name)
Definition ErrorCodes.h:264
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:65
@ rpcNOT_SYNCED
Definition ErrorCodes.h:48
Json::Value rpcError(int iError)
Definition RPCErr.cpp:12
Json::Value doConnect(RPC::JsonContext &context)
Definition Connect.cpp:20
Application & app
Definition Context.h:22
T to_string(T... args)