nat

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSupportProtocol = errors.New("not support protocol")
	ErrNoExternalAddress  = errors.New("no external address")
	ErrNoInternalAddress  = errors.New("no internal address")
)

Functions

func InGatewayLocalIp

func InGatewayLocalIp(gatewayIp net.IP) (net.IP, error)

func SetLogger

func SetLogger(l Logger)

Types

type Discover

type Discover struct {
}

func (*Discover) DiscoverNats

func (sel *Discover) DiscoverNats(ctx context.Context) ([]NAT, error)

type Logger

type Logger interface {
	Infof(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Warnf(format string, args ...interface{})
}

type NAT

type NAT interface {
	// Type 什么类型的NAT设备
	Type() string

	DeviceName() string

	Location() *url.URL

	// GetDeviceAddress 获取NAT设备的话网关地址,设备地址
	GetDeviceAddress() (addr net.IP, err error)

	// GetExternalAddress 获取NAT设备的外网地址
	GetExternalAddress() (addr net.IP, err error)

	// GetInternalAddress 获取当前连接NAT设备的内网地址
	GetInternalAddress() (addr net.IP, err error)

	// AddPortMapping 添加端口映射
	AddPortMapping(protocol string, internalPort int, externalPort int, leaseDuration uint, desc string) (err error)

	// DeletePortMapping 移除端口映射
	DeletePortMapping(protocol string, internalPort int) (err error)

	GetPortMapping(protocol string, externalPort int) (*upnp.GetSpecificPortMappingEntryResp, error)

	GetDeviceStatus() (*upnp.GetStatusInfoResp, error)
}

NAT protocol is either "udp" or "tcp"

func DiscoverNats

func DiscoverNats(ctx context.Context) ([]NAT, error)

type Protocol

type Protocol string
const (
	ProtocolTCP Protocol = "TCP" // ProtocolTCP tcp协议
	ProtocolUDP Protocol = "UDP" // ProtocolUDP udp协议
)

func (Protocol) IsSupport

func (p Protocol) IsSupport() error

func (Protocol) String

func (p Protocol) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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