-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscanner.cc
84 lines (69 loc) · 1.39 KB
/
scanner.cc
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
/* Copyright (c) 2011 Akamai Technologies, Inc. */
#include "system.hh"
#include "cgen.h"
#include "sensors.h"
#include "log.h"
#include "encode.h"
#include "decode.h"
#include "decider.h"
#include "traversal.h"
#include "fd_traversal.h"
#include "counter.h"
#include "scanner.h"
#include "scannable.h"
extern const int WINDOW_LEN = 10000;
Scanner::Scanner() : destroyed_(false), counter_(NULL) {}
Scanner::~Scanner()
{
if (!destroyed_)
{
PERROR("destructing live scanner");
}
}
int Scanner::Init(Counter* counter)
{
CHK(counter == NULL, "null counter", out_error);
counter_ = counter;
return 0;
out_error:
return 1;
}
int Scanner::Destroy()
{
destroyed_ = true;
return 0;
}
int Scanner::scan_pre(Scannable* sc)
{
(void)sc;
return 0;
}
int Scanner::scan_post(Scannable* sc)
{
(void)sc;
counter_->num_interesting += 1;
return 0;
}
int Scanner::scan(Scannable* sc)
{
CHK(scan_pre(sc) != 0, "unable to pre-scan", out_error);
if (sc->data_len() <= 2 * WINDOW_LEN)
{
CHK(sc->Scan(this, 0, sc->data_len(), NULL) != 0,
"unable to scan total range", out_error);
}
else
{
CHK(sc->Scan(this, 0, WINDOW_LEN, NULL) != 0,
"unable to scan start range", out_error);
CHK(sc->Scan(this,
sc->data_len() - WINDOW_LEN,
WINDOW_LEN,
NULL) != 0,
"unable to scan end range", out_error);
}
CHK(scan_post(sc) != 0, "unable to post-scan", out_error);
return 0;
out_error:
return 1;
}