Skip to content

Commit

Permalink
Merge pull request #41 from OpenHD/dev/code_cleanup
Browse files Browse the repository at this point in the history
Dev/code cleanup
Thank you @buldo
  • Loading branch information
Consti10 authored Nov 22, 2023
2 parents f368fd1 + 341ff62 commit 2762d89
Show file tree
Hide file tree
Showing 35 changed files with 1,530 additions and 1,205 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ fabric.properties
misc.xml
.idea/*

/.vs
25 changes: 25 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": 3,
"configurePresets": [
{
"name": "linux-debug",
"displayName": "Linux Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
}
]
}
16 changes: 14 additions & 2 deletions WBLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@ target_sources(wifibroadcast PRIVATE
# radiotap and fec
${CMAKE_CURRENT_LIST_DIR}/src/external/radiotap/radiotap.c
${CMAKE_CURRENT_LIST_DIR}/src/external/fec/fec_base.cpp
${CMAKE_CURRENT_LIST_DIR}/src/FECStream.cpp

${CMAKE_CURRENT_LIST_DIR}/src/encryption/Key.hpp
${CMAKE_CURRENT_LIST_DIR}/src/encryption/KeyPairTxRx.hpp
${CMAKE_CURRENT_LIST_DIR}/src/encryption/Encryptor.cpp
${CMAKE_CURRENT_LIST_DIR}/src/encryption/Encryption.cpp
${CMAKE_CURRENT_LIST_DIR}/src/encryption/EncryptionFsUtils.cpp
${CMAKE_CURRENT_LIST_DIR}/src/encryption/Decryptor.cpp

${CMAKE_CURRENT_LIST_DIR}/src/fec/FEC.cpp
${CMAKE_CURRENT_LIST_DIR}/src/fec/FECConstants.hpp
${CMAKE_CURRENT_LIST_DIR}/src/fec/FECDecoder.cpp
${CMAKE_CURRENT_LIST_DIR}/src/fec/FECEncoder.cpp
${CMAKE_CURRENT_LIST_DIR}/src/fec/RxBlock.cpp

${CMAKE_CURRENT_LIST_DIR}/src/WBStreamRx.cpp
${CMAKE_CURRENT_LIST_DIR}/src/WBStreamTx.cpp
${CMAKE_CURRENT_LIST_DIR}/src/WBTxRx.cpp
Expand All @@ -34,7 +47,6 @@ target_sources(wifibroadcast PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/radiotap/RadiotapHeaderTxHolder.hpp
${CMAKE_CURRENT_LIST_DIR}/src/radiotap/RSSIAccumulator.hpp
${CMAKE_CURRENT_LIST_DIR}/src/wifibroadcast_spdlog.cpp
${CMAKE_CURRENT_LIST_DIR}/src/Encryption.cpp
${CMAKE_CURRENT_LIST_DIR}/src/radiotap/RadiotapRxRfAggregator.cpp
)

Expand Down
8 changes: 6 additions & 2 deletions executables/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@
#include <sstream>
#include <string>

#include "../src/Encryption.h"
#include "../src/FECStream.h"
#include "../src/encryption/Encryption.h"
#include "../src/fec/FEC.h"
#include "../src/HelperSources/RandomBufferPot.hpp"
#include "../src/HelperSources/SchedulingHelper.hpp"
#include "../src/external/fec/fec_base.h"
#include "../src/fec/FECEncoder.h"
#include "../src/fec/FECConstants.hpp"
#include "../src/encryption/Encryptor.h"
#include "../src/encryption/Decryptor.h"

// Test the FEC encoding / decoding and Encryption / Decryption performance
// (throughput) of this system
Expand Down
77 changes: 73 additions & 4 deletions executables/unit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,87 @@
#include <sstream>
#include <string>

#include "../src/FECStream.h"
#include "../src/FEC.hpp"
#include "../src/fec/FEC.h"

#include "../src/Encryption.h"
#include "../src/encryption/Encryption.h"
#include "../src/encryption/EncryptionFsUtils.h"
#include "../src/HelperSources/Helper.hpp"
#include "../src/Ieee80211Header.hpp"
#include "../src/wifibroadcast_spdlog.h"
#include "../src/fec/FECDecoder.h"
#include "../src/fec/FECEncoder.h"
#include "../src/encryption/Encryptor.h"
#include "../src/encryption/Decryptor.h"

// Simple unit testing for the FEC lib that doesn't require wifi cards

namespace TestFEC {

// randomly select a possible combination of received indices (either primary or
// secondary).
static void testFecCPlusPlusWrapperY(const int nPrimaryFragments,
const int nSecondaryFragments) {
srand(time(NULL));
constexpr auto FRAGMENT_SIZE = 1446;

auto txBlockBuffer = GenericHelper::createRandomDataBuffers<FRAGMENT_SIZE>(
nPrimaryFragments + nSecondaryFragments);
std::cout << "XSelected nPrimaryFragments:" << nPrimaryFragments
<< " nSecondaryFragments:" << nSecondaryFragments << "\n";

fecEncode(FRAGMENT_SIZE, txBlockBuffer, nPrimaryFragments,
nSecondaryFragments);
std::cout << "Encode done\n";

for (int test = 0; test < 100; test++) {
// takes nPrimaryFragments random (possible) indices without duplicates
// NOTE: Perhaps you could calculate all possible permutations, but these
// would be quite a lot. Therefore, I just use n random selections of
// received indices
auto receivedFragmentIndices = GenericHelper::takeNRandomElements(
GenericHelper::createIndices(nPrimaryFragments + nSecondaryFragments),
nPrimaryFragments);
assert(receivedFragmentIndices.size() == nPrimaryFragments);
std::cout << "(Emulated) receivedFragmentIndices"
<< StringHelper::vectorAsString(receivedFragmentIndices) << "\n";

auto rxBlockBuffer = std::vector<std::array<uint8_t, FRAGMENT_SIZE>>(
nPrimaryFragments + nSecondaryFragments);
std::vector<bool> fragmentMap(nPrimaryFragments + nSecondaryFragments,
FRAGMENT_STATUS_UNAVAILABLE);
for (const auto idx : receivedFragmentIndices) {
rxBlockBuffer[idx] = txBlockBuffer[idx];
fragmentMap[idx] = FRAGMENT_STATUS_AVAILABLE;
}

fecDecode(FRAGMENT_SIZE, rxBlockBuffer, nPrimaryFragments, fragmentMap);

for (unsigned int i = 0; i < nPrimaryFragments; i++) {
// std::cout<<"Comparing fragment:"<<i<<"\n";
GenericHelper::assertArraysEqual(txBlockBuffer[i], rxBlockBuffer[i]);
}
}
}

// Note: This test will take quite a long time ! (or rather ages :) when trying
// to do all possible combinations. )
static void testFecCPlusPlusWrapperX() {
std::cout << "testFecCPlusPlusWrapper Begin\n";
// constexpr auto MAX_N_P_F=128;
// constexpr auto MAX_N_S_F=128;
// else it really takes ages
constexpr auto MAX_N_P_F = 32;
constexpr auto MAX_N_S_F = 32;
for (int nPrimaryFragments = 1; nPrimaryFragments < MAX_N_P_F;
nPrimaryFragments++) {
for (int nSecondaryFragments = 0; nSecondaryFragments < MAX_N_S_F;
nSecondaryFragments++) {
testFecCPlusPlusWrapperY(nPrimaryFragments, nSecondaryFragments);
}
}
std::cout << "testFecCPlusPlusWrapper End\n";
}

// Chooses randomly
// 1) block size (n fragments in block)
// 2) size of data in each fragment in a block
Expand Down Expand Up @@ -204,7 +273,7 @@ int main(int argc, char *argv[]) {
// First test FEC itself
test_gf();
test_fec();
testFecCPlusPlusWrapperX();
TestFEC::testFecCPlusPlusWrapperX();
// and then the FEC streaming implementation
TestFEC::test_fec_stream_random_bs_fs_overhead_dropped();
}
Expand Down
4 changes: 3 additions & 1 deletion executables/wfb_keygen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include <iostream>
#include <optional>

#include "../src/Encryption.h"
#include "../src/encryption/Encryption.h"
#include "../src/encryption/EncryptionFsUtils.h"
#include "../src/encryption/KeyPairTxRx.hpp"

/**
* Generates a new tx rx keypair and saves it to file for later use.
Expand Down
200 changes: 0 additions & 200 deletions src/Encryption.cpp

This file was deleted.

Loading

0 comments on commit 2762d89

Please sign in to comment.