Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2p/enode: add quic ENR entry #30283

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions p2p/enode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,16 @@ func (n *Node) TCPEndpoint() (netip.AddrPort, bool) {
return netip.AddrPortFrom(n.ip, n.tcp), true
}

// QUICEndpoint returns the announced QUIC endpoint.
func (n *Node) QUICEndpoint() (netip.AddrPort, bool) {
var quic enr.QUIC
n.Load(&quic)
if !n.ip.IsValid() || n.ip.IsUnspecified() || quic == 0 {
guillaumemichel marked this conversation as resolved.
Show resolved Hide resolved
return netip.AddrPort{}, false
}
return netip.AddrPortFrom(n.ip, uint16(quic)), true
}

// Pubkey returns the secp256k1 public key of the node, if present.
func (n *Node) Pubkey() *ecdsa.PublicKey {
var key ecdsa.PublicKey
Expand Down
8 changes: 8 additions & 0 deletions p2p/enode/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ func TestNodeEndpoints(t *testing.T) {
return SignNull(&r, id)
}(),
},
{
name: "quic-only",
node: func() *Node {
var r enr.Record
r.Set(enr.QUIC(9000))
return SignNull(&r, id)
}(),
},
{
name: "ipv4-only-loopback",
node: func() *Node {
Expand Down
10 changes: 10 additions & 0 deletions p2p/enr/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ type UDP6 uint16

func (v UDP6) ENRKey() string { return "udp6" }

// QUIC is the "quic" key, which holds the QUIC port of the node.
type QUIC uint16

func (v QUIC) ENRKey() string { return "quic" }

// QUIC6 is the "quic6" key, which holds the IPv6-specific quic6 port of the node.
type QUIC6 uint16

func (v QUIC6) ENRKey() string { return "quic6" }

// ID is the "id" key, which holds the name of the identity scheme.
type ID string

Expand Down