Pull request: all: imp docs, names
Merge in DNS/adguard-home from imp-text to master Squashed commit of the following: commit fa7d64014fb2ac379e1c137eaccc7aefca86419d Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Fri Jun 11 17:09:00 2021 +0300 all: imp docs, names
This commit is contained in:
@@ -63,13 +63,13 @@ const (
|
||||
|
||||
// RuntimeClient information
|
||||
type RuntimeClient struct {
|
||||
WhoisInfo *RuntimeClientWhoisInfo
|
||||
WHOISInfo *RuntimeClientWHOISInfo
|
||||
Host string
|
||||
Source clientSource
|
||||
}
|
||||
|
||||
// RuntimeClientWhoisInfo is the filtered WHOIS data for a runtime client.
|
||||
type RuntimeClientWhoisInfo struct {
|
||||
// RuntimeClientWHOISInfo is the filtered WHOIS data for a runtime client.
|
||||
type RuntimeClientWHOISInfo struct {
|
||||
City string `json:"city,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
Orgname string `json:"orgname,omitempty"`
|
||||
@@ -270,12 +270,12 @@ func (clients *clientsContainer) Exists(id string, source clientSource) (ok bool
|
||||
return source <= rc.Source
|
||||
}
|
||||
|
||||
func toQueryLogWhois(wi *RuntimeClientWhoisInfo) (cw *querylog.ClientWhois) {
|
||||
func toQueryLogWHOIS(wi *RuntimeClientWHOISInfo) (cw *querylog.ClientWHOIS) {
|
||||
if wi == nil {
|
||||
return &querylog.ClientWhois{}
|
||||
return &querylog.ClientWHOIS{}
|
||||
}
|
||||
|
||||
return &querylog.ClientWhois{
|
||||
return &querylog.ClientWHOIS{
|
||||
City: wi.City,
|
||||
Country: wi.Country,
|
||||
Orgname: wi.Orgname,
|
||||
@@ -287,7 +287,7 @@ func toQueryLogWhois(wi *RuntimeClientWhoisInfo) (cw *querylog.ClientWhois) {
|
||||
func (clients *clientsContainer) findMultiple(ids []string) (c *querylog.Client, err error) {
|
||||
for _, id := range ids {
|
||||
var name string
|
||||
whois := &querylog.ClientWhois{}
|
||||
whois := &querylog.ClientWHOIS{}
|
||||
|
||||
c, ok := clients.Find(id)
|
||||
if ok {
|
||||
@@ -300,7 +300,7 @@ func (clients *clientsContainer) findMultiple(ids []string) (c *querylog.Client,
|
||||
}
|
||||
|
||||
name = rc.Host
|
||||
whois = toQueryLogWhois(rc.WhoisInfo)
|
||||
whois = toQueryLogWHOIS(rc.WHOISInfo)
|
||||
}
|
||||
|
||||
ip := net.ParseIP(id)
|
||||
@@ -309,7 +309,7 @@ func (clients *clientsContainer) findMultiple(ids []string) (c *querylog.Client,
|
||||
return &querylog.Client{
|
||||
Name: name,
|
||||
DisallowedRule: disallowedRule,
|
||||
Whois: whois,
|
||||
WHOIS: whois,
|
||||
Disallowed: disallowed,
|
||||
}, nil
|
||||
}
|
||||
@@ -620,8 +620,8 @@ func (clients *clientsContainer) Update(name string, c *Client) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetWhoisInfo sets the WHOIS information for a client.
|
||||
func (clients *clientsContainer) SetWhoisInfo(ip string, wi *RuntimeClientWhoisInfo) {
|
||||
// SetWHOISInfo sets the WHOIS information for a client.
|
||||
func (clients *clientsContainer) SetWHOISInfo(ip string, wi *RuntimeClientWHOISInfo) {
|
||||
clients.lock.Lock()
|
||||
defer clients.lock.Unlock()
|
||||
|
||||
@@ -633,7 +633,7 @@ func (clients *clientsContainer) SetWhoisInfo(ip string, wi *RuntimeClientWhoisI
|
||||
|
||||
rc, ok := clients.ipToRC[ip]
|
||||
if ok {
|
||||
rc.WhoisInfo = wi
|
||||
rc.WHOISInfo = wi
|
||||
log.Debug("clients: set whois info for runtime client %s: %+v", rc.Host, wi)
|
||||
|
||||
return
|
||||
@@ -645,7 +645,7 @@ func (clients *clientsContainer) SetWhoisInfo(ip string, wi *RuntimeClientWhoisI
|
||||
Source: ClientSourceWHOIS,
|
||||
}
|
||||
|
||||
rc.WhoisInfo = wi
|
||||
rc.WHOISInfo = wi
|
||||
clients.ipToRC[ip] = rc
|
||||
|
||||
log.Debug("clients: set whois info for runtime client with ip %s: %+v", ip, wi)
|
||||
@@ -676,7 +676,7 @@ func (clients *clientsContainer) addHostLocked(ip, host string, src clientSource
|
||||
rc = &RuntimeClient{
|
||||
Host: host,
|
||||
Source: src,
|
||||
WhoisInfo: &RuntimeClientWhoisInfo{},
|
||||
WHOISInfo: &RuntimeClientWHOISInfo{},
|
||||
}
|
||||
|
||||
clients.ipToRC[ip] = rc
|
||||
|
||||
@@ -172,25 +172,25 @@ func TestClients(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestClientsWhois(t *testing.T) {
|
||||
func TestClientsWHOIS(t *testing.T) {
|
||||
clients := clientsContainer{
|
||||
testing: true,
|
||||
}
|
||||
clients.Init(nil, nil, nil)
|
||||
whois := &RuntimeClientWhoisInfo{
|
||||
whois := &RuntimeClientWHOISInfo{
|
||||
Country: "AU",
|
||||
Orgname: "Example Org",
|
||||
}
|
||||
|
||||
t.Run("new_client", func(t *testing.T) {
|
||||
clients.SetWhoisInfo("1.1.1.255", whois)
|
||||
clients.SetWHOISInfo("1.1.1.255", whois)
|
||||
|
||||
require.NotNil(t, clients.ipToRC["1.1.1.255"])
|
||||
|
||||
h := clients.ipToRC["1.1.1.255"]
|
||||
require.NotNil(t, h)
|
||||
|
||||
assert.Equal(t, h.WhoisInfo, whois)
|
||||
assert.Equal(t, h.WHOISInfo, whois)
|
||||
})
|
||||
|
||||
t.Run("existing_auto-client", func(t *testing.T) {
|
||||
@@ -198,13 +198,13 @@ func TestClientsWhois(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.True(t, ok)
|
||||
|
||||
clients.SetWhoisInfo("1.1.1.1", whois)
|
||||
clients.SetWHOISInfo("1.1.1.1", whois)
|
||||
|
||||
require.NotNil(t, clients.ipToRC["1.1.1.1"])
|
||||
h := clients.ipToRC["1.1.1.1"]
|
||||
require.NotNil(t, h)
|
||||
|
||||
assert.Equal(t, h.WhoisInfo, whois)
|
||||
assert.Equal(t, h.WHOISInfo, whois)
|
||||
})
|
||||
|
||||
t.Run("can't_set_manually-added", func(t *testing.T) {
|
||||
@@ -215,7 +215,7 @@ func TestClientsWhois(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.True(t, ok)
|
||||
|
||||
clients.SetWhoisInfo("1.1.1.2", whois)
|
||||
clients.SetWHOISInfo("1.1.1.2", whois)
|
||||
require.Nil(t, clients.ipToRC["1.1.1.2"])
|
||||
assert.True(t, clients.Del("client1"))
|
||||
})
|
||||
|
||||
@@ -24,7 +24,7 @@ type clientJSON struct {
|
||||
// the allowlist.
|
||||
DisallowedRule *string `json:"disallowed_rule,omitempty"`
|
||||
|
||||
WhoisInfo *RuntimeClientWhoisInfo `json:"whois_info,omitempty"`
|
||||
WHOISInfo *RuntimeClientWHOISInfo `json:"whois_info,omitempty"`
|
||||
|
||||
Name string `json:"name"`
|
||||
|
||||
@@ -42,7 +42,7 @@ type clientJSON struct {
|
||||
}
|
||||
|
||||
type runtimeClientJSON struct {
|
||||
WhoisInfo *RuntimeClientWhoisInfo `json:"whois_info"`
|
||||
WHOISInfo *RuntimeClientWHOISInfo `json:"whois_info"`
|
||||
|
||||
IP string `json:"ip"`
|
||||
Name string `json:"name"`
|
||||
@@ -70,7 +70,7 @@ func (clients *clientsContainer) handleGetClients(w http.ResponseWriter, _ *http
|
||||
cj := runtimeClientJSON{
|
||||
IP: ip,
|
||||
Name: rc.Host,
|
||||
WhoisInfo: rc.WhoisInfo,
|
||||
WHOISInfo: rc.WHOISInfo,
|
||||
}
|
||||
|
||||
cj.Source = "etc/hosts"
|
||||
@@ -143,7 +143,7 @@ func runtimeClientToJSON(ip string, rc RuntimeClient) (cj clientJSON) {
|
||||
cj = clientJSON{
|
||||
Name: rc.Host,
|
||||
IDs: []string{ip},
|
||||
WhoisInfo: rc.WhoisInfo,
|
||||
WHOISInfo: rc.WHOISInfo,
|
||||
}
|
||||
|
||||
return cj
|
||||
@@ -287,7 +287,7 @@ func (clients *clientsContainer) findRuntime(ip net.IP, idStr string) (cj client
|
||||
IDs: []string{idStr},
|
||||
Disallowed: &disallowed,
|
||||
DisallowedRule: &rule,
|
||||
WhoisInfo: &RuntimeClientWhoisInfo{},
|
||||
WHOISInfo: &RuntimeClientWHOISInfo{},
|
||||
}
|
||||
|
||||
return cj, true
|
||||
|
||||
@@ -135,11 +135,11 @@ type dnsConfig struct {
|
||||
}
|
||||
|
||||
type tlsConfigSettings struct {
|
||||
Enabled bool `yaml:"enabled" json:"enabled"` // Enabled is the encryption (DOT/DOH/HTTPS) status
|
||||
Enabled bool `yaml:"enabled" json:"enabled"` // Enabled is the encryption (DoT/DoH/HTTPS) status
|
||||
ServerName string `yaml:"server_name" json:"server_name,omitempty"` // ServerName is the hostname of your HTTPS/TLS server
|
||||
ForceHTTPS bool `yaml:"force_https" json:"force_https,omitempty"` // ForceHTTPS: if true, forces HTTP->HTTPS redirect
|
||||
PortHTTPS int `yaml:"port_https" json:"port_https,omitempty"` // HTTPS port. If 0, HTTPS will be disabled
|
||||
PortDNSOverTLS int `yaml:"port_dns_over_tls" json:"port_dns_over_tls,omitempty"` // DNS-over-TLS port. If 0, DOT will be disabled
|
||||
PortDNSOverTLS int `yaml:"port_dns_over_tls" json:"port_dns_over_tls,omitempty"` // DNS-over-TLS port. If 0, DoT will be disabled
|
||||
PortDNSOverQUIC int `yaml:"port_dns_over_quic" json:"port_dns_over_quic,omitempty"` // DNS-over-QUIC port. If 0, DoQ will be disabled
|
||||
|
||||
// PortDNSCrypt is the port for DNSCrypt requests. If it's zero,
|
||||
@@ -152,8 +152,8 @@ type tlsConfigSettings struct {
|
||||
// https://github.com/ameshkov/dnscrypt.
|
||||
DNSCryptConfigFile string `yaml:"dnscrypt_config_file" json:"dnscrypt_config_file"`
|
||||
|
||||
// Allow DOH queries via unencrypted HTTP (e.g. for reverse proxying)
|
||||
AllowUnencryptedDOH bool `yaml:"allow_unencrypted_doh" json:"allow_unencrypted_doh"`
|
||||
// Allow DoH queries via unencrypted HTTP (e.g. for reverse proxying)
|
||||
AllowUnencryptedDoH bool `yaml:"allow_unencrypted_doh" json:"allow_unencrypted_doh"`
|
||||
|
||||
dnsforward.TLSConfig `yaml:",inline" json:",inline"`
|
||||
}
|
||||
|
||||
@@ -198,9 +198,9 @@ func registerControlHandlers() {
|
||||
httpRegister(http.MethodPost, "/control/update", handleUpdate)
|
||||
httpRegister(http.MethodGet, "/control/profile", handleGetProfile)
|
||||
|
||||
// No auth is necessary for DOH/DOT configurations
|
||||
Context.mux.HandleFunc("/apple/doh.mobileconfig", postInstall(handleMobileConfigDOH))
|
||||
Context.mux.HandleFunc("/apple/dot.mobileconfig", postInstall(handleMobileConfigDOT))
|
||||
// No auth is necessary for DoH/DoT configurations
|
||||
Context.mux.HandleFunc("/apple/doh.mobileconfig", postInstall(handleMobileConfigDoH))
|
||||
Context.mux.HandleFunc("/apple/dot.mobileconfig", postInstall(handleMobileConfigDoT))
|
||||
RegisterAuthHandlers()
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ func initDNSServer() error {
|
||||
}
|
||||
|
||||
Context.rdns = NewRDNS(Context.dnsServer, &Context.clients, config.DNS.UsePrivateRDNS)
|
||||
Context.whois = initWhois(&Context.clients)
|
||||
Context.whois = initWHOIS(&Context.clients)
|
||||
|
||||
Context.filters.Init()
|
||||
return nil
|
||||
@@ -194,7 +194,7 @@ func generateServerConfig() (newConf dnsforward.ServerConfig, err error) {
|
||||
|
||||
newConf.TLSv12Roots = Context.tlsRoots
|
||||
newConf.TLSCiphers = Context.tlsCiphers
|
||||
newConf.TLSAllowUnencryptedDOH = tlsConf.AllowUnencryptedDOH
|
||||
newConf.TLSAllowUnencryptedDoH = tlsConf.AllowUnencryptedDoH
|
||||
|
||||
newConf.FilterHandler = applyAdditionalFiltering
|
||||
newConf.GetCustomUpstreamByClient = Context.clients.findUpstreams
|
||||
|
||||
@@ -48,7 +48,7 @@ type homeContext struct {
|
||||
queryLog querylog.QueryLog // query log module
|
||||
dnsServer *dnsforward.Server // DNS module
|
||||
rdns *RDNS // rDNS module
|
||||
whois *Whois // WHOIS module
|
||||
whois *WHOIS // WHOIS module
|
||||
dnsFilter *filtering.DNSFilter // DNS filtering module
|
||||
dhcpServer *dhcpd.Server // DHCP module
|
||||
auth *Auth // HTTP authentication module
|
||||
|
||||
@@ -163,10 +163,10 @@ func handleMobileConfig(w http.ResponseWriter, r *http.Request, dnsp string) {
|
||||
_, _ = w.Write(mobileconfig)
|
||||
}
|
||||
|
||||
func handleMobileConfigDOH(w http.ResponseWriter, r *http.Request) {
|
||||
func handleMobileConfigDoH(w http.ResponseWriter, r *http.Request) {
|
||||
handleMobileConfig(w, r, dnsProtoHTTPS)
|
||||
}
|
||||
|
||||
func handleMobileConfigDOT(w http.ResponseWriter, r *http.Request) {
|
||||
func handleMobileConfigDoT(w http.ResponseWriter, r *http.Request) {
|
||||
handleMobileConfig(w, r, dnsProtoTLS)
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ import (
|
||||
"howett.net/plist"
|
||||
)
|
||||
|
||||
func TestHandleMobileConfigDOH(t *testing.T) {
|
||||
func TestHandleMobileConfigDoH(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/doh.mobileconfig?host=example.org", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
handleMobileConfigDOH(w, r)
|
||||
handleMobileConfigDoH(w, r)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
var mc mobileConfig
|
||||
@@ -49,7 +49,7 @@ func TestHandleMobileConfigDOH(t *testing.T) {
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
handleMobileConfigDOH(w, r)
|
||||
handleMobileConfigDoH(w, r)
|
||||
assert.Equal(t, http.StatusInternalServerError, w.Code)
|
||||
assert.JSONEq(t, w.Body.String(), b.String())
|
||||
})
|
||||
@@ -60,7 +60,7 @@ func TestHandleMobileConfigDOH(t *testing.T) {
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
handleMobileConfigDOH(w, r)
|
||||
handleMobileConfigDoH(w, r)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
var mc mobileConfig
|
||||
@@ -74,14 +74,14 @@ func TestHandleMobileConfigDOH(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestHandleMobileConfigDOT(t *testing.T) {
|
||||
func TestHandleMobileConfigDoT(t *testing.T) {
|
||||
t.Run("success", func(t *testing.T) {
|
||||
r, err := http.NewRequest(http.MethodGet, "https://example.com:12345/apple/dot.mobileconfig?host=example.org", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
handleMobileConfigDOT(w, r)
|
||||
handleMobileConfigDoT(w, r)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
var mc mobileConfig
|
||||
@@ -111,7 +111,7 @@ func TestHandleMobileConfigDOT(t *testing.T) {
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
handleMobileConfigDOT(w, r)
|
||||
handleMobileConfigDoT(w, r)
|
||||
assert.Equal(t, http.StatusInternalServerError, w.Code)
|
||||
|
||||
assert.JSONEq(t, w.Body.String(), b.String())
|
||||
@@ -123,7 +123,7 @@ func TestHandleMobileConfigDOT(t *testing.T) {
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
handleMobileConfigDOT(w, r)
|
||||
handleMobileConfigDoT(w, r)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
var mc mobileConfig
|
||||
|
||||
@@ -48,7 +48,7 @@ func tlsCreate(conf tlsConfigSettings) *TLSMod {
|
||||
PortHTTPS: conf.PortHTTPS,
|
||||
PortDNSOverTLS: conf.PortDNSOverTLS,
|
||||
PortDNSOverQUIC: conf.PortDNSOverQUIC,
|
||||
AllowUnencryptedDOH: conf.AllowUnencryptedDOH,
|
||||
AllowUnencryptedDoH: conf.AllowUnencryptedDoH,
|
||||
}}
|
||||
}
|
||||
t.setCertFileTime()
|
||||
|
||||
@@ -23,8 +23,8 @@ const (
|
||||
whoisTTL = 1 * 60 * 60 // 1 hour
|
||||
)
|
||||
|
||||
// Whois - module context
|
||||
type Whois struct {
|
||||
// WHOIS - module context
|
||||
type WHOIS struct {
|
||||
clients *clientsContainer
|
||||
ipChan chan net.IP
|
||||
|
||||
@@ -41,9 +41,9 @@ type Whois struct {
|
||||
timeoutMsec uint
|
||||
}
|
||||
|
||||
// initWhois creates the Whois module context.
|
||||
func initWhois(clients *clientsContainer) *Whois {
|
||||
w := Whois{
|
||||
// initWHOIS creates the WHOIS module context.
|
||||
func initWHOIS(clients *clientsContainer) *WHOIS {
|
||||
w := WHOIS{
|
||||
timeoutMsec: 5000,
|
||||
clients: clients,
|
||||
ipAddrs: cache.New(cache.Config{
|
||||
@@ -67,8 +67,8 @@ func trimValue(s string) string {
|
||||
return s[:maxValueLength-3] + "..."
|
||||
}
|
||||
|
||||
// isWhoisComment returns true if the string is empty or is a WHOIS comment.
|
||||
func isWhoisComment(s string) (ok bool) {
|
||||
// isWHOISComment returns true if the string is empty or is a WHOIS comment.
|
||||
func isWHOISComment(s string) (ok bool) {
|
||||
return len(s) == 0 || s[0] == '#' || s[0] == '%'
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func whoisParse(data string) (m strmap) {
|
||||
var orgname string
|
||||
lines := strings.Split(data, "\n")
|
||||
for _, l := range lines {
|
||||
if isWhoisComment(l) {
|
||||
if isWHOISComment(l) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func whoisParse(data string) (m strmap) {
|
||||
const MaxConnReadSize = 64 * 1024
|
||||
|
||||
// Send request to a server and receive the response
|
||||
func (w *Whois) query(ctx context.Context, target, serverAddr string) (data string, err error) {
|
||||
func (w *WHOIS) query(ctx context.Context, target, serverAddr string) (data string, err error) {
|
||||
addr, _, _ := net.SplitHostPort(serverAddr)
|
||||
if addr == "whois.arin.net" {
|
||||
target = "n + " + target
|
||||
@@ -162,7 +162,7 @@ func (w *Whois) query(ctx context.Context, target, serverAddr string) (data stri
|
||||
}
|
||||
|
||||
// Query WHOIS servers (handle redirects)
|
||||
func (w *Whois) queryAll(ctx context.Context, target string) (string, error) {
|
||||
func (w *WHOIS) queryAll(ctx context.Context, target string) (string, error) {
|
||||
server := net.JoinHostPort(defaultServer, defaultPort)
|
||||
const maxRedirects = 5
|
||||
for i := 0; i != maxRedirects; i++ {
|
||||
@@ -170,7 +170,7 @@ func (w *Whois) queryAll(ctx context.Context, target string) (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
log.Debug("Whois: received response (%d bytes) from %s IP:%s", len(resp), server, target)
|
||||
log.Debug("whois: received response (%d bytes) from %s IP:%s", len(resp), server, target)
|
||||
|
||||
m := whoisParse(resp)
|
||||
redir, ok := m["whois"]
|
||||
@@ -186,25 +186,25 @@ func (w *Whois) queryAll(ctx context.Context, target string) (string, error) {
|
||||
server = redir
|
||||
}
|
||||
|
||||
log.Debug("Whois: redirected to %s IP:%s", redir, target)
|
||||
log.Debug("whois: redirected to %s IP:%s", redir, target)
|
||||
}
|
||||
return "", fmt.Errorf("whois: redirect loop")
|
||||
}
|
||||
|
||||
// Request WHOIS information
|
||||
func (w *Whois) process(ctx context.Context, ip net.IP) (wi *RuntimeClientWhoisInfo) {
|
||||
func (w *WHOIS) process(ctx context.Context, ip net.IP) (wi *RuntimeClientWHOISInfo) {
|
||||
resp, err := w.queryAll(ctx, ip.String())
|
||||
if err != nil {
|
||||
log.Debug("Whois: error: %s IP:%s", err, ip)
|
||||
log.Debug("whois: error: %s IP:%s", err, ip)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debug("Whois: IP:%s response: %d bytes", ip, len(resp))
|
||||
log.Debug("whois: IP:%s response: %d bytes", ip, len(resp))
|
||||
|
||||
m := whoisParse(resp)
|
||||
|
||||
wi = &RuntimeClientWhoisInfo{
|
||||
wi = &RuntimeClientWHOISInfo{
|
||||
City: m["city"],
|
||||
Country: m["country"],
|
||||
Orgname: m["orgname"],
|
||||
@@ -212,7 +212,7 @@ func (w *Whois) process(ctx context.Context, ip net.IP) (wi *RuntimeClientWhoisI
|
||||
|
||||
// Don't return an empty struct so that the frontend doesn't get
|
||||
// confused.
|
||||
if *wi == (RuntimeClientWhoisInfo{}) {
|
||||
if *wi == (RuntimeClientWHOISInfo{}) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ func (w *Whois) process(ctx context.Context, ip net.IP) (wi *RuntimeClientWhoisI
|
||||
}
|
||||
|
||||
// Begin - begin requesting WHOIS info
|
||||
func (w *Whois) Begin(ip net.IP) {
|
||||
func (w *WHOIS) Begin(ip net.IP) {
|
||||
now := uint64(time.Now().Unix())
|
||||
expire := w.ipAddrs.Get([]byte(ip))
|
||||
if len(expire) != 0 {
|
||||
@@ -234,18 +234,18 @@ func (w *Whois) Begin(ip net.IP) {
|
||||
binary.BigEndian.PutUint64(expire, now+whoisTTL)
|
||||
_ = w.ipAddrs.Set([]byte(ip), expire)
|
||||
|
||||
log.Debug("Whois: adding %s", ip)
|
||||
log.Debug("whois: adding %s", ip)
|
||||
select {
|
||||
case w.ipChan <- ip:
|
||||
//
|
||||
default:
|
||||
log.Debug("Whois: queue is full")
|
||||
log.Debug("whois: queue is full")
|
||||
}
|
||||
}
|
||||
|
||||
// workerLoop processes the IP addresses it got from the channel and associates
|
||||
// the retrieving WHOIS info with a client.
|
||||
func (w *Whois) workerLoop() {
|
||||
func (w *WHOIS) workerLoop() {
|
||||
for ip := range w.ipChan {
|
||||
info := w.process(context.Background(), ip)
|
||||
if info == nil {
|
||||
@@ -253,6 +253,6 @@ func (w *Whois) workerLoop() {
|
||||
}
|
||||
|
||||
id := ip.String()
|
||||
w.clients.SetWhoisInfo(id, info)
|
||||
w.clients.SetWHOISInfo(id, info)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func (c *fakeConn) fakeDial(ctx context.Context, network, addr string) (conn net
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func TestWhois(t *testing.T) {
|
||||
func TestWHOIS(t *testing.T) {
|
||||
const (
|
||||
nl = "\n"
|
||||
data = `OrgName: FakeOrg LLC` + nl +
|
||||
@@ -62,7 +62,7 @@ func TestWhois(t *testing.T) {
|
||||
data: []byte(data),
|
||||
}
|
||||
|
||||
w := Whois{
|
||||
w := WHOIS{
|
||||
timeoutMsec: 5000,
|
||||
dialContext: fc.fakeDial,
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func TestWhois(t *testing.T) {
|
||||
assert.Equal(t, "Nonreal", m["city"])
|
||||
}
|
||||
|
||||
func TestWhoisParse(t *testing.T) {
|
||||
func TestWHOISParse(t *testing.T) {
|
||||
const (
|
||||
city = "Nonreal"
|
||||
country = "Imagiland"
|
||||
|
||||
Reference in New Issue
Block a user