github.com/sagernet/sing-box@v1.9.0-rc.20/transport/v2ray/quic.go (about) 1 package v2ray 2 3 import ( 4 "context" 5 "os" 6 7 "github.com/sagernet/sing-box/adapter" 8 "github.com/sagernet/sing-box/common/tls" 9 "github.com/sagernet/sing-box/option" 10 M "github.com/sagernet/sing/common/metadata" 11 N "github.com/sagernet/sing/common/network" 12 ) 13 14 var ( 15 quicServerConstructor ServerConstructor[option.V2RayQUICOptions] 16 quicClientConstructor ClientConstructor[option.V2RayQUICOptions] 17 ) 18 19 func RegisterQUICConstructor(server ServerConstructor[option.V2RayQUICOptions], client ClientConstructor[option.V2RayQUICOptions]) { 20 quicServerConstructor = server 21 quicClientConstructor = client 22 } 23 24 func NewQUICServer(ctx context.Context, options option.V2RayQUICOptions, tlsConfig tls.ServerConfig, handler adapter.V2RayServerTransportHandler) (adapter.V2RayServerTransport, error) { 25 if quicServerConstructor == nil { 26 return nil, os.ErrInvalid 27 } 28 return quicServerConstructor(ctx, options, tlsConfig, handler) 29 } 30 31 func NewQUICClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, options option.V2RayQUICOptions, tlsConfig tls.Config) (adapter.V2RayClientTransport, error) { 32 if quicClientConstructor == nil { 33 return nil, os.ErrInvalid 34 } 35 return quicClientConstructor(ctx, dialer, serverAddr, options, tlsConfig) 36 }