Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion rt_diversity_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (

"github.com/libp2p/go-libp2p-kbucket/peerdiversity"

logging "github.com/ipfs/go-log"
ma "github.com/multiformats/go-multiaddr"
)

var dfLog = logging.Logger("dht/RtDiversityFilter")

var _ peerdiversity.PeerIPGroupFilter = (*rtPeerIPGroupFilter)(nil)

type rtPeerIPGroupFilter struct {
Expand Down Expand Up @@ -48,12 +51,15 @@ func (r *rtPeerIPGroupFilter) Allow(g peerdiversity.PeerGroupInfo) bool {
cpl := g.Cpl

if r.tableIpGroupCount[key] >= r.maxForTable {

dfLog.Debugw("rejecting (max for table) diversity of peer", g.Id, "cpl", g.Cpl, "ip group", g.IPGroupKey)
return false
}

c, ok := r.cplIpGroupCount[cpl]
allow := !ok || c[key] < r.maxPerCpl
if !allow {
dfLog.Debugw("rejecting (max for cpl) diversity of peer", g.Id, "cpl", g.Cpl, "ip group", g.IPGroupKey)
}
return allow
}

Expand Down