Skip to content
Merged
Changes from 1 commit
Commits
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
21 changes: 18 additions & 3 deletions peer/brontide.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ type Brontide struct {
// off new wire messages for handing.
msgRouter fn.Option[msgmux.Router]

// globalMsgRouter is a flag that indicates whether we have a global
// msg router. If so, then we don't worry about stopping the msg router
// when a peer disconnects.
globalMsgRouter bool
Comment on lines +535 to +538
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this field is totally unnecessary. I think we just inline the call to cfg.MsgRouter.IsSome()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah can do that too: we can check against the config version as it has a life cycle independent of the peer itself.


startReady chan struct{}
quit chan struct{}
wg sync.WaitGroup
Expand All @@ -547,6 +552,11 @@ var _ lnpeer.Peer = (*Brontide)(nil)
func NewBrontide(cfg Config) *Brontide {
logPrefix := fmt.Sprintf("Peer(%x):", cfg.PubKeyBytes)

// We have a global message router if one was passed in via the config.
// In this case, we don't need to attempt to tear it down when the peer
// is stopped.
globalMsgRouter := cfg.MsgRouter.IsSome()

// We'll either use the msg router instance passed in, or create a new
// blank instance.
msgRouter := cfg.MsgRouter.Alt(fn.Some[msgmux.Router](
Expand Down Expand Up @@ -576,6 +586,7 @@ func NewBrontide(cfg Config) *Brontide {
quit: make(chan struct{}),
log: build.NewPrefixLog(logPrefix, peerLog),
msgRouter: msgRouter,
globalMsgRouter: globalMsgRouter,
}

if cfg.Conn != nil && cfg.Conn.RemoteAddr() != nil {
Expand Down Expand Up @@ -1393,9 +1404,13 @@ func (p *Brontide) Disconnect(reason error) {

close(p.quit)

p.msgRouter.WhenSome(func(router msgmux.Router) {
router.Stop()
})
// If our msg router isn't global (local to this instance), then we'll
// stop it. Otherwise, we'll leave it running.
if !p.globalMsgRouter {
p.msgRouter.WhenSome(func(router msgmux.Router) {
router.Stop()
})
}
}

// String returns the string representation of this peer.
Expand Down