experimental.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package adapter
  2. import (
  3. "context"
  4. "net"
  5. "github.com/sagernet/sing-box/common/urltest"
  6. N "github.com/sagernet/sing/common/network"
  7. )
  8. type ClashServer interface {
  9. Service
  10. PreStarter
  11. Mode() string
  12. ModeList() []string
  13. StoreSelected() bool
  14. StoreFakeIP() bool
  15. CacheFile() ClashCacheFile
  16. HistoryStorage() *urltest.HistoryStorage
  17. RoutedConnection(ctx context.Context, conn net.Conn, metadata InboundContext, matchedRule Rule) (net.Conn, Tracker)
  18. RoutedPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext, matchedRule Rule) (N.PacketConn, Tracker)
  19. }
  20. type ClashCacheFile interface {
  21. LoadMode() string
  22. StoreMode(mode string) error
  23. LoadSelected(group string) string
  24. StoreSelected(group string, selected string) error
  25. LoadGroupExpand(group string) (isExpand bool, loaded bool)
  26. StoreGroupExpand(group string, expand bool) error
  27. FakeIPStorage
  28. }
  29. type Tracker interface {
  30. Leave()
  31. }
  32. type OutboundGroup interface {
  33. Outbound
  34. Now() string
  35. All() []string
  36. }
  37. type URLTestGroup interface {
  38. OutboundGroup
  39. URLTest(ctx context.Context, url string) (map[string]uint16, error)
  40. }
  41. func OutboundTag(detour Outbound) string {
  42. if group, isGroup := detour.(OutboundGroup); isGroup {
  43. return group.Now()
  44. }
  45. return detour.Tag()
  46. }
  47. type V2RayServer interface {
  48. Service
  49. StatsService() V2RayStatsService
  50. }
  51. type V2RayStatsService interface {
  52. RoutedConnection(inbound string, outbound string, user string, conn net.Conn) net.Conn
  53. RoutedPacketConnection(inbound string, outbound string, user string, conn N.PacketConn) N.PacketConn
  54. }