router.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. mdns "github.com/miekg/dns"
  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 *mdns.Msg) (*mdns.Msg, 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. ClashServer() ClashServer
  34. SetClashServer(controller ClashServer)
  35. }
  36. type Rule interface {
  37. Service
  38. Type() string
  39. UpdateGeosite() error
  40. Match(metadata *InboundContext) bool
  41. Outbound() string
  42. String() string
  43. }
  44. type DNSRule interface {
  45. Rule
  46. DisableCache() bool
  47. }