I am wondering how long on average would it take for a node to discover all other nodes in Bitcoin network and connect to them? Are there technical obstacles to this?
how long on average would it take for a node to discover all other nodes
No normal node ever does this.
A normal node only connects directly with a very small number of other nodes (e.g. max 8 outbound, max 125 inbound) and relies on those other nodes to pass on information to the small number of nodes they are in contact with. This way information diffuses across the entire network.
Since nodes are continually appearing and disappearing any attempt to contact all nodes would be essentially endless or both incomplete and incorrect (it would include nodes that have been removed since the start of the discovery process)
discover all other nodes in Bitcoin network and connect to them
Discovery and connecting are a bit different. To discover a node that node has to have advertised itself using an
addr message. I believe nodes that don't accept incoming connections (have no listening port) don't do this, so they can not be discovered unless your node listens for incoming connections and they initiate the connection.
Connecting to known nodes is simple and is what statistic tools such as bitnodes do, an I'm assuming this is what you have in mind otherwise as @RedGrittyBrick there is no point.
It could start from initial peer discovery using DNS seeders then it is a matter of making a TCP connection to each node's IP address through the port they listen on (almost always the default 8333 and 18333 for mainnet and testnet) and performing the handshake (
verack) which doesn't take more than a second. A
getaddr message could be sent to each node asking for a list of nodes they know of to construct a list and connect to each of them.
I don't think going through all reachable nodes (about 10k) would take longer than a minute.