Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Comment thread
nekohasekai marked this conversation as resolved.
}

// NewListener creates a Listener which accepts connections from an inner
Expand Down