mirror of
https://github.com/Green-Sky/tox_ngc_ft1.git
synced 2024-12-23 02:53:24 +01:00
Compare commits
3 Commits
ae9e2729d2
...
bbc96bd776
Author | SHA1 | Date | |
---|---|---|---|
bbc96bd776 | |||
3675c2a1a8 | |||
aa9c7c44ba |
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() > 5) { // TODO: magic
|
if (ack_seq_ids.size() > 3) { // TODO: magic
|
||||||
ack_seq_ids.pop_front();
|
ack_seq_ids.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,11 +142,8 @@ 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;
|
||||||
|
|
||||||
@ -263,9 +260,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>(450u, tf.file_size - tf.file_size_current);
|
size_t chunk_size = std::min<size_t>(496u, tf.file_size - tf.file_size_current);
|
||||||
if (chunk_size == 0) {
|
if (chunk_size == 0) {
|
||||||
// TODO: set to finishing?
|
tf.state = State::FINISHING;
|
||||||
break; // we done
|
break; // we done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,11 +287,21 @@ void NGC_FT1_iterate(Tox *tox, NGC_FT1* ngc_ft1_ctx, float time_delta) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case State::FINISHING:
|
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();
|
||||||
|
}
|
||||||
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();
|
||||||
@ -499,8 +506,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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// lossless?
|
// lossy
|
||||||
return tox_group_send_custom_private_packet(tox, group_number, peer_number, true, pkg.data(), pkg.size(), nullptr);
|
return tox_group_send_custom_private_packet(tox, group_number, peer_number, false, 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) {
|
||||||
@ -514,8 +521,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// lossless?
|
// lossy
|
||||||
return tox_group_send_custom_private_packet(tox, group_number, peer_number, true, pkg.data(), pkg.size(), nullptr);
|
return tox_group_send_custom_private_packet(tox, group_number, peer_number, false, 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; }
|
||||||
@ -804,8 +811,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) {
|
if (transfer.state != State::SENDING && transfer.state != State::FINISHING) {
|
||||||
fprintf(stderr, "FT: data_ack but not in SENDING state\n");
|
fprintf(stderr, "FT: data_ack but not in SENDING or FINISHING state (%d)\n", int(transfer.state));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -825,7 +832,8 @@ static void _handle_FT1_DATA_ACK(
|
|||||||
transfer.ssb.erase(seq_id);
|
transfer.ssb.erase(seq_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transfer.file_size == transfer.file_size_current) {
|
// delete if all packets acked
|
||||||
|
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…
Reference in New Issue
Block a user