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:
parent
72772ce4df
commit
d2b4f143b9
13
rpcserver.go
13
rpcserver.go
@ -9,6 +9,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -203,7 +204,17 @@ func (r *rpcServer) ConnectPeer(ctx context.Context,
|
|||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user