MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / addnode

Function addnode

src/rpc/net.cpp:193–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193static UniValue addnode(const JSONRPCRequest& request)
194{
195 std::string strCommand;
196 if (!request.params[1].isNull())
197 strCommand = request.params[1].get_str();
198 if (request.fHelp || request.params.size() != 2 ||
199 (strCommand != "onetry" && strCommand != "add" && strCommand != "remove"))
200 throw std::runtime_error(
201 "addnode \"node\" \"add|remove|onetry\"\n"
202 "\nAttempts to add or remove a node from the addnode list.\n"
203 "Or try a connection to a node once.\n"
204 "Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be\n"
205 "full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).\n"
206 "\nArguments:\n"
207 "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n"
208 "2. \"command\" (string, required) '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\n"
209 "\nExamples:\n"
210 + HelpExampleCli("addnode", "\"192.168.0.6:8338\" \"onetry\"")
211 + HelpExampleRpc("addnode", "\"192.168.0.6:8338\", \"onetry\"")
212 );
213
214 if(!g_connman)
215 throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
216
217 std::string strNode = request.params[0].get_str();
218
219 if (strCommand == "onetry")
220 {
221 CAddress addr;
222 g_connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), false, false, true);
223 return NullUniValue;
224 }
225
226 if (strCommand == "add")
227 {
228 if(!g_connman->AddNode(strNode))
229 throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
230 }
231 else if(strCommand == "remove")
232 {
233 if(!g_connman->RemoveAddedNode(strNode))
234 throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
235 }
236
237 return NullUniValue;
238}
239
240static UniValue disconnectnode(const JSONRPCRequest& request)
241{

Callers

nothing calls this directly

Calls 8

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
isNullMethod · 0.80
OpenNetworkConnectionMethod · 0.80
RemoveAddedNodeMethod · 0.80
sizeMethod · 0.45
AddNodeMethod · 0.45

Tested by

no test coverage detected