When i start bitcoind with default set.I found the connectioncount is always 10(the result of command "getconnectioncount").I have two questions below: 1、Where is the source code about this default connection count? 2、Can i use some command to set this number when starting bitcoind? Thanks!
1 Answer
Where is the source code about this default connection count?
static const int MAX_OUTBOUND_FULL_RELAY_CONNECTIONS = 8;
/** Maximum number of addnode outgoing nodes */
static const int MAX_ADDNODE_CONNECTIONS = 8;
/** Maximum number of block-relay-only outgoing connections */
static const int MAX_BLOCK_RELAY_ONLY_CONNECTIONS = 2;
/** The maximum number of peer connections to maintain. */
static const unsigned int DEFAULT_MAX_PEER_CONNECTIONS = 125;
https://github.com/bitcoin/bitcoin/blob/master/src/net.h#L66
https://github.com/bitcoin/bitcoin/blob/master/src/net.h#L76
There can be a maximum of 16 outgoing full relay connections, including 8 automated and 8 manual. Additionally, there are two block relay connections. Therefore, a node that starts up for the first time has 10 by default after a short while.
Can i use some command to set this number when starting bitcoind?
You can use -maxconnections
for maintaining at most N connections to peers however this includes outbound and inbound. It is 125 by default.
Some modifications to the source code will be required if you want to make outbound connections count configurable: Increase maximum number of outgoing connections for full node
You can also increase connection count by incoming connections. This doc includes instructions and settings to setup node and listen for incoming connections using i2p: https://github.com/bitcoin/bitcoin/blob/master/doc/i2p.md