-
Notifications
You must be signed in to change notification settings - Fork 0
/
opoznienia.cpp
87 lines (79 loc) · 2.54 KB
/
opoznienia.cpp
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
/*
* Paweł Kapica, 334579
* Sieci Komputerowe
* Duże zadanie zaliczeniowe
*
*/
#include <iostream>
#include <cstdlib>
#include <vector>
#include "utils.h"
#include "datacontainer.h"
#include "serverdns.h"
#include "serverudp.h"
#include "tcpconnection.h"
#include "telnetserver.h"
#include "delaychecker.h"
using namespace std;
namespace po = boost::program_options;
int main(int argc, char ** argv)
{
uint16_t udp_server_port, ui_port;
uint32_t latency_time, discover_time;
float_t ui_refresh_time;
po::options_description desc("Allowed options");
desc.add_options()
(",u", po::value<uint16_t>(&udp_server_port)->default_value(3382), "UDP server port")
(",U", po::value<uint16_t>(&ui_port)->default_value(3637), "UI port")
(",t", po::value<uint32_t>(&latency_time)->default_value(1), "time between measuring latency")
(",T", po::value<uint32_t>(&discover_time)->default_value(10), "time between discovering available hosts")
(",v", po::value<float_t>(&ui_refresh_time)->default_value(1.0), "UI refresh time")
(",s", "SSH broadcast")
;
po::variables_map vm;
try
{
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
}
catch(po::error& e)
{
cerr<<"ERROR: "<<e.what()<<endl;
cerr<<desc<<endl;
return 0;
}
try
{
unsigned int nthreads = boost::thread::hardware_concurrency();
boost::asio::io_service udp_serv_service;
boost::asio::io_service dns_serv_service;
boost::asio::io_service delay_service;
ServerUDP serverUDP(udp_serv_service, udp_server_port);
ServerDNS serverDNS(dns_serv_service, discover_time, vm.count("-s"));
boost::thread serverDNSThread(boost::bind(&boost::asio::io_service::run, &dns_serv_service));
boost::thread serverUDPThread(boost::bind(&ServerUDP::run_server, &serverUDP));
TelnetServer server(delay_service, ui_port, ui_refresh_time);
DelayChecker delcheck(delay_service, latency_time);
boost::asio::deadline_timer timer_(delay_service);
DataContainer::dc()->set_timer(&timer_);
boost::thread delayThread(boost::bind(&boost::asio::io_service::run, &delay_service));
std::vector<boost::thread*> threads;
for (size_t i = 0; i < nthreads-3; i++) {
boost::thread *t = new boost::thread(boost::bind(&boost::asio::io_service::run, &delay_service));
threads.push_back(t);
}
std::cerr<<"WORKING\n";
serverUDPThread.join();
serverDNSThread.join();
delayThread.join();
for (size_t i = 0; i < threads.size(); i++) {
threads[i]->join();
delete threads[i];
}
}
catch (std::exception& e)
{
cerr<<e.what()<<endl;
}
return 0;
}