portforward

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package portforward 实现 TCP/UDP 端口转发模块。

Index

Constants

View Source
const ID = "portforward"

ID 是模块标识。

Variables

This section is empty.

Functions

func ParsePorts

func ParsePorts(spec string) ([]int, error)

ParsePorts 解析端口表达式,支持 "80"、"80,443"、"8000-8010" 及其组合,保持书写顺序。

Types

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module 是端口转发模块。

func New

func New() *Module

New 创建模块实例。

func (*Module) ID

func (m *Module) ID() string

ID 实现 module.Module。

func (*Module) ImportLucky

func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)

ImportLucky 实现 luckyimport.Importer。

func (*Module) ImportRules

func (m *Module) ImportRules(rules []Rule) (int, error)

ImportRules 追加导入规则(由 Lucky 导入器调用),返回导入数量。

func (*Module) Init

func (m *Module) Init(env module.Env) error

Init 实现 module.Module。

func (*Module) Routes

func (m *Module) Routes(r module.Router)

Routes 实现 module.Module。

func (*Module) Start

func (m *Module) Start(ctx context.Context) error

Start 实现 module.Module。

func (*Module) Stop

func (m *Module) Stop() error

Stop 实现 module.Module。

func (*Module) Summary

func (m *Module) Summary() []module.SummaryItem

Summary 实现 module.Summarizer。

func (*Module) Title

func (m *Module) Title() string

Title 实现 module.Module。

type PortPair

type PortPair struct {
	Listen int `json:"listen"`
	Target int `json:"target"`
}

PortPair 是一组监听端口到目标端口的映射。

func MapPorts

func MapPorts(listenSpec, targetSpec string) ([]PortPair, error)

MapPorts 计算监听端口与目标端口的映射。 目标端口数量必须与监听端口相同(一一对应),或只有一个(全部转发到同一端口)。 目标端口为空时与监听端口相同。

type Rule

type Rule struct {
	Key             string   `json:"key"`
	Name            string   `json:"name"`
	Enable          bool     `json:"enable"`
	Protocols       []string `json:"protocols"`
	ListenAddress   string   `json:"listenAddress"`
	ListenPorts     string   `json:"listenPorts"`
	TargetAddresses []string `json:"targetAddresses"`
	TargetPorts     string   `json:"targetPorts"`
	// MaxConnections 是该规则每个 TCP 端口的最大并发连接数,0 表示使用全局默认值
	MaxConnections int `json:"maxConnections"`
	// UDPSessionTimeout 是 UDP 会话空闲超时(秒),0 表示使用全局默认值
	UDPSessionTimeout int    `json:"udpSessionTimeout"`
	Remark            string `json:"remark"`
}

Rule 是一条端口转发规则。

func (*Rule) Validate

func (r *Rule) Validate() error

Validate 校验规则并清理输入中的空白。

type RuleView

type RuleView struct {
	Rule
	Running bool          `json:"running"`
	Error   string        `json:"error,omitempty"`
	Details []string      `json:"details,omitempty"`
	Stats   StatsSnapshot `json:"stats"`
}

RuleView 是带运行状态的规则,用于 API 输出。

type Settings

type Settings struct {
	Enable                   bool `json:"enable"`
	DefaultMaxConnections    int  `json:"defaultMaxConnections"`
	DefaultUDPSessionTimeout int  `json:"defaultUDPSessionTimeout"`
	MaxUDPSessions           int  `json:"maxUDPSessions"`
	// DialTimeout 是连接目标的超时(秒)
	DialTimeout int `json:"dialTimeout"`
}

Settings 是模块级配置。

type Stats

type Stats struct {
	ActiveConns atomic.Int64
	TotalConns  atomic.Int64
	BytesIn     atomic.Int64 // 客户端 -> 目标
	BytesOut    atomic.Int64 // 目标 -> 客户端
}

Stats 是规则的运行统计,所有字段使用原子操作。

type StatsSnapshot

type StatsSnapshot struct {
	ActiveConns int64 `json:"activeConns"`
	TotalConns  int64 `json:"totalConns"`
	BytesIn     int64 `json:"bytesIn"`
	BytesOut    int64 `json:"bytesOut"`
}

StatsSnapshot 是统计的快照,用于 API 输出。

Jump to

Keyboard shortcuts

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