Skip to content

Commit

Permalink
Fix process_config.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: ea657dfc621fdf13a1641377a2bef6ddd396172a
  • Loading branch information
levlam committed Mar 8, 2018
1 parent 34f6fd8 commit c2dbb60
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 11 deletions.
18 changes: 10 additions & 8 deletions td/telegram/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,9 @@ void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
shared_config.set_option_integer("basic_group_size_max", config->chat_size_max_);
shared_config.set_option_integer("supergroup_size_max", config->megagroup_size_max_);
shared_config.set_option_integer("pinned_chat_count_max", config->pinned_dialogs_count_max_);
shared_config.set_option_string("t_me_url", config->me_url_prefix_);
if (is_from_main_dc || !shared_config.have_option("t_me_url")) {
shared_config.set_option_string("t_me_url", config->me_url_prefix_);
}
if (is_from_main_dc) {
if ((config->flags_ & telegram_api::config::TMP_SESSIONS_MASK) != 0) {
G()->shared_config().set_option_integer("session_count", config->tmp_sessions_);
Expand All @@ -680,15 +682,15 @@ void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
}
}

shared_config.set_option_integer("edit_time_limit", config->edit_time_limit_);
shared_config.set_option_boolean("revoke_pm_inbox",
(config->flags_ & telegram_api::config::REVOKE_PM_INBOX_MASK) != 0);
shared_config.set_option_integer("revoke_time_limit", config->revoke_time_limit_);
shared_config.set_option_integer("revoke_pm_time_limit", config->revoke_pm_time_limit_);
if (is_from_main_dc) {
shared_config.set_option_integer("edit_time_limit", config->edit_time_limit_);
shared_config.set_option_boolean("revoke_pm_inbox",
(config->flags_ & telegram_api::config::REVOKE_PM_INBOX_MASK) != 0);
shared_config.set_option_integer("revoke_time_limit", config->revoke_time_limit_);
shared_config.set_option_integer("revoke_pm_time_limit", config->revoke_pm_time_limit_);

shared_config.set_option_integer("rating_e_decay", config->rating_e_decay_);
shared_config.set_option_integer("rating_e_decay", config->rating_e_decay_);

if (is_from_main_dc) {
shared_config.set_option_boolean("calls_enabled", config->phonecalls_enabled_);
}
shared_config.set_option_integer("call_ring_timeout_ms", config->call_ring_timeout_ms_);
Expand Down
4 changes: 4 additions & 0 deletions td/telegram/ConfigShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ void ConfigShared::set_option_string(Slice name, Slice value) {
}
}

bool ConfigShared::have_option(Slice name) const {
return config_pmc_->isset(name.str());
}

string ConfigShared::get_option(Slice name) const {
return config_pmc_->get(name.str());
}
Expand Down
1 change: 1 addition & 0 deletions td/telegram/ConfigShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ConfigShared {
void set_option_integer(Slice name, int32 value);
void set_option_string(Slice name, Slice value);

bool have_option(Slice name) const;
string get_option(Slice name) const;
std::unordered_map<string, string> get_options(Slice prefix) const;
std::unordered_map<string, string> get_options() const;
Expand Down
5 changes: 5 additions & 0 deletions tddb/td/db/BinlogKeyValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ class BinlogKeyValue : public KeyValueSyncInterface {
binlog_->add_raw_event(seq_no, std::move(event));
}

bool isset(const string &key) override {
auto lock = rw_mutex_.lock_read().move_as_ok();
return map_.count(key) > 0;
}

string get(const string &key) override {
auto lock = rw_mutex_.lock_read().move_as_ok();
auto it = map_.find(key);
Expand Down
9 changes: 8 additions & 1 deletion tddb/td/db/KeyValueSyncInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "td/utils/common.h"

namespace td {

class KeyValueSyncInterface {
public:
// SeqNo is used to restore total order on all write queries.
Expand All @@ -21,8 +22,14 @@ class KeyValueSyncInterface {
KeyValueSyncInterface(KeyValueSyncInterface &&) = default;
KeyValueSyncInterface &operator=(KeyValueSyncInterface &&) = default;
virtual ~KeyValueSyncInterface() = default;

virtual SeqNo set(string key, string value) = 0;
virtual SeqNo erase(const string &key) = 0;

virtual bool isset(const string &key) = 0;

virtual string get(const string &key) = 0;

virtual SeqNo erase(const string &key) = 0;
};

} // namespace td
5 changes: 4 additions & 1 deletion tddb/td/db/Pmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once

#include "td/db/binlog/ConcurrentBinlog.h"
#include "td/db/BinlogKeyValue.h"
#include "td/db/SqliteKeyValue.h"

Expand All @@ -13,12 +15,13 @@
#include <memory>

namespace td {
class SqliteKeyValue;

using BinlogPmcBase = BinlogKeyValue<ConcurrentBinlog>;
using BinlogPmc = std::shared_ptr<BinlogPmcBase>;
using BinlogPmcPtr = BinlogPmcBase *;

using BigPmcBase = SqliteKeyValue;
using BigPmc = std::unique_ptr<BigPmcBase>;
using BigPmcPtr = BigPmcBase *;

}; // namespace td
8 changes: 7 additions & 1 deletion test/secret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,16 +490,22 @@ class OldFakeKeyValue : public KeyValueSyncInterface {
kv_[key] = value;
return 0;
}

SeqNo erase(const string &key) override {
kv_.erase(key);
return 0;
}

bool isset(const string &key) override {
return kv_.count(key) > 0;
}

string get(const string &key) override {
auto it = kv_.find(key);
if (it != kv_.end()) {
return it->second;
}
return "";
return string();
}

private:
Expand Down

0 comments on commit c2dbb60

Please sign in to comment.