I am wondering if there is a standard/de facto P2P library/implementation/spec used by Bitcoin Core and other implementations of Bitcoin?
2 Answers
Bitcoin has its own custom wire protocol using TCP. Peer discovery is by address rumoring, where connected nodes gossip about other potential available peers. When a node is new and has nobody to gossip with, they make a DNS lookup of specific hostnames which provide a number of known-good peers to make an outgoing connection to. If DNS seeds fail and none of the known peers are good, Bitcoin Core nodes fall back to a set of hardcoded peers as a last resort.
https://developer.bitcoin.org/devguide/p2p_network.html#peer-discovery
Bitcore, BitcoinJ and python-bitcoinlib all have basic implementations of the wire protocol in JavaScript, Java and Python respectively. It is fairly simple to interact with nodes but misbehavior (such as sending invalid data) will cause the remote peer to ban you.
I'd like to note that Bitcoin P2P libraries for C# are also available in NBitcoin and the Stratis fullnode.