p2p/discovery: use the seed table for finding nodes, auto drop stale ones

This commit is contained in:
Péter Szilágyi
2015-04-23 19:24:48 +03:00
parent 5f735d6fce
commit af923c965f
2 changed files with 38 additions and 5 deletions

View File

@ -177,8 +177,14 @@ func (tab *Table) refresh() {
result := tab.Lookup(randomID(tab.self.ID, ld))
if len(result) == 0 {
// bootstrap the table with a self lookup
all := tab.bondall(tab.nursery)
// Pick a batch of previously know seeds to lookup with and discard them (will come back if they are still live)
seeds := tab.db.list(10)
for _, seed := range seeds {
glog.V(logger.Debug).Infoln("Seeding network with:", seed)
tab.db.delete(seed.ID)
}
// Bootstrap the table with a self lookup
all := tab.bondall(append(tab.nursery, seeds...))
tab.mutex.Lock()
tab.add(all)
tab.mutex.Unlock()