-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsettings.go
169 lines (144 loc) · 2.83 KB
/
settings.go
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package http2
import (
"github.com/ami-GS/soac"
)
// PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n
var CONNECTION_PREFACE = []byte{0x50, 0x52, 0x49, 0x20, 0x2a, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x32, 0x2e, 0x30, 0x0d, 0x0a, 0x0d, 0x0a, 0x53, 0x4d, 0x0d, 0x0a, 0x0d, 0x0a}
type FLAG byte
const (
NO FLAG = 0x00
ACK = 0x01
END_STREAM = 0x01
END_HEADERS = 0x04
PADDED = 0x08
PRIORITY = 0x20
)
var flagNames map[FLAG]string = map[FLAG]string{
NO: "NO",
ACK: "ACK or END",
END_HEADERS: "END_HEADEDRS",
PADDED: "PADDED",
PRIORITY: "PRIORTY",
}
func (flag FLAG) String() string {
return flagNames[flag]
}
type TYPE byte
const (
DATA_FRAME TYPE = iota
HEADERS_FRAME
PRIORITY_FRAME
RST_STREAM_FRAME
SETTINGS_FRAME
PING_FRAME
GOAWAY_FRAME
WINDOW_UPDATE_FRAME
CONTINUATION_FRAME
)
var frameNames []string = []string{
"DATA",
"HEADERS",
"PRIORITY",
"RST_STREAM",
"SETTINGS",
"PING",
"GOAWAY",
"WINDOW_UPDATE",
"CONTINUATION",
}
func (frameType TYPE) String() string {
return frameNames[int(frameType)]
}
type STATE byte
const (
IDLE = iota
RESERVED_LOCAL
RESERVED_REMOTE
OPEN
HALF_CLOSED_LOCAL
HALF_CLOSED_REMOTE
CLOSED
)
var streamState []string = []string{
"IDLE",
"RESERVED_LOCAL",
"RESERVED_REMOTE",
"OPEN",
"HALF_CLOSED_LOCAL",
"HALF_CLOSED_REMOTE",
"CLOSED",
}
func (state STATE) String() string {
return streamState[int(state)]
}
type SETTING uint16
const INITIAL_WINDOW_SIZE_MAX = 2147483647
const MAX_FRAME_SIZE_MIN = 16384
const MAX_FRAME_SIZE_MAX = 16777215
const INFINITE = 2147483647
const (
NO_SETTING SETTING = iota
HEADER_TABLE_SIZE
ENABLE_PUSH
MAX_CONCURRENT_STREAMS
INITIAL_WINDOW_SIZE
MAX_FRAME_SIZE
MAX_HEADER_LIST_SIZE
)
var settingIDs []string = []string{
"NO_SETTING",
"HEADER_TABLE_SIZE",
"ENABLE_PUSH",
"MAX_CONCURRENT_STREAMS",
"INITIAL_WINDOW_SIZE",
"MAX_FRAME_SIZE",
"MAX_HEADER_LIST_SIZE",
}
func (setting SETTING) String() string {
return settingIDs[int(setting)]
}
type ERROR uint32
const (
NO_ERROR ERROR = iota
PROTOCOL_ERROR
INTERNAL_ERROR
FLOW_CONTROL_ERROR
SETTINGS_TIMEOUT
STREAM_CLOSED
FRAME_SIZE_ERROR
REFUSED_STREAM
CANCEL
COMPRESSION_ERROR
CONNECT_ERROR
ENHANCE_YOUR_CALM
INADEQUATE_SECURITY
HTTP_1_1_REQUIRED
)
var errorNames []string = []string{
"NO_ERROR",
"PROTOCOL_ERROR",
"INTERNAL_ERROR",
"FLOW_CONTROL_ERROR",
"SETTINGS_TIMEOUT",
"STREAM_CLOSED",
"FRAME_SIZE_ERROR",
"REFUSED_STREAM",
"CANCEL",
"COMPRESSION_ERROR",
"CONNECT_ERROR",
"ENHANCE_YOUR_CALM",
"INADEQUATE_SECURITY",
"HTTP_1_1_REQUIRED",
}
func (err ERROR) String() string {
return errorNames[int(err)]
}
var FrameC, SendC, RecvC *soac.Changer
func init() {
FrameC = soac.NewChanger()
SendC = soac.NewChanger()
RecvC = soac.NewChanger()
FrameC.Green()
SendC.Yellow().Underline()
RecvC.Magenda().Underline()
}