Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
implement Stringer for network.{Direction,Connectedness,Reachability}. (
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk authored May 14, 2020
1 parent e3a456b commit 9d35da1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ const (
DirOutbound
)

func (d Direction) String() string {
str := [...]string{"Unknown", "Inbound", "Outbound"}
if d < 0 || int(d) >= len(str) {
return "(unrecognized)"
}
return str[d]
}

// Connectedness signals the capacity for a connection with a given node.
// It is used to signal to services and other peers whether a node is reachable.
type Connectedness int
Expand All @@ -53,6 +61,14 @@ const (
CannotConnect
)

func (c Connectedness) String() string {
str := [...]string{"NotConnected", "Connected", "CanConnect", "CannotConnect"}
if c < 0 || int(c) >= len(str) {
return "(unrecognized)"
}
return str[c]
}

// Reachability indicates how reachable a node is.
type Reachability int

Expand All @@ -72,6 +88,14 @@ const (
ReachabilityPrivate
)

func (r Reachability) String() string {
str := [...]string{"Unknown", "Public", "Private"}
if r < 0 || int(r) >= len(str) {
return "(unrecognized)"
}
return str[r]
}

// Stat stores metadata pertaining to a given Stream/Conn.
type Stat struct {
Direction Direction
Expand Down

0 comments on commit 9d35da1

Please sign in to comment.