-
Notifications
You must be signed in to change notification settings - Fork 0
/
Crawler.h
129 lines (103 loc) · 2.26 KB
/
Crawler.h
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
#ifndef ___CRAWLER_H
#define ___CRAWLER_H
#include <iostream>
#include <fstream>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <thread>
#include <math.h>
#include <condition_variable>
#include "headers/downloaders.h"
#include "headers/getLinks.h"
#include "headers/getDomain.h"
#include "thread_safe/int_ts.cpp"
#include "thread_safe/map_ts.cpp"
#include "thread_safe/queue_ts.cpp"
using namespace std;
#define RED "\033[31m" /* Red */
#define CYAN "\033[36m" /* Cyan */
#define GREEN "\033[32m" /* Green */
#define BLUE "\033[34m" /* Blue */
#define RESET "\033[0m"
class Crawler
{
// setting public for testing purposes
public:
ofstream log; // logging
// Parameters
int maxLinks = 10;
int maxPages = 10;
int maxThreads = 5;
int max_file_size = 1024;
int time_out = 5;
bool SAVE_DATA = false;
bool RESTORE_DATA = false;
int_ts workingThreads; // total no of threads working
int_ts maxPagesReached; // for storing total processed pages till now
int_ts totalVisitedPages; // hashing utility for visited pages
mutex timingLock;
vector<vector<double>> threadTimings;
map_ts<string, int> download_stat;
// lock and cond_var for parent
bool ready = false;
condition_variable cv;
mutex cv_m;
// queue for storing linked websites
queue_ts linkQueue;
// map for storing visited websites
map_ts<string, bool> discoveredSites;
// for storing page relations
map_ts<string, set<string>> adjList;
// Constructor
// Crawler()
// {
// }
// Destructor
// ~Crawler()
// {
// }
// Public Functions
/*
Initialize the Crawler.
*/
void initialize();
/*
Terminate the Crawler
*/
void terminate();
/*
Downloads a website and save it in buffer folder
*/
string downloader(string url);
/*
Parse a file from the buffer and update parameters{concurrency part}
*/
void parseFile(string filename);
/*
Start a crawler to discover a specific website.
*/
void runCrawler();
/*
Show the results of the crawling
*/
void showResults();
/*
Create a single thread
*/
void createThread();
/*
Sleeping the main thread
*/
void gotosleep();
/*
Awake the main thread
*/
void awake();
} myCrawler;
/*
Child thread for downloading + parsing + updating shared variables
*/
void childThread(string url, int th_no);
#endif