From 4babdec04ad833ffdd28226aba19422854cfeb4e Mon Sep 17 00:00:00 2001 From: William Dumont Date: Wed, 6 Sep 2023 13:54:08 +0200 Subject: [PATCH] change network filter from ip4 to ip --- node.go | 2 +- node_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/node.go b/node.go index 1fc922b..721b35d 100644 --- a/node.go +++ b/node.go @@ -146,7 +146,7 @@ func NewNode(cli *http.Client, cfg Config) (*Node, error) { return nil, fmt.Errorf("failed to read advertise address: %w", err) } - advertiseIP, err := net.ResolveIPAddr("ip4", advertiseAddr) + advertiseIP, err := net.ResolveIPAddr("ip", advertiseAddr) if err != nil { return nil, fmt.Errorf("failed to lookup advertise address %q: %w", advertiseAddr, err) } diff --git a/node_test.go b/node_test.go index 3de1c9b..212d1a4 100644 --- a/node_test.go +++ b/node_test.go @@ -369,3 +369,37 @@ func TestNode_Peers(t *testing.T) { require.ElementsMatch(t, expectPeers, a.Peers()) }) } + +func TestNewNodeIPv6(t *testing.T) { + t.Helper() + l := testlogger.New(t) + name := "node-a" + + if l == nil { + l = log.NewNopLogger() + } + + lis, err := net.Listen("tcp", "[::1]:0") + require.NoError(t, err) + + cfg := Config{ + Name: name, + AdvertiseAddr: lis.Addr().String(), + Log: log.With(l, "node", name), + } + + cli := &http.Client{ + Transport: &http2.Transport{ + AllowHTTP: true, + DialTLS: func(network, addr string, _ *tls.Config) (net.Conn, error) { + return net.Dial(network, addr) + }, + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + }, + } + + _, err = NewNode(cli, cfg) + require.NoError(t, err) +}