stun

package
v0.0.0-...-0e67523 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

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

View Source
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

func (c *Client) Discover(test1Only bool) (NATType, *Host, error)

Discover contacts the STUN server and gets the response of NAT type, host for UDP punching.

func (*Client) Keepalive

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 (*Client) SetLocalIP

func (c *Client) SetLocalIP(ip string)

SetLocalIP allows user to set the local ip address to send request.

func (*Client) SetLocalPort

func (c *Client) SetLocalPort(port int)

SetLocalPort allows user to set the local port to send request.

func (*Client) SetServerAddr

func (c *Client) SetServerAddr(address string)

SetServerAddr allows user to set the transport layer STUN server address.

func (*Client) SetServerHost

func (c *Client) SetServerHost(host string, port int)

SetServerHost allows user to set the STUN hostname and port.

func (*Client) SetSoftwareName

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 (*Client) SetVVerbose

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 (*Client) SetVerbose

func (c *Client) SetVerbose(v bool)

SetVerbose sets the client to be in the verbose mode, which prints information 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

func (h *Host) Family() uint16

Family returns the family type of a host (IPv4 or IPv6).

func (*Host) IP

func (h *Host) IP() string

IP returns the internet protocol address of the host.

func (*Host) Port

func (h *Host) Port() uint16

Port returns the port number of the host.

func (*Host) String

func (h *Host) String() string

String returns the string representation of the host address.

func (*Host) TransportAddr

func (h *Host) TransportAddr() string

TransportAddr returns the transport layer address of the host.

type Logger

type Logger struct {
	log.Logger
	// contains filtered or unexported fields
}

Logger is a simple logger specified for this STUN client.

func NewLogger

func NewLogger() *Logger

NewLogger creates a default logger.

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

Debug outputs the log in the format of log.Print.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

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

func (l *Logger) Infof(format string, v ...interface{})

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

func (l *Logger) SetDebug(v bool)

SetDebug sets the logger running in debug mode or not.

func (*Logger) SetInfo

func (l *Logger) SetInfo(v bool)

SetInfo sets the logger running in info 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.

func (NATType) String

func (nat NATType) String() string

Jump to

Keyboard shortcuts

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