Skip to content

Commit

Permalink
[rpc] addnode rpc can include advertised services
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv committed Dec 29, 2021
1 parent 587cbca commit 43dc78e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fCo
std::vector<CService> resolved;
if (Lookup(pszDest, resolved, default_port, fNameLookup && !HaveNameProxy(), 256) && !resolved.empty()) {
const CService rnd{resolved[GetRand(resolved.size())]};
addrConnect = CAddress{MaybeFlipIPv6toCJDNS(rnd), NODE_NONE};
addrConnect = CAddress{MaybeFlipIPv6toCJDNS(rnd), addrConnect.nServices};
if (!addrConnect.IsValid()) {
LogPrint(BCLog::NET, "Resolver returned invalid address %s for %s\n", addrConnect.ToString(), pszDest);
return nullptr;
Expand Down Expand Up @@ -2977,7 +2977,8 @@ ServiceFlags CConnman::GetLocalServices() const
unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; }

CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, SOCKET hSocketIn, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion)
: m_connected{GetTime<std::chrono::seconds>()},
: nServices(addrIn.nServices),
m_connected{GetTime<std::chrono::seconds>()},
addr(addrIn),
addrBind(addrBindIn),
m_addr_name{addrNameIn.empty() ? addr.ToStringIPPort() : addrNameIn},
Expand Down
1 change: 1 addition & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "addpeeraddress", 1, "port"},
{ "addpeeraddress", 2, "tried"},
{ "stop", 0, "wait" },
{ "addnode", 2, "services" },
};
// clang-format on

Expand Down
8 changes: 6 additions & 2 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,12 @@ static RPCHelpMan addnode()
{
{"node", RPCArg::Type::STR, RPCArg::Optional::NO, "The node (see getpeerinfo for nodes)"},
{"command", RPCArg::Type::STR, RPCArg::Optional::NO, "'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once"},
{"services", RPCArg::Type::NUM, RPCArg::Default{0}, "Advertised services for the peer"},
},
RPCResult{RPCResult::Type::NONE, "", ""},
RPCExamples{
HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"")
+ HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")
HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\" 1033")
+ HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\" 1033")
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
Expand All @@ -300,6 +301,9 @@ static RPCHelpMan addnode()
if (strCommand == "onetry")
{
CAddress addr;
if (!request.params[2].isNull()) {
addr.nServices = ServiceFlags{static_cast<uint64_t>(request.params[2].get_int64())};
}
connman.OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), ConnectionType::MANUAL);
return NullUniValue;
}
Expand Down

0 comments on commit 43dc78e

Please sign in to comment.