Skip to content

Commit 3ee705f

Browse files
authored
Merge pull request #60 from mpretty-cyro/fix/remove-legacy-blinding-flag-convo-info-volatile
Removed 'legacy_blinding' flag from convo info volatile functions
2 parents 551a48b + a32528a commit 3ee705f

File tree

9 files changed

+104
-75
lines changed

9 files changed

+104
-75
lines changed

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.3
20+
VERSION 1.5.4
2121
DESCRIPTION "Session client utility library"
2222
LANGUAGES ${LANGS})
2323

include/session/config/contacts.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ typedef struct contacts_blinded_contact {
4545

4646
char name[101]; // This will be a 0-length string when unset
4747
user_profile_pic profile_pic;
48+
int64_t profile_updated; // unix timestamp (seconds)
49+
50+
int priority;
4851

4952
bool legacy_blinding;
5053
int64_t created; // unix timestamp (seconds)

include/session/config/contacts.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ namespace session::config {
6161
/// alive as empty dicts get pruned).
6262
/// p - profile url (string)
6363
/// q - profile decryption key (binary)
64+
/// t - The `profile_updated` unix timestamp (seconds) for this contacts profile information.
65+
/// + - the conversation priority; -1 means hidden; omitted means not pinned; otherwise an
66+
/// integer value >0, where a higher priority means the conversation is meant to appear
67+
/// earlier in the pinned conversation list.
6468
/// j - Unix timestamp (seconds) when the contact was created ("j" to match user_groups
6569
/// equivalent "j"oined field). Omitted if 0.
6670
/// y - flag indicating whether the blinded message request is using legac"y" blinding.
@@ -122,6 +126,13 @@ struct blinded_contact_info {
122126
const std::string session_id() const; // in hex
123127
std::string name;
124128
profile_pic profile_picture;
129+
std::chrono::sys_seconds profile_updated{}; /// The unix timestamp (seconds) that this
130+
/// profile information was last updated.
131+
int priority = 0; // If >0 then this message is pinned; higher values mean higher priority
132+
// (i.e. pinned earlier in the pinned list). If negative then this
133+
// conversation is hidden. Otherwise (0) this is a regular, unpinned
134+
// conversation.
135+
125136
bool legacy_blinding;
126137
std::chrono::sys_seconds created{}; // Unix timestamp (seconds) when this contact was added
127138

@@ -142,7 +153,7 @@ struct blinded_contact_info {
142153
/// - `c` -- Return Parameter that will be filled with data in blinded_contact_info
143154
void into(contacts_blinded_contact& c) const;
144155

145-
/// API: contacts/contact_info::set_name
156+
/// API: contacts/blinded_contact_info::set_name
146157
///
147158
/// Sets a name; this is exactly the same as assigning to .name directly,
148159
/// except that we throw an exception if the given name is longer than MAX_NAME_LENGTH.

include/session/config/convo_info_volatile.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,23 +368,20 @@ LIBSESSION_EXPORT bool convo_info_volatile_get_or_construct_legacy_group(
368368
/// [in] config_object* conf,
369369
/// [out] convo_info_volatile_blinded_1to1* convo,
370370
/// [in] const char* blinded_session_id
371-
/// [in] bool legacy_blinding
372371
/// );
373372
/// ```
374373
///
375374
/// Inputs:
376375
/// - `conf` -- [in] Pointer to the config object
377376
/// - `convo` -- [out] Pointer to conversation info
378377
/// - `blinded_session_id` -- [in] Null terminated hex string of the session_id
379-
/// - `legacy_blinding` -- flag indicating whether this blinded contact should use legacy blinding
380378
///
381379
/// Outputs:
382380
/// - `bool` - Returns true if the conversation exists
383381
LIBSESSION_EXPORT bool convo_info_volatile_get_blinded_1to1(
384382
config_object* conf,
385383
convo_info_volatile_blinded_1to1* convo,
386-
const char* blinded_session_id,
387-
bool legacy_blinding) LIBSESSION_WARN_UNUSED;
384+
const char* blinded_session_id) LIBSESSION_WARN_UNUSED;
388385

389386
/// API: convo_info_volatile/convo_info_volatile_get_or_construct_blinded_1to1
390387
///
@@ -405,23 +402,20 @@ LIBSESSION_EXPORT bool convo_info_volatile_get_blinded_1to1(
405402
/// [in] config_object* conf,
406403
/// [out] convo_info_volatile_blinded_1to1* convo,
407404
/// [in] const char* blinded_session_id
408-
/// [in] bool legacy_blinding
409405
/// );
410406
/// ```
411407
///
412408
/// Inputs:
413409
/// - `conf` -- [in] Pointer to the config object
414410
/// - `convo` -- [out] Pointer to conversation info
415411
/// - `blinded_session_id` -- [in] Null terminated hex string of the blinded session id
416-
/// - `legacy_blinding` -- flag indicating whether this blinded contact should use legacy blinding
417412
///
418413
/// Outputs:
419414
/// - `bool` - Returns true if the conversation exists
420415
LIBSESSION_EXPORT bool convo_info_volatile_get_or_construct_blinded_1to1(
421416
config_object* conf,
422417
convo_info_volatile_blinded_1to1* convo,
423-
const char* blinded_session_id,
424-
bool legacy_blinding) LIBSESSION_WARN_UNUSED;
418+
const char* blinded_session_id) LIBSESSION_WARN_UNUSED;
425419

426420
/// API: convo_info_volatile/convo_info_volatile_set_1to1
427421
///
@@ -630,19 +624,17 @@ LIBSESSION_EXPORT bool convo_info_volatile_erase_legacy_group(
630624
/// BOOL convo_info_volatile_erase_blinded_1to1(
631625
/// [in] config_object* conf,
632626
/// [in] const char* blinded_session_id
633-
/// [in] bool legacy_blinding
634627
/// );
635628
/// ```
636629
///
637630
/// Inputs:
638631
/// - `conf` -- [in] Pointer to the config object
639632
/// - `blinded_session_id` -- [in] Null terminated hex string
640-
/// - `legacy_blinding` -- flag indicating whether the blinded contact used legacy blinding
641633
///
642634
/// Outputs:
643635
/// - `bool` - Returns true if conversation was found and removed
644636
LIBSESSION_EXPORT bool convo_info_volatile_erase_blinded_1to1(
645-
config_object* conf, const char* blinded_session_id, bool legacy_blinding);
637+
config_object* conf, const char* blinded_session_id);
646638

647639
/// API: convo_info_volatile/convo_info_volatile_size
648640
///

include/session/config/convo_info_volatile.hpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,8 @@ namespace convo {
174174
///
175175
/// Inputs:
176176
/// - `blinded_session_id` -- Hex string of the blinded session id
177-
/// - `legacy_blinding` -- flag indicating whether this blinded contact should use legacy
178-
/// blinding
179-
explicit blinded_one_to_one(std::string&& blinded_session_id, bool legacy_blinding);
180-
explicit blinded_one_to_one(std::string_view blinded_session_id, bool legacy_blinding);
177+
explicit blinded_one_to_one(std::string&& blinded_session_id);
178+
explicit blinded_one_to_one(std::string_view blinded_session_id);
181179

182180
// Internal ctor/method for C API implementations:
183181
blinded_one_to_one(const struct convo_info_volatile_blinded_1to1& c); // From c struct
@@ -341,13 +339,11 @@ class ConvoInfoVolatile : public ConfigBase {
341339
///
342340
/// Inputs:
343341
/// - `blinded_session_id` -- Hex string of the blinded Session ID
344-
/// - `legacy_blinding` -- flag indicating whether this blinded contact should use legacy
345-
/// blinding
346342
///
347343
/// Outputs:
348344
/// - `std::optional<convo::blinded_one_to_one>` - Returns a contact
349345
std::optional<convo::blinded_one_to_one> get_blinded_1to1(
350-
std::string_view blinded_session_id, bool legacy_blinding) const;
346+
std::string_view blinded_session_id) const;
351347

352348
/// API: convo_info_volatile/ConvoInfoVolatile::get_or_construct_1to1
353349
///
@@ -444,13 +440,11 @@ class ConvoInfoVolatile : public ConfigBase {
444440
///
445441
/// Inputs:
446442
/// - `blinded_session_id` -- Hex string blinded Session ID
447-
/// - `legacy_blinding` -- flag indicating whether this blinded contact should use legacy
448-
/// blinding
449443
///
450444
/// Outputs:
451445
/// - `convo::blinded_one_to_one` - Returns a blinded contact
452446
convo::blinded_one_to_one get_or_construct_blinded_1to1(
453-
std::string_view blinded_session_id, bool legacy_blinding) const;
447+
std::string_view blinded_session_id) const;
454448

455449
/// API: convo_info_volatile/ConvoInfoVolatile::set
456450
///
@@ -545,11 +539,10 @@ class ConvoInfoVolatile : public ConfigBase {
545539
///
546540
/// Inputs:
547541
/// - `pubkey` -- hex blinded session id
548-
/// - `legacy_blinding` -- flag indicating whether this blinded contact is using legacy blinding
549542
///
550543
/// Outputs:
551544
/// - `bool` - Returns true if found and removed, otherwise false
552-
bool erase_blinded_1to1(std::string_view pubkey, bool legacy_blinding);
545+
bool erase_blinded_1to1(std::string_view pubkey);
553546

554547
/// API: convo_info_volatile/ConvoInfoVolatile::erase
555548
///

src/config/contacts.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ void blinded_contact_info::load(const dict& info_dict) {
332332
} else {
333333
profile_picture.clear();
334334
}
335+
profile_updated = ts_or_epoch(info_dict, "t");
336+
priority = int_or_0(info_dict, "+");
335337
legacy_blinding = int_or_0(info_dict, "y");
336338
created = ts_or_epoch(info_dict, "j");
337339
}
@@ -350,6 +352,8 @@ void blinded_contact_info::into(contacts_blinded_contact& c) const {
350352
} else {
351353
copy_c_str(c.profile_pic.url, "");
352354
}
355+
c.profile_updated = profile_updated.time_since_epoch().count();
356+
c.priority = priority;
353357
c.legacy_blinding = legacy_blinding;
354358
c.created = created.time_since_epoch().count();
355359
}
@@ -363,6 +367,8 @@ blinded_contact_info::blinded_contact_info(const contacts_blinded_contact& c) {
363367
profile_picture.url = c.profile_pic.url;
364368
profile_picture.key.assign(c.profile_pic.key, c.profile_pic.key + 32);
365369
}
370+
profile_updated = to_sys_seconds(c.profile_updated);
371+
priority = c.priority;
366372
legacy_blinding = c.legacy_blinding;
367373
created = to_sys_seconds(c.created);
368374
}
@@ -474,7 +480,8 @@ void Contacts::set_blinded(const blinded_contact_info& bc) {
474480
bc.profile_picture.url,
475481
info["q"],
476482
bc.profile_picture.key);
477-
483+
set_ts(info["t"], bc.profile_updated);
484+
set_nonzero_int(info["+"], bc.priority);
478485
set_positive_int(info["y"], bc.legacy_blinding);
479486
set_ts(info["j"], bc.created);
480487
}

src/config/convo_info_volatile.cpp

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,23 @@ namespace convo {
8282
c.unread = unread;
8383
}
8484

85-
blinded_one_to_one::blinded_one_to_one(std::string&& sid, bool legacy_blinding) :
86-
blinded_session_id{std::move(sid)}, legacy_blinding{legacy_blinding} {
87-
check_session_id(blinded_session_id, legacy_blinding ? "15" : "25");
85+
blinded_one_to_one::blinded_one_to_one(std::string&& sid) : blinded_session_id{std::move(sid)} {
86+
auto prefix = get_session_id_prefix(blinded_session_id);
87+
legacy_blinding = (prefix == session::SessionIDPrefix::community_blinded_legacy);
88+
89+
if (prefix != session::SessionIDPrefix::community_blinded &&
90+
prefix != session::SessionIDPrefix::community_blinded_legacy)
91+
throw std::invalid_argument{
92+
"Invalid blinded ID: Expected '15' or '25' prefix; got " + blinded_session_id};
8893
}
89-
blinded_one_to_one::blinded_one_to_one(std::string_view sid, bool legacy_blinding) :
90-
blinded_session_id{sid}, legacy_blinding{legacy_blinding} {
91-
check_session_id(blinded_session_id, legacy_blinding ? "15" : "25");
94+
blinded_one_to_one::blinded_one_to_one(std::string_view sid) : blinded_session_id{sid} {
95+
auto prefix = get_session_id_prefix(blinded_session_id);
96+
legacy_blinding = (prefix == session::SessionIDPrefix::community_blinded_legacy);
97+
98+
if (prefix != session::SessionIDPrefix::community_blinded &&
99+
prefix != session::SessionIDPrefix::community_blinded_legacy)
100+
throw std::invalid_argument{
101+
"Invalid blinded ID: Expected '15' or '25' prefix; got " + blinded_session_id};
92102
}
93103
blinded_one_to_one::blinded_one_to_one(const convo_info_volatile_blinded_1to1& c) :
94104
base{c.last_read, c.unread},
@@ -234,25 +244,31 @@ convo::legacy_group ConvoInfoVolatile::get_or_construct_legacy_group(
234244
}
235245

236246
std::optional<convo::blinded_one_to_one> ConvoInfoVolatile::get_blinded_1to1(
237-
std::string_view pubkey_hex, bool legacy_blinding) const {
238-
std::string pubkey = session_id_to_bytes(pubkey_hex, legacy_blinding ? "15" : "25");
247+
std::string_view pubkey_hex) const {
248+
auto prefix = get_session_id_prefix(pubkey_hex);
249+
250+
if (prefix != session::SessionIDPrefix::community_blinded &&
251+
prefix != session::SessionIDPrefix::community_blinded_legacy)
252+
throw std::invalid_argument{
253+
"Invalid blinded ID: Expected '15' or '25' prefix; got " + std::string{pubkey_hex}};
254+
255+
std::string pubkey = session_id_to_bytes(pubkey_hex, to_string(prefix));
239256

240257
auto* info_dict = data["b"][pubkey].dict();
241258
if (!info_dict)
242259
return std::nullopt;
243260

244-
auto result =
245-
std::make_optional<convo::blinded_one_to_one>(std::string{pubkey_hex}, legacy_blinding);
261+
auto result = std::make_optional<convo::blinded_one_to_one>(std::string{pubkey_hex});
246262
result->load(*info_dict);
247263
return result;
248264
}
249265

250266
convo::blinded_one_to_one ConvoInfoVolatile::get_or_construct_blinded_1to1(
251-
std::string_view pubkey_hex, bool legacy_blinding) const {
252-
if (auto maybe = get_blinded_1to1(pubkey_hex, legacy_blinding))
267+
std::string_view pubkey_hex) const {
268+
if (auto maybe = get_blinded_1to1(pubkey_hex))
253269
return *std::move(maybe);
254270

255-
return convo::blinded_one_to_one{std::string{pubkey_hex}, legacy_blinding};
271+
return convo::blinded_one_to_one{std::string{pubkey_hex}};
256272
}
257273

258274
void ConvoInfoVolatile::set(const convo::one_to_one& c) {
@@ -386,9 +402,8 @@ bool ConvoInfoVolatile::erase_group(std::string_view id) {
386402
bool ConvoInfoVolatile::erase_legacy_group(std::string_view id) {
387403
return erase(convo::legacy_group{id});
388404
}
389-
bool ConvoInfoVolatile::erase_blinded_1to1(
390-
std::string_view blinded_session_id, bool legacy_blinding) {
391-
return erase(convo::blinded_one_to_one{blinded_session_id, legacy_blinding});
405+
bool ConvoInfoVolatile::erase_blinded_1to1(std::string_view blinded_session_id) {
406+
return erase(convo::blinded_one_to_one{blinded_session_id});
392407
}
393408

394409
size_t ConvoInfoVolatile::size_1to1() const {
@@ -489,11 +504,7 @@ class val_loader {
489504

490505
if (k.size() == 33 && (k[0] == prefix || (legacy_prefix && k[0] == *legacy_prefix))) {
491506
if (auto* info_dict = std::get_if<dict>(&v)) {
492-
if constexpr (std::is_same_v<ConvoType, convo::blinded_one_to_one>)
493-
val = std::make_shared<convo::any>(ConvoType{
494-
oxenc::to_hex(k), (legacy_prefix && k[0] == *legacy_prefix)});
495-
else
496-
val = std::make_shared<convo::any>(ConvoType{oxenc::to_hex(k)});
507+
val = std::make_shared<convo::any>(ConvoType{oxenc::to_hex(k)});
497508
std::get<ConvoType>(*val).load(*info_dict);
498509
return true;
499510
}
@@ -693,13 +704,11 @@ LIBSESSION_C_API bool convo_info_volatile_get_or_construct_legacy_group(
693704
LIBSESSION_C_API bool convo_info_volatile_get_blinded_1to1(
694705
config_object* conf,
695706
convo_info_volatile_blinded_1to1* convo,
696-
const char* blinded_session_id,
697-
bool legacy_blinding) {
707+
const char* blinded_session_id) {
698708
return wrap_exceptions(
699709
conf,
700710
[&] {
701-
if (auto c = unbox<ConvoInfoVolatile>(conf)->get_blinded_1to1(
702-
blinded_session_id, legacy_blinding)) {
711+
if (auto c = unbox<ConvoInfoVolatile>(conf)->get_blinded_1to1(blinded_session_id)) {
703712
c->into(*convo);
704713
return true;
705714
}
@@ -711,13 +720,12 @@ LIBSESSION_C_API bool convo_info_volatile_get_blinded_1to1(
711720
LIBSESSION_C_API bool convo_info_volatile_get_or_construct_blinded_1to1(
712721
config_object* conf,
713722
convo_info_volatile_blinded_1to1* convo,
714-
const char* blinded_session_id,
715-
bool legacy_blinding) {
723+
const char* blinded_session_id) {
716724
return wrap_exceptions(
717725
conf,
718726
[&] {
719727
unbox<ConvoInfoVolatile>(conf)
720-
->get_or_construct_blinded_1to1(blinded_session_id, legacy_blinding)
728+
->get_or_construct_blinded_1to1(blinded_session_id)
721729
.into(*convo);
722730
return true;
723731
},
@@ -799,13 +807,10 @@ LIBSESSION_C_API bool convo_info_volatile_erase_legacy_group(
799807
false);
800808
}
801809
LIBSESSION_C_API bool convo_info_volatile_erase_blinded_1to1(
802-
config_object* conf, const char* blinded_session_id, bool legacy_blinding) {
810+
config_object* conf, const char* blinded_session_id) {
803811
return wrap_exceptions(
804812
conf,
805-
[&] {
806-
return unbox<ConvoInfoVolatile>(conf)->erase_blinded_1to1(
807-
blinded_session_id, legacy_blinding);
808-
},
813+
[&] { return unbox<ConvoInfoVolatile>(conf)->erase_blinded_1to1(blinded_session_id); },
809814
false);
810815
}
811816

0 commit comments

Comments
 (0)