vpn

package
v0.0.0-...-37f8b3f Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DHCPNetworkService

func DHCPNetworkService(ip chan string, l log.StandardLogger, maxTime time.Duration, leasedir string, address string) node.NetworkService

DHCPNetworkService 返回一个DHCP网络服务 参数 ip 为IP地址通道,l 为日志记录器,maxTime 为最大超时时间,leasedir 为租约目录,address 为基础地址

func Logger

func Logger(l log.StandardLogger) func(cfg *Config) error

Logger 设置日志记录器的选项

func NetLinkBootstrap

func NetLinkBootstrap(b bool) func(cfg *Config) error

NetLinkBootstrap 设置是否使用NetLink引导的选项

func Register

func Register(p ...Option) ([]node.Option, error)

Start the node and the vpn. Returns an error in case of failure When starting the vpn, there is no need to start the node Register 注册VPN服务,返回节点选项 启动节点和VPN。如果失败则返回错误 启动VPN时,无需单独启动节点

func VPNNetworkService

func VPNNetworkService(p ...Option) node.NetworkService

VPNNetworkService 返回一个VPN网络服务,用于处理VPN连接和数据转发 参数 p 为可选的配置选项

func WithInterface

func WithInterface(i *water.Interface) func(cfg *Config) error

WithInterface 设置网络接口的选项

func WithInterfaceAddress

func WithInterfaceAddress(i string) func(cfg *Config) error

WithInterfaceAddress 设置接口IP地址的选项

func WithInterfaceMTU

func WithInterfaceMTU(i int) func(cfg *Config) error

WithInterfaceMTU 设置接口MTU值的选项

func WithInterfaceName

func WithInterfaceName(i string) func(cfg *Config) error

WithInterfaceName 设置接口名称的选项

func WithInterfaceType

func WithInterfaceType(d water.DeviceType) func(cfg *Config) error

WithInterfaceType 设置接口设备类型的选项

func WithLedgerAnnounceTime

func WithLedgerAnnounceTime(t time.Duration) func(cfg *Config) error

WithLedgerAnnounceTime 设置账本公告时间间隔的选项

func WithMaxStreams

func WithMaxStreams(i int) func(cfg *Config) error

WithMaxStreams 设置最大流数量的选项

func WithPacketMTU

func WithPacketMTU(i int) func(cfg *Config) error

WithPacketMTU 设置数据包MTU值的选项

func WithRouterAddress

func WithRouterAddress(i string) func(cfg *Config) error

WithRouterAddress 设置路由器地址的选项

Types

type Config

type Config struct {
	Interface        *water.Interface // 网络接口实例
	InterfaceName    string           // 接口名称
	InterfaceAddress string           // 接口IP地址(CIDR格式)
	RouterAddress    string           // 路由器地址
	InterfaceMTU     int              // 接口MTU值
	MTU              int              // 数据包MTU值
	DeviceType       water.DeviceType // 设备类型(TUN/TAP)

	LedgerAnnounceTime time.Duration      // 账本公告时间间隔
	Logger             log.StandardLogger // 日志记录器

	NetLinkBootstrap bool // 是否使用NetLink引导

	// Frame timeout 帧超时时间
	Timeout time.Duration

	Concurrency       int // 并发处理数
	ChannelBufferSize int // 通道缓冲区大小
	MaxStreams        int // 最大流数量
	// contains filtered or unexported fields
}

Config VPN配置结构体,包含VPN接口和运行时参数

func (*Config) Apply

func (cfg *Config) Apply(opts ...Option) error

Apply 应用给定的选项到配置,返回遇到的第一个错误(如果有)

type Option

type Option func(cfg *Config) error

Option 配置选项函数类型

var LowProfile Option = func(cfg *Config) error {
	cfg.lowProfile = true

	return nil
}

LowProfile 低配置模式选项,启用后会限制资源使用

func DHCP

func DHCP(l log.StandardLogger, maxTime time.Duration, leasedir string, address string) ([]node.Option, []Option)

DHCP 返回一个DHCP网络服务。它需要Alive服务来确定可用节点。 可用节点用于确定哪些节点需要IP,当maxTime过期时,节点被标记为离线并不再考虑。 参数 l 为日志记录器,maxTime 为最大超时时间,leasedir 为租约目录,address 为基础地址 返回节点选项和VPN选项

func WithChannelBufferSize

func WithChannelBufferSize(i int) Option

WithChannelBufferSize 设置通道缓冲区大小的选项

func WithConcurrency

func WithConcurrency(i int) Option

WithConcurrency 设置并发处理数的选项

func WithTimeout

func WithTimeout(s string) Option

WithTimeout 设置超时时间的选项 参数 s 为超时时间字符串(如 "15s")

Jump to

Keyboard shortcuts

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