mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-03-30 13:20:06 +08:00
implement Stringer for network.{Direction,Connectedness,Reachability}. (#150)
This commit is contained in:
parent
e3a456b253
commit
9d35da1374
@ -34,6 +34,14 @@ const (
|
|||||||
DirOutbound
|
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.
|
// 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.
|
// It is used to signal to services and other peers whether a node is reachable.
|
||||||
type Connectedness int
|
type Connectedness int
|
||||||
@ -53,6 +61,14 @@ const (
|
|||||||
CannotConnect
|
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.
|
// Reachability indicates how reachable a node is.
|
||||||
type Reachability int
|
type Reachability int
|
||||||
|
|
||||||
@ -72,6 +88,14 @@ const (
|
|||||||
ReachabilityPrivate
|
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.
|
// Stat stores metadata pertaining to a given Stream/Conn.
|
||||||
type Stat struct {
|
type Stat struct {
|
||||||
Direction Direction
|
Direction Direction
|
||||||
|
Loading…
Reference in New Issue
Block a user