mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-23 11:25:30 +02:00
Merge pull request #3354 from carlaKC/peernotify-addpeernotifierservice
Peernotifier: Add Peer Notifier package
This commit is contained in:
32
server.go
32
server.go
@@ -44,6 +44,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/nat"
|
||||
"github.com/lightningnetwork/lnd/netann"
|
||||
"github.com/lightningnetwork/lnd/peernotifier"
|
||||
"github.com/lightningnetwork/lnd/pool"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
@@ -188,6 +189,8 @@ type server struct {
|
||||
|
||||
channelNotifier *channelnotifier.ChannelNotifier
|
||||
|
||||
peerNotifier *peernotifier.PeerNotifier
|
||||
|
||||
witnessBeacon contractcourt.WitnessBeacon
|
||||
|
||||
breachArbiter *breachArbiter
|
||||
@@ -1089,6 +1092,10 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Assemble a peer notifier which will provide clients with subscriptions
|
||||
// to peer online and offline events.
|
||||
s.peerNotifier = peernotifier.New()
|
||||
|
||||
if cfg.WtClient.Active {
|
||||
policy := wtpolicy.DefaultPolicy()
|
||||
|
||||
@@ -1191,6 +1198,10 @@ func (s *server) Start() error {
|
||||
startErr = err
|
||||
return
|
||||
}
|
||||
if err := s.peerNotifier.Start(); err != nil {
|
||||
startErr = err
|
||||
return
|
||||
}
|
||||
if err := s.sphinx.Start(); err != nil {
|
||||
startErr = err
|
||||
return
|
||||
@@ -1349,6 +1360,7 @@ func (s *server) Stop() error {
|
||||
s.chainArb.Stop()
|
||||
s.sweeper.Stop()
|
||||
s.channelNotifier.Stop()
|
||||
s.peerNotifier.Stop()
|
||||
s.cc.wallet.Shutdown()
|
||||
s.cc.chainView.Stop()
|
||||
s.connMgr.Stop()
|
||||
@@ -2721,7 +2733,8 @@ func (s *server) addPeer(p *peer) {
|
||||
// TODO(roasbeef): pipe all requests through to the
|
||||
// queryHandler/peerManager
|
||||
|
||||
pubStr := string(p.addr.IdentityKey.SerializeCompressed())
|
||||
pubSer := p.addr.IdentityKey.SerializeCompressed()
|
||||
pubStr := string(pubSer)
|
||||
|
||||
s.peersByPub[pubStr] = p
|
||||
|
||||
@@ -2730,6 +2743,13 @@ func (s *server) addPeer(p *peer) {
|
||||
} else {
|
||||
s.outboundPeers[pubStr] = p
|
||||
}
|
||||
|
||||
// Inform the peer notifier of a peer online event so that it can be reported
|
||||
// to clients listening for peer events.
|
||||
var pubKey [33]byte
|
||||
copy(pubKey[:], pubSer)
|
||||
|
||||
s.peerNotifier.NotifyPeerOnline(pubKey)
|
||||
}
|
||||
|
||||
// peerInitializer asynchronously starts a newly connected peer after it has
|
||||
@@ -2971,7 +2991,8 @@ func (s *server) removePeer(p *peer) {
|
||||
return
|
||||
}
|
||||
|
||||
pubStr := string(p.addr.IdentityKey.SerializeCompressed())
|
||||
pubSer := p.addr.IdentityKey.SerializeCompressed()
|
||||
pubStr := string(pubSer)
|
||||
|
||||
delete(s.peersByPub, pubStr)
|
||||
|
||||
@@ -2980,6 +3001,13 @@ func (s *server) removePeer(p *peer) {
|
||||
} else {
|
||||
delete(s.outboundPeers, pubStr)
|
||||
}
|
||||
|
||||
// Inform the peer notifier of a peer offline event so that it can be
|
||||
// reported to clients listening for peer events.
|
||||
var pubKey [33]byte
|
||||
copy(pubKey[:], pubSer)
|
||||
|
||||
s.peerNotifier.NotifyPeerOffline(pubKey)
|
||||
}
|
||||
|
||||
// openChanReq is a message sent to the server in order to request the
|
||||
|
Reference in New Issue
Block a user