2015-12-13 14:51:43 +01:00
// Copyright (c) 2009-2015 The Bitcoin Core developers
2016-12-20 14:26:45 +01:00
// Copyright (c) 2014-2017 The Dash Core developers
2014-11-20 03:19:29 +01:00
// Distributed under the MIT software license, see the accompanying
2012-06-29 05:18:38 +02:00
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2013-11-18 01:25:17 +01:00
2017-07-03 15:13:34 +02:00
# include "rpc/server.h"
2013-11-18 01:25:17 +01:00
2015-07-05 14:17:46 +02:00
# include "chainparams.h"
2014-10-29 02:33:23 +01:00
# include "clientversion.h"
2017-08-09 02:19:06 +02:00
# include "validation.h"
2013-04-13 07:13:08 +02:00
# include "net.h"
2017-08-09 02:19:06 +02:00
# include "net_processing.h"
2013-04-13 07:13:08 +02:00
# include "netbase.h"
# include "protocol.h"
# include "sync.h"
2014-06-19 15:08:37 +02:00
# include "timedata.h"
2015-06-20 20:27:28 +02:00
# include "ui_interface.h"
2013-04-13 07:13:08 +02:00
# include "util.h"
2015-07-05 14:17:46 +02:00
# include "utilstrencodings.h"
2014-09-15 03:54:32 +02:00
# include "version.h"
2013-04-13 07:13:08 +02:00
# include <boost/foreach.hpp>
2014-09-14 12:43:56 +02:00
2015-09-04 16:11:34 +02:00
# include <univalue.h>
2012-06-29 05:18:38 +02:00
using namespace std ;
2015-05-18 14:02:18 +02:00
UniValue getconnectioncount ( const UniValue & params , bool fHelp )
2012-06-29 05:18:38 +02:00
{
if ( fHelp | | params . size ( ) ! = 0 )
throw runtime_error (
" getconnectioncount \n "
2013-10-29 12:29:44 +01:00
" \n Returns the number of connections to other nodes. \n "
2015-10-22 17:00:36 +02:00
" \n Result: \n "
2013-10-29 12:29:44 +01:00
" n (numeric) The connection count \n "
" \n Examples: \n "
+ HelpExampleCli ( " getconnectioncount " , " " )
+ HelpExampleRpc ( " getconnectioncount " , " " )
) ;
2012-06-29 05:18:38 +02:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2014-10-19 10:46:17 +02:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
return ( int ) g_connman - > GetNodeCount ( CConnman : : CONNECTIONS_ALL ) ;
2012-06-29 05:18:38 +02:00
}
2015-05-18 14:02:18 +02:00
UniValue ping ( const UniValue & params , bool fHelp )
2013-08-22 13:34:33 +02:00
{
if ( fHelp | | params . size ( ) ! = 0 )
throw runtime_error (
" ping \n "
2013-10-29 12:29:44 +01:00
" \n Requests that a ping be sent to all other nodes, to measure ping time. \n "
2013-08-22 13:34:33 +02:00
" Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds. \n "
2014-01-30 14:13:30 +01:00
" Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping. \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
+ HelpExampleCli ( " ping " , " " )
+ HelpExampleRpc ( " ping " , " " )
) ;
2013-10-23 16:19:49 +02:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2013-08-22 13:34:33 +02:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
// Request that each node send a ping during next message processing pass
g_connman - > ForEachNode ( [ ] ( CNode * pnode ) {
pnode - > fPingQueued = true ;
} ) ;
2014-08-20 21:15:16 +02:00
return NullUniValue ;
2013-08-22 13:34:33 +02:00
}
2015-05-18 14:02:18 +02:00
UniValue getpeerinfo ( const UniValue & params , bool fHelp )
2012-06-29 23:24:53 +02:00
{
if ( fHelp | | params . size ( ) ! = 0 )
throw runtime_error (
" getpeerinfo \n "
2013-10-29 12:29:44 +01:00
" \n Returns data about each connected network node as a json array of objects. \n "
2015-10-22 17:00:36 +02:00
" \n Result: \n "
2013-10-29 12:29:44 +01:00
" [ \n "
" { \n "
2014-07-15 16:13:10 +02:00
" \" id \" : n, (numeric) Peer index \n "
2013-10-29 12:29:44 +01:00
" \" addr \" : \" host:port \" , (string) The ip address and port of the peer \n "
" \" addrlocal \" : \" ip:port \" , (string) local address \n "
2014-06-06 09:15:55 +02:00
" \" services \" : \" xxxxxxxxxxxxxxxx \" , (string) The services offered \n "
2015-11-21 00:51:44 +01:00
" \" relaytxes \" :true|false, (boolean) Whether peer has asked us to relay transactions to it \n "
2013-10-29 12:29:44 +01:00
" \" lastsend \" : ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send \n "
" \" lastrecv \" : ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive \n "
" \" bytessent \" : n, (numeric) The total bytes sent \n "
" \" bytesrecv \" : n, (numeric) The total bytes received \n "
" \" conntime \" : ttt, (numeric) The connection time in seconds since epoch (Jan 1 1970 GMT) \n "
2014-12-15 11:06:15 +01:00
" \" timeoffset \" : ttt, (numeric) The time offset in seconds \n "
2017-09-09 09:04:02 +02:00
" \" pingtime \" : n, (numeric) ping time (if available) \n "
" \" minping \" : n, (numeric) minimum observed ping time (if any at all) \n "
" \" pingwait \" : n, (numeric) ping wait (if non-zero) \n "
2013-10-29 12:29:44 +01:00
" \" version \" : v, (numeric) The peer version, such as 7001 \n "
2015-07-07 00:40:38 +02:00
" \" subver \" : \" /Dash Core:x.x.x/ \" , (string) The string version \n "
2013-10-29 12:29:44 +01:00
" \" inbound \" : true|false, (boolean) Inbound (true) or Outbound (false) \n "
" \" startingheight \" : n, (numeric) The starting height (block) of the peer \n "
2014-09-16 09:00:36 +02:00
" \" banscore \" : n, (numeric) The ban score \n "
2014-07-12 00:03:10 +02:00
" \" synced_headers \" : n, (numeric) The last header we have in common with this peer \n "
" \" synced_blocks \" : n, (numeric) The last block we have in common with this peer \n "
" \" inflight \" : [ \n "
" n, (numeric) The heights of blocks we're currently asking from this peer \n "
" ... \n "
" ] \n "
2017-06-29 03:51:10 +02:00
" \" bytessent_per_msg \" : { \n "
" \" addr \" : n, (numeric) The total bytes sent aggregated by message type \n "
" ... \n "
" } \n "
" \" bytesrecv_per_msg \" : { \n "
" \" addr \" : n, (numeric) The total bytes received aggregated by message type \n "
" ... \n "
" } \n "
2013-10-29 12:29:44 +01:00
" } \n "
" ,... \n "
2014-07-17 15:09:03 +02:00
" ] \n "
2013-10-29 12:29:44 +01:00
" \n Examples: \n "
+ HelpExampleCli ( " getpeerinfo " , " " )
+ HelpExampleRpc ( " getpeerinfo " , " " )
) ;
2012-06-29 23:24:53 +02:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2014-10-19 10:46:17 +02:00
2012-06-29 23:24:53 +02:00
vector < CNodeStats > vstats ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
g_connman - > GetNodeStats ( vstats ) ;
2012-06-29 23:24:53 +02:00
2015-05-10 14:48:35 +02:00
UniValue ret ( UniValue : : VARR ) ;
2012-06-29 23:24:53 +02:00
BOOST_FOREACH ( const CNodeStats & stats , vstats ) {
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2013-11-18 01:25:17 +01:00
CNodeStateStats statestats ;
bool fStateStats = GetNodeStateStats ( stats . nodeid , statestats ) ;
2014-07-15 16:13:10 +02:00
obj . push_back ( Pair ( " id " , stats . nodeid ) ) ;
2012-06-29 23:24:53 +02:00
obj . push_back ( Pair ( " addr " , stats . addrName ) ) ;
2013-08-22 07:50:19 +02:00
if ( ! ( stats . addrLocal . empty ( ) ) )
obj . push_back ( Pair ( " addrlocal " , stats . addrLocal ) ) ;
2014-06-06 09:15:55 +02:00
obj . push_back ( Pair ( " services " , strprintf ( " %016x " , stats . nServices ) ) ) ;
2015-11-21 00:51:44 +01:00
obj . push_back ( Pair ( " relaytxes " , stats . fRelayTxes ) ) ;
2014-05-05 20:08:13 +02:00
obj . push_back ( Pair ( " lastsend " , stats . nLastSend ) ) ;
obj . push_back ( Pair ( " lastrecv " , stats . nLastRecv ) ) ;
obj . push_back ( Pair ( " bytessent " , stats . nSendBytes ) ) ;
obj . push_back ( Pair ( " bytesrecv " , stats . nRecvBytes ) ) ;
obj . push_back ( Pair ( " conntime " , stats . nTimeConnected ) ) ;
2014-12-15 11:06:15 +01:00
obj . push_back ( Pair ( " timeoffset " , stats . nTimeOffset ) ) ;
2017-09-09 09:04:02 +02:00
if ( stats . dPingTime > 0.0 )
obj . push_back ( Pair ( " pingtime " , stats . dPingTime ) ) ;
if ( stats . dMinPing < std : : numeric_limits < int64_t > : : max ( ) / 1e6 )
obj . push_back ( Pair ( " minping " , stats . dMinPing ) ) ;
2013-08-22 13:34:33 +02:00
if ( stats . dPingWait > 0.0 )
obj . push_back ( Pair ( " pingwait " , stats . dPingWait ) ) ;
2012-06-29 23:24:53 +02:00
obj . push_back ( Pair ( " version " , stats . nVersion ) ) ;
2013-11-26 12:52:21 +01:00
// Use the sanitized form of subver here, to avoid tricksy remote peers from
// corrupting or modifiying the JSON output by putting special characters in
// their ver message.
obj . push_back ( Pair ( " subver " , stats . cleanSubVer ) ) ;
2012-06-29 23:24:53 +02:00
obj . push_back ( Pair ( " inbound " , stats . fInbound ) ) ;
2012-07-01 05:40:26 +02:00
obj . push_back ( Pair ( " startingheight " , stats . nStartingHeight ) ) ;
2013-11-18 01:25:17 +01:00
if ( fStateStats ) {
obj . push_back ( Pair ( " banscore " , statestats . nMisbehavior ) ) ;
2014-07-12 00:03:10 +02:00
obj . push_back ( Pair ( " synced_headers " , statestats . nSyncHeight ) ) ;
obj . push_back ( Pair ( " synced_blocks " , statestats . nCommonHeight ) ) ;
2015-05-10 14:48:35 +02:00
UniValue heights ( UniValue : : VARR ) ;
2014-07-12 00:03:10 +02:00
BOOST_FOREACH ( int height , statestats . vHeightInFlight ) {
heights . push_back ( height ) ;
}
obj . push_back ( Pair ( " inflight " , heights ) ) ;
2013-11-18 01:25:17 +01:00
}
2014-06-21 13:34:36 +02:00
obj . push_back ( Pair ( " whitelisted " , stats . fWhitelisted ) ) ;
2012-06-29 23:24:53 +02:00
2017-06-29 03:51:10 +02:00
UniValue sendPerMsgCmd ( UniValue : : VOBJ ) ;
BOOST_FOREACH ( const mapMsgCmdSize : : value_type & i , stats . mapSendBytesPerMsgCmd ) {
if ( i . second > 0 )
sendPerMsgCmd . push_back ( Pair ( i . first , i . second ) ) ;
}
obj . push_back ( Pair ( " bytessent_per_msg " , sendPerMsgCmd ) ) ;
UniValue recvPerMsgCmd ( UniValue : : VOBJ ) ;
BOOST_FOREACH ( const mapMsgCmdSize : : value_type & i , stats . mapRecvBytesPerMsgCmd ) {
if ( i . second > 0 )
recvPerMsgCmd . push_back ( Pair ( i . first , i . second ) ) ;
}
obj . push_back ( Pair ( " bytesrecv_per_msg " , recvPerMsgCmd ) ) ;
2012-06-29 23:24:53 +02:00
ret . push_back ( obj ) ;
}
2012-09-18 21:07:58 +02:00
2012-06-29 23:24:53 +02:00
return ret ;
}
2012-06-29 05:18:38 +02:00
2015-05-18 14:02:18 +02:00
UniValue addnode ( const UniValue & params , bool fHelp )
2013-01-23 17:45:00 +01:00
{
string strCommand ;
if ( params . size ( ) = = 2 )
strCommand = params [ 1 ] . get_str ( ) ;
if ( fHelp | | params . size ( ) ! = 2 | |
( strCommand ! = " onetry " & & strCommand ! = " add " & & strCommand ! = " remove " ) )
throw runtime_error (
2013-10-29 12:29:44 +01:00
" addnode \" node \" \" add|remove|onetry \" \n "
" \n Attempts add or remove a node from the addnode list. \n "
" Or try a connection to a node once. \n "
" \n Arguments: \n "
" 1. \" node \" (string, required) The node (see getpeerinfo for nodes) \n "
" 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 "
" \n Examples: \n "
2014-11-27 18:09:11 +01:00
+ HelpExampleCli ( " addnode " , " \" 192.168.0.6:9999 \" \" onetry \" " )
+ HelpExampleRpc ( " addnode " , " \" 192.168.0.6:9999 \" , \" onetry \" " )
2013-10-29 12:29:44 +01:00
) ;
2013-01-23 17:45:00 +01:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2013-01-23 17:45:00 +01:00
string strNode = params [ 0 ] . get_str ( ) ;
if ( strCommand = = " onetry " )
{
CAddress addr ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
g_connman - > OpenNetworkConnection ( addr , NULL , strNode . c_str ( ) ) ;
2014-08-20 21:15:16 +02:00
return NullUniValue ;
2013-01-23 17:45:00 +01:00
}
if ( strCommand = = " add " )
{
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman - > AddNode ( strNode ) )
2013-10-23 16:19:49 +02:00
throw JSONRPCError ( RPC_CLIENT_NODE_ALREADY_ADDED , " Error: Node already added " ) ;
2013-01-23 17:45:00 +01:00
}
else if ( strCommand = = " remove " )
{
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman - > RemoveAddedNode ( strNode ) )
2013-10-23 16:19:49 +02:00
throw JSONRPCError ( RPC_CLIENT_NODE_NOT_ADDED , " Error: Node has not been added. " ) ;
2013-01-23 17:45:00 +01:00
}
2014-08-20 21:15:16 +02:00
return NullUniValue ;
2013-01-23 17:45:00 +01:00
}
2015-06-12 05:20:54 +02:00
UniValue disconnectnode ( const UniValue & params , bool fHelp )
{
if ( fHelp | | params . size ( ) ! = 1 )
throw runtime_error (
" disconnectnode \" node \" \n "
" \n Immediately disconnects from the specified node. \n "
" \n Arguments: \n "
" 1. \" node \" (string, required) The node (see getpeerinfo for nodes) \n "
" \n Examples: \n "
+ HelpExampleCli ( " disconnectnode " , " \" 192.168.0.6:8333 \" " )
+ HelpExampleRpc ( " disconnectnode " , " \" 192.168.0.6:8333 \" " )
) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2015-06-12 05:20:54 +02:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
bool ret = g_connman - > DisconnectNode ( params [ 0 ] . get_str ( ) ) ;
if ( ! ret )
throw JSONRPCError ( RPC_CLIENT_NODE_NOT_CONNECTED , " Node not found in connected nodes " ) ;
2015-06-12 05:20:54 +02:00
return NullUniValue ;
}
2015-05-18 14:02:18 +02:00
UniValue getaddednodeinfo ( const UniValue & params , bool fHelp )
2013-01-23 17:48:17 +01:00
{
if ( fHelp | | params . size ( ) < 1 | | params . size ( ) > 2 )
throw runtime_error (
2017-07-14 18:58:57 +02:00
" getaddednodeinfo dummy ( \" node \" ) \n "
2013-10-29 12:29:44 +01:00
" \n Returns information about the given added node, or all added nodes \n "
2013-01-23 17:48:17 +01:00
" (note that onetry addnodes are not listed here) \n "
2013-10-29 12:29:44 +01:00
" \n Arguments: \n "
2017-07-14 18:58:57 +02:00
" 1. dummy (boolean, required) Kept for historical purposes but ignored \n "
2013-10-29 12:29:44 +01:00
" 2. \" node \" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned. \n "
" \n Result: \n "
" [ \n "
" { \n "
2017-07-14 18:58:57 +02:00
" \" addednode \" : \" 192.168.0.201 \" , (string) The node ip address or name (as provided to addnode) \n "
2013-10-29 12:29:44 +01:00
" \" connected \" : true|false, (boolean) If connected \n "
2017-07-14 18:58:57 +02:00
" \" addresses \" : [ (list of objects) Only when connected = true \n "
2013-10-29 12:29:44 +01:00
" { \n "
2017-07-14 18:58:57 +02:00
" \" address \" : \" 192.168.0.201:9999 \" , (string) The dash server IP and port we're connected to \n "
2013-10-29 12:29:44 +01:00
" \" connected \" : \" outbound \" (string) connection, inbound or outbound \n "
" } \n "
" ] \n "
" } \n "
" ,... \n "
" ] \n "
" \n Examples: \n "
+ HelpExampleCli ( " getaddednodeinfo " , " true " )
+ HelpExampleCli ( " getaddednodeinfo " , " true \" 192.168.0.201 \" " )
+ HelpExampleRpc ( " getaddednodeinfo " , " true, \" 192.168.0.201 \" " )
) ;
2013-01-23 17:48:17 +01:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
std : : vector < AddedNodeInfo > vInfo = g_connman - > GetAddedNodeInfo ( ) ;
2013-01-23 17:48:17 +01:00
2017-07-14 18:58:57 +02:00
if ( params . size ( ) = = 2 ) {
bool found = false ;
for ( const AddedNodeInfo & info : vInfo ) {
if ( info . strAddedNode = = params [ 1 ] . get_str ( ) ) {
vInfo . assign ( 1 , info ) ;
found = true ;
2013-01-23 17:48:17 +01:00
break ;
}
2015-05-31 15:36:44 +02:00
}
2017-07-14 18:58:57 +02:00
if ( ! found ) {
2013-10-23 16:19:49 +02:00
throw JSONRPCError ( RPC_CLIENT_NODE_NOT_ADDED , " Error: Node has not been added. " ) ;
2014-01-27 10:31:22 +01:00
}
2013-01-23 17:48:17 +01:00
}
2017-07-14 18:58:57 +02:00
UniValue ret ( UniValue : : VARR ) ;
2013-01-23 17:48:17 +01:00
2017-07-14 18:58:57 +02:00
for ( const AddedNodeInfo & info : vInfo ) {
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2017-07-14 18:58:57 +02:00
obj . push_back ( Pair ( " addednode " , info . strAddedNode ) ) ;
obj . push_back ( Pair ( " connected " , info . fConnected ) ) ;
2015-05-10 14:48:35 +02:00
UniValue addresses ( UniValue : : VARR ) ;
2017-07-14 18:58:57 +02:00
if ( info . fConnected ) {
UniValue address ( UniValue : : VOBJ ) ;
address . push_back ( Pair ( " address " , info . resolvedAddress . ToString ( ) ) ) ;
address . push_back ( Pair ( " connected " , info . fInbound ? " inbound " : " outbound " ) ) ;
addresses . push_back ( address ) ;
2013-01-23 17:48:17 +01:00
}
obj . push_back ( Pair ( " addresses " , addresses ) ) ;
ret . push_back ( obj ) ;
}
return ret ;
}
2015-05-18 14:02:18 +02:00
UniValue getnettotals ( const UniValue & params , bool fHelp )
2013-08-22 18:09:32 +02:00
{
if ( fHelp | | params . size ( ) > 0 )
throw runtime_error (
" getnettotals \n "
2013-10-29 12:29:44 +01:00
" \n Returns information about network traffic, including bytes in, bytes out, \n "
" and current time. \n "
" \n Result: \n "
" { \n "
" \" totalbytesrecv \" : n, (numeric) Total bytes received \n "
2013-12-05 08:46:50 +01:00
" \" totalbytessent \" : n, (numeric) Total bytes sent \n "
2015-11-12 13:14:54 +01:00
" \" timemillis \" : t, (numeric) Total cpu time \n "
" \" uploadtarget \" : \n "
" { \n "
" \" timeframe \" : n, (numeric) Length of the measuring timeframe in seconds \n "
" \" target \" : n, (numeric) Target in bytes \n "
" \" target_reached \" : true|false, (boolean) True if target is reached \n "
" \" serve_historical_blocks \" : true|false, (boolean) True if serving historical blocks \n "
" \" bytes_left_in_cycle \" : t, (numeric) Bytes left in current time cycle \n "
" \" time_left_in_cycle \" : t (numeric) Seconds left in current time cycle \n "
" } \n "
2013-10-29 12:29:44 +01:00
" } \n "
" \n Examples: \n "
+ HelpExampleCli ( " getnettotals " , " " )
+ HelpExampleRpc ( " getnettotals " , " " )
) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2013-08-22 18:09:32 +02:00
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
obj . push_back ( Pair ( " totalbytesrecv " , g_connman - > GetTotalBytesRecv ( ) ) ) ;
obj . push_back ( Pair ( " totalbytessent " , g_connman - > GetTotalBytesSent ( ) ) ) ;
2014-05-05 20:08:13 +02:00
obj . push_back ( Pair ( " timemillis " , GetTimeMillis ( ) ) ) ;
2015-09-02 17:03:27 +02:00
UniValue outboundLimit ( UniValue : : VOBJ ) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
outboundLimit . push_back ( Pair ( " timeframe " , g_connman - > GetMaxOutboundTimeframe ( ) ) ) ;
outboundLimit . push_back ( Pair ( " target " , g_connman - > GetMaxOutboundTarget ( ) ) ) ;
outboundLimit . push_back ( Pair ( " target_reached " , g_connman - > OutboundTargetReached ( false ) ) ) ;
outboundLimit . push_back ( Pair ( " serve_historical_blocks " , ! g_connman - > OutboundTargetReached ( true ) ) ) ;
outboundLimit . push_back ( Pair ( " bytes_left_in_cycle " , g_connman - > GetOutboundTargetBytesLeft ( ) ) ) ;
outboundLimit . push_back ( Pair ( " time_left_in_cycle " , g_connman - > GetMaxOutboundTimeLeftInCycle ( ) ) ) ;
2015-09-02 17:03:27 +02:00
obj . push_back ( Pair ( " uploadtarget " , outboundLimit ) ) ;
2013-08-22 18:09:32 +02:00
return obj ;
}
2014-05-05 13:22:28 +02:00
2015-05-13 21:29:19 +02:00
static UniValue GetNetworksInfo ( )
2014-07-30 15:35:14 +02:00
{
2015-05-10 14:48:35 +02:00
UniValue networks ( UniValue : : VARR ) ;
2014-07-30 15:35:14 +02:00
for ( int n = 0 ; n < NET_MAX ; + + n )
{
enum Network network = static_cast < enum Network > ( n ) ;
if ( network = = NET_UNROUTABLE )
continue ;
proxyType proxy ;
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2014-07-30 15:35:14 +02:00
GetProxy ( network , proxy ) ;
obj . push_back ( Pair ( " name " , GetNetworkName ( network ) ) ) ;
obj . push_back ( Pair ( " limited " , IsLimited ( network ) ) ) ;
obj . push_back ( Pair ( " reachable " , IsReachable ( network ) ) ) ;
2015-03-16 16:30:49 +01:00
obj . push_back ( Pair ( " proxy " , proxy . IsValid ( ) ? proxy . proxy . ToStringIPPort ( ) : string ( ) ) ) ;
obj . push_back ( Pair ( " proxy_randomize_credentials " , proxy . randomize_credentials ) ) ;
2014-07-30 15:35:14 +02:00
networks . push_back ( obj ) ;
}
return networks ;
}
2015-05-18 14:02:18 +02:00
UniValue getnetworkinfo ( const UniValue & params , bool fHelp )
2014-05-05 13:22:28 +02:00
{
if ( fHelp | | params . size ( ) ! = 0 )
throw runtime_error (
" getnetworkinfo \n "
" Returns an object containing various state info regarding P2P networking. \n "
" \n Result: \n "
" { \n "
2014-09-25 11:56:05 +02:00
" \" version \" : xxxxx, (numeric) the server version \n "
2015-07-07 00:40:38 +02:00
" \" subversion \" : \" /Dash Core:x.x.x/ \" , (string) the server subversion string \n "
2014-09-25 11:56:05 +02:00
" \" protocolversion \" : xxxxx, (numeric) the protocol version \n "
" \" localservices \" : \" xxxxxxxxxxxxxxxx \" , (string) the services we offer to the network \n "
2017-07-21 20:31:47 +02:00
" \" localrelay \" : true|false, (bool) true if transaction relay is requested from peers \n "
2014-09-25 11:56:05 +02:00
" \" timeoffset \" : xxxxx, (numeric) the time offset \n "
" \" connections \" : xxxxx, (numeric) the number of connections \n "
2017-09-11 15:38:14 +02:00
" \" networkactive \" : true|false, (bool) whether p2p networking is enabled \n "
2014-09-25 11:56:05 +02:00
" \" networks \" : [ (array) information per network \n "
" { \n "
" \" name \" : \" xxx \" , (string) network (ipv4, ipv6 or onion) \n "
" \" limited \" : true|false, (boolean) is the network limited using -onlynet? \n "
" \" reachable \" : true|false, (boolean) is the network reachable? \n "
" \" proxy \" : \" host:port \" (string) the proxy that is used for this network, or empty if none \n "
" } \n "
" ,... \n "
2014-07-30 15:35:14 +02:00
" ], \n "
2015-08-01 21:15:23 +02:00
" \" relayfee \" : x.xxxxxxxx, (numeric) minimum relay fee for non-free transactions in " + CURRENCY_UNIT + " /kB \n "
2014-09-25 11:56:05 +02:00
" \" localaddresses \" : [ (array) list of local addresses \n "
" { \n "
" \" address \" : \" xxxx \" , (string) network address \n "
" \" port \" : xxx, (numeric) network port \n "
" \" score \" : xxx (numeric) relative score \n "
" } \n "
" ,... \n "
2014-05-05 13:22:28 +02:00
" ] \n "
2015-06-11 22:12:34 +02:00
" \" warnings \" : \" ... \" (string) any network warnings (such as alert messages) \n "
2014-05-05 13:22:28 +02:00
" } \n "
" \n Examples: \n "
+ HelpExampleCli ( " getnetworkinfo " , " " )
+ HelpExampleRpc ( " getnetworkinfo " , " " )
) ;
2014-10-19 10:46:17 +02:00
LOCK ( cs_main ) ;
2015-05-10 14:48:35 +02:00
UniValue obj ( UniValue : : VOBJ ) ;
2014-09-25 11:56:05 +02:00
obj . push_back ( Pair ( " version " , CLIENT_VERSION ) ) ;
2015-07-31 18:05:42 +02:00
obj . push_back ( Pair ( " subversion " , strSubVersion ) ) ;
2014-09-25 11:56:05 +02:00
obj . push_back ( Pair ( " protocolversion " , PROTOCOL_VERSION ) ) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( g_connman )
obj . push_back ( Pair ( " localservices " , strprintf ( " %016x " , g_connman - > GetLocalServices ( ) ) ) ) ;
2017-07-21 20:31:47 +02:00
obj . push_back ( Pair ( " localrelay " , fRelayTxes ) ) ;
2014-05-05 20:08:13 +02:00
obj . push_back ( Pair ( " timeoffset " , GetTimeOffset ( ) ) ) ;
2017-09-11 15:38:14 +02:00
if ( g_connman ) {
obj . push_back ( Pair ( " networkactive " , g_connman - > GetNetworkActive ( ) ) ) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
obj . push_back ( Pair ( " connections " , ( int ) g_connman - > GetNodeCount ( CConnman : : CONNECTIONS_ALL ) ) ) ;
2017-09-11 15:38:14 +02:00
}
2014-07-30 15:35:14 +02:00
obj . push_back ( Pair ( " networks " , GetNetworksInfo ( ) ) ) ;
2014-07-03 20:25:32 +02:00
obj . push_back ( Pair ( " relayfee " , ValueFromAmount ( : : minRelayTxFee . GetFeePerK ( ) ) ) ) ;
2015-05-10 14:48:35 +02:00
UniValue localAddresses ( UniValue : : VARR ) ;
2014-05-05 13:22:28 +02:00
{
LOCK ( cs_mapLocalHost ) ;
BOOST_FOREACH ( const PAIRTYPE ( CNetAddr , LocalServiceInfo ) & item , mapLocalHost )
{
2015-05-10 14:48:35 +02:00
UniValue rec ( UniValue : : VOBJ ) ;
2014-05-05 13:22:28 +02:00
rec . push_back ( Pair ( " address " , item . first . ToString ( ) ) ) ;
rec . push_back ( Pair ( " port " , item . second . nPort ) ) ;
rec . push_back ( Pair ( " score " , item . second . nScore ) ) ;
localAddresses . push_back ( rec ) ;
}
}
obj . push_back ( Pair ( " localaddresses " , localAddresses ) ) ;
2015-06-11 22:12:34 +02:00
obj . push_back ( Pair ( " warnings " , GetWarnings ( " statusbar " ) ) ) ;
2014-05-05 13:22:28 +02:00
return obj ;
}
2015-05-19 10:07:46 +02:00
2015-06-12 18:31:47 +02:00
UniValue setban ( const UniValue & params , bool fHelp )
2015-05-19 10:07:46 +02:00
{
string strCommand ;
if ( params . size ( ) > = 2 )
strCommand = params [ 1 ] . get_str ( ) ;
if ( fHelp | | params . size ( ) < 2 | |
( strCommand ! = " add " & & strCommand ! = " remove " ) )
throw runtime_error (
2015-06-12 18:31:47 +02:00
" setban \" ip(/netmask) \" \" add|remove \" (bantime) (absolute) \n "
2015-05-25 20:03:51 +02:00
" \n Attempts add or remove a IP/Subnet from the banned list. \n "
2015-05-19 10:07:46 +02:00
" \n Arguments: \n "
2015-05-25 20:03:51 +02:00
" 1. \" ip(/netmask) \" (string, required) The IP/Subnet (see getpeerinfo for nodes ip) with a optional netmask (default is /32 = single ip) \n "
" 2. \" command \" (string, required) 'add' to add a IP/Subnet to the list, 'remove' to remove a IP/Subnet from the list \n "
2015-06-12 18:31:47 +02:00
" 3. \" bantime \" (numeric, optional) time in seconds how long (or until when if [absolute] is set) the ip is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument) \n "
" 4. \" absolute \" (boolean, optional) If set, the bantime must be a absolute timestamp in seconds since epoch (Jan 1 1970 GMT) \n "
2015-05-19 10:07:46 +02:00
" \n Examples: \n "
+ HelpExampleCli ( " setban " , " \" 192.168.0.6 \" \" add \" 86400 " )
2015-05-25 20:03:51 +02:00
+ HelpExampleCli ( " setban " , " \" 192.168.0.0/24 \" \" add \" " )
2015-05-19 10:07:46 +02:00
+ HelpExampleRpc ( " setban " , " \" 192.168.0.6 \" , \" add \" 86400 " )
) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2015-05-19 10:07:46 +02:00
2015-05-25 20:03:51 +02:00
CSubNet subNet ;
CNetAddr netAddr ;
bool isSubnet = false ;
if ( params [ 0 ] . get_str ( ) . find ( " / " ) ! = string : : npos )
isSubnet = true ;
2017-09-03 15:29:10 +02:00
if ( ! isSubnet ) {
CNetAddr resolved ;
LookupHost ( params [ 0 ] . get_str ( ) . c_str ( ) , resolved , false ) ;
netAddr = resolved ;
}
2015-05-25 20:03:51 +02:00
else
2017-09-03 15:29:10 +02:00
LookupSubNet ( params [ 0 ] . get_str ( ) . c_str ( ) , subNet ) ;
2015-05-25 20:03:51 +02:00
if ( ! ( isSubnet ? subNet . IsValid ( ) : netAddr . IsValid ( ) ) )
throw JSONRPCError ( RPC_CLIENT_NODE_ALREADY_ADDED , " Error: Invalid IP/Subnet " ) ;
2015-05-19 10:07:46 +02:00
if ( strCommand = = " add " )
{
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( isSubnet ? g_connman - > IsBanned ( subNet ) : g_connman - > IsBanned ( netAddr ) )
2015-05-25 20:03:51 +02:00
throw JSONRPCError ( RPC_CLIENT_NODE_ALREADY_ADDED , " Error: IP/Subnet already banned " ) ;
2015-05-19 10:07:46 +02:00
int64_t banTime = 0 ; //use standard bantime if not specified
2015-06-12 18:31:47 +02:00
if ( params . size ( ) > = 3 & & ! params [ 2 ] . isNull ( ) )
2015-05-19 10:07:46 +02:00
banTime = params [ 2 ] . get_int64 ( ) ;
2015-06-12 18:31:47 +02:00
bool absolute = false ;
if ( params . size ( ) = = 4 & & params [ 3 ] . isTrue ( ) )
absolute = true ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
isSubnet ? g_connman - > Ban ( subNet , BanReasonManuallyAdded , banTime , absolute ) : g_connman - > Ban ( netAddr , BanReasonManuallyAdded , banTime , absolute ) ;
2015-05-19 10:07:46 +02:00
}
else if ( strCommand = = " remove " )
{
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! ( isSubnet ? g_connman - > Unban ( subNet ) : g_connman - > Unban ( netAddr ) ) )
2015-06-12 22:27:03 +02:00
throw JSONRPCError ( RPC_MISC_ERROR , " Error: Unban failed " ) ;
2015-05-19 10:07:46 +02:00
}
2015-06-12 18:31:47 +02:00
return NullUniValue ;
2015-05-19 10:07:46 +02:00
}
2015-06-12 18:31:47 +02:00
UniValue listbanned ( const UniValue & params , bool fHelp )
2015-05-19 10:07:46 +02:00
{
if ( fHelp | | params . size ( ) ! = 0 )
throw runtime_error (
" listbanned \n "
2015-05-25 20:03:51 +02:00
" \n List all banned IPs/Subnets. \n "
2015-05-19 10:07:46 +02:00
" \n Examples: \n "
+ HelpExampleCli ( " listbanned " , " " )
+ HelpExampleRpc ( " listbanned " , " " )
) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2015-06-26 21:38:33 +02:00
banmap_t banMap ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
g_connman - > GetBanned ( banMap ) ;
2015-05-19 10:07:46 +02:00
2015-06-12 18:31:47 +02:00
UniValue bannedAddresses ( UniValue : : VARR ) ;
2015-06-26 21:38:33 +02:00
for ( banmap_t : : iterator it = banMap . begin ( ) ; it ! = banMap . end ( ) ; it + + )
2015-05-19 10:07:46 +02:00
{
2015-06-26 21:38:33 +02:00
CBanEntry banEntry = ( * it ) . second ;
2015-06-12 18:31:47 +02:00
UniValue rec ( UniValue : : VOBJ ) ;
2015-05-19 10:07:46 +02:00
rec . push_back ( Pair ( " address " , ( * it ) . first . ToString ( ) ) ) ;
2015-06-26 21:38:33 +02:00
rec . push_back ( Pair ( " banned_until " , banEntry . nBanUntil ) ) ;
rec . push_back ( Pair ( " ban_created " , banEntry . nCreateTime ) ) ;
rec . push_back ( Pair ( " ban_reason " , banEntry . banReasonToString ( ) ) ) ;
2015-05-19 10:07:46 +02:00
bannedAddresses . push_back ( rec ) ;
}
return bannedAddresses ;
}
2015-06-12 18:31:47 +02:00
UniValue clearbanned ( const UniValue & params , bool fHelp )
2015-05-19 10:07:46 +02:00
{
if ( fHelp | | params . size ( ) ! = 0 )
throw runtime_error (
" clearbanned \n "
" \n Clear all banned IPs. \n "
" \n Examples: \n "
+ HelpExampleCli ( " clearbanned " , " " )
+ HelpExampleRpc ( " clearbanned " , " " )
) ;
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
if ( ! g_connman )
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
2015-05-19 10:07:46 +02:00
Backport Bitcoin PR#8085: p2p: Begin encapsulation (#1537)
* net: move CBanDB and CAddrDB out of net.h/cpp
This will eventually solve a circular dependency
* net: Create CConnman to encapsulate p2p connections
* net: Move socket binding into CConnman
* net: move OpenNetworkConnection into CConnman
* net: move ban and addrman functions into CConnman
* net: Add oneshot functions to CConnman
* net: move added node functions to CConnman
* net: Add most functions needed for vNodes to CConnman
* net: handle nodesignals in CConnman
* net: Pass CConnection to wallet rather than using the global
* net: Add rpc error for missing/disabled p2p functionality
* net: Pass CConnman around as needed
* gui: add NodeID to the peer table
* net: create generic functor accessors and move vNodes to CConnman
* net: move whitelist functions into CConnman
* net: move nLastNodeId to CConnman
* net: move nLocalHostNonce to CConnman
This behavior seems to have been quite racy and broken.
Move nLocalHostNonce into CNode, and check received nonces against all
non-fully-connected nodes. If there's a match, assume we've connected
to ourself.
* net: move messageHandlerCondition to CConnman
* net: move send/recv statistics to CConnman
* net: move SendBufferSize/ReceiveFloodSize to CConnman
* net: move nLocalServices/nRelevantServices to CConnman
These are in-turn passed to CNode at connection time. This allows us to offer
different services to different peers (or test the effects of doing so).
* net: move semOutbound and semMasternodeOutbound to CConnman
* net: SocketSendData returns written size
* net: move max/max-outbound to CConnman
* net: Pass best block known height into CConnman
CConnman then passes the current best height into CNode at creation time.
This way CConnman/CNode have no dependency on main for height, and the signals
only move in one direction.
This also helps to prevent identity leakage a tiny bit. Before this change, an
attacker could theoretically make 2 connections on different interfaces. They
would connect fully on one, and only establish the initial connection on the
other. Once they receive a new block, they would relay it to your first
connection, and immediately commence the version handshake on the second. Since
the new block height is reflected immediately, they could attempt to learn
whether the two connections were correlated.
This is, of course, incredibly unlikely to work due to the small timings
involved and receipt from other senders. But it doesn't hurt to lock-in
nBestHeight at the time of connection, rather than letting the remote choose
the time.
* net: pass CClientUIInterface into CConnman
* net: Drop StartNode/StopNode and use CConnman directly
* net: Introduce CConnection::Options to avoid passing so many params
* net: add nSendBufferMaxSize/nReceiveFloodSize to CConnection::Options
* net: move vNodesDisconnected into CConnman
* Made the ForEachNode* functions in src/net.cpp more pragmatic and self documenting
* Convert ForEachNode* functions to take a templated function argument rather than a std::function to eliminate std::function overhead
* net: move MAX_FEELER_CONNECTIONS into connman
2017-07-21 11:35:19 +02:00
g_connman - > ClearBanned ( ) ;
2015-05-19 10:07:46 +02:00
2015-06-12 18:31:47 +02:00
return NullUniValue ;
2015-05-19 10:07:46 +02:00
}
2017-09-11 15:38:14 +02:00
UniValue setnetworkactive ( const UniValue & params , bool fHelp )
{
if ( fHelp | | params . size ( ) ! = 1 ) {
throw runtime_error (
" setnetworkactive true|false \n "
" Disable/enable all p2p network activity. "
) ;
}
if ( ! g_connman ) {
throw JSONRPCError ( RPC_CLIENT_P2P_DISABLED , " Error: Peer-to-peer functionality missing or disabled " ) ;
}
g_connman - > SetNetworkActive ( params [ 0 ] . get_bool ( ) ) ;
return g_connman - > GetNetworkActive ( ) ;
}