MCPcopy Create free account
hub / github.com/TelegramMessenger/cocoon / custom_initialize

Method custom_initialize

runners/key-manager/KeyManagerRunner.cpp:91–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91void KeyManagerRunner::custom_initialize(td::Promise<td::Unit> promise) {
92 kv_ = std::make_shared<td::RocksDb>(td::RocksDb::open(db_path_).move_as_ok());
93
94 {
95 td::UniqueSlice value = get_from_db("config");
96
97 if (value.size() > 0) {
98 auto obj = cocoon::fetch_tl_object<cocoon_api::keyManagerDb_Config>(value.as_slice(), true).move_as_ok();
99
100 cocoon_api::downcast_call(*obj, td::overloaded([&](cocoon_api::keyManagerDb_configEmpty &c) { UNREACHABLE(); },
101 [&](cocoon_api::keyManagerDb_configV1 &c) {
102 CHECK(runner_config()->root_contract_config->version() >=
103 (td::uint32)c.root_contract_version_);
104 active_config_version_ = c.root_contract_version_;
105 }));
106 } else {
107 active_config_version_ = 0;
108 }
109 }
110
111 auto snap = kv_->snapshot();
112 snap->for_each([&](td::Slice key, td::Slice value) -> td::Status {
113 process_db_key(key, value);
114 return td::Status::OK();
115 });
116
117 register_custom_http_handler("/stats", [&](http::HttpCallback::RequestType request_type,
118 std::vector<std::pair<std::string, std::string>> headers, std::string path,
119 std::vector<std::pair<std::string, std::string>> args, std::string body,
120 std::unique_ptr<http::HttpRequestCallback> answer_callback) {
121 http_send_static_answer(http_generate_main(), std::move(answer_callback));
122 });
123 register_custom_http_handler(
124 "/jsonstats",
125 [&](http::HttpCallback::RequestType request_type, std::vector<std::pair<std::string, std::string>> headers,
126 std::string path, std::vector<std::pair<std::string, std::string>> args, std::string body,
127 std::unique_ptr<http::HttpRequestCallback> answer_callback) {
128 http_send_static_answer(http_generate_json_stats(), std::move(answer_callback), "application/json");
129 });
130 register_custom_http_handler(
131 "/request/removekey",
132 [&](http::HttpCallback::RequestType request_type, std::vector<std::pair<std::string, std::string>> headers,
133 std::string path, std::vector<std::pair<std::string, std::string>> args, std::string body,
134 std::unique_ptr<http::HttpRequestCallback> answer_callback) {
135 if (request_type == http::HttpCallback::RequestType::Post) {
136 http_send_static_answer(http_remove_key(get_from_sorted_list(args, "key")), std::move(answer_callback));
137 } else {
138 http_send_static_answer(404, "not found", std::move(answer_callback));
139 }
140 });
141 register_custom_http_handler(
142 "/request/generatekey",
143 [&](http::HttpCallback::RequestType request_type, std::vector<std::pair<std::string, std::string>> headers,
144 std::string path, std::vector<std::pair<std::string, std::string>> args, std::string body,
145 std::unique_ptr<http::HttpRequestCallback> answer_callback) {
146 if (request_type == http::HttpCallback::RequestType::Post) {
147 http_send_static_answer(http_generate_key(get_from_sorted_list(args, "type")), std::move(answer_callback));
148 } else {

Callers

nothing calls this directly

Calls 3

as_sliceMethod · 0.80
versionMethod · 0.80
set_errorMethod · 0.80

Tested by

no test coverage detected