cca interface

This commit is contained in:
Green Sky 2023-08-23 13:04:54 +02:00
parent 2f9340b937
commit 95b55c3a4a
No known key found for this signature in database
5 changed files with 70 additions and 9 deletions

View File

@ -22,6 +22,7 @@ add_library(solanaceae_ngcft1
./solanaceae/ngc_ft1/ngcft1.hpp ./solanaceae/ngc_ft1/ngcft1.hpp
./solanaceae/ngc_ft1/ngcft1.cpp ./solanaceae/ngc_ft1/ngcft1.cpp
./solanaceae/ngc_ft1/cca.hpp
./solanaceae/ngc_ft1/ledbat.hpp ./solanaceae/ngc_ft1/ledbat.hpp
./solanaceae/ngc_ft1/ledbat.cpp ./solanaceae/ngc_ft1/ledbat.cpp

View File

@ -0,0 +1,56 @@
#pragma once
#include <vector>
#include <cstdint>
struct CCAI {
public: // config
using SeqIDType = std::pair<uint8_t, uint16_t>; // tf_id, seq_id
static constexpr size_t IPV4_HEADER_SIZE {20};
static constexpr size_t IPV6_HEADER_SIZE {40}; // bru
static constexpr size_t UDP_HEADER_SIZE {8};
// TODO: tcp AND IPv6 will be different
static constexpr size_t SEGMENT_OVERHEAD {
4+ // ft overhead
46+ // tox?
UDP_HEADER_SIZE+
IPV4_HEADER_SIZE
};
// TODO: make configurable, set with tox ngc lossy packet size
//const size_t MAXIMUM_SEGMENT_DATA_SIZE {1000-4};
const size_t MAXIMUM_SEGMENT_DATA_SIZE {500-4};
const size_t MAXIMUM_SEGMENT_SIZE {MAXIMUM_SEGMENT_DATA_SIZE + SEGMENT_OVERHEAD}; // tox 500 - 4 from ft
//static_assert(maximum_segment_size == 574); // mesured in wireshark
// flow control
float max_byterate_allowed {10*1024*1024}; // 10MiB/s
public: // api
CCAI(size_t maximum_segment_data_size) : MAXIMUM_SEGMENT_DATA_SIZE(maximum_segment_data_size) {}
// return the current believed window in bytes of how much data can be inflight,
virtual float getCWnD(void) const = 0;
// TODO: api for how much data we should send
// take time since last sent into account
// respect max_byterate_allowed
virtual size_t canSend(void) const = 0;
// get the list of timed out seq_ids
virtual std::vector<SeqIDType> getTimeouts(void) const = 0;
public: // callbacks
// data size is without overhead
virtual void onSent(SeqIDType seq, size_t data_size) = 0;
// TODO: copy???
virtual void onAck(std::vector<SeqIDType> seqs) = 0;
// if discard, not resent, not inflight
virtual void onLoss(SeqIDType seq, bool discard) = 0;
};

View File

@ -15,7 +15,7 @@
inline constexpr bool PLOTTING = false; inline constexpr bool PLOTTING = false;
LEDBAT::LEDBAT(size_t maximum_segment_data_size) : MAXIMUM_SEGMENT_DATA_SIZE(maximum_segment_data_size) { LEDBAT::LEDBAT(size_t maximum_segment_data_size) : CCAI(maximum_segment_data_size) {
_time_start_offset = clock::now(); _time_start_offset = clock::now();
} }

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include "./cca.hpp"
#include <chrono> #include <chrono>
#include <deque> #include <deque>
#include <vector> #include <vector>
@ -9,8 +11,9 @@
// LEDBAT++: https://www.ietf.org/archive/id/draft-irtf-iccrg-ledbat-plus-plus-01.txt // LEDBAT++: https://www.ietf.org/archive/id/draft-irtf-iccrg-ledbat-plus-plus-01.txt
// LEDBAT++ implementation // LEDBAT++ implementation
struct LEDBAT { struct LEDBAT : public CCAI{
public: // config public: // config
#if 0
using SeqIDType = std::pair<uint8_t, uint16_t>; // tf_id, seq_id using SeqIDType = std::pair<uint8_t, uint16_t>; // tf_id, seq_id
static constexpr size_t IPV4_HEADER_SIZE {20}; static constexpr size_t IPV4_HEADER_SIZE {20};
@ -32,6 +35,7 @@ struct LEDBAT {
//static constexpr size_t maximum_segment_size {496 + segment_overhead}; // tox 500 - 4 from ft //static constexpr size_t maximum_segment_size {496 + segment_overhead}; // tox 500 - 4 from ft
const size_t MAXIMUM_SEGMENT_SIZE {MAXIMUM_SEGMENT_DATA_SIZE + SEGMENT_OVERHEAD}; // tox 500 - 4 from ft const size_t MAXIMUM_SEGMENT_SIZE {MAXIMUM_SEGMENT_DATA_SIZE + SEGMENT_OVERHEAD}; // tox 500 - 4 from ft
//static_assert(maximum_segment_size == 574); // mesured in wireshark //static_assert(maximum_segment_size == 574); // mesured in wireshark
#endif
// ledbat++ says 60ms, we might need other values if relayed // ledbat++ says 60ms, we might need other values if relayed
//const float target_delay {0.060f}; //const float target_delay {0.060f};
@ -50,26 +54,26 @@ struct LEDBAT {
// return the current believed window in bytes of how much data can be inflight, // return the current believed window in bytes of how much data can be inflight,
// without overstepping the delay requirement // without overstepping the delay requirement
float getCWnD(void) const { float getCWnD(void) const override {
return _cwnd; return _cwnd;
} }
// TODO: api for how much data we should send // TODO: api for how much data we should send
// take time since last sent into account // take time since last sent into account
// respect max_byterate_allowed // respect max_byterate_allowed
size_t canSend(void) const; size_t canSend(void) const override;
// get the list of timed out seq_ids // get the list of timed out seq_ids
std::vector<SeqIDType> getTimeouts(void) const; std::vector<SeqIDType> getTimeouts(void) const override;
public: // callbacks public: // callbacks
// data size is without overhead // data size is without overhead
void onSent(SeqIDType seq, size_t data_size); void onSent(SeqIDType seq, size_t data_size) override;
void onAck(std::vector<SeqIDType> seqs); void onAck(std::vector<SeqIDType> seqs) override;
// if discard, not resent, not inflight // if discard, not resent, not inflight
void onLoss(SeqIDType seq, bool discard); void onLoss(SeqIDType seq, bool discard) override;
private: private:
using clock = std::chrono::steady_clock; using clock = std::chrono::steady_clock;

View File

@ -139,7 +139,7 @@ class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProvider
struct Group { struct Group {
struct Peer { struct Peer {
std::unique_ptr<LEDBAT> cca = std::make_unique<LEDBAT>(500-4); // TODO: replace with tox_group_max_custom_lossy_packet_length()-4 std::unique_ptr<CCAI> cca = std::make_unique<LEDBAT>(500-4); // TODO: replace with tox_group_max_custom_lossy_packet_length()-4
struct RecvTransfer { struct RecvTransfer {
uint32_t file_kind; uint32_t file_kind;