dns.go 718 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package context
  2. import (
  3. "context"
  4. "github.com/metacubex/mihomo/common/utils"
  5. "github.com/gofrs/uuid/v5"
  6. "github.com/miekg/dns"
  7. )
  8. const (
  9. DNSTypeHost = "host"
  10. DNSTypeFakeIP = "fakeip"
  11. DNSTypeRaw = "raw"
  12. )
  13. type DNSContext struct {
  14. context.Context
  15. id uuid.UUID
  16. msg *dns.Msg
  17. tp string
  18. }
  19. func NewDNSContext(ctx context.Context, msg *dns.Msg) *DNSContext {
  20. return &DNSContext{
  21. Context: ctx,
  22. id: utils.NewUUIDV4(),
  23. msg: msg,
  24. }
  25. }
  26. // ID implement C.PlainContext ID
  27. func (c *DNSContext) ID() uuid.UUID {
  28. return c.id
  29. }
  30. // SetType set type of response
  31. func (c *DNSContext) SetType(tp string) {
  32. c.tp = tp
  33. }
  34. // Type return type of response
  35. func (c *DNSContext) Type() string {
  36. return c.tp
  37. }