router.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. Rules() []Rule
  32. SetTrafficController(controller TrafficController)
  33. }
  34. type Rule interface {
  35. Service
  36. Type() string
  37. UpdateGeosite() error
  38. Match(metadata *InboundContext) bool
  39. Outbound() string
  40. String() string
  41. }
  42. type DNSRule interface {
  43. Rule
  44. DisableCache() bool
  45. }