autopilot: check if already connected before returning error

This commit fixes a small bug that could cause us to disconnect an
already connected peer if no addresses where provided to the ConnectPeer
method. Now we instead first check if we are already connected, and
return early.
This commit is contained in:
Johan T. Halseth 2018-08-17 09:26:54 +02:00
parent 643618b4f6
commit 2a3b52535e
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -109,12 +109,6 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.Agent, error)
Graph: autopilot.ChannelGraphFromDatabase(svr.chanDB.ChannelGraph()),
MaxPendingOpens: 10,
ConnectToPeer: func(target *btcec.PublicKey, addrs []net.Addr) (bool, error) {
// We can't establish a channel if no addresses were
// provided for the peer.
if len(addrs) == 0 {
return false, errors.New("no addresses specified")
}
// First, we'll check if we're already connected to the
// target peer. If we are, we can exit early. Otherwise,
// we'll need to establish a connection.
@ -122,6 +116,12 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.Agent, error)
return true, nil
}
// We can't establish a channel if no addresses were
// provided for the peer.
if len(addrs) == 0 {
return false, errors.New("no addresses specified")
}
atplLog.Tracef("Attempting to connect to %x",
target.SerializeCompressed())