Skip to content

Commit 3621158

Browse files
committed
peerconn: fix errorlint
1 parent ae0b0d6 commit 3621158

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

chanrestore.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package lnd
22

33
import (
4+
"errors"
45
"fmt"
56
"math"
67
"net"
@@ -331,9 +332,9 @@ func (s *server) ConnectPeer(nodePub *btcec.PublicKey, addrs []net.Addr) error {
331332

332333
// If we're already connected to this peer, then we don't
333334
// consider this an error, so we'll exit here.
334-
if _, ok := err.(*peerconn.ErrPeerAlreadyConnected); ok {
335+
targetErr := &peerconn.ErrPeerAlreadyConnected{}
336+
if errors.As(err, &targetErr) {
335337
return nil
336-
337338
} else if err != nil {
338339
// Otherwise, something else happened, so we'll try the
339340
// next address.

peerconn/conn_manager.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ func (p *PeerConnManager) EstablishPersistentConnections() error {
701701
// the reconnection port to the default peer port.
702702
linkNodes, err := p.Config.PartialPeerConfig.ChannelDB.LinkNodeDB().
703703
FetchAllLinkNodes()
704-
if err != nil && err != channeldb.ErrLinkNodesNotFound {
704+
if err != nil && !errors.Is(err, channeldb.ErrLinkNodesNotFound) {
705705
return err
706706
}
707707
for _, node := range linkNodes {
@@ -802,7 +802,7 @@ func (p *PeerConnManager) EstablishPersistentConnections() error {
802802
nodeAddrsMap[pubStr] = n
803803
return nil
804804
})
805-
if err != nil && err != channeldb.ErrGraphNoEdgesFound {
805+
if err != nil && !errors.Is(err, channeldb.ErrGraphNoEdgesFound) {
806806
return err
807807
}
808808

@@ -1182,14 +1182,14 @@ func (p *PeerConnManager) InboundPeerConnected(conn net.Conn) {
11821182
// default case as we expect these to be the only error values returned
11831183
// from findPeerByPubStr.
11841184
connectedPeer, err := p.findPeerByPubStr(pubStr)
1185-
switch err {
1186-
case ErrPeerNotConnected:
1185+
switch {
1186+
case errors.Is(err, ErrPeerNotConnected):
11871187
// We were unable to locate an existing connection with the
11881188
// target peer, proceed to connect.
11891189
p.cancelConnReqs(pubStr, nil)
11901190
p.peerConnected(conn, nil, true)
11911191

1192-
case nil:
1192+
case err == nil:
11931193
// We already have a connection with the incoming peer. If the
11941194
// connection we've already established should be kept and is
11951195
// not of the same type of the new connection (inbound), then
@@ -1296,13 +1296,13 @@ func (p *PeerConnManager) OutboundPeerConnected(connReq *connmgr.ConnReq,
12961296
// as we expect these to be the only error values returned from
12971297
// findPeerByPubStr.
12981298
connectedPeer, err := p.findPeerByPubStr(pubStr)
1299-
switch err {
1300-
case ErrPeerNotConnected:
1299+
switch {
1300+
case errors.Is(err, ErrPeerNotConnected):
13011301
// We were unable to locate an existing connection with the
13021302
// target peer, proceed to connect.
13031303
p.peerConnected(conn, connReq, false)
13041304

1305-
case nil:
1305+
case err == nil:
13061306
// We already have a connection with the incoming peer. If the
13071307
// connection we've already established should be kept and is
13081308
// not of the same type of the new connection (outbound), then
@@ -1540,7 +1540,7 @@ func (p *PeerConnManager) peerInitializer(peer *peer.Brontide) {
15401540
// Start the peer! If an error occurs, we Disconnect the peer, which
15411541
// will unblock the peerTerminationWatcher.
15421542
if err := peer.Start(); err != nil {
1543-
peer.Disconnect(fmt.Errorf("unable to start peer: %v", err))
1543+
peer.Disconnect(fmt.Errorf("unable to start peer: %w", err))
15441544
return
15451545
}
15461546

@@ -1676,7 +1676,7 @@ func (p *PeerConnManager) peerTerminationWatcher(peer *peer.Brontide,
16761676
addrs = advertisedAddrs
16771677

16781678
// The peer doesn't have an advertised address.
1679-
case err == errNoAdvertisedAddr:
1679+
case errors.Is(err, errNoAdvertisedAddr):
16801680
// If it is an outbound peer then we fall back to the existing
16811681
// peer address.
16821682
if !peer.Inbound() {
@@ -2031,7 +2031,7 @@ func (p *PeerConnManager) DisconnectPeer(pubKey *btcec.PublicKey) error {
20312031
// exit in an error as we can't disconnect from a peer that we're not
20322032
// currently connected to.
20332033
peer, err := p.findPeerByPubStr(pubStr)
2034-
if err == ErrPeerNotConnected {
2034+
if errors.Is(err, ErrPeerNotConnected) {
20352035
return fmt.Errorf("peer %x is not connected", pubBytes)
20362036
}
20372037

rpcserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8053,7 +8053,7 @@ func (r *rpcServer) SendCustomMessage(ctx context.Context, req *lnrpc.SendCustom
80538053
peer, lnwire.MessageType(req.Type), req.Data,
80548054
)
80558055
switch {
8056-
case err == peerconn.ErrPeerNotConnected:
8056+
case errors.Is(err, peerconn.ErrPeerNotConnected):
80578057
return nil, status.Error(codes.NotFound, err.Error())
80588058
case err != nil:
80598059
return nil, err

0 commit comments

Comments
 (0)