|
|
|
|
@ -1052,14 +1052,16 @@ static void cs_handle_channel_info_resp(struct chat_sync* cs, uint64_t peer,
|
|
|
|
|
if (vdb && inv_userinfo[0]) { |
|
|
|
|
sqlite3_stmt* ns = NULL; |
|
|
|
|
sqlite3_prepare_v2(vdb, |
|
|
|
|
"INSERT INTO nodes(node_id,name,x25519_pubkey,ed25519_pubkey) VALUES(?,?,?,?)" |
|
|
|
|
"INSERT INTO nodes(node_id,name,x25519_pubkey,ed25519_pubkey,created_at) VALUES(?,?,?,?,?)" |
|
|
|
|
" ON CONFLICT(node_id) DO UPDATE SET" |
|
|
|
|
" name=excluded.name, x25519_pubkey=excluded.x25519_pubkey, ed25519_pubkey=excluded.ed25519_pubkey", |
|
|
|
|
" name=excluded.name, x25519_pubkey=excluded.x25519_pubkey, ed25519_pubkey=excluded.ed25519_pubkey," |
|
|
|
|
" created_at=COALESCE(nodes.created_at, excluded.created_at)", |
|
|
|
|
-1, &ns, NULL); |
|
|
|
|
if (ns) { sqlite3_bind_int64(ns, 1, (sqlite3_int64)peer); |
|
|
|
|
sqlite3_bind_text(ns, 2, inv_userinfo, -1, SQLITE_STATIC); |
|
|
|
|
sqlite3_bind_blob(ns, 3, inv_x25519, 32, SQLITE_STATIC); |
|
|
|
|
sqlite3_bind_blob(ns, 4, inv_ed, 32, SQLITE_STATIC); |
|
|
|
|
sqlite3_bind_int64(ns, 5, (sqlite3_int64)ntp_time_get_seconds(cs->inst)); |
|
|
|
|
sqlite3_step(ns); sqlite3_finalize(ns); } |
|
|
|
|
} |
|
|
|
|
/* save inviter's address from ETCP connection */ |
|
|
|
|
@ -1094,7 +1096,7 @@ static void cs_handle_channel_info_resp(struct chat_sync* cs, uint64_t peer,
|
|
|
|
|
int rc = topo_node_sqlite_member_put(vdb, ch_id, peer, inviter_join_sig, inviter_join_ts, inviter_update_sig, inviter_update_ts, inv_x25519, inv_ed, inv_userinfo, inviter_join_sig); |
|
|
|
|
if (rc != 0) DEBUG_ERROR(DEBUG_CATEGORY_DB_SYNC, "%s: member_put(inviter) FAILED ch=%s peer=%016llx rc=%d", CS_ID, ch_id, (unsigned long long)peer, rc); |
|
|
|
|
char inv_name[128]; json_flat_get(inv_userinfo, "name", inv_name, sizeof(inv_name)); |
|
|
|
|
topo_node_sqlite_node_update_verified(vdb, peer, inv_name, inv_x25519, inv_ed, inviter_join_ts); |
|
|
|
|
topo_node_sqlite_node_update_verified(vdb, peer, inv_name, inv_x25519, inv_ed, inviter_join_ts, ntp_time_get_seconds(cs->inst)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* generate our own join_sig */ |
|
|
|
|
@ -1206,20 +1208,22 @@ static void cs_handle_channel_join(struct chat_sync* cs, uint64_t peer,
|
|
|
|
|
int rc = topo_node_sqlite_member_put(db, ch_id, node_id, join_sig, join_ts, NULL, 0, x25519, ed_pub, joiner_userinfo, NULL); |
|
|
|
|
if (rc != 0) DEBUG_ERROR(DEBUG_CATEGORY_DB_SYNC, "%s: member_put(joiner) FAILED ch=%s node=0x%016llx rc=%d", CS_ID, ch_id, (unsigned long long)node_id, rc); |
|
|
|
|
{ char j_name[128]; json_flat_get(joiner_userinfo, "name", j_name, sizeof(j_name)); |
|
|
|
|
topo_node_sqlite_node_update_verified(db, node_id, j_name, x25519, ed_pub, join_ts); } |
|
|
|
|
topo_node_sqlite_node_update_verified(db, node_id, j_name, x25519, ed_pub, join_ts, ntp_time_get_seconds(cs->inst)); } |
|
|
|
|
chat_conn_mgr_add_node(chat_conn_mgr_get(), node_id); |
|
|
|
|
/* save joiner node_info to local DB */ |
|
|
|
|
if (db && joiner_userinfo[0]) { |
|
|
|
|
sqlite3_stmt* ns = NULL; |
|
|
|
|
sqlite3_prepare_v2(db, |
|
|
|
|
"INSERT INTO nodes(node_id,name,x25519_pubkey,ed25519_pubkey) VALUES(?,?,?,?)" |
|
|
|
|
"INSERT INTO nodes(node_id,name,x25519_pubkey,ed25519_pubkey,created_at) VALUES(?,?,?,?,?)" |
|
|
|
|
" ON CONFLICT(node_id) DO UPDATE SET" |
|
|
|
|
" name=excluded.name, x25519_pubkey=excluded.x25519_pubkey, ed25519_pubkey=excluded.ed25519_pubkey", |
|
|
|
|
" name=excluded.name, x25519_pubkey=excluded.x25519_pubkey, ed25519_pubkey=excluded.ed25519_pubkey," |
|
|
|
|
" created_at=COALESCE(nodes.created_at, excluded.created_at)", |
|
|
|
|
-1, &ns, NULL); |
|
|
|
|
if (ns) { sqlite3_bind_int64(ns, 1, (sqlite3_int64)node_id); |
|
|
|
|
sqlite3_bind_text(ns, 2, joiner_userinfo, -1, SQLITE_STATIC); |
|
|
|
|
sqlite3_bind_blob(ns, 3, x25519, 32, SQLITE_STATIC); |
|
|
|
|
sqlite3_bind_blob(ns, 4, ed_pub, 32, SQLITE_STATIC); |
|
|
|
|
sqlite3_bind_int64(ns, 5, (sqlite3_int64)ntp_time_get_seconds(cs->inst)); |
|
|
|
|
sqlite3_step(ns); sqlite3_finalize(ns); } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1378,7 +1382,7 @@ static void cs_handle_welcome(struct chat_sync* cs, uint64_t peer,
|
|
|
|
|
int rc = topo_node_sqlite_member_put(db, ch_id, node_id, join_sig, join_ts, NULL, 0, x25519, ed_pub, peer_userinfo, NULL); |
|
|
|
|
if (rc != 0) DEBUG_ERROR(DEBUG_CATEGORY_DB_SYNC, "%s: member_put(welcome) FAILED ch=%s node=0x%016llx rc=%d", CS_ID, ch_id, (unsigned long long)node_id, rc); |
|
|
|
|
{ char pn[256]; json_flat_get(peer_userinfo, "name", pn, sizeof(pn)); |
|
|
|
|
topo_node_sqlite_node_update_verified(db, node_id, pn, x25519, ed_pub, join_ts); } |
|
|
|
|
topo_node_sqlite_node_update_verified(db, node_id, pn, x25519, ed_pub, join_ts, ntp_time_get_seconds(cs->inst)); } |
|
|
|
|
|
|
|
|
|
chat_conn_mgr_add_node(chat_conn_mgr_get(), node_id); |
|
|
|
|
|
|
|
|
|
@ -1482,19 +1486,21 @@ static void cs_handle_peer_upsert(struct chat_sync* cs, uint64_t peer,
|
|
|
|
|
int rc = topo_node_sqlite_member_put(db, ch_id, node_id, join_sig, join_ts, NULL, 0, x25519, ed_pub, peer_userinfo, NULL); |
|
|
|
|
if (rc != 0) DEBUG_ERROR(DEBUG_CATEGORY_DB_SYNC, "%s: member_put(peer_upsert) FAILED ch=%s node=0x%016llx rc=%d", CS_ID, ch_id, (unsigned long long)node_id, rc); |
|
|
|
|
{ char pn2[128]; json_flat_get(peer_userinfo, "name", pn2, sizeof(pn2)); |
|
|
|
|
topo_node_sqlite_node_update_verified(db, node_id, pn2, x25519, ed_pub, join_ts); } |
|
|
|
|
topo_node_sqlite_node_update_verified(db, node_id, pn2, x25519, ed_pub, join_ts, ntp_time_get_seconds(cs->inst)); } |
|
|
|
|
chat_conn_mgr_add_node(chat_conn_mgr_get(), node_id); |
|
|
|
|
if (db && peer_userinfo[0]) { |
|
|
|
|
sqlite3_stmt* ns = NULL; |
|
|
|
|
sqlite3_prepare_v2(db, |
|
|
|
|
"INSERT INTO nodes(node_id,name,x25519_pubkey,ed25519_pubkey) VALUES(?,?,?,?)" |
|
|
|
|
"INSERT INTO nodes(node_id,name,x25519_pubkey,ed25519_pubkey,created_at) VALUES(?,?,?,?,?)" |
|
|
|
|
" ON CONFLICT(node_id) DO UPDATE SET" |
|
|
|
|
" name=excluded.name, x25519_pubkey=excluded.x25519_pubkey, ed25519_pubkey=excluded.ed25519_pubkey", |
|
|
|
|
" name=excluded.name, x25519_pubkey=excluded.x25519_pubkey, ed25519_pubkey=excluded.ed25519_pubkey," |
|
|
|
|
" created_at=COALESCE(nodes.created_at, excluded.created_at)", |
|
|
|
|
-1, &ns, NULL); |
|
|
|
|
if (ns) { sqlite3_bind_int64(ns, 1, (sqlite3_int64)node_id); |
|
|
|
|
sqlite3_bind_text(ns, 2, peer_userinfo, -1, SQLITE_STATIC); |
|
|
|
|
sqlite3_bind_blob(ns, 3, x25519, 32, SQLITE_STATIC); |
|
|
|
|
sqlite3_bind_blob(ns, 4, ed_pub, 32, SQLITE_STATIC); |
|
|
|
|
sqlite3_bind_int64(ns, 5, (sqlite3_int64)ntp_time_get_seconds(cs->inst)); |
|
|
|
|
sqlite3_step(ns); sqlite3_finalize(ns); } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|