router.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. InterfaceFinder() control.InterfaceFinder
  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(server ClashServer)
  35. V2RayServer() V2RayServer
  36. SetV2RayServer(server V2RayServer)
  37. }
  38. type Rule interface {
  39. Service
  40. Type() string
  41. UpdateGeosite() error
  42. Match(metadata *InboundContext) bool
  43. Outbound() string
  44. String() string
  45. }
  46. type DNSRule interface {
  47. Rule
  48. DisableCache() bool
  49. }