Skip to content

Commit

Permalink
Perform handshake on first read/write
Browse files Browse the repository at this point in the history
Updates the connection to perform a handshake on first read/write
instead of on accept.

Closes #279.
  • Loading branch information
kevmo314 committed Jul 20, 2024
1 parent 602dc71 commit 76eb05f
Show file tree
Hide file tree
Showing 24 changed files with 347 additions and 312 deletions.
2 changes: 1 addition & 1 deletion bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestSimpleReadWrite(t *testing.T) {
return
}
buf := make([]byte, 1024)
if _, sErr = server.Read(buf); sErr != nil {
if _, sErr = server.Read(buf); sErr != nil { //nolint:contextcheck
t.Error(sErr)
}
gotHello <- struct{}{}
Expand Down
20 changes: 3 additions & 17 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,10 @@ type Config struct {

LoggerFactory logging.LoggerFactory

// ConnectContextMaker is a function to make a context used in Dial(),
// Client(), Server(), and Accept(). If nil, the default ConnectContextMaker
// is used. It can be implemented as following.
// ConnectContextMaker is no longer used. It is kept for compatibility
// reasons and will be removed in a future release.
//
// func ConnectContextMaker() (context.Context, func()) {
// return context.WithTimeout(context.Background(), 30*time.Second)
// }
// Deprecated: Use the context parameter in [HandshakeContext] instead.
ConnectContextMaker func() (context.Context, func())

// MTU is the length at which handshake messages will be fragmented to
Expand Down Expand Up @@ -230,17 +227,6 @@ type Config struct {
OnConnectionAttempt func(net.Addr) error
}

func defaultConnectContextMaker() (context.Context, func()) {
return context.WithTimeout(context.Background(), 30*time.Second)
}

func (c *Config) connectContextMaker() (context.Context, func()) {
if c.ConnectContextMaker == nil {
return defaultConnectContextMaker()
}
return c.ConnectContextMaker()
}

func (c *Config) includeCertificateSuites() bool {
return c.PSK == nil || len(c.Certificates) > 0 || c.GetCertificate != nil || c.GetClientCertificate != nil
}
Expand Down
Loading

0 comments on commit 76eb05f

Please sign in to comment.