Documentation ¶
Overview ¶
Package machine 定义一个 可以直接运行的有限状态机;这个机器可以直接被可执行文件或者动态库所使用.
machine把所有运行代理所需要的代码包装起来,对外像一个黑盒子。
关键点是不使用任何静态变量,所有变量都放在machine中。
Index ¶
- type ApiServerConf
- type AppConf
- type M
- func (m *M) AddToggleCallback(f func(int))
- func (m *M) AddUpdatedCallback(f func())
- func (m *M) ClientCount() int
- func (m *M) DefaultClientUsable() bool
- func (m *M) DumpStandardConf() (sc proxy.StandardConf)
- func (m *M) DumpVSConf() (vc VSConf)
- func (m *M) HasProxyRunning() bool
- func (m *M) HotDeleteClient(index int)
- func (m *M) HotDeleteServer(index int)
- func (m *M) HotLoadDialUrl(theUrlStr string, format int) error
- func (m *M) HotLoadListenUrl(theUrlStr string, format int) error
- func (m *M) IsApiServerRunning() bool
- func (m *M) IsRunning() bool
- func (m *M) LoadConfig(configFileName, listenURL, dialURL string) (confMode int, err error)
- func (m *M) LoadConfigByTomlBytes(bs []byte) (err error)
- func (m *M) LoadDialConf(conf []*proxy.DialConf) (ok bool)
- func (m *M) LoadListenConf(conf []*proxy.ListenConf, hot bool) (ok bool)
- func (m *M) LoadStandardConf()
- func (m *M) ParseFallbacksAtSymbol(fs []*httpLayer.FallbackConf)
- func (m *M) PrintAllState(w io.Writer)
- func (m *M) PrintAllStateForHuman(w io.Writer)
- func (m *M) RemoveAllClient()
- func (m *M) RemoveAllServer()
- func (m *M) ServerCount() int
- func (m *M) SetDefaultDirectClient()
- func (m *M) SetupApiConf()
- func (m *M) SetupDial()
- func (m *M) SetupListenAndRoute()
- func (m *M) Start()
- func (m *M) Stop()
- func (m *M) TryRunApiServer()
- type VSConf
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 (*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)
type M ¶
type M struct { sync.RWMutex v2ray_simple.GlobalInfo AppConf ApiServerConf CmdApiServerConf ApiServerConf DefaultOutClient proxy.Client // contains filtered or unexported fields }
func (*M) AddToggleCallback ¶
func (*M) AddUpdatedCallback ¶
func (m *M) AddUpdatedCallback(f func())
func (*M) ClientCount ¶
func (*M) DefaultClientUsable ¶
具有 DefaultOutClient 且不是direct也不是reject; 一般表明该通向一个外界代理
func (*M) DumpStandardConf ¶
func (m *M) DumpStandardConf() (sc proxy.StandardConf)
从当前内存中的配置 导出 proxy.StandardConf
func (*M) HasProxyRunning ¶
func (*M) IsApiServerRunning ¶
func (*M) LoadConfig ¶
先检查configFileName是否存在,存在就尝试加载文件到 standardConf , 否则尝试通过 listenURL, dialURL 参数 创建urlConf. 若使用url, 自动加载进机器; 若为toml, 需要手动调用 SetupListenAndRoute 和 SetupDial
func (*M) LoadConfigByTomlBytes ¶
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) PrintAllStateForHuman ¶
mimic PrintAllState
func (*M) RemoveAllClient ¶
func (m *M) RemoveAllClient()
func (*M) RemoveAllServer ¶
func (m *M) RemoveAllServer()
func (*M) ServerCount ¶
func (*M) SetDefaultDirectClient ¶
func (m *M) SetDefaultDirectClient()
func (*M) SetupApiConf ¶
func (m *M) SetupApiConf()
融合 CmdApiServerConf 和 TomlApiServerConf, CmdApiServerConf 的值会覆盖 TomlApiServerConf
func (*M) SetupListenAndRoute ¶
func (m *M) SetupListenAndRoute()
type VSConf ¶
type VSConf struct { AppConf *AppConf `toml:"app"` ApiServerConf *ApiServerConf `toml:"apiServer"` proxy.StandardConf }
VS 标准toml文件格式 由 proxy.StandardConf , ApiServerConf, AppConf 3部分组成