use go 1.12

Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
hongming
2019-03-12 15:47:56 +08:00
parent b59c244ca2
commit 4144404b0b
1110 changed files with 161100 additions and 14519 deletions

View File

@@ -0,0 +1,193 @@
package qerr
// The error codes defined by QUIC
// Remember to run `go generate ./...` whenever the error codes change.
//go:generate stringer -type=ErrorCode
const (
InternalError ErrorCode = 1
// There were data frames after the a fin or reset.
StreamDataAfterTermination ErrorCode = 2
// Control frame is malformed.
InvalidPacketHeader ErrorCode = 3
// Frame data is malformed.
InvalidFrameData ErrorCode = 4
// The packet contained no payload.
MissingPayload ErrorCode = 48
// FEC data is malformed.
InvalidFecData ErrorCode = 5
// STREAM frame data is malformed.
InvalidStreamData ErrorCode = 46
// STREAM frame data overlaps with buffered data.
OverlappingStreamData ErrorCode = 87
// Received STREAM frame data is not encrypted.
UnencryptedStreamData ErrorCode = 61
// Attempt to send unencrypted STREAM frame.
AttemptToSendUnencryptedStreamData ErrorCode = 88
// FEC frame data is not encrypted.
UnencryptedFecData ErrorCode = 77
// RST_STREAM frame data is malformed.
InvalidRstStreamData ErrorCode = 6
// CONNECTION_CLOSE frame data is malformed.
InvalidConnectionCloseData ErrorCode = 7
// GOAWAY frame data is malformed.
InvalidGoawayData ErrorCode = 8
// WINDOW_UPDATE frame data is malformed.
InvalidWindowUpdateData ErrorCode = 57
// BLOCKED frame data is malformed.
InvalidBlockedData ErrorCode = 58
// STOP_WAITING frame data is malformed.
InvalidStopWaitingData ErrorCode = 60
// PATH_CLOSE frame data is malformed.
InvalidPathCloseData ErrorCode = 78
// ACK frame data is malformed.
InvalidAckData ErrorCode = 9
// Version negotiation packet is malformed.
InvalidVersionNegotiationPacket ErrorCode = 10
// Public RST packet is malformed.
InvalidPublicRstPacket ErrorCode = 11
// There was an error decrypting.
DecryptionFailure ErrorCode = 12
// There was an error encrypting.
EncryptionFailure ErrorCode = 13
// The packet exceeded kMaxPacketSize.
PacketTooLarge ErrorCode = 14
// The peer is going away. May be a client or server.
PeerGoingAway ErrorCode = 16
// A stream ID was invalid.
InvalidStreamID ErrorCode = 17
// A priority was invalid.
InvalidPriority ErrorCode = 49
// Too many streams already open.
TooManyOpenStreams ErrorCode = 18
// The peer created too many available streams.
TooManyAvailableStreams ErrorCode = 76
// Received public reset for this connection.
PublicReset ErrorCode = 19
// Invalid protocol version.
InvalidVersion ErrorCode = 20
// The Header ID for a stream was too far from the previous.
InvalidHeaderID ErrorCode = 22
// Negotiable parameter received during handshake had invalid value.
InvalidNegotiatedValue ErrorCode = 23
// There was an error decompressing data.
DecompressionFailure ErrorCode = 24
// The connection timed out due to no network activity.
NetworkIdleTimeout ErrorCode = 25
// The connection timed out waiting for the handshake to complete.
HandshakeTimeout ErrorCode = 67
// There was an error encountered migrating addresses.
ErrorMigratingAddress ErrorCode = 26
// There was an error encountered migrating port only.
ErrorMigratingPort ErrorCode = 86
// There was an error while writing to the socket.
PacketWriteError ErrorCode = 27
// There was an error while reading from the socket.
PacketReadError ErrorCode = 51
// We received a STREAM_FRAME with no data and no fin flag set.
EmptyStreamFrameNoFin ErrorCode = 50
// We received invalid data on the headers stream.
InvalidHeadersStreamData ErrorCode = 56
// Invalid data on the headers stream received because of decompression
// failure.
HeadersStreamDataDecompressFailure ErrorCode = 97
// The peer received too much data, violating flow control.
FlowControlReceivedTooMuchData ErrorCode = 59
// The peer sent too much data, violating flow control.
FlowControlSentTooMuchData ErrorCode = 63
// The peer received an invalid flow control window.
FlowControlInvalidWindow ErrorCode = 64
// The connection has been IP pooled into an existing connection.
ConnectionIPPooled ErrorCode = 62
// The connection has too many outstanding sent packets.
TooManyOutstandingSentPackets ErrorCode = 68
// The connection has too many outstanding received packets.
TooManyOutstandingReceivedPackets ErrorCode = 69
// The quic connection has been cancelled.
ConnectionCancelled ErrorCode = 70
// Disabled QUIC because of high packet loss rate.
BadPacketLossRate ErrorCode = 71
// Disabled QUIC because of too many PUBLIC_RESETs post handshake.
PublicResetsPostHandshake ErrorCode = 73
// Disabled QUIC because of too many timeouts with streams open.
TimeoutsWithOpenStreams ErrorCode = 74
// Closed because we failed to serialize a packet.
FailedToSerializePacket ErrorCode = 75
// QUIC timed out after too many RTOs.
TooManyRtos ErrorCode = 85
// Crypto errors.
// Hanshake failed.
HandshakeFailed ErrorCode = 28
// Handshake message contained out of order tags.
CryptoTagsOutOfOrder ErrorCode = 29
// Handshake message contained too many entries.
CryptoTooManyEntries ErrorCode = 30
// Handshake message contained an invalid value length.
CryptoInvalidValueLength ErrorCode = 31
// A crypto message was received after the handshake was complete.
CryptoMessageAfterHandshakeComplete ErrorCode = 32
// A crypto message was received with an illegal message tag.
InvalidCryptoMessageType ErrorCode = 33
// A crypto message was received with an illegal parameter.
InvalidCryptoMessageParameter ErrorCode = 34
// An invalid channel id signature was supplied.
InvalidChannelIDSignature ErrorCode = 52
// A crypto message was received with a mandatory parameter missing.
CryptoMessageParameterNotFound ErrorCode = 35
// A crypto message was received with a parameter that has no overlap
// with the local parameter.
CryptoMessageParameterNoOverlap ErrorCode = 36
// A crypto message was received that contained a parameter with too few
// values.
CryptoMessageIndexNotFound ErrorCode = 37
// An internal error occurred in crypto processing.
CryptoInternalError ErrorCode = 38
// A crypto handshake message specified an unsupported version.
CryptoVersionNotSupported ErrorCode = 39
// A crypto handshake message resulted in a stateless reject.
CryptoHandshakeStatelessReject ErrorCode = 72
// There was no intersection between the crypto primitives supported by the
// peer and ourselves.
CryptoNoSupport ErrorCode = 40
// The server rejected our client hello messages too many times.
CryptoTooManyRejects ErrorCode = 41
// The client rejected the server's certificate chain or signature.
ProofInvalid ErrorCode = 42
// A crypto message was received with a duplicate tag.
CryptoDuplicateTag ErrorCode = 43
// A crypto message was received with the wrong encryption level (i.e. it
// should have been encrypted but was not.)
CryptoEncryptionLevelIncorrect ErrorCode = 44
// The server config for a server has expired.
CryptoServerConfigExpired ErrorCode = 45
// We failed to setup the symmetric keys for a connection.
CryptoSymmetricKeySetupFailed ErrorCode = 53
// A handshake message arrived, but we are still validating the
// previous handshake message.
CryptoMessageWhileValidatingClientHello ErrorCode = 54
// A server config update arrived before the handshake is complete.
CryptoUpdateBeforeHandshakeComplete ErrorCode = 65
// This connection involved a version negotiation which appears to have been
// tampered with.
VersionNegotiationMismatch ErrorCode = 55
// Multipath is not enabled, but a packet with multipath flag on is received.
BadMultipathFlag ErrorCode = 79
// IP address changed causing connection close.
IPAddressChanged ErrorCode = 80
// Connection migration errors.
// Network changed, but connection had no migratable streams.
ConnectionMigrationNoMigratableStreams ErrorCode = 81
// Connection changed networks too many times.
ConnectionMigrationTooManyChanges ErrorCode = 82
// Connection migration was attempted, but there was no new network to
// migrate to.
ConnectionMigrationNoNewNetwork ErrorCode = 83
// Network changed, but connection had one or more non-migratable streams.
ConnectionMigrationNonMigratableStream ErrorCode = 84
)

