Documentation ¶
Overview ¶
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`.
Index ¶
- Constants
- type BehaviorType
- type Client
- func (c *Client) BehaviorTest() (*NATBehavior, error)
- func (c *Client) Discover(test1Only bool) (NATType, *Host, error)
- func (c *Client) Keepalive() (*Host, error)
- func (c *Client) SetLocalIP(ip string)
- func (c *Client) SetLocalPort(port int)
- 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 NATBehavior
- type NATType
Constants ¶
const ( DefaultServerAddr = "stun.ekiga.net:3478" DefaultSoftwareName = "StunClient" )
Default server address and client name.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BehaviorType ¶
type BehaviorType int
BehaviorType is NAT behavior type.
const ( BehaviorTypeUnknown BehaviorType = iota BehaviorTypeEndpoint BehaviorTypeAddr BehaviorTypeAddrAndPort )
Behavior types.
func (BehaviorType) String ¶
func (natBhType BehaviorType) String() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a STUN client, which can be set STUN server address and is used to discover NAT type.
func NewClient ¶
func NewClient() *Client
NewClient returns a client without network connection. The network connection will be build when calling Discover function.
func NewClientWithConnection ¶
func NewClientWithConnection(conn net.PacketConn) *Client
NewClientWithConnection returns a client which uses the given connection. Please note the connection should be acquired via net.Listen* method.
func (*Client) BehaviorTest ¶
func (c *Client) BehaviorTest() (*NATBehavior, error)
BehaviorTest performs STUN behavior tests.
func (*Client) Discover ¶
Discover contacts the STUN server and gets the response of NAT type, host for UDP punching.
func (*Client) Keepalive ¶
Keepalive sends and receives a bind request, which ensures the mapping stays open Only applicable when client was created with a connection.
func (*Client) SetLocalIP ¶
SetLocalIP allows user to set the local ip address to send request.
func (*Client) SetLocalPort ¶
SetLocalPort allows user to set the local port to send request.
func (*Client) SetServerAddr ¶
SetServerAddr allows user to set the transport layer STUN server address.
func (*Client) SetServerHost ¶
SetServerHost allows user to set the STUN hostname and port.
func (*Client) SetSoftwareName ¶
SetSoftwareName allows user to set the name of the software, which is used for logging purpose (NOT used in the current implementation).
func (*Client) SetVVerbose ¶
SetVVerbose sets the client to be in the double verbose mode, which prints information and packet in the discover process.
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host defines the network address including address family, IP address and port.
func (*Host) Family ¶
Family returns the family type of a host (IPv4 or IPv6).
func (*Host) String ¶
String returns the string representation of the host address.
type Logger ¶
Logger is a simple logger specified for this STUN client.
func (*Logger) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug outputs the log in the format of log.Print.
func (*Logger) Debugf ¶
Debugf outputs the log in the format of log.Printf.
func (*Logger) Debugln ¶
func (l *Logger) Debugln(v ...interface{})
Debugln outputs the log in the format of log.Println.
func (*Logger) Info ¶
func (l *Logger) Info(v ...interface{})
Info outputs the log in the format of log.Print.
func (*Logger) Infof ¶
Infof outputs the log in the format of log.Printf.
func (*Logger) Infoln ¶
func (l *Logger) Infoln(v ...interface{})
Infoln outputs the log in the format of log.Println.
func (*Logger) SetDebug ¶
SetDebug sets the logger running in debug mode or not.
type NATBehavior ¶
type NATBehavior struct { MappingType BehaviorType FilteringType BehaviorType }
NATBehavior is NAT behavior type of MappingType and FilteringType.
func (NATBehavior) NormalType ¶
func (natBehavior NATBehavior) NormalType() string
NormalType returns the normal NAT type of the NatBehavior.
type NATType ¶
type NATType int
NATType is the type of NAT described by int.
const ( NATError NATType = iota NATUnknown NATNone NATBlocked NATFull NATSymmetric NATRestricted NATPortRestricted SymmetricUDPFirewall // Deprecated spellings of these constants NATSymetric = NATSymmetric NATSymetricUDPFirewall = SymmetricUDPFirewall NATSymmetricUDPFirewall = SymmetricUDPFirewall )
NAT types.