Only a partial answer for the first couple of sub-questions...
How many nodes do we connect to?
The maximum number is set to 25 by default, but can be configured using the --maxpeers
flag on the command line. This limit is flexible when taking into account "trusted" nodes. (See below.)
The finer detail is that we can also set the combined total of both pending incoming and outgoing connections using the --maxpendpeers
flag. This is the number of nodes simultaneously performing connection handshakes, which may or may not be successful, and which depends on whether we can verify their identity. This is set to 66 by default (50 and 16 respectively).
What is the criteria for selecting which nodes to connect to?
There are three different categories of nodes that we connect to, though I'm unsure of the criteria they must meet (other than they must complete the handshake process):
Bootstrap nodes
// Bootstrap nodes are used to establish connectivity
// with the rest of the network.
BootstrapNodes []*discover.Node
Static nodes:
// Static nodes are used as pre-configured connections which are always
// maintained and re-connected on disconnects.
StaticNodes []*discover.Node
Trusted nodes:
// Trusted nodes are used as pre-configured connections which are always
// allowed to connect, even above the peer limit.
TrustedNodes []*discover.Node
admin.addPeer()
allows you to add a new entry to the array of static nodes.