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 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 FetchExternalIp() 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 GetExtFromPath(path string) string
- func GetExternalIp() string
- func GetFastAddr(addr string, testType string) (string, error)
- func GetHostByName(hostname string) string
- func GetInstallPath() string
- func GetIntNoErrByStr(str string) int
- func GetIntranetIp() string
- 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 GetMatchingLocalAddr(remoteAddr, localAddr string) (string, error)
- 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 GetServerIpByClientIp(clientIp net.IP) string
- func GetSni(host string) string
- func GetStartTime() int64
- func GetStrByBool(b bool) string
- 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 IsBlackIp(ipPort, vkey string, blackIpList []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 IsValidIP(ip 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 NormalizeIP(ip net.IP) net.IP
- func ParseIPFromAddr(addr string) net.IP
- func ParseProxyACLEntries(raw string) []string
- 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 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 TimeOffset() time.Duration
- func TimestampToBytes(ts int64) []byte
- func TrimArr(arr []string) []string
- func ValidateAddr(s string) string
- func ValidatePoW(bits int, parts ...string) bool
- type Addr
- type NetPackager
- type ProxyACL
- type UDPDatagram
- type UDPHeader
Constants ¶
const ( CONN_DATA_SEQ = "*#*" // Separator VERIFY_EER = "vkey" VERIFY_SUCCESS = "sucs" WORK_MAIN = "main" WORK_CHAN = "chan" WORK_VISITOR = "vstr" WORK_CONFIG = "conf" WORK_REGISTER = "rgst" WORK_SECRET = "sert" WORK_FILE = "file" WORK_P2P = "p2pm" WORK_P2P_VISITOR = "p2pv" WORK_P2P_PROVIDER = "p2pp" WORK_P2P_CONNECT = "p2pc" WORK_P2P_SUCCESS = "p2ps" WORK_P2P_END = "p2pe" WORK_P2P_LAST = "p2pl" WORK_STATUS = "stus" RES_MSG = "msg0" RES_CLOSE = "clse" NEW_UDP_CONN = "udpc" // p2p udp conn NEW_TASK = "task" NEW_CONF = "conf" NEW_HOST = "host" CONN_ALL = "all" CONN_TCP = "tcp" CONN_UDP = "udp" CONN_KCP = "kcp" CONN_TLS = "tls" CONN_QUIC = "quic" CONN_WEB = "web" CONN_WS = "ws" CONN_WSS = "wss" CONN_TEST = "TST" CONN_ACK = "ACK" PING = "ping" PONG = "pong" TEST = "test" TOTP_SEQ = "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 PoolSizeSmall = 255 PoolSizeUdp = 1472 + 200 PoolSizeCopy = 32 << 10 )
Variables ¶
var ( BufPool = newBytePool64K() BufPoolUdp = newBytePoolUDP() BufPoolSmall = newBytePoolSmall() 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 CheckAuthWithAccountMap ¶
CheckAuthWithAccountMap u current login user p current login passwd user global user passwd global passwd accountMap enable multi user auth
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 FetchExternalIp ¶ added in v0.26.46
func FetchExternalIp() string
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 GetExtFromPath ¶
func GetExternalIp ¶
func GetExternalIp() string
func GetHostByName ¶
GetHostByName Get the corresponding IP address through domain name
func GetInstallPath ¶
func GetInstallPath() string
GetInstallPath Different systems get different installation paths
func GetIntranetIp ¶
func GetIntranetIp() string
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 GetMatchingLocalAddr ¶ added in v0.30.4
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 GetServerIpByClientIp ¶
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 ParseIPFromAddr ¶ added in v0.34.0
ParseIPFromAddr parses IP from an "ip:port" (supports "[v6]:port"). Returns nil if cannot parse.
func ParseProxyACLEntries ¶ added in v0.34.0
ParseProxyACLEntries parses newline-separated text, trims and lowercases. Lines starting with '#' or ';' are ignored.
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 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 TimeOffset ¶ added in v0.30.0
func TimestampToBytes ¶ added in v0.27.0
TimestampToBytes 8bit
func ValidateAddr ¶ added in v0.30.2
func ValidatePoW ¶ added in v0.29.30
Types ¶
type Addr ¶
func ToSocksAddr ¶
type NetPackager ¶
type ProxyACL ¶ added in v0.34.0
type ProxyACL struct {
Entries []string
ExactIPs map[string]struct{} // ip.String() => {}
CIDRs []*net.IPNet
Hostnames map[string]struct{} // exact hostname (lower)
// ".a.com" => subdomain-only (from "*.a.com")
// "a.com" => include root + subdomains (from "*a.com")
WildcardSuffixes []string
}
ProxyACL is an allow-list matcher for proxy destinations. Enabled when Entries is non-empty; deny-by-default.
Entry formats (one per line): - IP: 1.2.3.4, 2001:db8::1 - CIDR: 10.0.0.0/8, 2001:db8::/32 - Hostname: example.com - Host:Port: example.com:443, [2001:db8::1]:443 (port is ignored) - Wildcard: *.example.com (subdomains only; NOT include example.com) - Wildcard: *example.com (include example.com + subdomains)
func ParseProxyACL ¶ added in v0.34.0
ParseProxyACL builds a matcher from raw entries. Note: it does NOT resolve DNS; hostnames match only hostname/wildcard rules.
type UDPDatagram ¶
func NewUDPDatagram ¶
func NewUDPDatagram(header *UDPHeader, data []byte) *UDPDatagram
func ReadUDPDatagram ¶
func ReadUDPDatagram(r io.Reader) (*UDPDatagram, error)