@@ -117,7 +117,7 @@ func (e *ErrPeerAlreadyConnected) Error() string {
117
117
}
118
118
119
119
// PeerConnManagerConfig holds config info for the peer conn manager.
120
- type PeerConnManagerConfig struct {
120
+ type ManagerConfig struct {
121
121
// PartialPeerConfig holds a peer config that's not yet completed and
122
122
// will be finished by the peer conn manager when making a new peer.
123
123
PartialPeerConfig peer.Config
@@ -168,8 +168,8 @@ type PeerConnManagerConfig struct {
168
168
}
169
169
170
170
// PeerConnManager is responsible for managing peer connections.
171
- type PeerConnManager struct {
172
- Config * PeerConnManagerConfig
171
+ type Manager struct {
172
+ Config * ManagerConfig
173
173
174
174
// IdentityECDH is an ECDH capable wrapper for the private key used
175
175
// to authenticate any incoming connections.
@@ -242,7 +242,7 @@ type PeerConnManager struct {
242
242
}
243
243
244
244
// Start will start the peer conn manager.
245
- func (p * PeerConnManager ) Start () error {
245
+ func (p * Manager ) Start () error {
246
246
// Create the connection manager which will be responsible for
247
247
// maintaining persistent outbound connections and also accepting new
248
248
// incoming connections
@@ -280,7 +280,7 @@ func (p *PeerConnManager) Start() error {
280
280
}
281
281
282
282
// Stop will stop the peer conn manager.
283
- func (p * PeerConnManager ) Stop () error {
283
+ func (p * Manager ) Stop () error {
284
284
// Before we shutdown the manager, disconnect from each active peers to
285
285
// ensure that peerTerminationWatchers signal completion to each peer.
286
286
for _ , peer := range p .Peers () {
@@ -316,15 +316,15 @@ func (p *PeerConnManager) Stop() error {
316
316
317
317
// Stopped returns true if the peer conn manager has been instructed to
318
318
// shutdown.
319
- func (p * PeerConnManager ) Stopped () bool {
319
+ func (p * Manager ) Stopped () bool {
320
320
return atomic .LoadInt32 (& p .stopping ) != 0
321
321
}
322
322
323
323
// NewPeerConnManager creates and returns a new peer conn manager.
324
324
func NewPeerConnManager (nodeKey keychain.SingleKeyECDH ,
325
- tc * tor.Controller ) * PeerConnManager {
325
+ tc * tor.Controller ) * Manager {
326
326
327
- return & PeerConnManager {
327
+ return & Manager {
328
328
IdentityECDH : nodeKey ,
329
329
330
330
// Assemble a peer notifier which will provide clients with
@@ -357,7 +357,7 @@ func NewPeerConnManager(nodeKey keychain.SingleKeyECDH,
357
357
// advertised addresses for any NodeAnnouncements from our persisted peers.
358
358
//
359
359
//nolint:lll
360
- func (p * PeerConnManager ) UpdatePersistentPeerAddrs () error {
360
+ func (p * Manager ) UpdatePersistentPeerAddrs () error {
361
361
graphSub , err := p .Config .SubscribeTopology ()
362
362
if err != nil {
363
363
return err
@@ -445,7 +445,7 @@ type IgnoredPeers map[autopilot.NodeID]struct{}
445
445
// to itself.
446
446
// - the peers that already have connections with, as in s.peersByPub.
447
447
// - the peers that we are attempting to connect, as in s.persistentPeers.
448
- func (p * PeerConnManager ) CreateBootstrapIgnorePeers () IgnoredPeers {
448
+ func (p * Manager ) CreateBootstrapIgnorePeers () IgnoredPeers {
449
449
p .mu .RLock ()
450
450
defer p .mu .RUnlock ()
451
451
@@ -477,7 +477,7 @@ func (p *PeerConnManager) CreateBootstrapIgnorePeers() IgnoredPeers {
477
477
// invariant, we ensure that our node is connected to a diverse set of peers
478
478
// and that nodes newly joining the network receive an up to date network view
479
479
// as soon as possible.
480
- func (p * PeerConnManager ) PeerBootstrapper (numTargetPeers uint32 ,
480
+ func (p * Manager ) PeerBootstrapper (numTargetPeers uint32 ,
481
481
bootstrappers []discovery.NetworkPeerBootstrapper ) {
482
482
483
483
defer p .wg .Done ()
@@ -611,7 +611,7 @@ func (p *PeerConnManager) PeerBootstrapper(numTargetPeers uint32,
611
611
// initialPeerBootstrap attempts to continuously connect to peers on startup
612
612
// until the target number of peers has been reached. This ensures that nodes
613
613
// receive an up to date network view as soon as possible.
614
- func (p * PeerConnManager ) initialPeerBootstrap (
614
+ func (p * Manager ) initialPeerBootstrap (
615
615
ignore map [autopilot.NodeID ]struct {}, numTargetPeers uint32 ,
616
616
bootstrappers []discovery.NetworkPeerBootstrapper ) {
617
617
@@ -728,7 +728,7 @@ type nodeAddresses struct {
728
728
// to all our direct channel collaborators. In order to promote liveness of our
729
729
// active channels, we instruct the connection manager to attempt to establish
730
730
// and maintain persistent connections to all our direct channel counterparties.
731
- func (p * PeerConnManager ) EstablishPersistentConnections () error {
731
+ func (p * Manager ) EstablishPersistentConnections () error {
732
732
// nodeAddrsMap stores the combination of node public keys and addresses
733
733
// that we'll attempt to reconnect to. PubKey strings are used as keys
734
734
// since other PubKey forms can't be compared.
@@ -907,7 +907,7 @@ func (p *PeerConnManager) EstablishPersistentConnections() error {
907
907
// sampling a value for the delay between 0s and the maxInitReconnectDelay.
908
908
//
909
909
// NOTE: This method MUST be run as a goroutine.
910
- func (p * PeerConnManager ) delayInitialReconnect (pubStr string ) {
910
+ func (p * Manager ) delayInitialReconnect (pubStr string ) {
911
911
delay := time .Duration (prand .Intn (maxInitReconnectDelay )) * time .Second
912
912
select {
913
913
case <- time .After (delay ):
@@ -919,7 +919,7 @@ func (p *PeerConnManager) delayInitialReconnect(pubStr string) {
919
919
// PrunePersistentPeerConnection removes all internal state related to
920
920
// persistent connections to a peer within the server. This is used to avoid
921
921
// persistent connection retries to peers we do not have any open channels with.
922
- func (p * PeerConnManager ) PrunePersistentPeerConnection (
922
+ func (p * Manager ) PrunePersistentPeerConnection (
923
923
compressedPubKey [33 ]byte ) {
924
924
925
925
pubKeyStr := string (compressedPubKey [:])
@@ -946,7 +946,7 @@ func (p *PeerConnManager) PrunePersistentPeerConnection(
946
946
// the target peers.
947
947
//
948
948
// 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 {},
950
950
msgs ... lnwire.Message ) error {
951
951
952
952
connLog .Debugf ("Broadcasting %v messages" , len (msgs ))
@@ -998,7 +998,7 @@ func (p *PeerConnManager) BroadcastMessage(skips map[route.Vertex]struct{},
998
998
// particular peer comes online. The peer itself is sent across the peerChan.
999
999
//
1000
1000
// NOTE: This function is safe for concurrent access.
1001
- func (p * PeerConnManager ) NotifyWhenOnline (peerKey [33 ]byte ,
1001
+ func (p * Manager ) NotifyWhenOnline (peerKey [33 ]byte ,
1002
1002
peerChan chan <- lnpeer.Peer ) {
1003
1003
1004
1004
p .mu .Lock ()
@@ -1051,7 +1051,7 @@ func (p *PeerConnManager) NotifyWhenOnline(peerKey [33]byte,
1051
1051
// NotifyWhenOffline delivers a notification to the caller of when the peer with
1052
1052
// the given public key has been disconnected. The notification is signaled by
1053
1053
// closing the channel returned.
1054
- func (p * PeerConnManager ) NotifyWhenOffline (
1054
+ func (p * Manager ) NotifyWhenOffline (
1055
1055
peerPubKey [33 ]byte ) <- chan struct {} {
1056
1056
1057
1057
p .mu .Lock ()
@@ -1083,7 +1083,7 @@ func (p *PeerConnManager) NotifyWhenOffline(
1083
1083
// daemon's local representation of the remote peer.
1084
1084
//
1085
1085
// NOTE: This function is safe for concurrent access.
1086
- func (p * PeerConnManager ) FindPeer (
1086
+ func (p * Manager ) FindPeer (
1087
1087
peerKey * btcec.PublicKey ) (* peer.Brontide , error ) {
1088
1088
1089
1089
p .mu .RLock ()
@@ -1099,7 +1099,7 @@ func (p *PeerConnManager) FindPeer(
1099
1099
// public key.
1100
1100
//
1101
1101
// NOTE: This function is safe for concurrent access.
1102
- func (p * PeerConnManager ) FindPeerByPubStr (
1102
+ func (p * Manager ) FindPeerByPubStr (
1103
1103
pubStr string ) (* peer.Brontide , error ) {
1104
1104
1105
1105
p .mu .RLock ()
@@ -1110,7 +1110,7 @@ func (p *PeerConnManager) FindPeerByPubStr(
1110
1110
1111
1111
// findPeerByPubStr is an internal method that retrieves the specified peer from
1112
1112
// the server's internal state using.
1113
- func (p * PeerConnManager ) findPeerByPubStr (
1113
+ func (p * Manager ) findPeerByPubStr (
1114
1114
pubStr string ) (* peer.Brontide , error ) {
1115
1115
1116
1116
peer , ok := p .peersByPub [pubStr ]
@@ -1124,7 +1124,7 @@ func (p *PeerConnManager) findPeerByPubStr(
1124
1124
// nextPeerBackoff computes the next backoff duration for a peer's pubkey using
1125
1125
// exponential backoff. If no previous backoff was known, the default is
1126
1126
// returned.
1127
- func (p * PeerConnManager ) nextPeerBackoff (pubStr string ,
1127
+ func (p * Manager ) nextPeerBackoff (pubStr string ,
1128
1128
startTime time.Time ) time.Duration {
1129
1129
1130
1130
// Now, determine the appropriate backoff to use for the retry.
@@ -1187,7 +1187,7 @@ func shouldDropLocalConnection(local, remote *btcec.PublicKey) bool {
1187
1187
// connection.
1188
1188
//
1189
1189
// NOTE: This function is safe for concurrent access.
1190
- func (p * PeerConnManager ) InboundPeerConnected (conn net.Conn ) {
1190
+ func (p * Manager ) InboundPeerConnected (conn net.Conn ) {
1191
1191
// Exit early if we have already been instructed to shutdown, this
1192
1192
// prevents any delayed callbacks from accidentally registering peers.
1193
1193
if p .Stopped () {
@@ -1284,7 +1284,7 @@ func (p *PeerConnManager) InboundPeerConnected(conn net.Conn) {
1284
1284
// OutboundPeerConnected initializes a new peer in response to a new outbound
1285
1285
// connection.
1286
1286
// NOTE: This function is safe for concurrent access.
1287
- func (p * PeerConnManager ) OutboundPeerConnected (connReq * connmgr.ConnReq ,
1287
+ func (p * Manager ) OutboundPeerConnected (connReq * connmgr.ConnReq ,
1288
1288
conn net.Conn ) {
1289
1289
1290
1290
// Exit early if we have already been instructed to shutdown, this
@@ -1418,7 +1418,7 @@ const UnassignedConnID uint64 = 0
1418
1418
// optionally specify a connection ID to ignore, which prevents us from
1419
1419
// canceling a successful request. All persistent connreqs for the provided
1420
1420
// pubkey are discarded after the operationjw.
1421
- func (p * PeerConnManager ) cancelConnReqs (pubStr string , skip * uint64 ) {
1421
+ func (p * Manager ) cancelConnReqs (pubStr string , skip * uint64 ) {
1422
1422
// First, cancel any lingering persistent retry attempts, which will
1423
1423
// prevent retries for any with backoffs that are still maturing.
1424
1424
if cancelChan , ok := p .persistentRetryCancels [pubStr ]; ok {
@@ -1461,7 +1461,7 @@ func (p *PeerConnManager) cancelConnReqs(pubStr string, skip *uint64) {
1461
1461
// peer by adding it to the server's global list of all active peers, and
1462
1462
// starting all the goroutines the peer needs to function properly. The inbound
1463
1463
// 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 ,
1465
1465
inbound bool ) {
1466
1466
1467
1467
brontideConn , ok := conn .(* brontide.Conn )
@@ -1544,7 +1544,7 @@ func (p *PeerConnManager) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
1544
1544
1545
1545
// addPeer adds the passed peer to the server's global state of all active
1546
1546
// peers.
1547
- func (p * PeerConnManager ) addPeer (peer * peer.Brontide ) {
1547
+ func (p * Manager ) addPeer (peer * peer.Brontide ) {
1548
1548
if peer == nil {
1549
1549
return
1550
1550
}
@@ -1588,7 +1588,7 @@ func (p *PeerConnManager) addPeer(peer *peer.Brontide) {
1588
1588
// be signaled of the new peer once the method returns.
1589
1589
//
1590
1590
// NOTE: This MUST be launched as a goroutine.
1591
- func (p * PeerConnManager ) peerInitializer (peer * peer.Brontide ) {
1591
+ func (p * Manager ) peerInitializer (peer * peer.Brontide ) {
1592
1592
defer p .wg .Done ()
1593
1593
1594
1594
// Avoid initializing peers while the server is exiting.
@@ -1649,7 +1649,7 @@ func (p *PeerConnManager) peerInitializer(peer *peer.Brontide) {
1649
1649
// successfully, otherwise the peer should be disconnected instead.
1650
1650
//
1651
1651
// NOTE: This MUST be launched as a goroutine.
1652
- func (p * PeerConnManager ) peerTerminationWatcher (peer * peer.Brontide ,
1652
+ func (p * Manager ) peerTerminationWatcher (peer * peer.Brontide ,
1653
1653
ready chan struct {}) {
1654
1654
1655
1655
defer p .wg .Done ()
@@ -1847,7 +1847,7 @@ func (p *PeerConnManager) peerTerminationWatcher(peer *peer.Brontide,
1847
1847
// currently none for a given address and it removes old connection requests
1848
1848
// if the associated address is no longer in the latest address list for the
1849
1849
// peer.
1850
- func (p * PeerConnManager ) connectToPersistentPeer (pubKeyStr string ) {
1850
+ func (p * Manager ) connectToPersistentPeer (pubKeyStr string ) {
1851
1851
p .mu .Lock ()
1852
1852
defer p .mu .Unlock ()
1853
1853
@@ -1947,7 +1947,7 @@ func (p *PeerConnManager) connectToPersistentPeer(pubKeyStr string) {
1947
1947
1948
1948
// removePeer removes the passed peer from the server's state of all active
1949
1949
// peers.
1950
- func (p * PeerConnManager ) removePeer (peer * peer.Brontide ) {
1950
+ func (p * Manager ) removePeer (peer * peer.Brontide ) {
1951
1951
if peer == nil {
1952
1952
return
1953
1953
}
@@ -1999,7 +1999,7 @@ func (p *PeerConnManager) removePeer(peer *peer.Brontide) {
1999
1999
// connection is established, or the initial handshake process fails.
2000
2000
//
2001
2001
// NOTE: This function is safe for concurrent access.
2002
- func (p * PeerConnManager ) ConnectToPeer (addr * lnwire.NetAddress ,
2002
+ func (p * Manager ) ConnectToPeer (addr * lnwire.NetAddress ,
2003
2003
perm bool , timeout time.Duration ) error {
2004
2004
2005
2005
targetPub := string (addr .IdentityKey .SerializeCompressed ())
@@ -2075,7 +2075,7 @@ func (p *PeerConnManager) ConnectToPeer(addr *lnwire.NetAddress,
2075
2075
// connectToPeer establishes a connection to a remote peer. errChan is used to
2076
2076
// notify the caller if the connection attempt has failed. Otherwise, it will be
2077
2077
// closed.
2078
- func (p * PeerConnManager ) connectToPeer (addr * lnwire.NetAddress ,
2078
+ func (p * Manager ) connectToPeer (addr * lnwire.NetAddress ,
2079
2079
errChan chan <- error , timeout time.Duration ) {
2080
2080
2081
2081
conn , err := brontide .Dial (
@@ -2103,7 +2103,7 @@ func (p *PeerConnManager) connectToPeer(addr *lnwire.NetAddress,
2103
2103
// identified by public key.
2104
2104
//
2105
2105
// 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 {
2107
2107
pubBytes := pubKey .SerializeCompressed ()
2108
2108
pubStr := string (pubBytes )
2109
2109
@@ -2137,7 +2137,7 @@ func (p *PeerConnManager) DisconnectPeer(pubKey *btcec.PublicKey) error {
2137
2137
2138
2138
// SendCustomMessage sends a custom message to the peer with the specified
2139
2139
// pubkey.
2140
- func (p * PeerConnManager ) SendCustomMessage (peerPub [33 ]byte ,
2140
+ func (p * Manager ) SendCustomMessage (peerPub [33 ]byte ,
2141
2141
msgType lnwire.MessageType , data []byte ) error {
2142
2142
2143
2143
peer , err := p .FindPeerByPubStr (string (peerPub [:]))
@@ -2165,7 +2165,7 @@ func (p *PeerConnManager) SendCustomMessage(peerPub [33]byte,
2165
2165
}
2166
2166
2167
2167
// 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 ) {
2169
2169
p .mu .Lock ()
2170
2170
defer p .mu .Unlock ()
2171
2171
@@ -2178,7 +2178,7 @@ func (p *PeerConnManager) AddPersistentPeer(peerKey *btcec.PublicKey) {
2178
2178
// Peers returns a slice of all active peers.
2179
2179
//
2180
2180
// NOTE: This function is safe for concurrent access.
2181
- func (p * PeerConnManager ) Peers () []* peer.Brontide {
2181
+ func (p * Manager ) Peers () []* peer.Brontide {
2182
2182
p .mu .RLock ()
2183
2183
defer p .mu .RUnlock ()
2184
2184
@@ -2224,7 +2224,7 @@ var errNoAdvertisedAddr = errors.New("no advertised address found")
2224
2224
2225
2225
// fetchNodeAdvertisedAddrs attempts to fetch the advertised addresses of a
2226
2226
// node.
2227
- func (p * PeerConnManager ) fetchNodeAdvertisedAddrs (
2227
+ func (p * Manager ) fetchNodeAdvertisedAddrs (
2228
2228
pub * btcec.PublicKey ) ([]net.Addr , error ) {
2229
2229
2230
2230
vertex , err := route .NewVertexFromBytes (pub .SerializeCompressed ())
0 commit comments