Skip to content

Commit

Permalink
optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Consti10 committed Aug 13, 2023
1 parent b7acf1c commit a100d0d
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/Encryption.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ KeyPairTxRx read_keypair_from_file(const std::string& filename);

/**
* https://libsodium.gitbook.io/doc/key_derivation
* Helper since we both support encryption and one time validation to save cpu performance
* UINT16SeqNrHelper since we both support encryption and one time validation to save cpu performance
*/
std::array<uint8_t,32> create_onetimeauth_subkey(const uint64_t& nonce,const std::array<uint8_t, crypto_aead_chacha20poly1305_KEYBYTES>& session_key);

Expand Down
2 changes: 1 addition & 1 deletion src/HelperSources/Helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "StringHelper.hpp"

// Generic "Helper" code that does not depend on anything else other than the std libraries
// Generic "UINT16SeqNrHelper" code that does not depend on anything else other than the std libraries

namespace GenericHelper {
// fill buffer with random bytes
Expand Down
33 changes: 15 additions & 18 deletions src/HelperSources/SeqNrHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,11 @@
#include "../wifibroadcast_spdlog.h"
#include <spdlog/spdlog.h>

namespace seq_nr{

static int diff_between_packets_rolling_uint16_t(int last_packet,int curr_packet){
if(last_packet==curr_packet){
wifibroadcast::log::get_default()->debug("Duplicate in seq nr {}-{}, invalid usage",last_packet,curr_packet);
}
if(curr_packet<last_packet){
// We probably have overflown the uin16_t range
const auto diff=curr_packet+UINT16_MAX+1-last_packet;
return diff;
}else{
return curr_packet-last_packet;
}
}

// Helper for calculating statistics for a link with a rolling (wrap around) uint16_t sequence number
class Helper{
// UINT16SeqNrHelper for calculating statistics for a link with a rolling (wrap around) uint16_t sequence number
class UINT16SeqNrHelper {
public:
Helper(){
UINT16SeqNrHelper(){
m_gaps.reserve(MAX_N_STORED_GAPS);
m_curr_packet_loss=-1;
}
Expand Down Expand Up @@ -115,6 +101,18 @@ class Helper{
m_last_big_gaps_counter_recalculation=std::chrono::steady_clock::now();
}
}
static int diff_between_packets_rolling_uint16_t(int last_packet,int curr_packet){
if(last_packet==curr_packet){
wifibroadcast::log::get_default()->debug("Duplicate in seq nr {}-{}, invalid usage",last_packet,curr_packet);
}
if(curr_packet<last_packet){
// We probably have overflown the uin16_t range
const auto diff=curr_packet+UINT16_MAX+1-last_packet;
return diff;
}else{
return curr_packet-last_packet;
}
}
private:
int m_last_seq_nr=-1;
static constexpr int MAX_N_STORED_GAPS=1000;
Expand All @@ -132,5 +130,4 @@ class Helper{
bool m_store_and_debug_gaps= false;
};

}
#endif // WIFIBROADCAST_SRC_HELPERSOURCES_SEQNRHELPER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Created by consti10 on 08.08.23.
//

#ifndef WIFIBROADCAST_NONCESEQNRHELPER_H
#define WIFIBROADCAST_NONCESEQNRHELPER_H
#ifndef WIFIBROADCAST_UINT64SEQNRHELPER_H
#define WIFIBROADCAST_UINT64SEQNRHELPER_H

#include <atomic>
#include <cmath>
Expand All @@ -13,10 +13,10 @@
#include <spdlog/spdlog.h>
#include "StringHelper.hpp"

// Helper for dealing with sequence number
// UINT16SeqNrHelper for dealing with sequence number
// (calculate packet loss and more)
// Using a unique uint64_t nonce
class NonceSeqNrHelper{
class UInt64SeqNrHelper {
public:
int16_t get_current_loss_percent(){
return m_curr_loss_perc.load();
Expand Down Expand Up @@ -129,4 +129,4 @@ class NonceSeqNrHelper{
int m_card_index=0;
};

#endif // WIFIBROADCAST_NONCESEQNRHELPER_H
#endif // WIFIBROADCAST_UINT64SEQNRHELPER_H
6 changes: 3 additions & 3 deletions src/Ieee80211Header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "wifibroadcast_spdlog.h"
#include <spdlog/spdlog.h>

// Helper for dealing with the IEEE80211 header in wifibroadcast / openhd
// UINT16SeqNrHelper for dealing with the IEEE80211 header in wifibroadcast / openhd
// Usefully references:
// https://witestlab.poly.edu/blog/802-11-wireless-lan-2/
// https://en.wikipedia.org/wiki/802.11_Frame_Types
Expand All @@ -24,14 +24,14 @@
// | control field | duration | MAC of AP | SRC MAC | DST MAC | Sequence control |
static constexpr auto IEEE80211_HEADER_SIZE_BYTES = 24;

// Helper for control field - we do not touch it
// UINT16SeqNrHelper for control field - we do not touch it
struct ControlField{
uint8_t part1=0x08;
uint8_t part2=0x01;
}__attribute__ ((packed));
static_assert(sizeof(ControlField) == 2);

// Helper for sequence control field
// UINT16SeqNrHelper for sequence control field
//https://witestlab.poly.edu/blog/802-11-wireless-lan-2/
//Sequence Control: Contains a 4-bit fragment number subfield, used for fragmentation and reassembly, and a 12-bit sequence number used to number
//frames sent between a given transmitter and receiver.
Expand Down
2 changes: 1 addition & 1 deletion src/RSSIAccumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "wifibroadcast_spdlog.h"

/**
* Helper to accumulate RSSI values
* UINT16SeqNrHelper to accumulate RSSI values
*/
class RSSIAccumulator{
public:
Expand Down
2 changes: 1 addition & 1 deletion src/SignalQualityAccumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "wifibroadcast_spdlog.h"

/**
* Helper to accumulate (rtl8812au) signal quality values
* UINT16SeqNrHelper to accumulate (rtl8812au) signal quality values
*/
class SignalQualityAccumulator{
public:
Expand Down
1 change: 0 additions & 1 deletion src/WBStreamRx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,4 @@ WBStreamRx::FECRxStats2 WBStreamRx::get_latest_fec_stats() {
void WBStreamRx::reset_stream_stats() {
m_n_input_bytes=0;
m_n_input_packets=0;
m_seq_nr_helper.reset();
}
1 change: 0 additions & 1 deletion src/WBStreamRx.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class WBStreamRx {
// On the rx, either one of those two is active at the same time.
std::unique_ptr<FECDecoder> m_fec_decoder = nullptr;
std::unique_ptr<FECDisabledDecoder> m_fec_disabled_decoder = nullptr;
seq_nr::Helper m_seq_nr_helper;
void on_new_packet(uint64_t nonce,int wlan_index,const uint8_t *data, const int data_len);
void on_new_session();
void on_decoded_packet(const uint8_t* data,int data_len);
Expand Down
12 changes: 6 additions & 6 deletions src/WBTxRx.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
#include <atomic>
#include <map>
#include <mutex>
#include <optional>
#include <thread>
#include <utility>
#include <optional>

#include "Encryption.h"
#include "Ieee80211Header.hpp"
#include "NonceSeqNrHelper.h"
#include "RSSIAccumulator.hpp"
#include "RadiotapHeader.hpp"
#include "SeqNrHelper.hpp"
#include "TimeHelper.hpp"
#include "RSSIAccumulator.hpp"
#include "SignalQualityAccumulator.hpp"
#include "TimeHelper.hpp"
#include "UInt64SeqNrHelper.h"

/**
* This class exists to provide a clean, working interface to create a
Expand Down Expand Up @@ -299,10 +299,10 @@ class WBTxRx {
std::unique_ptr<std::thread> m_receive_thread;
std::vector<pollfd> m_receive_pollfds;
std::chrono::steady_clock::time_point m_last_receiver_error_log=std::chrono::steady_clock::now();
seq_nr::Helper m_seq_nr_helper_iee80211;
UINT16SeqNrHelper m_seq_nr_helper_iee80211;
// for calculating the loss and more per rx card (when multiple rx cards are used)
struct PerCardCalculators{
NonceSeqNrHelper seq_nr{};
UInt64SeqNrHelper seq_nr{};
RSSIAccumulator card_rssi{};
RSSIAccumulator antenna1_rssi{};
RSSIAccumulator antenna2_rssi{};
Expand Down

0 comments on commit a100d0d

Please sign in to comment.