]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix v4 in v6 IPs from being banned as IPv4
authorMatt Joiner <anacrolix@gmail.com>
Thu, 27 Jan 2022 04:11:01 +0000 (15:11 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 27 Jan 2022 04:11:01 +0000 (15:11 +1100)
client.go

index 29080c5756948effbe9cbd157eb53c63b9ba36a8..fae9cf278d5d6b296e281720517be925ab156d0d 100644 (file)
--- 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) {