Skip to content

Commit

Permalink
log peers rejected for diversity (#759)
Browse files Browse the repository at this point in the history
* log peers rejected for diversity reasons

* log both reasons for diversity rejection

* Update rt_diversity_filter.go

Co-authored-by: Marten Seemann <[email protected]>

* Update rt_diversity_filter.go

Co-authored-by: Marten Seemann <[email protected]>

* fix: typo

---------

Co-authored-by: Marten Seemann <[email protected]>
Co-authored-by: Guillaume Michel <[email protected]>
Co-authored-by: guillaumemichel <[email protected]>
  • Loading branch information
4 people authored Feb 5, 2025
1 parent 87c65fa commit 4a7d31d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/ipfs/go-cid v0.5.0
github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-log v1.0.5
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipfs/go-test v0.0.4
github.com/libp2p/go-libp2p v0.38.2
Expand Down Expand Up @@ -64,7 +65,6 @@ require (
github.com/huin/goupnp v1.3.0 // indirect
github.com/ipfs/go-block-format v0.2.0 // indirect
github.com/ipfs/go-ipfs-util v0.0.3 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipld/go-ipld-prime v0.21.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
Expand Down
9 changes: 7 additions & 2 deletions 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 All @@ -37,7 +40,6 @@ func NewRTPeerDiversityFilter(h host.Host, maxPerCpl, maxForTable int) *rtPeerIP
cplIpGroupCount: make(map[int]map[peerdiversity.PeerIPGroupKey]int),
tableIpGroupCount: make(map[peerdiversity.PeerIPGroupKey]int),
}

}

func (r *rtPeerIPGroupFilter) Allow(g peerdiversity.PeerGroupInfo) bool {
Expand All @@ -48,12 +50,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", "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", "peer", g.Id, "cpl", g.Cpl, "ip group", g.IPGroupKey)
}
return allow
}

Expand Down

0 comments on commit 4a7d31d

Please sign in to comment.