This repository has been archived by the owner on Apr 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstructure.go
308 lines (261 loc) · 7.58 KB
/
structure.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
// Data structures related to whole program
package main
import (
"bytes"
"fmt"
"github.com/grafov/m3u8"
"net/http"
"time"
)
const (
SERVER = "Stream Surfer"
)
// Kinds of streams
// Must be in consistence with StreamType2String() and String2StreamType()
const (
UNKSTREAM StreamType = iota // хрень какая-то
SAMPLE // internet resources for monitor self checks
HTTP // "plain" HTTP
HLS // Apple HTTP Live Streaming
HDS // Adobe HTTP Dynamic Streaming
WV // Widevine VOD
)
const (
INFO Severity = iota
WARNING
ERROR
CRITICAL
)
// Error codes (ordered by errors importance).
// If several errors detected then only one with the heaviest weight reported.
// Must be in consistence with String2StreamErr() and StreamErr2String()
const (
SUCCESS ErrType = iota
DEBUG_LEVEL // Internal debug messages follow below:
TTLEXPIRED // Task was not executed because task TTL expired. StreamSurfer too busy.
HLSPARSER // HLS parser error (debug)
BADREQUEST // Request failed (internal client error)
WARNING_LEVEL // Warnings follow below:
SLOW // SlowWarning threshold on reading server response
VERYSLOW // VerySlowWarning threshold on reading server response
ERROR_LEVEL // Errors follow below:
CTIMEOUT // Timeout on connect
RTIMEOUT // Timeout on read
BADLENGTH // ContentLength value not equal real content length
BODYREAD // Response body read error
CRITICAL_LEVEL // Permanent errors level
REFUSED // Connection refused
BADSTATUS // HTTP Status >= 400
BADURI // Incorret URI format
LISTEMPTY // HLS specific (by m3u8 lib)
BADFORMAT // HLS specific (by m3u8 lib)
UNKERR // хрень какая-то
)
// Commands for probers.
const (
STOP_MON Command = iota
START_MON
RELOAD_CONFIG // TODO made dynamic stream loading and unloading
LOAD_GROUP
LOAD_STREAM
DROP_GROUP
DROP_STREAM
)
type Severity uint
type StreamType uint // Type of checked streams
type ErrType uint
type Command uint
type Group struct {
Type StreamType
Name string
}
type Stream struct {
URI string
Type StreamType
Name string
Title string // опциональный заголовок = name по умолчанию
Group string
}
// Stream checking task
type Task struct {
Stream
ReadBody bool
ReplyTo chan *Result
TTL time.Time // valid until the time
Tid int64 // task id (unique for each stream box)
}
type VariantTask struct {
Task
}
type ChunkTask struct {
Task
}
// Stream group
type GroupTask struct {
Type StreamType
Name string
Tasks *Task
ReplyTo chan Result
}
// Result of task of check streaming
type Result struct {
Task *Task
ErrType ErrType
HTTPCode int // HTTP status code
HTTPStatus string // HTTP status string
ContentLength int64
RealContentLength int64
Headers http.Header
Body bytes.Buffer
Started time.Time // начало исполнения проверки
Elapsed time.Duration // понадобилось времени на задачу
TotalErrs uint
//Meta interface{} // Reference to metainformation about result data (playlist type etc.)
Pid *Result // link to parent check (is nil for top level URLs)
SubResults []*Result // Результаты вложенных проверок (i.e. media playlists for different bitrate of master playlists)
}
// Results persistently keeped in Redis
type KeepedResult struct {
Tid int64 // all subresults have same task id
Stream
Master bool // is master result?
ErrType ErrType
HTTPCode int // HTTP status code
HTTPStatus string // HTTP status string
ContentLength int64
RealContentLength int64
Headers http.Header
Body []byte
Started time.Time // начало исполнения проверки
Elapsed time.Duration // понадобилось времени на задачу
TotalErrs uint
}
// StreamBox statistics
type Stats struct {
Checks int64 // checks made
Errors int64 // total errors found
Errors6min int // errors in last 3 min
Errors6hours int //
LastCheck time.Time // last check was at the time
NextCheck time.Time // next check will be at this time
// TODO результаты анализа потока в streambox (анализ перезапускать регулярно по таймеру)
// TODO вынести инфу о потоке потом в отдельную структуру
}
type MetaHLS struct {
ListType m3u8.ListType // type of analyzed playlist
DeepLinks []string // sublists for analysis
}
type MetaHDS struct {
ListType m3u8.ListType // XXX type of analyzed playlist
DeepLinks []string // sublists for analysis
}
// ключ для статистики
type Key struct {
Group string
Name string
}
// serialised key
func (k *Key) String() string {
return fmt.Sprintf("%s/%s", k.Group, k.Name)
}
// запросppы на сохранение статистики
type StatInQuery struct {
Stream Stream
Last Stats
}
// запросы на получение статистики
type StatOutQuery struct {
Key Key
ReplyTo chan Stats
}
// запросы на сохранение статистики
type ResultInQuery struct {
Stream Stream
Last Result
}
// запросы на получение статистики
type ResultOutQuery struct {
Key Key
ReplyTo chan []KeepedResult
}
// common type for queries
type OutQuery struct {
Key Key
From time.Time
To time.Time
ReplyTo chan interface{}
}
type ErrHistoryKey struct {
Curhour string
ErrType ErrType
Group string
Name string
URI string
}
type ErrTotalHistoryKey struct {
Curhour string
Group string
Name string
}
// Values for the webpage
type PageValues struct {
Title string
Data interface{}
}
// Report about the occured errors
type Report struct {
Error ErrType
Severity Severity
Title string
Body string
RelatedGroups []*Group
RelatedStreams []*Stream
RelatedTasks []*Task
Generated time.Time
}
// Notes last checked point for the stream.
type CheckPoint struct {
Tid int64
Occured time.Time
OpenedRange *ErrRange // last non closed error range
}
// Range of errors in the stream. For usage in reports.
type ErrRange struct {
FromTid int64
ToTid int64
Occured time.Time
Discontinued time.Time
Err ErrType
}
/*
task1 change tid → isTaskOK
mas isCheckOK = true
med1 isCheckOK = true
*med2 isCheckOK=false isTaskOK=false make forSave, start range
med3 isCheckOK=true isTaskOK=false
!isTaskOK → continue range
task2 isTaskOK = true
mas isCheckOK=true
med1 isCheckOK=true
*med2 isCheckOK=false isTaskOK=false make forSave
med3 isCheckOK=true
!isTaskOK → continue range
task2 isTaskOK = true
mas isCheckOK=true
med1 isCheckOK=true
*med2 isCheckOK=false isTaskOK=false make forSave
med3 isCheckOK=true
isTaskOK && forSave → append range
------------------------------------
if prevTid > 0 && prevTid != curTid
if taskOK && forSave
save range
else
taskOK=true
prevTid = curTid
if prevTid == 0
prevTid = curTid
if ERR
taskOK=false
prpare forSave (start, stop, tid0, tid1)
*/