experimental.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. StoreSelected() bool
  13. StoreFakeIP() bool
  14. CacheFile() ClashCacheFile
  15. HistoryStorage() *urltest.HistoryStorage
  16. RoutedConnection(ctx context.Context, conn net.Conn, metadata InboundContext, matchedRule Rule) (net.Conn, Tracker)
  17. RoutedPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext, matchedRule Rule) (N.PacketConn, Tracker)
  18. }
  19. type ClashCacheFile interface {
  20. LoadSelected(group string) string
  21. StoreSelected(group string, selected string) error
  22. FakeIPStorage
  23. }
  24. type Tracker interface {
  25. Leave()
  26. }
  27. type OutboundGroup interface {
  28. Now() string
  29. All() []string
  30. }
  31. func OutboundTag(detour Outbound) string {
  32. if group, isGroup := detour.(OutboundGroup); isGroup {
  33. return group.Now()
  34. }
  35. return detour.Tag()
  36. }
  37. type V2RayServer interface {
  38. Service
  39. StatsService() V2RayStatsService
  40. }
  41. type V2RayStatsService interface {
  42. RoutedConnection(inbound string, outbound string, user string, conn net.Conn) net.Conn
  43. RoutedPacketConnection(inbound string, outbound string, user string, conn N.PacketConn) N.PacketConn
  44. }