Documentation
¶
Index ¶
Constants ¶
View Source
const CacheTime = 15 * time.Second
CacheTime 是映射缓存外部地址的时间
View Source
const MappingDuration = time.Minute
MappingDuration 是默认的端口映射持续时间 端口映射每 (MappingDuration / 3) 更新一次
Variables ¶
View Source
var ErrNoMapping = errors.New("未建立映射")
ErrNoMapping 表示地址没有映射
Functions ¶
This section is empty.
Types ¶
type NAT ¶
type NAT struct {
// contains filtered or unexported fields
}
NAT 是一个管理 NAT(网络地址转换器)中地址端口映射的对象 它是一个长期运行的服务,会定期更新端口映射, 并保持所有外部地址的最新列表
func DiscoverNAT ¶
DiscoverNAT 在网络中查找 NAT 设备并返回可以管理端口映射的对象 参数:
- ctx: context.Context 上下文对象
返回值:
- *NAT: NAT 管理对象
- error: 错误信息
func (*NAT) AddMapping ¶
AddMapping 尝试在指定协议和内部端口上构建映射 它会阻塞直到映射建立。一旦添加,它会定期更新映射。
可能不会成功,映射可能随时间变化; NAT 设备可能不遵守我们的端口请求,甚至会欺骗。 参数:
- ctx: context.Context 上下文对象
- protocol: string 协议名称
- port: int 端口号
返回值:
- error: 错误信息
func (*NAT) GetMapping ¶
GetMapping 获取指定协议和端口的映射 参数:
- protocol: string 协议名称
- port: int 端口号
返回值:
- addr: netip.AddrPort 映射的外部地址和端口
- found: bool 是否找到映射
Click to show internal directories.
Click to hide internal directories.