add logging cats

This commit is contained in:
Green Sky 2023-01-04 20:25:41 +01:00
parent d4f3d3c4fb
commit 6852cdd046
No known key found for this signature in database
3 changed files with 40 additions and 40 deletions

View File

@ -83,7 +83,7 @@ void NGC_EXT_handle_group_custom_packet(
_PacketType pkg_type = static_cast<_PacketType>(*(data + curser)); _PacketType pkg_type = static_cast<_PacketType>(*(data + curser));
curser++; curser++;
fprintf(stderr, "custom_packet [%s] %lu\n", _pkgid2str(pkg_type), length); fprintf(stderr, "EX: custom_packet [%s] %lu\n", _pkgid2str(pkg_type), length);
if (pkg_type == INVALID) { if (pkg_type == INVALID) {
fprintf(stderr, "(invalid)\n"); fprintf(stderr, "(invalid)\n");
@ -92,7 +92,7 @@ void NGC_EXT_handle_group_custom_packet(
auto handle_fn = ngc_ext_ctx->callbacks[pkg_type]; auto handle_fn = ngc_ext_ctx->callbacks[pkg_type];
if (handle_fn == nullptr) { if (handle_fn == nullptr) {
fprintf(stderr, "!!! no handler for packet\n"); fprintf(stderr, "EX: !!! no handler for packet\n");
return; return;
} }

View File

@ -126,12 +126,12 @@ void NGC_FT1_iterate(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx/*, void *user_data*/) {
if (tf.time_since_activity >= 20.f) { if (tf.time_since_activity >= 20.f) {
if (tf.inits_sent >= 3) { if (tf.inits_sent >= 3) {
// delete, timed out 3 times // delete, timed out 3 times
fprintf(stderr, "warning, ft init timed out, deleting\n"); fprintf(stderr, "FT: warning, ft init timed out, deleting\n");
tf_opt.reset(); tf_opt.reset();
continue; continue;
} else { } else {
// timed out, resend // timed out, resend
fprintf(stderr, "warning, ft init timed out, resending\n"); fprintf(stderr, "FT: warning, ft init timed out, resending\n");
_send_pkg_FT1_INIT(tox, group_number, peer_number, tf.file_kind, tf.file_size, idx, tf.file_id.data(), tf.file_id.size()); _send_pkg_FT1_INIT(tox, group_number, peer_number, tf.file_kind, tf.file_size, idx, tf.file_id.data(), tf.file_id.size());
tf.inits_sent++; tf.inits_sent++;
tf.time_since_activity = 0.f; tf.time_since_activity = 0.f;
@ -146,7 +146,7 @@ void NGC_FT1_iterate(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx/*, void *user_data*/) {
// finfin o.o // finfin o.o
default: // invalid state, delete default: // invalid state, delete
fprintf(stderr, "error, ft in invalid state, deleting\n"); fprintf(stderr, "FT: error, ft in invalid state, deleting\n");
tf_opt.reset(); tf_opt.reset();
continue; continue;
} }
@ -255,10 +255,10 @@ bool NGC_FT1_send_init_private(
size_t file_size size_t file_size
) { ) {
//fprintf(stderr, "TODO: init ft for %08X\n", msg_id); //fprintf(stderr, "TODO: init ft for %08X\n", msg_id);
fprintf(stderr, "init ft\n"); fprintf(stderr, "FT: init ft\n");
if (tox_group_peer_get_connection_status(tox, group_number, peer_number, nullptr) == TOX_CONNECTION_NONE) { if (tox_group_peer_get_connection_status(tox, group_number, peer_number, nullptr) == TOX_CONNECTION_NONE) {
fprintf(stderr, "error: cant init ft, peer offline\n"); fprintf(stderr, "FT: error: cant init ft, peer offline\n");
return false; return false;
} }
@ -282,7 +282,7 @@ bool NGC_FT1_send_init_private(
} while (i != idx); } while (i != idx);
if (!found) { if (!found) {
fprintf(stderr, "error: cant init ft, no free transfer slot\n"); fprintf(stderr, "FT: error: cant init ft, no free transfer slot\n");
return false; return false;
} }
} }
@ -420,11 +420,11 @@ static void _handle_FT1_REQUEST(
// TODO: might be uint16_t or even larger // TODO: might be uint16_t or even larger
uint8_t file_kind_u8; uint8_t file_kind_u8;
_DATA_HAVE(sizeof(file_kind_u8), fprintf(stderr, "packet too small, missing file_kind\n"); return) _DATA_HAVE(sizeof(file_kind_u8), fprintf(stderr, "FT: packet too small, missing file_kind\n"); return)
file_kind_u8 = data[curser++]; file_kind_u8 = data[curser++];
auto file_kind = static_cast<NGC_FT1_file_kind>(file_kind_u8); auto file_kind = static_cast<NGC_FT1_file_kind>(file_kind_u8);
fprintf(stderr, "got FT request with file_kind %u [", file_kind_u8); fprintf(stderr, "FT: got FT request with file_kind %u [", file_kind_u8);
for (size_t curser_copy = curser; curser_copy < length; curser_copy++) { for (size_t curser_copy = curser; curser_copy < length; curser_copy++) {
fprintf(stderr, "%02X", data[curser_copy]); fprintf(stderr, "%02X", data[curser_copy]);
} }
@ -437,7 +437,7 @@ static void _handle_FT1_REQUEST(
if (fn_ptr) { if (fn_ptr) {
fn_ptr(tox, ngc_ext_ctx, group_number, peer_number, data+curser, length-curser); fn_ptr(tox, ngc_ext_ctx, group_number, peer_number, data+curser, length-curser);
} else { } else {
fprintf(stderr, "missing cb for requests\n"); fprintf(stderr, "FT: missing cb for requests\n");
} }
} }
@ -458,25 +458,25 @@ static void _handle_FT1_INIT(
// TODO: might be uint16_t or even larger // TODO: might be uint16_t or even larger
uint8_t file_kind_u8; uint8_t file_kind_u8;
_DATA_HAVE(sizeof(file_kind_u8), fprintf(stderr, "packet too small, missing file_kind\n"); return) _DATA_HAVE(sizeof(file_kind_u8), fprintf(stderr, "FT: packet too small, missing file_kind\n"); return)
file_kind_u8 = data[curser++]; file_kind_u8 = data[curser++];
auto file_kind = static_cast<NGC_FT1_file_kind>(file_kind_u8); auto file_kind = static_cast<NGC_FT1_file_kind>(file_kind_u8);
// - 8 bytes (data size) // - 8 bytes (data size)
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, "FT: 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*8); 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)
uint8_t transfer_id; uint8_t transfer_id;
_DATA_HAVE(sizeof(transfer_id), fprintf(stderr, "packet too small, missing transfer_id\n"); return) _DATA_HAVE(sizeof(transfer_id), fprintf(stderr, "FT: packet too small, missing transfer_id\n"); return)
transfer_id = data[curser++]; transfer_id = data[curser++];
// - X bytes (file_kind dependent id, differnt sizes) // - X bytes (file_kind dependent id, differnt sizes)
fprintf(stderr, "got FT init with file_kind:%u file_size:%lu tf_id:%u [", file_kind_u8, file_size, transfer_id); fprintf(stderr, "FT: got FT init with file_kind:%u file_size:%lu tf_id:%u [", file_kind_u8, file_size, transfer_id);
for (size_t curser_copy = curser; curser_copy < length; curser_copy++) { for (size_t curser_copy = curser; curser_copy < length; curser_copy++) {
fprintf(stderr, "%02X", data[curser_copy]); fprintf(stderr, "%02X", data[curser_copy]);
} }
@ -494,16 +494,16 @@ static void _handle_FT1_INIT(
// last part of message (file_id) is not yet parsed, just give it to cb // last part of message (file_id) is not yet parsed, just give it to cb
accept_ft = fn_ptr(tox, ngc_ext_ctx, group_number, peer_number, data+curser, length-curser, transfer_id, file_size); accept_ft = fn_ptr(tox, ngc_ext_ctx, group_number, peer_number, data+curser, length-curser, transfer_id, file_size);
} else { } else {
fprintf(stderr, "missing cb for init\n"); fprintf(stderr, "FT: missing cb for init\n");
accept_ft = false; accept_ft = false;
} }
if (accept_ft) { if (accept_ft) {
_send_pkg_FT1_INIT_ACK(tox, group_number, peer_number, transfer_id); _send_pkg_FT1_INIT_ACK(tox, group_number, peer_number, transfer_id);
fprintf(stderr, "accepted init\n"); fprintf(stderr, "FT: accepted init\n");
} else { } else {
// TODO deny? // TODO deny?
fprintf(stderr, "rejected init\n"); fprintf(stderr, "FT: rejected init\n");
} }
} }

View File

@ -26,7 +26,7 @@ void NGC_HS1::Peer::append(uint32_t msg_id, Tox_Message_Type type, const std::st
heard_of.erase(msg_id); heard_of.erase(msg_id);
} }
fprintf(stderr, "######## last msgs ########\n"); fprintf(stderr, "HS: ######## last msgs ########\n");
auto rit = order.crbegin(); auto rit = order.crbegin();
for (size_t i = 0; i < 10 && rit != order.crend(); i++, rit++) { for (size_t i = 0; i < 10 && rit != order.crend(); i++, rit++) {
fprintf(stderr, " %08X - %s\n", *rit, dict.at(*rit).text.c_str()); fprintf(stderr, " %08X - %s\n", *rit, dict.at(*rit).text.c_str());
@ -126,7 +126,7 @@ static void _iterate_group(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_nu
} }
if (ngc_hs1_ctx->history.count(g_id) == 0) { if (ngc_hs1_ctx->history.count(g_id) == 0) {
fprintf(stderr, "adding new group: %u %X%X%X%X\n", fprintf(stderr, "HS: adding new group: %u %X%X%X%X\n",
group_number, group_number,
g_id.data.data()[0], g_id.data.data()[0],
g_id.data.data()[1], g_id.data.data()[1],
@ -144,7 +144,7 @@ static void _iterate_group(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_nu
if (peer.time_since_last_request_sent > ngc_hs1_ctx->options.query_interval_per_peer) { if (peer.time_since_last_request_sent > ngc_hs1_ctx->options.query_interval_per_peer) {
peer.time_since_last_request_sent = 0.f; peer.time_since_last_request_sent = 0.f;
fprintf(stderr, "requesting ids for %X%X%X%X\n", peer_key.data.data()[0], peer_key.data.data()[1], peer_key.data.data()[2], peer_key.data.data()[3]); fprintf(stderr, "HS: requesting ids for %X%X%X%X\n", peer_key.data.data()[0], peer_key.data.data()[1], peer_key.data.data()[2], peer_key.data.data()[3]);
// TODO: other way around? // TODO: other way around?
// ask everyone if they have newer stuff for this peer // ask everyone if they have newer stuff for this peer
@ -165,7 +165,7 @@ static void _iterate_group(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_nu
it->second.time_since_ft_activity += time_delta; it->second.time_since_ft_activity += time_delta;
if (it->second.time_since_ft_activity >= ngc_hs1_ctx->options.ft_activity_timeout) { if (it->second.time_since_ft_activity >= ngc_hs1_ctx->options.ft_activity_timeout) {
// timed out // timed out
fprintf(stderr, "!!! pending ft request timed out (%08X)\n", it->first); fprintf(stderr, "HS: !!! pending ft request timed out (%08X)\n", it->first);
it = peer.pending.erase(it); it = peer.pending.erase(it);
} else { } else {
it++; it++;
@ -185,7 +185,7 @@ static void _iterate_group(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx, uint32_t group_nu
} }
if (remote_peer_numbers.empty()) { if (remote_peer_numbers.empty()) {
fprintf(stderr, "!!! msg_id we heard of, but no remote peer !!!\n"); fprintf(stderr, "HS: !!! msg_id we heard of, but no remote peer !!!\n");
continue; continue;
} }
@ -241,7 +241,7 @@ void NGC_HS1_iterate(Tox *tox, NGC_EXT_CTX* ngc_ext_ctx/*, void *user_data*/) {
// safety // safety
if (g_i > group_count + 1000) { if (g_i > group_count + 1000) {
fprintf(stderr, "WAY PAST GOUPS in iterate\n"); fprintf(stderr, "HS: WAY PAST GOUPS in iterate\n");
break; break;
} }
} }
@ -312,7 +312,7 @@ void NGC_HS1_record_own_message(
Tox_Message_Type type, const uint8_t *message, size_t length, uint32_t message_id Tox_Message_Type type, const uint8_t *message, size_t length, uint32_t message_id
) { ) {
NGC_HS1* ngc_hs1_ctx = ngc_ext_ctx->ngc_hs1_ctx; NGC_HS1* ngc_hs1_ctx = ngc_ext_ctx->ngc_hs1_ctx;
fprintf(stderr, "record_own_message %08X\n", message_id); fprintf(stderr, "HS: record_own_message %08X\n", message_id);
// get group id // get group id
_GroupKey g_id{}; _GroupKey g_id{};
{ // TODO: error { // TODO: error
@ -345,7 +345,7 @@ void NGC_HS1_record_message(
return; return;
} }
fprintf(stderr, "record_message %08X\n", message_id); fprintf(stderr, "HS: record_message %08X\n", message_id);
// get group id // get group id
_GroupKey g_id{}; _GroupKey g_id{};
{ // TODO: error { // TODO: error
@ -379,7 +379,7 @@ void _handle_HS1_ft_recv_request(
uint8_t* tmp_ptr = reinterpret_cast<uint8_t*>(&msg_id); uint8_t* tmp_ptr = reinterpret_cast<uint8_t*>(&msg_id);
std::copy(file_id+TOX_GROUP_PEER_PUBLIC_KEY_SIZE, file_id+TOX_GROUP_PEER_PUBLIC_KEY_SIZE+sizeof(uint32_t), tmp_ptr); std::copy(file_id+TOX_GROUP_PEER_PUBLIC_KEY_SIZE, file_id+TOX_GROUP_PEER_PUBLIC_KEY_SIZE+sizeof(uint32_t), tmp_ptr);
fprintf(stderr, "got a ft request for xxx msg_id %08X\n", msg_id); fprintf(stderr, "HS: got a ft request for xxx msg_id %08X\n", msg_id);
// get group id // get group id
_GroupKey group_id{}; _GroupKey group_id{};
@ -392,13 +392,13 @@ void _handle_HS1_ft_recv_request(
// do we have that message // do we have that message
if (!peers.count(peer_key)) { if (!peers.count(peer_key)) {
fprintf(stderr, "got ft request for unknown peer\n"); fprintf(stderr, "HS: got ft request for unknown peer\n");
return; return;
} }
const auto& peer = peers.at(peer_key); const auto& peer = peers.at(peer_key);
if (!peer.dict.count(msg_id)) { if (!peer.dict.count(msg_id)) {
fprintf(stderr, "got ft request for unknown message_id %08X\n", msg_id); fprintf(stderr, "HS: got ft request for unknown message_id %08X\n", msg_id);
return; return;
} }
@ -430,7 +430,7 @@ bool _handle_HS1_ft_recv_init(
const uint8_t transfer_id, const uint8_t transfer_id,
const size_t file_size const size_t file_size
) { ) {
fprintf(stderr, "-------hs handle ft init\n"); fprintf(stderr, "HS: -------hs handle ft init\n");
// peer id and msg id from file id // peer id and msg id from file id
// TODO: replace, remote crash // TODO: replace, remote crash
@ -461,13 +461,13 @@ bool _handle_HS1_ft_recv_init(
if (!pending.count(msg_id)) { if (!pending.count(msg_id)) {
// we did not ask for this // we did not ask for this
// TODO: accept? // TODO: accept?
fprintf(stderr, "ft init from peer we did not ask\n"); fprintf(stderr, "HS: ft init from peer we did not ask\n");
return false; // deny return false; // deny
} }
if (pending.at(msg_id).peer_number != peer_number) { if (pending.at(msg_id).peer_number != peer_number) {
// wrong peer ? // wrong peer ?
fprintf(stderr, "ft init from peer we did not ask while asking someone else\n"); fprintf(stderr, "HS: ft init from peer we did not ask while asking someone else\n");
return false; // deny return false; // deny
} }
@ -501,12 +501,12 @@ void _handle_HS1_ft_recv_data(
// get based on transfer_id // get based on transfer_id
if (!group.transfers.count(std::make_pair(peer_number, transfer_id))) { if (!group.transfers.count(std::make_pair(peer_number, transfer_id))) {
if (data_offset != 0) { if (data_offset != 0) {
fprintf(stderr, "!! got stray tf data from %d tid:%d\n", peer_number, transfer_id); fprintf(stderr, "HS: !! got stray tf data from %d tid:%d\n", peer_number, transfer_id);
return; return;
} }
// new transfer? // new transfer?
fprintf(stderr, "!! got transfer from %d tid:%d\n", peer_number, transfer_id); fprintf(stderr, "HS: !! got transfer from %d tid:%d\n", peer_number, transfer_id);
} }
// add data to tmp buffer // add data to tmp buffer
@ -529,15 +529,15 @@ void _handle_HS1_REQUEST_LAST_IDS(
size_t curser = 0; size_t curser = 0;
_PeerKey p_key; _PeerKey p_key;
_HS1_HAVE(p_key.data.size(), fprintf(stderr, "packet too small, missing pkey\n"); return) _HS1_HAVE(p_key.data.size(), fprintf(stderr, "HS: packet too small, missing pkey\n"); return)
std::copy(data+curser, data+curser+p_key.data.size(), p_key.data.begin()); std::copy(data+curser, data+curser+p_key.data.size(), p_key.data.begin());
curser += p_key.data.size(); curser += p_key.data.size();
_HS1_HAVE(1, fprintf(stderr, "packet too small, missing count\n"); return) _HS1_HAVE(1, fprintf(stderr, "HS: packet too small, missing count\n"); return)
uint8_t last_msg_id_count = data[curser++]; uint8_t last_msg_id_count = data[curser++];
fprintf(stderr, "got request for last %u ids\n", last_msg_id_count); fprintf(stderr, "HS: got request for last %u ids\n", last_msg_id_count);
// get group id // get group id
_GroupKey g_id{}; _GroupKey g_id{};
@ -602,17 +602,17 @@ void _handle_HS1_RESPONSE_LAST_IDS(
size_t curser = 0; size_t curser = 0;
_PeerKey p_key; _PeerKey p_key;
_HS1_HAVE(p_key.data.size(), fprintf(stderr, "packet too small, missing pkey\n"); return) _HS1_HAVE(p_key.data.size(), fprintf(stderr, "HS: packet too small, missing pkey\n"); return)
std::copy(data+curser, data+curser+p_key.data.size(), p_key.data.begin()); std::copy(data+curser, data+curser+p_key.data.size(), p_key.data.begin());
curser += p_key.data.size(); curser += p_key.data.size();
// TODO: did we ask? // TODO: did we ask?
_HS1_HAVE(1, fprintf(stderr, "packet too small, missing count\n"); return) _HS1_HAVE(1, fprintf(stderr, "HS: packet too small, missing count\n"); return)
uint8_t last_msg_id_count = data[curser++]; uint8_t last_msg_id_count = data[curser++];
fprintf(stderr, "got response with last %u ids:\n", last_msg_id_count); fprintf(stderr, "HS: got response with last %u ids:\n", last_msg_id_count);
if (last_msg_id_count == 0) { if (last_msg_id_count == 0) {
return; return;