From: Matt Joiner Date: Thu, 27 Jan 2022 04:11:01 +0000 (+1100) Subject: Fix v4 in v6 IPs from being banned as IPv4 X-Git-Tag: v1.42.0~8^2^2~9 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=f1e250672fe274cef9102e8ef1e5a4e939bac506;p=btrtrc.git Fix v4 in v6 IPs from being banned as IPv4 --- 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) {