Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,35 @@ cmake-build-debug/
cmake-build-linux/

# Visual Studio 2015/2017 cache/options directory
.vs/
.vs/
cmake_install.cmake
CMakeCache.txt
install_manifest.txt
Makefile
SpeedTest
SpeedTestConfig.h
CMakeFiles/cmake.check_cache
CMakeFiles/CMakeDirectoryInformation.cmake
CMakeFiles/CMakeOutput.log
CMakeFiles/Makefile.cmake
CMakeFiles/Makefile2
CMakeFiles/progress.marks
CMakeFiles/TargetDirectories.txt
CMakeFiles/3.16.3/CMakeCCompiler.cmake
CMakeFiles/3.16.3/CMakeCXXCompiler.cmake
CMakeFiles/3.16.3/CMakeDetermineCompilerABI_C.bin
CMakeFiles/3.16.3/CMakeDetermineCompilerABI_CXX.bin
CMakeFiles/3.16.3/CMakeSystem.cmake
CMakeFiles/3.16.3/CompilerIdC/CMakeCCompilerId.c
CMakeFiles/3.16.3/CompilerIdCXX/CMakeCXXCompilerId.cpp
CMakeFiles/SpeedTest.dir/build.make
CMakeFiles/SpeedTest.dir/cmake_clean.cmake
CMakeFiles/SpeedTest.dir/CXX.includecache
CMakeFiles/SpeedTest.dir/depend.internal
CMakeFiles/SpeedTest.dir/depend.make
CMakeFiles/SpeedTest.dir/DependInfo.cmake
CMakeFiles/SpeedTest.dir/flags.make
CMakeFiles/SpeedTest.dir/link.txt
CMakeFiles/SpeedTest.dir/progress.make
CMakeFiles/Progress/1
CMakeFiles/Progress/count.txt
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.7)
project(SpeedTest)

set (SpeedTest_VERSION_MAJOR 1)
set (SpeedTest_VERSION_MINOR 14)
set (SpeedTest_VERSION_MINOR 15)
set (SpeedTest_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR})
set (SpeedTest_SYSTEM ${CMAKE_SYSTEM})

Expand Down
136 changes: 78 additions & 58 deletions CmdOptions.h
Original file line number Diff line number Diff line change
@@ -1,86 +1,106 @@
//
// Created by Francesco Laurita on 9/9/16.
// SPDX-License-Identifier: MIT
//

#ifndef SPEEDTEST_CMDOPTIONS_H
#define SPEEDTEST_CMDOPTIONS_H
#include <getopt.h>

enum OutputType { verbose, text, json };

enum OutputType
{
verbose,
text,
json
};
enum LineType
{
automatic,
slow,
narrow,
broad,
fiber,
gigasym
};

