rpc: allow for omitting the port when handling the Connect RPC

This commit slightly modifies the handling of the Connect RPC to allow
users to omit the port when specifying the target node to connect to.
If the port isn’t specified, then the default p2p port will be used in
place.
This commit is contained in:
Olaoluwa Osuntokun
2017-03-29 21:17:21 -07:00
parent 72772ce4df
commit d2b4f143b9

View File

@@ -9,6 +9,7 @@ import (
"io"
"math"
"net"
"strconv"
"strings"
"time"
@@ -203,7 +204,17 @@ func (r *rpcServer) ConnectPeer(ctx context.Context,
return nil, err
}
host, err := net.ResolveTCPAddr("tcp", in.Addr.Host)
// If the address doesn't already have a port, we'll assume the current
// default port.
var addr string
_, _, err = net.SplitHostPort(in.Addr.Host)
if err != nil {
addr = net.JoinHostPort(in.Addr.Host, strconv.Itoa(defaultPeerPort))
} else {
addr = in.Addr.Host
}
host, err := net.ResolveTCPAddr("tcp", addr)
if err != nil {
return nil, err
}