2021-01-23 14:49:46 +08:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
2023-03-14 21:18:09 +08:00
|
|
|
"github.com/gofrs/uuid/v5"
|
2021-01-23 14:49:46 +08:00
|
|
|
"github.com/miekg/dns"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
DNSTypeHost = "host"
|
|
|
|
DNSTypeFakeIP = "fakeip"
|
|
|
|
DNSTypeRaw = "raw"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DNSContext struct {
|
|
|
|
id uuid.UUID
|
|
|
|
msg *dns.Msg
|
|
|
|
tp string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDNSContext(msg *dns.Msg) *DNSContext {
|
|
|
|
id, _ := uuid.NewV4()
|
|
|
|
return &DNSContext{
|
|
|
|
id: id,
|
|
|
|
msg: msg,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ID implement C.PlainContext ID
|
|
|
|
func (c *DNSContext) ID() uuid.UUID {
|
|
|
|
return c.id
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetType set type of response
|
|
|
|
func (c *DNSContext) SetType(tp string) {
|
|
|
|
c.tp = tp
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type return type of response
|
|
|
|
func (c *DNSContext) Type() string {
|
|
|
|
return c.tp
|
|
|
|
}
|