Use separate DNSRequestContext struct for adding DNS context to connections
This commit is contained in:
@@ -44,8 +44,8 @@ type ResolvedDomain struct {
|
||||
// information.
|
||||
Resolver *ResolverInfo
|
||||
|
||||
// RRCache holds the DNS response that was received for this domain.
|
||||
RRCache *RRCache
|
||||
// DNSRequestContext holds the DNS request context.
|
||||
DNSRequestContext *DNSRequestContext
|
||||
|
||||
// Expires holds the timestamp when this entry expires.
|
||||
// This does not mean that the entry may not be used anymore afterwards,
|
||||
|
||||
39
resolver/rr_context.go
Normal file
39
resolver/rr_context.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package resolver
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// DNSRequestContext is a static structure to add information to DNS request connections.
|
||||
type DNSRequestContext struct {
|
||||
Domain string
|
||||
Question string
|
||||
RCode string
|
||||
|
||||
ServedFromCache bool
|
||||
RequestingNew bool
|
||||
IsBackup bool
|
||||
Filtered bool
|
||||
|
||||
Modified time.Time
|
||||
Expires time.Time
|
||||
}
|
||||
|
||||
// ToDNSRequestContext returns a new DNSRequestContext of the RRCache.
|
||||
func (rrCache *RRCache) ToDNSRequestContext() *DNSRequestContext {
|
||||
return &DNSRequestContext{
|
||||
Domain: rrCache.Domain,
|
||||
Question: rrCache.Question.String(),
|
||||
RCode: dns.RcodeToString[rrCache.RCode],
|
||||
|
||||
ServedFromCache: rrCache.ServedFromCache,
|
||||
RequestingNew: rrCache.RequestingNew,
|
||||
IsBackup: rrCache.IsBackup,
|
||||
Filtered: rrCache.Filtered,
|
||||
|
||||
Modified: time.Unix(rrCache.Modified, 0),
|
||||
Expires: time.Unix(rrCache.Expires, 0),
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package resolver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
@@ -45,25 +44,6 @@ type RRCache struct {
|
||||
Modified int64
|
||||
}
|
||||
|
||||
func (rrCache *RRCache) MarshalJSON() ([]byte, error) {
|
||||
var record = struct {
|
||||
RRCache
|
||||
|
||||
Question string
|
||||
RCode string
|
||||
Modified time.Time
|
||||
Expires time.Time
|
||||
}{
|
||||
RRCache: *rrCache,
|
||||
Question: rrCache.Question.String(),
|
||||
RCode: dns.RcodeToString[rrCache.RCode],
|
||||
Modified: time.Unix(rrCache.Modified, 0),
|
||||
Expires: time.Unix(rrCache.Expires, 0),
|
||||
}
|
||||
|
||||
return json.Marshal(record)
|
||||
}
|
||||
|
||||
// ID returns the ID of the RRCache consisting of the domain and question type.
|
||||
func (rrCache *RRCache) ID() string {
|
||||
return rrCache.Domain + rrCache.Question.String()
|
||||
|
||||
Reference in New Issue
Block a user