Skip to content

Commit a122f37

Browse files
committed
peerconn+server: fix linter revive
This commit renames `PeerConnManager` and `PeerConnManagerConfig` to `Manager` and `ManagerConfig` by the request of the linter `revive`.
1 parent 04200c1 commit a122f37

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

peerconn/conn_manager.go

+38-38
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (e *ErrPeerAlreadyConnected) Error() string {
117117
}
118118

119119
// PeerConnManagerConfig holds config info for the peer conn manager.
120-
type PeerConnManagerConfig struct {
120+
type ManagerConfig struct {
121121
// PartialPeerConfig holds a peer config that's not yet completed and
122122
// will be finished by the peer conn manager when making a new peer.
123123
PartialPeerConfig peer.Config
@@ -168,8 +168,8 @@ type PeerConnManagerConfig struct {
168168
}
169169

170170
// PeerConnManager is responsible for managing peer connections.
171-
type PeerConnManager struct {
172-
Config *PeerConnManagerConfig
171+
type Manager struct {
172+
Config *ManagerConfig
173173

174174
// IdentityECDH is an ECDH capable wrapper for the private key used
175175
// to authenticate any incoming connections.
@@ -242,7 +242,7 @@ type PeerConnManager struct {
242242
}
243243

244244
// Start will start the peer conn manager.
245-
func (p *PeerConnManager) Start() error {
245+
func (p *Manager) Start() error {
246246
// Create the connection manager which will be responsible for
247247
// maintaining persistent outbound connections and also accepting new
248248
// incoming connections
@@ -280,7 +280,7 @@ func (p *PeerConnManager) Start() error {
280280
}
281281

282282
// Stop will stop the peer conn manager.
283-
func (p *PeerConnManager) Stop() error {
283+
func (p *Manager) Stop() error {
284284
// Before we shutdown the manager, disconnect from each active peers to
285285
// ensure that peerTerminationWatchers signal completion to each peer.
286286
for _, peer := range p.Peers() {
@@ -316,15 +316,15 @@ func (p *PeerConnManager) Stop() error {
316316

317317
// Stopped returns true if the peer conn manager has been instructed to
318318
// shutdown.
319-
func (p *PeerConnManager) Stopped() bool {
319+
func (p *Manager) Stopped() bool {
320320
return atomic.LoadInt32(&p.stopping) != 0
321321
}
322322

323323
// NewPeerConnManager creates and returns a new peer conn manager.
324324
func NewPeerConnManager(nodeKey keychain.SingleKeyECDH,
325-
tc *tor.Controller) *PeerConnManager {
325+
tc *tor.Controller) *Manager {
326326

327-
return &PeerConnManager{
327+
return &Manager{
328328
IdentityECDH: nodeKey,
329329

330330
// Assemble a peer notifier which will provide clients with
@@ -357,7 +357,7 @@ func NewPeerConnManager(nodeKey keychain.SingleKeyECDH,
357357
// advertised addresses for any NodeAnnouncements from our persisted peers.
358358
//
359359
//nolint:lll
360-
func (p *PeerConnManager) UpdatePersistentPeerAddrs() error {
360+
func (p *Manager) UpdatePersistentPeerAddrs() error {
361361
graphSub, err := p.Config.SubscribeTopology()
362362
if err != nil {
363363
return err
@@ -445,7 +445,7 @@ type IgnoredPeers map[autopilot.NodeID]struct{}
445445
// to itself.
446446
// - the peers that already have connections with, as in s.peersByPub.
447447
// - the peers that we are attempting to connect, as in s.persistentPeers.
448-
func (p *PeerConnManager) CreateBootstrapIgnorePeers() IgnoredPeers {
448+
func (p *Manager) CreateBootstrapIgnorePeers() IgnoredPeers {
449449
p.mu.RLock()
450450
defer p.mu.RUnlock()
451451

@@ -477,7 +477,7 @@ func (p *PeerConnManager) CreateBootstrapIgnorePeers() IgnoredPeers {
477477
// invariant, we ensure that our node is connected to a diverse set of peers
478478
// and that nodes newly joining the network receive an up to date network view
479479
// as soon as possible.
480-
func (p *PeerConnManager) PeerBootstrapper(numTargetPeers uint32,
480+
func (p *Manager) PeerBootstrapper(numTargetPeers uint32,
481481
bootstrappers []discovery.NetworkPeerBootstrapper) {
482482

483483
defer p.wg.Done()
@@ -611,7 +611,7 @@ func (p *PeerConnManager) PeerBootstrapper(numTargetPeers uint32,
611611
// initialPeerBootstrap attempts to continuously connect to peers on startup
612612
// until the target number of peers has been reached. This ensures that nodes
613613
// receive an up to date network view as soon as possible.
614-
func (p *PeerConnManager) initialPeerBootstrap(
614+
func (p *Manager) initialPeerBootstrap(
615615
ignore map[autopilot.NodeID]struct{}, numTargetPeers uint32,
616616
bootstrappers []discovery.NetworkPeerBootstrapper) {
617617

@@ -728,7 +728,7 @@ type nodeAddresses struct {
728728
// to all our direct channel collaborators. In order to promote liveness of our
729729
// active channels, we instruct the connection manager to attempt to establish
730730
// and maintain persistent connections to all our direct channel counterparties.
731-
func (p *PeerConnManager) EstablishPersistentConnections() error {
731+
func (p *Manager) EstablishPersistentConnections() error {
732732
// nodeAddrsMap stores the combination of node public keys and addresses
733733
// that we'll attempt to reconnect to. PubKey strings are used as keys
734734
// since other PubKey forms can't be compared.
@@ -907,7 +907,7 @@ func (p *PeerConnManager) EstablishPersistentConnections() error {
907907
// sampling a value for the delay between 0s and the maxInitReconnectDelay.
908908
//
909909
// NOTE: This method MUST be run as a goroutine.
910-
func (p *PeerConnManager) delayInitialReconnect(pubStr string) {
910+
func (p *Manager) delayInitialReconnect(pubStr string) {
911911
delay := time.Duration(prand.Intn(maxInitReconnectDelay)) * time.Second
912912
select {
913913
case <-time.After(delay):
@@ -919,7 +919,7 @@ func (p *PeerConnManager) delayInitialReconnect(pubStr string) {
919919
// PrunePersistentPeerConnection removes all internal state related to
920920
// persistent connections to a peer within the server. This is used to avoid
921921
// persistent connection retries to peers we do not have any open channels with.
922-
func (p *PeerConnManager) PrunePersistentPeerConnection(
922+
func (p *Manager) PrunePersistentPeerConnection(
923923
compressedPubKey [33]byte) {
924924

925925
pubKeyStr := string(compressedPubKey[:])
@@ -946,7 +946,7 @@ func (p *PeerConnManager) PrunePersistentPeerConnection(
946946
// the target peers.
947947
//
948948
// NOTE: This function is safe for concurrent access.
949-
func (p *PeerConnManager) BroadcastMessage(skips map[route.Vertex]struct{},
949+
func (p *Manager) BroadcastMessage(skips map[route.Vertex]struct{},
950950
msgs ...lnwire.Message) error {
951951

952952
connLog.Debugf("Broadcasting %v messages", len(msgs))
@@ -998,7 +998,7 @@ func (p *PeerConnManager) BroadcastMessage(skips map[route.Vertex]struct{},
998998
// particular peer comes online. The peer itself is sent across the peerChan.
999999
//
10001000
// NOTE: This function is safe for concurrent access.
1001-
func (p *PeerConnManager) NotifyWhenOnline(peerKey [33]byte,
1001+
func (p *Manager) NotifyWhenOnline(peerKey [33]byte,
10021002
peerChan chan<- lnpeer.Peer) {
10031003

10041004
p.mu.Lock()
@@ -1051,7 +1051,7 @@ func (p *PeerConnManager) NotifyWhenOnline(peerKey [33]byte,
10511051
// NotifyWhenOffline delivers a notification to the caller of when the peer with
10521052
// the given public key has been disconnected. The notification is signaled by
10531053
// closing the channel returned.
1054-
func (p *PeerConnManager) NotifyWhenOffline(
1054+
func (p *Manager) NotifyWhenOffline(
10551055
peerPubKey [33]byte) <-chan struct{} {
10561056

10571057
p.mu.Lock()
@@ -1083,7 +1083,7 @@ func (p *PeerConnManager) NotifyWhenOffline(
10831083
// daemon's local representation of the remote peer.
10841084
//
10851085
// NOTE: This function is safe for concurrent access.
1086-
func (p *PeerConnManager) FindPeer(
1086+
func (p *Manager) FindPeer(
10871087
peerKey *btcec.PublicKey) (*peer.Brontide, error) {
10881088

10891089
p.mu.RLock()
@@ -1099,7 +1099,7 @@ func (p *PeerConnManager) FindPeer(
10991099
// public key.
11001100
//
11011101
// NOTE: This function is safe for concurrent access.
1102-
func (p *PeerConnManager) FindPeerByPubStr(
1102+
func (p *Manager) FindPeerByPubStr(
11031103
pubStr string) (*peer.Brontide, error) {
11041104

11051105
p.mu.RLock()
@@ -1110,7 +1110,7 @@ func (p *PeerConnManager) FindPeerByPubStr(
11101110

11111111
// findPeerByPubStr is an internal method that retrieves the specified peer from
11121112
// the server's internal state using.
1113-
func (p *PeerConnManager) findPeerByPubStr(
1113+
func (p *Manager) findPeerByPubStr(
11141114
pubStr string) (*peer.Brontide, error) {
11151115

11161116
peer, ok := p.peersByPub[pubStr]
@@ -1124,7 +1124,7 @@ func (p *PeerConnManager) findPeerByPubStr(
11241124
// nextPeerBackoff computes the next backoff duration for a peer's pubkey using
11251125
// exponential backoff. If no previous backoff was known, the default is
11261126
// returned.
1127-
func (p *PeerConnManager) nextPeerBackoff(pubStr string,
1127+
func (p *Manager) nextPeerBackoff(pubStr string,
11281128
startTime time.Time) time.Duration {
11291129

11301130
// Now, determine the appropriate backoff to use for the retry.
@@ -1187,7 +1187,7 @@ func shouldDropLocalConnection(local, remote *btcec.PublicKey) bool {
11871187
// connection.
11881188
//
11891189
// NOTE: This function is safe for concurrent access.
1190-
func (p *PeerConnManager) InboundPeerConnected(conn net.Conn) {
1190+
func (p *Manager) InboundPeerConnected(conn net.Conn) {
11911191
// Exit early if we have already been instructed to shutdown, this
11921192
// prevents any delayed callbacks from accidentally registering peers.
11931193
if p.Stopped() {
@@ -1284,7 +1284,7 @@ func (p *PeerConnManager) InboundPeerConnected(conn net.Conn) {
12841284
// OutboundPeerConnected initializes a new peer in response to a new outbound
12851285
// connection.
12861286
// NOTE: This function is safe for concurrent access.
1287-
func (p *PeerConnManager) OutboundPeerConnected(connReq *connmgr.ConnReq,
1287+
func (p *Manager) OutboundPeerConnected(connReq *connmgr.ConnReq,
12881288
conn net.Conn) {
12891289

12901290
// Exit early if we have already been instructed to shutdown, this
@@ -1418,7 +1418,7 @@ const UnassignedConnID uint64 = 0
14181418
// optionally specify a connection ID to ignore, which prevents us from
14191419
// canceling a successful request. All persistent connreqs for the provided
14201420
// pubkey are discarded after the operationjw.
1421-
func (p *PeerConnManager) cancelConnReqs(pubStr string, skip *uint64) {
1421+
func (p *Manager) cancelConnReqs(pubStr string, skip *uint64) {
14221422
// First, cancel any lingering persistent retry attempts, which will
14231423
// prevent retries for any with backoffs that are still maturing.
14241424
if cancelChan, ok := p.persistentRetryCancels[pubStr]; ok {
@@ -1461,7 +1461,7 @@ func (p *PeerConnManager) cancelConnReqs(pubStr string, skip *uint64) {
14611461
// peer by adding it to the server's global list of all active peers, and
14621462
// starting all the goroutines the peer needs to function properly. The inbound
14631463
// boolean should be true if the peer initiated the connection to us.
1464-
func (p *PeerConnManager) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
1464+
func (p *Manager) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
14651465
inbound bool) {
14661466

14671467
brontideConn, ok := conn.(*brontide.Conn)
@@ -1544,7 +1544,7 @@ func (p *PeerConnManager) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
15441544

15451545
// addPeer adds the passed peer to the server's global state of all active
15461546
// peers.
1547-
func (p *PeerConnManager) addPeer(peer *peer.Brontide) {
1547+
func (p *Manager) addPeer(peer *peer.Brontide) {
15481548
if peer == nil {
15491549
return
15501550
}
@@ -1588,7 +1588,7 @@ func (p *PeerConnManager) addPeer(peer *peer.Brontide) {
15881588
// be signaled of the new peer once the method returns.
15891589
//
15901590
// NOTE: This MUST be launched as a goroutine.
1591-
func (p *PeerConnManager) peerInitializer(peer *peer.Brontide) {
1591+
func (p *Manager) peerInitializer(peer *peer.Brontide) {
15921592
defer p.wg.Done()
15931593

15941594
// Avoid initializing peers while the server is exiting.
@@ -1649,7 +1649,7 @@ func (p *PeerConnManager) peerInitializer(peer *peer.Brontide) {
16491649
// successfully, otherwise the peer should be disconnected instead.
16501650
//
16511651
// NOTE: This MUST be launched as a goroutine.
1652-
func (p *PeerConnManager) peerTerminationWatcher(peer *peer.Brontide,
1652+
func (p *Manager) peerTerminationWatcher(peer *peer.Brontide,
16531653
ready chan struct{}) {
16541654

16551655
defer p.wg.Done()
@@ -1847,7 +1847,7 @@ func (p *PeerConnManager) peerTerminationWatcher(peer *peer.Brontide,
18471847
// currently none for a given address and it removes old connection requests
18481848
// if the associated address is no longer in the latest address list for the
18491849
// peer.
1850-
func (p *PeerConnManager) connectToPersistentPeer(pubKeyStr string) {
1850+
func (p *Manager) connectToPersistentPeer(pubKeyStr string) {
18511851
p.mu.Lock()
18521852
defer p.mu.Unlock()
18531853

@@ -1947,7 +1947,7 @@ func (p *PeerConnManager) connectToPersistentPeer(pubKeyStr string) {
19471947

19481948
// removePeer removes the passed peer from the server's state of all active
19491949
// peers.
1950-
func (p *PeerConnManager) removePeer(peer *peer.Brontide) {
1950+
func (p *Manager) removePeer(peer *peer.Brontide) {
19511951
if peer == nil {
19521952
return
19531953
}
@@ -1999,7 +1999,7 @@ func (p *PeerConnManager) removePeer(peer *peer.Brontide) {
19991999
// connection is established, or the initial handshake process fails.
20002000
//
20012001
// NOTE: This function is safe for concurrent access.
2002-
func (p *PeerConnManager) ConnectToPeer(addr *lnwire.NetAddress,
2002+
func (p *Manager) ConnectToPeer(addr *lnwire.NetAddress,
20032003
perm bool, timeout time.Duration) error {
20042004

20052005
targetPub := string(addr.IdentityKey.SerializeCompressed())
@@ -2075,7 +2075,7 @@ func (p *PeerConnManager) ConnectToPeer(addr *lnwire.NetAddress,
20752075
// connectToPeer establishes a connection to a remote peer. errChan is used to
20762076
// notify the caller if the connection attempt has failed. Otherwise, it will be
20772077
// closed.
2078-
func (p *PeerConnManager) connectToPeer(addr *lnwire.NetAddress,
2078+
func (p *Manager) connectToPeer(addr *lnwire.NetAddress,
20792079
errChan chan<- error, timeout time.Duration) {
20802080

20812081
conn, err := brontide.Dial(
@@ -2103,7 +2103,7 @@ func (p *PeerConnManager) connectToPeer(addr *lnwire.NetAddress,
21032103
// identified by public key.
21042104
//
21052105
// NOTE: This function is safe for concurrent access.
2106-
func (p *PeerConnManager) DisconnectPeer(pubKey *btcec.PublicKey) error {
2106+
func (p *Manager) DisconnectPeer(pubKey *btcec.PublicKey) error {
21072107
pubBytes := pubKey.SerializeCompressed()
21082108
pubStr := string(pubBytes)
21092109

@@ -2137,7 +2137,7 @@ func (p *PeerConnManager) DisconnectPeer(pubKey *btcec.PublicKey) error {
21372137

21382138
// SendCustomMessage sends a custom message to the peer with the specified
21392139
// pubkey.
2140-
func (p *PeerConnManager) SendCustomMessage(peerPub [33]byte,
2140+
func (p *Manager) SendCustomMessage(peerPub [33]byte,
21412141
msgType lnwire.MessageType, data []byte) error {
21422142

21432143
peer, err := p.FindPeerByPubStr(string(peerPub[:]))
@@ -2165,7 +2165,7 @@ func (p *PeerConnManager) SendCustomMessage(peerPub [33]byte,
21652165
}
21662166

21672167
// AddPersistentPeer adds a peer's public key to the persistentPeers map.
2168-
func (p *PeerConnManager) AddPersistentPeer(peerKey *btcec.PublicKey) {
2168+
func (p *Manager) AddPersistentPeer(peerKey *btcec.PublicKey) {
21692169
p.mu.Lock()
21702170
defer p.mu.Unlock()
21712171

@@ -2178,7 +2178,7 @@ func (p *PeerConnManager) AddPersistentPeer(peerKey *btcec.PublicKey) {
21782178
// Peers returns a slice of all active peers.
21792179
//
21802180
// NOTE: This function is safe for concurrent access.
2181-
func (p *PeerConnManager) Peers() []*peer.Brontide {
2181+
func (p *Manager) Peers() []*peer.Brontide {
21822182
p.mu.RLock()
21832183
defer p.mu.RUnlock()
21842184

@@ -2224,7 +2224,7 @@ var errNoAdvertisedAddr = errors.New("no advertised address found")
22242224

22252225
// fetchNodeAdvertisedAddrs attempts to fetch the advertised addresses of a
22262226
// node.
2227-
func (p *PeerConnManager) fetchNodeAdvertisedAddrs(
2227+
func (p *Manager) fetchNodeAdvertisedAddrs(
22282228
pub *btcec.PublicKey) ([]net.Addr, error) {
22292229

22302230
vertex, err := route.NewVertexFromBytes(pub.SerializeCompressed())

server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ type server struct {
241241

242242
wg sync.WaitGroup
243243

244-
pcm *peerconn.PeerConnManager
244+
pcm *peerconn.Manager
245245
}
246246

247247
// CustomMessage is a custom message that is received from a peer.
@@ -1441,7 +1441,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
14411441
// Create liveness monitor.
14421442
s.createLivenessMonitor(cfg, cc)
14431443

1444-
s.pcm.Config = &peerconn.PeerConnManagerConfig{
1444+
s.pcm.Config = &peerconn.ManagerConfig{
14451445
PartialPeerConfig: s.createPartialPeerConfig(),
14461446
FeatureMgr: s.featureMgr,
14471447
Net: s.cfg.net,

0 commit comments

Comments
 (0)