Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
address comments from CR
Browse files Browse the repository at this point in the history
whyrusleeping committed Jun 1, 2015
1 parent 44656bd commit 6c6d788
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions routing/dht/providers.go
Original file line number Diff line number Diff line change
@@ -16,13 +16,16 @@ type providerInfo struct {
}

type ProviderManager struct {
// all non channel fields are meant to be accessed only within
// the run method
providers map[u.Key]map[peer.ID]time.Time
local map[u.Key]struct{}
lpeer peer.ID
getlocal chan chan []u.Key
newprovs chan *addProv
getprovs chan *getProv
period time.Duration

getlocal chan chan []u.Key
newprovs chan *addProv
getprovs chan *getProv
period time.Duration
ctxgroup.ContextGroup
}

@@ -70,19 +73,15 @@ func (pm *ProviderManager) run() {

case gp := <-pm.getprovs:
var parr []peer.ID
var remove []peer.ID
now := time.Now()
provs := pm.providers[gp.k]
for p, t := range provs {
if now.Sub(t) > time.Hour*24 {
remove = append(remove, p)
delete(provs, p)
} else {
parr = append(parr, p)
}
}
for _, p := range remove {
delete(provs, p)
}
gp.resp <- parr

case lc := <-pm.getlocal:
@@ -94,15 +93,11 @@ func (pm *ProviderManager) run() {

case <-tick.C:
for _, provs := range pm.providers {
var toremove []peer.ID
for p, t := range provs {
if time.Now().Sub(t) > time.Hour*24 {
toremove = append(toremove, p)
delete(provs, p)
}
}
for _, p := range toremove {
delete(provs, p)
}
}

case <-pm.Closing():

0 comments on commit 6c6d788

Please sign in to comment.