Skip to content

Commit

Permalink
upgrader: drop support for multistream simultaneous open
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Sep 5, 2023
1 parent dce9424 commit 3cbce17
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions p2p/net/upgrader/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ func (u *upgrader) upgrade(ctx context.Context, t transport.Transport, maconn ma

func (u *upgrader) setupSecurity(ctx context.Context, conn net.Conn, p peer.ID, dir network.Direction) (sec.SecureConn, protocol.ID, bool, error) {
isServer := dir == network.DirInbound
var st sec.SecureTransport
var err error
st, isServer, err = u.negotiateSecurity(ctx, conn, isServer)
st, err := u.negotiateSecurity(ctx, conn, isServer)
if err != nil {
return nil, "", false, err
}
Expand Down Expand Up @@ -308,41 +306,38 @@ func (u *upgrader) getSecurityByID(id protocol.ID) sec.SecureTransport {
return nil
}

func (u *upgrader) negotiateSecurity(ctx context.Context, insecure net.Conn, server bool) (sec.SecureTransport, bool, error) {
func (u *upgrader) negotiateSecurity(ctx context.Context, insecure net.Conn, server bool) (sec.SecureTransport, error) {
type result struct {
proto protocol.ID
iamserver bool
err error
proto protocol.ID
err error
}

done := make(chan result, 1)
go func() {
if server {
var r result
r.iamserver = true
r.proto, _, r.err = u.securityMuxer.Negotiate(insecure)
done <- r
return
}
var r result
r.proto, r.iamserver, r.err = mss.SelectWithSimopenOrFail(u.securityIDs, insecure)
r.proto, r.err = mss.SelectOneOf(u.securityIDs, insecure)
done <- r
}()

select {
case r := <-done:
if r.err != nil {
return nil, false, r.err
return nil, r.err
}
if s := u.getSecurityByID(r.proto); s != nil {
return s, r.iamserver, nil
return s, nil
}
return nil, false, fmt.Errorf("selected unknown security transport: %s", r.proto)
return nil, fmt.Errorf("selected unknown security transport: %s", r.proto)
case <-ctx.Done():
// We *must* do this. We have outstanding work on the connection
// and it's no longer safe to use.
// We *must* do this. We have outstanding work on the connection, and it's no longer safe to use.
insecure.Close()
<-done // wait to stop using the connection.
return nil, false, ctx.Err()
return nil, ctx.Err()
}
}

0 comments on commit 3cbce17

Please sign in to comment.