Skip to content

Commit c462f85

Browse files
authored
Merge pull request #64 from Doy-lee/doyle-pro-backend-polish
Pro backend request/response glue code
2 parents 3f22c8a + a6bef56 commit c462f85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+22651
-8498
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@
2222
[submodule "external/oxen-logging"]
2323
path = external/oxen-logging
2424
url = https://github.com/oxen-io/oxen-logging.git
25+
[submodule "external/simdutf"]
26+
path = external/simdutf
27+
url = https://github.com/simdutf/simdutf.git

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if(CCACHE_PROGRAM)
1717
endif()
1818

1919
project(libsession-util
20-
VERSION 1.5.7
20+
VERSION 1.5.8
2121
DESCRIPTION "Session client utility library"
2222
LANGUAGES ${LANGS})
2323

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
# Session utility library
22

3+
## Build
4+
5+
```
6+
# Configure the build
7+
#
8+
# Options
9+
# Enable APIs for creating onion-requests with:
10+
#
11+
# -D ENABLE_ONIONERQ
12+
#
13+
# Enable testing of a Session Pro Backend by defining on the configure line:
14+
#
15+
# -D TEST_PRO_BACKEND_WITH_DEV_SERVER=1
16+
#
17+
# These tests require the Session Pro Backend running in development mode (SESH_PRO_BACKEND_DEV=1)
18+
# to be running and tests the request and response flow of registering, updating and revoking
19+
# Session Pro from the development backend. You must also have a libcurl available such that
20+
# `find_package(CURL)` succeeds (e.g. a system installed libcurl) for this to compile
21+
# successfully.
22+
#
23+
# By default, it contacts http://127.0.0.1:5000 but this URL can be changed using the CLI arg
24+
# --pro-backend-dev-server-url="<url>" when invoking the test suite.
25+
#
26+
cmake -G Ninja -S . -B Build
27+
28+
# Regenerate protobuf files
29+
cmake --build Build --target regen-protobuf --parallel --verbose
30+
31+
# Build
32+
cmake --build Build --parallel --verbose
33+
```
34+
335
## Docs
436

537
C Library: https://api.oxen.io/libsession-util-c/#/

external/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,15 @@ libsession_static_bundle(libzstd_static)
193193
set(JSON_BuildTests OFF CACHE INTERNAL "")
194194
set(JSON_Install ON CACHE INTERNAL "") # Required to export targets that we use
195195
libsession_system_or_submodule(NLOHMANN nlohmann_json nlohmann_json>=3.7.0 nlohmann-json)
196+
197+
set(JSON_BuildTests OFF CACHE INTERNAL "")
198+
set(JSON_Install ON CACHE INTERNAL "") # Required to export targets that we use
199+
200+
function(simdutf_subdir)
201+
set(SIMDUTF_TESTS OFF CACHE BOOL "")
202+
set(SIMDUTF_TOOLS OFF CACHE BOOL "")
203+
set(BUILD_SHARED_LIBS OFF)
204+
add_subdirectory(simdutf)
205+
endfunction()
206+
simdutf_subdir()
207+
libsession_static_bundle(simdutf)

external/simdutf

Submodule simdutf added at 7b3f5af

