From f064b1047a5671ec5a435462d5639792274fb32e Mon Sep 17 00:00:00 2001 From: ton Date: Mon, 6 Jul 2020 17:07:20 +0300 Subject: [PATCH] pow-testgiver support --- adnl/adnl-pong.cpp | 42 +- adnl/adnl-proxy-types.h | 1 + adnl/adnl-proxy.cpp | 43 +- adnl/adnl-tunnel.h | 27 + adnl/test/adnl-test-ping.cpp | 4 +- blockchain-explorer/blockchain-explorer.cpp | 26 +- catchain/catchain-types.h | 2 +- create-hardfork/create-hardfork.cpp | 53 +- crypto/CMakeLists.txt | 8 + crypto/common/bigint.hpp | 12 + crypto/common/util.h | 1 + crypto/fift/lib/Asm.fif | 12 + crypto/fift/utils.cpp | 1 + crypto/func/asmops.cpp | 3 + crypto/smartcont/new-pow-testgiver.fif | 59 + crypto/smartcont/pow-testgiver-code.fc | 158 ++ crypto/smartcont/wallet-v3.fif | 4 +- crypto/smc-envelope/PaymentChannel.cpp | 19 + crypto/smc-envelope/PaymentChannel.h | 19 + crypto/test/wycheproof.h | 9 +- crypto/tl/tlblib.hpp | 1 + crypto/util/Miner.cpp | 108 + crypto/util/Miner.h | 23 + crypto/util/pow-miner.cpp | 214 ++ crypto/vm/boc.cpp | 5 +- crypto/vm/stack.hpp | 28 +- dht-server/dht-server.cpp | 42 +- dht/test/dht-test-ping.cpp | 4 +- doc/TestGrams-HOWTO | 163 ++ http/http-proxy.cpp | 10 +- http/http.cpp | 2 + lite-client/lite-client.cpp | 51 +- rldp-http-proxy/rldp-http-proxy.cpp | 77 +- rldp2/Ack.cpp | 19 + rldp2/Ack.h | 19 + rldp2/Bbr.cpp | 19 + rldp2/Bbr.h | 19 + rldp2/BdwStats.cpp | 19 + rldp2/BdwStats.h | 19 + rldp2/FecHelper.cpp | 19 + rldp2/FecHelper.h | 19 + rldp2/InboundTransfer.cpp | 19 + rldp2/InboundTransfer.h | 19 + rldp2/LossSender.cpp | 19 + rldp2/LossSender.h | 19 + rldp2/LossStats.cpp | 19 + rldp2/LossStats.h | 19 + rldp2/OutboundTransfer.cpp | 19 + rldp2/OutboundTransfer.h | 19 + rldp2/Pacer.cpp | 19 + rldp2/Pacer.h | 19 + rldp2/RldpConnection.cpp | 19 + rldp2/RldpConnection.h | 19 + rldp2/RldpReceiver.cpp | 19 + rldp2/RldpReceiver.h | 19 + rldp2/RldpSender.cpp | 19 + rldp2/RldpSender.h | 19 + rldp2/RttStats.cpp | 19 + rldp2/RttStats.h | 19 + rldp2/SenderPackets.cpp | 19 + rldp2/SenderPackets.h | 19 + rldp2/rldp-in.hpp | 2 +- rldp2/rldp.cpp | 2 +- rldp2/rldp.hpp | 2 +- storage/Bitset.h | 19 + storage/LoadSpeed.cpp | 19 + storage/LoadSpeed.h | 19 + storage/MerkleTree.cpp | 19 + storage/MerkleTree.h | 19 + storage/NodeActor.cpp | 19 + storage/NodeActor.h | 19 + storage/PartsHelper.h | 19 + storage/PeerActor.cpp | 19 + storage/PeerActor.h | 19 + storage/PeerState.cpp | 19 + storage/PeerState.h | 19 + storage/SharedState.h | 19 + storage/Torrent.cpp | 19 + storage/Torrent.h | 19 + storage/TorrentCreator.cpp | 19 + storage/TorrentCreator.h | 19 + storage/TorrentHeader.cpp | 19 + storage/TorrentHeader.h | 19 + storage/TorrentHeader.hpp | 19 + storage/TorrentInfo.cpp | 19 + storage/TorrentInfo.h | 19 + storage/TorrentMeta.cpp | 19 + storage/TorrentMeta.h | 19 + storage/storage-cli.cpp | 45 +- storage/test/storage.cpp | 19 + tddb/td/db/utils/BlobView.cpp | 2 +- tddb/td/db/utils/BlobView.h | 3 +- tddb/td/db/utils/StreamInterface.h | 1 + tddb/test/io-bench.cpp | 26 +- tdfec/td/fec/fec.h | 1 + tdnet/example/tcp_ping_pong.cpp | 15 +- tdnet/example/udp_ping_pong.cpp | 14 +- tdtl/td/tl/tl_simple.h | 54 +- tdutils/CMakeLists.txt | 32 +- tdutils/generate/mime_types.txt | 1 + tdutils/td/utils/AesCtrByteFlow.h | 2 +- tdutils/td/utils/AtomicRead.h | 30 +- tdutils/td/utils/BigNum.cpp | 20 +- tdutils/td/utils/BigNum.h | 4 - tdutils/td/utils/BufferedFd.h | 6 +- tdutils/td/utils/BufferedUdp.h | 5 +- tdutils/td/utils/ConcurrentHashTable.h | 2 +- tdutils/td/utils/DecTree.h | 6 +- tdutils/td/utils/Enumerator.h | 5 +- .../td/utils/EpochBasedMemoryReclamation.h | 8 +- tdutils/td/utils/FileLog.cpp | 9 +- tdutils/td/utils/FileLog.h | 2 +- tdutils/td/utils/Gzip.cpp | 28 +- tdutils/td/utils/Gzip.h | 12 +- tdutils/td/utils/GzipByteFlow.cpp | 2 +- tdutils/td/utils/HazardPointers.h | 6 +- tdutils/td/utils/Hints.cpp | 2 +- tdutils/td/utils/HttpUrl.cpp | 30 +- tdutils/td/utils/HttpUrl.h | 4 +- tdutils/td/utils/JsonBuilder.cpp | 9 + tdutils/td/utils/JsonBuilder.h | 42 +- tdutils/td/utils/List.h | 43 +- tdutils/td/utils/MemoryLog.h | 20 +- tdutils/td/utils/MovableValue.h | 6 +- tdutils/td/utils/MpscLinkQueue.h | 2 +- tdutils/td/utils/ObjectPool.h | 2 +- tdutils/td/utils/OptionParser.cpp | 231 +++ tdutils/td/utils/OptionParser.h | 72 + tdutils/td/utils/OptionsParser.cpp | 20 +- tdutils/td/utils/Parser.h | 2 +- tdutils/td/utils/PathView.cpp | 70 + tdutils/td/utils/PathView.h | 46 +- tdutils/td/utils/Random.cpp | 35 +- tdutils/td/utils/Random.h | 1 + tdutils/td/utils/ScopeGuard.h | 2 +- tdutils/td/utils/SharedSlice.cpp | 3 +- tdutils/td/utils/SharedSlice.h | 20 +- tdutils/td/utils/Slice-decl.h | 4 +- tdutils/td/utils/Slice.cpp | 8 +- tdutils/td/utils/Span.h | 7 +- tdutils/td/utils/Status.h | 42 +- tdutils/td/utils/StringBuilder.cpp | 22 +- tdutils/td/utils/StringBuilder.h | 6 +- tdutils/td/utils/ThreadLocalStorage.h | 28 +- tdutils/td/utils/ThreadSafeCounter.h | 11 +- tdutils/td/utils/Time.h | 2 +- tdutils/td/utils/Timer.cpp | 1 - tdutils/td/utils/TsFileLog.cpp | 10 +- tdutils/td/utils/TsFileLog.h | 5 +- tdutils/td/utils/TsList.h | 213 ++ tdutils/td/utils/UInt.h | 6 +- tdutils/td/utils/VectorQueue.h | 12 +- tdutils/td/utils/base64.cpp | 337 ++- tdutils/td/utils/base64.h | 8 +- tdutils/td/utils/bits.h | 18 +- tdutils/td/utils/buffer.h | 12 +- tdutils/td/utils/config.h.in | 1 - tdutils/td/utils/crypto.cpp | 431 +++- tdutils/td/utils/crypto.h | 46 + tdutils/td/utils/filesystem.h | 1 + tdutils/td/utils/format.h | 15 +- tdutils/td/utils/logging.cpp | 3 + tdutils/td/utils/misc.cpp | 51 +- tdutils/td/utils/misc.h | 68 +- tdutils/td/utils/port/Clocks.cpp | 42 +- tdutils/td/utils/port/Clocks.h | 17 +- tdutils/td/utils/port/CxCli.h | 11 +- tdutils/td/utils/port/FileFd.cpp | 74 +- tdutils/td/utils/port/FileFd.h | 4 + tdutils/td/utils/port/IPAddress.cpp | 75 +- tdutils/td/utils/port/IPAddress.h | 15 +- tdutils/td/utils/port/ServerSocketFd.cpp | 3 +- tdutils/td/utils/port/SocketFd.cpp | 9 +- tdutils/td/utils/port/Stat.cpp | 95 +- tdutils/td/utils/port/Stat.h | 24 +- tdutils/td/utils/port/StdStreams.cpp | 11 +- tdutils/td/utils/port/UdpSocketFd.cpp | 14 +- tdutils/td/utils/port/UdpSocketFd.h | 4 +- tdutils/td/utils/port/detail/Epoll.cpp | 5 +- tdutils/td/utils/port/detail/EventFdBsd.cpp | 2 + tdutils/td/utils/port/detail/EventFdLinux.cpp | 3 + tdutils/td/utils/port/detail/KQueue.cpp | 1 + tdutils/td/utils/port/detail/NativeFd.cpp | 44 +- tdutils/td/utils/port/detail/NativeFd.h | 15 +- tdutils/td/utils/port/detail/Poll.cpp | 2 + tdutils/td/utils/port/detail/PollableFd.h | 25 - .../td/utils/port/detail/ThreadPthread.cpp | 114 ++ tdutils/td/utils/port/detail/ThreadPthread.h | 48 +- tdutils/td/utils/port/detail/skip_eintr.h | 52 + tdutils/td/utils/port/path.cpp | 9 +- tdutils/td/utils/port/rlimit.cpp | 17 +- tdutils/td/utils/port/rlimit.h | 5 +- tdutils/td/utils/port/signals.cpp | 3 +- tdutils/td/utils/port/stacktrace.cpp | 12 +- tdutils/td/utils/port/stacktrace.h | 2 + tdutils/td/utils/port/uname.cpp | 172 ++ tdutils/td/utils/port/uname.h | 9 + tdutils/td/utils/port/user.cpp | 61 +- tdutils/td/utils/port/user.h | 8 +- tdutils/td/utils/port/wstring_convert.cpp | 5 +- tdutils/td/utils/tests.cpp | 2 +- tdutils/td/utils/tests.h | 7 +- tdutils/td/utils/tl_helpers.h | 32 + tdutils/td/utils/tl_parsers.cpp | 37 +- tdutils/td/utils/tl_parsers.h | 48 +- tdutils/td/utils/tl_storers.h | 32 +- tdutils/td/utils/translit.cpp | 6 +- tdutils/td/utils/unicode.cpp | 1801 +++++++++-------- tdutils/td/utils/utf8.h | 15 + tdutils/test/ConcurrentHashMap.cpp | 15 +- tdutils/test/List.cpp | 179 ++ tdutils/test/OptionParser.cpp | 95 + tdutils/test/SharedSlice.cpp | 44 +- tdutils/test/StealingQueue.cpp | 30 +- tdutils/test/crypto.cpp | 112 +- tdutils/test/filesystem.cpp | 65 +- tdutils/test/gzip.cpp | 54 +- tdutils/test/heap.cpp | 37 +- tdutils/test/json.cpp | 5 +- tdutils/test/log.cpp | 27 +- tdutils/test/misc.cpp | 170 ++ tdutils/test/port.cpp | 74 +- test/test-catchain.cpp | 2 +- test/test-ext-client.cpp | 4 +- test/test-ext-server.cpp | 4 +- test/test-hello-world.cpp | 2 +- test/test-http.cpp | 2 +- test/test-node.cpp | 4 +- test/test-rldp2.cpp | 2 +- test/test-rocksdb.cpp | 10 +- test/test-td-main.cpp | 2 +- test/test-ton-collator.cpp | 75 +- test/test-validator-session.cpp | 4 +- test/test-validator.cpp | 4 +- tl/generate/generate_common.cpp | 6 +- tl/generate/tl_json_converter.cpp | 71 +- tl/generate/tl_json_converter.h | 35 +- tl/generate/tl_writer_cpp.cpp | 2 +- tl/tl/tl_json.h | 40 +- ton/ton-types.h | 4 +- tonlib/test/online.cpp | 13 +- tonlib/tonlib/ClientJson.cpp | 2 +- tonlib/tonlib/keys/SimpleEncryption.cpp | 1 + tonlib/tonlib/tonlib-cli.cpp | 60 +- utils/generate-random-id.cpp | 21 +- utils/json2tlo.cpp | 22 +- utils/pack-viewer.cpp | 2 +- .../validator-engine-console.cpp | 25 +- validator-engine/validator-engine.cpp | 60 +- validator-engine/validator-engine.hpp | 20 +- validator-session/validator-session-types.h | 4 +- validator/full-node-shard.cpp | 8 +- validator/full-node-shard.hpp | 12 +- validator/manager-init.cpp | 2 +- validator/validator-options.cpp | 4 +- validator/validator-options.hpp | 36 +- validator/validator.h | 26 +- 257 files changed, 6581 insertions(+), 2524 deletions(-) create mode 100644 crypto/smartcont/new-pow-testgiver.fif create mode 100644 crypto/smartcont/pow-testgiver-code.fc create mode 100644 crypto/util/Miner.cpp create mode 100644 crypto/util/Miner.h create mode 100644 crypto/util/pow-miner.cpp create mode 100644 doc/TestGrams-HOWTO create mode 100644 tdutils/td/utils/OptionParser.cpp create mode 100644 tdutils/td/utils/OptionParser.h create mode 100644 tdutils/td/utils/PathView.cpp create mode 100644 tdutils/td/utils/TsList.h create mode 100644 tdutils/td/utils/port/detail/ThreadPthread.cpp create mode 100644 tdutils/td/utils/port/detail/skip_eintr.h create mode 100644 tdutils/td/utils/port/uname.cpp create mode 100644 tdutils/td/utils/port/uname.h create mode 100644 tdutils/test/List.cpp create mode 100644 tdutils/test/OptionParser.cpp diff --git a/adnl/adnl-pong.cpp b/adnl/adnl-pong.cpp index 9594019b3..e04e82ba6 100644 --- a/adnl/adnl-pong.cpp +++ b/adnl/adnl-pong.cpp @@ -30,7 +30,7 @@ #include "td/utils/port/IPAddress.h" #include "td/net/UdpServer.h" #include "td/utils/port/signals.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/FileLog.h" #include "td/utils/port/path.h" #include "td/utils/port/user.h" @@ -91,12 +91,11 @@ int main(int argc, char *argv[]) { std::string config = "/var/ton-work/etc/adnl-proxy.conf.json"; - td::OptionsParser p; + td::OptionParser p; p.set_description("adnl pinger"); p.add_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { int v = VERBOSITY_NAME(FATAL) + (td::to_integer(arg)); SET_VERBOSITY_LEVEL(v); - return td::Status::OK(); }); p.add_option('h', "help", "prints_help", [&]() { char b[10240]; @@ -104,7 +103,6 @@ int main(int argc, char *argv[]) { sb << p; std::cout << sb.as_cslice().c_str(); std::exit(2); - return td::Status::OK(); }); p.add_option('d', "daemonize", "set SIGHUP", [&]() { #if TD_DARWIN || TD_LINUX @@ -112,9 +110,8 @@ int main(int argc, char *argv[]) { setsid(); #endif td::set_signal_handler(td::SignalType::HangUp, force_rotate_logs).ensure(); - return td::Status::OK(); }); - p.add_option('l', "logname", "log to file", [&](td::Slice fname) { + p.add_checked_option('l', "logname", "log to file", [&](td::Slice fname) { auto F = std::make_unique(); TRY_STATUS(F->init(fname.str(), std::numeric_limits::max(), true)); logger_ = std::move(F); @@ -122,25 +119,26 @@ int main(int argc, char *argv[]) { return td::Status::OK(); }); td::uint32 threads = 7; - p.add_option('t', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice fname) { - td::int32 v; - try { - v = std::stoi(fname.str()); - } catch (...) { - return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: not a number"); - } - if (v < 1 || v > 256) { - return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be in range [1..256]"); - } - threads = v; - return td::Status::OK(); - }); - p.add_option('u', "user", "change user", [&](td::Slice user) { return td::change_user(user); }); - p.add_option('k', "key", "private key", [&](td::Slice key) { + p.add_checked_option( + 't', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice fname) { + td::int32 v; + try { + v = std::stoi(fname.str()); + } catch (...) { + return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: not a number"); + } + if (v < 1 || v > 256) { + return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be in range [1..256]"); + } + threads = v; + return td::Status::OK(); + }); + p.add_checked_option('u', "user", "change user", [&](td::Slice user) { return td::change_user(user.str()); }); + p.add_checked_option('k', "key", "private key", [&](td::Slice key) { TRY_RESULT_ASSIGN(pk, ton::PrivateKey::import(key)); return td::Status::OK(); }); - p.add_option('a', "addr", "ip:port of instance", [&](td::Slice key) { + p.add_checked_option('a', "addr", "ip:port of instance", [&](td::Slice key) { TRY_STATUS(addr.init_host_port(key.str())); return td::Status::OK(); }); diff --git a/adnl/adnl-proxy-types.h b/adnl/adnl-proxy-types.h index 133704c63..f18d2dc04 100644 --- a/adnl/adnl-proxy-types.h +++ b/adnl/adnl-proxy-types.h @@ -19,6 +19,7 @@ #pragma once #include "td/utils/buffer.h" +#include "td/utils/Status.h" #include "auto/tl/ton_api.h" namespace ton { diff --git a/adnl/adnl-proxy.cpp b/adnl/adnl-proxy.cpp index cc264a734..93f33e401 100644 --- a/adnl/adnl-proxy.cpp +++ b/adnl/adnl-proxy.cpp @@ -30,7 +30,7 @@ #include "td/utils/port/IPAddress.h" #include "td/net/UdpServer.h" #include "td/utils/port/signals.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/FileLog.h" #include "td/utils/port/path.h" #include "td/utils/port/user.h" @@ -297,12 +297,11 @@ int main(int argc, char *argv[]) { std::string config = "/var/ton-work/etc/adnl-proxy.conf.json"; - td::OptionsParser p; + td::OptionParser p; p.set_description("validator or full node for TON network"); p.add_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { int v = VERBOSITY_NAME(FATAL) + (td::to_integer(arg)); SET_VERBOSITY_LEVEL(v); - return td::Status::OK(); }); p.add_option('h', "help", "prints_help", [&]() { char b[10240]; @@ -310,21 +309,16 @@ int main(int argc, char *argv[]) { sb << p; std::cout << sb.as_cslice().c_str(); std::exit(2); - return td::Status::OK(); - }); - p.add_option('c', "config", "config file", [&](td::Slice arg) { - config = arg.str(); - return td::Status::OK(); }); + p.add_option('c', "config", "config file", [&](td::Slice arg) { config = arg.str(); }); p.add_option('d', "daemonize", "set SIGHUP", [&]() { #if TD_DARWIN || TD_LINUX close(0); setsid(); #endif td::set_signal_handler(td::SignalType::HangUp, force_rotate_logs).ensure(); - return td::Status::OK(); }); - p.add_option('l', "logname", "log to file", [&](td::Slice fname) { + p.add_checked_option('l', "logname", "log to file", [&](td::Slice fname) { auto F = std::make_unique(); TRY_STATUS(F->init(fname.str(), std::numeric_limits::max(), true)); logger_ = std::move(F); @@ -332,20 +326,21 @@ int main(int argc, char *argv[]) { return td::Status::OK(); }); td::uint32 threads = 7; - p.add_option('t', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice fname) { - td::int32 v; - try { - v = std::stoi(fname.str()); - } catch (...) { - return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: not a number"); - } - if (v < 1 || v > 256) { - return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be in range [1..256]"); - } - threads = v; - return td::Status::OK(); - }); - p.add_option('u', "user", "change user", [&](td::Slice user) { return td::change_user(user); }); + p.add_checked_option( + 't', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice fname) { + td::int32 v; + try { + v = std::stoi(fname.str()); + } catch (...) { + return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: not a number"); + } + if (v < 1 || v > 256) { + return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be in range [1..256]"); + } + threads = v; + return td::Status::OK(); + }); + p.add_checked_option('u', "user", "change user", [&](td::Slice user) { return td::change_user(user.str()); }); p.run(argc, argv).ensure(); diff --git a/adnl/adnl-tunnel.h b/adnl/adnl-tunnel.h index c92839ab8..9d54dcc9e 100644 --- a/adnl/adnl-tunnel.h +++ b/adnl/adnl-tunnel.h @@ -1,3 +1,30 @@ +/* + This file is part of TON Blockchain source code. + + TON Blockchain is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + TON Blockchain is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with TON Blockchain. If not, see . + + In addition, as a special exception, the copyright holders give permission + to link the code of portions of this program with the OpenSSL library. + You must obey the GNU General Public License in all respects for all + of the code used other than OpenSSL. If you modify file(s) with this + exception, you may extend this exception to your version of the file(s), + but you are not obligated to do so. If you do not wish to do so, delete this + exception statement from your version. If you delete this exception statement + from all source files in the program, then also delete it here. + + Copyright 2017-2020 Telegram Systems LLP +*/ #pragma once #include "adnl.h" diff --git a/adnl/test/adnl-test-ping.cpp b/adnl/test/adnl-test-ping.cpp index 0e1f2ebc8..289aa043f 100644 --- a/adnl/test/adnl-test-ping.cpp +++ b/adnl/test/adnl-test-ping.cpp @@ -31,7 +31,7 @@ #include "keys/encryptor.h" #include "td/utils/Time.h" #include "td/utils/format.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include #include @@ -168,7 +168,7 @@ td::Result get_uint256(std::string str) { int main(int argc, char *argv[]) { td::actor::ActorOwn x; - td::OptionsParser p; + td::OptionParser p; p.set_description("test basic adnl functionality"); p.add_option('h', "help", "prints_help", [&]() { char b[10240]; diff --git a/blockchain-explorer/blockchain-explorer.cpp b/blockchain-explorer/blockchain-explorer.cpp index 47ce7378b..4c0122a86 100644 --- a/blockchain-explorer/blockchain-explorer.cpp +++ b/blockchain-explorer/blockchain-explorer.cpp @@ -28,7 +28,7 @@ #include "adnl/adnl-ext-client.h" #include "adnl/utils.hpp" #include "auto/tl/ton_api_json.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/Time.h" #include "td/utils/filesystem.h" #include "td/utils/format.h" @@ -591,9 +591,9 @@ int main(int argc, char* argv[]) { td::actor::ActorOwn x; - td::OptionsParser p; + td::OptionParser p; p.set_description("TON Blockchain explorer"); - p.add_option('h', "help", "prints_help", [&]() { + p.add_checked_option('h', "help", "prints_help", [&]() { char b[10240]; td::StringBuilder sb(td::MutableSlice{b, 10000}); sb << p; @@ -601,31 +601,31 @@ int main(int argc, char* argv[]) { std::exit(2); return td::Status::OK(); }); - p.add_option('I', "hide-ips", "hides ips from status", [&]() { + p.add_checked_option('I', "hide-ips", "hides ips from status", [&]() { td::actor::send_closure(x, &CoreActor::set_hide_ips, true); return td::Status::OK(); }); - p.add_option('u', "user", "change user", [&](td::Slice user) { return td::change_user(user); }); - p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) { + p.add_checked_option('u', "user", "change user", [&](td::Slice user) { return td::change_user(user.str()); }); + p.add_checked_option('C', "global-config", "file to read global config", [&](td::Slice fname) { td::actor::send_closure(x, &CoreActor::set_global_config, fname.str()); return td::Status::OK(); }); - p.add_option('a', "addr", "connect to ip:port", [&](td::Slice arg) { + p.add_checked_option('a', "addr", "connect to ip:port", [&](td::Slice arg) { td::IPAddress addr; TRY_STATUS(addr.init_host_port(arg.str())); td::actor::send_closure(x, &CoreActor::set_remote_addr, addr); return td::Status::OK(); }); - p.add_option('p', "pub", "remote public key", [&](td::Slice arg) { + p.add_checked_option('p', "pub", "remote public key", [&](td::Slice arg) { td::actor::send_closure(x, &CoreActor::set_remote_public_key, td::BufferSlice{arg}); return td::Status::OK(); }); - p.add_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { + p.add_checked_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { verbosity = td::to_integer(arg); SET_VERBOSITY_LEVEL(VERBOSITY_NAME(FATAL) + verbosity); return (verbosity >= 0 && verbosity <= 9) ? td::Status::OK() : td::Status::Error("verbosity must be 0..9"); }); - p.add_option('d', "daemonize", "set SIGHUP", [&]() { + p.add_checked_option('d', "daemonize", "set SIGHUP", [&]() { td::set_signal_handler(td::SignalType::HangUp, [](int sig) { #if TD_DARWIN || TD_LINUX close(0); @@ -634,16 +634,16 @@ int main(int argc, char* argv[]) { }).ensure(); return td::Status::OK(); }); - p.add_option('H', "http-port", "listen on http port", [&](td::Slice arg) { + p.add_checked_option('H', "http-port", "listen on http port", [&](td::Slice arg) { td::actor::send_closure(x, &CoreActor::set_http_port, td::to_integer(arg)); return td::Status::OK(); }); - p.add_option('L', "local-scripts", "use local copy of ajax/bootstrap/... JS", [&]() { + p.add_checked_option('L', "local-scripts", "use local copy of ajax/bootstrap/... JS", [&]() { local_scripts = true; return td::Status::OK(); }); #if TD_DARWIN || TD_LINUX - p.add_option('l', "logname", "log to file", [&](td::Slice fname) { + p.add_checked_option('l', "logname", "log to file", [&](td::Slice fname) { auto FileLog = td::FileFd::open(td::CSlice(fname.str().c_str()), td::FileFd::Flags::Create | td::FileFd::Flags::Append | td::FileFd::Flags::Write) .move_as_ok(); diff --git a/catchain/catchain-types.h b/catchain/catchain-types.h index cb95135e3..414e59464 100644 --- a/catchain/catchain-types.h +++ b/catchain/catchain-types.h @@ -36,7 +36,7 @@ struct CatChainNode { }; struct CatChainOptions { - td::Clocks::Duration idle_timeout = 16.0; + double idle_timeout = 16.0; td::uint32 max_deps = 4; bool debug_disable_db = false; diff --git a/create-hardfork/create-hardfork.cpp b/create-hardfork/create-hardfork.cpp index 1a6b7a8ac..5c38ac025 100644 --- a/create-hardfork/create-hardfork.cpp +++ b/create-hardfork/create-hardfork.cpp @@ -30,7 +30,7 @@ #include "auto/tl/ton_api_json.h" #include "dht/dht.h" #include "overlay/overlays.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/Time.h" #include "td/utils/filesystem.h" #include "td/utils/format.h" @@ -254,7 +254,7 @@ int main(int argc, char *argv[]) { td::actor::ActorOwn x; - td::OptionsParser p; + td::OptionParser p; p.set_description("test collate block"); p.add_option('h', "help", "prints_help", [&]() { char b[10240]; @@ -262,27 +262,19 @@ int main(int argc, char *argv[]) { sb << p; std::cout << sb.as_cslice().c_str(); std::exit(2); - return td::Status::OK(); - }); - p.add_option('D', "db", "root for dbs", [&](td::Slice fname) { - td::actor::send_closure(x, &HardforkCreator::set_db_root, fname.str()); - return td::Status::OK(); }); - p.add_option('m', "ext-message", "binary file with serialized inbound external message", [&](td::Slice fname) { - td::actor::send_closure(x, &HardforkCreator::load_ext_message, fname.str()); - return td::Status::OK(); - }); - p.add_option('M', "top-shard-message", "binary file with serialized shard top block description", - [&](td::Slice fname) { - td::actor::send_closure(x, &HardforkCreator::load_shard_block_message, fname.str()); - return td::Status::OK(); - }); + p.add_option('D', "db", "root for dbs", + [&](td::Slice fname) { td::actor::send_closure(x, &HardforkCreator::set_db_root, fname.str()); }); + p.add_option('m', "ext-message", "binary file with serialized inbound external message", + [&](td::Slice fname) { td::actor::send_closure(x, &HardforkCreator::load_ext_message, fname.str()); }); + p.add_option( + 'M', "top-shard-message", "binary file with serialized shard top block description", + [&](td::Slice fname) { td::actor::send_closure(x, &HardforkCreator::load_shard_block_message, fname.str()); }); p.add_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { int v = VERBOSITY_NAME(FATAL) + (verbosity = td::to_integer(arg)); SET_VERBOSITY_LEVEL(v); - return td::Status::OK(); }); - p.add_option('w', "workchain", "[:]\tcollate block in this workchain", [&](td::Slice arg) { + p.add_checked_option('w', "workchain", "[:]\tcollate block in this workchain", [&](td::Slice arg) { ton::ShardId shard = 0; auto pos = std::min(arg.find(':'), arg.size()); TRY_RESULT(workchain, td::to_integer_safe(arg.substr(0, pos))); @@ -299,18 +291,18 @@ int main(int argc, char *argv[]) { ton::ShardIdFull{workchain, shard ? shard : ton::shardIdAll}); return td::Status::OK(); }); - p.add_option('T', "top-block", "BlockIdExt of top block (new block will be generated atop of it)", - [&](td::Slice arg) { - ton::BlockIdExt block_id; - if (block::parse_block_id_ext(arg, block_id)) { - LOG(INFO) << "setting previous block to " << block_id.to_str(); - td::actor::send_closure(x, &HardforkCreator::set_shard_top_block, block_id); - - return td::Status::OK(); - } else { - return td::Status::Error("cannot parse BlockIdExt"); - } - }); + p.add_checked_option('T', "top-block", "BlockIdExt of top block (new block will be generated atop of it)", + [&](td::Slice arg) { + ton::BlockIdExt block_id; + if (block::parse_block_id_ext(arg, block_id)) { + LOG(INFO) << "setting previous block to " << block_id.to_str(); + td::actor::send_closure(x, &HardforkCreator::set_shard_top_block, block_id); + + return td::Status::OK(); + } else { + return td::Status::Error("cannot parse BlockIdExt"); + } + }); p.add_option('d', "daemonize", "set SIGHUP", [&]() { td::set_signal_handler(td::SignalType::HangUp, [](int sig) { #if TD_DARWIN || TD_LINUX @@ -318,7 +310,6 @@ int main(int argc, char *argv[]) { setsid(); #endif }).ensure(); - return td::Status::OK(); }); td::actor::Scheduler scheduler({7}); diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index a9a30cbda..0ea0e1ac6 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -259,6 +259,7 @@ set(FIFT_TEST_SOURCE PARENT_SCOPE ) + add_library(ton_crypto STATIC ${TON_CRYPTO_SOURCE}) target_include_directories(ton_crypto PUBLIC $ $) @@ -306,6 +307,12 @@ if (WINGETOPT_FOUND) target_link_libraries_system(tlbc wingetopt) endif() +add_executable(pow-miner util/pow-miner.cpp util/Miner.cpp util/Miner.h) +target_link_libraries(pow-miner PUBLIC ton_crypto ton_block) +if (WINGETOPT_FOUND) + target_link_libraries_system(fift wingetopt) +endif() + add_library(ton_block ${BLOCK_SOURCE}) target_include_directories(ton_block PUBLIC $ $ $) @@ -371,6 +378,7 @@ if (NOT CMAKE_CROSSCOMPILING) GenFif(DEST smartcont/auto/restricted-wallet-code SOURCE smartcont/restricted-wallet-code.fc NAME restricted-wallet) GenFif(DEST smartcont/auto/restricted-wallet2-code SOURCE smartcont/restricted-wallet2-code.fc NAME restricted-wallet2) GenFif(DEST smartcont/auto/restricted-wallet3-code SOURCE smartcont/restricted-wallet3-code.fc NAME restricted-wallet3) + GenFif(DEST smartcont/auto/pow-testgiver-code SOURCE smartcont/pow-testgiver-code.fc NAME pow-testgiver) GenFif(DEST smartcont/auto/dns-manual-code SOURCE smartcont/dns-manual-code.fc NAME dns-manual) GenFif(DEST smartcont/auto/dns-auto-code SOURCE smartcont/dns-auto-code.fc NAME dns-auto) diff --git a/crypto/common/bigint.hpp b/crypto/common/bigint.hpp index cde80ce2b..07ccc7d17 100644 --- a/crypto/common/bigint.hpp +++ b/crypto/common/bigint.hpp @@ -267,6 +267,9 @@ class AnyIntView { return size() > 1 ? (double)digits[size() - 1] + (double)digits[size() - 2] * (1.0 / Tr::Base) : (double)digits[size() - 1]; } + bool is_odd_any() const { + return size() > 0 && (digits[0] & 1); + } word_t to_long_any() const; int parse_hex_any(const char* str, int str_len, int* frac = nullptr); int parse_binary_any(const char* str, int str_len, int* frac = nullptr); @@ -658,6 +661,15 @@ class BigIntG { word_t to_long() const { return as_any_int().to_long_any(); } + bool is_odd() const { + return n > 0 && (digits[0] & 1); + } + bool is_even() const { + return n > 0 && !(digits[0] & 1); + } + word_t mod_pow2_short(int pow) const { + return n > 0 ? digits[0] & ((1 << pow) - 1) : 0; + } private: word_t top_word() const { diff --git a/crypto/common/util.h b/crypto/common/util.h index e6b8ec2eb..c56677b6a 100644 --- a/crypto/common/util.h +++ b/crypto/common/util.h @@ -19,6 +19,7 @@ #pragma once #include #include "td/utils/Slice.h" +#include "td/utils/Status.h" #include "td/utils/buffer.h" #include "bitstring.h" diff --git a/crypto/fift/lib/Asm.fif b/crypto/fift/lib/Asm.fif index a2d22af24..d61923c12 100644 --- a/crypto/fift/lib/Asm.fif +++ b/crypto/fift/lib/Asm.fif @@ -399,6 +399,18 @@ x{B7B5} @Defop(8u+1) QUFITS x{B7B600} @Defop QFITSX x{B7B601} @Defop QUFITSX +// advanced integer constants +{ 0 { over 1 and 0= } { 1+ swap 2/ swap } while } : pow2decomp +{ dup 8 fits { PUSHINT } { + dup pow2decomp over 1 = { nip nip PUSHPOW2 } { + over -1 = { nip nip PUSHNEGPOW2 } { + dup 20 >= { rot drop -rot PUSHINT swap LSHIFT# } { + { drop PUSHINT } { + not pow2decomp swap -1 = { nip PUSHPOW2DEC } { + drop PUSHINT + } cond } cond } cond } cond } cond } cond +} dup : PUSHINTX : INTX + // integer comparison x{B8} @Defop SGN x{B9} @Defop LESS diff --git a/crypto/fift/utils.cpp b/crypto/fift/utils.cpp index b6c61c6d6..b8c5c61f1 100644 --- a/crypto/fift/utils.cpp +++ b/crypto/fift/utils.cpp @@ -20,6 +20,7 @@ #include "words.h" #include "td/utils/PathView.h" #include "td/utils/filesystem.h" +#include "td/utils/misc.h" #include "td/utils/port/path.h" namespace fift { diff --git a/crypto/func/asmops.cpp b/crypto/func/asmops.cpp index cb0fff1be..f0df9f3d7 100644 --- a/crypto/func/asmops.cpp +++ b/crypto/func/asmops.cpp @@ -183,6 +183,9 @@ AsmOp AsmOp::IntConst(td::RefInt256 x) { if (k >= 0) { return AsmOp::Const(k, "PUSHNEGPOW2"); } + if (!x->mod_pow2_short(23)) { + return AsmOp::Const(dec_string(std::move(x)) + " PUSHINTX"); + } return AsmOp::Const(dec_string(std::move(x)) + " PUSHINT"); } diff --git a/crypto/smartcont/new-pow-testgiver.fif b/crypto/smartcont/new-pow-testgiver.fif new file mode 100644 index 000000000..676f1f033 --- /dev/null +++ b/crypto/smartcont/new-pow-testgiver.fif @@ -0,0 +1,59 @@ +#!/usr/bin/fift -s +"TonUtil.fif" include +"Asm.fif" include + +{ ."usage: " $0 type ." []" cr + ."Creates a new proof-of-work testgiver with unique 32-bit identifier designed to deliver every seconds, with SHA256 hash complexity between 2** and 2**, with private key saved to or loaded from .pk" cr + ."('pow-giver.pk' by default)" cr 1 halt +} : usage +$# 7 - -2 and ' usage if + +8 :$1..n +$1 parse-workchain-id =: wc // set workchain id from command line argument +$2 parse-int dup =: subwallet-id + 0= abort"giver-id must be non-zero" +$3 $>GR =: amount +$4 parse-int dup =: interval + dup 24 ufits and 0= abort"invalid interval" +$5 parse-int dup =: min-cpl + 1- 8 ufits not abort"invalid minimal log-complexity (must be 1..256)" +$6 parse-int dup =: init-cpl + 1- 8 ufits not abort"invalid initial log-complexity (must be 1..256)" +$7 parse-int dup =: max-cpl + 1- 8 ufits not abort"invalid maximal log-complexity (must be 1..256)" +$8 "pow-giver" replace-if-null =: file-base + +min-cpl init-cpl > abort"initial complexity cannot be below minimal complexity" +max-cpl init-cpl < abort"initial complexity cannot exceed maximal complexity" +subwallet-id (.) 1 ' $+ does : +subwallet + +."Creating new proof-of-work testgiver in workchain " wc . +."with unique giver id " subwallet-id . cr +."Designed to give " amount .GR ."approximately every " interval . ."seconds" cr +."Complexity (in SHA256 hashes): min=" min-cpl 1<< . ."init=" init-cpl 1<< . ."max=" max-cpl 1<< . cr + +"auto/pow-testgiver-code.fif" include // code +{ 256 swap - 8 u, } : cpl, + ref, +b> // data +null // no libraries + // create StateInit +dup ."StateInit: " +dup ."signing message: " +dup ."External message for initialization is " B dup Bx. cr +file-base +subwallet +"-query.boc" tuck B>file +."(Saved proof-of-work testgiver creating query to file " type .")" cr diff --git a/crypto/smartcont/pow-testgiver-code.fc b/crypto/smartcont/pow-testgiver-code.fc new file mode 100644 index 000000000..6361a4613 --- /dev/null +++ b/crypto/smartcont/pow-testgiver-code.fc @@ -0,0 +1,158 @@ +;; Advanced TestGiver smart contract with Proof-of-Work verification + +int ufits(int x, int bits) impure asm "UFITSX"; + +() recv_internal(slice in_msg) impure { + ;; do nothing for internal messages +} + +() check_proof_of_work(slice cs) impure inline_ref { + var hash = slice_hash(cs); + var ds = get_data().begin_parse(); + var (stored_seqno_sw, public_key, seed, pow_complexity) = (ds~load_uint(64), ds~load_uint(256), ds~load_uint(128), ds~load_uint(256)); + throw_unless(24, hash < pow_complexity); ;; hash problem NOT solved + var (op, flags, expire, whom, rdata1, rseed, rdata2) = (cs~load_uint(32), cs~load_int(8), cs~load_uint(32), cs~load_uint(256), cs~load_uint(256), cs~load_uint(128), cs~load_uint(256)); + cs.end_parse(); + ufits(expire - now(), 10); + throw_unless(25, (rseed == seed) & (rdata1 == rdata2)); + ;; Proof of Work correct + accept_message(); + randomize_lt(); + randomize(rdata1); + var (last_success, xdata) = (ds~load_uint(32), ds~load_ref()); + ds.end_parse(); + ds = xdata.begin_parse(); + var (amount, target_delta, min_cpl, max_cpl) = (ds~load_grams(), ds~load_uint(32), ds~load_uint(8), ds~load_uint(8)); + ds.end_parse(); + ;; recompute complexity + int delta = now() - last_success; + if (delta > 0) { + int factor = muldivr(delta, 1 << 128, target_delta); + factor = min(max(factor, 7 << 125), 9 << 125); ;; factor must be in range 7/8 .. 9/8 + pow_complexity = muldivr(pow_complexity, factor, 1 << 128); ;; rescale complexity + pow_complexity = min(max(pow_complexity, 1 << min_cpl), 1 << max_cpl); + } + ;; update data + set_data(begin_cell() + .store_uint(stored_seqno_sw, 64) + .store_uint(public_key, 256) + .store_uint(random() >> 128, 128) ;; new seed + .store_uint(pow_complexity, 256) + .store_uint(now(), 32) ;; new last_success + .store_ref(xdata) + .end_cell()); + commit(); + ;; create outbound message + send_raw_message(begin_cell() + .store_uint(((flags & 1) << 6) | 0x84, 9) + .store_int(flags >> 2, 8) + .store_uint(whom, 256) + .store_grams(amount) + .store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1) + .end_cell(), 3); +} + +() rescale_complexity(slice cs) impure inline_ref { + var (op, expire) = (cs~load_uint(32), cs~load_uint(32)); + cs.end_parse(); + int time = now(); + throw_unless(28, time > expire); + var ds = get_data().begin_parse(); + var (skipped_data, pow_complexity, last_success, xdata) = (ds~load_bits(64 + 256 + 128), ds~load_uint(256), ds~load_uint(32), ds~load_ref()); + ds.end_parse(); + throw_unless(29, expire > last_success); + ds = xdata.begin_parse(); + var (amount, target_delta) = (ds~load_grams(), ds~load_uint(32)); + int delta = time - last_success; + throw_unless(30, delta >= target_delta * 16); + accept_message(); + var (min_cpl, max_cpl) = (ds~load_uint(8), ds~load_uint(8)); + ds.end_parse(); + int factor = muldivr(delta, 1 << 128, target_delta); + int max_complexity = (1 << max_cpl); + int max_factor = muldiv(max_complexity, 1 << 128, pow_complexity); + pow_complexity = (max_factor < factor ? max_complexity : muldivr(pow_complexity, factor, 1 << 128)); + last_success = time - target_delta; + set_data(begin_cell() + .store_slice(skipped_data) + .store_uint(pow_complexity, 256) + .store_uint(last_success, 32) ;; new last_success + .store_ref(xdata) + .end_cell()); +} + +(slice, ()) ~update_params(slice ds, cell pref) inline_ref { + var cs = pref.begin_parse(); + var reset_cpl = cs~load_uint(8); + var (seed, pow_complexity, last_success) = (ds~load_uint(128), ds~load_uint(256), ds~load_uint(32)); + if (reset_cpl) { + randomize(seed); + pow_complexity = (1 << reset_cpl); + seed = (random() >> 128); + } + var c = begin_cell() + .store_uint(seed, 128) + .store_uint(pow_complexity, 256) + .store_uint(now(), 32) + .store_ref(begin_cell().store_slice(cs).end_cell()) + .end_cell(); + return (begin_parse(c), ()); +} + +() recv_external(slice in_msg) impure { + var op = in_msg.preload_uint(32); + if (op == 0x4d696e65) { + ;; Mine = Obtain test grams by presenting valid proof of work + return check_proof_of_work(in_msg); + } + if (op == 0x5253636c) { + ;; RScl = Rescale complexity if no success for long time + return rescale_complexity(in_msg); + } + var signature = in_msg~load_bits(512); + var cs = in_msg; + var (subwallet_id, valid_until, msg_seqno) = (cs~load_uint(32), cs~load_uint(32), cs~load_uint(32)); + throw_if(35, valid_until <= now()); + var ds = get_data().begin_parse(); + var (stored_seqno, stored_subwallet, public_key) = (ds~load_uint(32), ds~load_uint(32), ds~load_uint(256)); + throw_unless(33, msg_seqno == stored_seqno); + throw_unless(34, (subwallet_id == stored_subwallet) | (subwallet_id == 0)); + throw_unless(35, check_signature(slice_hash(in_msg), signature, public_key)); + accept_message(); + cs~touch(); + while (cs.slice_refs()) { + var ref = cs~load_ref(); + var mode = cs~load_uint(8); + if (mode < 0xff) { + send_raw_message(ref, mode); + } else { + ds~update_params(ref); + } + } + set_data(begin_cell() + .store_uint(stored_seqno + 1, 32) + .store_uint(stored_subwallet, 32) + .store_uint(public_key, 256) + .store_slice(ds) + .end_cell()); +} + +;; Get methods + +int seqno() method_id { + return get_data().begin_parse().preload_uint(32); +} + +;; gets (seed, pow_complexity, amount, interval) +(int, int, int, int) get_pow_params() method_id { + var ds = get_data().begin_parse().skip_bits(32 + 32 + 256); + var (seed, pow_complexity, xdata) = (ds~load_uint(128), ds~load_uint(256), ds.preload_ref()); + ds = xdata.begin_parse(); + return (seed, pow_complexity, ds~load_grams(), ds.preload_uint(32)); +} + +int get_public_key() method_id { + var ds = get_data().begin_parse(); + ds~load_uint(32 + 32); + return ds.preload_uint(256); +} diff --git a/crypto/smartcont/wallet-v3.fif b/crypto/smartcont/wallet-v3.fif index a81ffb054..c090dc095 100644 --- a/crypto/smartcont/wallet-v3.fif +++ b/crypto/smartcont/wallet-v3.fif @@ -46,8 +46,10 @@ $3 parse-int =: subwallet_id $4 parse-int =: seqno $5 $>cc extra-cc+! extra-currencies @ 2=: amount $6 "wallet-query" replace-if-null =: savefile +subwallet_id (.) 1 ' $+ does : +subwallet -file-base +".addr" load-address +file-base +subwallet +".addr" dup file-exists? { drop file-base +".addr" } ifnot +load-address 2dup 2constant wallet_addr ."Source wallet address = " 2dup .addr cr 6 .Addr cr file-base +".pk" load-keypair nip constant wallet_pk diff --git a/crypto/smc-envelope/PaymentChannel.cpp b/crypto/smc-envelope/PaymentChannel.cpp index e70e23c1a..ff54996c5 100644 --- a/crypto/smc-envelope/PaymentChannel.cpp +++ b/crypto/smc-envelope/PaymentChannel.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "PaymentChannel.h" #include "GenericAccount.h" #include "vm/cells.h" diff --git a/crypto/smc-envelope/PaymentChannel.h b/crypto/smc-envelope/PaymentChannel.h index db6b159e9..0cd0220d5 100644 --- a/crypto/smc-envelope/PaymentChannel.h +++ b/crypto/smc-envelope/PaymentChannel.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "vm/cells.h" #include "vm/cellslice.h" diff --git a/crypto/test/wycheproof.h b/crypto/test/wycheproof.h index 182760acb..124108d78 100644 --- a/crypto/test/wycheproof.h +++ b/crypto/test/wycheproof.h @@ -288,7 +288,8 @@ std::string wycheproof_ed25519() { "sig" : "7c38e026f29e14aabd059a0f2db8b0cd783040609a8be684db12f82a27774ab07a9155711ecfaf7f99f277bad0c6ae7e39d4eef676573336a5c51eb6f946b30d2020", "result" : "invalid", "flags" : [] - },)abcd" R"abcd( + },)abcd" + R"abcd( { "tcId" : 34, "comment" : "include pk in signature", @@ -570,7 +571,8 @@ std::string wycheproof_ed25519() { "flags" : [ "SignatureMalleability" ] - },)abcd" R"abcd( + },)abcd" + R"abcd( { "tcId" : 68, "comment" : "checking malleability ", @@ -858,7 +860,8 @@ std::string wycheproof_ed25519() { "flags" : [] } ] - },)abcd" R"abcd( + },)abcd" + R"abcd( { "key" : { "curve" : "edwards25519", diff --git a/crypto/tl/tlblib.hpp b/crypto/tl/tlblib.hpp index b3260a74b..a6350ece3 100644 --- a/crypto/tl/tlblib.hpp +++ b/crypto/tl/tlblib.hpp @@ -20,6 +20,7 @@ #include #include #include "vm/cellslice.h" +#include namespace tlb { diff --git a/crypto/util/Miner.cpp b/crypto/util/Miner.cpp new file mode 100644 index 000000000..90bc8613a --- /dev/null +++ b/crypto/util/Miner.cpp @@ -0,0 +1,108 @@ +#include "Miner.h" + +#include "td/utils/Random.h" +#include "td/utils/misc.h" +#include "td/utils/crypto.h" +#include "td/utils/port/Clocks.h" +#include + +namespace ton { +#pragma pack(push, 1) +struct HData { + unsigned char op[4]; + signed char flags = -4; + unsigned char expire[4] = {}, myaddr[32] = {}, rdata1[32] = {}, pseed[16] = {}, rdata2[32] = {}; + void inc() { + for (long i = 31; !(rdata1[i] = ++(rdata2[i])); --i) { + } + } + void set_expire(unsigned x) { + for (int i = 3; i >= 0; --i) { + expire[i] = (x & 0xff); + x >>= 8; + } + } + + td::Slice as_slice() const { + return td::Slice(reinterpret_cast(this), sizeof(*this)); + } +}; + +struct HDataEnv { + unsigned char d1 = 0, d2 = sizeof(HData) * 2; + HData body; + + td::Slice as_slice() const { + return td::Slice(reinterpret_cast(this), sizeof(*this)); + } + + void init(const block::StdAddress& my_address, td::Slice seed) { + std::memcpy(body.myaddr, my_address.addr.data(), sizeof(body.myaddr)); + body.flags = static_cast(my_address.workchain * 4 + my_address.bounceable); + CHECK(seed.size() == 16); + std::memcpy(body.pseed, seed.data(), 16); + std::memcpy(body.op, "Mine", 4); + + td::Random::secure_bytes(body.rdata1, 32); + std::memcpy(body.rdata2, body.rdata1, 32); + } +}; + +static_assert(std::is_trivially_copyable::value, "HDataEnv must be a trivial type"); +#pragma pack(pop) + +td::optional Miner::run(const Options& options) { + HDataEnv H; + H.init(options.my_address, td::Slice(options.seed.data(), options.seed.size())); + + td::Slice data = H.as_slice(); + CHECK(data.size() == 123); + + constexpr size_t prefix_size = 72; + constexpr size_t guard_pos = prefix_size - (72 - 28); + CHECK(0 <= guard_pos && guard_pos < 32); + size_t got_prefix_size = (const unsigned char*)H.body.rdata1 + guard_pos + 1 - (const unsigned char*)&H; + CHECK(prefix_size == got_prefix_size); + + auto head = data.substr(0, prefix_size); + auto tail = data.substr(prefix_size); + + SHA256_CTX shactx1, shactx2; + std::array hash; + SHA256_Init(&shactx1); + auto guard = head.back(); + + td::int64 i = 0, i0 = 0; + for (; i < options.max_iterations; i++) { + if (!(i & 0xfffff) || head.back() != guard) { + if (options.hashes_computed) { + *options.hashes_computed += i - i0; + } + i0 = i; + if (options.expire_at && options.expire_at.value().is_in_past(td::Timestamp::now())) { + break; + } + H.body.set_expire((unsigned)td::Clocks::system() + 900); + guard = head.back(); + SHA256_Init(&shactx1); + SHA256_Update(&shactx1, head.ubegin(), head.size()); + } + shactx2 = shactx1; + SHA256_Update(&shactx2, tail.ubegin(), tail.size()); + SHA256_Final(hash.data(), &shactx2); + + if (memcmp(hash.data(), options.complexity.data(), 32) < 0) { + // FOUND + if (options.hashes_computed) { + *options.hashes_computed += i - i0; + } + return H.body.as_slice().str(); + } + H.body.inc(); + } + if (options.hashes_computed) { + *options.hashes_computed += i - i0; + } + return {}; +} +} // namespace ton diff --git a/crypto/util/Miner.h b/crypto/util/Miner.h new file mode 100644 index 000000000..12acc559f --- /dev/null +++ b/crypto/util/Miner.h @@ -0,0 +1,23 @@ +#pragma once + +#include "block/block.h" +#include "td/utils/optional.h" +#include "td/utils/Time.h" +#include +#include + +namespace ton { +class Miner { + public: + struct Options { + block::StdAddress my_address; + std::array seed; + std::array complexity; + td::optional expire_at; + td::int64 max_iterations = std::numeric_limits::max(); + std::atomic* hashes_computed{nullptr}; + }; + + static td::optional run(const Options& options); +}; +} // namespace ton diff --git a/crypto/util/pow-miner.cpp b/crypto/util/pow-miner.cpp new file mode 100644 index 000000000..49001571b --- /dev/null +++ b/crypto/util/pow-miner.cpp @@ -0,0 +1,214 @@ +#include "common/bigint.hpp" +#include "common/refint.h" +#include "block/block.h" +#include "td/utils/benchmark.h" +#include "td/utils/filesystem.h" +#include "vm/boc.h" +#include "openssl/digest.hpp" +#include +#include +#include +#include +#include + +#include "Miner.h" + +const char* progname; + +int usage() { + std::cerr + << "usage: " << progname + << " [-v][-B][-w] [-t] [ " + "]\n" + "Outputs a valid value for proof-of-work testgiver after computing at most hashes " + "or terminates with non-zero exit code\n"; + std::exit(2); +} + +td::RefInt256 parse_bigint(std::string str, int bits) { + int len = (int)str.size(); + auto num = td::make_refint(); + auto& x = num.write(); + if (len >= 3 && str[0] == '0' && str[1] == 'x') { + if (x.parse_hex(str.data() + 2, len - 2) != len - 2) { + return {}; + } + } else if (!len || x.parse_dec(str.data(), len) != len) { + return {}; + } + return x.unsigned_fits_bits(bits) ? std::move(num) : td::RefInt256{}; +} + +td::RefInt256 parse_bigint_chk(std::string str, int bits) { + auto x = parse_bigint(std::move(str), bits); + if (x.is_null()) { + std::cerr << "fatal: `" << str << "` is not an integer" << std::endl; + usage(); + } + return x; +} + +void parse_addr(std::string str, block::StdAddress& addr) { + if (!addr.parse_addr(str) || (addr.workchain != -1 && addr.workchain != 0)) { + std::cerr << "fatal: `" << str.c_str() << "` is not a valid blockchain address" << std::endl; + usage(); + } +} + +bool make_boc = false; +std::string boc_filename; +block::StdAddress miner_address; + +int verbosity = 0; +std::atomic hashes_computed{0}; +td::Timestamp start_at; + +void print_stats() { + auto passed = td::Timestamp::now().at() - start_at.at(); + if (passed < 1e-9) { + passed = 1; + } + std::cerr << "[ hashes computed: " << hashes_computed << " ]" << std::endl; + std::cerr << "[ speed: " << static_cast(hashes_computed) / passed << " hps ]" << std::endl; +} + +int found(td::Slice data) { + for (unsigned i = 0; i < data.size(); i++) { + printf("%02X", data.ubegin()[i]); + } + printf("\n"); + if (make_boc) { + vm::CellBuilder cb; + td::Ref ext_msg, body; + CHECK(cb.store_bytes_bool(data) // body + && cb.finalize_to(body) // -> body + && cb.store_long_bool(0x44, 7) // ext_message_in$10 ... + && cb.store_long_bool(miner_address.workchain, 8) // workchain + && cb.store_bytes_bool(miner_address.addr.as_slice()) // miner addr + && cb.store_long_bool(1, 6) // amount:Grams ... + && cb.store_ref_bool(std::move(body)) // body:^Cell + && cb.finalize_to(ext_msg)); + auto boc = vm::std_boc_serialize(std::move(ext_msg), 2).move_as_ok(); + std::cerr << "Saving " << boc.size() << " bytes of serialized external message into file `" << boc_filename << "`" + << std::endl; + td::write_file(boc_filename, boc).ensure(); + } + if (verbosity > 0) { + print_stats(); + } + std::exit(0); + return 0; +} + +void miner(const ton::Miner::Options& options) { + auto res = ton::Miner::run(options); + if (res) { + found(res.value()); + } +} + +class MinerBench : public td::Benchmark { + public: + std::string get_description() const override { + return "Miner"; + } + + void run(int n) override { + ton::Miner::Options options; + options.my_address.parse_addr("EQDU86V5wyPrLd4nQ0RHPcCLPZq_y1O5wFWyTsMw63vjXTOv"); + std::fill(options.seed.begin(), options.seed.end(), 0xa7); + std::fill(options.complexity.begin(), options.complexity.end(), 0); + options.max_iterations = n; + CHECK(!ton::Miner::run(options)); + } +}; + +int main(int argc, char* const argv[]) { + ton::Miner::Options options; + + progname = argv[0]; + int i, threads = 0; + bool bounce = false, benchmark = false; + while ((i = getopt(argc, argv, "bnvw:t:Bh")) != -1) { + switch (i) { + case 'v': + ++verbosity; + break; + case 'w': + threads = atoi(optarg); + CHECK(threads > 0 && threads <= 128); + break; + case 't': { + int timeout = atoi(optarg); + CHECK(timeout > 0); + options.expire_at = td::Timestamp::in(timeout); + break; + } + case 'B': + benchmark = true; + break; + case 'b': + bounce = true; + break; + case 'n': + bounce = false; + break; + case 'h': + return usage(); + default: + std::cerr << "unknown option" << std::endl; + return usage(); + } + } + if (benchmark && argc == optind) { + td::bench(MinerBench()); + return 0; + } + + if (argc != optind + 4 && argc != optind + 6) { + return usage(); + } + + parse_addr(argv[optind], options.my_address); + options.my_address.bounceable = bounce; + CHECK(parse_bigint_chk(argv[optind + 1], 128)->export_bytes(options.seed.data(), 16, false)); + + auto cmplx = parse_bigint_chk(argv[optind + 2], 256); + CHECK(cmplx->export_bytes(options.complexity.data(), 32, false)); + CHECK(!cmplx->unsigned_fits_bits(256 - 62)); + td::BigInt256 bigpower, hrate; + bigpower.set_pow2(256).mod_div(*cmplx, hrate); + long long hash_rate = hrate.to_long(); + options.max_iterations = parse_bigint_chk(argv[optind + 3], 50)->to_long(); + if (argc == optind + 6) { + make_boc = true; + parse_addr(argv[optind + 4], miner_address); + boc_filename = argv[optind + 5]; + } + + if (verbosity >= 2) { + std::cerr << "[ expected required hashes for success: " << hash_rate << " ]" << std::endl; + } + if (benchmark) { + td::bench(MinerBench()); + } + + start_at = td::Timestamp::now(); + + options.hashes_computed = &hashes_computed; + // may invoke several miner threads + if (threads <= 0) { + miner(options); + } else { + std::vector T; + for (int i = 0; i < threads; i++) { + T.emplace_back(miner, options); + } + for (auto& thr : T) { + thr.join(); + } + } + if (verbosity > 0) { + print_stats(); + } +} diff --git a/crypto/vm/boc.cpp b/crypto/vm/boc.cpp index 5ab6f5ea3..058f1e997 100644 --- a/crypto/vm/boc.cpp +++ b/crypto/vm/boc.cpp @@ -23,9 +23,10 @@ #include "vm/cells.h" #include "vm/cellslice.h" #include "td/utils/bits.h" -#include "td/utils/Slice-decl.h" -#include "td/utils/format.h" #include "td/utils/crypto.h" +#include "td/utils/format.h" +#include "td/utils/misc.h" +#include "td/utils/Slice-decl.h" namespace vm { using td::Ref; diff --git a/crypto/vm/stack.hpp b/crypto/vm/stack.hpp index d67a9dbbc..32040bd71 100644 --- a/crypto/vm/stack.hpp +++ b/crypto/vm/stack.hpp @@ -35,6 +35,8 @@ #include "td/utils/Span.h" +#include + namespace td { extern template class td::Cnt; extern template class td::Ref>; @@ -186,7 +188,7 @@ class StackEntry { private: static bool is_list(const StackEntry* se); template - Ref dynamic_as() const & { + Ref dynamic_as() const& { return tp == tag ? static_cast>(ref) : td::Ref{}; } template @@ -198,7 +200,7 @@ class StackEntry { return tp == tag ? static_cast>(std::move(ref)) : td::Ref{}; } template - Ref as() const & { + Ref as() const& { return tp == tag ? Ref{td::static_cast_ref(), ref} : td::Ref{}; } template @@ -230,31 +232,31 @@ class StackEntry { return ref; } } - td::RefInt256 as_int() const & { + td::RefInt256 as_int() const& { return as(); } td::RefInt256 as_int() && { return move_as(); } - Ref as_cell() const & { + Ref as_cell() const& { return as(); } Ref as_cell() && { return move_as(); } - Ref as_builder() const & { + Ref as_builder() const& { return as(); } Ref as_builder() && { return move_as(); } - Ref as_slice() const & { + Ref as_slice() const& { return as(); } Ref as_slice() && { return move_as(); } - Ref as_cont() const &; + Ref as_cont() const&; Ref as_cont() &&; Ref> as_string_ref() const { return as, t_string>(); @@ -269,16 +271,16 @@ class StackEntry { std::string as_bytes() const { return tp == t_bytes ? *as_bytes_ref() : ""; } - Ref as_box() const &; + Ref as_box() const&; Ref as_box() &&; - Ref as_tuple() const &; + Ref as_tuple() const&; Ref as_tuple() &&; - Ref as_tuple_range(unsigned max_len = 255, unsigned min_len = 0) const &; + Ref as_tuple_range(unsigned max_len = 255, unsigned min_len = 0) const&; Ref as_tuple_range(unsigned max_len = 255, unsigned min_len = 0) &&; - Ref as_atom() const &; + Ref as_atom() const&; Ref as_atom() &&; template - Ref as_object() const & { + Ref as_object() const& { return dynamic_as(); } template @@ -444,7 +446,7 @@ class Stack : public td::CntObject { } return *this; } - std::vector extract_contents() const & { + std::vector extract_contents() const& { return stack; } std::vector extract_contents() && { diff --git a/dht-server/dht-server.cpp b/dht-server/dht-server.cpp index b122d791a..8048a457e 100644 --- a/dht-server/dht-server.cpp +++ b/dht-server/dht-server.cpp @@ -30,7 +30,7 @@ #include "td/utils/filesystem.h" #include "td/actor/MultiPromise.h" #include "td/utils/overloaded.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/port/path.h" #include "td/utils/port/user.h" #include "td/utils/port/signals.h" @@ -1176,12 +1176,11 @@ int main(int argc, char *argv[]) { std::vector> acts; - td::OptionsParser p; + td::OptionParser p; p.set_description("dht server for TON DHT network"); p.add_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { int v = VERBOSITY_NAME(FATAL) + (td::to_integer(arg)); SET_VERBOSITY_LEVEL(v); - return td::Status::OK(); }); p.add_option('h', "help", "prints_help", [&]() { char b[10240]; @@ -1189,17 +1188,14 @@ int main(int argc, char *argv[]) { sb << p; std::cout << sb.as_cslice().c_str(); std::exit(2); - return td::Status::OK(); }); p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) { acts.push_back([&x, fname = fname.str()]() { td::actor::send_closure(x, &DhtServer::set_global_config, fname); }); - return td::Status::OK(); }); p.add_option('c', "local-config", "file to read local config", [&](td::Slice fname) { acts.push_back([&x, fname = fname.str()]() { td::actor::send_closure(x, &DhtServer::set_local_config, fname); }); - return td::Status::OK(); }); - p.add_option('I', "ip", "ip:port of instance", [&](td::Slice arg) { + p.add_checked_option('I', "ip", "ip:port of instance", [&](td::Slice arg) { td::IPAddress addr; TRY_STATUS(addr.init_host_port(arg.str())); acts.push_back([&x, addr]() { td::actor::send_closure(x, &DhtServer::add_ip, addr); }); @@ -1207,7 +1203,6 @@ int main(int argc, char *argv[]) { }); p.add_option('D', "db", "root for dbs", [&](td::Slice fname) { acts.push_back([&x, fname = fname.str()]() { td::actor::send_closure(x, &DhtServer::set_db_root, fname); }); - return td::Status::OK(); }); p.add_option('d', "daemonize", "set SIGHUP", [&]() { #if TD_DARWIN || TD_LINUX @@ -1215,28 +1210,27 @@ int main(int argc, char *argv[]) { setsid(); #endif td::set_signal_handler(td::SignalType::HangUp, force_rotate_logs).ensure(); - return td::Status::OK(); }); p.add_option('l', "logname", "log to file", [&](td::Slice fname) { logger_ = td::TsFileLog::create(fname.str()).move_as_ok(); td::log_interface = logger_.get(); - return td::Status::OK(); }); td::uint32 threads = 7; - p.add_option('t', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice fname) { - td::int32 v; - try { - v = std::stoi(fname.str()); - } catch (...) { - return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: not a number"); - } - if (v < 1 || v > 256) { - return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be in range [1..256]"); - } - threads = v; - return td::Status::OK(); - }); - p.add_option('u', "user", "change user", [&](td::Slice user) { return td::change_user(user); }); + p.add_checked_option( + 't', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice fname) { + td::int32 v; + try { + v = std::stoi(fname.str()); + } catch (...) { + return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: not a number"); + } + if (v < 1 || v > 256) { + return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be in range [1..256]"); + } + threads = v; + return td::Status::OK(); + }); + p.add_checked_option('u', "user", "change user", [&](td::Slice user) { return td::change_user(user.str()); }); p.run(argc, argv).ensure(); td::set_runtime_signal_handler(1, need_stats).ensure(); diff --git a/dht/test/dht-test-ping.cpp b/dht/test/dht-test-ping.cpp index 669840f5a..f2756b472 100644 --- a/dht/test/dht-test-ping.cpp +++ b/dht/test/dht-test-ping.cpp @@ -31,7 +31,7 @@ #include "keys/encryptor.h" #include "td/utils/Time.h" #include "td/utils/format.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/filesystem.h" #include "dht/dht.h" #include "auto/tl/ton_api_json.h" @@ -265,7 +265,7 @@ td::Result get_uint256(std::string str) { int main(int argc, char *argv[]) { td::actor::ActorOwn x; - td::OptionsParser p; + td::OptionParser p; p.set_description("test basic adnl functionality"); p.add_option('h', "help", "prints_help", [&]() { char b[10240]; diff --git a/doc/TestGrams-HOWTO b/doc/TestGrams-HOWTO new file mode 100644 index 000000000..8156e9757 --- /dev/null +++ b/doc/TestGrams-HOWTO @@ -0,0 +1,163 @@ +The aim of this text is to describe how to quickly obtain a small amount of test Grams for test purposes, or a larger amount of test Grams for running a validator in the test network. We assume familiarity with the TON Blockchain LiteClient as explained in the LiteClient-HOWTO, and with the procedure required to compile the LiteClient and other software. For obtaining larger amount of test Grams required for running a validator, we also assume acquaintance with the FullNode-HOWTO and Validator-HOWTO. You will also need a dedicated server powerful enough for running a Full Node in order to obtain the larger amount of test Grams. Obtaining small amounts of test Grams does not require a dedicated server and may be done in several minutes on a home computer. + +1. Proof-of-Work TestGiver smart contracts +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In order to prevent a small number of malicious parties to collect all test Grams reserved for test purposes, a special kind of "Proof-of-Work TestGiver" smart contracts have been deployed in the masterchain of the test network. The addresses of these smart contacts are: + +Small testgivers (deliver from 10 to 100 test Grams every several minutes): + +kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN +kf8SYc83pm5JkGt0p3TQRkuiM58O9Cr3waUtR9OoFq716lN- +kf-FV4QTxLl-7Ct3E6MqOtMt-RGXMxi27g4I645lw6MTWraV +kf_NSzfDJI1A3rOM0GQm7xsoUXHTgmdhN5-OrGD8uwL2JMvQ +kf8gf1PQy4u2kURl-Gz4LbS29eaN4sVdrVQkPO-JL80VhOe6 +kf8kO6K6Qh6YM4ddjRYYlvVAK7IgyW8Zet-4ZvNrVsmQ4EOF +kf-P_TOdwcCh0AXHhBpICDMxStxHenWdLCDLNH5QcNpwMHJ8 +kf91o4NNTryJ-Cw3sDGt9OTiafmETdVFUMvylQdFPoOxIsLm +kf9iWhwk9GwAXjtwKG-vN7rmXT3hLIT23RBY6KhVaynRrIK7 +kf8JfFUEJhhpRW80_jqD7zzQteH6EBHOzxiOhygRhBdt4z2N + +Large testgivers (deliver 10000 test Grams at least once a day): + +kf8guqdIbY6kpMykR8WFeVGbZcP2iuBagXfnQuq0rGrxgE04 +kf9CxReRyaGj0vpSH0gRZkOAitm_yDHvgiMGtmvG-ZTirrMC +kf-WXA4CX4lqyVlN4qItlQSWPFIy00NvO2BAydgC4CTeIUme +kf8yF4oXfIj7BZgkqXM6VsmDEgCqWVSKECO1pC0LXWl399Vx +kf9nNY69S3_heBBSUtpHRhIzjjqY0ChugeqbWcQGtGj-gQxO +kf_wUXx-l1Ehw0kfQRgFtWKO07B6WhSqcUQZNyh4Jmj8R4zL +kf_6keW5RniwNQYeq3DNWGcohKOwI85p-V2MsPk4v23tyO3I +kf_NSPpF4ZQ7mrPylwk-8XQQ1qFD5evLnx5_oZVNywzOjSfh +kf-uNWj4JmTJefr7IfjBSYQhFbd3JqtQ6cxuNIsJqDQ8SiEA +kf8mO4l6ZB_eaMn1OqjLRrrkiBcSt7kYTvJC_dzJLdpEDKxn + +The first ten smart contracts enable a tester willing to obtain a small amount of test Grams to obtain some without spending too much computing power (typically, several minutes of work of a home computer should suffice). The remaining smart contracts are for obtaining larger amounts of test Grams required for running a validator in the test network; typically, a day of work of a dedicated server powerful enough to run a validator should suffice to obtain the necessary amount. + +You should randomly choose one of these "proof-of-work testgiver" smart contracts (from one of these two lists depending on your purpose) and obtain test Grams from this smart contract by a procedure similar to "mining". Essentially, you have to present an external message containing the proof of work and the address of your wallet to the chosen "proof-of-work testgiver" smart contract, and then the necessary amount will be sent to you. + +2. The "mining" process +~~~~~~~~~~~~~~~~~~~~~~~ + +In order to create an external message containing the "proof of work", you should run a special "mining" utility, compiled from the TON sources located in the GitHub repository. The utility is located in file './crypto/pow-miner' with respect to the build directory, and can be compiled by typing 'make pow-miner' in the build directory. + +However, before running "pow-miner", you need to know the actual values of "seed" and "complexity" parameters of the chosen "proof-of-work testgiver" smart contract. This can be done by invoking get-method "get_pow_params" of this smart contract. For instance, if you use testgiver smart contract kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN, you can simply type + + > runmethod kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN get_pow_params + +in the LiteClient console and obtain output like + + ... + arguments: [ 101616 ] + result: [ 229760179690128740373110445116482216837 53919893334301279589334030174039261347274288845081144962207220498432 100000000000 256 ] + remote result (not to be trusted): [ 229760179690128740373110445116482216837 53919893334301279589334030174039261347274288845081144962207220498432 100000000000 256 ] + +The two first large numbers in the "result:" line are the "seed" and the "complexity" of this smart contract. In this example, the seed is 229760179690128740373110445116482216837 and the complexity is 53919893334301279589334030174039261347274288845081144962207220498432. + +Next, you invoke the pow-miner utility as follows: + + $ crypto/pow-miner -vv -w -t + +Here is the number of CPU cores that you want to use for mining, is the maximal amount of seconds that the miner would run before admitting failure, is the address of your wallet (possibly not initialized yet), either in the masterchain or in the workchain (note that you need a masterchain wallet to control a validator), and are the most recent values obtained by running get-method 'get-pow-params', is the address of the chosen proof-of-work testgiver smartcontract, and is the filename of the output file where the external message with the proof of work will be saved in the case of success. + +For example, if your wallet address is kQBWkNKqzCAwA9vjMwRmg7aY75Rf8lByPA9zKXoqGkHi8SM7, you might run + + $ crypto/pow-miner -vv -w7 -t100 kQBWkNKqzCAwA9vjMwRmg7aY75Rf8lByPA9zKXoqGkHi8SM7 229760179690128740373110445116482216837 53919893334301279589334030174039261347274288845081144962207220498432 100000000000 kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN mined.boc + +The program will run for some time (at most 100 seconds in this case) and either terminate successfully (with zero exit code) and save the required proof of work into file "mined.boc", or terminate with a non-zero exit code if no proof of work was found. + +In the case of failure, you will see something like + + [ expected required hashes for success: 2147483648 ] + [ hashes computed: 1192230912 ] + +and the program will terminate with a non-zero exit code. Then you have to obtain the "seed" and "complexity" again (because they may have changed in the meantime as a result of processing requests from more successful miners) and re-run the "pow-miner" with the new parameters, repeating the process again and again until success. + +In the case of success, you will see something like + + [ expected required hashes for success: 2147483648 ] + 4D696E65005EFE49705690D2AACC203003DBE333046683B698EF945FF250723C0F73297A2A1A41E2F1A1F533B3BC4F5664D6C743C1C5C74BB3342F3A7314364B3D0DA698E6C80C1EA4ACDA33755876665780BAE9BE8A4D6385A1F533B3BC4F5664D6C743C1C5C74BB3342F3A7314364B3D0DA698E6C80C1EA4 + Saving 176 bytes of serialized external message into file `mined.boc` + [ hashes computed: 1122036095 ] + +Then you can use the LiteClient to send external message from file "mined.boc" to the proof-of-work testgiver smart contract (and you must do this as soon as possible): + +> sendfile mined.boc +... external message status is 1 + +You can wait for several seconds and check the state of your wallet: + +> last +> getaccount kQBWkNKqzCAwA9vjMwRmg7aY75Rf8lByPA9zKXoqGkHi8SM7 +... +account state is (account + addr:(addr_std + anycast:nothing workchain_id:0 address:x5690D2AACC203003DBE333046683B698EF945FF250723C0F73297A2A1A41E2F1) + storage_stat:(storage_info + used:(storage_used + cells:(var_uint len:1 value:1) + bits:(var_uint len:1 value:111) + public_cells:(var_uint len:0 value:0)) last_paid:1593722498 + due_payment:nothing) + storage:(account_storage last_trans_lt:7720869000002 + balance:(currencies + grams:(nanograms + amount:(var_uint len:5 value:100000000000)) + other:(extra_currencies + dict:hme_empty)) + state:account_uninit)) +x{C005690D2AACC203003DBE333046683B698EF945FF250723C0F73297A2A1A41E2F12025BC2F7F2341000001C169E9DCD0945D21DBA0004_} +last transaction lt = 7720869000001 hash = 83C15CDED025970FEF7521206E82D2396B462AADB962C7E1F4283D88A0FAB7D4 +account balance is 100000000000ng + +If nobody has sent a valid proof of work with this *seed* and *complexity* before you, the proof-of-work testgiver will accept your proof of work and this will be reflected in the balance of your wallet (10 or 20 seconds may elapse after sending the external message before this happens; be sure to make several attempts and type "last" each time before checking the balance of your wallet to refresh the LiteClient state). In the case of success, you will see that the balance has been increased (and even that your wallet has been created in uninitialized state if it did not exist before). In the case of failure, you will have to obtain the new "seed" and "complexity" and repeat the mining process from the very beginning. + +If you have been lucky and the balance of your wallet has been increased, you may want to initialize the wallet if it wasn't initialized before (more information on wallet creation can be found in LiteClient-HOWTO): + +> sendfile new-wallet-query.boc +... external message status is 1 +> last +> getaccount kQBWkNKqzCAwA9vjMwRmg7aY75Rf8lByPA9zKXoqGkHi8SM7 +... +account state is (account + addr:(addr_std + anycast:nothing workchain_id:0 address:x5690D2AACC203003DBE333046683B698EF945FF250723C0F73297A2A1A41E2F1) + storage_stat:(storage_info + used:(storage_used + cells:(var_uint len:1 value:3) + bits:(var_uint len:2 value:1147) + public_cells:(var_uint len:0 value:0)) last_paid:1593722691 + due_payment:nothing) + storage:(account_storage last_trans_lt:7720945000002 + balance:(currencies + grams:(nanograms + amount:(var_uint len:5 value:99995640998)) + other:(extra_currencies + dict:hme_empty)) + state:(account_active + ( + split_depth:nothing + special:nothing + code:(just + value:(raw@^Cell + x{} + x{FF0020DD2082014C97BA218201339CBAB19C71B0ED44D0D31FD70BFFE304E0A4F260810200D71820D70B1FED44D0D31FD3FFD15112BAF2A122F901541044F910F2A2F80001D31F3120D74A96D307D402FB00DED1A4C8CB1FCBFFC9ED54} + )) + data:(just + value:(raw@^Cell + x{} + x{00000001CE6A50A6E9467C32671667F8C00C5086FC8D62E5645652BED7A80DF634487715} + )) + library:hme_empty)))) +x{C005690D2AACC203003DBE333046683B698EF945FF250723C0F73297A2A1A41E2F1206811EC2F7F23A1800001C16B0BC790945D20D1929934_} + x{FF0020DD2082014C97BA218201339CBAB19C71B0ED44D0D31FD70BFFE304E0A4F260810200D71820D70B1FED44D0D31FD3FFD15112BAF2A122F901541044F910F2A2F80001D31F3120D74A96D307D402FB00DED1A4C8CB1FCBFFC9ED54} + x{00000001CE6A50A6E9467C32671667F8C00C5086FC8D62E5645652BED7A80DF634487715} +last transaction lt = 7720945000001 hash = 73353151859661AB0202EA5D92FF409747F201D10F1E52BD0CBB93E1201676BF +account balance is 99995640998ng + +Now you are a happy owner of 100 test Grams that can be used for whatever testing purposes you had in mind. Congratulations! + +3. Automating the mining process in the case of failure +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you fail to obtain your test Grams for a long time, this may happen because too many other testers are simultaneously "mining" from the same proof-of-work testgiver smart contract. Maybe you should choose another proof-of-work testgiver smart contract from one of the lists given above. Alternatively, you can write a simple script to automatically run `pow-miner` with the correct parameters again and again until success (detected by checking the exit code of `pow-miner`) and invoke the lite-client with parameter -c 'sendfile mined.boc' to send the external message immediately after it is found. + diff --git a/http/http-proxy.cpp b/http/http-proxy.cpp index 155380564..4470e55cf 100644 --- a/http/http-proxy.cpp +++ b/http/http-proxy.cpp @@ -29,7 +29,7 @@ #include "http/http-client.h" #include "td/utils/port/signals.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/FileLog.h" #include @@ -258,12 +258,11 @@ int main(int argc, char *argv[]) { td::log_interface = td::default_log_interface; }; - td::OptionsParser p; + td::OptionParser p; p.set_description("simple http proxy"); p.add_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { int v = VERBOSITY_NAME(FATAL) + (td::to_integer(arg)); SET_VERBOSITY_LEVEL(v); - return td::Status::OK(); }); p.add_option('h', "help", "prints_help", [&]() { char b[10240]; @@ -271,9 +270,8 @@ int main(int argc, char *argv[]) { sb << p; std::cout << sb.as_cslice().c_str(); std::exit(2); - return td::Status::OK(); }); - p.add_option('p', "port", "sets listening port", [&](td::Slice arg) -> td::Status { + p.add_checked_option('p', "port", "sets listening port", [&](td::Slice arg) -> td::Status { TRY_RESULT(port, td::to_integer_safe(arg)); td::actor::send_closure(x, &HttpProxy::set_port, port); return td::Status::OK(); @@ -285,13 +283,11 @@ int main(int argc, char *argv[]) { setsid(); #endif }).ensure(); - return td::Status::OK(); }); #if TD_DARWIN || TD_LINUX p.add_option('l', "logname", "log to file", [&](td::Slice fname) { logger_ = td::FileLog::create(fname.str()).move_as_ok(); td::log_interface = logger_.get(); - return td::Status::OK(); }); #endif diff --git a/http/http.cpp b/http/http.cpp index c69ce3eed..b3c56c9e8 100644 --- a/http/http.cpp +++ b/http/http.cpp @@ -18,6 +18,8 @@ */ #include "http.h" +#include "td/utils/misc.h" + #include namespace ton { diff --git a/lite-client/lite-client.cpp b/lite-client/lite-client.cpp index 8b9c7c1af..2aa6cf162 100644 --- a/lite-client/lite-client.cpp +++ b/lite-client/lite-client.cpp @@ -33,7 +33,7 @@ #include "tl-utils/lite-utils.hpp" #include "auto/tl/ton_api_json.h" #include "auto/tl/lite_api.hpp" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/Time.h" #include "td/utils/filesystem.h" #include "td/utils/format.h" @@ -4167,7 +4167,7 @@ int main(int argc, char* argv[]) { td::actor::ActorOwn x; - td::OptionsParser p; + td::OptionParser p; p.set_description("Test Lite Client for TON Blockchain"); p.add_option('h', "help", "prints_help", [&]() { char b[10240]; @@ -4175,30 +4175,21 @@ int main(int argc, char* argv[]) { sb << p; std::cout << sb.as_cslice().c_str(); std::exit(2); - return td::Status::OK(); - }); - p.add_option('C', "global-config", "file to read global config", [&](td::Slice fname) { - td::actor::send_closure(x, &TestNode::set_global_config, fname.str()); - return td::Status::OK(); - }); - p.add_option('r', "disable-readline", "", [&]() { - td::actor::send_closure(x, &TestNode::set_readline_enabled, false); - return td::Status::OK(); - }); - p.add_option('R', "enable-readline", "", [&]() { - td::actor::send_closure(x, &TestNode::set_readline_enabled, true); - return td::Status::OK(); - }); - p.add_option('D', "db", "root for dbs", [&](td::Slice fname) { - td::actor::send_closure(x, &TestNode::set_db_root, fname.str()); - return td::Status::OK(); }); - p.add_option('L', "print-limit", "sets maximum count of recursively printed objects", [&](td::Slice arg) { + p.add_option('C', "global-config", "file to read global config", + [&](td::Slice fname) { td::actor::send_closure(x, &TestNode::set_global_config, fname.str()); }); + p.add_option('r', "disable-readline", "", + [&]() { td::actor::send_closure(x, &TestNode::set_readline_enabled, false); }); + p.add_option('R', "enable-readline", "", + [&]() { td::actor::send_closure(x, &TestNode::set_readline_enabled, true); }); + p.add_option('D', "db", "root for dbs", + [&](td::Slice fname) { td::actor::send_closure(x, &TestNode::set_db_root, fname.str()); }); + p.add_checked_option('L', "print-limit", "sets maximum count of recursively printed objects", [&](td::Slice arg) { auto plimit = td::to_integer(arg); td::actor::send_closure(x, &TestNode::set_print_limit, plimit); return plimit >= 0 ? td::Status::OK() : td::Status::Error("printing limit must be non-negative"); }); - p.add_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { + p.add_checked_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { verbosity = td::to_integer(arg); SET_VERBOSITY_LEVEL(VERBOSITY_NAME(FATAL) + verbosity); return (verbosity >= 0 && verbosity <= 9) ? td::Status::OK() : td::Status::Error("verbosity must be 0..9"); @@ -4206,27 +4197,21 @@ int main(int argc, char* argv[]) { p.add_option('i', "idx", "set liteserver idx", [&](td::Slice arg) { auto idx = td::to_integer(arg); td::actor::send_closure(x, &TestNode::set_liteserver_idx, idx); - return td::Status::OK(); }); - p.add_option('a', "addr", "connect to ip:port", [&](td::Slice arg) { + p.add_checked_option('a', "addr", "connect to ip:port", [&](td::Slice arg) { td::IPAddress addr; TRY_STATUS(addr.init_host_port(arg.str())); td::actor::send_closure(x, &TestNode::set_remote_addr, addr); return td::Status::OK(); }); - p.add_option('c', "cmd", "schedule command", [&](td::Slice arg) { - td::actor::send_closure(x, &TestNode::add_cmd, td::BufferSlice{arg}); - return td::Status::OK(); - }); + p.add_option('c', "cmd", "schedule command", + [&](td::Slice arg) { td::actor::send_closure(x, &TestNode::add_cmd, td::BufferSlice{arg}); }); p.add_option('t', "timeout", "timeout in batch mode", [&](td::Slice arg) { auto d = td::to_double(arg); td::actor::send_closure(x, &TestNode::set_fail_timeout, td::Timestamp::in(d)); - return td::Status::OK(); - }); - p.add_option('p', "pub", "remote public key", [&](td::Slice arg) { - td::actor::send_closure(x, &TestNode::set_public_key, td::BufferSlice{arg}); - return td::Status::OK(); }); + p.add_option('p', "pub", "remote public key", + [&](td::Slice arg) { td::actor::send_closure(x, &TestNode::set_public_key, td::BufferSlice{arg}); }); p.add_option('d', "daemonize", "set SIGHUP", [&]() { td::set_signal_handler(td::SignalType::HangUp, [](int sig) { #if TD_DARWIN || TD_LINUX @@ -4234,7 +4219,6 @@ int main(int argc, char* argv[]) { setsid(); #endif }).ensure(); - return td::Status::OK(); }); #if TD_DARWIN || TD_LINUX p.add_option('l', "logname", "log to file", [&](td::Slice fname) { @@ -4244,7 +4228,6 @@ int main(int argc, char* argv[]) { dup2(FileLog.get_native_fd().fd(), 1); dup2(FileLog.get_native_fd().fd(), 2); - return td::Status::OK(); }); #endif diff --git a/rldp-http-proxy/rldp-http-proxy.cpp b/rldp-http-proxy/rldp-http-proxy.cpp index 2c4c208dd..b8258be30 100644 --- a/rldp-http-proxy/rldp-http-proxy.cpp +++ b/rldp-http-proxy/rldp-http-proxy.cpp @@ -29,7 +29,7 @@ #include "http/http-client.h" #include "td/utils/port/signals.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/FileLog.h" #include "td/utils/Random.h" #include "td/utils/filesystem.h" @@ -1121,7 +1121,7 @@ int main(int argc, char *argv[]) { td::log_interface = td::default_log_interface; }; - td::OptionsParser p; + td::OptionParser p; p.set_description( "A simple rldp-to-http and http-to-rldp proxy for running and accessing ton sites\n" "Example:\n\trldp-http-proxy -p 8080 -c 3333 -C ton-global.config.json\tRuns a local HTTP->RLDP proxy that " @@ -1132,7 +1132,6 @@ int main(int argc, char *argv[]) { p.add_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { int v = VERBOSITY_NAME(FATAL) + (td::to_integer(arg)); SET_VERBOSITY_LEVEL(v); - return td::Status::OK(); }); p.add_option('h', "help", "prints a help message", [&]() { char b[10240]; @@ -1140,45 +1139,41 @@ int main(int argc, char *argv[]) { sb << p; std::cout << sb.as_cslice().c_str(); std::exit(2); - return td::Status::OK(); }); - p.add_option('p', "port", "sets http listening port", [&](td::Slice arg) -> td::Status { + p.add_checked_option('p', "port", "sets http listening port", [&](td::Slice arg) -> td::Status { TRY_RESULT(port, td::to_integer_safe(arg)); td::actor::send_closure(x, &RldpHttpProxy::set_port, port); return td::Status::OK(); }); - p.add_option('a', "address", "local : to use for adnl queries", [&](td::Slice arg) -> td::Status { + p.add_checked_option('a', "address", "local : to use for adnl queries", [&](td::Slice arg) -> td::Status { td::IPAddress addr; TRY_STATUS(addr.init_host_port(arg.str())); td::actor::send_closure(x, &RldpHttpProxy::set_addr, addr); return td::Status::OK(); }); - p.add_option('A', "adnl", "server ADNL addr", [&](td::Slice arg) -> td::Status { + p.add_checked_option('A', "adnl", "server ADNL addr", [&](td::Slice arg) -> td::Status { TRY_RESULT(adnl, ton::adnl::AdnlNodeIdShort::parse(arg)); td::actor::send_closure(x, &RldpHttpProxy::add_adnl_addr, adnl); return td::Status::OK(); }); - p.add_option('c', "client-port", "local to use for client adnl queries", [&](td::Slice arg) -> td::Status { - TRY_RESULT(port, td::to_integer_safe(arg)); - td::actor::send_closure(x, &RldpHttpProxy::set_client_port, port); - return td::Status::OK(); - }); - p.add_option('C', "global-config", "global TON configuration file", [&](td::Slice arg) -> td::Status { - td::actor::send_closure(x, &RldpHttpProxy::set_global_config, arg.str()); - return td::Status::OK(); - }); - p.add_option('L', "local", "http hostname that will be proxied to http server at localhost:80", - [&](td::Slice arg) -> td::Status { - td::IPAddress addr; - TRY_STATUS(addr.init_ipv4_port("127.0.0.1", 80)); - td::actor::send_closure(x, &RldpHttpProxy::set_local_host, arg.str(), addr); - return td::Status::OK(); - }); - p.add_option('D', "db", "db root", [&](td::Slice arg) -> td::Status { - td::actor::send_closure(x, &RldpHttpProxy::set_db_root, arg.str()); - return td::Status::OK(); - }); - p.add_option( + p.add_checked_option('c', "client-port", "local to use for client adnl queries", + [&](td::Slice arg) -> td::Status { + TRY_RESULT(port, td::to_integer_safe(arg)); + td::actor::send_closure(x, &RldpHttpProxy::set_client_port, port); + return td::Status::OK(); + }); + p.add_option('C', "global-config", "global TON configuration file", + [&](td::Slice arg) { td::actor::send_closure(x, &RldpHttpProxy::set_global_config, arg.str()); }); + p.add_checked_option('L', "local", "http hostname that will be proxied to http server at localhost:80", + [&](td::Slice arg) -> td::Status { + td::IPAddress addr; + TRY_STATUS(addr.init_ipv4_port("127.0.0.1", 80)); + td::actor::send_closure(x, &RldpHttpProxy::set_local_host, arg.str(), addr); + return td::Status::OK(); + }); + p.add_option('D', "db", "db root", + [&](td::Slice arg) { td::actor::send_closure(x, &RldpHttpProxy::set_db_root, arg.str()); }); + p.add_checked_option( 'R', "remote", "@:, indicates a http hostname that will be proxied to remote http server at :", [&](td::Slice arg) -> td::Status { @@ -1198,25 +1193,23 @@ int main(int argc, char *argv[]) { setsid(); #endif }).ensure(); - return td::Status::OK(); }); p.add_option('l', "logname", "log to file", [&](td::Slice fname) { logger_ = td::FileLog::create(fname.str()).move_as_ok(); td::log_interface = logger_.get(); - return td::Status::OK(); }); - p.add_option('P', "proxy-all", "value=[YES|NO]. proxy all HTTP requests (default only *.ton and *.adnl)", - [&](td::Slice value) { - if (value == "YES" || value == "yes") { - td::actor::send_closure(x, &RldpHttpProxy::set_proxy_all, true); - } else if (value == "NO" || value == "no") { - td::actor::send_closure(x, &RldpHttpProxy::set_proxy_all, false); - } else { - return td::Status::Error("--proxy-all expected YES or NO"); - } - - return td::Status::OK(); - }); + p.add_checked_option('P', "proxy-all", "value=[YES|NO]. proxy all HTTP requests (default only *.ton and *.adnl)", + [&](td::Slice value) { + if (value == "YES" || value == "yes") { + td::actor::send_closure(x, &RldpHttpProxy::set_proxy_all, true); + } else if (value == "NO" || value == "no") { + td::actor::send_closure(x, &RldpHttpProxy::set_proxy_all, false); + } else { + return td::Status::Error("--proxy-all expected YES or NO"); + } + + return td::Status::OK(); + }); td::actor::Scheduler scheduler({7}); diff --git a/rldp2/Ack.cpp b/rldp2/Ack.cpp index 2d71f9562..453e5706c 100644 --- a/rldp2/Ack.cpp +++ b/rldp2/Ack.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "Ack.h" namespace ton { diff --git a/rldp2/Ack.h b/rldp2/Ack.h index 092ea938a..30c016ae0 100644 --- a/rldp2/Ack.h +++ b/rldp2/Ack.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/int_types.h" diff --git a/rldp2/Bbr.cpp b/rldp2/Bbr.cpp index 93d06f827..b0f841a96 100644 --- a/rldp2/Bbr.cpp +++ b/rldp2/Bbr.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "Bbr.h" #include "BdwStats.h" diff --git a/rldp2/Bbr.h b/rldp2/Bbr.h index 29d4f8577..6d2acf70c 100644 --- a/rldp2/Bbr.h +++ b/rldp2/Bbr.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/int_types.h" #include "td/utils/Time.h" diff --git a/rldp2/BdwStats.cpp b/rldp2/BdwStats.cpp index d0bc75714..41221ec43 100644 --- a/rldp2/BdwStats.cpp +++ b/rldp2/BdwStats.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "BdwStats.h" namespace ton { diff --git a/rldp2/BdwStats.h b/rldp2/BdwStats.h index a953169bf..fe8f7e52a 100644 --- a/rldp2/BdwStats.h +++ b/rldp2/BdwStats.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/Time.h" diff --git a/rldp2/FecHelper.cpp b/rldp2/FecHelper.cpp index 0f53b7ccd..469ab234a 100644 --- a/rldp2/FecHelper.cpp +++ b/rldp2/FecHelper.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "FecHelper.h" #include "td/utils/check.h" diff --git a/rldp2/FecHelper.h b/rldp2/FecHelper.h index b3e656555..89f9c6746 100644 --- a/rldp2/FecHelper.h +++ b/rldp2/FecHelper.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/int_types.h" diff --git a/rldp2/InboundTransfer.cpp b/rldp2/InboundTransfer.cpp index c9ef9feaf..1869d3a33 100644 --- a/rldp2/InboundTransfer.cpp +++ b/rldp2/InboundTransfer.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "InboundTransfer.h" #include "common/errorcode.h" diff --git a/rldp2/InboundTransfer.h b/rldp2/InboundTransfer.h index 86cfbd172..c9fed8e4e 100644 --- a/rldp2/InboundTransfer.h +++ b/rldp2/InboundTransfer.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/optional.h" diff --git a/rldp2/LossSender.cpp b/rldp2/LossSender.cpp index 46da0533f..69ecde594 100644 --- a/rldp2/LossSender.cpp +++ b/rldp2/LossSender.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "LossSender.h" #include "td/utils/logging.h" diff --git a/rldp2/LossSender.h b/rldp2/LossSender.h index 2a27a8d00..e2fa6887e 100644 --- a/rldp2/LossSender.h +++ b/rldp2/LossSender.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include diff --git a/rldp2/LossStats.cpp b/rldp2/LossStats.cpp index 9eca2e9db..62691a518 100644 --- a/rldp2/LossStats.cpp +++ b/rldp2/LossStats.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "LossStats.h" #include "td/utils/misc.h" diff --git a/rldp2/LossStats.h b/rldp2/LossStats.h index 19e5427c9..a39e04de7 100644 --- a/rldp2/LossStats.h +++ b/rldp2/LossStats.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "LossSender.h" diff --git a/rldp2/OutboundTransfer.cpp b/rldp2/OutboundTransfer.cpp index 1449cc097..b0e97e7cc 100644 --- a/rldp2/OutboundTransfer.cpp +++ b/rldp2/OutboundTransfer.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "OutboundTransfer.h" namespace ton { diff --git a/rldp2/OutboundTransfer.h b/rldp2/OutboundTransfer.h index 249659bd6..ab3e5e545 100644 --- a/rldp2/OutboundTransfer.h +++ b/rldp2/OutboundTransfer.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "RldpSender.h" diff --git a/rldp2/Pacer.cpp b/rldp2/Pacer.cpp index 933695ee3..9880093d0 100644 --- a/rldp2/Pacer.cpp +++ b/rldp2/Pacer.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "Pacer.h" namespace ton { namespace rldp2 { diff --git a/rldp2/Pacer.h b/rldp2/Pacer.h index 560858b46..cc50a6924 100644 --- a/rldp2/Pacer.h +++ b/rldp2/Pacer.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/optional.h" #include "td/utils/Time.h" diff --git a/rldp2/RldpConnection.cpp b/rldp2/RldpConnection.cpp index 12034e6ec..02c916629 100644 --- a/rldp2/RldpConnection.cpp +++ b/rldp2/RldpConnection.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "RldpConnection.h" #include "td/utils/overloaded.h" diff --git a/rldp2/RldpConnection.h b/rldp2/RldpConnection.h index e0adaeb49..b9c43bcb3 100644 --- a/rldp2/RldpConnection.h +++ b/rldp2/RldpConnection.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "Bbr.h" diff --git a/rldp2/RldpReceiver.cpp b/rldp2/RldpReceiver.cpp index ed97c5340..169bd5514 100644 --- a/rldp2/RldpReceiver.cpp +++ b/rldp2/RldpReceiver.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "RldpReceiver.h" namespace ton { diff --git a/rldp2/RldpReceiver.h b/rldp2/RldpReceiver.h index b41a55f88..bf191453d 100644 --- a/rldp2/RldpReceiver.h +++ b/rldp2/RldpReceiver.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "Ack.h" diff --git a/rldp2/RldpSender.cpp b/rldp2/RldpSender.cpp index 6964689af..1f2dc26aa 100644 --- a/rldp2/RldpSender.cpp +++ b/rldp2/RldpSender.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "RldpSender.h" #include "RttStats.h" diff --git a/rldp2/RldpSender.h b/rldp2/RldpSender.h index a5f582b7e..72316d779 100644 --- a/rldp2/RldpSender.h +++ b/rldp2/RldpSender.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/Time.h" diff --git a/rldp2/RttStats.cpp b/rldp2/RttStats.cpp index 4e998e2cd..8269cfe47 100644 --- a/rldp2/RttStats.cpp +++ b/rldp2/RttStats.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "RttStats.h" #include diff --git a/rldp2/RttStats.h b/rldp2/RttStats.h index fca1385c8..c0d518f33 100644 --- a/rldp2/RttStats.h +++ b/rldp2/RttStats.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/Time.h" diff --git a/rldp2/SenderPackets.cpp b/rldp2/SenderPackets.cpp index d0969fef4..268972c30 100644 --- a/rldp2/SenderPackets.cpp +++ b/rldp2/SenderPackets.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "SenderPackets.h" #include "td/utils/bits.h" diff --git a/rldp2/SenderPackets.h b/rldp2/SenderPackets.h index 6282e1ce0..43f06834e 100644 --- a/rldp2/SenderPackets.h +++ b/rldp2/SenderPackets.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/VectorQueue.h" diff --git a/rldp2/rldp-in.hpp b/rldp2/rldp-in.hpp index afb6b395a..e1697c4da 100644 --- a/rldp2/rldp-in.hpp +++ b/rldp2/rldp-in.hpp @@ -14,7 +14,7 @@ You should have received a copy of the GNU Lesser General Public License along with TON Blockchain Library. If not, see . - Copyright 2017-2019 Telegram Systems LLP + Copyright 2017-2020 Telegram Systems LLP */ #pragma once diff --git a/rldp2/rldp.cpp b/rldp2/rldp.cpp index 06f47448b..7a608c140 100644 --- a/rldp2/rldp.cpp +++ b/rldp2/rldp.cpp @@ -14,7 +14,7 @@ You should have received a copy of the GNU Lesser General Public License along with TON Blockchain Library. If not, see . - Copyright 2017-2019 Telegram Systems LLP + Copyright 2017-2020 Telegram Systems LLP */ #include "rldp-in.hpp" #include "auto/tl/ton_api.h" diff --git a/rldp2/rldp.hpp b/rldp2/rldp.hpp index 824217db7..473cc95b4 100644 --- a/rldp2/rldp.hpp +++ b/rldp2/rldp.hpp @@ -14,7 +14,7 @@ You should have received a copy of the GNU Lesser General Public License along with TON Blockchain Library. If not, see . - Copyright 2017-2019 Telegram Systems LLP + Copyright 2017-2020 Telegram Systems LLP */ #pragma once diff --git a/storage/Bitset.h b/storage/Bitset.h index 1ed569e9e..553807426 100644 --- a/storage/Bitset.h +++ b/storage/Bitset.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/Slice.h" diff --git a/storage/LoadSpeed.cpp b/storage/LoadSpeed.cpp index 274eb5f91..a2708055c 100644 --- a/storage/LoadSpeed.cpp +++ b/storage/LoadSpeed.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "LoadSpeed.h" #include "td/utils/format.h" diff --git a/storage/LoadSpeed.h b/storage/LoadSpeed.h index a56626e5b..c2902e614 100644 --- a/storage/LoadSpeed.h +++ b/storage/LoadSpeed.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/StringBuilder.h" diff --git a/storage/MerkleTree.cpp b/storage/MerkleTree.cpp index 8a90a4dc1..ff88ee44e 100644 --- a/storage/MerkleTree.cpp +++ b/storage/MerkleTree.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "MerkleTree.h" #include "common/bitstring.h" diff --git a/storage/MerkleTree.h b/storage/MerkleTree.h index 9234a94d1..551eddc3e 100644 --- a/storage/MerkleTree.h +++ b/storage/MerkleTree.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/optional.h" diff --git a/storage/NodeActor.cpp b/storage/NodeActor.cpp index 63e49989d..434a3d628 100644 --- a/storage/NodeActor.cpp +++ b/storage/NodeActor.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "NodeActor.h" #include "vm/boc.h" diff --git a/storage/NodeActor.h b/storage/NodeActor.h index 3b4f57e55..79c78b7bc 100644 --- a/storage/NodeActor.h +++ b/storage/NodeActor.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "LoadSpeed.h" diff --git a/storage/PartsHelper.h b/storage/PartsHelper.h index 0f76c352f..1fe0558dc 100644 --- a/storage/PartsHelper.h +++ b/storage/PartsHelper.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "PeerState.h" #include "Bitset.h" diff --git a/storage/PeerActor.cpp b/storage/PeerActor.cpp index 4b23ba49b..51ec20d25 100644 --- a/storage/PeerActor.cpp +++ b/storage/PeerActor.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "PeerActor.h" #include "auto/tl/ton_api.hpp" diff --git a/storage/PeerActor.h b/storage/PeerActor.h index 397d76a81..cc72496db 100644 --- a/storage/PeerActor.h +++ b/storage/PeerActor.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "Bitset.h" diff --git a/storage/PeerState.cpp b/storage/PeerState.cpp index 3c1657306..35d27e43a 100644 --- a/storage/PeerState.cpp +++ b/storage/PeerState.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "PeerState.h" namespace ton { void PeerState::notify_node() { diff --git a/storage/PeerState.h b/storage/PeerState.h index 0e948d7e5..3a3595f2c 100644 --- a/storage/PeerState.h +++ b/storage/PeerState.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/buffer.h" #include "td/utils/common.h" diff --git a/storage/SharedState.h b/storage/SharedState.h index 0d5297522..75b02e914 100644 --- a/storage/SharedState.h +++ b/storage/SharedState.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include diff --git a/storage/Torrent.cpp b/storage/Torrent.cpp index 3c1464f79..2012d0535 100644 --- a/storage/Torrent.cpp +++ b/storage/Torrent.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "Torrent.h" #include "td/utils/Status.h" diff --git a/storage/Torrent.h b/storage/Torrent.h index baa1d7a5c..a335c4b43 100644 --- a/storage/Torrent.h +++ b/storage/Torrent.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "MerkleTree.h" #include "TorrentMeta.h" diff --git a/storage/TorrentCreator.cpp b/storage/TorrentCreator.cpp index 640a2b853..cdd2e4cf9 100644 --- a/storage/TorrentCreator.cpp +++ b/storage/TorrentCreator.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "TorrentCreator.h" #include "td/db/utils/CyclicBuffer.h" diff --git a/storage/TorrentCreator.h b/storage/TorrentCreator.h index 8e80a0d05..5d8d7a1ca 100644 --- a/storage/TorrentCreator.h +++ b/storage/TorrentCreator.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "Torrent.h" diff --git a/storage/TorrentHeader.cpp b/storage/TorrentHeader.cpp index b8bb58295..dc3ae265f 100644 --- a/storage/TorrentHeader.cpp +++ b/storage/TorrentHeader.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "TorrentHeader.hpp" #include "td/utils/tl_helpers.h" diff --git a/storage/TorrentHeader.h b/storage/TorrentHeader.h index a2fde56b2..6a13855dc 100644 --- a/storage/TorrentHeader.h +++ b/storage/TorrentHeader.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/Slice.h" diff --git a/storage/TorrentHeader.hpp b/storage/TorrentHeader.hpp index c2fd2c48d..2b84ccb08 100644 --- a/storage/TorrentHeader.hpp +++ b/storage/TorrentHeader.hpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/tl_helpers.h" diff --git a/storage/TorrentInfo.cpp b/storage/TorrentInfo.cpp index bd6b4cc60..46c1cf69b 100644 --- a/storage/TorrentInfo.cpp +++ b/storage/TorrentInfo.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "TorrentInfo.h" #include "vm/cells/CellString.h" diff --git a/storage/TorrentInfo.h b/storage/TorrentInfo.h index ff95c3b56..fd4778fa4 100644 --- a/storage/TorrentInfo.h +++ b/storage/TorrentInfo.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "td/utils/Slice.h" diff --git a/storage/TorrentMeta.cpp b/storage/TorrentMeta.cpp index 4b6745f16..0e6777157 100644 --- a/storage/TorrentMeta.cpp +++ b/storage/TorrentMeta.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "TorrentMeta.h" #include "TorrentHeader.hpp" diff --git a/storage/TorrentMeta.h b/storage/TorrentMeta.h index 8b7c33773..cfa2b8b0b 100644 --- a/storage/TorrentMeta.h +++ b/storage/TorrentMeta.h @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #pragma once #include "TorrentHeader.h" diff --git a/storage/storage-cli.cpp b/storage/storage-cli.cpp index 65fb40879..beb05cba9 100644 --- a/storage/storage-cli.cpp +++ b/storage/storage-cli.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "adnl/adnl.h" #include "common/bigint.hpp" #include "common/bitstring.h" @@ -11,7 +30,7 @@ #include "td/utils/port/signals.h" #include "td/utils/Parser.h" #include "td/utils/overloaded.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/PathView.h" #include "td/utils/Random.h" #include "td/utils/misc.h" @@ -807,37 +826,27 @@ int main(int argc, char *argv[]) { td::set_default_failure_signal_handler(); StorageCliOptions options; - td::OptionsParser p; + td::OptionParser p; p.set_description("experimental cli for ton storage"); p.add_option('h', "help", "prints_help", [&]() { std::cout << (PSLICE() << p).c_str(); std::exit(2); - return td::Status::OK(); }); - p.add_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { + p.add_checked_option('v', "verbosity", "set verbosity level", [&](td::Slice arg) { auto verbosity = td::to_integer(arg); SET_VERBOSITY_LEVEL(VERBOSITY_NAME(FATAL) + verbosity); return (verbosity >= 0 && verbosity <= 20) ? td::Status::OK() : td::Status::Error("verbosity must be 0..20"); }); - p.add_option('C', "config", "set ton config", [&](td::Slice arg) { - options.config = arg.str(); - return td::Status::OK(); - }); - p.add_option('D', "db", "root for dbs", [&](td::Slice fname) { - options.db_root = fname.str(); - return td::Status::OK(); - }); - p.add_option('I', "ip", "set ip:port", [&](td::Slice arg) { + p.add_option('C', "config", "set ton config", [&](td::Slice arg) { options.config = arg.str(); }); + p.add_option('D', "db", "root for dbs", [&](td::Slice fname) { options.db_root = fname.str(); }); + p.add_checked_option('I', "ip", "set ip:port", [&](td::Slice arg) { td::IPAddress addr; TRY_STATUS(addr.init_host_port(arg.str())); options.addr = addr; return td::Status::OK(); }); - p.add_option('E', "execute", "execute one command", [&](td::Slice arg) { - options.cmd = arg.str(); - return td::Status::OK(); - }); - p.add_option('d', "dir", "working directory", [&](td::Slice arg) { return td::chdir(arg.str()); }); + p.add_option('E', "execute", "execute one command", [&](td::Slice arg) { options.cmd = arg.str(); }); + p.add_checked_option('d', "dir", "working directory", [&](td::Slice arg) { return td::chdir(arg.str()); }); auto S = p.run(argc, argv); if (S.is_error()) { diff --git a/storage/test/storage.cpp b/storage/test/storage.cpp index c15cab85a..7bdd03de0 100644 --- a/storage/test/storage.cpp +++ b/storage/test/storage.cpp @@ -1,3 +1,22 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + #include "td/utils/benchmark.h" #include "td/utils/crypto.h" #include "td/utils/Container.h" diff --git a/tddb/td/db/utils/BlobView.cpp b/tddb/td/db/utils/BlobView.cpp index 213b73610..7011a00ed 100644 --- a/tddb/td/db/utils/BlobView.cpp +++ b/tddb/td/db/utils/BlobView.cpp @@ -14,7 +14,7 @@ You should have received a copy of the GNU Lesser General Public License along with TON Blockchain Library. If not, see . - Copyright 2017-2019 Telegram Systems LLP + Copyright 2017-2020 Telegram Systems LLP */ #include "td/db/utils/BlobView.h" diff --git a/tddb/td/db/utils/BlobView.h b/tddb/td/db/utils/BlobView.h index 5ae69b69a..8e2dcfc27 100644 --- a/tddb/td/db/utils/BlobView.h +++ b/tddb/td/db/utils/BlobView.h @@ -14,10 +14,11 @@ You should have received a copy of the GNU Lesser General Public License along with TON Blockchain Library. If not, see . - Copyright 2017-2019 Telegram Systems LLP + Copyright 2017-2020 Telegram Systems LLP */ #pragma once #include "td/utils/buffer.h" +#include "td/utils/Status.h" namespace td { class BlobViewImpl; diff --git a/tddb/td/db/utils/StreamInterface.h b/tddb/td/db/utils/StreamInterface.h index 68b853c4a..5262f3df5 100644 --- a/tddb/td/db/utils/StreamInterface.h +++ b/tddb/td/db/utils/StreamInterface.h @@ -20,6 +20,7 @@ #include "td/utils/buffer.h" #include "td/utils/Slice.h" #include "td/utils/Span.h" +#include "td/utils/Status.h" #include "td/utils/port/IoSlice.h" namespace td { diff --git a/tddb/test/io-bench.cpp b/tddb/test/io-bench.cpp index 084e7c6c2..833f6b2a9 100644 --- a/tddb/test/io-bench.cpp +++ b/tddb/test/io-bench.cpp @@ -25,7 +25,7 @@ Copyright 2017-2020 Telegram Systems LLP */ -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/filesystem.h" #include "td/utils/port/FileFd.h" #include "td/utils/Timer.h" @@ -598,12 +598,13 @@ int main(int argc, char **argv) { Mode mode = Baseline; size_t buffer_size = 1024; - td::OptionsParser options_parser; - options_parser.add_option('f', td::Slice("from"), td::Slice("read from file"), [&](td::Slice arg) -> td::Status { - from = arg.str(); - return td::Status::OK(); - }); - options_parser.add_option('m', td::Slice("mode"), td::Slice("mode"), [&](td::Slice arg) -> td::Status { + td::OptionParser options_parser; + options_parser.add_checked_option('f', td::Slice("from"), td::Slice("read from file"), + [&](td::Slice arg) -> td::Status { + from = arg.str(); + return td::Status::OK(); + }); + options_parser.add_checked_option('m', td::Slice("mode"), td::Slice("mode"), [&](td::Slice arg) -> td::Status { TRY_RESULT(x, td::to_integer_safe(arg)); switch (x) { case 0: @@ -627,11 +628,12 @@ int main(int argc, char **argv) { } return td::Status::Error("unknown mode"); }); - options_parser.add_option('b', td::Slice("buffer"), td::Slice("buffer size"), [&](td::Slice arg) -> td::Status { - TRY_RESULT(x, td::to_integer_safe(arg)); - buffer_size = x; - return td::Status::OK(); - }); + options_parser.add_checked_option('b', td::Slice("buffer"), td::Slice("buffer size"), + [&](td::Slice arg) -> td::Status { + TRY_RESULT(x, td::to_integer_safe(arg)); + buffer_size = x; + return td::Status::OK(); + }); auto status = options_parser.run(argc, argv); if (status.is_error()) { diff --git a/tdfec/td/fec/fec.h b/tdfec/td/fec/fec.h index dd50dde96..0cd61ccb9 100644 --- a/tdfec/td/fec/fec.h +++ b/tdfec/td/fec/fec.h @@ -19,6 +19,7 @@ #pragma once #include "td/utils/buffer.h" +#include "td/utils/Status.h" namespace td { namespace raptorq { diff --git a/tdnet/example/tcp_ping_pong.cpp b/tdnet/example/tcp_ping_pong.cpp index 9bcbee990..2c4792423 100644 --- a/tdnet/example/tcp_ping_pong.cpp +++ b/tdnet/example/tcp_ping_pong.cpp @@ -28,7 +28,7 @@ #include "td/actor/actor.h" #include "td/utils/BufferedFd.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/port/SocketFd.h" #include "td/utils/port/ServerSocketFd.h" #include "td/utils/Observer.h" @@ -105,19 +105,14 @@ class PingClient : public td::actor::Actor, td::ObserverBase { }; int main(int argc, char *argv[]) { - td::OptionsParser options_parser; + td::OptionParser options_parser; options_parser.set_description("Tcp ping server/client (based on td::actors2)"); int port = 8081; bool is_client = false; - options_parser.add_option('p', "port", "listen/connect to tcp port (8081 by default)", [&](td::Slice arg) { - port = td::to_integer(arg); - return td::Status::OK(); - }); - options_parser.add_option('c', "client", "Work as client (server by default)", [&]() { - is_client = true; - return td::Status::OK(); - }); + options_parser.add_option('p', "port", "listen/connect to tcp port (8081 by default)", + [&](td::Slice arg) { port = td::to_integer(arg); }); + options_parser.add_option('c', "client", "Work as client (server by default)", [&]() { is_client = true; }); auto status = options_parser.run(argc, argv); if (status.is_error()) { LOG(ERROR) << status.error(); diff --git a/tdnet/example/udp_ping_pong.cpp b/tdnet/example/udp_ping_pong.cpp index 069380a71..78154a775 100644 --- a/tdnet/example/udp_ping_pong.cpp +++ b/tdnet/example/udp_ping_pong.cpp @@ -27,7 +27,7 @@ */ #include "td/actor/actor.h" -#include "td/utils/OptionsParser.h" +#include "td/utils/OptionParser.h" #include "td/utils/Observer.h" #include "td/utils/port/UdpSocketFd.h" @@ -113,21 +113,15 @@ class PingPong : public td::actor::Actor { }; int main(int argc, char *argv[]) { - td::OptionsParser options_parser; + td::OptionParser options_parser; options_parser.set_description("Udp ping server/client (8083 <-> 8084) (based on td::actors2)"); int from_port = 8083; int to_port = 8084; bool is_client = false; bool use_tcp = false; - options_parser.add_option('c', "client", "Work as client (server by default)", [&]() { - is_client = true; - return td::Status::OK(); - }); - options_parser.add_option('t', "tcp", "Use tcp (udp by default)", [&]() { - use_tcp = true; - return td::Status::OK(); - }); + options_parser.add_option('c', "client", "Work as client (server by default)", [&]() { is_client = true; }); + options_parser.add_option('t', "tcp", "Use tcp (udp by default)", [&]() { use_tcp = true; }); auto status = options_parser.run(argc, argv); if (status.is_error()) { LOG(ERROR) << status.error(); diff --git a/tdtl/td/tl/tl_simple.h b/tdtl/td/tl/tl_simple.h index 5a0af816b..dd5a1e53a 100644 --- a/tdtl/td/tl/tl_simple.h +++ b/tdtl/td/tl/tl_simple.h @@ -28,10 +28,11 @@ #include #include +#include + namespace td { namespace tl { namespace simple { -// TL type is std::string gen_cpp_name(std::string name) { for (std::size_t i = 0; i < name.size(); i++) { @@ -92,6 +93,9 @@ struct Constructor { struct CustomType { std::string name; std::vector constructors; + + mutable bool is_result_{false}; + mutable bool is_query_{false}; }; struct Function { @@ -120,6 +124,23 @@ class Schema { auto *from_function = config.get_function_by_num(function_num); functions.push_back(get_function(from_function)); } + for (auto &function : functions_) { + mark_result(function->type); + for (auto &arg : function->args) { + mark_query(arg.type); + } + } + + //for (auto custom_type : custom_types) { + //std::cerr << custom_type->name; + //if (custom_type->is_result_) { + //std::cerr << " result"; + //} + //if (custom_type->is_query_) { + //std::cerr << " query"; + //} + //std::cerr << std::endl; + //} } std::vector custom_types; @@ -136,6 +157,34 @@ class Schema { std::map constructor_by_id; std::map function_by_id; + void mark_result(const Type *type) { + do_mark(type, true); + } + + void mark_query(const Type *type) { + do_mark(type, false); + } + + void do_mark(const Type *type, bool is_result) { + if (type->type == Type::Vector) { + return do_mark(type->vector_value_type, is_result); + } + if (type->type != Type::Custom) { + return; + } + auto *custom = type->custom; + auto &was = is_result ? custom->is_result_ : custom->is_query_; + if (was) { + return; + } + was = true; + for (auto constructor : custom->constructors) { + for (auto &arg : constructor->args) { + do_mark(arg.type, is_result); + } + } + } + const Type *get_type(const tl_type *from_type) { auto &type = type_by_id[from_type->id]; if (!type) { @@ -185,6 +234,7 @@ class Schema { } return type; } + const CustomType *get_custom_type(const tl_type *from_type) { auto *type = get_type(from_type); assert(type->type == Type::Custom); @@ -208,6 +258,7 @@ class Schema { } return constructor; } + const Function *get_function(const tl_combinator *from) { auto &function = function_by_id[from->id]; if (!function) { @@ -225,6 +276,7 @@ class Schema { } return function; } + const Type *get_type(const tl_tree *tree) { assert(tree->get_type() == NODE_TYPE_TYPE); auto *type_tree = static_cast(tree); diff --git a/tdutils/CMakeLists.txt b/tdutils/CMakeLists.txt index 721a32b7d..4f7928d47 100644 --- a/tdutils/CMakeLists.txt +++ b/tdutils/CMakeLists.txt @@ -10,6 +10,10 @@ else() set(TD_HAVE_GETOPT 1) endif() +if (NOT DEFINED CMAKE_INSTALL_LIBDIR) + set(CMAKE_INSTALL_LIBDIR "lib") +endif() + if (NOT ZLIB_FOUND) find_package(ZLIB) endif() @@ -67,6 +71,8 @@ set(TDUTILS_SOURCE td/utils/port/thread_local.cpp td/utils/port/user.cpp td/utils/port/UdpSocketFd.cpp + td/utils/port/uname.cpp + td/utils/port/user.cpp td/utils/port/wstring_convert.cpp td/utils/port/detail/Epoll.cpp @@ -79,6 +85,7 @@ set(TDUTILS_SOURCE td/utils/port/detail/Poll.cpp td/utils/port/detail/Select.cpp td/utils/port/detail/ThreadIdGuard.cpp + td/utils/port/detail/ThreadPthread.cpp td/utils/port/detail/WineventPoll.cpp ${TDMIME_AUTO} @@ -100,10 +107,11 @@ set(TDUTILS_SOURCE td/utils/logging.cpp td/utils/misc.cpp td/utils/MpmcQueue.cpp - td/utils/OptionsParser.cpp + td/utils/OptionParser.cpp + td/utils/PathView.cpp td/utils/Random.cpp - td/utils/Slice.cpp td/utils/SharedSlice.cpp + td/utils/Slice.cpp td/utils/StackAllocator.cpp td/utils/Status.cpp td/utils/StringBuilder.cpp @@ -113,6 +121,7 @@ set(TDUTILS_SOURCE td/utils/tests.cpp td/utils/tl_parsers.cpp td/utils/translit.cpp + td/utils/TsFileLog.cpp td/utils/unicode.cpp td/utils/utf8.cpp @@ -143,6 +152,8 @@ set(TDUTILS_SOURCE td/utils/port/thread_local.h td/utils/port/user.h td/utils/port/UdpSocketFd.h + td/utils/port/uname.h + td/utils/port/user.h td/utils/port/wstring_convert.h td/utils/port/detail/Epoll.h @@ -155,6 +166,7 @@ set(TDUTILS_SOURCE td/utils/port/detail/Poll.h td/utils/port/detail/PollableFd.h td/utils/port/detail/Select.h + td/utils/port/detail/skip_eintr.h td/utils/port/detail/ThreadIdGuard.h td/utils/port/detail/ThreadPthread.h td/utils/port/detail/ThreadStl.h @@ -215,7 +227,7 @@ set(TDUTILS_SOURCE td/utils/ObjectPool.h td/utils/Observer.h td/utils/optional.h - td/utils/OptionsParser.h + td/utils/OptionParser.h td/utils/OrderedEventsProcessor.h td/utils/overloaded.h td/utils/Parser.h @@ -224,6 +236,7 @@ set(TDUTILS_SOURCE td/utils/Random.h td/utils/ScopeGuard.h td/utils/SharedObjectPool.h + td/utils/SharedSlice.h td/utils/Slice-decl.h td/utils/Slice.h td/utils/Span.h @@ -235,6 +248,7 @@ set(TDUTILS_SOURCE td/utils/StorerBase.h td/utils/StringBuilder.h td/utils/tests.h + td/utils/ThreadLocalStorage.h td/utils/ThreadSafeCounter.h td/utils/Time.h td/utils/TimedStat.h @@ -244,6 +258,8 @@ set(TDUTILS_SOURCE td/utils/tl_parsers.h td/utils/tl_storers.h td/utils/translit.h + td/utils/TsFileLog.h + td/utils/TsList.h td/utils/type_traits.h td/utils/UInt.h td/utils/uint128.h @@ -272,11 +288,13 @@ set(TDUTILS_TEST_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/test/HazardPointers.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/heap.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/json.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/List.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/log.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/misc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/MpmcQueue.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/MpmcWaiter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/MpscLinkQueue.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/OptionParser.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/OrderedEventsProcessor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/port.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test/pq.cpp @@ -294,7 +312,7 @@ if (WIN32) # find_library(WS2_32_LIBRARY ws2_32) # find_library(MSWSOCK_LIBRARY Mswsock) # target_link_libraries(tdutils PRIVATE ${WS2_32_LIBRARY} ${MSWSOCK_LIBRARY}) - target_link_libraries(tdutils PRIVATE ws2_32 Mswsock Normaliz) + target_link_libraries(tdutils PRIVATE ws2_32 Mswsock Normaliz psapi) endif() if (NOT CMAKE_CROSSCOMPILING AND TDUTILS_MIME_TYPE) add_dependencies(tdutils tdmime_auto) @@ -335,8 +353,6 @@ if (CMAKE_HOST_SYSTEM_NAME MATCHES "NetBSD") endif() install(TARGETS tdutils EXPORT TdTargets - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib - RUNTIME DESTINATION bin - INCLUDES DESTINATION include + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) diff --git a/tdutils/generate/mime_types.txt b/tdutils/generate/mime_types.txt index cc1fb5e34..4f8c9d324 100644 --- a/tdutils/generate/mime_types.txt +++ b/tdutils/generate/mime_types.txt @@ -565,6 +565,7 @@ application/x-tex-tfm tfm application/x-texinfo texinfo texi application/x-tgif obj application/x-tgsticker tgs +application/x-tgwallpattern tgv application/x-ustar ustar application/x-wais-source src application/x-x509-ca-cert der crt diff --git a/tdutils/td/utils/AesCtrByteFlow.h b/tdutils/td/utils/AesCtrByteFlow.h index 8ce35b49e..0b1f2408d 100644 --- a/tdutils/td/utils/AesCtrByteFlow.h +++ b/tdutils/td/utils/AesCtrByteFlow.h @@ -31,7 +31,7 @@ namespace td { class AesCtrByteFlow : public ByteFlowInplaceBase { public: void init(const UInt256 &key, const UInt128 &iv) { - state_.init(key, iv); + state_.init(as_slice(key), as_slice(iv)); } void init(AesCtrState &&state) { state_ = std::move(state); diff --git a/tdutils/td/utils/AtomicRead.h b/tdutils/td/utils/AtomicRead.h index 0eb85c6dc..7dfc59eb0 100644 --- a/tdutils/td/utils/AtomicRead.h +++ b/tdutils/td/utils/AtomicRead.h @@ -1,30 +1,22 @@ /* - This file is part of TON Blockchain source code. + This file is part of TON Blockchain Library. - TON Blockchain is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - TON Blockchain is distributed in the hope that it will be useful, + TON Blockchain Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + GNU Lesser General Public License for more details. - You should have received a copy of the GNU General Public License - along with TON Blockchain. If not, see . + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . - In addition, as a special exception, the copyright holders give permission - to link the code of portions of this program with the OpenSSL library. - You must obey the GNU General Public License in all respects for all - of the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete this - exception statement from your version. If you delete this exception statement - from all source files in the program, then also delete it here. - - Copyright 2019-2020 Telegram Systems LLP + Copyright 2017-2020 Telegram Systems LLP */ + #include #include "td/utils/common.h" diff --git a/tdutils/td/utils/BigNum.cpp b/tdutils/td/utils/BigNum.cpp index 913413520..36dde064c 100644 --- a/tdutils/td/utils/BigNum.cpp +++ b/tdutils/td/utils/BigNum.cpp @@ -28,6 +28,8 @@ char disable_linker_warning_about_empty_file_bignum_cpp TD_UNUSED; #include #include +#include + namespace td { class BigNumContext::Impl { @@ -103,8 +105,9 @@ BigNum BigNum::from_le_binary(Slice str) { #elif OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) return BigNum(make_unique(BN_lebin2bn(str.ubegin(), narrow_cast(str.size()), nullptr))); #else - LOG(FATAL) << "Unsupported from_le_binary"; - return BigNum(); + string str_copy = str.str(); + std::reverse(str_copy.begin(), str_copy.end()); + return from_binary(str_copy); #endif } @@ -133,14 +136,6 @@ BigNum BigNum::from_raw(void *openssl_big_num) { BigNum::BigNum(unique_ptr &&impl) : impl_(std::move(impl)) { } -void BigNum::ensure_const_time() { -#if !defined(OPENSSL_IS_BORINGSSL) - BN_set_flags(impl_->big_num, BN_FLG_CONSTTIME); -#else - LOG(FATAL) << "Unsupported BN_FLG_CONSTTIME"; -#endif -} - int BigNum::get_num_bits() const { return BN_num_bits(impl_->big_num); } @@ -238,8 +233,9 @@ string BigNum::to_le_binary(int exact_size) const { #endif return res; #else - LOG(FATAL) << "Unsupported to_le_binary"; - return ""; + string result = to_binary(exact_size); + std::reverse(result.begin(), result.end()); + return result; #endif } diff --git a/tdutils/td/utils/BigNum.h b/tdutils/td/utils/BigNum.h index 73e3e21e7..b0094659c 100644 --- a/tdutils/td/utils/BigNum.h +++ b/tdutils/td/utils/BigNum.h @@ -55,7 +55,6 @@ class BigNum { static BigNum from_binary(Slice str); - // Available only if OpenSSL >= 1.1.0 static BigNum from_le_binary(Slice str); static Result from_decimal(CSlice str); @@ -66,8 +65,6 @@ class BigNum { void set_value(uint32 new_value); - void ensure_const_time(); - int get_num_bits() const; int get_num_bytes() const; @@ -84,7 +81,6 @@ class BigNum { string to_binary(int exact_size = -1) const; - // Available only if OpenSSL >= 1.1.0 string to_le_binary(int exact_size = -1) const; string to_decimal() const; diff --git a/tdutils/td/utils/BufferedFd.h b/tdutils/td/utils/BufferedFd.h index 9940eb1e7..03ab73d8b 100644 --- a/tdutils/td/utils/BufferedFd.h +++ b/tdutils/td/utils/BufferedFd.h @@ -127,12 +127,12 @@ Result BufferedFdBase::flush_write() { write_->sync_with_writer(); size_t result = 0; while (!write_->empty() && ::td::can_write(*this)) { - constexpr size_t buf_size = 20; - IoSlice buf[buf_size]; + constexpr size_t BUF_SIZE = 20; + IoSlice buf[BUF_SIZE]; auto it = write_->clone(); size_t buf_i; - for (buf_i = 0; buf_i < buf_size; buf_i++) { + for (buf_i = 0; buf_i < BUF_SIZE; buf_i++) { Slice slice = it.prepare_read(); if (slice.empty()) { break; diff --git a/tdutils/td/utils/BufferedUdp.h b/tdutils/td/utils/BufferedUdp.h index 8a966c0b2..bf4aa1b80 100644 --- a/tdutils/td/utils/BufferedUdp.h +++ b/tdutils/td/utils/BufferedUdp.h @@ -76,7 +76,8 @@ class UdpReaderHelper { } private: - enum : size_t { MAX_PACKET_SIZE = 2048, RESERVED_SIZE = MAX_PACKET_SIZE * 8 }; + static constexpr size_t MAX_PACKET_SIZE = 2048; + static constexpr size_t RESERVED_SIZE = MAX_PACKET_SIZE * 8; UdpMessage message_; BufferSlice buffer_; }; @@ -110,7 +111,7 @@ class UdpReader { } private: - enum : size_t { BUFFER_SIZE = 16 }; + static constexpr size_t BUFFER_SIZE = 16; std::array messages_; std::array helpers_; }; diff --git a/tdutils/td/utils/ConcurrentHashTable.h b/tdutils/td/utils/ConcurrentHashTable.h index 95661e94d..725d1278d 100644 --- a/tdutils/td/utils/ConcurrentHashTable.h +++ b/tdutils/td/utils/ConcurrentHashTable.h @@ -121,7 +121,7 @@ class ConcurrentHashMap { ConcurrentHashMap(ConcurrentHashMap &&) = delete; ConcurrentHashMap &operator=(ConcurrentHashMap &&) = delete; ~ConcurrentHashMap() { - unique_ptr(hash_map_.load()); + unique_ptr(hash_map_.load()).reset(); } static std::string get_name() { diff --git a/tdutils/td/utils/DecTree.h b/tdutils/td/utils/DecTree.h index 786dc0b09..80bd0e21c 100644 --- a/tdutils/td/utils/DecTree.h +++ b/tdutils/td/utils/DecTree.h @@ -192,7 +192,7 @@ class DecTree { } } void insert(KeyType key, ValueType value) { - root_ = insert_node(std::move(root_), std::move(key), std::move(value), td::Random::fast_uint32()); + root_ = insert_node(std::move(root_), std::move(key), std::move(value), Random::fast_uint32()); } void remove(const KeyType &key) { root_ = remove_node(std::move(root_), key); @@ -207,7 +207,7 @@ class DecTree { if (size() == 0) { return nullptr; } else { - return get_node_by_idx(root_, td::Random::fast_uint32() % size()); + return get_node_by_idx(root_, Random::fast_uint32() % size()); } } const ValueType *get(const KeyType &key) const { @@ -217,7 +217,7 @@ class DecTree { if (size() == 0) { return nullptr; } else { - return get_node_by_idx(root_, td::Random::fast_uint32() % size()); + return get_node_by_idx(root_, Random::fast_uint32() % size()); } } bool exists(const KeyType &key) const { diff --git a/tdutils/td/utils/Enumerator.h b/tdutils/td/utils/Enumerator.h index d7bfe5125..6d301ae15 100644 --- a/tdutils/td/utils/Enumerator.h +++ b/tdutils/td/utils/Enumerator.h @@ -19,8 +19,8 @@ #pragma once #include "td/utils/common.h" -#include "td/utils/misc.h" +#include #include #include @@ -32,7 +32,8 @@ class Enumerator { using Key = int32; Key add(ValueT v) { - int32 next_id = narrow_cast(arr_.size() + 1); + CHECK(arr_.size() < static_cast(std::numeric_limits::max() - 1)); + int32 next_id = static_cast(arr_.size() + 1); bool was_inserted; decltype(map_.begin()) it; std::tie(it, was_inserted) = map_.emplace(std::move(v), next_id); diff --git a/tdutils/td/utils/EpochBasedMemoryReclamation.h b/tdutils/td/utils/EpochBasedMemoryReclamation.h index e1122ea22..becff2d72 100644 --- a/tdutils/td/utils/EpochBasedMemoryReclamation.h +++ b/tdutils/td/utils/EpochBasedMemoryReclamation.h @@ -107,13 +107,13 @@ class EpochBasedMemoryReclamation { static constexpr size_t MAX_BAGS = 3; struct ThreadData { std::atomic epoch{1}; - char pad[TD_CONCURRENCY_PAD - sizeof(epoch)]; + char pad[TD_CONCURRENCY_PAD - sizeof(std::atomic)]; size_t to_skip{0}; size_t checked_thread_i{0}; size_t bag_i{0}; std::vector> to_delete[MAX_BAGS]; - char pad2[TD_CONCURRENCY_PAD - sizeof(to_delete)]; + char pad2[TD_CONCURRENCY_PAD - sizeof(std::vector>) * MAX_BAGS]; void rotate_bags() { bag_i = (bag_i + 1) % MAX_BAGS; @@ -143,10 +143,10 @@ class EpochBasedMemoryReclamation { } }; std::vector threads_; - char pad[TD_CONCURRENCY_PAD - sizeof(threads_)]; + char pad[TD_CONCURRENCY_PAD - sizeof(std::vector)]; std::atomic epoch_{1}; - char pad2[TD_CONCURRENCY_PAD - sizeof(epoch_)]; + char pad2[TD_CONCURRENCY_PAD - sizeof(std::atomic)]; void lock(size_t thread_id) { auto &data = threads_[thread_id]; diff --git a/tdutils/td/utils/FileLog.cpp b/tdutils/td/utils/FileLog.cpp index 9dbedab7d..036969bff 100644 --- a/tdutils/td/utils/FileLog.cpp +++ b/tdutils/td/utils/FileLog.cpp @@ -30,13 +30,13 @@ namespace td { Status FileLog::init(string path, int64 rotate_threshold, bool redirect_stderr) { + if (path.empty()) { + return Status::Error("Log file path can't be empty"); + } if (path == path_) { set_rotate_threshold(rotate_threshold); return Status::OK(); } - if (path.empty()) { - return Status::Error("Log file path can't be empty"); - } TRY_RESULT(fd, FileFd::open(path, FileFd::Create | FileFd::Write | FileFd::Append)); @@ -52,8 +52,7 @@ Status FileLog::init(string path, int64 rotate_threshold, bool redirect_stderr) } else { path_ = r_path.move_as_ok(); } - TRY_RESULT(size, fd_.get_size()); - size_ = size; + TRY_RESULT_ASSIGN(size_, fd_.get_size()); rotate_threshold_ = rotate_threshold; redirect_stderr_ = redirect_stderr; return Status::OK(); diff --git a/tdutils/td/utils/FileLog.h b/tdutils/td/utils/FileLog.h index 68bb7e7e8..0bdbddf01 100644 --- a/tdutils/td/utils/FileLog.h +++ b/tdutils/td/utils/FileLog.h @@ -53,7 +53,7 @@ class FileLog : public LogInterface { string path_; int64 size_ = 0; int64 rotate_threshold_ = 0; - bool redirect_stderr_; + bool redirect_stderr_ = false; std::atomic want_rotate_{}; void do_rotate(); diff --git a/tdutils/td/utils/Gzip.cpp b/tdutils/td/utils/Gzip.cpp index 00af44513..5fa764b83 100644 --- a/tdutils/td/utils/Gzip.cpp +++ b/tdutils/td/utils/Gzip.cpp @@ -45,9 +45,9 @@ class Gzip::Impl { }; Status Gzip::init_encode() { - CHECK(mode_ == Empty); + CHECK(mode_ == Mode::Empty); init_common(); - mode_ = Encode; + mode_ = Mode::Encode; int ret = deflateInit2(&impl_->stream_, 6, Z_DEFLATED, 15, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); if (ret != Z_OK) { return Status::Error(PSLICE() << "zlib deflate init failed: " << ret); @@ -56,9 +56,9 @@ Status Gzip::init_encode() { } Status Gzip::init_decode() { - CHECK(mode_ == Empty); + CHECK(mode_ == Mode::Empty); init_common(); - mode_ = Decode; + mode_ = Mode::Decode; int ret = inflateInit2(&impl_->stream_, MAX_WBITS + 32); if (ret != Z_OK) { return Status::Error(PSLICE() << "zlib inflate init failed: " << ret); @@ -88,19 +88,19 @@ void Gzip::set_output(MutableSlice output) { Result Gzip::run() { while (true) { int ret; - if (mode_ == Decode) { + if (mode_ == Mode::Decode) { ret = inflate(&impl_->stream_, Z_NO_FLUSH); } else { ret = deflate(&impl_->stream_, close_input_flag_ ? Z_FINISH : Z_NO_FLUSH); } if (ret == Z_OK) { - return Running; + return State::Running; } if (ret == Z_STREAM_END) { // TODO(now): fail if input is not empty; clear(); - return Done; + return State::Done; } clear(); return Status::Error(PSLICE() << "zlib error " << ret); @@ -131,12 +131,12 @@ void Gzip::init_common() { } void Gzip::clear() { - if (mode_ == Decode) { + if (mode_ == Mode::Decode) { inflateEnd(&impl_->stream_); - } else if (mode_ == Encode) { + } else if (mode_ == Mode::Encode) { deflateEnd(&impl_->stream_); } - mode_ = Empty; + mode_ = Mode::Empty; } Gzip::Gzip() : impl_(make_unique()) { @@ -180,7 +180,7 @@ BufferSlice gzdecode(Slice s) { return BufferSlice(); } auto state = r_state.ok(); - if (state == Gzip::Done) { + if (state == Gzip::State::Done) { message.confirm_append(gzip.flush_output()); break; } @@ -196,12 +196,12 @@ BufferSlice gzdecode(Slice s) { return message.extract_reader().move_as_buffer_slice(); } -BufferSlice gzencode(Slice s, double k) { +BufferSlice gzencode(Slice s, double max_compression_ratio) { Gzip gzip; gzip.init_encode().ensure(); gzip.set_input(s); gzip.close_input(); - size_t max_size = static_cast(static_cast(s.size()) * k); + size_t max_size = static_cast(static_cast(s.size()) * max_compression_ratio); BufferWriter message{max_size}; gzip.set_output(message.prepare_append()); auto r_state = gzip.run(); @@ -209,7 +209,7 @@ BufferSlice gzencode(Slice s, double k) { return BufferSlice(); } auto state = r_state.ok(); - if (state != Gzip::Done) { + if (state != Gzip::State::Done) { return BufferSlice(); } message.confirm_append(gzip.flush_output()); diff --git a/tdutils/td/utils/Gzip.h b/tdutils/td/utils/Gzip.h index 0b890c757..63e871116 100644 --- a/tdutils/td/utils/Gzip.h +++ b/tdutils/td/utils/Gzip.h @@ -36,11 +36,11 @@ class Gzip { Gzip &operator=(Gzip &&other); ~Gzip(); - enum Mode { Empty, Encode, Decode }; + enum class Mode { Empty, Encode, Decode }; Status init(Mode mode) TD_WARN_UNUSED_RESULT { - if (mode == Encode) { + if (mode == Mode::Encode) { return init_encode(); - } else if (mode == Decode) { + } else if (mode == Mode::Decode) { return init_decode(); } clear(); @@ -91,7 +91,7 @@ class Gzip { return res; } - enum State { Running, Done }; + enum class State { Running, Done }; Result run() TD_WARN_UNUSED_RESULT; private: @@ -101,7 +101,7 @@ class Gzip { size_t input_size_ = 0; size_t output_size_ = 0; bool close_input_flag_ = false; - Mode mode_ = Empty; + Mode mode_ = Mode::Empty; void init_common(); void clear(); @@ -111,7 +111,7 @@ class Gzip { BufferSlice gzdecode(Slice s); -BufferSlice gzencode(Slice s, double k = 0.9); +BufferSlice gzencode(Slice s, double max_compression_ratio); } // namespace td diff --git a/tdutils/td/utils/GzipByteFlow.cpp b/tdutils/td/utils/GzipByteFlow.cpp index 4d61a222e..5cce04eda 100644 --- a/tdutils/td/utils/GzipByteFlow.cpp +++ b/tdutils/td/utils/GzipByteFlow.cpp @@ -64,7 +64,7 @@ void GzipByteFlow::loop() { return finish(r_state.move_as_error()); } auto state = r_state.ok(); - if (state == Gzip::Done) { + if (state == Gzip::State::Done) { on_output_updated(); return consume_input(); } diff --git a/tdutils/td/utils/HazardPointers.h b/tdutils/td/utils/HazardPointers.h index 418492215..954d6efdc 100644 --- a/tdutils/td/utils/HazardPointers.h +++ b/tdutils/td/utils/HazardPointers.h @@ -109,14 +109,14 @@ class HazardPointers { private: struct ThreadData { std::array, MaxPointersN> hazard_; - char pad[TD_CONCURRENCY_PAD - sizeof(hazard_)]; + char pad[TD_CONCURRENCY_PAD - sizeof(std::array, MaxPointersN>)]; // stupid gc std::vector> to_delete_; - char pad2[TD_CONCURRENCY_PAD - sizeof(to_delete_)]; + char pad2[TD_CONCURRENCY_PAD - sizeof(std::vector>)]; }; std::vector threads_; - char pad2[TD_CONCURRENCY_PAD - sizeof(threads_)]; + char pad2[TD_CONCURRENCY_PAD - sizeof(std::vector)]; template static S *do_protect(std::atomic &hazard_ptr, std::atomic &to_protect) { diff --git a/tdutils/td/utils/Hints.cpp b/tdutils/td/utils/Hints.cpp index b21a93ddb..0b8987df4 100644 --- a/tdutils/td/utils/Hints.cpp +++ b/tdutils/td/utils/Hints.cpp @@ -80,7 +80,7 @@ vector Hints::get_words(Slice name, bool is_search) { void Hints::add_word(const string &word, KeyT key, std::map> &word_to_keys) { vector &keys = word_to_keys[word]; - CHECK(std::find(keys.begin(), keys.end(), key) == keys.end()); + CHECK(!td::contains(keys, key)); keys.push_back(key); } diff --git a/tdutils/td/utils/HttpUrl.cpp b/tdutils/td/utils/HttpUrl.cpp index 2a73f2286..6e2d1c4d5 100644 --- a/tdutils/td/utils/HttpUrl.cpp +++ b/tdutils/td/utils/HttpUrl.cpp @@ -22,16 +22,17 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Parser.h" +#include "td/utils/port/IPAddress.h" namespace td { string HttpUrl::get_url() const { string result; switch (protocol_) { - case Protocol::HTTP: + case Protocol::Http: result += "http://"; break; - case Protocol::HTTPS: + case Protocol::Https: result += "https://"; break; default: @@ -41,13 +42,7 @@ string HttpUrl::get_url() const { result += userinfo_; result += '@'; } - if (is_ipv6_) { - result += '['; - } result += host_; - if (is_ipv6_) { - result += ']'; - } if (specified_port_ > 0) { result += ':'; result += to_string(specified_port_); @@ -60,15 +55,15 @@ string HttpUrl::get_url() const { Result parse_url(Slice url, HttpUrl::Protocol default_protocol) { // url == [https?://][userinfo@]host[:port] ConstParser parser(url); - string protocol_str = to_lower(parser.read_till_nofail(':')); + string protocol_str = to_lower(parser.read_till_nofail(":/?#@[]")); HttpUrl::Protocol protocol; if (parser.start_with("://")) { parser.advance(3); if (protocol_str == "http") { - protocol = HttpUrl::Protocol::HTTP; + protocol = HttpUrl::Protocol::Http; } else if (protocol_str == "https") { - protocol = HttpUrl::Protocol::HTTPS; + protocol = HttpUrl::Protocol::Https; } else { return Status::Error("Unsupported URL protocol"); } @@ -100,8 +95,11 @@ Result parse_url(Slice url, HttpUrl::Protocol default_protocol) { bool is_ipv6 = false; if (!host.empty() && host[0] == '[' && host.back() == ']') { - host.remove_prefix(1); - host.remove_suffix(1); + IPAddress ip_address; + if (ip_address.init_ipv6_port(host.str(), 1).is_error()) { + return Status::Error("Wrong IPv6 address specified in the URL"); + } + CHECK(ip_address.is_ipv6()); is_ipv6 = true; } if (host.empty()) { @@ -113,10 +111,10 @@ Result parse_url(Slice url, HttpUrl::Protocol default_protocol) { int specified_port = port; if (port == 0) { - if (protocol == HttpUrl::Protocol::HTTP) { + if (protocol == HttpUrl::Protocol::Http) { port = 80; } else { - CHECK(protocol == HttpUrl::Protocol::HTTPS); + CHECK(protocol == HttpUrl::Protocol::Https); port = 443; } } @@ -183,7 +181,7 @@ Result parse_url(Slice url, HttpUrl::Protocol default_protocol) { } StringBuilder &operator<<(StringBuilder &sb, const HttpUrl &url) { - sb << tag("protocol", url.protocol_ == HttpUrl::Protocol::HTTP ? "HTTP" : "HTTPS") << tag("userinfo", url.userinfo_) + sb << tag("protocol", url.protocol_ == HttpUrl::Protocol::Http ? "HTTP" : "HTTPS") << tag("userinfo", url.userinfo_) << tag("host", url.host_) << tag("port", url.port_) << tag("query", url.query_); return sb; } diff --git a/tdutils/td/utils/HttpUrl.h b/tdutils/td/utils/HttpUrl.h index a4e0ab6f2..f1ce84aee 100644 --- a/tdutils/td/utils/HttpUrl.h +++ b/tdutils/td/utils/HttpUrl.h @@ -27,7 +27,7 @@ namespace td { class HttpUrl { public: - enum class Protocol { HTTP, HTTPS } protocol_ = Protocol::HTTP; + enum class Protocol { Http, Https } protocol_ = Protocol::Http; string userinfo_; string host_; bool is_ipv6_ = false; @@ -49,7 +49,7 @@ class HttpUrl { }; Result parse_url(Slice url, - HttpUrl::Protocol default_protocol = HttpUrl::Protocol::HTTP) TD_WARN_UNUSED_RESULT; + HttpUrl::Protocol default_protocol = HttpUrl::Protocol::Http) TD_WARN_UNUSED_RESULT; StringBuilder &operator<<(StringBuilder &sb, const HttpUrl &url); diff --git a/tdutils/td/utils/JsonBuilder.cpp b/tdutils/td/utils/JsonBuilder.cpp index 7a8447401..b858db663 100644 --- a/tdutils/td/utils/JsonBuilder.cpp +++ b/tdutils/td/utils/JsonBuilder.cpp @@ -605,6 +605,15 @@ bool has_json_object_field(const JsonObject &object, Slice name) { return false; } +JsonValue get_json_object_field_force(JsonObject &object, Slice name) { + for (auto &field_value : object) { + if (field_value.first == name) { + return std::move(field_value.second); + } + } + return JsonValue(); +} + Result get_json_object_field(JsonObject &object, Slice name, JsonValue::Type type, bool is_optional) { for (auto &field_value : object) { if (field_value.first == name) { diff --git a/tdutils/td/utils/JsonBuilder.h b/tdutils/td/utils/JsonBuilder.h index d67af2834..823cca4b8 100644 --- a/tdutils/td/utils/JsonBuilder.h +++ b/tdutils/td/utils/JsonBuilder.h @@ -27,20 +27,11 @@ #include "td/utils/StringBuilder.h" #include -#include #include #include namespace td { -template -std::tuple ctie(const Args &... args) TD_WARN_UNUSED_RESULT; - -template -std::tuple ctie(const Args &... args) { - return std::tie(args...); -} - class JsonTrue { public: friend StringBuilder &operator<<(StringBuilder &sb, const JsonTrue &val) { @@ -210,8 +201,11 @@ class JsonBuilder { return offset_ >= 0; } void print_offset() { - for (int x = 0; x < offset_; x++) { - sb_ << " "; + if (offset_ >= 0) { + sb_ << '\n'; + for (int x = 0; x < offset_; x++) { + sb_ << " "; + } } } void dec_offset() { @@ -307,9 +301,7 @@ class JsonScope { *sb_ << x; return *this; } - JsonScope &operator<<(bool x) { - return *this << JsonBool(x); - } + JsonScope &operator<<(bool x) = delete; JsonScope &operator<<(int32 x) { return *this << JsonInt(x); } @@ -319,8 +311,6 @@ class JsonScope { JsonScope &operator<<(double x) { return *this << JsonFloat(x); } - template - JsonScope &operator<<(const T *x); // not implemented template JsonScope &operator<<(const char (&x)[N]) { return *this << JsonString(Slice(x)); @@ -328,9 +318,6 @@ class JsonScope { JsonScope &operator<<(const char *x) { return *this << JsonString(Slice(x)); } - JsonScope &operator<<(const string &x) { - return *this << JsonString(Slice(x)); - } JsonScope &operator<<(Slice x) { return *this << JsonString(x); } @@ -428,16 +415,8 @@ class JsonObjectScope : public JsonScope { } *sb_ << "}"; } - template - JsonObjectScope &operator<<(std::tuple key_value) { - return (*this)(std::get<0>(key_value), std::get<1>(key_value)); - } - template - JsonObjectScope &operator<<(std::pair key_value) { - return (*this)(key_value.first, key_value.second); - } - template - JsonObjectScope &operator()(S &&key, T &&value) { + template + JsonObjectScope &operator()(Slice key, T &&value) { CHECK(is_active()); if (is_first_) { *sb_ << ","; @@ -624,7 +603,7 @@ class JsonValue : public Jsonable { case Type::Object: { auto object = scope->enter_object(); for (auto &key_value : get_object()) { - object << ctie(JsonString(key_value.first), key_value.second); + object(key_value.first, key_value.second); } break; } @@ -846,6 +825,7 @@ class JsonObjectImpl : Jsonable { private: F f_; }; + template auto json_object(F &&f) { return JsonObjectImpl(std::forward(f)); @@ -881,6 +861,8 @@ auto json_array(const A &a, F &&f) { bool has_json_object_field(const JsonObject &object, Slice name); +JsonValue get_json_object_field_force(JsonObject &object, Slice name) TD_WARN_UNUSED_RESULT; + Result get_json_object_field(JsonObject &object, Slice name, JsonValue::Type type, bool is_optional = true) TD_WARN_UNUSED_RESULT; diff --git a/tdutils/td/utils/List.h b/tdutils/td/utils/List.h index 4f3c38895..ebd2da06b 100644 --- a/tdutils/td/utils/List.h +++ b/tdutils/td/utils/List.h @@ -40,19 +40,19 @@ struct ListNode { if (other.empty()) { clear(); } else { - ListNode *head = other.prev; - other.remove(); - head->put(this); + init_from(std::move(other)); } } ListNode &operator=(ListNode &&other) { + if (this == &other) { + return *this; + } + this->remove(); if (!other.empty()) { - ListNode *head = other.prev; - other.remove(); - head->put(this); + init_from(std::move(other)); } return *this; @@ -70,11 +70,12 @@ struct ListNode { } void put(ListNode *other) { - other->connect(next); - this->connect(other); + DCHECK(other->empty()); + put_unsafe(other); } void put_back(ListNode *other) { + DCHECK(other->empty()); prev->connect(other); other->connect(this); } @@ -94,11 +95,35 @@ struct ListNode { return next == this; } - private: + ListNode *begin() { + return next; + } + ListNode *end() { + return this; + } + ListNode *get_next() { + return next; + } + ListNode *get_prev() { + return prev; + } + + protected: void clear() { next = this; prev = this; } + + void init_from(ListNode &&other) { + ListNode *head = other.prev; + other.remove(); + head->put_unsafe(this); + } + + void put_unsafe(ListNode *other) { + other->connect(next); + this->connect(other); + } }; } // namespace td diff --git a/tdutils/td/utils/MemoryLog.h b/tdutils/td/utils/MemoryLog.h index 92bb0d76f..6e78d7750 100644 --- a/tdutils/td/utils/MemoryLog.h +++ b/tdutils/td/utils/MemoryLog.h @@ -46,30 +46,30 @@ class MemoryLog : public LogInterface { size_t slice_size = slice.size(); CHECK(slice_size * 3 < buffer_size); size_t pad_size = ((slice_size + 15) & ~15) - slice_size; - constexpr size_t magic_size = 16; - uint32 total_size = static_cast(slice_size + pad_size + magic_size); + constexpr size_t MAGIC_SIZE = 16; + uint32 total_size = static_cast(slice_size + pad_size + MAGIC_SIZE); uint32 real_pos = pos_.fetch_add(total_size, std::memory_order_relaxed); CHECK((total_size & 15) == 0); uint32 start_pos = real_pos & (buffer_size - 1); uint32 end_pos = start_pos + total_size; if (likely(end_pos <= buffer_size)) { - std::memcpy(&buffer_[start_pos + magic_size], slice.data(), slice_size); - std::memcpy(&buffer_[start_pos + magic_size + slice_size], " ", pad_size); + std::memcpy(&buffer_[start_pos + MAGIC_SIZE], slice.data(), slice_size); + std::memcpy(&buffer_[start_pos + MAGIC_SIZE + slice_size], " ", pad_size); } else { - size_t first = buffer_size - start_pos - magic_size; + size_t first = buffer_size - start_pos - MAGIC_SIZE; size_t second = slice_size - first; - std::memcpy(&buffer_[start_pos + magic_size], slice.data(), first); + std::memcpy(&buffer_[start_pos + MAGIC_SIZE], slice.data(), first); std::memcpy(&buffer_[0], slice.data() + first, second); std::memcpy(&buffer_[second], " ", pad_size); } CHECK((start_pos & 15) == 0); - CHECK(start_pos <= buffer_size - magic_size); + CHECK(start_pos <= buffer_size - MAGIC_SIZE); buffer_[start_pos] = '\n'; - size_t printed = std::snprintf(&buffer_[start_pos + 1], magic_size - 1, "LOG:%08x: ", real_pos); - CHECK(printed == magic_size - 2); - buffer_[start_pos + magic_size - 1] = ' '; + size_t printed = std::snprintf(&buffer_[start_pos + 1], MAGIC_SIZE - 1, "LOG:%08x: ", real_pos); + CHECK(printed == MAGIC_SIZE - 2); + buffer_[start_pos + MAGIC_SIZE - 1] = ' '; if (log_level == VERBOSITY_NAME(FATAL)) { process_fatal_error(new_slice); diff --git a/tdutils/td/utils/MovableValue.h b/tdutils/td/utils/MovableValue.h index 64001a5df..c5d4f9715 100644 --- a/tdutils/td/utils/MovableValue.h +++ b/tdutils/td/utils/MovableValue.h @@ -30,8 +30,10 @@ class MovableValue { other.clear(); } MovableValue &operator=(MovableValue &&other) { - val_ = other.val_; - other.clear(); + if (this != &other) { + val_ = other.val_; + other.clear(); + } return *this; } MovableValue(const MovableValue &) = delete; diff --git a/tdutils/td/utils/MpscLinkQueue.h b/tdutils/td/utils/MpscLinkQueue.h index 831616ded..41c5ce850 100644 --- a/tdutils/td/utils/MpscLinkQueue.h +++ b/tdutils/td/utils/MpscLinkQueue.h @@ -166,7 +166,7 @@ class MpscLinkQueueUniquePtrNode { MpscLinkQueueImpl::Node *to_mpsc_link_queue_node() { return ptr_.release()->to_mpsc_link_queue_node(); } - static MpscLinkQueueUniquePtrNode from_mpsc_link_queue_node(td::MpscLinkQueueImpl::Node *node) { + static MpscLinkQueueUniquePtrNode from_mpsc_link_queue_node(MpscLinkQueueImpl::Node *node) { return MpscLinkQueueUniquePtrNode(unique_ptr(Value::from_mpsc_link_queue_node(node))); } diff --git a/tdutils/td/utils/ObjectPool.h b/tdutils/td/utils/ObjectPool.h index 12fb5f6ba..a34ef9087 100644 --- a/tdutils/td/utils/ObjectPool.h +++ b/tdutils/td/utils/ObjectPool.h @@ -57,7 +57,7 @@ class ObjectPool { // It is not very usual case of acquire/release use. // Instead of publishing an object via some flag we do the opposite. // We publish new generation via destruction of the data. - // In usual case if we see a flag then we are able to use an object. + // In usual case if we see a flag, then we are able to use an object. // In our case if we have used an object and it is already invalid, then generation will mismatch bool is_alive() const { if (!storage_) { diff --git a/tdutils/td/utils/OptionParser.cpp b/tdutils/td/utils/OptionParser.cpp new file mode 100644 index 000000000..b95848562 --- /dev/null +++ b/tdutils/td/utils/OptionParser.cpp @@ -0,0 +1,231 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ + +#include "td/utils/OptionParser.h" + +#include "td/utils/misc.h" + +#include +#include + +namespace td { + +void OptionParser::set_description(string description) { + description_ = std::move(description); +} + +void OptionParser::add_option(Option::Type type, char short_key, Slice long_key, Slice description, + std::function callback) { + for (auto &option : options_) { + if (option.short_key == short_key || (!long_key.empty() && long_key == option.long_key)) { + LOG(ERROR) << "Ignore duplicated option '" << short_key << "' '" << long_key << "'"; + } + } + options_.push_back(Option{type, short_key, long_key.str(), description.str(), std::move(callback)}); +} + +void OptionParser::add_checked_option(char short_key, Slice long_key, Slice description, + std::function callback) { + add_option(Option::Type::Arg, short_key, long_key, description, std::move(callback)); +} + +void OptionParser::add_checked_option(char short_key, Slice long_key, Slice description, + std::function callback) { + add_option(Option::Type::NoArg, short_key, long_key, description, + [callback = std::move(callback)](Slice) { return callback(); }); +} + +void OptionParser::add_option(char short_key, Slice long_key, Slice description, std::function callback) { + add_option(Option::Type::Arg, short_key, long_key, description, [callback = std::move(callback)](Slice parameter) { + callback(parameter); + return Status::OK(); + }); +} + +void OptionParser::add_option(char short_key, Slice long_key, Slice description, std::function callback) { + add_option(Option::Type::NoArg, short_key, long_key, description, [callback = std::move(callback)](Slice) { + callback(); + return Status::OK(); + }); +} + +void OptionParser::add_check(std::function check) { + checks_.push_back(std::move(check)); +} + +Result> OptionParser::run(int argc, char *argv[], int expected_non_option_count) { + std::unordered_map short_options; + std::unordered_map long_options; + for (auto &opt : options_) { + if (opt.short_key != '\0') { + short_options[opt.short_key] = &opt; + } + if (!opt.long_key.empty()) { + long_options[opt.long_key] = &opt; + } + } + + vector non_options; + for (int arg_pos = 1; arg_pos < argc; arg_pos++) { + const char *arg = argv[arg_pos]; + if (arg[0] != '-' || arg[1] == '\0') { + non_options.push_back(argv[arg_pos]); + continue; + } + if (arg[1] == '-' && arg[2] == '\0') { + // "--"; after it everything is non-option + while (++arg_pos < argc) { + non_options.push_back(argv[arg_pos]); + } + break; + } + + if (arg[1] == '-') { + // long option + Slice long_arg(arg + 2, std::strlen(arg + 2)); + Slice parameter; + auto equal_pos = long_arg.find('='); + bool has_equal = equal_pos != Slice::npos; + if (has_equal) { + parameter = long_arg.substr(equal_pos + 1); + long_arg = long_arg.substr(0, equal_pos); + } + + auto it = long_options.find(long_arg.str()); + if (it == long_options.end()) { + return Status::Error(PSLICE() << "Option " << long_arg << " was unrecognized"); + } + + auto option = it->second; + switch (option->type) { + case Option::Type::NoArg: + if (has_equal) { + return Status::Error(PSLICE() << "Option " << long_arg << " must not have argument"); + } + break; + case Option::Type::Arg: + if (!has_equal) { + if (++arg_pos == argc) { + return Status::Error(PSLICE() << "Option " << long_arg << " must have argument"); + } + parameter = Slice(argv[arg_pos], std::strlen(argv[arg_pos])); + } + break; + default: + UNREACHABLE(); + } + + TRY_STATUS(option->arg_callback(parameter)); + continue; + } + + for (size_t opt_pos = 1; arg[opt_pos] != '\0'; opt_pos++) { + auto it = short_options.find(arg[opt_pos]); + if (it == short_options.end()) { + return Status::Error(PSLICE() << "Option " << arg[opt_pos] << " was unrecognized"); + } + + auto option = it->second; + Slice parameter; + switch (option->type) { + case Option::Type::NoArg: + // nothing to do + break; + case Option::Type::Arg: + if (arg[opt_pos + 1] == '\0') { + if (++arg_pos == argc) { + return Status::Error(PSLICE() << "Option " << arg[opt_pos] << " must have argument"); + } + parameter = Slice(argv[arg_pos], std::strlen(argv[arg_pos])); + } else { + parameter = Slice(arg + opt_pos + 1, std::strlen(arg + opt_pos + 1)); + opt_pos += parameter.size(); + } + break; + default: + UNREACHABLE(); + } + + TRY_STATUS(option->arg_callback(parameter)); + } + } + if (expected_non_option_count >= 0 && non_options.size() != static_cast(expected_non_option_count)) { + if (expected_non_option_count == 0) { + return Status::Error("Unexpected non-option parameters specified"); + } + if (non_options.size() > static_cast(expected_non_option_count)) { + return Status::Error("Too much non-option parameters specified"); + } else { + return Status::Error("Too few non-option parameters specified"); + } + } + for (auto &check : checks_) { + TRY_STATUS(check()); + } + + return std::move(non_options); +} + +StringBuilder &operator<<(StringBuilder &sb, const OptionParser &o) { + if (!o.description_.empty()) { + sb << o.description_ << ". "; + } + sb << "Options:\n"; + + size_t max_length = 0; + for (auto &opt : o.options_) { + bool has_short_key = opt.short_key != '\0'; + bool has_long_key = !opt.long_key.empty(); + size_t length = (has_short_key ? 2 : 0) + (has_long_key ? 2 + opt.long_key.size() + 2 * has_short_key : 0); + if (opt.type != OptionParser::Option::Type::NoArg) { + length += 5; + } + if (length > max_length) { + max_length = length; + } + } + max_length++; + + for (auto &opt : o.options_) { + bool has_short_key = opt.short_key != '\0'; + sb << " "; + size_t length = max_length; + if (has_short_key) { + sb << '-' << opt.short_key; + length -= 2; + } + if (!opt.long_key.empty()) { + if (has_short_key) { + sb << ", "; + length -= 2; + } + sb << "--" << opt.long_key; + length -= 2 + opt.long_key.size(); + } + if (opt.type != OptionParser::Option::Type::NoArg) { + sb << ""; + length -= 5; + } + sb << string(length, ' ') << opt.description; + sb << '\n'; + } + return sb; +} + +} // namespace td diff --git a/tdutils/td/utils/OptionParser.h b/tdutils/td/utils/OptionParser.h new file mode 100644 index 000000000..92987c920 --- /dev/null +++ b/tdutils/td/utils/OptionParser.h @@ -0,0 +1,72 @@ +/* + This file is part of TON Blockchain Library. + + TON Blockchain Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + TON Blockchain Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with TON Blockchain Library. If not, see . + + Copyright 2017-2020 Telegram Systems LLP +*/ +#pragma once + +#include "td/utils/common.h" +#include "td/utils/Slice.h" +#include "td/utils/Status.h" +#include "td/utils/StringBuilder.h" + +#include + +namespace td { + +class OptionParser { + class Option { + public: + enum class Type { NoArg, Arg }; + Type type; + char short_key; + string long_key; + string description; + std::function arg_callback; + }; + + void add_option(Option::Type type, char short_key, Slice long_key, Slice description, + std::function callback); + + public: + void set_description(string description); + + void add_checked_option(char short_key, Slice long_key, Slice description, std::function callback); + + void add_checked_option(char short_key, Slice long_key, Slice description, std::function callback); + + void add_option(char short_key, Slice long_key, Slice description, std::function callback) = delete; + + void add_option(char short_key, Slice long_key, Slice description, std::function callback) = delete; + + void add_option(char short_key, Slice long_key, Slice description, std::function callback); + + void add_option(char short_key, Slice long_key, Slice description, std::function callback); + + void add_check(std::function check); + + // returns found non-option parameters + Result> run(int argc, char *argv[], int expected_non_option_count = -1) TD_WARN_UNUSED_RESULT; + + friend StringBuilder &operator<<(StringBuilder &sb, const OptionParser &o); + + private: + vector