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.
This commit is contained in:
Erik Grinaker
2021-01-04 15:05:43 +00:00
committed by GitHub
parent 9c47b572f7
commit 46964f62db
2 changed files with 3 additions and 2 deletions
+1 -1
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
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
}