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

Function main

runners/KeyManagerRunner.cpp:12–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12int main(int argc, char **argv) {
13 SET_VERBOSITY_LEVEL(verbosity_INFO);
14
15 td::set_default_failure_signal_handler().ensure();
16
17 std::string engine_config_filename = "key-manager-config.json";
18 std::string pseudo_config_filename = "";
19 bool check_hash = false;
20
21 td::OptionParser option_parser;
22 option_parser.set_description("key manager runner: run COCOON key manager");
23 option_parser.add_option('c', "config", "key manager config",
24 [&](td::Slice opt) { engine_config_filename = opt.str(); });
25 option_parser.add_checked_option('v', "verbosity", "set verbosity level", [&](td::Slice opt) -> td::Status {
26 TRY_RESULT(level, td::to_integer_safe<td::int32>(opt));
27 SET_VERBOSITY_LEVEL(level);
28 return td::Status::OK();
29 });
30 option_parser.add_option('C', "disable-ton", "disable ton and use fake ton config",
31 [&](td::Slice opt) { pseudo_config_filename = opt.str(); });
32 option_parser.add_option('p', "check-hashes", "check hashes of requesters", [&]() { check_hash = true; });
33 option_parser.run(argc, argv, 0).ensure();
34
35 td::actor::set_debug(true);
36 td::actor::Scheduler scheduler({7});
37
38 td::actor::ActorOwn<cocoon::KeyManagerRunner> key_manager_runner;
39
40 scheduler.run_in_context([&] {
41 key_manager_runner =
42 td::actor::create_actor<cocoon::KeyManagerRunner>("key-manager", std::move(engine_config_filename), &scheduler);
43 td::actor::send_lambda(key_manager_runner, [&]() {
44 auto &ptr = key_manager_runner.get_actor_unsafe();
45 if (pseudo_config_filename.size() > 0) {
46 ptr.disable_ton(pseudo_config_filename);
47 }
48 if (check_hash) {
49 ptr.enable_check_hashes();
50 }
51 ptr.initialize();
52 });
53 });
54
55 while (scheduler.run(1)) {
56 if (need_stats_flag.exchange(false)) {
57 dump_stats();
58 }
59 if (need_scheduler_status_flag.exchange(false)) {
60 LOG(ERROR) << "DUMPING SCHEDULER STATISTICS";
61 td::StringBuilder sb;
62 scheduler.get_debug().dump(sb);
63 LOG(ERROR) << "GOT SCHEDULER STATISTICS\n" << sb.as_cslice();
64 }
65 if (rotate_logs_flags.exchange(false)) {
66 if (td::log_interface) {
67 td::log_interface->rotate();
68 }
69 }

Callers

nothing calls this directly

Calls 6

disable_tonMethod · 0.80
enable_check_hashesMethod · 0.80
as_csliceMethod · 0.80
dump_statsFunction · 0.70
runMethod · 0.45
initializeMethod · 0.45

Tested by

no test coverage detected