How does a stellar-core node discover its peers?
I mean both on startup and on the go.
Stellar Stack Exchange is a question and answer site for developers and users of Stellar and the Stellar Distributed Exchange. It only takes a minute to sign up.Sign up to join this community
After startup, your node should have established connection with your indicated peers. On the go, there's not much to do with after startup. The nodes just exchange data and run consensus algorithm.
In stellar-core.config, there are several fields related to peers discovery (refer to example config here).
NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015"
No one can join a network without knowing the "NETWORK_PASSPHRASE". This is like the name of the organization/network that you would like to join.
If you want to set up a private network, you will keep your NETWORK_PASSPHRASE as a secret. Without knowing this secret, random guys cannot discover your private network.
Suppose you are not in the network yet. You need some existing, running peers to pull you into the organization/network. Put an IP at "KNOWN_PEERS".
The IP/web address of the intended peer is like the location of your friend, which allows you to find him.
If you are already in the network and wants to pull somebody else in, let them add your IP under KNOWN_PEERS.
An IP address has many ports, just like a park can have many entrance gates. So, you also need to know which gate your friend is at.
11625 is the default value for peer port. If your peer changed its peer port, you will need to suggest a value for this field.
Without matching both the IP and peer port number, a peer cannot be discovered.
The above are the most basic ones for startup. For simplicity, complicated settings were not mentioned.