Add v2ray QUIC transport

This commit is contained in:
世界 2022-08-22 21:20:05 +08:00
parent 77c98fd042
commit d4b7e221f0
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
22 changed files with 336 additions and 25 deletions

23
transport/v2ray/quic.go Normal file
View file

@ -0,0 +1,23 @@
//go:build with_quic
package v2ray
import (
"context"
"crypto/tls"
"github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-box/transport/v2rayquic"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
)
func NewQUICServer(ctx context.Context, options option.V2RayQUICOptions, tlsConfig *tls.Config, handler N.TCPConnectionHandler, errorHandler E.Handler) (adapter.V2RayServerTransport, error) {
return v2rayquic.NewServer(ctx, options, tlsConfig, handler, errorHandler), nil
}
func NewQUICClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, options option.V2RayQUICOptions, tlsConfig *tls.Config) (adapter.V2RayClientTransport, error) {
return v2rayquic.NewClient(ctx, dialer, serverAddr, options, tlsConfig), nil
}

View file

@ -0,0 +1,23 @@
//go:build !with_quic
package v2ray
import (
"context"
"crypto/tls"
"github.com/sagernet/sing-box/adapter"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
)
func NewQUICServer(ctx context.Context, options option.V2RayQUICOptions, tlsConfig *tls.Config, handler N.TCPConnectionHandler, errorHandler E.Handler) (adapter.V2RayServerTransport, error) {
return nil, C.ErrQUICNotIncluded
}
func NewQUICClient(ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr, options option.V2RayQUICOptions, tlsConfig *tls.Config) (adapter.V2RayClientTransport, error) {
return nil, C.ErrQUICNotIncluded
}

View file

@ -22,6 +22,8 @@ func NewServerTransport(ctx context.Context, options option.V2RayTransportOption
return NewGRPCServer(ctx, options.GRPCOptions, tlsConfig, handler)
case C.V2RayTransportTypeWebsocket:
return v2raywebsocket.NewServer(ctx, options.WebsocketOptions, tlsConfig, handler, errorHandler), nil
case C.V2RayTransportTypeQUIC:
return NewQUICServer(ctx, options.QUICOptions, tlsConfig, handler, errorHandler)
default:
return nil, E.New("unknown transport type: " + options.Type)
}
@ -36,6 +38,8 @@ func NewClientTransport(ctx context.Context, dialer N.Dialer, serverAddr M.Socks
return NewGRPCClient(ctx, dialer, serverAddr, options.GRPCOptions, tlsConfig)
case C.V2RayTransportTypeWebsocket:
return v2raywebsocket.NewClient(ctx, dialer, serverAddr, options.WebsocketOptions, tlsConfig), nil
case C.V2RayTransportTypeQUIC:
return NewQUICClient(ctx, dialer, serverAddr, options.QUICOptions, tlsConfig)
default:
return nil, E.New("unknown transport type: " + options.Type)
}