github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/adapter/experimental.go (about)

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