Browse Source

p2p: fix IPv6 address handling in new transport API (#5853)

The old code naïvely concatenated IP and port, which doesn't work for IPv6 addresses where `:` can be part of the IP as well.
pull/5857/head
Erik Grinaker 3 years ago
committed by GitHub
parent
commit
46964f62db
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions
  1. +1
    -1
      p2p/transport.go
  2. +2
    -1
      p2p/transport_mconn.go

+ 1
- 1
p2p/transport.go View File

@ -69,7 +69,7 @@ func (e Endpoint) String() string {
if len(e.IP) > 0 {
u.Host = e.IP.String()
if e.Port > 0 {
u.Host += fmt.Sprintf(":%v", e.Port)
u.Host = net.JoinHostPort(u.Host, fmt.Sprintf("%v", e.Port))
}
} else if e.Path != "" {
u.Opaque = e.Path


+ 2
- 1
p2p/transport_mconn.go View File

@ -253,7 +253,8 @@ func (m *MConnTransport) Dial(ctx context.Context, endpoint Endpoint) (Connectio
defer cancel()
dialer := net.Dialer{}
tcpConn, err := dialer.DialContext(ctx, "tcp", fmt.Sprintf("%v:%v", endpoint.IP, endpoint.Port))
tcpConn, err := dialer.DialContext(ctx, "tcp",
net.JoinHostPort(endpoint.IP.String(), fmt.Sprintf("%v", endpoint.Port)))
if err != nil {
return nil, err
}


Loading…
Cancel
Save