fix application bug
This commit is contained in:
71
vendor/github.com/lucas-clemente/quic-go/internal/qerr/error_codes.go
generated
vendored
Normal file
71
vendor/github.com/lucas-clemente/quic-go/internal/qerr/error_codes.go
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
package qerr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/marten-seemann/qtls"
|
||||
)
|
||||
|
||||
// ErrorCode can be used as a normal error without reason.
|
||||
type ErrorCode uint16
|
||||
|
||||
// The error codes defined by QUIC
|
||||
const (
|
||||
NoError ErrorCode = 0x0
|
||||
InternalError ErrorCode = 0x1
|
||||
ServerBusy ErrorCode = 0x2
|
||||
FlowControlError ErrorCode = 0x3
|
||||
StreamLimitError ErrorCode = 0x4
|
||||
StreamStateError ErrorCode = 0x5
|
||||
FinalSizeError ErrorCode = 0x6
|
||||
FrameEncodingError ErrorCode = 0x7
|
||||
TransportParameterError ErrorCode = 0x8
|
||||
VersionNegotiationError ErrorCode = 0x9
|
||||
ProtocolViolation ErrorCode = 0xa
|
||||
InvalidMigration ErrorCode = 0xc
|
||||
)
|
||||
|
||||
func (e ErrorCode) isCryptoError() bool {
|
||||
return e >= 0x100 && e < 0x200
|
||||
}
|
||||
|
||||
func (e ErrorCode) Error() string {
|
||||
if e.isCryptoError() {
|
||||
return fmt.Sprintf("%s: %s", e.String(), qtls.Alert(e-0x100).Error())
|
||||
}
|
||||
return e.String()
|
||||
}
|
||||
|
||||
func (e ErrorCode) String() string {
|
||||
switch e {
|
||||
case NoError:
|
||||
return "NO_ERROR"
|
||||
case InternalError:
|
||||
return "INTERNAL_ERROR"
|
||||
case ServerBusy:
|
||||
return "SERVER_BUSY"
|
||||
case FlowControlError:
|
||||
return "FLOW_CONTROL_ERROR"
|
||||
case StreamLimitError:
|
||||
return "STREAM_LIMIT_ERROR"
|
||||
case StreamStateError:
|
||||
return "STREAM_STATE_ERROR"
|
||||
case FinalSizeError:
|
||||
return "FINAL_SIZE_ERROR"
|
||||
case FrameEncodingError:
|
||||
return "FRAME_ENCODING_ERROR"
|
||||
case TransportParameterError:
|
||||
return "TRANSPORT_PARAMETER_ERROR"
|
||||
case VersionNegotiationError:
|
||||
return "VERSION_NEGOTIATION_ERROR"
|
||||
case ProtocolViolation:
|
||||
return "PROTOCOL_VIOLATION"
|
||||
case InvalidMigration:
|
||||
return "INVALID_MIGRATION"
|
||||
default:
|
||||
if e.isCryptoError() {
|
||||
return "CRYPTO_ERROR"
|
||||
}
|
||||
return fmt.Sprintf("unknown error code: %#x", uint16(e))
|
||||
}
|
||||
}
|
||||
73
vendor/github.com/lucas-clemente/quic-go/internal/qerr/quic_error.go
generated
vendored
Normal file
73
vendor/github.com/lucas-clemente/quic-go/internal/qerr/quic_error.go
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
package qerr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
// A QuicError consists of an error code plus a error reason
|
||||
type QuicError struct {
|
||||
ErrorCode ErrorCode
|
||||
ErrorMessage string
|
||||
isTimeout bool
|
||||
}
|
||||
|
||||
var _ net.Error = &QuicError{}
|
||||
|
||||
// Error creates a new QuicError instance
|
||||
func Error(errorCode ErrorCode, errorMessage string) *QuicError {
|
||||
return &QuicError{
|
||||
ErrorCode: errorCode,
|
||||
ErrorMessage: errorMessage,
|
||||
}
|
||||
}
|
||||
|
||||
// TimeoutError creates a new QuicError instance for a timeout error
|
||||
func TimeoutError(errorMessage string) *QuicError {
|
||||
return &QuicError{
|
||||
ErrorMessage: errorMessage,
|
||||
isTimeout: true,
|
||||
}
|
||||
}
|
||||
|
||||
// CryptoError create a new QuicError instance for a crypto error
|
||||
func CryptoError(tlsAlert uint8, errorMessage string) *QuicError {
|
||||
return &QuicError{
|
||||
ErrorCode: 0x100 + ErrorCode(tlsAlert),
|
||||
ErrorMessage: errorMessage,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *QuicError) Error() string {
|
||||
if len(e.ErrorMessage) == 0 {
|
||||
return e.ErrorCode.Error()
|
||||
}
|
||||
return fmt.Sprintf("%s: %s", e.ErrorCode.String(), e.ErrorMessage)
|
||||
}
|
||||
|
||||
// IsCryptoError says if this error is a crypto error
|
||||
func (e *QuicError) IsCryptoError() bool {
|
||||
return e.ErrorCode.isCryptoError()
|
||||
}
|
||||
|
||||
// Temporary says if the error is temporary.
|
||||
func (e *QuicError) Temporary() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Timeout says if this error is a timeout.
|
||||
func (e *QuicError) Timeout() bool {
|
||||
return e.isTimeout
|
||||
}
|
||||
|
||||
// ToQuicError converts an arbitrary error to a QuicError. It leaves QuicErrors
|
||||
// unchanged, and properly handles `ErrorCode`s.
|
||||
func ToQuicError(err error) *QuicError {
|
||||
switch e := err.(type) {
|
||||
case *QuicError:
|
||||
return e
|
||||
case ErrorCode:
|
||||
return Error(e, "")
|
||||
}
|
||||
return Error(InternalError, err.Error())
|
||||
}
|
||||
Reference in New Issue
Block a user