inetaf / nat Goto Github PK
View Code? Open in Web Editor NEWA collection of Go networking packages for dealing with NATs and NAT traversal.
License: BSD 3-Clause "New" or "Revised" License
A collection of Go networking packages for dealing with NATs and NAT traversal.
License: BSD 3-Clause "New" or "Revised" License
Per the discussions with @danderson in #1, there is a need to enable sending/receiving NAT-PMP (and later PCP) messages over a single multiplexed UDP socket.
I think the best way to do this is to add a low-level Conn API (inspired by my NDP package) that looks something like so:
package natpmp
type Conn struct {
// TODO: do or do not embed this directly to allow access to all deadline/raw byte I/O methods?
net.PacketConn
}
func NewConn(pc net.PacketConn) (*Conn, error) {
// Setup logic probably using x/net/ipv4. We still need to think about the multicast group case
// where a NAT gateway can notify us of its new external IP.
}
type Message interface {
Op() uint8
encoding.BinaryMarshaler
encoding.BinaryUnmarshaler
}
// All messages implement the Message interface.
type ExternalAddressRequest struct{}
type ExternalAddress struct{}
// other messages
// Marshaling to/from bytes while also dealing with message headers and I/O errors.
func ParseMessage(b []byte) (Message, error) {}
func MarshalMessage(m Message) ([]byte, error) {}
// Convenient APIs for dealing with Messages directly, while the underlying Conn also permits raw byte I/O
func (c *Conn) SendMessage(m Message, addr net.Addr) error {}
func (c *Conn) ReceiveMessage() (Message, net.Addr, error) {}
The existing Client can make use of this API in a very concise way and keep all the existing serialization and backoff/retry logic. It's unclear to me if any of that logic should live in Conn directly, but I'm leaning toward keeping it out.
For the Tailscale netcheck use case, it'd be easy to probe for NAT-PMP (and later PCP) using Conn.SendMessage, and then messages could be received using a raw Conn.ReadFrom combined with a call to ParseMessage.
Overall I think this approach provides significant flexibility while also allowing a nice low and high-level APIs. Thoughts, @danderson?
Hey @bradfitz, I assume you had to do something special on your end to make inet.af/netaddr work. Would you mind doing the same for inet.af/nat/* when it's convenient for you to do so? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.