utils

package
v0.0.0-...-70d54de Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Byte = 1.0 << (10 * iota)
	Kilobyte
	Megabyte
	Gigabyte
	Terabyte
)

Variables

This section is empty.

Functions

func ConvBandwidth

func ConvBandwidth(bw interface{}) (uint64, error)

ConvBandwidth handles both string and int types for bandwidth. When using string, it will be parsed as a bandwidth string with units. When using int, it will be parsed as a raw bandwidth in bytes per second. It does NOT support float types.

func Merge

func Merge(a, b []byte) []byte

func PrintQR

func PrintQR(str string)

func ReadLength

func ReadLength(header []byte) int

ReadLength []byte length to int length

func SplitRead

func SplitRead(stream io.Reader, expectLen int, packet []byte) (int, error)

func StringToBps

func StringToBps(s string) (uint64, error)

StringToBps converts a string to a bandwidth value in bytes per second. E.g. "100 Mbps", "512 kbps", "1g" are all valid.

func WriteLength

func WriteLength(header []byte, length int)

Types

type GeoIPLoader

type GeoIPLoader struct {
	Filename        string
	DownloadFunc    func(filename, url string) // Called when downloading the GeoIP database.
	DownloadErrFunc func(err error)            // Called when downloading the GeoIP database succeeds/fails.
	// contains filtered or unexported fields
}

GeoIPLoader provides the on-demand GeoIP database loading function required by the ACL engine.

func (*GeoIPLoader) Load

func (l *GeoIPLoader) Load() *geoip2.Reader

type UpdateChecker

type UpdateChecker struct {
	CurrentVersion string
	Platform       string
	Architecture   string
	Channel        string
	Side           string
	Client         *http.Client
}

func NewClientUpdateChecker

func NewClientUpdateChecker(currentVersion, platform, architecture, channel string, hyClient client.Client) *UpdateChecker

NewClientUpdateChecker ensures that update checks are routed through a HyClient, not being sent directly. This safeguard is CRITICAL, especially in scenarios where users use Hysteria to bypass censorship. Making direct HTTPS requests to the API endpoint could be easily spotted by censors (through SNI, for example), and could serve as a signal to identify and penalize Hysteria users.

func NewServerUpdateChecker

func NewServerUpdateChecker(currentVersion, platform, architecture, channel string) *UpdateChecker

func (*UpdateChecker) Check

func (uc *UpdateChecker) Check() (*UpdateResponse, error)

type UpdateResponse

type UpdateResponse struct {
	HasUpdate     bool   `json:"update"`
	LatestVersion string `json:"lver"`
	URL           string `json:"url"`
	Urgent        bool   `json:"urgent"`
}

Jump to

Keyboard shortcuts

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