Fix some connection bugs

This commit is contained in:
Asim Aslam 2019-07-31 16:49:48 +01:00
parent 873bfcc73c
commit 679c5f0ccd

View File

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