Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryLog Interface #5099

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 16.14.2
6 changes: 3 additions & 3 deletions internal/dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/querylog/logs"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream"
Expand Down Expand Up @@ -68,7 +68,7 @@ type Server struct {
dnsProxy *proxy.Proxy // DNS proxy instance
dnsFilter *filtering.DNSFilter // DNS filter instance
dhcpServer dhcpd.Interface // DHCP server instance (optional)
queryLog querylog.QueryLog // Query log instance
queryLog logs.Api // Query log instance
stats stats.Interface
access *accessManager

Expand Down Expand Up @@ -116,7 +116,7 @@ const defaultLocalDomainSuffix = "lan"
type DNSCreateParams struct {
DNSFilter *filtering.DNSFilter
Stats stats.Interface
QueryLog querylog.QueryLog
QueryLog logs.Api
DHCPServer dhcpd.Interface
PrivateNets netutil.SubnetSet
Anonymizer *aghnet.IPMut
Expand Down
12 changes: 6 additions & 6 deletions internal/dnsforward/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/querylog/logs"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/golibs/log"
Expand Down Expand Up @@ -59,7 +59,7 @@ func (s *Server) logQuery(
elapsed time.Duration,
ip net.IP,
) {
p := &querylog.AddParams{
p := &logs.AddParams{
Question: pctx.Req,
ReqECS: pctx.ReqECS,
Answer: pctx.Res,
Expand All @@ -73,13 +73,13 @@ func (s *Server) logQuery(

switch pctx.Proto {
case proxy.ProtoHTTPS:
p.ClientProto = querylog.ClientProtoDoH
p.ClientProto = logs.ClientProtoDoH
case proxy.ProtoQUIC:
p.ClientProto = querylog.ClientProtoDoQ
p.ClientProto = logs.ClientProtoDoQ
case proxy.ProtoTLS:
p.ClientProto = querylog.ClientProtoDoT
p.ClientProto = logs.ClientProtoDoT
case proxy.ProtoDNSCrypt:
p.ClientProto = querylog.ClientProtoDNSCrypt
p.ClientProto = logs.ClientProtoDNSCrypt
default:
// Consider this a plain DNS-over-UDP or DNS-over-TCP request.
}
Expand Down
24 changes: 12 additions & 12 deletions internal/home/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/querylog/logs"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/dnsproxy/upstream"
"github.com/AdguardTeam/golibs/errors"
Expand Down Expand Up @@ -351,12 +351,12 @@ func (clients *clientsContainer) exists(ip net.IP, source clientSource) (ok bool
return source <= rc.Source
}

func toQueryLogWHOIS(wi *RuntimeClientWHOISInfo) (cw *querylog.ClientWHOIS) {
func toQueryLogWHOIS(wi *RuntimeClientWHOISInfo) (cw *logs.ClientWHOIS) {
if wi == nil {
return &querylog.ClientWHOIS{}
return &logs.ClientWHOIS{}
}

return &querylog.ClientWHOIS{
return &logs.ClientWHOIS{
City: wi.City,
Country: wi.Country,
Orgname: wi.Orgname,
Expand All @@ -367,8 +367,8 @@ func toQueryLogWHOIS(wi *RuntimeClientWHOISInfo) (cw *querylog.ClientWHOIS) {
// the query log. c is never nil; if no information about the client is found,
// it returns an artificial client record by only setting the blocking-related
// fields. err is always nil.
func (clients *clientsContainer) findMultiple(ids []string) (c *querylog.Client, err error) {
var artClient *querylog.Client
func (clients *clientsContainer) findMultiple(ids []string) (c *logs.Client, err error) {
var artClient *logs.Client
var art bool
for _, id := range ids {
c, art = clients.clientOrArtificial(net.ParseIP(id), id)
Expand All @@ -391,38 +391,38 @@ func (clients *clientsContainer) findMultiple(ids []string) (c *querylog.Client,
func (clients *clientsContainer) clientOrArtificial(
ip net.IP,
id string,
) (c *querylog.Client, art bool) {
) (c *logs.Client, art bool) {
defer func() {
c.Disallowed, c.DisallowedRule = clients.dnsServer.IsBlockedClient(ip, id)
if c.WHOIS == nil {
c.WHOIS = &querylog.ClientWHOIS{}
c.WHOIS = &logs.ClientWHOIS{}
}
}()

client, ok := clients.Find(id)
if ok {
return &querylog.Client{
return &logs.Client{
Name: client.Name,
}, false
}

if ip == nil {
// Technically should never happen, but still.
return &querylog.Client{
return &logs.Client{
Name: "",
}, true
}

var rc *RuntimeClient
rc, ok = clients.findRuntimeClient(ip)
if ok {
return &querylog.Client{
return &logs.Client{
Name: rc.Host,
WHOIS: toQueryLogWHOIS(rc.WHOISInfo),
}, false
}

return &querylog.Client{
return &logs.Client{
Name: "",
}, true
}
Expand Down
4 changes: 2 additions & 2 deletions internal/home/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/querylog/logs"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/dnsproxy/fastip"
"github.com/AdguardTeam/golibs/errors"
Expand Down Expand Up @@ -454,7 +454,7 @@ func (c *configuration) write() (err error) {
}

if Context.queryLog != nil {
dc := querylog.Config{}
dc := logs.Config{}
Context.queryLog.WriteDiskConfig(&dc)
config.DNS.QueryLogEnabled = dc.Enabled
config.DNS.QueryLogFileEnabled = dc.FileEnabled
Expand Down
10 changes: 6 additions & 4 deletions internal/home/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/querylog/jsonfile"
"github.com/AdguardTeam/AdGuardHome/internal/querylog/logs"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/dnsproxy/proxy"
"github.com/AdguardTeam/golibs/errors"
Expand Down Expand Up @@ -46,7 +47,7 @@ func initDNSServer() (err error) {

var anonFunc aghnet.IPMutFunc
if config.DNS.AnonymizeClientIP {
anonFunc = querylog.AnonymizeIP
anonFunc = logs.AnonymizeIP
}
anonymizer := aghnet.NewIPMut(anonFunc)

Expand All @@ -61,7 +62,7 @@ func initDNSServer() (err error) {
return fmt.Errorf("init stats: %w", err)
}

conf := querylog.Config{
conf := logs.Config{
Anonymizer: anonymizer,
ConfigModified: onConfigModified,
HTTPRegister: httpRegister,
Expand All @@ -73,7 +74,8 @@ func initDNSServer() (err error) {
FileEnabled: config.DNS.QueryLogFileEnabled,
AnonymizeClientIP: config.DNS.AnonymizeClientIP,
}
Context.queryLog = querylog.New(conf)
Context.queryLog = jsonfile.New(conf)
logs.RegisterHTTP(Context.queryLog, httpRegister)

Context.filters, err = filtering.New(config.DNS.DnsfilterConf, nil)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/dhcpd"
"github.com/AdguardTeam/AdGuardHome/internal/dnsforward"
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
"github.com/AdguardTeam/AdGuardHome/internal/querylog"
"github.com/AdguardTeam/AdGuardHome/internal/querylog/logs"
"github.com/AdguardTeam/AdGuardHome/internal/stats"
"github.com/AdguardTeam/AdGuardHome/internal/updater"
"github.com/AdguardTeam/AdGuardHome/internal/version"
Expand All @@ -51,7 +51,7 @@ type homeContext struct {

clients clientsContainer // per-client-settings module
stats stats.Interface // statistics module
queryLog querylog.QueryLog // query log module
queryLog logs.Api // query log module
dnsServer *dnsforward.Server // DNS module
rdns *RDNS // rDNS module
whois *WHOIS // WHOIS module
Expand Down
32 changes: 0 additions & 32 deletions internal/querylog/client.go

This file was deleted.

Loading