Documentation
¶
Overview ¶
Package client provides a high-level interface for connecting and querying STUN and TURN services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LongtermCredentials ¶
func LongtermCredentials(username, password string) stun.Credentials
LongtermCredentials is a utility for indicating the long-term out-of-band credentials needed by TURN relays.
Types ¶
type StunClient ¶
type StunClient struct {
// The connection transport for communication with the server. This connection
// comes from net.Dial, and can be over UDP, TCP, or TCP over TLS as supported
// by the server.
net.Conn
// A net.Dialer is used to provide additional flexibility when Connect() is
// called, since a new connection to the server will need to be created. The
// StunClient defaults to using the same transport method for these subsequent
// connections, but this can be further specified with a custom Dialer.
*net.Dialer
// Credentials used for authenticating communication with the server.
*stun.Credentials
// Timeout until the active connection expires.
Timeout time.Duration
// Time until the next message must be received.
Deadline time.Time
// contains filtered or unexported fields
}
StunClient maintains state on a connection with a stun/turn server. New StunClient's should be created either by wrapping an existing net.Conn Connection to a Stun Server (as shown in the getIP and reflexiveTurn examples), or can be implicitly created through the Dialer interface.
func (*StunClient) Allocate ¶
func (s *StunClient) Allocate(c *stun.Credentials) (net.Addr, error)
Allocate Requests to connect to a TURN server. The TURN protocol uses the term allocation to refer to an authenticated connection with the server. Returns the bound address.
func (*StunClient) Bind ¶
func (s *StunClient) Bind() (net.Addr, error)
Bind Requests a Stun "Binding" to retrieve the Internet-visible address of the connection with the server. This is the function provided by the STUN RFC - to learn how a remote machine sees an active UDP connection created by the client, so that you can offer that endpoint for other machines to connect to.
A trivial Binding usage would be:
// Wrap a connection with a StunClient.
client := client.StunClient{Conn: c}
// Request the Binding.
address, err := client.Bind()
if err != nil {
log.Fatal("Failed bind:", err)
}
fmt.Printf("My address is: %s", address.String())
func (*StunClient) Connect ¶
Connect creates a new connection to 'to', relayed through the TURN server. The remote address must be pre-negotiated using RequestPermission for the proxied connection to be permitted.
func (*StunClient) RequestPermission ¶
func (s *StunClient) RequestPermission(with net.Addr) error
RequestPermission secures permission to send data with a remote address. The Client should already have an authenticated connection with the server, using Allocate, for this request to succeed.
type TurnDialer ¶
type TurnDialer struct {
// The connection to the Relay
StunClient
// Fields to implement a net.Dialer
Timeout time.Duration
Deadline time.Time
LocalAddr net.Addr
DualStack bool
FallbackDelay time.Duration
KeepAlive time.Duration
Cancel <-chan struct{}
}
A TURN Dialer is an implementation of net.Dialer which connects through a TURN relay.