parameterize

This commit is contained in:
Green Sky 2023-01-17 00:16:18 +01:00
parent 5bb4349e27
commit ae9e2729d2
No known key found for this signature in database
2 changed files with 19 additions and 12 deletions

View File

@ -208,8 +208,7 @@ void NGC_FT1_kill(NGC_FT1* ngc_ft1_ctx) {
delete ngc_ft1_ctx; delete ngc_ft1_ctx;
} }
void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx) { void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta) {
//void NGC_FT1_iterate(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx/*, void *user_data*/) {
assert(ngc_ft1_ctx); assert(ngc_ft1_ctx);
for (auto& [group_number, group] : ngc_ft1_ctx->groups) { for (auto& [group_number, group] : ngc_ft1_ctx->groups) {
@ -220,12 +219,12 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx) {
if (tf_opt) { if (tf_opt) {
auto& tf = tf_opt.value(); auto& tf = tf_opt.value();
tf.time_since_activity += 0.025f; // TODO: actual delta tf.time_since_activity += time_delta;
switch (tf.state) { switch (tf.state) {
using State = NGC_FT1::Group::Peer::SendTransfer::State; using State = NGC_FT1::Group::Peer::SendTransfer::State;
case State::INIT_SENT: case State::INIT_SENT:
if (tf.time_since_activity >= 10.f) { if (tf.time_since_activity >= ngc_ft1_ctx->options.init_retry_timeout_after) {
if (tf.inits_sent >= 3) { if (tf.inits_sent >= 3) {
// delete, timed out 3 times // delete, timed out 3 times
fprintf(stderr, "FT: warning, ft init timed out, deleting\n"); fprintf(stderr, "FT: warning, ft init timed out, deleting\n");
@ -241,15 +240,15 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx) {
} }
break; break;
case State::SENDING: { case State::SENDING: {
tf.ssb.for_each(0.025f, [&](uint16_t id, const std::vector<uint8_t>& data, float& time_since_activity) { tf.ssb.for_each(time_delta, [&](uint16_t id, const std::vector<uint8_t>& data, float& time_since_activity) {
// no ack after 5 sec -> resend // no ack after 5 sec -> resend
if (time_since_activity >= 5.f) { if (time_since_activity >= ngc_ft1_ctx->options.sending_resend_without_ack_after) {
_send_pkg_FT1_DATA(tox, group_number, peer_number, idx, id, data.data(), data.size()); _send_pkg_FT1_DATA(tox, group_number, peer_number, idx, id, data.data(), data.size());
time_since_activity = 0.f; time_since_activity = 0.f;
} }
}); });
if (tf.time_since_activity >= 30.f) { if (tf.time_since_activity >= ngc_ft1_ctx->options.sending_give_up_after) {
// no ack after 30sec, close ft // no ack after 30sec, close ft
// TODO: notify app // TODO: notify app
fprintf(stderr, "FT: warning, sending ft in progress timed out, deleting\n"); fprintf(stderr, "FT: warning, sending ft in progress timed out, deleting\n");
@ -260,10 +259,10 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx) {
assert(ngc_ft1_ctx->cb_send_data.count(tf.file_kind)); assert(ngc_ft1_ctx->cb_send_data.count(tf.file_kind));
// if chunks in flight < window size (2) // if chunks in flight < window size (2)
static const size_t window_size {2}; // TODO: expose while (tf.ssb.size() < ngc_ft1_ctx->options.packet_window_size) {
while (tf.ssb.size() < window_size) {
std::vector<uint8_t> new_data; std::vector<uint8_t> new_data;
// TODO: parameterize packet size? -> only if JF increases lossy packet size >:)
size_t chunk_size = std::min<size_t>(450u, tf.file_size - tf.file_size_current); size_t chunk_size = std::min<size_t>(450u, tf.file_size - tf.file_size_current);
if (chunk_size == 0) { if (chunk_size == 0) {
// TODO: set to finishing? // TODO: set to finishing?

View File

@ -17,8 +17,15 @@ extern "C" {
typedef struct NGC_FT1 NGC_FT1; typedef struct NGC_FT1 NGC_FT1;
struct NGC_FT1_options { struct NGC_FT1_options {
// TODO: expose some parameters // TODO
int tmp; size_t acks_per_packet; // 5
float init_retry_timeout_after; // 10sec
float sending_resend_without_ack_after; // 5sec
float sending_give_up_after; // 30sec
size_t packet_window_size; // 2
}; };
// uint16_t ? // uint16_t ?
@ -76,7 +83,8 @@ bool NGC_FT1_register_ext(NGC_FT1* ngc_ft1_ctx, NGC_EXT_CTX* ngc_ext_ctx);
void NGC_FT1_kill(NGC_FT1* ngc_ft1_ctx); void NGC_FT1_kill(NGC_FT1* ngc_ft1_ctx);
// ========== iterate ========== // ========== iterate ==========
void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx); // time_delta in seconds
void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta);
// TODO: announce // TODO: announce
// ========== request ========== // ========== request ==========