Documentation
¶
Index ¶
- Constants
- Variables
- type ClientInfo
- type ConnectInfo
- type DNSEndpoint
- type DOHEndpoint
- func (e *DOHEndpoint) Equal(e2 Endpoint) bool
- func (e *DOHEndpoint) Exchange(ctx context.Context, payload, buf []byte) (n int, err error)
- func (e *DOHEndpoint) Protocol() Protocol
- func (e *DOHEndpoint) RoundTrip(req *http.Request) (resp *http.Response, err error)
- func (e *DOHEndpoint) String() string
- type Endpoint
- type Manager
- type Protocol
- type Provider
- type ProviderFunc
- type SourceHTTPSSVCProvider
- type SourceURLProvider
- type StaticProvider
- type Tester
Constants ¶
View Source
const ( // DefaultErrorThreshold defines the default value for Manager ErrorThreshold. DefaultErrorThreshold = 10 // DefaultMinTestInterval defines the default value for Manager MinTestInterval. DefaultMinTestInterval = 2 * time.Hour )
Variables ¶
View Source
var TestDomain = "probe-test.dns.nextdns.io."
Functions ¶
This section is empty.
Types ¶
type ClientInfo ¶ added in v1.2.0
type ConnectInfo ¶ added in v1.2.0
type DNSEndpoint ¶ added in v1.2.0
type DNSEndpoint struct {
// Addr use to contact the DNS server.
Addr string
}
func (*DNSEndpoint) Equal ¶ added in v1.2.0
func (e *DNSEndpoint) Equal(e2 Endpoint) bool
func (*DNSEndpoint) Protocol ¶ added in v1.2.0
func (e *DNSEndpoint) Protocol() Protocol
func (*DNSEndpoint) String ¶ added in v1.2.0
func (e *DNSEndpoint) String() string
type DOHEndpoint ¶ added in v1.2.0
type DOHEndpoint struct {
// Hostname use to contact the DoH server. If Bootstrap is provided,
// Hostname is only used for TLS verification.
Hostname string
// Path to use with DoH HTTP requests. If empty, the path received in the
// request by Transport is left untouched.
Path string
// Bootstrap is the IPs to use to contact the DoH server. When provided, no
// DNS request is necessary to contact the DoH server. The fastest IP is
// used.
Bootstrap []string `json:"ips"`
// ALPN is the list of alpn-id declared to be supported by the endpoint
// through HTTPSSVC or Alt-Svc. If missing, h2 is assumed.
ALPN []string
// contains filtered or unexported fields
}
Endpoint represents a DoH server endpoint.
func (*DOHEndpoint) Equal ¶ added in v1.2.0
func (e *DOHEndpoint) Equal(e2 Endpoint) bool
func (*DOHEndpoint) Protocol ¶ added in v1.2.0
func (e *DOHEndpoint) Protocol() Protocol
func (*DOHEndpoint) String ¶ added in v1.2.0
func (e *DOHEndpoint) String() string
type Endpoint ¶
type Endpoint interface {
fmt.Stringer
// Protocol returns the protocol used by this endpoint to transport DNS.
Protocol() Protocol
// Equal returns true if e represent the same endpoint.
Equal(e Endpoint) bool
// Send a DNS payload and get the response in buf.
Exchange(ctx context.Context, payload, buf []byte) (n int, err error)
}
Endpoint represents a DNS server endpoint.
func New ¶
New is a convenient method to build a Endpoint.
Supported format for server are:
- DoH: https://doh.server.com/path
- DoH: https://doh.server.com/path#1.2.3.4 // with bootstrap
- DNS53: 1.2.3.4
- DNS53: 1.2.3.4:5353
type Manager ¶
type Manager struct {
// Providers is a list of Endpoint providers listed in order of preference.
// The first working provided is selected on each call to Test or internal
// test performed on error or opportunistically.
//
// Calling Test with an empty Providers list will result in a panic.
Providers []Provider
// InitEndpoint defines the endpoint to use before Providers returned a
// working endpoint.
InitEndpoint Endpoint
// ErrorThreshold is the number of consecutive errors with a endpoint
// requires to trigger a test to fallback on another endpoint. If zero,
// DefaultErrorThreshold is used.
ErrorThreshold int
// MinTestInterval is the minimum interval to keep between two opportunistic
// tests. Opportunistic tests are scheduled only when a DNS request attempt
// is performed and the last test happened at list TestMinInterval age.
MinTestInterval time.Duration
// GetMinTestInterval returns the MinTestInterval to use for e. If
// GetMinTestInterval returns 0 or is unset, MinTestInterval is used.
GetMinTestInterval func(e Endpoint) time.Duration
// TestEndpoint specifies a custom tester for e. If not defined or nil
// returned, Test is called on e.
EndpointTester func(e Endpoint) Tester
// OnChange is called whenever the active endpoint changes.
OnChange func(e Endpoint)
// OnConnect is called whenever an endpoint connects (for connected
// endpoints).
OnConnect func(*ConnectInfo)
// OnError is called each time a test on e failed, forcing Manager to
// fallback to the next endpoint. If e is nil, the error happended on the
// Provider.
OnError func(e Endpoint, err error)
// OnProviderError is called when a provider returns an error.
OnProviderError func(p Provider, err error)
// contains filtered or unexported fields
}
type ProviderFunc ¶ added in v1.4.33
func (ProviderFunc) GetEndpoints ¶ added in v1.4.33
func (p ProviderFunc) GetEndpoints(ctx context.Context) ([]Endpoint, error)
type SourceHTTPSSVCProvider ¶ added in v1.10.0
func (*SourceHTTPSSVCProvider) GetEndpoints ¶ added in v1.10.0
func (p *SourceHTTPSSVCProvider) GetEndpoints(ctx context.Context) ([]Endpoint, error)
GetEndpoints implements the Provider interface.
type SourceURLProvider ¶
type SourceURLProvider struct {
// SourceURL is a URL pointing to a JSON resource listing one or more
// Endpoints.
SourceURL string
// Client is the http.Client to use to fetch SourceURL. If not defined,
// http.DefaultClient is used.
Client *http.Client
// contains filtered or unexported fields
}
SourceURLProvider loads a list of endpoints from a remote URL.
func (*SourceURLProvider) GetEndpoints ¶
func (p *SourceURLProvider) GetEndpoints(ctx context.Context) ([]Endpoint, error)
GetEndpoints implements the Provider interface.
func (*SourceURLProvider) String ¶ added in v1.3.0
func (p *SourceURLProvider) String() string
type StaticProvider ¶
type StaticProvider []Endpoint
StaticProvider wraps a Endpoint slice to adapt it to the Provider interface.
func (StaticProvider) GetEndpoints ¶
func (p StaticProvider) GetEndpoints(ctx context.Context) ([]Endpoint, error)
GetEndpoints implements the Provider interface.
Click to show internal directories.
Click to hide internal directories.