Browse Source

feat: switch to a single routability event

This means we can make the event _stateful_ so subscribing always gives us the
last state.
pull/1683/head
Steven Allen 5 years ago
parent
commit
105e5f22bf
  1. 24
      core/event/routability.go
  2. 18
      core/network/network.go

24
core/event/routability.go

@ -1,21 +1,13 @@
package event
// EvtLocalRoutabilityPrivate is an event struct to be emitted with the local's
// node routability changes to PRIVATE (i.e. not routable from the Internet).
//
// This event is usually emitted by the AutoNAT subsystem.
type EvtLocalRoutabilityPrivate struct{}
// EvtLocalRoutabilityPublic is an event struct to be emitted with the local's
// node routability changes to PUBLIC (i.e. appear to routable from the
// Internet).
//
// This event is usually emitted by the AutoNAT subsystem.
type EvtLocalRoutabilityPublic struct{}
import (
"github.com/libp2p/go-libp2p-core/network"
)
// EvtLocalRoutabilityUnknown is an event struct to be emitted with the local's
// node routability changes to UNKNOWN (i.e. we were unable to make a
// determination about our NAT status with enough confidence).
// EvtLocalRoutability is an event struct to be emitted with the local's node
// routability changes state.
//
// This event is usually emitted by the AutoNAT subsystem.
type EvtLocalRoutabilityUnknown struct{}
type EvtLocalRoutability struct {
Routability network.Routability
}

18
core/network/network.go

@ -53,6 +53,24 @@ const (
CannotConnect
)
// Routability indicates how reachable a node is.
type Routability int
const (
// RoutabilityUnknown indicates that the routability status is unknown.
RoutabilityUnknown = iota
// RoutabilityPublic indicates that the node is reachable from the
// public internet.
RoutabilityPublic
// RoutabilityPrivate indicates that the node is not reachable from the
// public internet.
//
// NOTE: This node may _still_ be reachable via relays.
RoutabilityPrivate
)
// Stat stores metadata pertaining to a given Stream/Conn.
type Stat struct {
Direction Direction

Loading…
Cancel
Save