agent

package
v0.0.0-...-6d0c0f3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACTION_REG      = "register"
	AGENT_PKG_SIZE  = 4096
	AGENT_HEAD_SIZE = 4
	AGENT_PEER_SIZE = 16

	PROXY_MAGIC         = "CGTW"
	PROXY_FLAG_DEST_SVR = 0x01
	PROXY_FLAG_AUTH_REQ = 0x02
	PROXY_FLAG_AUTH_SYN = 0x04
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AcceptClientConnect

type AcceptClientConnect func(chan AgentStream)

type ActionProxy

type ActionProxy struct {
	Success interface{} `json:"success"`
	Type    string      `json:"type"` // 一般是json
	Action  string      `json:"action"`
	Data    ProxyInfo   `json:"data"`
}

func (*ActionProxy) IsSuccess

func (a *ActionProxy) IsSuccess() bool

type Agent

type Agent struct {
	//基础网络连接
	NetConn net.PacketConn
	//接入的会话列表
	Socket *Socket
	//当前代理的远程地址
	RemoteAddress net.Addr
	//当前主机的代理配置信息
	Proxy  *ProxyInfo
	Server *server.Server
	Config *Config
}

func NewAgent

func NewAgent(addr string, idx uint32, flag byte, config *Config) (*Agent, error)

NewAgent 创建新的客户端代理

func NewAgentService

func NewAgentService(conn net.PacketConn, proxyAddr net.Addr, idx uint32, flag byte, config *Config) (*Agent, error)

NewAgentService 创建新的代理服务,支持客户端和服务端

type AgentMessageCallbackFunc

type AgentMessageCallbackFunc func(int, string)

type AgentStream

type AgentStream struct {
	Info   *network.StreamInfo
	Stream *quic.Stream
	Server *server.Server
}

type Auth

type Auth struct {
	Ts   int64  `json:"t"`
	Ver  string `json:"v"` // 客户端的版本号
	Sign string `json:"s"` // 客户端的签名,用于服务端校验客户端的合法性
}

type Config

type Config struct {
	Id       int64
	MgrAddr  string           `json:"mgr_addr"`
	Hearts   int              `json:"hearts"`
	Data     utils.JsonObject `json:"data"`
	Version  string           `json:"version" default:"1"`
	SignSalt string           `json:"sign_salt" required:"true"`
}

type ManagePlatform

type ManagePlatform struct {
	//用于串联代理中心和主机之间的通讯
	AgentStreamChannel chan AgentStream

	framework.CloseableObject
	Agents map[int]*Agent
	// contains filtered or unexported fields
}

func NewManagePlatform

func NewManagePlatform(cfg *Config) *ManagePlatform

func (*ManagePlatform) ConnectToPlatform

func (mgr *ManagePlatform) ConnectToPlatform()

func (*ManagePlatform) GetServer

func (mgr *ManagePlatform) GetServer(clientId string) *server.Server

func (*ManagePlatform) GetServerSocket

func (mgr *ManagePlatform) GetServerSocket(clientId string) *network.Socket

func (*ManagePlatform) Hearts

func (mgr *ManagePlatform) Hearts()

func (*ManagePlatform) ListenAgentConnect

func (mgr *ManagePlatform) ListenAgentConnect(onAcceptSocket, onDisconnect network.SocketCallbackFunc) error

func (*ManagePlatform) OnClosed

func (mgr *ManagePlatform) OnClosed() error

func (*ManagePlatform) OnClosing

func (mgr *ManagePlatform) OnClosing() bool

type PlatformActionInfo

type PlatformActionInfo struct {
	Action string           `json:"action"`
	From   string           `json:"from"`
	Info   utils.JsonObject `json:"info"`
}

PlatformActionInfo 连接管理平台的信息

type ProxyInfo

type ProxyInfo struct {
	ProxyIp           string `json:"proxy_ip"`
	ProxyPort         string `json:"proxy_port"`
	ProxyExternalIp   string `json:"proxy_external_ip"`   //管理平台的外网ip
	ProxyExternalPort string `json:"proxy_external_port"` //管理平台的外网端口
	ProxyAddr         string //实际使用的地址
	Idx               int    `json:"idx"`
	AllowExternal     bool   `json:"allow_external" default:"false"` //是否允许外网连接
}

func GetProxy

func GetProxy(req *Requst) (*ProxyInfo, error)

type Requst

type Requst struct {
	MgrAddr string `json:"mgr_addr"`  // 管理平台的地址
	Token   string `json:"token"`     // 管理平台的token
	DevId   string `json:"dev_id"`    // 管理平台的dev_id
	ProxyId string `json:"proxy_id"`  // 管理平台的proxy_id
	Proxy   bool   `json:"proxy"`     // 是否代理
	CliId   string `json:"client_id"` // 客户端ID
	NetType string // 网络类型
	SvcType string // 服务地址
	SvcAddr string `json:"service"`  // 目标地址
	LoAddr  string `json:"lo_addr"`  // 本地监听地址,此时需要设置 up_buf down_buf
	UpBuf   int    `json:"up_buf"`   // TCP的上行缓冲区大小,默认64KB,此大小会影响吞吐、延迟
	DownBuf int    `json:"down_buf"` // TCP的下行缓冲区大小,默认64KB,此大小会影响吞吐、延迟
}

type Socket

type Socket struct {
	Conn      net.PacketConn
	ReadData  []byte
	WriteData []byte
	Idx       uint32

	io.Closer
}

Socket 用于包装代理需要的头,实现了 net.PacketConn的所有方法,可以被用于quic的监听

func (*Socket) Close

func (a *Socket) Close() error

func (*Socket) LocalAddr

func (a *Socket) LocalAddr() net.Addr

func (*Socket) ReadFrom

func (a *Socket) ReadFrom(p []byte) (int, net.Addr, error)

func (*Socket) SetDeadline

func (a *Socket) SetDeadline(t time.Time) error

func (*Socket) SetReadDeadline

func (a *Socket) SetReadDeadline(t time.Time) error

func (*Socket) SetWriteDeadline

func (a *Socket) SetWriteDeadline(t time.Time) error

func (*Socket) WriteTo

func (a *Socket) WriteTo(p []byte, addr net.Addr) (int, error)

Jump to

Keyboard shortcuts

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