lnd+rpcserver: allow customized timeout in ConnectPeer

This commit is contained in:
yyforyongyu committed 2020-09-16 11:50:04 +08:00
1 parent ef38b12fda
commit 469aba9282
8 files changed
+754 -668

No files matched your search

+19 -2
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
}