Skip to content

Commit 4a7d31d

Browse files
petarmarten-seemannguillaumemichel
authored
log peers rejected for diversity (#759)
* 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]>
1 parent 87c65fa commit 4a7d31d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/ipfs/go-cid v0.5.0
1414
github.com/ipfs/go-datastore v0.6.0
1515
github.com/ipfs/go-detect-race v0.0.1
16+
github.com/ipfs/go-log v1.0.5
1617
github.com/ipfs/go-log/v2 v2.5.1
1718
github.com/ipfs/go-test v0.0.4
1819
github.com/libp2p/go-libp2p v0.38.2
@@ -64,7 +65,6 @@ require (
6465
github.com/huin/goupnp v1.3.0 // indirect
6566
github.com/ipfs/go-block-format v0.2.0 // indirect
6667
github.com/ipfs/go-ipfs-util v0.0.3 // indirect
67-
github.com/ipfs/go-log v1.0.5 // indirect
6868
github.com/ipld/go-ipld-prime v0.21.0 // indirect
6969
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
7070
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect

rt_diversity_filter.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import (
88

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

11+
logging "github.com/ipfs/go-log"
1112
ma "github.com/multiformats/go-multiaddr"
1213
)
1314

15+
var dfLog = logging.Logger("dht/RtDiversityFilter")
16+
1417
var _ peerdiversity.PeerIPGroupFilter = (*rtPeerIPGroupFilter)(nil)
1518

1619
type rtPeerIPGroupFilter struct {
@@ -37,7 +40,6 @@ func NewRTPeerDiversityFilter(h host.Host, maxPerCpl, maxForTable int) *rtPeerIP
3740
cplIpGroupCount: make(map[int]map[peerdiversity.PeerIPGroupKey]int),
3841
tableIpGroupCount: make(map[peerdiversity.PeerIPGroupKey]int),
3942
}
40-
4143
}
4244

4345
func (r *rtPeerIPGroupFilter) Allow(g peerdiversity.PeerGroupInfo) bool {
@@ -48,12 +50,15 @@ func (r *rtPeerIPGroupFilter) Allow(g peerdiversity.PeerGroupInfo) bool {
4850
cpl := g.Cpl
4951

5052
if r.tableIpGroupCount[key] >= r.maxForTable {
51-
53+
dfLog.Debugw("rejecting (max for table) diversity", "peer", g.Id, "cpl", g.Cpl, "ip group", g.IPGroupKey)
5254
return false
5355
}
5456

5557
c, ok := r.cplIpGroupCount[cpl]
5658
allow := !ok || c[key] < r.maxPerCpl
59+
if !allow {
60+
dfLog.Debugw("rejecting (max for cpl) diversity", "peer", g.Id, "cpl", g.Cpl, "ip group", g.IPGroupKey)
61+
}
5762
return allow
5863
}
5964

0 commit comments

Comments
 (0)