diff options
author | Dr David Alan Gilbert <dave@treblig.org> | 2017-07-30 12:21:32 +0100 |
---|---|---|
committer | Dr. David Alan Gilbert <dave@treblig.org> | 2018-02-25 02:08:49 +0000 |
commit | e23ec6e50b6ff755668e8bbca362e42958c9eaef (patch) | |
tree | b3a3da62336e256332689aca794d0a89165fdcfa /matrix-e2e.c | |
parent | 77a487c7eedfef3104835d09044e71939b5dcbfa (diff) | |
download | purple-matrix-e23ec6e50b6ff755668e8bbca362e42958c9eaef.tar.gz |
e2e: parse sync_key_counts to decide on key sending
The server returns the count of one-time-keys that it has,
we parse that and detect if we need to send more.
It's a little tricky in that a server that doesn't have
any keys will send an empty response, so force sending in
that case.
If we get to the point of multiple types of keys this will
need reworking to make sure we only send the key types needed.
Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
Diffstat (limited to 'matrix-e2e.c')
-rw-r--r-- | matrix-e2e.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/matrix-e2e.c b/matrix-e2e.c index c4c2cfa..f12c19f 100644 --- a/matrix-e2e.c +++ b/matrix-e2e.c @@ -298,6 +298,44 @@ static int get_id_keys(PurpleConnection *pc, OlmAccount *account, gchar ***algor return n_keys; } +/* Called from sync with an object of the form: + * "device_one_time_keys_count" : { + * "signed_curve25519" : 100 + * }, + */ +void matrix_e2e_handle_sync_key_counts(PurpleConnection *pc, JsonObject *count_object, + gboolean force_send) +{ + gboolean need_to_send = force_send; + gboolean valid_counts = FALSE; + MatrixConnectionData *conn = purple_connection_get_protocol_data(pc); + size_t max_keys = olm_account_max_number_of_one_time_keys(conn->e2e->oa); + size_t to_create = max_keys; + + if (!force_send) { + JsonObjectIter iter; + const gchar *key_algo; + JsonNode *key_count_node; + json_object_iter_init(&iter, count_object); + while (json_object_iter_next(&iter, &key_algo, &key_count_node)) { + valid_counts = TRUE; + gint64 count = matrix_json_node_get_int(key_count_node); + if (count < max_keys / 2) { + to_create = (max_keys / 2) - count; + need_to_send = TRUE; + } + purple_debug_info("matrixprpl", "%s: %s: %ld\n", + __func__, key_algo, count); + } + } + + need_to_send |= !valid_counts; + if (need_to_send) { + purple_debug_info("matrixprpl", "%s: need to send\n",__func__); + // TODO send_one_time_keys(conn, to_create); + } +} + static void key_upload_callback(MatrixConnectionData *conn, gpointer user_data, struct _JsonNode *json_root, @@ -457,4 +495,9 @@ void matrix_e2e_cleanup_connection(MatrixConnectionData *conn) { } +void matrix_e2e_handle_sync_key_counts(PurpleConnection *pc, JsonObject *count_object, + gboolean force_send) +{ +} + #endif |