rippled
Loading...
Searching...
No Matches
Connect.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/main/Application.h>
21#include <xrpld/core/Config.h>
22#include <xrpld/overlay/Overlay.h>
23#include <xrpld/rpc/Context.h>
24#include <xrpld/rpc/detail/Handler.h>
25
26#include <xrpl/protocol/ErrorCodes.h>
27#include <xrpl/protocol/RPCErr.h>
28#include <xrpl/protocol/SystemParameters.h>
29#include <xrpl/protocol/jss.h>
30
31namespace ripple {
32
33// {
34// ip: <string>,
35// port: <number>
36// }
37// XXX Might allow domain for manual connections.
40{
41 if (context.app.config().standalone())
42 {
44 }
45
46 if (!context.params.isMember(jss::ip))
47 return RPC::missing_field_error(jss::ip);
48
49 if (context.params.isMember(jss::port) &&
50 !context.params[jss::port].isConvertibleTo(Json::intValue))
51 {
53 }
54
55 int iPort;
56
57 if (context.params.isMember(jss::port))
58 iPort = context.params[jss::port].asInt();
59 else
60 iPort = DEFAULT_PEER_PORT;
61
62 auto const ip_str = context.params[jss::ip].asString();
63 auto ip = beast::IP::Endpoint::from_string(ip_str);
64
65 if (!is_unspecified(ip))
66 context.app.overlay().connect(ip.at_port(iPort));
67
69 "attempting connection to IP:" + ip_str +
70 " port: " + std::to_string(iPort));
71}
72
73} // namespace ripple
Represents a JSON value.
Definition json_value.h:149
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:336
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:39
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:66
Json::Value missing_field_error(std::string const &name)
Definition ErrorCodes.h:283
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
@ rpcINVALID_PARAMS
Definition ErrorCodes.h:84
@ rpcNOT_SYNCED
Definition ErrorCodes.h:67
Json::Value rpcError(int iError)
Definition RPCErr.cpp:31
Json::Value doConnect(RPC::JsonContext &context)
Definition Connect.cpp:39
Application & app
Definition Context.h:41
T to_string(T... args)