2021-02-02 12:05:47 +01:00
|
|
|
// Package uncensored contains code used by Jafar to evade its own
|
|
|
|
// censorship efforts by taking alternate routes.
|
|
|
|
package uncensored
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-07 18:33:37 +01:00
|
|
|
"errors"
|
2021-02-02 12:05:47 +01:00
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
2022-01-07 18:33:37 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2022-06-02 22:25:37 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
2021-02-02 12:05:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Client is DNS, HTTP, and TCP client.
|
|
|
|
type Client struct {
|
2022-01-10 11:53:06 +01:00
|
|
|
dnsClient model.Resolver
|
2022-01-07 18:33:37 +01:00
|
|
|
httpTransport model.HTTPTransport
|
|
|
|
dialer model.Dialer
|
2021-02-02 12:05:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewClient creates a new Client.
|
2022-06-02 22:25:37 +02:00
|
|
|
func NewClient(resolverURL string) *Client {
|
|
|
|
dnsClient := netxlite.NewParallelDNSOverHTTPSResolver(log.Log, resolverURL)
|
2021-02-02 12:05:47 +01:00
|
|
|
return &Client{
|
2022-06-02 22:25:37 +02:00
|
|
|
dnsClient: dnsClient,
|
|
|
|
httpTransport: netxlite.NewHTTPTransportWithResolver(log.Log, dnsClient),
|
|
|
|
dialer: netxlite.NewDialerWithResolver(log.Log, dnsClient),
|
|
|
|
}
|
2021-02-02 12:05:47 +01:00
|
|
|
}
|
|
|
|
|
2022-01-07 19:18:33 +01:00
|
|
|
// Address implements Resolver.Address
|
2021-02-02 12:05:47 +01:00
|
|
|
func (c *Client) Address() string {
|
|
|
|
return c.dnsClient.Address()
|
|
|
|
}
|
|
|
|
|
2022-01-07 19:18:33 +01:00
|
|
|
// LookupHost implements Resolver.LookupHost
|
2021-02-02 12:05:47 +01:00
|
|
|
func (c *Client) LookupHost(ctx context.Context, domain string) ([]string, error) {
|
|
|
|
return c.dnsClient.LookupHost(ctx, domain)
|
|
|
|
}
|
|
|
|
|
2022-01-07 18:33:37 +01:00
|
|
|
// LookupHTTPS implements model.Resolver.LookupHTTPS.
|
|
|
|
func (c *Client) LookupHTTPS(ctx context.Context, domain string) (*model.HTTPSSvc, error) {
|
|
|
|
return nil, errors.New("not implemented")
|
|
|
|
}
|
|
|
|
|
2022-05-16 10:46:53 +02:00
|
|
|
// LookupNS implements model.Resolver.LookupNS.
|
|
|
|
func (c *Client) LookupNS(ctx context.Context, domain string) ([]*net.NS, error) {
|
|
|
|
return nil, errors.New("not implemented")
|
|
|
|
}
|
|
|
|
|
2022-01-07 19:18:33 +01:00
|
|
|
// Network implements Resolver.Network
|
2021-02-02 12:05:47 +01:00
|
|
|
func (c *Client) Network() string {
|
|
|
|
return c.dnsClient.Network()
|
|
|
|
}
|
|
|
|
|
2022-01-07 19:18:33 +01:00
|
|
|
// DialContext implements Dialer.DialContext
|
2021-02-02 12:05:47 +01:00
|
|
|
func (c *Client) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
|
|
|
return c.dialer.DialContext(ctx, network, address)
|
|
|
|
}
|
|
|
|
|
2022-01-07 19:18:33 +01:00
|
|
|
// CloseIdleConnections implement HTTPRoundTripper.CloseIdleConnections
|
2021-02-02 12:05:47 +01:00
|
|
|
func (c *Client) CloseIdleConnections() {
|
|
|
|
c.dnsClient.CloseIdleConnections()
|
|
|
|
c.httpTransport.CloseIdleConnections()
|
|
|
|
}
|
|
|
|
|
2022-01-07 19:18:33 +01:00
|
|
|
// RoundTrip implement HTTPRoundTripper.RoundTrip
|
2021-02-02 12:05:47 +01:00
|
|
|
func (c *Client) RoundTrip(req *http.Request) (*http.Response, error) {
|
|
|
|
return c.httpTransport.RoundTrip(req)
|
|
|
|
}
|