Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Introduce PeerConnManager to manage peer connections #7283

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
28b13b9
lnd: add struct `peerConnManager` to hold info related to peer conn
yyforyongyu Oct 21, 2022
9a5d734
lnd: move `createBootstrapIgnorePeers` to peer conn manager
yyforyongyu Oct 21, 2022
cd5e3d2
lnd: move `findPeerByPubStr` to peer conn manager
yyforyongyu Oct 21, 2022
ae33318
lnd: move `peerNotifier` to peer conn manager
yyforyongyu Oct 21, 2022
4d6b101
lnd: use `sync` to start and stop peer conn manager
yyforyongyu Oct 22, 2022
dd98e6b
lnd: move `connectToPersistentPeer` to PeerConnManager
yyforyongyu Oct 22, 2022
16f5cbe
lnd: move `updatePersistentPeerAddrs` to PeerConnManager
yyforyongyu Oct 22, 2022
8c30222
lnd: move `removePeer` and `addPeer` to PeerConnManager
yyforyongyu Oct 22, 2022
6204373
peer+lnd: move `peerTerminationWatcher` to peer conn manager
yyforyongyu Oct 22, 2022
91e0fe2
lnd: move `prunePersistentPeerConnection` and `peerInitializer` to peer
yyforyongyu Oct 23, 2022
a8b98d3
lnd: move `DisconnectPeer` to peer conn manager
yyforyongyu Oct 23, 2022
d13f390
lnd: add method `createPartialPeerConfig` to config peer conn manager
yyforyongyu Nov 26, 2022
9684078
lnd: move `peerConnected` to peer conn manager
yyforyongyu Nov 26, 2022
908ad2a
lnd: move `OutboundPeerConnected` to peer conn manager
yyforyongyu Oct 23, 2022
287bb60
lnd: move `connectToPeer` to peer conn manager
yyforyongyu Oct 23, 2022
d5a0580
lnd: move `InboundPeerConnected` to peer conn manager
yyforyongyu Oct 23, 2022
b71e2ff
lnd: move `connectToPersistentPeer` to peer conn manager
yyforyongyu Oct 23, 2022
c2ea355
lnd: move `peerBootstrapper` to peer conn manager
yyforyongyu Oct 23, 2022
950d898
lnd: move `NotifyWhenOnline` and `NotifyWhenOffline` to peer conn man…
yyforyongyu Oct 29, 2022
8c2e92a
lnd: move `BroadcastMessage` to peer conn manager
yyforyongyu Nov 25, 2022
77c4f18
lnd: move `FindPeer` and `FindPeerByPubStr` to peer conn manager
yyforyongyu Nov 26, 2022
e09386c
lnd: stop accessing peer conn manager's private fields in server
yyforyongyu Nov 26, 2022
d79d772
server: move init of `connMgr` inside peer conn manager's Start
yyforyongyu Nov 26, 2022
dc162cc
lnd: move connMgr shutdown inside peer conn manager's Shutdown
yyforyongyu Nov 26, 2022
c8ff087
lnd: add dedicated logger for peer conn manager
yyforyongyu Nov 26, 2022
01cdbe7
lnd: add method `NewPeerConnManager` to init peer conn manager
yyforyongyu Nov 26, 2022
fcacc2b
lnd: export error `errPeerAlreadyConnected`
yyforyongyu Dec 6, 2022
b94b8df
peerconn: add new package `peerconn` and init logger
yyforyongyu Nov 26, 2022
ae0b0d6
lnd+peerconn: move `PeerConnManager` to peerconn
yyforyongyu Nov 26, 2022
3621158
peerconn: fix `errorlint`
yyforyongyu Dec 6, 2022
dcfd76b
peerconn: fix `forcetypeassert`
yyforyongyu Dec 6, 2022
90a0849
peerconn: fix gomod
yyforyongyu Dec 6, 2022
04200c1
peerconn: fix make lint issues
yyforyongyu Dec 6, 2022
a122f37
peerconn+server: fix linter `revive`
yyforyongyu Jan 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ linters-settings:
ignored-numbers:
- '0666'
- '0755'
- "2" # ignore two as we want to easily double things.

# List of function patterns to exclude from analysis.
# Values always ignored: `time.Date`
Expand Down
12 changes: 8 additions & 4 deletions chanrestore.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lnd

import (
"errors"
"fmt"
"math"
"net"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/peerconn"
"github.com/lightningnetwork/lnd/shachain"
)

Expand Down Expand Up @@ -304,7 +306,7 @@ func (s *server) ConnectPeer(nodePub *btcec.PublicKey, addrs []net.Addr) error {
// Before we connect to the remote peer, we'll remove any connections
// to ensure the new connection is created after this new link/channel
// is known.
if err := s.DisconnectPeer(nodePub); err != nil {
if err := s.pcm.DisconnectPeer(nodePub); err != nil {
ltndLog.Infof("Peer(%v) is already connected, proceeding "+
"with chan restore", nodePub.SerializeCompressed())
}
Expand All @@ -324,13 +326,15 @@ func (s *server) ConnectPeer(nodePub *btcec.PublicKey, addrs []net.Addr) error {
// Attempt to connect to the peer using this full address. If
// we're unable to connect to them, then we'll try the next
// address in place of it.
err := s.ConnectToPeer(netAddr, true, s.cfg.ConnectionTimeout)
err := s.pcm.ConnectToPeer(
netAddr, true, s.cfg.ConnectionTimeout,
)

// If we're already connected to this peer, then we don't
// consider this an error, so we'll exit here.
if _, ok := err.(*errPeerAlreadyConnected); ok {
targetErr := &peerconn.ErrPeerAlreadyConnected{}
if errors.As(err, &targetErr) {
return nil

} else if err != nil {
// Otherwise, something else happened, so we'll try the
// next address.
Expand Down
2 changes: 1 addition & 1 deletion peer/brontide.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ type Config struct {

// Switch is a pointer to the htlcswitch. It is used to setup, get, and
// tear-down ChannelLinks.
Switch messageSwitch
Switch MessageSwitch

// InterceptSwitch is a pointer to the InterceptableSwitch, a wrapper around
// the regular Switch. We only export it here to pass ForwardPackets to the
Expand Down
4 changes: 2 additions & 2 deletions peer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/lightningnetwork/lnd/lnwire"
)

// messageSwitch is an interface that abstracts managing the lifecycle of
// MessageSwitch is an interface that abstracts managing the lifecycle of
// abstract links. This is intended for peer package usage only.
type messageSwitch interface {
type MessageSwitch interface {
// BestHeight returns the best height known to the messageSwitch.
BestHeight() uint32

Expand Down
Loading
Loading