fix: UDP packet size and addr_type classification
- etcp_connections.h: add WIRE_OVERHEAD, IP_UDP_OVERHEAD_V4/V6, SC_ENCRYPT_OVERHEAD (properly accounts for v6 IP(40)+UDP(8)+SC(3)+CCM tag(16) = 67 vs old UDP_HDR_SIZE=28) - etcp_connections.c etcp_encrypt_send: use WIRE_OVERHEAD instead of UDP_HDR_SIZE - etcp_connections.c send_init_response: clamp padding to max_data = mtu - WIRE_OVERHEAD - chat_core_priv.h: add addr_type_from_ip() classifier - chat_profile.c, chat_sync.c, member_sync.c: use classified addr_type instead of hardcoded 0 - chat_sync.c: skip zero nat_addr in JOIN, fall back to interface_addr - topo_node_sqlite.c, member_sync.c: remove addr_type=0 filter from SELECT/DELETE - chat_profile.c, member_sync.c: DELETE all addresses (not just addr_type=0)
This commit is contained in:
1 parent
5066cff333
commit
25ebad9f52
8 files changed
+128
-55
No files matched your search
+23
-12
@@ -1,5 +1,6 @@
|
||||
#include "chat_sync.h"
|
||||
#include "chat_core.h"
|
||||
#include "chat_core_priv.h"
|
||||
#include "chat_setting.h"
|
||||
#include "chat_event.h"
|
||||
#include "../routing_layer/topo_node_sqlite.h"
|
||||
@@ -1063,13 +1064,14 @@ static void cs_handle_channel_info_resp(struct chat_sync* cs, uint64_t peer,
|
||||
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,protocol,address,port,addr_type,socket_id) VALUES(?,4,1,?,?,0,?)");
|
||||
"INSERT OR REPLACE INTO node_addresses(node_id,family,protocol,address,port,addr_type,socket_id) VALUES(?,4,1,?,?,?,?)");
|
||||
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_bind_int(as, 4, (int)lk->conn->sock_id);
|
||||
sqlite3_bind_int(as, 4, addr_type_from_ip(4, ip));
|
||||
sqlite3_bind_int(as, 5, (int)lk->conn->sock_id);
|
||||
sqlite3_step(as); sqlite3_finalize(as);
|
||||
lk_written++;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_MEMBER_SYNC, "%s: [ADDR_SYNC] INFO_RESP INSERT peer=%016llx sock=%d %d.%d.%d.%d:%d",
|
||||
@@ -1122,10 +1124,16 @@ static void cs_handle_channel_info_resp(struct chat_sync* cs, uint64_t peer,
|
||||
jbuf[joff++] = 0;
|
||||
struct ETCP_SOCKET* sock = cs->inst->etcp_sockets;
|
||||
while (sock && addr_cnt < 255) {
|
||||
struct sockaddr_storage* sa;
|
||||
if (sock->nat_addr.ss_family) sa = &sock->nat_addr;
|
||||
else if (sock->interface_addr.ss_family) sa = &sock->interface_addr;
|
||||
else { sock = sock->next; continue; }
|
||||
struct sockaddr_storage* sa = NULL;
|
||||
if (sock->nat_addr.ss_family) {
|
||||
sa = &sock->nat_addr;
|
||||
int is_zero = 0;
|
||||
if (sa->ss_family == AF_INET) { if (((struct sockaddr_in*)sa)->sin_addr.s_addr == 0) is_zero = 1; }
|
||||
else { static const uint8_t z[16]; if (!memcmp(&((struct sockaddr_in6*)sa)->sin6_addr, z, 16)) is_zero = 1; }
|
||||
if (is_zero) sa = NULL;
|
||||
}
|
||||
if (!sa && sock->interface_addr.ss_family) sa = &sock->interface_addr;
|
||||
if (!sa) { sock = sock->next; continue; }
|
||||
if (sa->ss_family == AF_INET) {
|
||||
struct sockaddr_in* sin = (struct sockaddr_in*)sa;
|
||||
if (joff + 9 > sizeof(jbuf)) break;
|
||||
@@ -1214,7 +1222,7 @@ static void cs_handle_channel_join(struct chat_sync* cs, uint64_t peer,
|
||||
|
||||
char sql[256]; snprintf(sql, sizeof(sql),
|
||||
"INSERT OR REPLACE INTO node_addresses(node_id,family,protocol,address,port,addr_type,socket_id)"
|
||||
" VALUES(?,?,?,?,?,0,?)");
|
||||
" VALUES(?,?,?,?,?,?,?)");
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_int64(stmt, 1, (sqlite3_int64)node_id);
|
||||
@@ -1222,7 +1230,8 @@ static void cs_handle_channel_join(struct chat_sync* cs, uint64_t peer,
|
||||
sqlite3_bind_int(stmt, 3, (int)proto);
|
||||
sqlite3_bind_blob(stmt, 4, ip, ip_len, SQLITE_STATIC);
|
||||
sqlite3_bind_int(stmt, 5, (int)port);
|
||||
sqlite3_bind_int(stmt, 6, (int)sid);
|
||||
sqlite3_bind_int(stmt, 6, addr_type_from_ip(fm, ip));
|
||||
sqlite3_bind_int(stmt, 7, (int)sid);
|
||||
sqlite3_step(stmt); sqlite3_finalize(stmt);
|
||||
}
|
||||
if (fm == 4)
|
||||
@@ -1389,7 +1398,7 @@ static void cs_handle_welcome(struct chat_sync* cs, uint64_t peer,
|
||||
|
||||
char sql[256]; snprintf(sql, sizeof(sql),
|
||||
"INSERT OR REPLACE INTO node_addresses(node_id,family,protocol,address,port,addr_type,socket_id)"
|
||||
" VALUES(?,?,?,?,?,0,?)");
|
||||
" VALUES(?,?,?,?,?,?,?)");
|
||||
sqlite3_stmt* stmt2 = NULL;
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &stmt2, NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_int64(stmt2, 1, (sqlite3_int64)node_id);
|
||||
@@ -1397,7 +1406,8 @@ static void cs_handle_welcome(struct chat_sync* cs, uint64_t peer,
|
||||
sqlite3_bind_int(stmt2, 3, (int)proto);
|
||||
sqlite3_bind_blob(stmt2, 4, ip, ip_len, SQLITE_STATIC);
|
||||
sqlite3_bind_int(stmt2, 5, (int)port);
|
||||
sqlite3_bind_int(stmt2, 6, (int)sid);
|
||||
sqlite3_bind_int(stmt2, 6, addr_type_from_ip(fm, ip));
|
||||
sqlite3_bind_int(stmt2, 7, (int)sid);
|
||||
sqlite3_step(stmt2); sqlite3_finalize(stmt2);
|
||||
}
|
||||
if (fm == 4)
|
||||
@@ -1503,7 +1513,7 @@ static void cs_handle_peer_upsert(struct chat_sync* cs, uint64_t peer,
|
||||
|
||||
char sql[256]; snprintf(sql, sizeof(sql),
|
||||
"INSERT OR REPLACE INTO node_addresses(node_id,family,protocol,address,port,addr_type,socket_id)"
|
||||
" VALUES(?,?,?,?,?,0,?)");
|
||||
" VALUES(?,?,?,?,?,?,?)");
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_int64(stmt, 1, (sqlite3_int64)node_id);
|
||||
@@ -1511,7 +1521,8 @@ static void cs_handle_peer_upsert(struct chat_sync* cs, uint64_t peer,
|
||||
sqlite3_bind_int(stmt, 3, (int)proto);
|
||||
sqlite3_bind_blob(stmt, 4, ip, ip_len, SQLITE_STATIC);
|
||||
sqlite3_bind_int(stmt, 5, (int)port);
|
||||
sqlite3_bind_int(stmt, 6, (int)sid);
|
||||
sqlite3_bind_int(stmt, 6, addr_type_from_ip(fm, ip));
|
||||
sqlite3_bind_int(stmt, 7, (int)sid);
|
||||
sqlite3_step(stmt); sqlite3_finalize(stmt);
|
||||
}
|
||||
if (fm == 4)
|
||||
|
||||
Reference in new issue
Block a user