Skip to content

Commit

Permalink
Rename & tweak
Browse files Browse the repository at this point in the history
- rename `debug_dump` to `make_dump`, since it is also used internally
  (for non-debugging).
- make it `const` to ensure we aren't mutating state.  (And we were,
  with clearing old hashes: that is now done only by `dump()` but not
  `make_dump()`).
- Update API documentation wording
  • Loading branch information
jagerman committed Sep 18, 2023
1 parent 3198403 commit 849d215
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
11 changes: 6 additions & 5 deletions include/session/config/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,24 +1020,25 @@ class ConfigBase : public ConfigSig {
/// Returns a dump of the current state for storage in the database; this value would get passed
/// into the constructor to reconstitute the object (including the push/not pushed status). This
/// method is *not* virtual: if subclasses need to store extra data they should set it in the
/// `subclass_data` field. Updates the internal needs_dump flag to false.
/// `subclass_data` field. Resets the `needs_dump()` flag to false.
///
/// Inputs: None
///
/// Outputs:
/// - `ustring` -- Returns binary data of the state dump
ustring dump();

/// API: base/ConfigBase::debug_dump
/// API: base/ConfigBase::make_dump
///
/// Returns a dump of the current state for debugging. Does *not* update the
/// internal needs_dump flag.
/// Returns a dump of the current state; unlike `dump()` this does *not* update the internal
/// needs_dump flag; it is mostly used internally (by `dump()`), but can also be called
/// externally for debugging purposes.
///
/// Inputs: None
///
/// Outputs:
/// - `ustring` -- Returns binary data of the state dump
ustring debug_dump();
ustring make_dump() const;

/// API: base/ConfigBase::needs_dump
///
Expand Down
11 changes: 6 additions & 5 deletions include/session/config/groups/keys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,16 +592,17 @@ class Keys final : public ConfigSig {
/// to the `Keys` constructor to reinitialize a Keys object with the current state.
ustring dump();

/// API: groups/Keys::debug_dump
/// API: groups/Keys::make_dump
///
/// Returns a dump of the current state; unlike `dump()` this does *not* update the internal
/// needs_dump flag; it is mostly used internally (by `dump()`), but can also be called
/// externally for debugging purposes.
///
/// Returns a dump of the current state for debugging. Does *not* update the
/// internal needs_dump flag.

/// Inputs: None
///
/// Outputs:
/// - `ustring` -- Returns binary data of the state dump
ustring debug_dump();
ustring make_dump() const;

/// API: groups/Keys::encrypt_message
///
Expand Down
8 changes: 4 additions & 4 deletions src/config/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,15 @@ void ConfigBase::confirm_pushed(seqno_t seqno, std::string msg_hash) {
}

ustring ConfigBase::dump() {
auto d = this->debug_dump();
if (is_readonly())
_old_hashes.clear();

auto d = make_dump();
_needs_dump = false;
return d;
}

ustring ConfigBase::debug_dump() {
ustring ConfigBase::make_dump() const {
auto data = _config->serialize(false /* disable signing for local storage */);
auto data_sv = from_unsigned_sv(data);
oxenc::bt_list old_hashes;
Expand All @@ -295,8 +297,6 @@ ustring ConfigBase::debug_dump() {
d.append("$", data_sv);
d.append("(", _curr_hash);

if (is_readonly())
_old_hashes.clear();
d.append_list(")").append(_old_hashes.begin(), _old_hashes.end());

if (auto extra = extra_data(); !extra.empty())
Expand Down
4 changes: 2 additions & 2 deletions src/config/groups/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ bool Keys::needs_dump() const {
}

ustring Keys::dump() {
auto dumped = this->debug_dump();
auto dumped = make_dump();

needs_dump_ = false;
return dumped;
}

ustring Keys::debug_dump() {
ustring Keys::make_dump() const {
oxenc::bt_dict_producer d;
{
auto active = d.append_list("active");
Expand Down

0 comments on commit 849d215

Please sign in to comment.