Skip to content

Commit 99433a2

Browse files
authored
Make BlackHoleState type public (#2917)
This commit changes the `blackHoleState` type from private to public by renaming it to `BlackHoleState`. This modification allows other packages to access and use this type, which is essential for monitoring and debugging purposes within the libp2p system. Related issue: #2890
1 parent 74c393c commit 99433a2

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

p2p/net/swarm/black_hole_detector.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88
manet "github.com/multiformats/go-multiaddr/net"
99
)
1010

11-
type blackHoleState int
11+
type BlackHoleState int
1212

1313
const (
14-
blackHoleStateProbing blackHoleState = iota
14+
blackHoleStateProbing BlackHoleState = iota
1515
blackHoleStateAllowed
1616
blackHoleStateBlocked
1717
)
1818

19-
func (st blackHoleState) String() string {
19+
func (st BlackHoleState) String() string {
2020
switch st {
2121
case blackHoleStateProbing:
2222
return "Probing"
@@ -57,7 +57,7 @@ type BlackHoleSuccessCounter struct {
5757
// successes is the count of successful dials in outcomes
5858
successes int
5959
// state is the current state of the detector
60-
state blackHoleState
60+
state BlackHoleState
6161
}
6262

6363
// RecordResult records the outcome of a dial. A successful dial in Blocked state will change the
@@ -91,7 +91,7 @@ func (b *BlackHoleSuccessCounter) RecordResult(success bool) {
9191
}
9292

9393
// HandleRequest returns the result of applying the black hole filter for the request.
94-
func (b *BlackHoleSuccessCounter) HandleRequest() blackHoleState {
94+
func (b *BlackHoleSuccessCounter) HandleRequest() BlackHoleState {
9595
b.mu.Lock()
9696
defer b.mu.Unlock()
9797

@@ -129,7 +129,7 @@ func (b *BlackHoleSuccessCounter) updateState() {
129129
}
130130
}
131131

132-
func (b *BlackHoleSuccessCounter) State() blackHoleState {
132+
func (b *BlackHoleSuccessCounter) State() BlackHoleState {
133133
b.mu.Lock()
134134
defer b.mu.Unlock()
135135

@@ -138,7 +138,7 @@ func (b *BlackHoleSuccessCounter) State() blackHoleState {
138138

139139
type blackHoleInfo struct {
140140
name string
141-
state blackHoleState
141+
state BlackHoleState
142142
nextProbeAfter int
143143
successFraction float64
144144
}
@@ -251,7 +251,7 @@ func (d *blackHoleDetector) RecordResult(addr ma.Multiaddr, success bool) {
251251
}
252252
}
253253

254-
func (d *blackHoleDetector) getFilterState(f *BlackHoleSuccessCounter) blackHoleState {
254+
func (d *blackHoleDetector) getFilterState(f *BlackHoleSuccessCounter) BlackHoleState {
255255
if d.readOnly {
256256
if f.State() != blackHoleStateAllowed {
257257
return blackHoleStateBlocked

p2p/net/swarm/black_hole_detector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestBlackHoleSuccessCounterSuccessFraction(t *testing.T) {
5959
n := 10
6060
tests := []struct {
6161
minSuccesses, successes int
62-
result blackHoleState
62+
result BlackHoleState
6363
}{
6464
{minSuccesses: 5, successes: 5, result: blackHoleStateAllowed},
6565
{minSuccesses: 3, successes: 3, result: blackHoleStateAllowed},

p2p/net/swarm/swarm_metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ type MetricsTracer interface {
131131
FailedDialing(ma.Multiaddr, error, error)
132132
DialCompleted(success bool, totalDials int)
133133
DialRankingDelay(d time.Duration)
134-
UpdatedBlackHoleSuccessCounter(name string, state blackHoleState, nextProbeAfter int, successFraction float64)
134+
UpdatedBlackHoleSuccessCounter(name string, state BlackHoleState, nextProbeAfter int, successFraction float64)
135135
}
136136

137137
type metricsTracer struct{}
@@ -274,7 +274,7 @@ func (m *metricsTracer) DialRankingDelay(d time.Duration) {
274274
dialRankingDelay.Observe(d.Seconds())
275275
}
276276

277-
func (m *metricsTracer) UpdatedBlackHoleSuccessCounter(name string, state blackHoleState,
277+
func (m *metricsTracer) UpdatedBlackHoleSuccessCounter(name string, state BlackHoleState,
278278
nextProbeAfter int, successFraction float64) {
279279
tags := metricshelper.GetStringSlice()
280280
defer metricshelper.PutStringSlice(tags)

p2p/net/swarm/swarm_metrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestMetricsNoAllocNoCover(t *testing.T) {
7979
}
8080

8181
bhfNames := []string{"udp", "ipv6", "tcp", "icmp"}
82-
bhfState := []blackHoleState{blackHoleStateAllowed, blackHoleStateBlocked}
82+
bhfState := []BlackHoleState{blackHoleStateAllowed, blackHoleStateBlocked}
8383

8484
tests := map[string]func(){
8585
"OpenedConnection": func() {

0 commit comments

Comments
 (0)