resolved.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package option
  2. import (
  3. "context"
  4. "net/netip"
  5. "github.com/sagernet/sing/common"
  6. "github.com/sagernet/sing/common/json"
  7. "github.com/sagernet/sing/common/json/badoption"
  8. )
  9. type _ResolvedServiceOptions struct {
  10. ListenOptions
  11. }
  12. type ResolvedServiceOptions _ResolvedServiceOptions
  13. func (r ResolvedServiceOptions) MarshalJSONContext(ctx context.Context) ([]byte, error) {
  14. if r.Listen != nil && netip.Addr(*r.Listen) == (netip.AddrFrom4([4]byte{127, 0, 0, 53})) {
  15. r.Listen = nil
  16. }
  17. if r.ListenPort == 53 {
  18. r.ListenPort = 0
  19. }
  20. return json.MarshalContext(ctx, (*_ResolvedServiceOptions)(&r))
  21. }
  22. func (r *ResolvedServiceOptions) UnmarshalJSONContext(ctx context.Context, bytes []byte) error {
  23. err := json.UnmarshalContextDisallowUnknownFields(ctx, bytes, (*_ResolvedServiceOptions)(r))
  24. if err != nil {
  25. return err
  26. }
  27. if r.Listen == nil {
  28. r.Listen = (*badoption.Addr)(common.Ptr(netip.AddrFrom4([4]byte{127, 0, 0, 53})))
  29. }
  30. if r.ListenPort == 0 {
  31. r.ListenPort = 53
  32. }
  33. return nil
  34. }
  35. type ResolvedDNSServerOptions struct {
  36. Service string `json:"service"`
  37. AcceptDefaultResolvers bool `json:"accept_default_resolvers,omitempty"`
  38. // NDots int `json:"ndots,omitempty"`
  39. // Timeout badoption.Duration `json:"timeout,omitempty"`
  40. // Attempts int `json:"attempts,omitempty"`
  41. // Rotate bool `json:"rotate,omitempty"`
  42. }