Compare commits

..

No commits in common. "bbc96bd776a29a6581545d60b5cb6e60e7453f1f" and "ae9e2729d20ff5134e718a3603459b218aebf077" have entirely different histories.

@ -71,7 +71,7 @@ struct RecvSequenceBuffer {
void add(uint16_t seq_id, std::vector<uint8_t>&& data) {
entries[seq_id] = {data};
ack_seq_ids.push_back(seq_id);
if (ack_seq_ids.size() > 3) { // TODO: magic
if (ack_seq_ids.size() > 5) { // TODO: magic
ack_seq_ids.pop_front();
}
}
@ -142,8 +142,11 @@ struct NGC_FT1 {
SENDING, // we got the ack and are now sending data
// is this real?
FINISHING, // we sent all data but acks still outstanding????
FINFIN, // we sent the data_fin and are waiting for the data_fin_ack
// delete
} state;
@ -260,9 +263,9 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta) {
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>(496u, 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) {
tf.state = State::FINISHING;
// TODO: set to finishing?
break; // we done
}
@ -287,21 +290,11 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta) {
}
}
break;
case State::FINISHING: // we still have unacked packets
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
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());
time_since_activity = 0.f;
}
});
if (tf.time_since_activity >= ngc_ft1_ctx->options.sending_give_up_after) {
// no ack after 30sec, close ft
// TODO: notify app
fprintf(stderr, "FT: warning, sending ft finishing timed out, deleting\n");
tf_opt.reset();
}
case State::FINISHING:
break;
// finfin o.o
default: // invalid state, delete
fprintf(stderr, "FT: error, ft in invalid state, deleting\n");
tf_opt.reset();
@ -506,8 +499,8 @@ static bool _send_pkg_FT1_DATA(const Tox* tox, uint32_t group_number, uint32_t p
pkg.push_back(data[i]);
}
// lossy
return tox_group_send_custom_private_packet(tox, group_number, peer_number, false, pkg.data(), pkg.size(), nullptr);
// lossless?
return tox_group_send_custom_private_packet(tox, group_number, peer_number, true, pkg.data(), pkg.size(), nullptr);
}
static bool _send_pkg_FT1_DATA_ACK(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, const uint16_t* seq_ids, size_t seq_ids_size) {
@ -521,8 +514,8 @@ static bool _send_pkg_FT1_DATA_ACK(const Tox* tox, uint32_t group_number, uint32
pkg.push_back((seq_ids[i] >> (1*8)) & 0xff);
}
// lossy
return tox_group_send_custom_private_packet(tox, group_number, peer_number, false, pkg.data(), pkg.size(), nullptr);
// lossless?
return tox_group_send_custom_private_packet(tox, group_number, peer_number, true, pkg.data(), pkg.size(), nullptr);
}
#define _DATA_HAVE(x, error) if ((length - curser) < (x)) { error; }
@ -811,8 +804,8 @@ static void _handle_FT1_DATA_ACK(
NGC_FT1::Group::Peer::SendTransfer& transfer = peer.send_transfers[transfer_id].value();
using State = NGC_FT1::Group::Peer::SendTransfer::State;
if (transfer.state != State::SENDING && transfer.state != State::FINISHING) {
fprintf(stderr, "FT: data_ack but not in SENDING or FINISHING state (%d)\n", int(transfer.state));
if (transfer.state != State::SENDING) {
fprintf(stderr, "FT: data_ack but not in SENDING state\n");
return;
}
@ -832,8 +825,7 @@ static void _handle_FT1_DATA_ACK(
transfer.ssb.erase(seq_id);
}
// delete if all packets acked
if (transfer.file_size == transfer.file_size_current && transfer.ssb.size() == 0) {
if (transfer.file_size == transfer.file_size_current) {
fprintf(stderr, "FT: %d done\n", transfer_id);
peer.send_transfers[transfer_id] = std::nullopt;
}