Bredbandskollen CLI  1.2
Asynchronous network task engine
speedtest.h
1 // Copyright (c) 2018 IIS (The Internet Foundation in Sweden)
2 // Written by Göran Andersson <initgoran@gmail.com>
3 
4 #pragma once
5 
6 // Perform a standard speed test, measuring latency, download speed, and upload
7 // speed.
8 
9 #include "../json11/json11.hpp"
10 #include "../framework/task.h"
11 #include "../http/httphost.h"
12 
13 class MeasurementAgent;
14 class InfoTask;
15 
16 class SpeedTest : public Task {
17 public:
18  SpeedTest(MeasurementAgent *agent, const HttpHost &mserver,
19  const std::map<std::string, std::string> &report_data);
20  double start() override;
21  void taskMessage(Task *task) override;
22  void taskFinished(Task *task) override;
23  void uploadComplete();
24  void doSaveReport(const json11::Json &args = json11::Json::object());
25  void addToReport(const std::string &attr, const std::string &val);
26 private:
27  MeasurementAgent *the_agent = nullptr;
28  InfoTask *info_task = nullptr;
29  HttpHost mserv;
30  std::map<std::string, std::string> report;
31  std::string tstr;
32  double upload_duration, download_duration;
33  std::string server_upload_speed, local_upload_speed;
34 
35  bool report_sent_to_server = false;
36  bool websocket_works = false;
37  // Normally, the server should calculate the latency result.
38  // If that failed and we have a locally calculated latency result,
39  // this will be set to true:
40  bool local_latency = false;
41 
42  double speed_limit = 0.0;
43  unsigned int initial_no_dconn = 10, initial_no_uconn = 4;
44  unsigned int max_no_dconn = 100, max_no_uconn = 100;
45 
46  uint64_t bytesSentAtStart;
47  uint64_t bytesRecAtStart;
48 };
The host name and port number of a HTTP host.
Definition: httphost.h:17
Definition: infotask.h:8
Definition: measurementagent.h:17
Definition: speedtest.h:16
void taskMessage(Task *task) override
Definition: speedtest.cpp:66
void taskFinished(Task *task) override
Definition: speedtest.cpp:130
double start() override
Definition: speedtest.cpp:60
The purpose of a task is to manage socket connections, and/or to execute timers.
Definition: task.h:39