diff --git a/meson.build b/meson.build index 5be78f0..204d957 100644 --- a/meson.build +++ b/meson.build @@ -20,11 +20,18 @@ sources = files([ 'src/TlsConnectionManager.cpp', ]) +# Pull in subprojects +fmt_wrap = subproject('fmt', default_options: 'default_library=static') +meson.override_dependency('fmt', fmt_wrap.get_variable('fmt_dep')) # Use our copy of fmt for spdlog +spdlog_wrap = subproject('spdlog', default_options: ['default_library=static', 'compile_library=true', 'external_fmt=true'] ) +catch2_wrap = subproject('catch2') + deps = [ dependency('libssl'), dependency('libcrypto'), - dependency('catch2', fallback: ['catch2', 'catch2_dep']), - subproject('spdlog').get_variable('spdlog_dep'), # use wrapped copy of spdlog + # Meson wrapped dependencies + fmt_wrap.get_variable('fmt_dep'), + spdlog_wrap.get_variable('spdlog_dep'), ] incdir = include_directories(['src', 'inc']) @@ -32,6 +39,7 @@ incdir = include_directories(['src', 'inc']) executable( 'janus-ftl-orchestrator', sources, + cpp_pch: 'pch/pch.h', include_directories: incdir, dependencies: deps, install: true, @@ -51,9 +59,19 @@ testsources = files([ 'src/TlsConnectionManager.cpp', ]) +testdeps = [ + dependency('libssl'), + dependency('libcrypto'), + # Meson wrapped dependencies + fmt_wrap.get_variable('fmt_dep'), + spdlog_wrap.get_variable('spdlog_dep'), + catch2_wrap.get_variable('catch2_dep'), +] + executable( 'janus-ftl-orchestrator-test', testsources, + cpp_pch: 'pch/test_pch.h', include_directories: incdir, - dependencies: deps, + dependencies: testdeps, ) \ No newline at end of file diff --git a/pch/pch.h b/pch/pch.h new file mode 100644 index 0000000..2e479a9 --- /dev/null +++ b/pch/pch.h @@ -0,0 +1,10 @@ +/** + * @file pch.h + * @author Hayden McAfee (hayden@outlook.com) + * @date 2021-02-28 + * @copyright Copyright (c) 2021 Hayden McAfee + * @brief Pre-compiled header for janus-ftl-orchestrator + */ + +#include +#include \ No newline at end of file diff --git a/pch/test_pch.h b/pch/test_pch.h new file mode 100644 index 0000000..f7af40d --- /dev/null +++ b/pch/test_pch.h @@ -0,0 +1,13 @@ +/** + * @file test_pch.h + * @author Hayden McAfee (hayden@outlook.com) + * @date 2021-02-28 + * @copyright Copyright (c) 2021 Hayden McAfee + * @brief Pre-compiled header for janus-ftl-orchestrator-test + */ + +#include +#include + +#define CATCH_CONFIG_ALL_PARTS +#include \ No newline at end of file diff --git a/src/Configuration.cpp b/src/Configuration.cpp index c0e032d..9670093 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -7,7 +7,6 @@ #include "Configuration.h" -#include #include #pragma region Public methods diff --git a/src/Orchestrator.cpp b/src/Orchestrator.cpp index d7e3d21..af91c2f 100644 --- a/src/Orchestrator.cpp +++ b/src/Orchestrator.cpp @@ -12,8 +12,6 @@ #include "StreamStore.h" #include "Util.h" -#include - #include #pragma region Constructor/Destructor diff --git a/src/SubscriptionStore.h b/src/SubscriptionStore.h index ab1d9a3..7dd5e86 100644 --- a/src/SubscriptionStore.h +++ b/src/SubscriptionStore.h @@ -10,8 +10,6 @@ #include "ChannelSubscription.h" #include "FtlTypes.h" -#include - #include #include #include diff --git a/src/TlsConnectionManager.cpp b/src/TlsConnectionManager.cpp index 9cf0763..ef52eb2 100644 --- a/src/TlsConnectionManager.cpp +++ b/src/TlsConnectionManager.cpp @@ -12,7 +12,6 @@ #include "Util.h" #include -#include #include #include diff --git a/src/test-client.cpp b/src/test-client.cpp deleted file mode 100644 index 7dd2541..0000000 --- a/src/test-client.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/** - * @file test-client.cpp - * @author Hayden McAfee (hayden@outlook.com) - * @date 2020-10-18 - * @copyright Copyright (c) 2020 Hayden McAfee - */ - -#include "Util.h" - -#include -#include -#include -#include -#include -#include -#include - -int psk(SSL *ssl, const EVP_MD *md, const unsigned char **id, size_t *idlen, SSL_SESSION **sess) -{ - long keyLength = 0; - unsigned char* key = OPENSSL_hexstr2buf("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", &keyLength); - - spdlog::info("PSK processing with key {} / {}...", key, keyLength); - spdlog::info("Using key {}", spdlog::to_hex(key, key + keyLength)); - - spdlog::info("MD: {:p}", reinterpret_cast(md)); - - // Find the cipher we'll be using - // identified by IANA mapping: https://testssl.sh/openssl-iana.mapping.html - const unsigned char tls13_aes128gcmsha256_id[] = { 0x13, 0x01 }; - const SSL_CIPHER* cipher = SSL_CIPHER_find(ssl, tls13_aes128gcmsha256_id); - if (cipher == nullptr) - { - spdlog::error("OpenSSL could not find cipher suite!"); - OPENSSL_free(key); - return 0; - } - - // Create an SSL session and set some parameters on it - SSL_SESSION* temporarySslSession = SSL_SESSION_new(); - if (temporarySslSession == nullptr) - { - spdlog::error("Could not create new SSL session!"); - OPENSSL_free(key); - return 0; - } - - if (!SSL_SESSION_set1_master_key(temporarySslSession, key, keyLength)) - { - spdlog::error("Could not set key on new SSL session!"); - OPENSSL_free(key); - return 0; - } - OPENSSL_free(key); - - if (!SSL_SESSION_set_cipher(temporarySslSession, cipher)) - { - spdlog::error("Could not set cipher on new SSL session!"); - return 0; - } - - if (!SSL_SESSION_set_protocol_version(temporarySslSession, TLS1_3_VERSION)) - { - spdlog::error("Could not set version on new SSL session!"); - return 0; - } - - - *sess = temporarySslSession; - *id = reinterpret_cast("test"); - *idlen = 4; - - return 1; -} - -int main() -{ - uint16_t port = 8085; - - spdlog::info("Hello world!"); - - // Let's try connecting... - SSL_load_error_strings(); - SSL_library_init(); - OpenSSL_add_all_algorithms(); - - int clientSocketHandle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - sockaddr_in serverAddr - { - .sin_family = AF_INET, - .sin_port = htons(port), - .sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) } - }; - - spdlog::info("Connecting to port {}...", port); - - if (connect(clientSocketHandle, reinterpret_cast(&serverAddr), sizeof(serverAddr)) < 0) - { - int error = errno; - std::stringstream errStr; - errStr << "Unable to connect! Error " - << error << ": " << Util::ErrnoToString(error); - throw std::runtime_error(errStr.str()); - } - - spdlog::info("Connected!"); - - SSL_CTX* sslContext = SSL_CTX_new(TLS_client_method()); - if (sslContext == nullptr) - { - throw std::runtime_error("Error creating SSL context"); - } - - // Set up PSK - SSL_CTX_set_psk_use_session_callback(sslContext, psk); - - SSL* ssl = SSL_new(sslContext); - if (ssl == nullptr) - { - throw std::runtime_error("Error creating SSL instance"); - } - - spdlog::info("Setting SSL fd..."); - - SSL_set_fd(ssl, clientSocketHandle); - - spdlog::info("SSL Connecting..."); - const int status = SSL_connect(ssl); - if (status != 1) - { - char sslErrStr[256]; - unsigned long sslErr = ERR_get_error(); - ERR_error_string_n(sslErr, sslErrStr, sizeof(sslErrStr)); - throw std::runtime_error(sslErrStr); - } - - spdlog::info("Connected"); -} \ No newline at end of file diff --git a/subprojects/fmt.wrap b/subprojects/fmt.wrap new file mode 100644 index 0000000..e1f315d --- /dev/null +++ b/subprojects/fmt.wrap @@ -0,0 +1,11 @@ +[wrap-file] +directory = fmt-7.1.3 +source_url = https://github.com/fmtlib/fmt/archive/7.1.3.tar.gz +source_filename = fmt-7.1.3.tar.gz +source_hash = 5cae7072042b3043e12d53d50ef404bbb76949dad1de368d7f993a15c8c05ecc +patch_url = https://wrapdb.mesonbuild.com/v1/projects/fmt/7.1.3/1/get_zip +patch_filename = fmt-7.1.3-1-wrap.zip +patch_hash = 6eb951a51806fd6ffd596064825c39b844c1fe1799840ef507b61a53dba08213 + +[provide] +fmt = fmt_dep diff --git a/test/TestLogging.h b/test/TestLogging.h index 0afe680..508cd98 100644 --- a/test/TestLogging.h +++ b/test/TestLogging.h @@ -7,9 +7,7 @@ #pragma once -#include #include - #include template diff --git a/test/functional/FunctionalTests.cpp b/test/functional/FunctionalTests.cpp index 51efcee..c4a3123 100644 --- a/test/functional/FunctionalTests.cpp +++ b/test/functional/FunctionalTests.cpp @@ -5,8 +5,6 @@ * @copyright Copyright (c) 2020 Hayden McAfee */ -#include - #include #include #include diff --git a/test/test.cpp b/test/test.cpp index f2913be..9a76e12 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -5,15 +5,18 @@ * @copyright Copyright (c) 2020 Hayden McAfee */ -#define CATCH_CONFIG_RUNNER // This tells Catch that we'll be providing the main entrypoint -#include -#include - #include "TestLogging.h" #include #include +// Some Catch2 defines required for PCH support +// https://github.com/catchorg/Catch2/blob/v2.x/docs/ci-and-misc.md#precompiled-headers-pchs +#undef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +#define CATCH_CONFIG_IMPL_ONLY +#define CATCH_CONFIG_RUNNER +#include + int main(int argc, char* argv[]) { // Set up logging diff --git a/test/unit/FtlConnectionUnitTests.cpp b/test/unit/FtlConnectionUnitTests.cpp index e5a825a..80d9388 100644 --- a/test/unit/FtlConnectionUnitTests.cpp +++ b/test/unit/FtlConnectionUnitTests.cpp @@ -5,8 +5,6 @@ * @copyright Copyright (c) 2020 Hayden McAfee */ -#include - #include #include "../mocks/MockConnectionTransport.h" diff --git a/test/unit/OrchestratorUnitTests.cpp b/test/unit/OrchestratorUnitTests.cpp index 7a16801..4795713 100644 --- a/test/unit/OrchestratorUnitTests.cpp +++ b/test/unit/OrchestratorUnitTests.cpp @@ -6,8 +6,6 @@ * @brief Contains unit tests for the Orchestrator class. */ -#include - #include #include #include