gost

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

AuthConfig 认证配置

type ChainConfig

type ChainConfig struct {
	Name     string          `json:"name"`
	Selector *SelectorConfig `json:"selector,omitempty"`
	Hops     []string        `json:"hops,omitempty"`
}

ChainConfig 转发链配置

type Client

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

Client gost API 客户端

func NewClient

func NewClient(cfg *Config) *Client

NewClient 创建客户端

func (*Client) CreateChain

func (c *Client) CreateChain(ctx context.Context, chain *ChainConfig) error

CreateChain 创建转发链

func (*Client) CreateHop

func (c *Client) CreateHop(ctx context.Context, hop *HopConfig) error

CreateHop 创建跳点

func (*Client) CreateService

func (c *Client) CreateService(ctx context.Context, svc *ServiceConfig) error

CreateService 创建服务

func (*Client) DeleteChain

func (c *Client) DeleteChain(ctx context.Context, name string) error

DeleteChain 删除转发链

func (*Client) DeleteHop

func (c *Client) DeleteHop(ctx context.Context, name string) error

DeleteHop 删除跳点

func (*Client) DeleteService

func (c *Client) DeleteService(ctx context.Context, name string) error

DeleteService 删除服务

func (*Client) GetAllServiceTrafficTotals

func (c *Client) GetAllServiceTrafficTotals(ctx context.Context) (map[string]*ServiceTrafficTotals, error)

GetAllServiceTrafficTotals 从 gost 的 Prometheus /metrics 端点读取该节点所有 service 的累计流量, 用于节点级统计(不按具体 forward 过滤)。

func (*Client) GetChains

func (c *Client) GetChains(ctx context.Context) ([]*ChainConfig, error)

GetChains 获取转发链列表

func (*Client) GetService

func (c *Client) GetService(ctx context.Context, name string) (*ServiceConfig, error)

GetService 获取单个服务

func (*Client) GetServiceStats deprecated

func (c *Client) GetServiceStats(ctx context.Context, name string) (*ServiceStats, error)

GetServiceStats 获取单个服务统计

Deprecated: gost v3.2.6 的管理 API (端口 18080) 不存在 /api/stats 系列接口, 调用这个方法会一直收到 404。字节计数只能通过 GetServiceTrafficTotals 从 Prometheus /metrics 端口读取。保留此方法仅为兼容旧引用,不再作为采集手段。

func (*Client) GetServiceTrafficTotals

func (c *Client) GetServiceTrafficTotals(ctx context.Context, serviceNames []string) (map[string]*ServiceTrafficTotals, error)

GetServiceTrafficTotals 从 gost 的 Prometheus /metrics 端点读取指定 service 的累计流量。 gost_service_transfer_input_bytes_total / _output_bytes_total 按 client IP 分行, 需要对同一个 service label 的所有行求和才是该服务的总流量。

func (*Client) GetServices

func (c *Client) GetServices(ctx context.Context) (*ServiceListResponse, error)

GetServices 获取服务列表

func (*Client) GetStats

func (c *Client) GetStats(ctx context.Context) (*StatsResponse, error)

GetStats 获取统计信息

func (*Client) HasMetricsEndpoint

func (c *Client) HasMetricsEndpoint() bool

HasMetricsEndpoint 是否已配置 Prometheus /metrics 地址

func (*Client) HealthCheck

func (c *Client) HealthCheck(ctx context.Context) error

HealthCheck 检查 gost API 是否可用

func (*Client) Reload

func (c *Client) Reload(ctx context.Context) error

Reload 重载配置

func (*Client) UpdateService

func (c *Client) UpdateService(ctx context.Context, name string, svc *ServiceConfig) error

UpdateService 更新服务

type Config

type Config struct {
	Host        string // gost API 地址,如 "http://192.168.1.1:18080"
	MetricsHost string // gost Prometheus /metrics 地址,如 "http://192.168.1.1:9000",为空表示未配置
	APIToken    string // API 认证令牌
	Timeout     time.Duration
}

