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

Commit 8157087

Browse files
committed
feat: switch to a single routability event
This means we can make the event _stateful_ so subscribing always gives us the last state.
1 parent bcf3ad5 commit 8157087

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

event/routability.go

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
package event
22

3-
// EvtLocalRoutabilityPrivate is an event struct to be emitted with the local's
4-
// node routability changes to PRIVATE (i.e. not routable from the Internet).
5-
//
6-
// This event is usually emitted by the AutoNAT subsystem.
7-
type EvtLocalRoutabilityPrivate struct{}
8-
9-
// EvtLocalRoutabilityPublic is an event struct to be emitted with the local's
10-
// node routability changes to PUBLIC (i.e. appear to routable from the
11-
// Internet).
12-
//
13-
// This event is usually emitted by the AutoNAT subsystem.
14-
type EvtLocalRoutabilityPublic struct{}
3+
import (
4+
"github.com/libp2p/go-libp2p-core/network"
5+
)
156

16-
// EvtLocalRoutabilityUnknown is an event struct to be emitted with the local's
17-
// node routability changes to UNKNOWN (i.e. we were unable to make a
18-
// determination about our NAT status with enough confidence).
7+
// EvtLocalRoutability is an event struct to be emitted with the local's node
8+
// routability changes state.
199
//
2010
// This event is usually emitted by the AutoNAT subsystem.
21-
type EvtLocalRoutabilityUnknown struct{}
11+
type EvtLocalRoutability struct {
12+
Routability network.Routability
13+
}

network/network.go

+18
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ const (
5353
CannotConnect
5454
)
5555

56+
// Routability indicates how reachable a node is.
57+
type Routability int
58+
59+
const (
60+
// RoutabilityUnknown indicates that the routability status is unknown.
61+
RoutabilityUnknown = iota
62+
63+
// RoutabilityPublic indicates that the node is reachable from the
64+
// public internet.
65+
RoutabilityPublic
66+
67+
// RoutabilityPrivate indicates that the node is not reachable from the
68+
// public internet.
69+
//
70+
// NOTE: This node may _still_ be reachable via relays.
71+
RoutabilityPrivate
72+
)
73+
5674
// Stat stores metadata pertaining to a given Stream/Conn.
5775
type Stat struct {
5876
Direction Direction

0 commit comments

Comments
 (0)