Documentation
¶
Overview ¶
SPDX-License-Identifier: GPL-3.0-or-later
SPDX-License-Identifier: GPL-3.0-or-later
defaults.go
SPDX-License-Identifier: GPL-3.0-or-later
SPDX-License-Identifier: GPL-3.0-or-later
SPDX-License-Identifier: GPL-3.0-or-later
*
* This file implements a simple job system.
*
* Usage:
* jsys := NewJobSystem(4);
*
* // define your job struct
* type MyJob struct {...}
*
* // implement JobExec() for your type
* func (j MyJob) JobExec() {
* ...
- } *
- job := MyJob{ID: i};
- // spawn your jobs, maybe in a loop
- // Spawn() is a non-blocking call in general,
- // only becomes blocking when the maximum workers count,
- // in this example 4, jobs is exceeded,
- // Or it equals to 1 (one job at time).
- jsys.Spawn(job); *
- At the end, wait for them to finish.
- jsys.Wait();
Index ¶
- Constants
- Variables
- func GetFormatByExtension(filename string) string
- func Test_Max_Concurrency(n int)
- type ConnectivityTester_I
- type IP_Contester
- type Job
- type JobSystem
- type JobWrapper
- type Simple_Contester
- type TestResult
- type V2utils
- func (v2 V2utils) Apply_URL(url string) error
- func (v2 *V2utils) Apply_template(file_path string) error
- func (v2 *V2utils) Apply_template_byio(rio io.Reader) error
- func (v2 *V2utils) Apply_template_bystr(template string) error
- func (v2 V2utils) CFG_Out(w io.Writer, indention bool) error
- func (v2 V2utils) Convert_conf2url() (string, error)
- func (v2 V2utils) CustomDial(ctx context.Context, network, addr string) (xnet.Conn, error)
- func (v2 *V2utils) Exec_Xray() error
- func (v2 *V2utils) HasInboundConfig() bool
- func (v2 *V2utils) HasTemplate() bool
- func (v2 *V2utils) Init_Outbound_byURL(url string) error
- func (v2 V2utils) Kill_Xray()
- func (v2 *V2utils) Run_Xray() error
- func (v2 *V2utils) SetDefaultInboundConfig()
- func (v2 *V2utils) SetLogLevel(level int)
- func (v2 *V2utils) Test_CFG(path string, tester ConnectivityTester_I, callback func(error, *TestResult))
- func (v2 *V2utils) Test_URL(url string, tester ConnectivityTester_I, callback func(error, *TestResult))
- func (v2 *V2utils) Test_Wait()
- func (v2 *V2utils) UnsetTemplate()
Constants ¶
const ( V2_Suppress_Logs = iota V2_Warning_Logs V2_Verbose_Logs )
const ( // Default template for run command DEF_Run_Template = `` /* 266-byte string literal not displayed */ // Default template for test command DEF_Test_Template = ` { "log": {"loglevel": "none"} }` )
const ( // Default test endpoint, does not report IP Test_Endpoint_goog = "http://www.google.com" // API to report IP address Test_Endpoint_ip1 = "http://api4.ipify.org" Test_Endpoint_ip2 = "http://v4.api.ipinfo.io/ip" Test_Endpoint_ip3 = "http://check-host.net/ip" Test_Endpoint_ip4 = "http://ipv4.icanhazip.com" MAX_ALLOWED_WORKERS = 16 )
const MAX_WORKERS_COUNT = 4
Variables ¶
var ( // Timeout to fail a test TestTimeout time.Duration = 10 * time.Second // Maximum number of endpoints to test TestCount int = 3 // Returned when max allowed tests failed Not_Responding_Error = errors.New("Not responding") )
var ( // Simple report of duration and connectivity SimpleTester = &Simple_Contester{ endpoints: []string{ Test_Endpoint_goog, Test_Endpoint_ip1, Test_Endpoint_ip2, Test_Endpoint_ip3, Test_Endpoint_ip4, }, } // Advanced tester, also reports IP address AdvancedTester = &IP_Contester{ endpoints: []string{ Test_Endpoint_ip1, Test_Endpoint_ip2, Test_Endpoint_ip3, Test_Endpoint_ip4, }, } )
Connectivity testers
Functions ¶
func GetFormatByExtension ¶
func Test_Max_Concurrency ¶
func Test_Max_Concurrency(n int)
Types ¶
type ConnectivityTester_I ¶
type ConnectivityTester_I interface {
Test(v2 *V2utils) (error, *TestResult)
}
type IP_Contester ¶
type IP_Contester struct {
// contains filtered or unexported fields
}
Connectivity tester with IP report
func (*IP_Contester) Test ¶
func (tester *IP_Contester) Test(v2 *V2utils) (error, *TestResult)
type JobSystem ¶
type JobSystem struct {
// contains filtered or unexported fields
}
func NewJobSystem ¶
func (*JobSystem) Wait_and_Stop ¶
func (js *JobSystem) Wait_and_Stop()
type JobWrapper ¶
type JobWrapper struct {
ID int
// contains filtered or unexported fields
}
type Simple_Contester ¶
type Simple_Contester struct {
// contains filtered or unexported fields
}
Simple connectivity tester
func (*Simple_Contester) Test ¶
func (tester *Simple_Contester) Test(v2 *V2utils) (error, *TestResult)
type TestResult ¶
type V2utils ¶
type V2utils struct {
CFG *conf.Config
Xray_instance *core.Instance // xray-core client instance
// contains filtered or unexported fields
}
func (*V2utils) Apply_template ¶
Applies the template v2.template_path to v2.CFG
func (*V2utils) Apply_template_bystr ¶
func (V2utils) Convert_conf2url ¶
URL generator
func (V2utils) CustomDial ¶
This will utilize the xray-core Dial function (DialContext compatible)
func (*V2utils) HasInboundConfig ¶
func (*V2utils) HasTemplate ¶
func (*V2utils) Init_Outbound_byURL ¶
Initializes @v2.CFG.OutboundConfig by the provided proxy URL @url
func (V2utils) Kill_Xray ¶
func (v2 V2utils) Kill_Xray()
Do NOT use v2.Xray_instance after this call
func (*V2utils) SetDefaultInboundConfig ¶
func (v2 *V2utils) SetDefaultInboundConfig()
func (*V2utils) SetLogLevel ¶
func (*V2utils) Test_CFG ¶
func (v2 *V2utils) Test_CFG(path string, tester ConnectivityTester_I, callback func(error, *TestResult))
Tests a config file @path
func (*V2utils) Test_URL ¶
func (v2 *V2utils) Test_URL(url string, tester ConnectivityTester_I, callback func(error, *TestResult))
Tests a minimal config generated by DEF_Test_Template It will not create any local listening proxy, instead it passes a simple HTTP request through the running xray-core instance @v2.Xray_instance.
func (*V2utils) UnsetTemplate ¶
func (v2 *V2utils) UnsetTemplate()