Documentation
¶
Overview ¶
Package stun 实现 STUN 内网穿透模块:在 NAT1(全锥形)网络下获取公网映射端口, 并通过保活与内置转发把外部访问引到内网服务。
Index ¶
- Constants
- type AddrChange
- type Bind
- type Module
- func (m *Module) ID() string
- func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)
- func (m *Module) Init(env module.Env) error
- func (m *Module) Metrics() []module.Sample
- func (m *Module) Routes(r module.Router)
- func (m *Module) Start(ctx context.Context) error
- func (m *Module) Stop() error
- func (m *Module) Summary() []module.SummaryItem
- func (m *Module) Title() string
- type Rule
- type RuleState
- type RuleView
- type Settings
- type Stats
Constants ¶
const ( ProtoTCP4 = "tcp4" ProtoUDP4 = "udp4" )
协议取值
const ( BindIP = "ip" BindInterface = "interface" )
通道绑定方式
const ( StatusStopped = "stopped" StatusConnecting = "connecting" StatusOK = "ok" StatusRetrying = "retrying" StatusFailed = "failed" )
规则状态取值
const ID = "stun"
ID 是模块标识。
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddrChange ¶
AddrChange 记录一次公网地址变化。
type Bind ¶
type Bind struct {
Mode string `json:"mode"`
// IP 为空表示所有地址
IP string `json:"ip"`
Interface string `json:"interface"`
// Regex 选择网卡上的地址:留空取第 1 个、数字 n 取第 n 个、24* 前缀、*24 后缀,其余按正则
Regex string `json:"regex"`
}
Bind 指定穿透通道使用的本地地址,多拨或多线路时用来选择出口。
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module 是 STUN 穿透模块。
func (*Module) ImportLucky ¶
func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)
ImportLucky 实现 luckyimport.Importer。
func (*Module) Summary ¶
func (m *Module) Summary() []module.SummaryItem
Summary 实现 module.Summarizer。
type Rule ¶
type Rule struct {
Key string `json:"key"`
Name string `json:"name"`
// Group 为列表中的分组名称,只影响管理界面的展示,留空为未分组
Group string `json:"group"`
Enable bool `json:"enable"`
Protocol string `json:"protocol"`
Bind Bind `json:"bind"`
// LocalPort 为穿透通道本地端口,0 表示随机
LocalPort int `json:"localPort"`
UseGlobalServers bool `json:"useGlobalServers"`
StunServers []string `json:"stunServers"`
// KeepAliveServers 仅 TCP 使用:保持 NAT 映射的长连接目标,格式 host:port,端口缺省为 80
KeepAliveServers []string `json:"keepAliveServers"`
// DisableForward 为 true 时不使用内置转发,需在路由器上把通道端口映射到目标
DisableForward bool `json:"disableForward"`
TargetAddresses []string `json:"targetAddresses"`
TargetPort int `json:"targetPort"`
UPnP bool `json:"upnp"`
// UPnPGateway 为网关 IP,留空自动发现
UPnPGateway string `json:"upnpGateway"`
// UPnPLocalHost 覆盖映射的内部地址(Docker 桥接网络时填宿主机局域网 IP)
UPnPLocalHost string `json:"upnpLocalHost"`
// UPnPControlURL 直接指定 IGD 控制地址,跳过发现
UPnPControlURL string `json:"upnpControlUrl"`
// UPnPInternalPort 非 0 时把路由器端口直接映射到本机该端口(绕过内置转发)
UPnPInternalPort int `json:"upnpInternalPort"`
NATPMP bool `json:"natpmp"`
NATPMPGateway string `json:"natpmpGateway"`
// AutoFirewall 为 true 时在本机防火墙(nftables / iptables 的 input 链)放行通道端口,
// 规则停止时删除;Gately 运行在路由器或开了防火墙的主机上时使用
AutoFirewall bool `json:"autoFirewall"`
// 以下时间单位为毫秒
HeartbeatInterval int `json:"heartbeatInterval"`
StunTimeout int `json:"stunTimeout"`
RetryInterval int `json:"retryInterval"`
AutoRetry bool `json:"autoRetry"`
// DisableCheck 关闭通道有效性检测(连接自身公网地址验证可达)
DisableCheck bool `json:"disableCheck"`
// UseGlobalWebhook 与 Webhook.Enable 相互独立:两个都开时地址变化会分别发送到全局与自有 Webhook
UseGlobalWebhook bool `json:"useGlobalWebhook"`
Webhook webhook.Config `json:"webhook"`
// WebhookOnlyOnChange 为 true 时只在公网地址变化时触发通知
WebhookOnlyOnChange bool `json:"webhookOnlyOnChange"`
ScriptEnable bool `json:"scriptEnable"`
// Script 以 sh -c 执行,变量通过环境变量传入:ruleName time ip port ipAddr
Script string `json:"script"`
MaxConnections int `json:"maxConnections"`
UDPSessionTimeout int `json:"udpSessionTimeout"`
// Access 为内置转发的来源 IP 访问控制(白名单 / 黑名单),在连接目标之前判断;封禁表中的地址无论何种模式都会被拒绝。
// 修改名单时不重启穿透,公网端口保持不变
iplist.Access
Remark string `json:"remark"`
// contains filtered or unexported fields
}
Rule 是一条 STUN 穿透规则。
type RuleState ¶
type RuleState struct {
Status string `json:"status"`
PublicAddr string `json:"publicAddr,omitempty"`
LocalAddr string `json:"localAddr,omitempty"`
StunServer string `json:"stunServer,omitempty"`
Since time.Time `json:"since,omitzero"`
Error string `json:"error,omitempty"`
Mapping string `json:"mapping,omitempty"`
// Firewall 为自动放行防火墙的结果说明
Firewall string `json:"firewall,omitempty"`
History []AddrChange `json:"history,omitempty"`
Stats Stats `json:"stats"`
}
RuleState 是规则运行状态。
type Settings ¶
type Settings struct {
Enable bool `json:"enable"`
StunServers []string `json:"stunServers"`
KeepAliveServers []string `json:"keepAliveServers"`
Webhook webhook.Config `json:"webhook"`
// AddrCheckInterval 为重新查询公网地址的周期(秒)
AddrCheckInterval int `json:"addrCheckInterval"`
}
Settings 是模块级配置。