experimental.go 1.2 KB

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