Expose DM mode and resolved conversation ID to headless clients
This commit is contained in:
1 parent
8f4fec4247
commit
452f5b4169
3 files changed
+14
-4
No files matched your search
@@ -838,6 +838,12 @@ static void hc_handle_dm_start(struct headless_client* cli, int id, const char*
|
||||
if (json_get_str(cli, "ch", ch, sizeof(ch)) < 0) ch[0] = '\0';
|
||||
uint64_t target = strtoull(node_id_str, NULL, 16);
|
||||
if (!target || !hc->inst) { send_response(cli, id, NULL, "invalid node_id"); return; }
|
||||
char mode_name[16] = "device";
|
||||
if (json_get_str(cli, "mode", mode_name, sizeof(mode_name)) < 0) strcpy(mode_name, "device");
|
||||
if (strcmp(mode_name, "device") && strcmp(mode_name, "groups")) {
|
||||
send_response(cli, id, NULL, "mode must be 'device' or 'groups'"); return;
|
||||
}
|
||||
enum dm_mode mode = !strcmp(mode_name, "groups") ? DM_MODE_GROUPS : DM_MODE_DEVICE;
|
||||
|
||||
sqlite3* db = chat_core_get_db(hc->inst);
|
||||
uint8_t x25519[32], ed25519[32]; char name[MS_USERINFO_MAX + 1];
|
||||
@@ -863,9 +869,12 @@ static void hc_handle_dm_start(struct headless_client* cli, int id, const char*
|
||||
int final = sqlite3_finalize(st);
|
||||
if (final != SQLITE_OK) { DEBUG_ERROR(DEBUG_CATEGORY_HEADLESS, "headless: DM identity finalize rc=%d", final); ok = 0; }
|
||||
if (!ok) { send_response(cli, id, NULL, "failed to start DM (node not found?)"); return; }
|
||||
if (dm_start(hc->inst, target, x25519, ed25519, name, ch[0] ? ch : NULL)) { send_response(cli, id, NULL, "DM start failed"); return; }
|
||||
uint64_t conv_num = 0;
|
||||
if (dm_start(hc->inst, target, x25519, ed25519, name, ch[0] ? ch : NULL, mode, &conv_num)) {
|
||||
send_response(cli, id, NULL, "DM start failed"); return;
|
||||
}
|
||||
|
||||
char conv[64]; uint64_t conv_num = dm_derive_conv_id(hc->inst->node_id, target);
|
||||
char conv[64];
|
||||
snprintf(conv, sizeof(conv), "%llu", (unsigned long long)conv_num);
|
||||
char resp[256]; snprintf(resp, sizeof(resp), "{\"conv_id\":\"%s\",\"started\":true}", conv);
|
||||
send_response(cli, id, resp, NULL);
|
||||
|
||||
@@ -64,7 +64,7 @@ static int peer(struct UTUN_INSTANCE* a, struct UTUN_INSTANCE* b, char conv[64])
|
||||
sqlite3_bind_int64(st, 1, (sqlite3_int64)b->node_id); sqlite3_bind_blob(st, 2, b->my_keys.public_key, 32, SQLITE_STATIC);
|
||||
sqlite3_bind_blob(st, 3, b->my_ed25519_pubkey, 32, SQLITE_STATIC);
|
||||
int rc = sqlite3_step(st); sqlite3_finalize(st);
|
||||
if (rc != SQLITE_DONE || dm_start(a, b->node_id, b->my_keys.public_key, b->my_ed25519_pubkey, "peer", NULL)) return -1;
|
||||
if (rc != SQLITE_DONE || dm_start(a, b->node_id, b->my_keys.public_key, b->my_ed25519_pubkey, "peer", NULL, DM_MODE_DEVICE, NULL)) return -1;
|
||||
snprintf(conv, 64, "%llu", (unsigned long long)dm_derive_conv_id(a->node_id, b->node_id)); return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -200,7 +200,8 @@ int main(void) {
|
||||
snprintf(deleted_conv, sizeof(deleted_conv), "%llu", (unsigned long long)dm_derive_conv_id(nodes[0]->node_id, nodes[1]->node_id));
|
||||
CHECK(!dm_history_delete(nodes[0], deleted_conv, dm_history_generation(nodes[0], deleted_conv)), "delete with pending invitation");
|
||||
CHECK(wait_result(ua, 7, DM_INVITE_CANCELLED) && !message_count(), "delete cancels invitation without publishing PM");
|
||||
CHECK(!dm_start(nodes[0], nodes[1]->node_id, nodes[1]->my_keys.public_key, nodes[1]->my_ed25519_pubkey, "B", source_id),
|
||||
CHECK(!dm_start(nodes[0], nodes[1]->node_id, nodes[1]->my_keys.public_key, nodes[1]->my_ed25519_pubkey,
|
||||
"B", source_id, DM_MODE_DEVICE, NULL),
|
||||
"explicit start reopens PM after deletion");
|
||||
request(3, 0, source_id, 0);
|
||||
CHECK(wait_result(ua, 3, DM_INVITE_BUILD_ERROR) && !message_count(), "invalid group sends nothing");
|
||||
|
||||
Reference in new issue
Block a user