Documentation
¶
Index ¶
- Constants
- Variables
- func BinaryWrite(raw *bytes.Buffer, v ...string)
- func BuildAddress(host string, port string) string
- func BuildTCPBindAddr(localIP string) net.Addr
- func BuildUDPBindAddr(localIP string) *net.UDPAddr
- func BuildUdpBindAddr(serverIP string, clientIP net.IP) (network string, addr *net.UDPAddr)
- func BytesToNum(b []byte) int
- func BytesToTimestamp(b []byte) int64
- func CalibrateTimeOffset(server string) (time.Duration, error)
- func CheckAuth(r *http.Request, user, passwd string, accountMap, authMap map[string]string) bool
- func CheckAuthWithAccountMap(u, p, user, passwd string, accountMap, authMap map[string]string) bool
- func CheckProxyAuth(r *http.Request, user, passwd string, accountMap, authMap map[string]string) bool
- func ChooseLocalAddrForPeer(selfLocal, peerLocal string) string
- func ContainsFold(s, substr string) bool
- func DealMultiUser(s string) map[string]string
- func DecodeIP(data []byte) net.IP
- func DomainCheck(domain string) bool
- func EncodeIP(ip net.IP) []byte
- func ExtendArrs(arrays ...*[]string) int
- func ExtractHost(input string) string
- func FileExists(name string) bool
- func FixUdpListenAddrForRemote(remoteAddr, localAddr string) (string, string, error)
- func FormatAddress(s string) string
- func GetAppPath() string
- func GetBoolByStr(s string) bool
- func GetCertContent(filePath, header string) (string, error)
- func GetCertType(s string) string
- func GetConfigPath() string
- func GetCustomDNS() string
- func GetEnvMap() map[string]string
- func GetFastAddr(addr string, testType string) (string, error)
- func GetInstallPath() string
- func GetIntNoErrByStr(str string) int
- func GetIpByAddr(host string) string
- func GetLocalUdp4Addr() (*net.UDPAddr, error)
- func GetLocalUdp4IP() (net.IP, error)
- func GetLocalUdp6Addr() (*net.UDPAddr, error)
- func GetLocalUdp6IP() (net.IP, error)
- func GetLocalUdpAddr() (*net.UDPAddr, error)
- func GetLogPath() string
- func GetNpcLogPath() string
- func GetOutboundIP() net.IP
- func GetOutboundIPv4() net.IP
- func GetOutboundIPv6() net.IP
- func GetPath(filePath string) string
- func GetPort(value int) int
- func GetPortByAddr(addr string) int
- func GetPortStrByAddr(addr string) string
- func GetPorts(s string) []int
- func GetRunPath() string
- func GetRunSecs() int64
- func GetRunTime() string
- func GetServerIp(ip string) string
- func GetSni(host string) string
- func GetStartTime() int64
- func GetSyncMapLen(m *sync.Map) int
- func GetTimeNoErrByStr(str string) time.Time
- func GetTmpPath() string
- func GetWriteStr(v ...string) []byte
- func HandleArrEmptyVal(list []string) []string
- func HasIPv6InLocalList(localStr string) bool
- func InIntArr(arr []int, val int) bool
- func InStrArr(arr []string, val string) bool
- func InitPProfByAddr(addr string)
- func IsArrContains(arr []string, val string) bool
- func IsDomain(s string) bool
- func IsPort(p string) bool
- func IsPublicHost(addr string) bool
- func IsPublicIP(ip net.IP) bool
- func IsPublicIPStrict(ip net.IP) bool
- func IsSameIPType(addr1, addr2 string) bool
- func IsTrustedProxy(list, ipStr string) bool
- func IsWindows() bool
- func IsZeroIP(ip net.IP) bool
- func LoadCert(certFile, keyFile string) (tls.Certificate, bool)
- func LoadCertPair(certFile, keyFile string) (certContent, keyContent string, ok bool)
- func Max(values ...int) int
- func Min(values ...int) int
- func NeedsAuth(user, passwd string, accountMap, authMap map[string]string) bool
- func NormalizeIP(ip net.IP) net.IP
- func NormalizeNewlines(s string) string
- func ParseBasicAuth(header string) (user, passwd string, ok bool)
- func ParseIPFromAddr(addr string) net.IP
- func ParseStr(str string) (string, error)
- func PickBestV4V6FromLocalList(localStr string) (bestV4 string, bestV6 string, fallback string)
- func PickEgressIPFor(dstIP net.IP) net.IP
- func RandomBytes(maxLen int) ([]byte, error)
- func ReadAllFromFile(filePath string) ([]byte, error)
- func RemoveArrVal(arr []string, val string) []string
- func RemovePortFromHost(host string) string
- func ResolvePath(path string) string
- func SetCustomDNS(dnsAddr string)
- func SetNtpInterval(d time.Duration)
- func SetNtpServer(server string)
- func SetTimezone(tz string) error
- func SplitAddrAndHost(s string) (addr, host, sni string)
- func SplitCommaAddrList(s string) []string
- func SplitLines(s string) []string
- func SplitServerAndPath(s string) (server, path string)
- func SyncTime()
- func TestLatency(addr string, testType string) (time.Duration, error)
- func TestTcpPort(port int) bool
- func TestUdpPort(port int) bool
- func TimeNow() time.Time
- func TimestampToBytes(ts int64) []byte
- func TrimArr(arr []string) []string
- func ValidateAddr(s string) string
- func ValidatePoW(bits int, parts ...string) bool
Constants ¶
const ( ConnDataSeq = "*#*" // Separator VerifyErr = "vkey" VerifySuccess = "sucs" WorkMain = "main" WorkChan = "chan" WorkVisitor = "vstr" WorkConfig = "conf" WorkRegister = "rgst" WorkSecret = "sert" WorkFile = "file" WorkP2P = "p2pm" WorkP2PSession = "p2sj" WorkStatus = "stus" ResClose = "clse" P2PPunchStart = "p2st" // P2P invitation on the signal connection UpdateRequest = "updt" // update request on the signal connection FlagNewTask = "task" FlagNewConf = "conf" FlagNewHost = "host" ConnAll = "all" ConnTCP = "tcp" ConnUDP = "udp" ConnTLS = "tls" ConnQUIC = "quic" ConnWeb = "web" ConnWS = "ws" ConnWSS = "wss" ConnTest = "TST" ConnAck = "ACK" TOTPSeq = "totp:" // TOTP Separator "Content-Type: text/plain; charset=utf-8\r\n" + "WWW-Authenticate: Basic realm=\"easyProxy\"\r\n" + "\r\n" + "401 Unauthorized" ProxyAuthRequiredBytes = "HTTP/1.1 407 Proxy Authentication Required\r\n" + "Proxy-Authenticate: Basic realm=\"Proxy\"\r\n" + "Content-Length: 0\r\n" + "Connection: close\r\n" + "\r\n" ConnectionFailBytes = "HTTP/1.1 404 Not Found\r\n" + "\r\n" IPv4DNS = "8.8.8.8:53" IPv6DNS = "[2400:3200::1]:53" )
const ( PoolSize = 64 << 10 PoolSizeUdp = 1472 + 200 PoolSizeCopy = 32 << 10 )
Variables ¶
var ( BufPool = newBytePool64K() BufPoolUdp = newBytePoolUDP() BufPoolCopy = newBytePoolCopy() )
var ConfPath string
var DefaultPort = map[string]string{
"tcp": "8024",
"kcp": "8024",
"tls": "8025",
"quic": "8025",
"ws": "80",
"wss": "443",
}
var StartTime = time.Now()
Functions ¶
func BinaryWrite ¶
BinaryWrite Write length and individual byte data Length prevents sticking # Characters are used to separate data
func BuildAddress ¶ added in v0.26.51
func BuildTCPBindAddr ¶ added in v0.34.2
func BuildUDPBindAddr ¶ added in v0.34.2
func BuildUdpBindAddr ¶ added in v0.33.9
func BytesToTimestamp ¶ added in v0.27.0
BytesToTimestamp 8bit
func CalibrateTimeOffset ¶ added in v0.30.0
func CheckAuth ¶
CheckAuth validates the Basic credentials of a request to a reverse-proxied host. It reads Authorization and falls back to Proxy-Authorization only when the request carries no Authorization header at all.
func CheckAuthWithAccountMap ¶
CheckAuthWithAccountMap u current login user p current login passwd user global user passwd global passwd accountMap enable multi user auth
func CheckProxyAuth ¶ added in v0.34.8
func CheckProxyAuth(r *http.Request, user, passwd string, accountMap, authMap map[string]string) bool
CheckProxyAuth validates the Basic credentials of a forward proxy request. It reads Proxy-Authorization and falls back to Authorization only when the request carries no Proxy-Authorization header at all, so a client's own Authorization for the origin server never overrides its proxy credentials.
func ChooseLocalAddrForPeer ¶ added in v0.34.0
ChooseLocalAddrForPeer chooses ONE address from selfLocal to return to peer. Rule: - If both sides contain IPv6 -> return self IPv6 (best, public preferred) - Else -> return self IPv4 (best, public preferred) - Else -> return self IPv6 if any - Else -> return fallback (first valid) or ""
func ContainsFold ¶ added in v0.26.45
func DealMultiUser ¶ added in v0.26.47
func ExtendArrs ¶ added in v0.26.48
func FileExists ¶
FileExists reports whether the named file or directory exists.
func FixUdpListenAddrForRemote ¶ added in v0.34.0
FixUdpListenAddrForRemote makes sure localAddr is a concrete address (not wildcard) and matches the IP family of remoteAddr. Returns (network, fixedLocalAddr).
func FormatAddress ¶
FormatAddress if the s is just a port,return 127.0.0.1:s
func GetAppPath ¶
func GetAppPath() string
GetAppPath Get the absolute path to the running directory
func GetCertContent ¶
func GetCertType ¶ added in v0.29.9
func GetCustomDNS ¶ added in v0.26.46
func GetCustomDNS() string
func GetInstallPath ¶
func GetInstallPath() string
GetInstallPath Different systems get different installation paths
func GetLocalUdp4Addr ¶ added in v0.26.47
func GetLocalUdp4IP ¶ added in v0.34.0
GetLocalUdp4IP returns the preferred local IPv4 egress IP.
func GetLocalUdp6Addr ¶ added in v0.26.47
func GetLocalUdp6IP ¶ added in v0.34.0
GetLocalUdp6IP returns the preferred local IPv6 egress IP.
func GetLocalUdpAddr ¶
GetLocalUdpAddr send this ip forget to get a local udp port
func GetOutboundIP ¶ added in v0.26.46
func GetOutboundIPv4 ¶ added in v0.34.7
func GetOutboundIPv6 ¶ added in v0.29.3
func GetPortStrByAddr ¶ added in v0.29.20
func GetRunPath ¶
func GetRunPath() string
GetRunPath Get the currently selected configuration file directory For non-Windows systems, select the /etc/nps as config directory if exist, or select ./ windows system, select the C:\Program Files\nps as config directory if exist, or select ./
func GetRunSecs ¶ added in v0.29.5
func GetRunSecs() int64
func GetRunTime ¶ added in v0.29.3
func GetRunTime() string
func GetServerIp ¶ added in v0.26.46
func GetStartTime ¶ added in v0.29.5
func GetStartTime() int64
func GetSyncMapLen ¶ added in v0.30.4
GetSyncMapLen get the length of the sync map
func HandleArrEmptyVal ¶ added in v0.26.48
func HasIPv6InLocalList ¶ added in v0.34.0
HasIPv6InLocalList reports whether localStr contains at least one valid IPv6 "[...]:port".
func InitPProfByAddr ¶ added in v0.32.2
func InitPProfByAddr(addr string)
func IsArrContains ¶
func IsPublicHost ¶ added in v0.34.3
func IsPublicIP ¶
func IsPublicIPStrict ¶ added in v0.34.0
IsPublicIPStrict checks if IP is globally routable on the Internet. It excludes RFC1918, loopback, link-local, multicast, unspecified, and also excludes CGNAT / TEST-NET / benchmarking / documentation ranges.
func IsSameIPType ¶ added in v0.26.47
func IsTrustedProxy ¶ added in v0.33.3
func IsWindows ¶
func IsWindows() bool
IsWindows Determine whether the current system is a Windows system?
func LoadCertPair ¶ added in v0.26.48
func NeedsAuth ¶ added in v0.34.8
NeedsAuth reports whether any credential is configured. A username or a password on its own is enough to require authentication.
func NormalizeNewlines ¶ added in v0.34.9
NormalizeNewlines turns the line endings of s, \r\n (Windows), \r (classic Mac) and \n (Unix), into \n, and drops a byte order mark at the start.
func ParseBasicAuth ¶ added in v0.34.8
ParseBasicAuth parses a "Basic <base64(user:pass)>" credential. The scheme is matched case-insensitively and unpadded base64 is accepted.
func ParseIPFromAddr ¶ added in v0.34.0
ParseIPFromAddr parses IP from an "ip:port" (supports "[v6]:port"). Returns nil if cannot parse.
func PickBestV4V6FromLocalList ¶ added in v0.34.0
PickBestV4V6FromLocalList picks best IPv4/IPv6 address from localStr (comma-separated). Rules within each family: - First seen becomes candidate. - If later a "public" address appears and current is not public, replace it. Returns: - bestV4: best IPv4 "ip:port" if any - bestV6: best IPv6 "[ip]:port" if any - fallback: first valid address from list (stable)
func RandomBytes ¶ added in v0.27.0
func ReadAllFromFile ¶
ReadAllFromFile Read file content by file path
func RemoveArrVal ¶
RemoveArrVal remove value from string array
func RemovePortFromHost ¶
RemovePortFromHost return "[2001:db8::1]"
func ResolvePath ¶ added in v0.29.11
func SetCustomDNS ¶ added in v0.26.45
func SetCustomDNS(dnsAddr string)
func SetNtpInterval ¶ added in v0.30.1
func SetNtpServer ¶ added in v0.30.0
func SetNtpServer(server string)
func SetTimezone ¶ added in v0.32.3
func SplitAddrAndHost ¶ added in v0.33.6
func SplitCommaAddrList ¶ added in v0.34.0
SplitCommaAddrList splits "ip:port,ip:port,..." into a de-duplicated list of valid IP:port. - Accepts single item without comma. - Ignores invalid entries. - Keeps first valid one as stable fallback.
func SplitLines ¶ added in v0.34.9
SplitLines splits s into lines ending in \r\n, \r or \n.
func SplitServerAndPath ¶ added in v0.27.0
func TestLatency ¶ added in v0.26.51
func TestTcpPort ¶
TestTcpPort Judge whether the TCP port can open normally
func TestUdpPort ¶
TestUdpPort Judge whether the UDP port can open normally
func TimestampToBytes ¶ added in v0.27.0
TimestampToBytes 8bit
func ValidateAddr ¶ added in v0.30.2
func ValidatePoW ¶ added in v0.29.30
Types ¶
This section is empty.