apply styles

This commit is contained in:
Shelikhoo 2023-05-30 14:52:29 +01:00
parent b7e8554ee3
commit 1f8e71fe5c
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316
5 changed files with 28 additions and 18 deletions

View File

@ -34,7 +34,8 @@ func (s *simpleAssemblerClient) NewSession(ctx context.Context, opts ...request.
sessionContext, finish := context.WithCancel(ctx) sessionContext, finish := context.WithCancel(ctx)
session := &simpleAssemblerClientSession{ session := &simpleAssemblerClientSession{
sessionID: sessionID, tripper: s.assembly.Tripper(), readBuffer: bytes.NewBuffer(nil), sessionID: sessionID, tripper: s.assembly.Tripper(), readBuffer: bytes.NewBuffer(nil),
ctx: sessionContext, finish: finish, writerChan: make(chan []byte), readerChan: make(chan []byte, 16), assembler: s} ctx: sessionContext, finish: finish, writerChan: make(chan []byte), readerChan: make(chan []byte, 16), assembler: s,
}
go session.keepRunning() go session.keepRunning()
return session, nil return session, nil
} }

View File

@ -18,6 +18,7 @@ import (
) )
func newHTTPRoundTripperClient(ctx context.Context, config *ClientConfig) request.RoundTripperClient { func newHTTPRoundTripperClient(ctx context.Context, config *ClientConfig) request.RoundTripperClient {
_ = ctx
return &httpTripperClient{config: config} return &httpTripperClient{config: config}
} }
@ -27,8 +28,7 @@ type httpTripperClient struct {
assembly request.TransportClientAssembly assembly request.TransportClientAssembly
} }
type unimplementedBackDrop struct { type unimplementedBackDrop struct{}
}
func (u unimplementedBackDrop) RoundTrip(r *http.Request) (*http.Response, error) { func (u unimplementedBackDrop) RoundTrip(r *http.Request) (*http.Response, error) {
return nil, newError("unimplemented") return nil, newError("unimplemented")

View File

@ -36,9 +36,10 @@ func meekDial(ctx context.Context, dest net.Destination, streamSettings *interne
BackoffFactor: 1.5, BackoffFactor: 1.5,
FailedRetryIntervalMs: 1000, FailedRetryIntervalMs: 1000,
} }
httprtSetting := &httprt.ClientConfig{Http: &httprt.HTTPConfig{ httprtSetting := &httprt.ClientConfig{
UrlPrefix: meekSetting.Url, Http: &httprt.HTTPConfig{
}, UrlPrefix: meekSetting.Url,
},
} }
request := &assembly.Config{ request := &assembly.Config{
Assembler: serial.ToTypedMessage(simpleAssembler), Assembler: serial.ToTypedMessage(simpleAssembler),

View File

@ -10,8 +10,9 @@ import (
"sync" "sync"
"time" "time"
"github.com/v2fly/v2ray-core/v5/transport/internet/security"
"golang.org/x/net/http2" "golang.org/x/net/http2"
"github.com/v2fly/v2ray-core/v5/transport/internet/security"
) )
type DialerFunc func(ctx context.Context, addr string) (net.Conn, error) type DialerFunc func(ctx context.Context, addr string) (net.Conn, error)
@ -19,7 +20,8 @@ type DialerFunc func(ctx context.Context, addr string) (net.Conn, error)
// NewALPNAwareHTTPRoundTripper creates an instance of RoundTripper that dial to remote HTTPS endpoint with // NewALPNAwareHTTPRoundTripper creates an instance of RoundTripper that dial to remote HTTPS endpoint with
// an alternative version of TLS implementation. // an alternative version of TLS implementation.
func NewALPNAwareHTTPRoundTripper(ctx context.Context, dialer DialerFunc, func NewALPNAwareHTTPRoundTripper(ctx context.Context, dialer DialerFunc,
backdropTransport http.RoundTripper) http.RoundTripper { backdropTransport http.RoundTripper,
) http.RoundTripper {
rtImpl := &alpnAwareHTTPRoundTripperImpl{ rtImpl := &alpnAwareHTTPRoundTripperImpl{
connectWithH1: map[string]bool{}, connectWithH1: map[string]bool{},
backdropTransport: backdropTransport, backdropTransport: backdropTransport,
@ -51,9 +53,11 @@ type pendingConnKey struct {
dest string dest string
} }
var errEAGAIN = errors.New("incorrect ALPN negotiated, try again with another ALPN") var (
var errEAGAINTooMany = errors.New("incorrect ALPN negotiated") errEAGAIN = errors.New("incorrect ALPN negotiated, try again with another ALPN")
var errExpired = errors.New("connection have expired") errEAGAINTooMany = errors.New("incorrect ALPN negotiated")
errExpired = errors.New("connection have expired")
)
func (r *alpnAwareHTTPRoundTripperImpl) RoundTrip(req *http.Request) (*http.Response, error) { func (r *alpnAwareHTTPRoundTripperImpl) RoundTrip(req *http.Request) (*http.Response, error) {
if req.URL.Scheme != "https" { if req.URL.Scheme != "https" {
@ -106,19 +110,21 @@ func getPendingConnectionID(dest string, alpnIsH2 bool) pendingConnKey {
} }
func (r *alpnAwareHTTPRoundTripperImpl) putConn(addr string, alpnIsH2 bool, conn net.Conn) { func (r *alpnAwareHTTPRoundTripperImpl) putConn(addr string, alpnIsH2 bool, conn net.Conn) {
connId := getPendingConnectionID(addr, alpnIsH2) connID := getPendingConnectionID(addr, alpnIsH2)
r.pendingConn[connId] = NewUnclaimedConnection(conn, time.Minute) r.pendingConn[connID] = NewUnclaimedConnection(conn, time.Minute)
} }
func (r *alpnAwareHTTPRoundTripperImpl) getConn(addr string, alpnIsH2 bool) net.Conn { func (r *alpnAwareHTTPRoundTripperImpl) getConn(addr string, alpnIsH2 bool) net.Conn {
connId := getPendingConnectionID(addr, alpnIsH2) connID := getPendingConnectionID(addr, alpnIsH2)
if conn, ok := r.pendingConn[connId]; ok { if conn, ok := r.pendingConn[connID]; ok {
delete(r.pendingConn, connId) delete(r.pendingConn, connID)
if claimedConnection, err := conn.claimConnection(); err == nil { if claimedConnection, err := conn.claimConnection(); err == nil {
return claimedConnection return claimedConnection
} }
} }
return nil return nil
} }
func (r *alpnAwareHTTPRoundTripperImpl) dialOrGetTLSWithExpectedALPN(ctx context.Context, addr string, expectedH2 bool) (net.Conn, error) { func (r *alpnAwareHTTPRoundTripperImpl) dialOrGetTLSWithExpectedALPN(ctx context.Context, addr string, expectedH2 bool) (net.Conn, error) {
r.accessDialingConnection.Lock() r.accessDialingConnection.Lock()
defer r.accessDialingConnection.Unlock() defer r.accessDialingConnection.Unlock()
@ -127,7 +133,7 @@ func (r *alpnAwareHTTPRoundTripperImpl) dialOrGetTLSWithExpectedALPN(ctx context
return nil, errEAGAIN return nil, errEAGAIN
} }
//Get a cached connection if possible to reduce preflight connection closed without sending data // Get a cached connection if possible to reduce preflight connection closed without sending data
if gconn := r.getConn(addr, expectedH2); gconn != nil { if gconn := r.getConn(addr, expectedH2); gconn != nil {
return gconn, nil return gconn, nil
} }
@ -164,6 +170,7 @@ func (r *alpnAwareHTTPRoundTripperImpl) dialOrGetTLSWithExpectedALPN(ctx context
} }
func (r *alpnAwareHTTPRoundTripperImpl) dialTLS(ctx context.Context, addr string) (net.Conn, error) { func (r *alpnAwareHTTPRoundTripperImpl) dialTLS(ctx context.Context, addr string) (net.Conn, error) {
_ = ctx
return r.dialer(r.ctx, addr) return r.dialer(r.ctx, addr)
} }

View File

@ -23,7 +23,8 @@ func (l *combinedListener) Close() error {
} }
func ListenWithSecuritySettings(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig) ( func ListenWithSecuritySettings(ctx context.Context, address net.Address, port net.Port, streamSettings *internet.MemoryStreamConfig) (
net.Listener, error) { net.Listener, error,
) {
var l combinedListener var l combinedListener
transportEnvironment := envctx.EnvironmentFromContext(ctx).(environment.TransportEnvironment) transportEnvironment := envctx.EnvironmentFromContext(ctx).(environment.TransportEnvironment)