mirror of
https://github.com/Green-Sky/tox_ngc_ft1.git
synced 2025-01-12 16:47:20 +01:00
Compare commits
No commits in common. "bbc96bd776a29a6581545d60b5cb6e60e7453f1f" and "ae9e2729d20ff5134e718a3603459b218aebf077" have entirely different histories.
bbc96bd776
...
ae9e2729d2
42
ngc_ft1.cpp
42
ngc_ft1.cpp
@ -71,7 +71,7 @@ struct RecvSequenceBuffer {
|
|||||||
void add(uint16_t seq_id, std::vector<uint8_t>&& data) {
|
void add(uint16_t seq_id, std::vector<uint8_t>&& data) {
|
||||||
entries[seq_id] = {data};
|
entries[seq_id] = {data};
|
||||||
ack_seq_ids.push_back(seq_id);
|
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();
|
ack_seq_ids.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,8 +142,11 @@ struct NGC_FT1 {
|
|||||||
|
|
||||||
SENDING, // we got the ack and are now sending data
|
SENDING, // we got the ack and are now sending data
|
||||||
|
|
||||||
|
// is this real?
|
||||||
FINISHING, // we sent all data but acks still outstanding????
|
FINISHING, // we sent all data but acks still outstanding????
|
||||||
|
|
||||||
|
FINFIN, // we sent the data_fin and are waiting for the data_fin_ack
|
||||||
|
|
||||||
// delete
|
// delete
|
||||||
} state;
|
} 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;
|
std::vector<uint8_t> new_data;
|
||||||
|
|
||||||
// TODO: parameterize packet size? -> only if JF increases lossy packet size >:)
|
// 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) {
|
if (chunk_size == 0) {
|
||||||
tf.state = State::FINISHING;
|
// TODO: set to finishing?
|
||||||
break; // we done
|
break; // we done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,21 +290,11 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case State::FINISHING: // we still have unacked packets
|
case State::FINISHING:
|
||||||
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();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// finfin o.o
|
||||||
|
|
||||||
default: // invalid state, delete
|
default: // invalid state, delete
|
||||||
fprintf(stderr, "FT: error, ft in invalid state, deleting\n");
|
fprintf(stderr, "FT: error, ft in invalid state, deleting\n");
|
||||||
tf_opt.reset();
|
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]);
|
pkg.push_back(data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// lossy
|
// lossless?
|
||||||
return tox_group_send_custom_private_packet(tox, group_number, peer_number, false, pkg.data(), pkg.size(), nullptr);
|
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) {
|
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);
|
pkg.push_back((seq_ids[i] >> (1*8)) & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
// lossy
|
// lossless?
|
||||||
return tox_group_send_custom_private_packet(tox, group_number, peer_number, false, pkg.data(), pkg.size(), nullptr);
|
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; }
|
#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();
|
NGC_FT1::Group::Peer::SendTransfer& transfer = peer.send_transfers[transfer_id].value();
|
||||||
|
|
||||||
using State = NGC_FT1::Group::Peer::SendTransfer::State;
|
using State = NGC_FT1::Group::Peer::SendTransfer::State;
|
||||||
if (transfer.state != State::SENDING && transfer.state != State::FINISHING) {
|
if (transfer.state != State::SENDING) {
|
||||||
fprintf(stderr, "FT: data_ack but not in SENDING or FINISHING state (%d)\n", int(transfer.state));
|
fprintf(stderr, "FT: data_ack but not in SENDING state\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -832,8 +825,7 @@ static void _handle_FT1_DATA_ACK(
|
|||||||
transfer.ssb.erase(seq_id);
|
transfer.ssb.erase(seq_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete if all packets acked
|
if (transfer.file_size == transfer.file_size_current) {
|
||||||
if (transfer.file_size == transfer.file_size_current && transfer.ssb.size() == 0) {
|
|
||||||
fprintf(stderr, "FT: %d done\n", transfer_id);
|
fprintf(stderr, "FT: %d done\n", transfer_id);
|
||||||
peer.send_transfers[transfer_id] = std::nullopt;
|
peer.send_transfers[transfer_id] = std::nullopt;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user