Addressed code reviews.

This commit is contained in:
Mark Beamer Jr 2018-06-12 19:53:21 -04:00 committed by Alex Grintsvayg
parent 470e3721d0
commit 63e58248cc

View file

@ -136,10 +136,12 @@ func (dht *DHT) join() {
// now call iterativeFind on yourself // now call iterativeFind on yourself
nf := newContactFinder(dht.node, dht.node.id, false) nf := newContactFinder(dht.node, dht.node.id, false)
// stop if dht is stopped // stop if dht is stopped
go func(finder *contactFinder) { go func() {
<-dht.stop.Ch() <-dht.stop.Ch()
if nf != nil {
nf.Cancel() nf.Cancel()
}(nf) }
}()
_, err := nf.Find() _, err := nf.Find()
if err != nil { if err != nil {
log.Errorf("[%s] join: %s", dht.node.id.HexShort(), err.Error()) log.Errorf("[%s] join: %s", dht.node.id.HexShort(), err.Error())
@ -160,18 +162,21 @@ func (dht *DHT) Start() error {
if err != nil { if err != nil {
return err return err
} }
//Perform join in the background
dht.stop.Add(1) dht.stop.Add(1)
go func() { go func() {
defer dht.stop.Done() defer dht.stop.Done()
dht.join() dht.join()
}() log.Debugf("[%s] DHT ready on %s (%d nodes found during join)",
dht.node.id.HexShort(), dht.contact.Addr().String(), dht.node.rt.Count())
//Reannouncer can only be launched after join is complete.
dht.stop.Add(1) dht.stop.Add(1)
go func() { go func() {
defer dht.stop.Done() defer dht.stop.Done()
dht.startReannouncer() dht.startReannouncer()
}() }()
}()
log.Debugf("[%s] DHT ready on %s (%d nodes found during join)", dht.node.id.HexShort(), dht.contact.Addr().String(), dht.node.rt.Count())
return nil return nil
} }