cmd/devp2p: add combined discovery listener#35254
Conversation
|
Pushed 4b7f221 with a few fixes on top of the original commit:
|
Add `devp2p discovery listen`, which runs all supported discovery protocol versions (discv4 and discv5) on a single UDP socket, the way a real node does. For a single-protocol node, `discv4 listen` / `discv5 listen` remain. Also expose the --rpc debug API on `discv5 listen`, for parity with `discv4 listen`.
Serve the RPC handler directly instead of via http.DefaultServeMux, which also exposed /debug/pprof on the RPC port. lookupRandom now closes its iterator and stops when the client disconnects, instead of hanging forever on nodes with an empty table and leaking a context per call. Results go through enode.ReadNodes: deduplicated (may return fewer than n) and empty responses marshal as [] instead of null. The discv4 issues predate this branch; fixed here because the combined listener exposes them. Also export discover.SharedUDPConn and use it from p2p.Server and the combined listener instead of keeping two diverging copies.
4b7f221 to
9b57371
Compare
What
Adds
devp2p discovery listen, which runs a discovery-only node speaking all supported discovery protocol versions (discv4 and discv5) on a single UDP socket — the way a real node does viap2p.Server. Until nowdevp2pcould only run one protocol per process (discv4 listenordiscv5 listen), each on its own socket.It also exposes the
--rpcdebug API ondiscv5 listen, for parity withdiscv4 listen.Why
devp2p discv4 listen/discv5 listenis the documented replacement for the removedbootnodetool, but neither can run both protocols on one port. Other clients and the old bootnode tooling can serve discv4 and discv5 simultaneously on a single UDP port; this closes that gap.The two protocols are distinguishable on the wire, so they share one socket: v4 is the primary listener and forwards packets it can't parse to v5 over an
unhandledchannel, wrapped in asharedUDPConn— the same mechanismp2p.Serveralready uses.Usage
Single-protocol nodes remain available via
devp2p discv4 listen/devp2p discv5 listen. A future protocol version (e.g. v6) can be added as an opt-in flag without changing this surface.Notes
discoverydeliberately has no--v4/--v5flags: single-protocol use is already covered by thediscv4/discv5command families, so the combined command just means "all supported versions."self,lookupRandom) —UDPv5has no routing-table accessor equivalent toUDPv4.TableBuckets, so there is nodiscv5_buckets.unhandledchannel.Testing
Built and exercised manually:
discovery listenanswers bothdiscv4 pinganddiscv5 pingon one port.discovery listen --rpcservesdiscv4_self/discv4_lookupRandom/discv4_bucketsanddiscv5_self/discv5_lookupRandom;discv5_bucketscorrectly returns method-not-found.discv5 listen --rpcserves thediscv5_*API standalone.ListenAndServeto fail in combined mode exits cleanly instead of hanging (shutdown close-order).[::]) works.