File: error_codes.go

package info (click to toggle)
golang-github-lucas-clemente-quic-go 0.54.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,312 kB
  • sloc: sh: 54; makefile: 7
file content (87 lines) | stat: -rw-r--r-- 2,511 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package qerr

import (
	"crypto/tls"
	"fmt"
)

// TransportErrorCode is a QUIC transport error.
type TransportErrorCode uint64

// The error codes defined by QUIC
const (
	NoError                   TransportErrorCode = 0x0
	InternalError             TransportErrorCode = 0x1
	ConnectionRefused         TransportErrorCode = 0x2
	FlowControlError          TransportErrorCode = 0x3
	StreamLimitError          TransportErrorCode = 0x4
	StreamStateError          TransportErrorCode = 0x5
	FinalSizeError            TransportErrorCode = 0x6
	FrameEncodingError        TransportErrorCode = 0x7
	TransportParameterError   TransportErrorCode = 0x8
	ConnectionIDLimitError    TransportErrorCode = 0x9
	ProtocolViolation         TransportErrorCode = 0xa
	InvalidToken              TransportErrorCode = 0xb
	ApplicationErrorErrorCode TransportErrorCode = 0xc
	CryptoBufferExceeded      TransportErrorCode = 0xd
	KeyUpdateError            TransportErrorCode = 0xe
	AEADLimitReached          TransportErrorCode = 0xf
	NoViablePathError         TransportErrorCode = 0x10
)

func (e TransportErrorCode) IsCryptoError() bool {
	return e >= 0x100 && e < 0x200
}

// Message is a description of the error.
// It only returns a non-empty string for crypto errors.
func (e TransportErrorCode) Message() string {
	if !e.IsCryptoError() {
		return ""
	}
	return tls.AlertError(e - 0x100).Error()
}

func (e TransportErrorCode) String() string {
	switch e {
	case NoError:
		return "NO_ERROR"
	case InternalError:
		return "INTERNAL_ERROR"
	case ConnectionRefused:
		return "CONNECTION_REFUSED"
	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 ConnectionIDLimitError:
		return "CONNECTION_ID_LIMIT_ERROR"
	case ProtocolViolation:
		return "PROTOCOL_VIOLATION"
	case InvalidToken:
		return "INVALID_TOKEN"
	case ApplicationErrorErrorCode:
		return "APPLICATION_ERROR"
	case CryptoBufferExceeded:
		return "CRYPTO_BUFFER_EXCEEDED"
	case KeyUpdateError:
		return "KEY_UPDATE_ERROR"
	case AEADLimitReached:
		return "AEAD_LIMIT_REACHED"
	case NoViablePathError:
		return "NO_VIABLE_PATH"
	default:
		if e.IsCryptoError() {
			return fmt.Sprintf("CRYPTO_ERROR %#x", uint16(e))
		}
		return fmt.Sprintf("unknown error code: %#x", uint16(e))
	}
}