@ -271,25 +271,22 @@ UniValue getaddednodeinfo(const UniValue& params, bool fHelp)
{
{
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 2 )
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 2 )
throw runtime_error (
throw runtime_error (
" getaddednodeinfo dns ( \" node \" ) \n "
" getaddednodeinfo dummy ( \" node \" ) \n "
" \n Returns information about the given added node, or all added nodes \n "
" \n Returns information about the given added node, or all added nodes \n "
" (note that onetry addnodes are not listed here) \n "
" (note that onetry addnodes are not listed here) \n "
" If dns is false, only a list of added nodes will be provided, \n "
" otherwise connected information will also be available. \n "
" \n Arguments: \n "
" \n Arguments: \n "
" 1. dns (boolean, required) If false, only a list of added nodes will be provided, otherwise connected information will also be available. \n "
" 1. dummy (boolean, required) Kept for historical purposes but ignored \n "
" 2. \" node \" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned. \n "
" 2. \" node \" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned. \n "
" \n Result: \n "
" \n Result: \n "
" [ \n "
" [ \n "
" { \n "
" { \n "
" \" addednode \" : \" 192.168.0.201 \" , (string) The node ip address \n "
" \" addednode \" : \" 192.168.0.201 \" , (string) The node ip address or name (as provided to addnode) \n "
" \" connected \" : true|false, (boolean) If connected \n "
" \" connected \" : true|false, (boolean) If connected \n "
" \" addresses \" : [ \n "
" \" addresses \" : [ (list of objects) Only when connected = true \n "
" { \n "
" { \n "
" \" address \" : \" 192.168.0.201:8333 \" , (string) The bitcoin server host and port \n "
" \" address \" : \" 192.168.0.201:8333 \" , (string) The bitcoin server IP and port we're connected to \n "
" \" connected \" : \" outbound \" (string) connection, inbound or outbound \n "
" \" connected \" : \" outbound \" (string) connection, inbound or outbound \n "
" } \n "
" } \n "
" ,... \n "
" ] \n "
" ] \n "
" } \n "
" } \n "
" ,... \n "
" ,... \n "
@ -300,83 +297,35 @@ UniValue getaddednodeinfo(const UniValue& params, bool fHelp)
+ HelpExampleRpc ( " getaddednodeinfo " , " true, \" 192.168.0.201 \" " )
+ HelpExampleRpc ( " getaddednodeinfo " , " true, \" 192.168.0.201 \" " )
) ;
) ;
bool fDns = params [ 0 ] . get_bool ( ) ;
std : : vector < AddedNodeInfo > vInfo = GetAddedNodeInfo ( ) ;
list < string > laddedNodes ( 0 ) ;
if ( params . size ( ) = = 2 ) {
if ( params . size ( ) = = 1 )
bool found = false ;
{
for ( const AddedNodeInfo & info : vInfo ) {
LOCK ( cs_vAddedNodes ) ;
if ( info . strAddedNode = = params [ 1 ] . get_str ( ) ) {
BOOST_FOREACH ( const std : : string & strAddNode , vAddedNodes )
vInfo . assign ( 1 , info ) ;
laddedNodes . push_back ( strAddNode ) ;
found = true ;
}
else
{
string strNode = params [ 1 ] . get_str ( ) ;
LOCK ( cs_vAddedNodes ) ;
BOOST_FOREACH ( const std : : string & strAddNode , vAddedNodes ) {
if ( strAddNode = = strNode )
{
laddedNodes . push_back ( strAddNode ) ;
break ;
break ;
}
}
}
}
if ( laddedNodes . size ( ) = = 0 )
if ( ! found ) {
throw JSONRPCError ( RPC_CLIENT_NODE_NOT_ADDED , " Error: Node has not been added. " ) ;
throw JSONRPCError ( RPC_CLIENT_NODE_NOT_ADDED , " Error: Node has not been added. " ) ;
}
}
UniValue ret ( UniValue : : VARR ) ;
if ( ! fDns )
{
BOOST_FOREACH ( const std : : string & strAddNode , laddedNodes ) {
UniValue obj ( UniValue : : VOBJ ) ;
obj . push_back ( Pair ( " addednode " , strAddNode ) ) ;
ret . push_back ( obj ) ;
}
return ret ;
}
}
list < pair < string , vector < CService > > > laddedAddreses ( 0 ) ;
UniValue ret ( UniValue : : VARR ) ;
BOOST_FOREACH ( const std : : string & strAddNode , laddedNodes ) {
vector < CService > vservNode ( 0 ) ;
if ( Lookup ( strAddNode . c_str ( ) , vservNode , Params ( ) . GetDefaultPort ( ) , fNameLookup , 0 ) )
laddedAddreses . push_back ( make_pair ( strAddNode , vservNode ) ) ;
else
{
UniValue obj ( UniValue : : VOBJ ) ;
obj . push_back ( Pair ( " addednode " , strAddNode ) ) ;
obj . push_back ( Pair ( " connected " , false ) ) ;
UniValue addresses ( UniValue : : VARR ) ;
obj . push_back ( Pair ( " addresses " , addresses ) ) ;
ret . push_back ( obj ) ;
}
}
LOCK ( cs_vNodes ) ;
for ( const AddedNodeInfo & info : vInfo ) {
for ( list < pair < string , vector < CService > > > : : iterator it = laddedAddreses . begin ( ) ; it ! = laddedAddreses . end ( ) ; it + + )
{
UniValue obj ( UniValue : : VOBJ ) ;
UniValue obj ( UniValue : : VOBJ ) ;
obj . push_back ( Pair ( " addednode " , it - > first ) ) ;
obj . push_back ( Pair ( " addednode " , info . strAddedNode ) ) ;
obj . push_back ( Pair ( " connected " , info . fConnected ) ) ;
UniValue addresses ( UniValue : : VARR ) ;
UniValue addresses ( UniValue : : VARR ) ;
bool fConnected = false ;
if ( info . fConnected ) {
BOOST_FOREACH ( const CService & addrNode , it - > second ) {
UniValue address ( UniValue : : VOBJ ) ;
bool fFound = false ;
address . push_back ( Pair ( " address " , info . resolvedAddress . ToString ( ) ) ) ;
UniValue node ( UniValue : : VOBJ ) ;
address . push_back ( Pair ( " connected " , info . fInbound ? " inbound " : " outbound " ) ) ;
node . push_back ( Pair ( " address " , addrNode . ToString ( ) ) ) ;
addresses . push_back ( address ) ;
BOOST_FOREACH ( CNode * pnode , vNodes ) {
if ( pnode - > addr = = addrNode )
{
fFound = true ;
fConnected = true ;
node . push_back ( Pair ( " connected " , pnode - > fInbound ? " inbound " : " outbound " ) ) ;
break ;
}
}
if ( ! fFound )
node . push_back ( Pair ( " connected " , " false " ) ) ;
addresses . push_back ( node ) ;
}
}
obj . push_back ( Pair ( " connected " , fConnected ) ) ;
obj . push_back ( Pair ( " addresses " , addresses ) ) ;
obj . push_back ( Pair ( " addresses " , addresses ) ) ;
ret . push_back ( obj ) ;
ret . push_back ( obj ) ;
}
}