This repository was archived by the owner on Sep 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 76
Event for user's NAT Device Type: Tell user if the node is behind an Easy or Hard NAT #173
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9dc2088
event for NAT device type
aarshkshah1992 775b5cc
emit NAT type
aarshkshah1992 3842955
add transport protocol to NAT event
aarshkshah1992 6a62da7
event changes
aarshkshah1992 4024e24
Update network/nattype.go
aarshkshah1992 3ebc778
Update network/nattype.go
aarshkshah1992 948b39c
Update network/nattype.go
aarshkshah1992 9749f4b
removed alloc
aarshkshah1992 1e7e328
NAT protocol to string
aarshkshah1992 de360ba
refactor packages
aarshkshah1992 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package event | ||
|
||
import "github.com/libp2p/go-libp2p-core/network" | ||
|
||
// EvtNATDeviceTypeChanged is an event struct to be emitted when the type of the NAT device changes for a Transport Protocol. | ||
// | ||
// Note: This event is meaningful ONLY if the AutoNAT Reachability is Private. | ||
// Consumers of this event should ALSO consume the `EvtLocalReachabilityChanged` event and interpret | ||
// this event ONLY if the Reachability on the `EvtLocalReachabilityChanged` is Private. | ||
type EvtNATDeviceTypeChanged struct { | ||
// TransportProtocol is the Transport Protocol for which the NAT Device Type has been determined. | ||
TransportProtocol network.NATTransportProtocol | ||
// NatDeviceType indicates the type of the NAT Device for the Transport Protocol. | ||
// Currently, it can be either a `Cone NAT` or a `Symmetric NAT`. Please see the detailed documentation | ||
// on `network.NATDeviceType` enumerations for a better understanding of what these types mean and | ||
// how they impact Connectivity and Hole Punching. | ||
NatDeviceType network.NATDeviceType | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package network | ||
|
||
// NATDeviceType indicates the type of the NAT device. | ||
type NATDeviceType int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to have this definition of nat type be merged with the existing network.Reachability this seems to be a sub-division of what's currently used for network.ReachabilityPrivate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering that we need this event on a per transport protocol basis, it'll be extremely tricky to combine this with the |
||
|
||
const ( | ||
// NATDeviceTypeUnknown indicates that the type of the NAT device is unknown. | ||
NATDeviceTypeUnknown NATDeviceType = iota | ||
|
||
// NATDeviceTypeCone indicates that the NAT device is a Cone NAT. | ||
// A Cone NAT is a NAT where all outgoing connections from the same source IP address and port are mapped by the NAT device | ||
// to the same IP address and port irrespective of the destination address. | ||
// With regards to RFC 3489, this could be either a Full Cone NAT, a Restricted Cone NAT or a | ||
// Port Restricted Cone NAT. However, we do NOT differentiate between them here and simply classify all such NATs as a Cone NAT. | ||
// NAT traversal with hole punching is possible with a Cone NAT ONLY if the remote peer is ALSO behind a Cone NAT. | ||
// If the remote peer is behind a Symmetric NAT, hole punching will fail. | ||
NATDeviceTypeCone | ||
|
||
// NATDeviceTypeSymmetric indicates that the NAT device is a Symmetric NAT. | ||
// A Symmetric NAT maps outgoing connections with different destination addresses to different IP addresses and ports, | ||
// even if they originate from the same source IP address and port. | ||
// NAT traversal with hole-punching is currently NOT possible in libp2p with Symmetric NATs irrespective of the remote peer's NAT type. | ||
NATDeviceTypeSymmetric | ||
) | ||
|
||
func (r NATDeviceType) String() string { | ||
switch r { | ||
case 0: | ||
return "Unknown" | ||
case 1: | ||
return "Cone" | ||
case 2: | ||
return "Symmetric" | ||
default: | ||
return "unrecognized" | ||
} | ||
} | ||
|
||
// NATTransportProtocol is the transport protocol for which the NAT Device Type has been determined. | ||
type NATTransportProtocol int | ||
|
||
const ( | ||
// NATTransportUDP means that the NAT Device Type has been determined for the UDP Protocol. | ||
NATTransportUDP NATTransportProtocol = iota | ||
// NATTransportTCP means that the NAT Device Type has been determined for the TCP Protocol. | ||
NATTransportTCP | ||
) | ||
|
||
func (n NATTransportProtocol) String() string { | ||
switch n { | ||
case 0: | ||
return "UDP" | ||
case 1: | ||
return "TCP" | ||
default: | ||
return "unrecognized" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.