utils

package
v0.0.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	IDENTIFIER = "Speed"
)
View Source

Variables

View Source
var BRAND string
View Source
var BUILDCOUNT string
View Source
var BUILDTOKEN string
View Source
var COMMIT string
View Source
var COMPILATIONTIME string
View Source
var MaxMindDBs []*maxminddb.Reader
View Source
var VERSION = "4.5.0"
View Source
var VerboseLevel = LTWarn

Functions

func DNSLookuper

func DNSLookuper(addr string, queryServers []string) []net.IP

queryServer = "8.8.8.8:53"

func Download

func Download(url string) (*http.Response, error)

func DownloadBytes

func DownloadBytes(url string) ([]byte, error)

func FindAndExtract

func FindAndExtract(gzipReader io.Reader, filters ...regexp.Regexp) (map[string][]byte, error)

func LoadMaxMindDB

func LoadMaxMindDB(pathList string) error

func LogTypeToStr

func LogTypeToStr(lt LogType) string

func LookupIPv46

func LookupIPv46(addr string, retry int, queryServers []string) *interfaces.IPStacks

func MakeSysChan

func MakeSysChan() chan os.Signal

func PrintLogUnit

func PrintLogUnit(lu *LogUnit)

func RandomUUID

func RandomUUID() string

func ReadFile added in v0.0.4

func ReadFile(path string) string

func SignRequest

func SignRequest(token string, req *interfaces.SlaveRequest) string

func SignRequestOld

func SignRequestOld(token string, req *interfaces.SlaveRequestV1) string

func StandardDeviation added in v0.0.4

func StandardDeviation(data []float64) float64

计算标准差

func ToJSON

func ToJSON(a any) string

func WrapError

func WrapError(desc string, fn func() error, onError ...func(err error)) (err error)

func WrapErrorPure

func WrapErrorPure(desc string, erro any) (err error)

Types

type GlobalConfig

type GlobalConfig struct {
	Token            string
	Binder           string
	WhiteList        []string
	AllowIPs         []string
	SpeedLimit       uint64
	TaskLimit        uint
	PauseSecond      uint
	ConnTaskTreading uint
	MiaoKoSignedTLS  bool
	NoSpeedFlag      bool
	MaxmindDB        string
	Path             string
}
var GCFG GlobalConfig

func (*GlobalConfig) InWhiteList

func (gc *GlobalConfig) InWhiteList(invoker string) bool

func (*GlobalConfig) SignRequest

func (gc *GlobalConfig) SignRequest(req *interfaces.SlaveRequest) string

func (*GlobalConfig) ValidateWSPath added in v0.0.4

func (gc *GlobalConfig) ValidateWSPath(path string) bool

func (*GlobalConfig) VerifyRequest

func (gc *GlobalConfig) VerifyRequest(req *interfaces.SlaveRequest) bool

type LogType

type LogType int
const (
	LTDebug LogType = iota
	LTLog
	LTInfo
	LTWarn
	LTError
)

type LogUnit

type LogUnit struct {
	Type    LogType
	Data    string
	Time    int64
	TimeStr string
}

func DBase

func DBase(t LogType, a ...interface{}) *LogUnit

func DBasef

func DBasef(t LogType, format string, a ...interface{}) *LogUnit

func DBlackhole

func DBlackhole(a ...interface{}) *LogUnit

func DBlackholef

func DBlackholef(format string, a ...interface{}) *LogUnit

func DError

func DError(a ...interface{}) *LogUnit

func DErrorE

func DErrorE(err error, a ...interface{}) *LogUnit

func DErrorEf

func DErrorEf(err error, format string, a ...interface{}) *LogUnit

func DErrorf

func DErrorf(format string, a ...interface{}) *LogUnit

func DInfo

func DInfo(a ...interface{}) *LogUnit

func DInfof

func DInfof(format string, a ...interface{}) *LogUnit

func DLog

func DLog(a ...interface{}) *LogUnit

func DLogf

func DLogf(format string, a ...interface{}) *LogUnit

func DWarn

func DWarn(a ...interface{}) *LogUnit

func DWarnf

func DWarnf(format string, a ...interface{}) *LogUnit

func (*LogUnit) Error

func (l *LogUnit) Error() error

type MMDBResult

type MMDBResult struct {
	IP      string
	Reverse string
	Via     string

	ASN    int    `maxminddb:"autonomous_system_number"`
	ASNOrg string `maxminddb:"autonomous_system_organization"`

	City struct {
		GeoNameID int `maxminddb:"geoname_id"`
		Names     struct {
			EN string `maxminddb:"en"`
			JA string `maxminddb:"ja"`
			ZH string `maxminddb:"zh-CN"`
		} `maxminddb:"names"`
	} `maxminddb:"city"`

	Continent struct {
		Code      string `maxminddb:"code"`
		GeoNameID int    `maxminddb:"geoname_id"`
		Names     struct {
			EN string `maxminddb:"en"`
			JA string `maxminddb:"ja"`
			ZH string `maxminddb:"zh-CN"`
		} `maxminddb:"names"`
	} `maxminddb:"continent"`

	Country struct {
		ISOCode   string `maxminddb:"iso_code"`
		GeoNameID int    `maxminddb:"geoname_id"`
		Names     struct {
			EN string `maxminddb:"en"`
			JA string `maxminddb:"ja"`
			ZH string `maxminddb:"zh-CN"`
		} `maxminddb:"names"`
	} `maxminddb:"country"`

	RegisteredCountry struct {
		ISOCode   string `maxminddb:"iso_code"`
		GeoNameID int    `maxminddb:"geoname_id"`
		Names     struct {
			EN string `maxminddb:"en"`
			JA string `maxminddb:"ja"`
			ZH string `maxminddb:"zh-CN"`
		} `maxminddb:"names"`
	} `maxminddb:"registered_country"`

	Location struct {
		Accuracy  int     `maxminddb:"accuracy_radius"`
		Latitude  float32 `maxminddb:"latitude"`
		Longitude float32 `maxminddb:"longitude"`
		TimeZone  string  `maxminddb:"time_zone"`
	} `maxminddb:"location"`
}

func QueryMaxMindDB

func QueryMaxMindDB(rawIp string) *MMDBResult

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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