From d2b4f143b958a33002286572533dcbe7e06aae5c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 29 Mar 2017 21:17:21 -0700 Subject: [PATCH] rpc: allow for omitting the port when handling the Connect RPC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- rpcserver.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index d70cf358..9b13aaa8 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -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 }