pkg

package
v0.0.0-...-0c5e3db Latest Latest
Warning

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

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

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

View Source
const (
	V2_Suppress_Logs = iota
	V2_Warning_Logs
	V2_Verbose_Logs
)
View Source
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"}
         }`
)
View Source
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
)
View Source
const MAX_WORKERS_COUNT = 4

Variables

View Source
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")
)
View Source
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 GetFormatByExtension(filename string) string

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 Job

type Job interface {
	JobExec()
}

type JobSystem

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

func NewJobSystem

func NewJobSystem(maxWorkers int) *JobSystem

func (*JobSystem) Spawn

func (js *JobSystem) Spawn(job Job) error

func (*JobSystem) Stop

func (js *JobSystem) Stop()

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 TestResult struct {
	IP       string
	Duration int64
}

type V2utils

type V2utils struct {
	CFG *conf.Config

	Xray_instance *core.Instance // xray-core client instance
	// contains filtered or unexported fields
}

func (V2utils) Apply_URL

func (v2 V2utils) Apply_URL(url string) error

func (*V2utils) Apply_template

func (v2 *V2utils) Apply_template(file_path string) error

Applies the template v2.template_path to v2.CFG

func (*V2utils) Apply_template_byio

func (v2 *V2utils) Apply_template_byio(rio io.Reader) error

func (*V2utils) Apply_template_bystr

func (v2 *V2utils) Apply_template_bystr(template string) error

func (V2utils) CFG_Out

func (v2 V2utils) CFG_Out(w io.Writer, indention bool) error

Makes json output of v2.CFG, on @w

func (V2utils) Convert_conf2url

func (v2 V2utils) Convert_conf2url() (string, error)

URL generator

func (V2utils) CustomDial

func (v2 V2utils) CustomDial(ctx context.Context, network, addr string) (xnet.Conn, error)

This will utilize the xray-core Dial function (DialContext compatible)

func (*V2utils) Exec_Xray

func (v2 *V2utils) Exec_Xray() error

Run_Xray (blocking)

func (*V2utils) HasInboundConfig

func (v2 *V2utils) HasInboundConfig() bool

func (*V2utils) HasTemplate

func (v2 *V2utils) HasTemplate() bool

func (*V2utils) Init_Outbound_byURL

func (v2 *V2utils) Init_Outbound_byURL(url string) error

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) Run_Xray

func (v2 *V2utils) Run_Xray() error

Runs xray-core instance (non-blocking)

func (*V2utils) SetDefaultInboundConfig

func (v2 *V2utils) SetDefaultInboundConfig()

func (*V2utils) SetLogLevel

func (v2 *V2utils) SetLogLevel(level int)

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) Test_Wait

func (v2 *V2utils) Test_Wait()

func (*V2utils) UnsetTemplate

func (v2 *V2utils) UnsetTemplate()

Jump to

Keyboard shortcuts

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