From f1e250672fe274cef9102e8ef1e5a4e939bac506 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 27 Jan 2022 15:11:01 +1100 Subject: [PATCH] Fix v4 in v6 IPs from being banned as IPv4 --- client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 29080c57..fae9cf27 100644 --- a/client.go +++ b/client.go @@ -1494,7 +1494,13 @@ func (cl *Client) AddDhtNodes(nodes []string) { } func (cl *Client) banPeerIP(ip net.IP) { - generics.MakeMapIfNilAndSet(&cl.badPeerIPs, netip.MustParseAddr(ip.String()), struct{}{}) + // We can't take this from string, because it will lose netip's v4on6. net.ParseIP parses v4 + // addresses directly to v4on6, which doesn't compare equal with v4. + ipAddr, ok := netip.AddrFromSlice(ip) + if !ok { + panic(ip) + } + generics.MakeMapIfNilAndSet(&cl.badPeerIPs, ipAddr, struct{}{}) } func (cl *Client) newConnection(nc net.Conn, outgoing bool, remoteAddr PeerRemoteAddr, network, connString string) (c *PeerConn) { -- 2.48.1