typedef struct program_options_t {
bool help = false;
bool latency = false;
typedef struct program_options_t
{
bool help = false;
bool latency = false;
bool download = false;
bool upload = false;
bool share = false;
bool upload = false;
bool share = false;
bool insecure = false;
std::string selected_server = "";
OutputType output_type = OutputType::verbose;
LineType line_type = LineType::automatic;
} ProgramOptions;

static struct option CmdLongOptions[] = {
{"help", no_argument, 0, 'h' },
{"latency", no_argument, 0, 'l' },
{"download", no_argument, 0, 'd' },
{"upload", no_argument, 0, 'u' },
{"share", no_argument, 0, 's' },
{"insecure", no_argument, 0, 'i' },
{"test-server", required_argument, 0, 't' },
{"output", required_argument, 0, 'o' },
{0, 0, 0, 0 }
static struct option CmdLongOptions[] =
{
{"help", no_argument, 0, 'h'},
{"latency", no_argument, 0, 'l'},
{"download", no_argument, 0, 'd'},
{"upload", no_argument, 0, 'u'},
{"share", no_argument, 0, 's'},
{"insecure", no_argument, 0, 'i' },
{"test-server", required_argument, 0, 't'},
{"output", required_argument, 0, 'o'},
{"line-type", required_argument, 0, 'i'},
{0, 0, 0, 0}
};

const char *optStr = "hldusiqt:o:";
const char *optStr = "hldusqt:o:";

bool ParseOptions(const int argc, const char **argv, ProgramOptions& options){
int long_index =0;
bool ParseOptions(const int argc, const char **argv, ProgramOptions &options)
{
int long_index = 0;
int opt = 0;
while ((opt = getopt_long(argc, (char **)argv, optStr, CmdLongOptions, &long_index )) != -1) {
switch (opt){
case 'h':
options.help = true;
break;
case 'l':
options.latency = true;
break;
case 'd':
options.download = true;
break;
case 'u':
options.upload = true;
break;
case 's':
options.share = true;
break;
case 'i':
options.insecure = true;
break;
case 't':
options.selected_server.append(optarg);
break;
case 'o':
if (strcmp(optarg, "verbose") == 0)
options.output_type = OutputType::verbose;
else if (strcmp(optarg, "text") == 0)
options.output_type = OutputType::text;
else if (strcmp(optarg, "json") == 0)
options.output_type = OutputType::json;
else {
std::cerr << "Unsupported output type " << optarg << std::endl;
std::cerr << "Supported output type: default, text, json" <<std::endl;
return false;
}
while ((opt = getopt_long(argc, (char **)argv, optStr, CmdLongOptions, &long_index)) != -1)
{
switch (opt)
{
case 'h':
options.help = true;
break;
case 'l':
options.latency = true;
break;
case 'd':
options.download = true;
break;
case 'u':
options.upload = true;
break;
case 's':
options.share = true;
break;
case 'i':
options.insecure = true;
break;
case 't':
options.selected_server.append(optarg);
break;
case 'o':
if (strcmp(optarg, "verbose") == 0)
options.output_type = OutputType::verbose;
else if (strcmp(optarg, "text") == 0)
options.output_type = OutputType::text;
else if (strcmp(optarg, "json") == 0)
options.output_type = OutputType::json;
else
{
std::cerr << "Unsupported output type " << optarg << std::endl;
std::cerr << "Supported output type: default, text, json" << std::endl;
return false;
}

break;
default:
return false;
}

}
return true;
}


#endif //SPEEDTEST_CMDOPTIONS_H
#endif // SPEEDTEST_CMDOPTIONS_H
16 changes: 10 additions & 6 deletions DataTypes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// Created by Francesco Laurita on 6/8/16.
// SPDX-License-Identifier: MIT
//

#ifndef SPEEDTEST_DATATYPES_H
Expand All @@ -9,35 +10,38 @@
#include <stdlib.h>
static const float EARTH_RADIUS_KM = 6371.0;

typedef struct ip_info_t {
typedef struct ip_info_t
{
std::string ip_address;
std::string isp;
float lat;
float lon;
} IPInfo;

typedef struct server_info_t {
typedef struct server_info_t
{
std::string url;
std::string name;
std::string country;
std::string country_code;
std::string host;
std::string sponsor;
int id;
int id;
float lat;
float lon;
float distance;

} ServerInfo;

typedef struct test_config_t {
typedef struct test_config_t
{
long start_size;
long max_size;
long incr_size;
long buff_size;
long min_test_time_ms;
int concurrency;
int concurrency;
std::string label;
} TestConfig;

#endif //SPEEDTEST_DATATYPES_H
#endif // SPEEDTEST_DATATYPES_H
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# SPDX-License-Identifier: MIT

FROM ubuntu:latest as builder

RUN mkdir -p /tmp/build /tmp/src
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 taganaka

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 4 additions & 3 deletions MD5Util.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//
// Created by Francesco Laurita on 6/3/16.
// SPDX-License-Identifier: MIT
//

#include <sstream>
#include "MD5Util.h"

std::string MD5Util::hexDigest(const std::string &str) {
std::string MD5Util::hexDigest(const std::string &str)
{
unsigned char digest[MD5_DIGEST_LENGTH];

MD5_CTX ctx;
Expand All @@ -15,8 +17,7 @@ std::string MD5Util::hexDigest(const std::string &str) {

char hexDigest[33] = {'\0'};
for (int i = 0; i < 16; i++)
std::sprintf(&hexDigest[i*2], "%02x", (unsigned int)digest[i]);
std::sprintf(&hexDigest[i * 2], "%02x", (unsigned int)digest[i]);

return std::string(hexDigest);
}

15 changes: 8 additions & 7 deletions MD5Util.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
//
// Created by Francesco Laurita on 6/3/16.
// SPDX-License-Identifier: MIT
//

#ifndef SPEEDTEST_MD5UTIL_H
#define SPEEDTEST_MD5UTIL_H
#if defined(__APPLE__)
# define COMMON_DIGEST_FOR_OPENSSL
# include <CommonCrypto/CommonDigest.h>
#define COMMON_DIGEST_FOR_OPENSSL
#include <CommonCrypto/CommonDigest.h>
#include <string>

# define SHA1 CC_SHA1
#define SHA1 CC_SHA1
#else
# include <openssl/md5.h>
#include <openssl/md5.h>
#endif

class MD5Util {
class MD5Util
{
public:
static std::string hexDigest(const std::string &str);
};


#endif //SPEEDTEST_MD5UTIL_H
#endif // SPEEDTEST_MD5UTIL_H
Loading