View File

@@ -0,0 +1,46 @@
// Code generated by "stringer -type=ErrorCode"; DO NOT EDIT.
package qerr
import "strconv"
const (
_ErrorCode_name_0 = "InternalErrorStreamDataAfterTerminationInvalidPacketHeaderInvalidFrameDataInvalidFecDataInvalidRstStreamDataInvalidConnectionCloseDataInvalidGoawayDataInvalidAckDataInvalidVersionNegotiationPacketInvalidPublicRstPacketDecryptionFailureEncryptionFailurePacketTooLarge"
_ErrorCode_name_1 = "PeerGoingAwayInvalidStreamIDTooManyOpenStreamsPublicResetInvalidVersion"
_ErrorCode_name_2 = "InvalidHeaderIDInvalidNegotiatedValueDecompressionFailureNetworkIdleTimeoutErrorMigratingAddressPacketWriteErrorHandshakeFailedCryptoTagsOutOfOrderCryptoTooManyEntriesCryptoInvalidValueLengthCryptoMessageAfterHandshakeCompleteInvalidCryptoMessageTypeInvalidCryptoMessageParameterCryptoMessageParameterNotFoundCryptoMessageParameterNoOverlapCryptoMessageIndexNotFoundCryptoInternalErrorCryptoVersionNotSupportedCryptoNoSupportCryptoTooManyRejectsProofInvalidCryptoDuplicateTagCryptoEncryptionLevelIncorrectCryptoServerConfigExpiredInvalidStreamData"
_ErrorCode_name_3 = "MissingPayloadInvalidPriorityEmptyStreamFrameNoFinPacketReadErrorInvalidChannelIDSignatureCryptoSymmetricKeySetupFailedCryptoMessageWhileValidatingClientHelloVersionNegotiationMismatchInvalidHeadersStreamDataInvalidWindowUpdateDataInvalidBlockedDataFlowControlReceivedTooMuchDataInvalidStopWaitingDataUnencryptedStreamDataConnectionIPPooledFlowControlSentTooMuchDataFlowControlInvalidWindowCryptoUpdateBeforeHandshakeComplete"
_ErrorCode_name_4 = "HandshakeTimeoutTooManyOutstandingSentPacketsTooManyOutstandingReceivedPacketsConnectionCancelledBadPacketLossRateCryptoHandshakeStatelessRejectPublicResetsPostHandshakeTimeoutsWithOpenStreamsFailedToSerializePacketTooManyAvailableStreamsUnencryptedFecDataInvalidPathCloseDataBadMultipathFlagIPAddressChangedConnectionMigrationNoMigratableStreamsConnectionMigrationTooManyChangesConnectionMigrationNoNewNetworkConnectionMigrationNonMigratableStreamTooManyRtosErrorMigratingPortOverlappingStreamDataAttemptToSendUnencryptedStreamData"
_ErrorCode_name_5 = "HeadersStreamDataDecompressFailure"
)
var (
_ErrorCode_index_0 = [...]uint16{0, 13, 39, 58, 74, 88, 108, 134, 151, 165, 196, 218, 235, 252, 266}
_ErrorCode_index_1 = [...]uint8{0, 13, 28, 46, 57, 71}
_ErrorCode_index_2 = [...]uint16{0, 15, 37, 57, 75, 96, 112, 127, 147, 167, 191, 226, 250, 279, 309, 340, 366, 385, 410, 425, 445, 457, 475, 505, 530, 547}
_ErrorCode_index_3 = [...]uint16{0, 14, 29, 50, 65, 90, 119, 158, 184, 208, 231, 249, 279, 301, 322, 340, 366, 390, 425}
_ErrorCode_index_4 = [...]uint16{0, 16, 45, 78, 97, 114, 144, 169, 192, 215, 238, 256, 276, 292, 308, 346, 379, 410, 448, 459, 477, 498, 532}
)
func (i ErrorCode) String() string {
switch {
case 1 <= i && i <= 14:
i -= 1
return _ErrorCode_name_0[_ErrorCode_index_0[i]:_ErrorCode_index_0[i+1]]
case 16 <= i && i <= 20:
i -= 16
return _ErrorCode_name_1[_ErrorCode_index_1[i]:_ErrorCode_index_1[i+1]]
case 22 <= i && i <= 46:
i -= 22
return _ErrorCode_name_2[_ErrorCode_index_2[i]:_ErrorCode_index_2[i+1]]
case 48 <= i && i <= 65:
i -= 48
return _ErrorCode_name_3[_ErrorCode_index_3[i]:_ErrorCode_index_3[i+1]]
case 67 <= i && i <= 88:
i -= 67
return _ErrorCode_name_4[_ErrorCode_index_4[i]:_ErrorCode_index_4[i+1]]
case i == 97:
return _ErrorCode_name_5
default:
return "ErrorCode(" + strconv.FormatInt(int64(i), 10) + ")"
}
}

View File

@@ -0,0 +1,53 @@
package qerr
import (
"fmt"
)
// ErrorCode can be used as a normal error without reason.
type ErrorCode uint32
func (e ErrorCode) Error() string {
return e.String()
}
// A QuicError consists of an error code plus a error reason
type QuicError struct {
ErrorCode ErrorCode
ErrorMessage string
}
// Error creates a new QuicError instance
func Error(errorCode ErrorCode, errorMessage string) *QuicError {
return &QuicError{
ErrorCode: errorCode,
ErrorMessage: errorMessage,
}
}
func (e *QuicError) Error() string {
return fmt.Sprintf("%s: %s", e.ErrorCode.String(), e.ErrorMessage)
}
// Timeout says if this error is a timeout.
func (e *QuicError) Timeout() bool {
switch e.ErrorCode {
case NetworkIdleTimeout,
HandshakeTimeout,
TimeoutsWithOpenStreams:
return true
}
return false
}
// 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())
}