Documentation ¶
Index ¶
- Constants
- Variables
- func AddHost(host string, ip string)
- func DialAutoGMTLSContextWithoutProxy(ctx context.Context, network, addr string) (net.Conn, error)
- func DialContext(ctx context.Context, target string, proxies ...string) (net.Conn, error)
- func DialContextWithoutProxy(ctx context.Context, network, addr string) (net.Conn, error)
- func DialForceGMTLSContextWithoutProxy(ctx context.Context, network, addr string) (net.Conn, error)
- func DialSocksProxy(socksType int, proxy string, username string, password string) func(string, string) (net.Conn, error)
- func DialTCPTimeout(timeout time.Duration, target string, proxies ...string) (net.Conn, error)
- func DialTCPTimeoutForceProxy(timeout time.Duration, target string, proxy string) (net.Conn, error)
- func DialTLSContextWithoutProxy(ctx context.Context, network, addr string, tlsConfig *tls.Config) (net.Conn, error)
- func DialTLSTimeout(timeout time.Duration, target string, tlsConfig any, proxy ...string) (net.Conn, error)
- func DialTimeout(connectTimeout time.Duration, target string, proxy ...string) (net.Conn, error)
- func DialTimeoutWithoutProxy(timeout time.Duration, network, addr string) (net.Conn, error)
- func DialX(target string, opt ...DialXOption) (net.Conn, error)
- func FixProxy(i string) string
- func GetDefaultHostsFilePath() string
- func GetHost(host string) (ip string, ok bool)
- func GetProxyFromEnv() string
- func IsExistedHost(host string) bool
- func IsTLSService(addr string, proxies ...string) bool
- func LoadHostsFromFile(p string) error
- func LookupAll(host string, opt ...DNSOption) []string
- func LookupCallback(host string, h func(dnsType, domain, ip, fromServer string, method string), ...) error
- func LookupFirst(host string, opt ...DNSOption) string
- func NewDefaultHTTPClient(proxy ...string) *http.Client
- func NewDialContextFunc(timeout time.Duration, opts ...DNSOption) func(ctx context.Context, network string, addr string) (net.Conn, error)
- func NewDialGMTLSContextFunc(enableGM bool, preferGMTLS bool, onlyGMTLS bool, timeout time.Duration, ...) func(ctx context.Context, network string, addr string) (net.Conn, error)
- func SetDefaultOptions(opt ...DNSOption)
- func UpgradeToTLSConnection(conn net.Conn, sni string, i any) (net.Conn, error)
- func UpgradeToTLSConnectionWithTimeout(conn net.Conn, sni string, i any, timeout time.Duration) (net.Conn, error)
- type DNSOption
- func GetDefaultOptions() []DNSOption
- func WithDNSCallback(cb func(dnsType, domain, ip, fromServer, method string)) DNSOption
- func WithDNSContext(ctx context.Context) DNSOption
- func WithDNSDisableSystemResolver(b bool) DNSOption
- func WithDNSFallbackDoH(b bool) DNSOption
- func WithDNSFallbackSpecificDNS(b bool) DNSOption
- func WithDNSFallbackTCP(b bool) DNSOption
- func WithDNSNoCache(b bool) DNSOption
- func WithDNSOnFinished(cb func()) DNSOption
- func WithDNSPreferDoH(b bool) DNSOption
- func WithDNSPreferTCP(b bool) DNSOption
- func WithDNSRetryTimes(i int) DNSOption
- func WithDNSServers(s ...string) DNSOption
- func WithDNSSpecificDoH(s ...string) DNSOption
- func WithTemporaryHosts(i map[string]string) DNSOption
- func WithTimeout(timeout time.Duration) DNSOption
- type DialXOption
- func DialX_WithDNSOptions(opt ...DNSOption) DialXOption
- func DialX_WithGMTLSConfig(config *gmtls.Config) DialXOption
- func DialX_WithGMTLSOnly(b bool) DialXOption
- func DialX_WithGMTLSPrefer(b bool) DialXOption
- func DialX_WithGMTLSSupport(b bool) DialXOption
- func DialX_WithProxy(proxy ...string) DialXOption
- func DialX_WithSNI(sni string) DialXOption
- func DialX_WithTLS(b bool) DialXOption
- func DialX_WithTLSConfig(tlsConfig *tls.Config) DialXOption
- func DialX_WithTLSTimeout(t time.Duration) DialXOption
- func DialX_WithTimeout(timeout time.Duration) DialXOption
- func DialX_WithTimeoutRetry(max int) DialXOption
- func DialX_WithTimeoutRetryWait(timeout time.Duration) DialXOption
- func DialX_WithTimeoutRetryWaitRange(min, max time.Duration) DialXOption
- type DoHDNSResponse
- type ReliableDNSConfig
- type TLSStrategy
Constants ¶
const ( SOCKS4 = iota SOCKS4A SOCKS5 )
Constants to choose which version of SOCKS protocol to use.
const DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"
Variables ¶
var DefaultCustomDNSServers = []string{
"223.5.5.5", "223.6.6.6",
"120.53.53.53", "1.1.1.1",
"8.8.8.8",
}
var DefaultCustomDoHServers = []string{
"https://223.5.5.5/resolve",
"https://223.6.6.6/resolve",
"https://1.12.12.12/dns-query",
"https://120.53.53.53/dns-query",
"https://1.1.1.1/dns-query",
"https://8.8.8.8/resolve",
"https://8.8.4.4/resolve",
}
Functions ¶
func DialAutoGMTLSContextWithoutProxy ¶
DialAutoGMTLSContextWithoutProxy dials a GMTLS connection with a context.
func DialContext ¶ added in v1.2.5
func DialContextWithoutProxy ¶
DialContextWithoutProxy dials a connection with a context.
func DialForceGMTLSContextWithoutProxy ¶
DialForceGMTLSContextWithoutProxy dials a GMTLS connection with a context.
func DialSocksProxy ¶
func DialSocksProxy(socksType int, proxy string, username string, password string) func(string, string) (net.Conn, error)
DialSocksProxy returns the dial function to be used in http.Transport object. Argument socksType should be one of SOCKS4, SOCKS4A and SOCKS5. Argument proxy should be in this format "127.0.0.1:1080".
func DialTCPTimeout ¶
DialTCPTimeout dial tcp with timeout
1. if no proxy, dial directly, timeout for
func DialTLSContextWithoutProxy ¶
func DialTLSContextWithoutProxy(ctx context.Context, network, addr string, tlsConfig *tls.Config) (net.Conn, error)
DialTLSContextWithoutProxy dials a TLS connection with a context.
func DialTLSTimeout ¶
func DialTimeout ¶
func DialTimeoutWithoutProxy ¶
DialTimeoutWithoutProxy dials a connection with a timeout.
func DialX ¶ added in v1.2.6
func DialX(target string, opt ...DialXOption) (net.Conn, error)
DialX is netx dial with more options
Proxy is a list of proxy servers, if empty, no proxy will be used, otherwise retry with each proxy until success (no redirect)
func GetDefaultHostsFilePath ¶
func GetDefaultHostsFilePath() string
func GetProxyFromEnv ¶
func GetProxyFromEnv() string
func IsExistedHost ¶
func IsTLSService ¶
func LookupCallback ¶
func LookupFirst ¶
func NewDefaultHTTPClient ¶ added in v1.2.6
func NewDialContextFunc ¶
func NewDialContextFunc(timeout time.Duration, opts ...DNSOption) func(ctx context.Context, network string, addr string) (net.Conn, error)
NewDialContextFunc is a function that can be used to dial a connection.
func NewDialGMTLSContextFunc ¶
func SetDefaultOptions ¶
func SetDefaultOptions(opt ...DNSOption)
func UpgradeToTLSConnection ¶
Types ¶
type DNSOption ¶
type DNSOption func(*ReliableDNSConfig)
func GetDefaultOptions ¶
func GetDefaultOptions() []DNSOption
func WithDNSCallback ¶
func WithDNSContext ¶
func WithDNSFallbackDoH ¶
func WithDNSFallbackTCP ¶
func WithDNSNoCache ¶
func WithDNSOnFinished ¶ added in v1.2.6
func WithDNSOnFinished(cb func()) DNSOption
func WithDNSPreferDoH ¶
func WithDNSPreferTCP ¶
func WithDNSRetryTimes ¶
func WithDNSServers ¶
func WithDNSSpecificDoH ¶
func WithTemporaryHosts ¶
func WithTimeout ¶
type DialXOption ¶ added in v1.2.6
type DialXOption func(c *dialXConfig)
func DialX_WithDNSOptions ¶ added in v1.2.6
func DialX_WithDNSOptions(opt ...DNSOption) DialXOption
func DialX_WithGMTLSConfig ¶ added in v1.2.6
func DialX_WithGMTLSConfig(config *gmtls.Config) DialXOption
func DialX_WithGMTLSOnly ¶ added in v1.2.6
func DialX_WithGMTLSOnly(b bool) DialXOption
func DialX_WithGMTLSPrefer ¶ added in v1.2.6
func DialX_WithGMTLSPrefer(b bool) DialXOption
func DialX_WithGMTLSSupport ¶ added in v1.2.6
func DialX_WithGMTLSSupport(b bool) DialXOption
func DialX_WithProxy ¶ added in v1.2.6
func DialX_WithProxy(proxy ...string) DialXOption
func DialX_WithSNI ¶ added in v1.2.6
func DialX_WithSNI(sni string) DialXOption
func DialX_WithTLS ¶ added in v1.2.6
func DialX_WithTLS(b bool) DialXOption
func DialX_WithTLSConfig ¶ added in v1.2.6
func DialX_WithTLSConfig(tlsConfig *tls.Config) DialXOption
func DialX_WithTLSTimeout ¶ added in v1.2.6
func DialX_WithTLSTimeout(t time.Duration) DialXOption
func DialX_WithTimeout ¶ added in v1.2.6
func DialX_WithTimeout(timeout time.Duration) DialXOption
func DialX_WithTimeoutRetry ¶ added in v1.2.6
func DialX_WithTimeoutRetry(max int) DialXOption
func DialX_WithTimeoutRetryWait ¶ added in v1.2.6
func DialX_WithTimeoutRetryWait(timeout time.Duration) DialXOption
func DialX_WithTimeoutRetryWaitRange ¶ added in v1.2.6
func DialX_WithTimeoutRetryWaitRange(min, max time.Duration) DialXOption
type DoHDNSResponse ¶
type DoHDNSResponse struct { Status int `json:"Status"` TC bool `json:"TC"` RD bool `json:"RD"` RA bool `json:"RA"` AD bool `json:"AD"` CD bool `json:"CD"` Question json.RawMessage Answer []struct { Name string `json:"name"` Type int `json:"type"` TTL int `json:"TTL"` Data string `json:"data"` } `json:"Answer"` }
type ReliableDNSConfig ¶
type ReliableDNSConfig struct { Timeout time.Duration Hosts map[string]string PreferTCP bool FallbackTCP bool RetryTimes int // default 3 // DoH config PreferDoH bool FallbackDoH bool // as backup SpecificDoH []string // NoCache NoCache bool // Disable System Resolver DisableSystemResolver bool // SpecificDNSServers 作为备选项 FallbackSpecificDNS bool SpecificDNSServers []string // ctx BaseContext context.Context Callback func(dnsType string, domain string, ip, fromServer, method string) OnFinished func() // contains filtered or unexported fields }
func NewBackupInitilizedReliableDNSConfig ¶
func NewBackupInitilizedReliableDNSConfig() *ReliableDNSConfig
func NewDefaultReliableDNSConfig ¶
func NewDefaultReliableDNSConfig() *ReliableDNSConfig
func (*ReliableDNSConfig) GetBaseContext ¶
func (r *ReliableDNSConfig) GetBaseContext() context.Context
type TLSStrategy ¶ added in v1.2.6
type TLSStrategy string
const ( TLS_Strategy_GMDail TLSStrategy = "gmtls" TLS_Strategy_GMDial_Without_GMSupport TLSStrategy = "gmtls-ns" TLS_Strategy_Ordinary TLSStrategy = "tls" )