mirror of
https://github.com/XTLS/REALITY.git
synced 2026-09-28 01:48:07 +03:00
crypto/tls: add QUICErrorEvent
Add a new QUICEvent type for reporting errors. This provides a way to report errors that don't occur as a result of QUICConn.Start, QUICConn.HandleData, or QUICConn.SendSessionTicket. Fixes #75108 Change-Id: I941371a21f26b940e75287a66d7e0211fc0baab1 Reviewed-on: https://go-review.googlesource.com/c/go/+/719040 Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Roland Shoemaker <roland@golang.org>
This commit is contained in:
@@ -117,6 +117,11 @@ const (
|
||||
// The application may modify the [SessionState] before storing it.
|
||||
// This event only occurs on client connections.
|
||||
QUICStoreSession
|
||||
|
||||
// QUICErrorEvent indicates that a fatal error has occurred.
|
||||
// The handshake cannot proceed and the connection must be closed.
|
||||
// QUICEvent.Err is set.
|
||||
QUICErrorEvent
|
||||
)
|
||||
|
||||
// A QUICEvent is an event occurring on a QUIC connection.
|
||||
@@ -138,6 +143,10 @@ type QUICEvent struct {
|
||||
|
||||
// Set for QUICResumeSession and QUICStoreSession.
|
||||
SessionState *SessionState
|
||||
|
||||
// Set for QUICErrorEvent.
|
||||
// The error will wrap AlertError.
|
||||
Err error
|
||||
}
|
||||
|
||||
type quicState struct {
|
||||
@@ -157,6 +166,7 @@ type quicState struct {
|
||||
cancel context.CancelFunc
|
||||
|
||||
waitingForDrain bool
|
||||
errorReturned bool
|
||||
|
||||
// readbuf is shared between HandleData and the handshake goroutine.
|
||||
// HandshakeCryptoData passes ownership to the handshake goroutine by
|
||||
@@ -230,6 +240,15 @@ func (q *QUICConn) NextEvent() QUICEvent {
|
||||
<-qs.signalc
|
||||
<-qs.blockedc
|
||||
}
|
||||
if err := q.conn.handshakeErr; err != nil {
|
||||
if qs.errorReturned {
|
||||
return QUICEvent{Kind: QUICNoEvent}
|
||||
}
|
||||
qs.errorReturned = true
|
||||
qs.events = nil
|
||||
qs.nextEvent = 0
|
||||
return QUICEvent{Kind: QUICErrorEvent, Err: q.conn.handshakeErr}
|
||||
}
|
||||
if qs.nextEvent >= len(qs.events) {
|
||||
qs.events = qs.events[:0]
|
||||
qs.nextEvent = 0
|
||||
|
||||
Reference in New Issue
Block a user