Addressed code reviews.
This commit is contained in:
parent
470e3721d0
commit
63e58248cc
1 changed files with 14 additions and 9 deletions
13
dht/dht.go
13
dht/dht.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue