forked from quic-go/quic-go
simplify the blocking logic for the non-forward-secure session
This commit is contained in:
23
session.go
23
session.go
@@ -85,8 +85,9 @@ type session struct {
|
|||||||
// it is closed as soon as the handshake is complete
|
// it is closed as soon as the handshake is complete
|
||||||
aeadChanged <-chan protocol.EncryptionLevel
|
aeadChanged <-chan protocol.EncryptionLevel
|
||||||
handshakeComplete bool
|
handshakeComplete bool
|
||||||
handshakeChan chan struct{} // will be closed as soon as the handshake completes
|
// will be closed as soon as the handshake completes, and receive any error that might occur until then
|
||||||
handshakeErrorChan chan error
|
// it is used to block WaitUntilHandshakeComplete()
|
||||||
|
handshakeCompleteChan chan error
|
||||||
|
|
||||||
nextAckScheduledTime time.Time
|
nextAckScheduledTime time.Time
|
||||||
|
|
||||||
@@ -217,8 +218,7 @@ func (s *session) setup() {
|
|||||||
s.undecryptablePackets = make([]*receivedPacket, 0, protocol.MaxUndecryptablePackets)
|
s.undecryptablePackets = make([]*receivedPacket, 0, protocol.MaxUndecryptablePackets)
|
||||||
s.aeadChanged = make(chan protocol.EncryptionLevel, 2)
|
s.aeadChanged = make(chan protocol.EncryptionLevel, 2)
|
||||||
s.runClosed = make(chan struct{})
|
s.runClosed = make(chan struct{})
|
||||||
s.handshakeChan = make(chan struct{})
|
s.handshakeCompleteChan = make(chan error, 1)
|
||||||
s.handshakeErrorChan = make(chan error, 1)
|
|
||||||
|
|
||||||
s.timer = time.NewTimer(0)
|
s.timer = time.NewTimer(0)
|
||||||
s.lastNetworkActivityTime = now
|
s.lastNetworkActivityTime = now
|
||||||
@@ -278,7 +278,7 @@ runLoop:
|
|||||||
if !ok {
|
if !ok {
|
||||||
s.handshakeComplete = true
|
s.handshakeComplete = true
|
||||||
aeadChanged = nil // prevent this case from ever being selected again
|
aeadChanged = nil // prevent this case from ever being selected again
|
||||||
close(s.handshakeChan)
|
close(s.handshakeCompleteChan)
|
||||||
} else {
|
} else {
|
||||||
if l == protocol.EncryptionForwardSecure {
|
if l == protocol.EncryptionForwardSecure {
|
||||||
s.packer.SetForwardSecure()
|
s.packer.SetForwardSecure()
|
||||||
@@ -310,7 +310,11 @@ runLoop:
|
|||||||
s.garbageCollectStreams()
|
s.garbageCollectStreams()
|
||||||
}
|
}
|
||||||
|
|
||||||
s.handshakeErrorChan <- closeErr.err
|
// only send the error the handshakeChan when the handshake is not completed yet
|
||||||
|
// otherwise this chan will already be closed
|
||||||
|
if !s.handshakeComplete {
|
||||||
|
s.handshakeCompleteChan <- closeErr.err
|
||||||
|
}
|
||||||
s.handleCloseError(closeErr)
|
s.handleCloseError(closeErr)
|
||||||
close(s.runClosed)
|
close(s.runClosed)
|
||||||
return closeErr.err
|
return closeErr.err
|
||||||
@@ -758,12 +762,7 @@ func (s *session) OpenStreamSync() (Stream, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) WaitUntilHandshakeComplete() error {
|
func (s *session) WaitUntilHandshakeComplete() error {
|
||||||
select {
|
return <-s.handshakeCompleteChan
|
||||||
case <-s.handshakeChan:
|
|
||||||
return nil
|
|
||||||
case err := <-s.handshakeErrorChan:
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) queueResetStreamFrame(id protocol.StreamID, offset protocol.ByteCount) {
|
func (s *session) queueResetStreamFrame(id protocol.StreamID, offset protocol.ByteCount) {
|
||||||
|
|||||||
Reference in New Issue
Block a user