machine

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package machine 定义一个 可以直接运行的有限状态机;这个机器可以直接被可执行文件或者动态库所使用.

machine把所有运行代理所需要的代码包装起来,对外像一个黑盒子。

关键点是不使用任何静态变量,所有变量都放在machine中。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiServerConf

type ApiServerConf struct {
	EnableApiServer bool   `toml:"enable"`
	PlainHttp       bool   `toml:"plain"`
	KeyFile         string `toml:"key"`
	CertFile        string `toml:"cert"`
	PathPrefix      string `toml:"prefix"`
	AdminPass       string `toml:"admin_pass"`
	Addr            string `toml:"addr"`
}

func NewApiServerConf

func NewApiServerConf() (ac ApiServerConf)

内含默认值的 ApiServerConf

func (*ApiServerConf) SetNonDefault

func (c *ApiServerConf) SetNonDefault(ref *ApiServerConf)

若 ref 里有与默认值不同的项且字符串不为空, 将该项的值赋值给 c

func (*ApiServerConf) SetupFlags

func (asc *ApiServerConf) SetupFlags(fs *flag.FlagSet)

type AppConf

type AppConf struct {
	LogLevel          *int    `toml:"loglevel"` //需要为指针, 否则无法判断0到底是未给出的默认值还是 显式声明的0
	LogFile           *string `toml:"logfile"`
	DefaultUUID       string  `toml:"default_uuid"`
	MyCountryISO_3166 string  `toml:"mycountry"` //加了mycountry后,就会自动按照geoip分流,也会对顶级域名进行国别分流

	NoReadV bool `toml:"noreadv"`

	UDP_timeout *int `toml:"udp_timeout"` //分钟

	DialTimeoutSeconds *int `toml:"dial_timeout"` //秒
	ReadTimeoutSeconds *int `toml:"read_timeout"` //秒

	GeoipFile     *string `toml:"geoip_file"`
	GeositeFolder *string `toml:"geosite_folder"`
}

AppConf 配置App级别的配置

func GetAppConfByCurrentState

func GetAppConfByCurrentState() (ac AppConf)

func (*AppConf) Setup

func (ac *AppConf) Setup()

type M

type M struct {
	sync.RWMutex
	v2ray_simple.GlobalInfo

	AppConf

	ApiServerConf

	CmdApiServerConf ApiServerConf

	DefaultOutClient proxy.Client
	// contains filtered or unexported fields
}

func New

func New() *M

func (*M) AddToggleCallback

func (m *M) AddToggleCallback(f func(int))

func (*M) AddUpdatedCallback

func (m *M) AddUpdatedCallback(f func())

func (*M) ClientCount

func (m *M) ClientCount() int

func (*M) DefaultClientUsable

func (m *M) DefaultClientUsable() bool

具有 DefaultOutClient 且不是direct也不是reject; 一般表明该通向一个外界代理

func (*M) DumpStandardConf

func (m *M) DumpStandardConf() (sc proxy.StandardConf)

从当前内存中的配置 导出 proxy.StandardConf

func (*M) DumpVSConf

func (m *M) DumpVSConf() (vc VSConf)

从当前内存中的配置 导出 VSConf

func (*M) HasProxyRunning

func (m *M) HasProxyRunning() bool

func (*M) HotDeleteClient

func (m *M) HotDeleteClient(index int)

delete and stop the client

func (*M) HotDeleteServer

func (m *M) HotDeleteServer(index int)

delete and close the server

func (*M) HotLoadDialUrl

func (m *M) HotLoadDialUrl(theUrlStr string, format int) error

func (*M) HotLoadListenUrl

func (m *M) HotLoadListenUrl(theUrlStr string, format int) error

func (*M) IsApiServerRunning

func (m *M) IsApiServerRunning() bool

func (*M) IsRunning

func (m *M) IsRunning() bool

func (*M) LoadConfig

func (m *M) LoadConfig(configFileName, listenURL, dialURL string) (confMode int, err error)

先检查configFileName是否存在,存在就尝试加载文件到 standardConf , 否则尝试通过 listenURL, dialURL 参数 创建urlConf. 若使用url, 自动加载进机器; 若为toml, 需要手动调用 SetupListenAndRoute 和 SetupDial

func (*M) LoadConfigByTomlBytes

func (m *M) LoadConfigByTomlBytes(bs []byte) (err error)

func (*M) LoadDialConf

func (m *M) LoadDialConf(conf []*proxy.DialConf) (ok bool)

func (*M) LoadListenConf

func (m *M) LoadListenConf(conf []*proxy.ListenConf, hot bool) (ok bool)

add; when hot=true, listen the server

func (*M) LoadStandardConf

func (m *M) LoadStandardConf()

func (*M) ParseFallbacksAtSymbol

func (m *M) ParseFallbacksAtSymbol(fs []*httpLayer.FallbackConf)

将fallback配置中的@转化成实际对应的server的地址

func (*M) PrintAllState

func (m *M) PrintAllState(w io.Writer)

func (*M) PrintAllStateForHuman

func (m *M) PrintAllStateForHuman(w io.Writer)

mimic PrintAllState

func (*M) RemoveAllClient

func (m *M) RemoveAllClient()

func (*M) RemoveAllServer

func (m *M) RemoveAllServer()

func (*M) ServerCount

func (m *M) ServerCount() int

func (*M) SetDefaultDirectClient

func (m *M) SetDefaultDirectClient()

func (*M) SetupApiConf

func (m *M) SetupApiConf()

融合 CmdApiServerConf 和 TomlApiServerConf, CmdApiServerConf 的值会覆盖 TomlApiServerConf

func (*M) SetupDial

func (m *M) SetupDial()

func (*M) SetupListenAndRoute

func (m *M) SetupListenAndRoute()

func (*M) Start

func (m *M) Start()

运行配置 以及 apiServer

func (*M) Stop

func (m *M) Stop()

Stop不会停止ApiServer

func (*M) TryRunApiServer

func (m *M) TryRunApiServer()

非阻塞,如果运行成功则 apiServerRunning 会被设为 true

type VSConf

type VSConf struct {
	AppConf       *AppConf       `toml:"app"`
	ApiServerConf *ApiServerConf `toml:"apiServer"`
	proxy.StandardConf
}

VS 标准toml文件格式 由 proxy.StandardConf , ApiServerConf, AppConf 3部分组成

func LoadVSConfFromBs

func LoadVSConfFromBs(bs []byte) (vsConf VSConf, err error)

Jump to

Keyboard shortcuts

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