lnd+rpcserver: allow customized timeout in ConnectPeer

This commit is contained in:
yyforyongyu
2020-08-25 12:54:31 +08:00
parent ef38b12fda
commit 469aba9282
8 changed files with 754 additions and 668 deletions

View File

@ -1512,8 +1512,25 @@ func (r *rpcServer) ConnectPeer(ctx context.Context,
rpcsLog.Debugf("[connectpeer] requested connection to %x@%s",
peerAddr.IdentityKey.SerializeCompressed(), peerAddr.Address)
if err := r.server.ConnectToPeer(peerAddr, in.Perm); err != nil {
rpcsLog.Errorf("[connectpeer]: error connecting to peer: %v", err)
// By default, we will use the global connection timeout value.
timeout := r.cfg.ConnectionTimeout
// Check if the connection timeout is set. If set, we will use it in our
// request.
if in.Timeout != 0 {
timeout = time.Duration(in.Timeout) * time.Second
rpcsLog.Debugf(
"[connectpeer] connection timeout is set to %v",
timeout,
)
}
if err := r.server.ConnectToPeer(peerAddr,
in.Perm, timeout); err != nil {
rpcsLog.Errorf(
"[connectpeer]: error connecting to peer: %v", err,
)
return nil, err
}