2021-01-23 14:49:46 +08:00
|
|
|
package context
|
|
|
|
|
|
|
|
import (
|
2022-11-12 13:18:36 +08:00
|
|
|
"context"
|
2023-11-03 21:01:45 +08:00
|
|
|
"github.com/metacubex/mihomo/common/utils"
|
2022-11-12 13:18:36 +08:00
|
|
|
|
2023-04-09 15:40:17 +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 {
|
2022-11-12 13:18:36 +08:00
|
|
|
context.Context
|
|
|
|
|
2021-01-23 14:49:46 +08:00
|
|
|
id uuid.UUID
|
|
|
|
msg *dns.Msg
|
|
|
|
tp string
|
|
|
|
}
|
|
|
|
|
2022-11-12 13:18:36 +08:00
|
|
|
func NewDNSContext(ctx context.Context, msg *dns.Msg) *DNSContext {
|
2021-01-23 14:49:46 +08:00
|
|
|
return &DNSContext{
|
2022-11-12 13:18:36 +08:00
|
|
|
Context: ctx,
|
|
|
|
|
2023-03-15 10:10:03 +08:00
|
|
|
id: utils.NewUUIDV4(),
|
2021-01-23 14:49:46 +08:00
|
|
|
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
|
|
|
|
}
|