-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into AG-20200-translation-script-update-auto
- Loading branch information
Showing
6 changed files
with
220 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package querylog | ||
|
||
import ( | ||
"net" | ||
"time" | ||
|
||
"github.com/AdguardTeam/AdGuardHome/internal/filtering" | ||
"github.com/AdguardTeam/golibs/errors" | ||
"github.com/AdguardTeam/golibs/log" | ||
"github.com/miekg/dns" | ||
) | ||
|
||
// logEntry represents a single entry in the file. | ||
type logEntry struct { | ||
// client is the found client information, if any. | ||
client *Client | ||
|
||
Time time.Time `json:"T"` | ||
|
||
QHost string `json:"QH"` | ||
QType string `json:"QT"` | ||
QClass string `json:"QC"` | ||
|
||
ReqECS string `json:"ECS,omitempty"` | ||
|
||
ClientID string `json:"CID,omitempty"` | ||
ClientProto ClientProto `json:"CP"` | ||
|
||
Upstream string `json:",omitempty"` | ||
|
||
Answer []byte `json:",omitempty"` | ||
OrigAnswer []byte `json:",omitempty"` | ||
|
||
IP net.IP `json:"IP"` | ||
|
||
Result filtering.Result | ||
|
||
Elapsed time.Duration | ||
|
||
Cached bool `json:",omitempty"` | ||
AuthenticatedData bool `json:"AD,omitempty"` | ||
} | ||
|
||
// shallowClone returns a shallow clone of e. | ||
func (e *logEntry) shallowClone() (clone *logEntry) { | ||
cloneVal := *e | ||
|
||
return &cloneVal | ||
} | ||
|
||
// addResponse adds data from resp to e.Answer if resp is not nil. If isOrig is | ||
// true, addResponse sets the e.OrigAnswer field instead of e.Answer. Any | ||
// errors are logged. | ||
func (e *logEntry) addResponse(resp *dns.Msg, isOrig bool) { | ||
if resp == nil { | ||
return | ||
} | ||
|
||
var err error | ||
if isOrig { | ||
e.Answer, err = resp.Pack() | ||
err = errors.Annotate(err, "packing answer: %w") | ||
} else { | ||
e.OrigAnswer, err = resp.Pack() | ||
err = errors.Annotate(err, "packing orig answer: %w") | ||
} | ||
if err != nil { | ||
log.Error("querylog: %s", err) | ||
} | ||
} |
Oops, something went wrong.