Config 客户端配置

type ConnectorConfig

type ConnectorConfig struct {
	Type     string            `json:"type"`
	Auth     *AuthConfig       `json:"auth,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

ConnectorConfig 连接器配置

type CurrentStats

type CurrentStats struct {
	Connections int   `json:"connections"`
	Handled     int64 `json:"handled"`
	InBytes     int64 `json:"inBytes"`
	OutBytes    int64 `json:"outBytes"`
}

CurrentStats 当前统计

type DialerConfig

type DialerConfig struct {
	Type     string            `json:"type"`
	Auth     *AuthConfig       `json:"auth,omitempty"`
	TLS      *TLSConfig        `json:"tls,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

DialerConfig 拨号器配置

type ForwarderConfig

type ForwarderConfig struct {
	Nodes    []ForwarderNode `json:"nodes,omitempty"`
	Selector *SelectorConfig `json:"selector,omitempty"`
}

ForwarderConfig 转发器配置

type ForwarderNode

type ForwarderNode struct {
	Name     string `json:"name"`
	Addr     string `json:"addr"`
	Protocol string `json:"protocol,omitempty"`
}

ForwarderNode 转发目标节点

type HandlerConfig

type HandlerConfig struct {
	Type     string            `json:"type"`
	Auth     *AuthConfig       `json:"auth,omitempty"`
	Chain    string            `json:"chain,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

HandlerConfig 处理器配置

type HopConfig

type HopConfig struct {
	Name     string          `json:"name"`
	Selector *SelectorConfig `json:"selector,omitempty"`
	Nodes    []HopNode       `json:"nodes,omitempty"`
}

HopConfig 跳点配置

type HopNode

type HopNode struct {
	Name      string           `json:"name"`
	Addr      string           `json:"addr"`
	Interface string           `json:"interface,omitempty"`
	Connector *ConnectorConfig `json:"connector,omitempty"`
	Dialer    *DialerConfig    `json:"dialer,omitempty"`
}

HopNode 跳点节点

type ListenerConfig

type ListenerConfig struct {
	Type     string            `json:"type"`
	Auth     *AuthConfig       `json:"auth,omitempty"`
	Chain    string            `json:"chain,omitempty"`
	TLS      *TLSConfig        `json:"tls,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

ListenerConfig 监听器配置

type Manager

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

Manager gost 转发管理器

func NewManager

func NewManager(db *gorm.DB) *Manager

NewManager 创建管理器

func (*Manager) CheckNodeHealth

func (m *Manager) CheckNodeHealth(ctx context.Context, nodeID uint) error

CheckNodeHealth 检查节点健康状态

func (*Manager) CreateChain

func (m *Manager) CreateChain(ctx context.Context, relayNodeID, exitNodeID uint, chainName string) error

CreateChain 创建转发链(中转 -> 落地)

func (*Manager) CreateForwardRule

func (m *Manager) CreateForwardRule(ctx context.Context, rule *model.ForwardRule) error

CreateForwardRule 创建转发规则 对于中转节点(relay): 创建监听服务 对于落地节点(exit): 需要在中转节点上配置转发链

func (*Manager) DeleteForwardRule

func (m *Manager) DeleteForwardRule(ctx context.Context, rule *model.ForwardRule) error

DeleteForwardRule 删除转发规则

func (*Manager) GetClient

func (m *Manager) GetClient(nodeID uint) (*Client, error)

GetClient 获取节点的 gost 客户端

func (*Manager) GetNodeStats deprecated

func (m *Manager) GetNodeStats(ctx context.Context, nodeID uint) (*StatsResponse, error)

GetNodeStats 获取节点统计信息

Deprecated: 依赖 client.GetStats(),而 gost v3.2.6 的 REST API 不存在 /api/stats, 调用会一直 404。节点级流量统计请用 GetNodeTrafficTotals(走 Prometheus /metrics)。

func (*Manager) GetNodeTrafficTotals

func (m *Manager) GetNodeTrafficTotals(ctx context.Context, nodeID uint) (map[string]*ServiceTrafficTotals, error)

GetNodeTrafficTotals 通过节点的 Prometheus /metrics 端点汇总该节点上所有 service 的流量, 用于节点级"同步统计",替代已失效的 GetNodeStats(REST /api/stats)。

func (*Manager) GetRuleStats

func (m *Manager) GetRuleStats(ctx context.Context, rule *model.ForwardRule) (*ServiceStats, error)

GetRuleStats 获取规则统计信息

func (*Manager) RegisterNode

func (m *Manager) RegisterNode(node *model.ForwardNode) error

RegisterNode 注册节点(创建客户端)

func (*Manager) SyncAllRules

func (m *Manager) SyncAllRules(ctx context.Context) error

SyncAllRules 同步所有启用的规则到 gost

func (*Manager) SyncRuleToGost

func (m *Manager) SyncRuleToGost(ctx context.Context, rule *model.ForwardRule) error

SyncRuleToGost 同步规则到 gost(用于规则状态变更)

func (*Manager) UnregisterNode

func (m *Manager) UnregisterNode(nodeID uint)

UnregisterNode 注销节点(移除客户端)

func (*Manager) UpdateForwardRule

func (m *Manager) UpdateForwardRule(ctx context.Context, rule *model.ForwardRule) error

UpdateForwardRule 更新转发规则

type SelectorConfig

type SelectorConfig struct {
	Strategy    string `json:"strategy"` // round, rand, hash, failover
	MaxFails    int    `json:"maxFails,omitempty"`
	FailTimeout string `json:"failTimeout,omitempty"`
}

SelectorConfig 选择器配置

type ServiceConfig

type ServiceConfig struct {
	Name      string            `json:"name"`
	Addr      string            `json:"addr"`
	Interface string            `json:"interface,omitempty"`
	Handler   *HandlerConfig    `json:"handler,omitempty"`
	Listener  *ListenerConfig   `json:"listener,omitempty"`
	Forwarder *ForwarderConfig  `json:"forwarder,omitempty"`
	Metadata  map[string]string `json:"metadata,omitempty"`
}

ServiceConfig gost 服务配置

type ServiceEvent

type ServiceEvent struct {
	Time   time.Time `json:"time"`
	Type   string    `json:"type"`
	Status string    `json:"status"`
}

ServiceEvent 服务事件

type ServiceListResponse

type ServiceListResponse struct {
	Count int              `json:"count"`
	List  []*ServiceConfig `json:"list"`
}

ServiceListResponse 服务列表响应

type ServiceStats

type ServiceStats struct {
	Name    string         `json:"name"`
	Addr    string         `json:"addr"`
	Events  []ServiceEvent `json:"events"`
	Current CurrentStats   `json:"current"`
	Total   TotalStats     `json:"total"`
}

ServiceStats 服务统计

type ServiceTrafficTotals

type ServiceTrafficTotals struct {
	InBytes  int64
	OutBytes int64
}

ServiceTrafficTotals 单个 service 在所有 client 上的累计字节数

type StatsResponse

type StatsResponse struct {
	Services []ServiceStats `json:"services"`
}

StatsResponse 统计响应

type TLSConfig

type TLSConfig struct {
	CertFile   string `json:"certFile,omitempty"`
	KeyFile    string `json:"keyFile,omitempty"`
	CAFile     string `json:"caFile,omitempty"`
	ServerName string `json:"serverName,omitempty"`
	Secure     bool   `json:"secure,omitempty"`
}

TLSConfig TLS 配置

type TotalStats

type TotalStats struct {
	Connections int64 `json:"connections"`
	Handled     int64 `json:"handled"`
	InBytes     int64 `json:"inBytes"`
	OutBytes    int64 `json:"outBytes"`
}

TotalStats 总计统计

Jump to

Keyboard shortcuts

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