Browse Source

Диагностика синхронизации: merkle_sync DEBUG_DEBUG логи обмена; убран спам auto_connect no IPv4; сохранение адреса инвайтера из ETCP; детали DECRYPT FAIL (link_state/enc_errs)

topo_upd
Evgeny 3 months ago
parent
commit
0479c309bb
  1. 5
      src/etcp_connections.c
  2. 3
      tools/chatgui/transport/chat_core.c
  3. 21
      tools/chatgui/transport/chat_sync.c
  4. 9
      tools/chatgui/transport/merkle_sync.c

5
src/etcp_connections.c

@ -1551,7 +1551,10 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) {
if (!dec_rc) {
goto process_decrypted;
}
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "etcp: DECRYPT FAIL rc=%d link=%p log=%s session_ready=%d my_pub=%016llx peer_pub=%016llx", dec_rc, link, link->etcp->log_name, link->etcp->crypto_ctx.session_ready, *(uint64_t*)link->etcp->crypto_ctx.pk->public_key, *(uint64_t*)link->etcp->crypto_ctx.peer_public_key);
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "etcp: DECRYPT FAIL rc=%d link=%p log=%s sess=%d link_state=%d keepalive=%d enc_errs=%zu my_pub=%016llx peer_pub=%016llx",
dec_rc, link, link->etcp->log_name, link->etcp->crypto_ctx.session_ready,
link->link_state, link->recv_keepalive, link->encrypt_errors,
*(uint64_t*)link->etcp->crypto_ctx.pk->public_key, *(uint64_t*)link->etcp->crypto_ctx.peer_public_key);
} else {
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "SKIP normal decrypt: link=%p session_ready=%d — trying init decrypt",
link, link && link->etcp ? link->etcp->crypto_ctx.session_ready : -1);

3
tools/chatgui/transport/chat_core.c

@ -918,8 +918,7 @@ void chat_core_connect_auto(uint64_t node_id,
}
addr_count = uniq; }
if (addr_count == 0) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: auto_connect no IPv4 addrs for node 0x%016llx",
CC_ID, (unsigned long long)node_id);
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: auto_connect no IPv4 addrs yet for node 0x%016llx (BGP not synced?)", CC_ID, (unsigned long long)node_id);
cb(CONN_MGR_ERR_NO_ADDRESSES, node_id, arg);
return;
}

21
tools/chatgui/transport/chat_sync.c

@ -890,6 +890,27 @@ static void cs_handle_channel_info_resp(struct chat_sync* cs, uint64_t peer,
sqlite3_bind_blob(ns, 4, inv_ed, 32, SQLITE_STATIC);
sqlite3_step(ns); sqlite3_finalize(ns); }
}
/* save inviter's address from ETCP connection */
{ struct ETCP_LINK* lk = inv_conn->links;
while (lk) {
if (lk->initialized && lk->remote_addr.ss_family == AF_INET) {
struct sockaddr_in* sin = (struct sockaddr_in*)&lk->remote_addr;
uint8_t ip[4]; memcpy(ip, &sin->sin_addr, 4); uint16_t port = ntohs(sin->sin_port);
char sql[256]; snprintf(sql, sizeof(sql),
"INSERT OR REPLACE INTO node_addresses(node_id,family,address,port,is_nat) VALUES(?,4,?,?,0)");
sqlite3_stmt* as = NULL;
if (sqlite3_prepare_v2(vdb, sql, -1, &as, NULL) == SQLITE_OK) {
sqlite3_bind_int64(as, 1, (sqlite3_int64)peer);
sqlite3_bind_blob(as, 2, ip, 4, SQLITE_STATIC);
sqlite3_bind_int(as, 3, port);
sqlite3_step(as); sqlite3_finalize(as);
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: saved inviter addr peer=%016llx %d.%d.%d.%d:%d", CS_ID,
(unsigned long long)peer, ip[0], ip[1], ip[2], ip[3], port);
}
}
lk = lk->next;
}
}
}
/* save inviter as node and member */

9
tools/chatgui/transport/merkle_sync.c

@ -225,6 +225,7 @@ static int _send_hashes(struct merkle_sync* ms, uint64_t peer, const char* ns,
} else {
uint32_t bitmap; uint8_t hashes[MT_BUCKETS][MT_HASH_SIZE];
_get_level_hashes(ms, ns, level, prefix, prefix_bytes, &bitmap, hashes);
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: send_hashes peer=%016llx ns=%s level=%d prefix=%016llx bitmap=%08x", MS_ID, (unsigned long long)peer, ns, level, (unsigned long long)prefix, bitmap);
memcpy(p, &bitmap, 4); p += 4;
for (int i = 0; i < MT_BUCKETS; i++)
if (bitmap & (1u << i)) { memcpy(p, hashes[i], MT_HASH_SIZE); p += MT_HASH_SIZE; }
@ -362,7 +363,6 @@ static void _handle_hashes(struct merkle_sync* ms, uint64_t peer, const char* ns
for (int i = 0; i < MT_BUCKETS; i++) {
if (!(local_bm & (1u << i)) && !(remote_bm & (1u << i))) continue;
if ((local_bm & (1u << i)) && (remote_bm & (1u << i))) {
/* find offset of remote hash for slot i in the received blob */
int rh_idx = 0;
for (int j = 0; j < i; j++) if (remote_bm & (1u << j)) rh_idx++;
if (memcmp(rh + (size_t)rh_idx * MT_HASH_SIZE, lh[i], MT_HASH_SIZE) == 0)
@ -370,6 +370,9 @@ static void _handle_hashes(struct merkle_sync* ms, uint64_t peer, const char* ns
}
}
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: handle_hashes peer=%016llx ns=%s level=%d remote_bm=%08x local_bm=%08x differs=%08x is_data=%d",
MS_ID, (unsigned long long)peer, ns, level, remote_bm, local_bm, differs, is_data);
if (differs == 0) { _session_done(s, MT_OK); return; }
int next_shift = 63 - ((int)level + 1) * 5;
@ -420,6 +423,8 @@ static void _handle_request(struct merkle_sync* ms, uint64_t peer, const char* n
if (plen < 1) return;
uint8_t count = pl[0]; const uint8_t* bp = pl + 1; size_t off = 0;
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: handle_request peer=%016llx ns=%s count=%d", MS_ID, (unsigned long long)peer, ns, count);
struct bucket_entry buckets[32]; int bc = 0;
for (uint8_t i = 0; i < count && bc < 32; i++) {
if (off + 2 > plen - 1) break;
@ -444,6 +449,8 @@ static void _handle_batch(struct merkle_sync* ms, uint64_t peer, const char* ns,
if (plen < 1) return;
uint8_t count = pl[0]; const uint8_t* bp = pl + 1; size_t rem = plen - 1;
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "%s: handle_batch peer=%016llx ns=%s count=%d len=%zu", MS_ID, (unsigned long long)peer, ns, count, plen - 1);
for (uint8_t i = 0; i < count && rem >= 3; i++) {
uint8_t lvl = bp[0]; uint8_t pb_i = bp[1]; rem -= 2; bp += 2;
if (rem < pb_i + 1) break;

Loading…
Cancel
Save