Skip to content

Commit

Permalink
Make BlackHoleState type public (#2917)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cpeliciari committed Aug 19, 2024
1 parent 74c393c commit 99433a2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions p2p/net/swarm/black_hole_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
manet "github.com/multiformats/go-multiaddr/net"
)

type blackHoleState int
type BlackHoleState int

const (
blackHoleStateProbing blackHoleState = iota
blackHoleStateProbing BlackHoleState = iota
blackHoleStateAllowed
blackHoleStateBlocked
)

func (st blackHoleState) String() string {
func (st BlackHoleState) String() string {
switch st {
case blackHoleStateProbing:
return "Probing"
Expand Down Expand Up @@ -57,7 +57,7 @@ type BlackHoleSuccessCounter struct {
// successes is the count of successful dials in outcomes
successes int
// state is the current state of the detector
state blackHoleState
state BlackHoleState
}

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

// HandleRequest returns the result of applying the black hole filter for the request.
func (b *BlackHoleSuccessCounter) HandleRequest() blackHoleState {
func (b *BlackHoleSuccessCounter) HandleRequest() BlackHoleState {
b.mu.Lock()
defer b.mu.Unlock()

Expand Down Expand Up @@ -129,7 +129,7 @@ func (b *BlackHoleSuccessCounter) updateState() {
}
}

func (b *BlackHoleSuccessCounter) State() blackHoleState {
func (b *BlackHoleSuccessCounter) State() BlackHoleState {
b.mu.Lock()
defer b.mu.Unlock()

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

type blackHoleInfo struct {
name string
state blackHoleState
state BlackHoleState
nextProbeAfter int
successFraction float64
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func (d *blackHoleDetector) RecordResult(addr ma.Multiaddr, success bool) {
}
}

func (d *blackHoleDetector) getFilterState(f *BlackHoleSuccessCounter) blackHoleState {
func (d *blackHoleDetector) getFilterState(f *BlackHoleSuccessCounter) BlackHoleState {
if d.readOnly {
if f.State() != blackHoleStateAllowed {
return blackHoleStateBlocked
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/black_hole_detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestBlackHoleSuccessCounterSuccessFraction(t *testing.T) {
n := 10
tests := []struct {
minSuccesses, successes int
result blackHoleState
result BlackHoleState
}{
{minSuccesses: 5, successes: 5, result: blackHoleStateAllowed},
{minSuccesses: 3, successes: 3, result: blackHoleStateAllowed},
Expand Down
4 changes: 2 additions & 2 deletions p2p/net/swarm/swarm_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type MetricsTracer interface {
FailedDialing(ma.Multiaddr, error, error)
DialCompleted(success bool, totalDials int)
DialRankingDelay(d time.Duration)
UpdatedBlackHoleSuccessCounter(name string, state blackHoleState, nextProbeAfter int, successFraction float64)
UpdatedBlackHoleSuccessCounter(name string, state BlackHoleState, nextProbeAfter int, successFraction float64)
}

type metricsTracer struct{}
Expand Down Expand Up @@ -274,7 +274,7 @@ func (m *metricsTracer) DialRankingDelay(d time.Duration) {
dialRankingDelay.Observe(d.Seconds())
}

func (m *metricsTracer) UpdatedBlackHoleSuccessCounter(name string, state blackHoleState,
func (m *metricsTracer) UpdatedBlackHoleSuccessCounter(name string, state BlackHoleState,
nextProbeAfter int, successFraction float64) {
tags := metricshelper.GetStringSlice()
defer metricshelper.PutStringSlice(tags)
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/swarm/swarm_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestMetricsNoAllocNoCover(t *testing.T) {
}

bhfNames := []string{"udp", "ipv6", "tcp", "icmp"}
bhfState := []blackHoleState{blackHoleStateAllowed, blackHoleStateBlocked}
bhfState := []BlackHoleState{blackHoleStateAllowed, blackHoleStateBlocked}

tests := map[string]func(){
"OpenedConnection": func() {
Expand Down

0 comments on commit 99433a2

Please sign in to comment.