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:
parent
8f76c23ba6
commit
14f5d5380b
@ -515,6 +515,8 @@ const (
|
|||||||
// modified. A Config may be reused; the tls package will also not
|
// modified. A Config may be reused; the tls package will also not
|
||||||
// modify it.
|
// modify it.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
DialContext func(ctx context.Context, network, address string) (net.Conn, error)
|
||||||
|
|
||||||
Show bool
|
Show bool
|
||||||
Type string
|
Type string
|
||||||
Dest string
|
Dest string
|
||||||
|
10
tls.go
10
tls.go
@ -115,13 +115,13 @@ func Value(vals ...byte) (value int) {
|
|||||||
// using conn as the underlying transport.
|
// using conn as the underlying transport.
|
||||||
// The configuration config must be non-nil and must include
|
// The configuration config must be non-nil and must include
|
||||||
// at least one certificate or else set GetCertificate.
|
// 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()
|
remoteAddr := conn.RemoteAddr().String()
|
||||||
if config.Show {
|
if config.Show {
|
||||||
fmt.Printf("REALITY remoteAddr: %v\n", remoteAddr)
|
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 {
|
if err != nil {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return nil, errors.New("REALITY: failed to dial dest: " + err.Error())
|
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()
|
underlying = pc.Raw()
|
||||||
}
|
}
|
||||||
|
|
||||||
hs := serverHandshakeStateTLS13{ctx: context.TODO()}
|
hs := serverHandshakeStateTLS13{ctx: context.Background()}
|
||||||
|
|
||||||
c2sSaved := make([]byte, 0, size)
|
c2sSaved := make([]byte, 0, size)
|
||||||
s2cSaved := make([]byte, 0, size)
|
s2cSaved := make([]byte, 0, size)
|
||||||
@ -201,7 +201,7 @@ func Server(conn net.Conn, config *Config) (*Conn, error) {
|
|||||||
conn: readerConn,
|
conn: readerConn,
|
||||||
config: config,
|
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 {
|
if err != nil || readerConn.Reader.Len() > 0 || readerConn.Written > 0 || readerConn.Closed {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -421,7 +421,7 @@ func (l *listener) Accept() (net.Conn, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// NewListener creates a Listener which accepts connections from an inner
|
||||||
|
Loading…
Reference in New Issue
Block a user