Documentation ¶
Overview ¶
package nattywad implements NAT traversal using go-natty and waddell.
Index ¶
Constants ¶
const ( ServerReady = "ServerReady" Timeout = 30 * time.Second NattywadTopic = waddell.TopicId(5001) )
const DefaultWaddellCert = `` /* 1297-byte string literal not displayed */
DefaultWaddellCert is the certificate for the production waddell server(s) used by, amongst other things, flashlight.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // ClientMgr the ClientMgr to use to obtain Waddell connections ClientMgr *waddell.ClientMgr // OnSuccess: a callback that's invoked once a five tuple has been // obtained. Must be specified in order for Client to work. OnSuccess ClientSuccessCallback // OnFailure: a optional callback that's invoked if the NAT traversal fails // (e.g. times out). If unpopulated, failures aren't reported. OnFailure ClientFailureCallback // KeepAliveInterval: If specified to a non-zero value, nattywad will send a // keepalive message over the waddell channel to keep open the underlying // connections. KeepAliveInterval time.Duration // contains filtered or unexported fields }
Client is a client that initiates NAT traversals to one or more configured servers. When a NAT traversal results in a 5-tuple, the OnFiveTuple callback is called.
func (*Client) Configure ¶
func (c *Client) Configure(serverPeers []*ServerPeer)
Configure (re)configures this Client to communicate with the given list of server peers. Anytime that the list is found to contain a new peer, a NAT traversal is attempted to that peer.
type ClientFailureCallback ¶
type ClientFailureCallback func(info *TraversalInfo)
ClientFailureCallback is a callback that is invoked if a client NAT traversal fails.
type ClientSuccessCallback ¶
type ClientSuccessCallback func(info *TraversalInfo)
ClientSuccessCallback is a function that gets invoked when a client NAT traversal results in a UDP five tuple.
type Server ¶
type Server struct { // Client: the waddell Client that this server uses to communicate with // waddell. Client *waddell.Client // OnSuccess: a callback that's invoked once a five tuple has been // obtained. Must be specified in order for Server to work. OnSuccess ServerSuccessCallback // OnFailure: a optional callback that's invoked when a NAT traversal fails. // If unpopulated, failures aren't reported. OnFailure ServerFailureCallback // contains filtered or unexported fields }
Server is a server that answers NAT traversal requests received via waddell. When a NAT traversal results in a 5-tuple, the OnFiveTuple callback is called.
type ServerFailureCallback ¶
type ServerFailureCallback func(err error)
ServerFailureCallback is a function that gets invoked when a server NAT traversal fails for any reason.
type ServerPeer ¶
type ServerPeer struct { // ID: the server's PeerID on waddell (type 4 GUID) ID string // WaddellAddr: the address of the waddell server on which the server is // listening for offers. WaddellAddr string // Extras: Extra information about the peer (pass-through) Extras map[string]interface{} }
ServerPeer identifies a server for NAT traversal
func (*ServerPeer) CompositeID ¶
func (p *ServerPeer) CompositeID() string
func (*ServerPeer) String ¶
func (p *ServerPeer) String() string
type ServerSuccessCallback ¶
ServerSuccessCallback is a function that gets invoked when a server NAT traversal results in a UDP five tuple. The function allows the consumer of nattywad to bind to the resulting local and remote addresses and start whatever processing it needs to. ServerSuccessCallback should return true to indicate that the server is bound and ready, which will cause nattywad to emit a ServerReady message. Only once this has happened will the client on the other side of the NAT traversal actually get a five tuple through its own callback.
type TraversalInfo ¶
type TraversalInfo struct { // Peer: the ServerPeer with which we attempted traversal. Peer *ServerPeer // ServerRespondedToSignaling: indicates whether nattywad received any // signaling messages from the server peer during the traversal. ServerRespondedToSignaling bool // ServerGotFiveTuple: indicates whether or not the server peer got a // FiveTuple of its own. ServerGotFiveTuple bool // LocalAddr: on a successful traversal, this contains the local UDP addr of // the FiveTuple. LocalAddr *net.UDPAddr // RemoteAddr: on a successful traversal, this contains the remote UDP addr // of the FiveTuple. RemoteAddr *net.UDPAddr // Duration: the duration of the traversal Duration time.Duration }
TraversalInfo provides information about traversals (successful and failed).