0
0
mirror of https://github.com/XTLS/REALITY.git synced 2025-08-25 16:05:32 +00:00

Add DialContext (#1)

Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
世界 2023-02-26 14:43:27 +08:00 committed by GitHub
parent 8f76c23ba6
commit 14f5d5380b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -515,6 +515,8 @@ const (
// modified. A Config may be reused; the tls package will also not
// modify it.
type Config struct {
DialContext func(ctx context.Context, network, address string) (net.Conn, error)
Show bool
Type string
Dest string

10
tls.go
View File

@ -115,13 +115,13 @@ func Value(vals ...byte) (value int) {
// using conn as the underlying transport.
// The configuration config must be non-nil and must include
// at least one certificate or else set GetCertificate.
func Server(conn net.Conn, config *Config) (*Conn, error) {
func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
remoteAddr := conn.RemoteAddr().String()
if config.Show {
fmt.Printf("REALITY remoteAddr: %v\n", remoteAddr)
}
target, err := net.Dial(config.Type, config.Dest)
target, err := config.DialContext(ctx, config.Type, config.Dest)
if err != nil {
conn.Close()
return nil, errors.New("REALITY: failed to dial dest: " + err.Error())
@ -140,7 +140,7 @@ func Server(conn net.Conn, config *Config) (*Conn, error) {
underlying = pc.Raw()
}
hs := serverHandshakeStateTLS13{ctx: context.TODO()}
hs := serverHandshakeStateTLS13{ctx: context.Background()}
c2sSaved := make([]byte, 0, size)
s2cSaved := make([]byte, 0, size)
@ -201,7 +201,7 @@ func Server(conn net.Conn, config *Config) (*Conn, error) {
conn: readerConn,
config: config,
}
hs.clientHello, err = hs.c.readClientHello(context.TODO())
hs.clientHello, err = hs.c.readClientHello(context.Background())
if err != nil || readerConn.Reader.Len() > 0 || readerConn.Written > 0 || readerConn.Closed {
break
}
@ -421,7 +421,7 @@ func (l *listener) Accept() (net.Conn, error) {
if err != nil {
return nil, err
}
return Server(c, l.config)
return Server(context.Background(), c, l.config)
}
// NewListener creates a Listener which accepts connections from an inner