stun

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ChangeIpPort 6
	ChangeIpPort = 6
	// ChangeIp 4
	ChangeIp = 4
	// ChangePort 2
	ChangePort = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BehaviorType

type BehaviorType int

BehaviorType nat Behavior Type

const (
	// BehaviorTypeUnknown 0
	BehaviorTypeUnknown BehaviorType = iota
	// BehaviorTypeEndpoint 1
	BehaviorTypeEndpoint
	// BehaviorTypeAddr 2
	BehaviorTypeAddr
	// BehaviorTypeAddrAndPort 3
	BehaviorTypeAddrAndPort
)

type ChangeNotifyParam

type ChangeNotifyParam struct {
	OtherAddr       ma.Multiaddr
	NotifyAddr      string
	LocalNotifyAddr string
}

ChangeNotifyParam one public addr

type ChangeParam

type ChangeParam struct {
	OtherAddr             ma.Multiaddr
	OtherMasterListenAddr ma.Multiaddr
	OtherSlaveListenAddr  ma.Multiaddr
	OtherMasterNetwork    network.Network
	OtherSlaveNetwork     network.Network
}

ChangeParam two public addr

type Client

type Client interface {
	//SetNetwork: save a network use to dial or listen
	SetNetwork(network.Network) error
	//CheckNatType: send msg to server and recv response to check nat type
	CheckNatType(peerId string, clientListenAddr, stunServerAddr ma.Multiaddr) (NATDeviceType, error)
	//CheckNatTypeByDomain: send msg to server support domain and recv response to check nat type
	CheckNatTypeByDomain(clientListenAddr ma.Multiaddr, peerId, stunServerDomain string) (NATDeviceType, error)
	//GetPeerNatType: send msg to server and recv response to get peer nat type
	GetPeerNatType(peerId string, clientListenAddr, stunServerAddr ma.Multiaddr) (NATDeviceType, error)
	//GetNatType: get nat type last time checked
	GetNatType() NATDeviceType
	//GetMappingType: get mapping type last time checked
	GetMappingType() BehaviorType
	//GetFilteringType: get filter type last time checked
	GetFilteringType() BehaviorType
}

Client . @Description: is use to check local nat

func NewDefaultStunClient

func NewDefaultStunClient(logger api.Logger) (Client, error)

NewDefaultStunClient .

@Description: new a client
@param logger:
@return Client:
@return error:

func NewUdpStunClient

func NewUdpStunClient(logger api.Logger) (Client, error)

NewUdpStunClient .

@Description: new a stun client
@param logger:
@return Client:
@return error:

type Data

type Data []byte

Data for stun

func (Data) AddTo

func (d Data) AddTo(m *stun.Message) error

AddTo adds DATA to message.

func (*Data) GetFrom

func (d *Data) GetFrom(m *stun.Message) error

GetFrom decodes DATA from message.

func (*Data) String

func (d *Data) String() string

String

type HolePunch

type HolePunch interface {
	//HolePunchAvailable: calculate a result if punch is available between two nat type
	HolePunchAvailable(type1, type2 NATDeviceType) bool
	//SetHost: set a host use to punch
	SetHost(host host.Host) error
	//DirectConnect: try punch
	DirectConnect(otherPeerAddr ma.Multiaddr) (network.Conn, error)
}

HolePunch . @Description:

type NATBehavior

type NATBehavior struct {
	// NAT MappingType
	MappingType BehaviorType
	// NAT FilteringType
	FilteringType BehaviorType
}

NATBehavior nat MappingType and FilteringType

type NATDeviceType

type NATDeviceType int

NATDeviceType .

const (
	// NATTypeUnknown 0
	NATTypeUnknown NATDeviceType = iota
	// NATTypeFullCone 1
	NATTypeFullCone
	// NATTypeRestrictedCone 2
	NATTypeRestrictedCone
	// NATTypePortRestrictedCone 3
	NATTypePortRestrictedCone
	// NATTypeSymmetric 4
	NATTypeSymmetric
)

type Server

type Server interface {
	//SetNetwork: save a network use to dial or listen
	SetNetwork(net1, net2 network.Network) error
	//Listen: start listen
	Listen(addr1, addr2 ma.Multiaddr) error
	//local device have two net card and two public address
	InitChangeIpLocal(*ChangeParam) error
	//other stun server locate another device
	InitChangeIpNotify(*ChangeNotifyParam) error
	//HandleChangeIpReq: handle change ip req from client
	HandleChangeIpReq(ma.Multiaddr, []byte) error
	//CloseListen: stop listen and close all conn
	CloseListen() error
}

Server . @Description: stun server,help stun client to check its nat type

InitChangeIpLocal: start listen on second public addr
InitChangeIpNotify:start server on http serve to handle notify

func NewDefaultStunServer

func NewDefaultStunServer(log api.Logger) (Server, error)

NewDefaultStunServer .

func NewUdpStunServer

func NewUdpStunServer(log api.Logger) (Server, error)

NewUdpStunServer .

@Description:  New a Udp StunServer
@param log:
@return Server:
@return error:

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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