ft raw packet send functions
This commit is contained in:
parent
213457fccf
commit
4afd13f70e
@ -66,7 +66,7 @@ enum _PacketType : uint8_t {
|
|||||||
// acknowlage data fragments
|
// acknowlage data fragments
|
||||||
// TODO: last 3 should be sufficient, 5 should be generous, would eleminate the byte for size
|
// TODO: last 3 should be sufficient, 5 should be generous, would eleminate the byte for size
|
||||||
// - 1 byte (temporary_file_tf_id)
|
// - 1 byte (temporary_file_tf_id)
|
||||||
// - 1 byte (number of sequence ids to ack, this kind of depends on window size)
|
// // this is implicit (pkg size)- 1 byte (number of sequence ids to ack, this kind of depends on window size)
|
||||||
// - array [ (of sequece ids)
|
// - array [ (of sequece ids)
|
||||||
// - 2 bytes (sequece id)
|
// - 2 bytes (sequece id)
|
||||||
// - ]
|
// - ]
|
||||||
|
62
ngc_ft1.cpp
62
ngc_ft1.cpp
@ -69,9 +69,8 @@ struct NGC_FT1 {
|
|||||||
static bool _send_pkg_FT1_REQUEST(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t file_kind, const uint8_t* file_id, size_t file_id_size);
|
static bool _send_pkg_FT1_REQUEST(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t file_kind, const uint8_t* file_id, size_t file_id_size);
|
||||||
static bool _send_pkg_FT1_INIT(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t file_kind, uint64_t file_size, uint8_t transfer_id, const uint8_t* file_id, size_t file_id_size);
|
static bool _send_pkg_FT1_INIT(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t file_kind, uint64_t file_size, uint8_t transfer_id, const uint8_t* file_id, size_t file_id_size);
|
||||||
static bool _send_pkg_FT1_INIT_ACK(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id);
|
static bool _send_pkg_FT1_INIT_ACK(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id);
|
||||||
|
static bool _send_pkg_FT1_DATA(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, uint16_t sequence_id, const uint8_t* data, size_t data_size);
|
||||||
static bool _send_pkg_FT1_DATA(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id);
|
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);
|
|
||||||
static bool _send_pkg_FT1_DATA_FIN(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id);
|
static bool _send_pkg_FT1_DATA_FIN(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id);
|
||||||
static bool _send_pkg_FT1_DATA_FIN_ACK(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id);
|
static bool _send_pkg_FT1_DATA_FIN_ACK(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id);
|
||||||
|
|
||||||
@ -239,7 +238,7 @@ static bool _send_pkg_FT1_INIT(const Tox* tox, uint32_t group_number, uint32_t p
|
|||||||
pkg.push_back(FT1_INIT);
|
pkg.push_back(FT1_INIT);
|
||||||
pkg.push_back(file_kind);
|
pkg.push_back(file_kind);
|
||||||
for (size_t i = 0; i < sizeof(file_size); i++) {
|
for (size_t i = 0; i < sizeof(file_size); i++) {
|
||||||
pkg.push_back((file_size>>i) & 0xff);
|
pkg.push_back((file_size>>(i*8)) & 0xff);
|
||||||
}
|
}
|
||||||
pkg.push_back(transfer_id);
|
pkg.push_back(transfer_id);
|
||||||
for (size_t i = 0; i < file_id_size; i++) {
|
for (size_t i = 0; i < file_id_size; i++) {
|
||||||
@ -262,6 +261,59 @@ static bool _send_pkg_FT1_INIT_ACK(const Tox* tox, uint32_t group_number, uint32
|
|||||||
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, true, pkg.data(), pkg.size(), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool _send_pkg_FT1_DATA(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, uint16_t sequence_id, const uint8_t* data, size_t data_size) {
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// check header_size+data_size <= max pkg size
|
||||||
|
|
||||||
|
std::vector<uint8_t> pkg;
|
||||||
|
pkg.push_back(FT1_DATA);
|
||||||
|
pkg.push_back(transfer_id);
|
||||||
|
pkg.push_back(sequence_id & 0xff);
|
||||||
|
pkg.push_back((sequence_id >> (1*8)) & 0xff);
|
||||||
|
|
||||||
|
// TODO: optimize
|
||||||
|
for (size_t i = 0; i < data_size; i++) {
|
||||||
|
pkg.push_back(data[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
std::vector<uint8_t> pkg;
|
||||||
|
pkg.push_back(FT1_DATA_ACK);
|
||||||
|
pkg.push_back(transfer_id);
|
||||||
|
|
||||||
|
// TODO: optimize
|
||||||
|
for (size_t i = 0; i < seq_ids_size; i++) {
|
||||||
|
pkg.push_back(seq_ids[i] & 0xff);
|
||||||
|
pkg.push_back((seq_ids[i] >> (1*8)) & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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_FIN(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id) {
|
||||||
|
std::vector<uint8_t> pkg;
|
||||||
|
pkg.push_back(FT1_DATA_FIN);
|
||||||
|
pkg.push_back(transfer_id);
|
||||||
|
|
||||||
|
// 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_FIN_ACK(const Tox* tox, uint32_t group_number, uint32_t peer_number, uint8_t transfer_id) {
|
||||||
|
std::vector<uint8_t> pkg;
|
||||||
|
pkg.push_back(FT1_DATA_FIN_ACK);
|
||||||
|
pkg.push_back(transfer_id);
|
||||||
|
|
||||||
|
// 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; }
|
#define _DATA_HAVE(x, error) if ((length - curser) < (x)) { error; }
|
||||||
|
|
||||||
static void _handle_FT1_REQUEST(
|
static void _handle_FT1_REQUEST(
|
||||||
@ -324,7 +376,7 @@ static void _handle_FT1_INIT(
|
|||||||
size_t file_size {0u};
|
size_t file_size {0u};
|
||||||
_DATA_HAVE(sizeof(file_size), fprintf(stderr, "packet too small, missing file_size\n"); return)
|
_DATA_HAVE(sizeof(file_size), fprintf(stderr, "packet too small, missing file_size\n"); return)
|
||||||
for (size_t i = 0; i < sizeof(file_size); i++, curser++) {
|
for (size_t i = 0; i < sizeof(file_size); i++, curser++) {
|
||||||
file_size |= size_t(data[curser]) << i;
|
file_size |= size_t(data[curser]) << (i*8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - 1 byte (temporary_file_tf_id, for this peer only, technically just a prefix to distinguish between simultainious fts)
|
// - 1 byte (temporary_file_tf_id, for this peer only, technically just a prefix to distinguish between simultainious fts)
|
||||||
|
Reference in New Issue
Block a user