stunner

package
v0.97.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stunner

type Stunner struct {
	// Send sends a packet.
	// It will typically be a PacketConn.WriteTo method value.
	Send func([]byte, net.Addr) (int, error) // sends a packet

	// Endpoint is called whenever a STUN response is received.
	// The server is the STUN server that replied, endpoint is the ip:port
	// from the STUN response, and d is the duration that the STUN request
	// took on the wire (not including DNS lookup time.
	Endpoint func(server, endpoint string, d time.Duration)

	Servers []string // STUN servers to contact

	// DNSCache optionally specifies a DNSCache to use.
	// If nil, a DNS cache is not used.
	DNSCache *dnscache.Resolver

	// Logf optionally specifies a log function. If nil, logging is disabled.
	Logf func(format string, args ...interface{})

	// OnlyIPv6 controls whether IPv6 is exclusively used.
	// If false, only IPv4 is used. There is currently no mixed mode.
	OnlyIPv6 bool
	// contains filtered or unexported fields
}

Stunner sends a STUN request to several servers and handles a response.

It is designed to used on a connection owned by other code and so does not directly reference a net.Conn of any sort. Instead, the user should provide Send function to send packets, and call Receive when a new STUN response is received.

In response, a Stunner will call Endpoint with any endpoints determined for the connection. (An endpoint may be reported multiple times if multiple servers are provided.)

func (*Stunner) Receive

func (s *Stunner) Receive(p []byte, fromAddr *net.UDPAddr)

Receive delivers a STUN packet to the stunner.

func (*Stunner) Run

func (s *Stunner) Run(ctx context.Context) error

Run starts a Stunner and blocks until all servers either respond or are tried multiple times and timeout. It can not be called concurrently with itself.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL