stun package - github.com/ccding/go-stun/stun - Go Packages (original) (raw)
Package stun is a STUN (RFC 3489 and RFC 5389) client implementation in golang.
It is extremely easy to use -- just one line of code.
nat, host, err := stun.NewClient().Discover()
More details please go to `main.go`.
- Constants
- type Client
- func (c *Client) Discover() (NATType, *Host, error)
- func (c *Client) Keepalive() (*Host, error)
- func (c *Client) SetServerAddr(address string)
- func (c *Client) SetServerHost(host string, port int)
- func (c *Client) SetSoftwareName(name string)
- func (c *Client) SetVVerbose(v bool)
- func (c *Client) SetVerbose(v bool)
- type Host
- type Logger
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Debugln(v ...interface{})
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Infoln(v ...interface{})
- func (l *Logger) SetDebug(v bool)
- func (l *Logger) SetInfo(v bool)
- type NATType
const ( DefaultServerAddr = "stun.ekiga.net:3478" DefaultSoftwareName = "StunClient" )
Default server address and client name.
This section is empty.
This section is empty.
Client is a STUN client, which can be set STUN server address and is used to discover NAT type.
NewClient returns a client without network connection. The network connection will be build when calling Discover function.
NewClientWithConnection returns a client which uses the given connection. Please note the connection should be acquired via net.Listen* method.
func (c *Client) Discover() (NATType, *Host, error)
Discover contacts the STUN server and gets the response of NAT type, host for UDP punching.
func (c Client) Keepalive() (Host, error)
Keepalive sends and receives a bind request, which ensures the mapping stays open Only applicable when client was created with a connection.
func (c *Client) SetServerAddr(address string)
SetServerAddr allows user to set the transport layer STUN server address.
SetServerHost allows user to set the STUN hostname and port.
func (c *Client) SetSoftwareName(name string)
SetSoftwareName allows user to set the name of the software, which is used for logging purpose (NOT used in the current implementation).
func (c *Client) SetVVerbose(v bool)
SetVVerbose sets the client to be in the double verbose mode, which prints information and packet in the discover process.
func (c *Client) SetVerbose(v bool)
SetVerbose sets the client to be in the verbose mode, which prints information in the discover process.
Host defines the network address including address family, IP address and port.
Family returns the family type of a host (IPv4 or IPv6).
IP returns the internet protocol address of the host.
Port returns the port number of the host.
String returns the string representation of the host address.
func (h *Host) TransportAddr() string
TransportAddr returns the transport layer address of the host.
Logger is a simple logger specified for this STUN client.
NewLogger creates a default logger.
func (l *Logger) Debug(v ...interface{})
Debug outputs the log in the format of log.Print.
func (l *Logger) Debugf(format string, v ...interface{})
Debugf outputs the log in the format of log.Printf.
func (l *Logger) Debugln(v ...interface{})
Debugln outputs the log in the format of log.Println.
func (l *Logger) Info(v ...interface{})
Info outputs the log in the format of log.Print.
func (l *Logger) Infof(format string, v ...interface{})
Infof outputs the log in the format of log.Printf.
func (l *Logger) Infoln(v ...interface{})
Infoln outputs the log in the format of log.Println.
func (l *Logger) SetDebug(v bool)
SetDebug sets the logger running in debug mode or not.
func (l *Logger) SetInfo(v bool)
SetInfo sets the logger running in info mode or not.
NATType is the type of NAT described by int.
const ( NATError NATType = iota NATUnknown NATNone NATBlocked NATFull NATSymmetric NATRestricted NATPortRestricted NATSymmetricUDPFirewall
NATSymetric = [NATSymmetric](#NATSymmetric)
NATSymetricUDPFirewall = [NATSymmetricUDPFirewall](#NATSymmetricUDPFirewall))
NAT types.