mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 00:02:34 +01:00
modules/client/room_keys: Unify version and keys into single module.
This commit is contained in:
parent
502a03a8cf
commit
4d5d99ab2c
6 changed files with 114 additions and 56 deletions
|
@ -132,8 +132,7 @@ ircd::m::module_names
|
|||
"client_keys_query",
|
||||
"client_keys_signatures_upload",
|
||||
"client_keys_device_signing_upload",
|
||||
"client_room_keys_version",
|
||||
"client_room_keys_keys",
|
||||
"client_room_keys",
|
||||
"client_presence",
|
||||
"client_groups",
|
||||
"client_joined_groups",
|
||||
|
|
|
@ -506,12 +506,14 @@ client_module_LTLIBRARIES += \
|
|||
# client/room_keys/
|
||||
#
|
||||
|
||||
client_client_room_keys_version_la_SOURCES = client/room_keys/version.cc
|
||||
client_client_room_keys_keys_la_SOURCES = client/room_keys/keys.cc
|
||||
client_client_room_keys_la_SOURCES = \
|
||||
client/room_keys/keys.cc \
|
||||
client/room_keys/version.cc \
|
||||
client/room_keys/room_keys.cc \
|
||||
###
|
||||
|
||||
client_module_LTLIBRARIES += \
|
||||
client/client_room_keys_version.la \
|
||||
client/client_room_keys_keys.la \
|
||||
client/client_room_keys.la \
|
||||
###
|
||||
|
||||
#
|
||||
|
|
|
@ -8,11 +8,10 @@
|
|||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#include "room_keys.h"
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
static string_view make_state_key(const mutable_buffer &, const string_view &, const string_view &, const event::idx &);
|
||||
static std::tuple<string_view, string_view, string_view> unmake_state_key(const string_view &);
|
||||
|
||||
static resource::response _get_room_keys_keys(client &, const resource::request &, const room::state &, const event::idx &, const string_view &, const string_view &);
|
||||
static void _get_room_keys_keys(client &, const resource::request &, const room::state &, const event::idx &, const string_view &, json::stack::object &);
|
||||
static resource::response get_room_keys_keys(client &, const resource::request &);
|
||||
|
@ -30,12 +29,6 @@ namespace ircd::m
|
|||
extern resource room_keys_keys;
|
||||
}
|
||||
|
||||
ircd::mapi::header
|
||||
IRCD_MODULE
|
||||
{
|
||||
"Client (undocumented) :e2e Room Keys Keys"
|
||||
};
|
||||
|
||||
decltype(ircd::m::room_keys_keys)
|
||||
ircd::m::room_keys_keys
|
||||
{
|
||||
|
@ -501,45 +494,36 @@ ircd::m::_get_room_keys_keys(client &client,
|
|||
return {}; // responded from closure or thrown
|
||||
}
|
||||
|
||||
std::tuple<ircd::string_view, ircd::string_view, ircd::string_view>
|
||||
ircd::m::unmake_state_key(const string_view &state_key)
|
||||
std::tuple<int64_t, int64_t>
|
||||
ircd::m::count_etag(const room::state &state,
|
||||
const event::idx &version)
|
||||
{
|
||||
assert(state_key);
|
||||
string_view part[3];
|
||||
const auto parts
|
||||
char version_buf[64];
|
||||
const auto version_str
|
||||
{
|
||||
tokens(state_key, ":::", part)
|
||||
lex_cast(version)
|
||||
};
|
||||
|
||||
assert(parts == 3);
|
||||
if(unlikely(!m::valid(id::ROOM, part[0])))
|
||||
part[0] = {};
|
||||
|
||||
if(unlikely(!lex_castable<ulong>(part[2])))
|
||||
part[2] = {};
|
||||
|
||||
return std::make_tuple
|
||||
(
|
||||
part[0], part[1], part[2]
|
||||
);
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::make_state_key(const mutable_buffer &buf,
|
||||
const string_view &room_id,
|
||||
const string_view &session_id,
|
||||
const event::idx &version)
|
||||
{
|
||||
assert(room_id);
|
||||
assert(m::valid(id::ROOM, room_id));
|
||||
assert(session_id);
|
||||
assert(session_id != "sessions");
|
||||
assert(version != 0);
|
||||
return fmt::sprintf
|
||||
uint64_t count(0), etag(0);
|
||||
state.for_each("ircd.room_keys.key", [&]
|
||||
(const string_view &type, const string_view &state_key, const event::idx &event_idx)
|
||||
{
|
||||
buf, "%s:::%s:::%u",
|
||||
room_id,
|
||||
session_id,
|
||||
version,
|
||||
const auto &[room_id, session_id, _version_str]
|
||||
{
|
||||
unmake_state_key(state_key)
|
||||
};
|
||||
|
||||
if(_version_str != version_str)
|
||||
return true;
|
||||
|
||||
etag += event_idx;
|
||||
count += 1;
|
||||
return true;
|
||||
});
|
||||
|
||||
return
|
||||
{
|
||||
int64_t(count),
|
||||
int64_t(etag),
|
||||
};
|
||||
}
|
||||
|
|
60
modules/client/room_keys/room_keys.cc
Normal file
60
modules/client/room_keys/room_keys.cc
Normal file
|
@ -0,0 +1,60 @@
|
|||
// The Construct
|
||||
//
|
||||
// Copyright (C) The Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2023 Jason Volk <jason@zemos.net>
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#include "room_keys.h"
|
||||
|
||||
ircd::mapi::header
|
||||
IRCD_MODULE
|
||||
{
|
||||
"Client :e2e Room Keys"
|
||||
};
|
||||
|
||||
std::tuple<ircd::string_view, ircd::string_view, ircd::string_view>
|
||||
ircd::m::unmake_state_key(const string_view &state_key)
|
||||
{
|
||||
assert(state_key);
|
||||
string_view part[3];
|
||||
const auto parts
|
||||
{
|
||||
tokens(state_key, ":::", part)
|
||||
};
|
||||
|
||||
assert(parts == 3);
|
||||
if(unlikely(!m::valid(id::ROOM, part[0])))
|
||||
part[0] = {};
|
||||
|
||||
if(unlikely(!lex_castable<ulong>(part[2])))
|
||||
part[2] = {};
|
||||
|
||||
return std::make_tuple
|
||||
(
|
||||
part[0], part[1], part[2]
|
||||
);
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::make_state_key(const mutable_buffer &buf,
|
||||
const string_view &room_id,
|
||||
const string_view &session_id,
|
||||
const event::idx &version)
|
||||
{
|
||||
assert(room_id);
|
||||
assert(m::valid(id::ROOM, room_id));
|
||||
assert(session_id);
|
||||
assert(session_id != "sessions");
|
||||
assert(version != 0);
|
||||
return fmt::sprintf
|
||||
{
|
||||
buf, "%s:::%s:::%u",
|
||||
room_id,
|
||||
session_id,
|
||||
version,
|
||||
};
|
||||
}
|
17
modules/client/room_keys/room_keys.h
Normal file
17
modules/client/room_keys/room_keys.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
// The Construct
|
||||
//
|
||||
// Copyright (C) The Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2023 Jason Volk <jason@zemos.net>
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#pragma GCC visibility push(hidden)
|
||||
namespace ircd::m
|
||||
{
|
||||
string_view make_state_key(const mutable_buffer &, const string_view &, const string_view &, const event::idx &);
|
||||
std::tuple<string_view, string_view, string_view> unmake_state_key(const string_view &);
|
||||
}
|
||||
#pragma GCC visibility pop
|
|
@ -8,6 +8,8 @@
|
|||
// copyright notice and this permission notice is present in all copies. The
|
||||
// full license for this software is available in the LICENSE file.
|
||||
|
||||
#include "room_keys.h"
|
||||
|
||||
namespace ircd::m
|
||||
{
|
||||
static resource::response get_room_keys_version(client &, const resource::request &);
|
||||
|
@ -25,12 +27,6 @@ namespace ircd::m
|
|||
extern resource room_keys_version;
|
||||
}
|
||||
|
||||
ircd::mapi::header
|
||||
IRCD_MODULE
|
||||
{
|
||||
"Client (undocumented) :e2e Room Keys Version"
|
||||
};
|
||||
|
||||
decltype(ircd::m::room_keys_version)
|
||||
ircd::m::room_keys_version
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue