router.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package adapter
  2. import (
  3. "context"
  4. "net"
  5. "net/netip"
  6. "github.com/sagernet/sing-box/common/geoip"
  7. "github.com/sagernet/sing-dns"
  8. "github.com/sagernet/sing-tun"
  9. "github.com/sagernet/sing/common/control"
  10. N "github.com/sagernet/sing/common/network"
  11. "golang.org/x/net/dns/dnsmessage"
  12. )
  13. type Router interface {
  14. Service
  15. Outbounds() []Outbound
  16. Outbound(tag string) (Outbound, bool)
  17. DefaultOutbound(network string) Outbound
  18. RouteConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
  19. RoutePacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
  20. GeoIPReader() *geoip.Reader
  21. LoadGeosite(code string) (Rule, error)
  22. Exchange(ctx context.Context, message *dnsmessage.Message) (*dnsmessage.Message, error)
  23. Lookup(ctx context.Context, domain string, strategy dns.DomainStrategy) ([]netip.Addr, error)
  24. LookupDefault(ctx context.Context, domain string) ([]netip.Addr, error)
  25. InterfaceBindManager() control.BindManager
  26. DefaultInterface() string
  27. AutoDetectInterface() bool
  28. DefaultMark() int
  29. NetworkMonitor() tun.NetworkUpdateMonitor
  30. InterfaceMonitor() tun.DefaultInterfaceMonitor
  31. PackageManager() tun.PackageManager
  32. Rules() []Rule
  33. SetTrafficController(controller TrafficController)
  34. }
  35. type Rule interface {
  36. Service
  37. Type() string
  38. UpdateGeosite() error
  39. Match(metadata *InboundContext) bool
  40. Outbound() string
  41. String() string
  42. }
  43. type DNSRule interface {
  44. Rule
  45. DisableCache() bool
  46. }