Fix counting logic to avoid double counting
@@ -93,13 +93,16 @@ func (r *Relay) addLiveHop(from, to peer.ID) {
r.lhLk.Lock()
defer r.lhLk.Unlock()
- r.lhCount++
trg, ok := r.liveHops[from]
if !ok {
trg = make(map[peer.ID]struct{})
r.liveHops[from] = trg
}
+ if _, ok := trg[to]; ok {
+ return
+ }
+ r.lhCount++
trg[to] = struct{}{}
}
@@ -111,6 +114,9 @@ func (r *Relay) rmLiveHop(from, to peer.ID) {
if !ok {
return
}
+ if _, ok := trg[to]; !ok {
+ return
+ }
r.lhCount--
delete(trg, to)
