diff --git a/network/default.go b/network/default.go index 415824a9..78553653 100644 --- a/network/default.go +++ b/network/default.go @@ -55,6 +55,8 @@ func (n *network) process(advertChan <-chan *router.Advert) { Timestamp: a.Timestamp.UnixNano(), Events: events, }) + case <-n.exit: + return } } } @@ -78,10 +80,12 @@ func (n *network) Connect() error { defer n.Unlock() // check if we're connected - if !n.connected { + if n.connected { return nil } + n.exit = make(chan bool) + // start advertising advertChan, err := n.options.Router.Advertise() if err != nil { @@ -111,6 +115,8 @@ func (n *network) Close() error { return nil } + close(n.exit) + // set connected to false n.connected = false