outbound.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package adapter
  2. import (
  3. "context"
  4. "net/netip"
  5. "time"
  6. "github.com/sagernet/sing-box/log"
  7. "github.com/sagernet/sing-box/option"
  8. "github.com/sagernet/sing-tun"
  9. N "github.com/sagernet/sing/common/network"
  10. )
  11. // Note: for proxy protocols, outbound creates early connections by default.
  12. type Outbound interface {
  13. Type() string
  14. Tag() string
  15. Network() []string
  16. Dependencies() []string
  17. N.Dialer
  18. }
  19. type OutboundWithPreferredRoutes interface {
  20. Outbound
  21. PreferredDomain(domain string) bool
  22. PreferredAddress(address netip.Addr) bool
  23. }
  24. type DirectRouteOutbound interface {
  25. Outbound
  26. NewDirectRouteConnection(metadata InboundContext, routeContext tun.DirectRouteContext, timeout time.Duration) (tun.DirectRouteDestination, error)
  27. }
  28. type OutboundRegistry interface {
  29. option.OutboundOptionsRegistry
  30. CreateOutbound(ctx context.Context, router Router, logger log.ContextLogger, tag string, outboundType string, options any) (Outbound, error)
  31. }
  32. type OutboundManager interface {
  33. Lifecycle
  34. Outbounds() []Outbound
  35. Outbound(tag string) (Outbound, bool)
  36. Default() Outbound
  37. Remove(tag string) error
  38. Create(ctx context.Context, router Router, logger log.ContextLogger, tag string, outboundType string, options any) error
  39. }