include/session/blinding.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ extern "C" {
55
#endif
66

77
#include <stddef.h>
8+
#include <stdint.h>
89

910
#include "export.h"
1011
#include "platform.h"
@@ -15,7 +16,7 @@ extern "C" {
1516
///
1617
/// Inputs:
1718
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes).
18-
/// - `server_pk` -- [in] the public key of the open group server to generate the
19+
/// - `server_pk` -- [in] the public key of the community server to generate the
1920
/// blinded id for (32 bytes).
2021
/// - `blinded_pk_out` -- [out] pointer to a buffer of at least 32 bytes where the blinded_pk will
2122
/// be written if generation was successful.
@@ -36,7 +37,7 @@ LIBSESSION_EXPORT bool session_blind15_key_pair(
3637
///
3738
/// Inputs:
3839
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes).
39-
/// - `server_pk` -- [in] the public key of the open group server to generate the
40+
/// - `server_pk` -- [in] the public key of the community server to generate the
4041
/// blinded id for (32 bytes).
4142
/// - `blinded_pk_out` -- [out] pointer to a buffer of at least 32 bytes where the blinded_pk will
4243
/// be written if generation was successful.
@@ -75,7 +76,7 @@ LIBSESSION_EXPORT bool session_blind_version_key_pair(
7576
///
7677
/// Inputs:
7778
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes).
78-
/// - `server_pk` -- [in] the public key of the open group server to generate the
79+
/// - `server_pk` -- [in] the public key of the community server to generate the
7980
/// blinded id for (32 bytes).
8081
/// - `msg` -- [in] Pointer to a data buffer containing the message to generate a signature for.
8182
/// - `msg_len` -- [in] Length of `msg`
@@ -97,7 +98,7 @@ LIBSESSION_EXPORT bool session_blind15_sign(
9798
///
9899
/// Inputs:
99100
/// - `ed25519_seckey` -- [in] the Ed25519 private key of the sender (64 bytes).
100-
/// - `server_pk` -- [in] the public key of the open group server to generate the
101+
/// - `server_pk` -- [in] the public key of the community server to generate the
101102
/// blinded id for (32 bytes).
102103
/// - `msg` -- [in] Pointer to a data buffer containing the message to generate a signature for.
103104
/// - `msg_len` -- [in] Length of `msg`
@@ -145,7 +146,7 @@ LIBSESSION_EXPORT bool session_blind_version_sign(
145146
/// Inputs:
146147
/// - `session_id` -- [in] the session_id to compare (66 bytes with a 05 prefix).
147148
/// - `blinded_id` -- [in] the blinded_id to compare, can be either 15 or 25 blinded (66 bytes).
148-
/// - `server_pk` -- [in] the public key of the open group server to the blinded id came from (64
149+
/// - `server_pk` -- [in] the public key of the community server to the blinded id came from (64
149150
/// bytes).
150151
///
151152
/// Outputs:

include/session/config/base.hpp

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <list>
88
#include <memory>
99
#include <session/config.hpp>
10+
#include <session/types.hpp>
1011
#include <session/util.hpp>
1112
#include <span>
1213
#include <type_traits>
@@ -29,9 +30,6 @@ class bt_dict_consumer;
2930

3031
namespace session::config {
3132

32-
template <typename T, typename... U>
33-
static constexpr bool is_one_of = (std::is_same_v<T, U> || ...);
34-
3533
/// True for a dict_value direct subtype, but not scalar sub-subtypes.
3634
template <typename T>
3735
static constexpr bool is_dict_subtype = is_one_of<T, config::scalar, config::set, config::dict>;
@@ -436,12 +434,16 @@ class ConfigBase : public ConfigSig {
436434
///
437435
/// Inputs:
438436
/// - `value` -- This will be assigned to the dict if it is missing
439-
void insert_if_missing(config::scalar&& value) {
437+
//
438+
/// Ouputs:
439+
/// - `bool` -- True if the value was inserted, false otherwise
440+
bool insert_if_missing(config::scalar&& value) {
440441
if (!_conf.is_dirty())
441442
if (auto current = get_clean<config::set>(); current && current->count(value))
442-
return;
443+
return false;
443444

444445
get_dirty<config::set>().insert(std::move(value));
446+
return true;
445447
}
446448

447449
/// API: base/ConfigBase::DictFieldProxy::set_erase_impl
@@ -450,28 +452,35 @@ class ConfigBase : public ConfigSig {
450452
///
451453
/// Inputs:
452454
/// - `value` -- This will be deleted from the dict
453-
void set_erase_impl(const config::scalar& value) {
455+
///
456+
/// Outputs:
457+
/// - `bool` -- True if an element was erased, false otherwise
458+
bool set_erase_impl(const config::scalar& value) {
454459
if (!_conf.is_dirty())
455460
if (auto current = get_clean<config::set>(); current && !current->count(value))
456-
return;
461+
return false;
457462

458463
config::dict* data = &_conf.dirty().data();
459464

460465
for (const auto& key : _inter_keys) {
461466
auto it = data->find(key);
462467
data = it != data->end() ? std::get_if<config::dict>(&it->second) : nullptr;
463468
if (!data)
464-
return;
469+
return false;
465470
}
466471

467472
auto it = data->find(_last_key);
468473
if (it == data->end())
469-
return;
474+
return false;
470475
auto& val = it->second;
471-
if (auto* current = std::get_if<config::set>(&val))
476+
bool result = false;
477+
if (auto* current = std::get_if<config::set>(&val)) {
472478
current->erase(value);
473-
else
479+
result = true;
480+
} else {
474481
val.emplace<config::set>();
482+
}
483+
return result;
475484
}
476485

477486
public:
@@ -797,8 +806,8 @@ class ConfigBase : public ConfigSig {
797806
///
798807
/// Inputs:
799808
/// - `value` -- The value to be set
800-
void set_insert(std::string_view value) {
801-
insert_if_missing(config::scalar{std::string{value}});
809+
bool set_insert(std::string_view value) {
810+
return insert_if_missing(config::scalar{std::string{value}});
802811
}
803812

804813
/// API: base/ConfigBase::DictFieldProxy::set_insert(int64_t)
@@ -808,7 +817,7 @@ class ConfigBase : public ConfigSig {
808817
///
809818
/// Inputs:
810819
/// - `value` -- The value to be set
811-
void set_insert(int64_t value) { insert_if_missing(config::scalar{value}); }
820+
bool set_insert(int64_t value) { return insert_if_missing(config::scalar{value}); }
812821

813822
/// API: base/ConfigBase::DictFieldProxy::set_erase(std::string_view)
814823
///
@@ -818,8 +827,11 @@ class ConfigBase : public ConfigSig {
818827
///
819828
/// Inputs:
820829
/// - `value` -- The value to be set
821-
void set_erase(std::string_view value) {
822-
set_erase_impl(config::scalar{std::string{value}});
830+
///
831+
/// Outputs:
832+
/// - `bool` -- True if an element was erased, false otherwise
833+
bool set_erase(std::string_view value) {
834+
return set_erase_impl(config::scalar{std::string{value}});
823835
}
824836

825837
/// API: base/ConfigBase::DictFieldProxy::set_erase(int64_t)
@@ -830,7 +842,10 @@ class ConfigBase : public ConfigSig {
830842
///
831843
/// Inputs:
832844
/// - `value` -- The value to be set
833-
void set_erase(int64_t value) { set_erase_impl(scalar{value}); }
845+
///
846+
/// Outputs:
847+
/// - `bool` -- True if an element was erased, false otherwise
848+
bool set_erase(int64_t value) { return set_erase_impl(scalar{value}); }
834849

835850
/// API: base/ConfigBase::DictFieldProxy::emplace
836851
///
@@ -944,7 +959,7 @@ class ConfigBase : public ConfigSig {
944959
/// API: base/ConfigBase::load_key
945960
///
946961
/// Called to load an ed25519 key for encryption; this is meant for use by single-ownership
947-
/// config types, like UserProfile, but not shared config types (closed groups).
962+
/// config types, like UserProfile, but not shared config types (groups).
948963
///
949964
/// Takes a binary string which is either the 32-byte seed, or 64-byte libsodium secret (which
950965
/// is just the seed and pubkey concatenated together), and then calls `key(...)` with the seed.

include/session/config/contacts.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern "C" {
77
#include "base.h"
88
#include "expiring.h"
99
#include "notify.h"
10+
#include "pro.h"
1011
#include "profile_pic.h"
1112
#include "util.h"
1213

@@ -35,6 +36,8 @@ typedef struct contacts_contact {
3536

3637
int64_t created; // unix timestamp (seconds)
3738

39+
session_protocol_pro_profile_bitset profile_bitset;
40+
3841
} contacts_contact;
3942

4043
typedef struct contacts_blinded_contact {
@@ -52,6 +55,8 @@ typedef struct contacts_blinded_contact {
5255
bool legacy_blinding;
5356
int64_t created; // unix timestamp (seconds)
5457

58+
session_protocol_pro_profile_bitset profile_bitset;
59+
5560
} contacts_blinded_contact;
5661

5762
/// Struct containing a list of contacts_blinded_contact structs. Typically where this is returned

include/session/config/contacts.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "expiring.hpp"
1212
#include "namespaces.hpp"
1313
#include "notify.hpp"
14+
#include "pro.hpp"
1415
#include "profile_pic.hpp"
1516

1617
extern "C" struct contacts_contact;
@@ -47,6 +48,7 @@ namespace session::config {
4748
/// j - Unix timestamp (seconds) when the contact was created ("j" to match user_groups
4849
/// equivalent "j"oined field). Omitted if 0.
4950
/// t - The `profile_updated` unix timestamp (seconds) for this contacts profile information.
51+
/// f - session pro profile features bitset for this contact
5052
///
5153
/// b - dict of blinded contacts. This is a nested dict where the outer keys are the BASE_URL of
5254
/// the community the blinded contact originated from and the outer value is a dict containing:
@@ -68,6 +70,7 @@ namespace session::config {
6870
/// j - Unix timestamp (seconds) when the contact was created ("j" to match user_groups
6971
/// equivalent "j"oined field). Omitted if 0.
7072
/// y - flag indicating whether the blinded message request is using legac"y" blinding.
73+
/// f - session pro profile features bitset for this blinded contact
7174

7275
struct contact_info {
7376
static constexpr size_t MAX_NAME_LENGTH = 100;
@@ -93,6 +96,8 @@ struct contact_info {
9396
std::chrono::seconds exp_timer{0}; // The expiration timer (in seconds)
9497
int64_t created = 0; // Unix timestamp (seconds) when this contact was added
9598

99+
ProProfileBitset profile_bitset = {};
100+
96101
explicit contact_info(std::string sid);
97102

98103
// Internal ctor/method for C API implementations:
@@ -136,6 +141,8 @@ struct blinded_contact_info {
136141
bool legacy_blinding;
137142
std::chrono::sys_seconds created{}; // Unix timestamp (seconds) when this contact was added
138143

144+
ProProfileBitset profile_bitset = {};
145+
139146
blinded_contact_info() = default;
140147
explicit blinded_contact_info(
141148
std::string_view community_base_url,
@@ -428,6 +435,16 @@ class Contacts : public ConfigBase {
428435
/// - `timestamp` -- standard unix timestamp of the time contact was created
429436
void set_created(std::string_view session_id, int64_t timestamp);
430437

438+
/// API: contacts/contacts::set_pro_features
439+
///
440+
/// Alternative to `set()` for setting a single field. (If setting multiple fields at once you
441+
/// should use `set()` instead).
442+
///
443+
/// Inputs:
444+
/// - `session_id` -- hex string of the session id
445+
/// - `features` -- The updated profile features to use
446+
void set_pro_features(std::string_view session_id, ProProfileBitset features);
447+
431448
/// API: contacts/contacts::erase
432449
///
433450
/// Removes a contact, if present. Returns true if it was found and removed, false otherwise.

include/session/config/convo_info_volatile.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ extern "C" {
66

77
#include "base.h"
88
#include "profile_pic.h"
9+
#include "session/types.h"
910

1011
typedef struct convo_info_volatile_1to1 {
1112
char session_id[67]; // in hex; 66 hex chars + null terminator.
1213

1314
int64_t last_read; // milliseconds since unix epoch
1415
bool unread; // true if the conversation is explicitly marked unread
16+
17+
bool has_pro_gen_index_hash; // Flag indicating if hash is set
18+
bytes32 pro_gen_index_hash; // Hash of the generation index set by the Session Pro Backend
19+
uint64_t pro_expiry_unix_ts_ms; // Unix epoch timestamp to which this contacts entitlement to
20+
// Session Pro features is valid to
1521
} convo_info_volatile_1to1;
1622

1723
typedef struct convo_info_volatile_community {
@@ -44,6 +50,11 @@ typedef struct convo_info_volatile_blinded_1to1 {
4450

4551
int64_t last_read; // ms since unix epoch
4652
bool unread; // true if the conversation is explicitly marked unread
53+
54+
bool has_pro_gen_index_hash; // Flag indicating if hash is set
55+
bytes32 pro_gen_index_hash; // Hash of the generation index set by the Session Pro Backend
56+
uint64_t pro_expiry_unix_ts_ms; // Unix epoch timestamp to which this contacts entitlement to
57+
// Session Pro features is valid to
4758
} convo_info_volatile_blinded_1to1;
4859

4960
/// API: convo_info_volatile/convo_info_volatile_init

0 commit comments

Comments
 (0)