router.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/common/control"
  9. N "github.com/sagernet/sing/common/network"
  10. "golang.org/x/net/dns/dnsmessage"
  11. )
  12. type Router interface {
  13. Service
  14. Outbound(tag string) (Outbound, bool)
  15. DefaultOutbound(network string) Outbound
  16. RouteConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
  17. RoutePacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
  18. GeoIPReader() *geoip.Reader
  19. LoadGeosite(code string) (Rule, error)
  20. Exchange(ctx context.Context, message *dnsmessage.Message) (*dnsmessage.Message, error)
  21. Lookup(ctx context.Context, domain string, strategy dns.DomainStrategy) ([]netip.Addr, error)
  22. LookupDefault(ctx context.Context, domain string) ([]netip.Addr, error)
  23. InterfaceBindManager() control.BindManager
  24. DefaultInterface() string
  25. AutoDetectInterface() bool
  26. AutoDetectInterfaceName() string
  27. AutoDetectInterfaceIndex() int
  28. Rules() []Rule
  29. SetTrafficController(controller TrafficController)
  30. }
  31. type Rule interface {
  32. Service
  33. Type() string
  34. UpdateGeosite() error
  35. Match(metadata *InboundContext) bool
  36. Outbound() string
  37. String() string
  38. }