Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 9 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
# ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '.h>$'
Priority: -1
- Regex: '>$'
Priority: -2
- Regex: '^\".*\"$'
Priority: 0
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
Expand All @@ -70,7 +78,7 @@ PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: false # true
SortIncludes: false # disabled, because we need case insensitive sort
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
Expand Down
4 changes: 2 additions & 2 deletions adnl/adnl-address-list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#include "adnl-address-list.hpp"
#include "adnl-peer-table.h"
#include "auto/tl/ton_api.hpp"
#include "td/utils/overloaded.h"
#include "td/net/UdpServer.h"
#include "keys/encryptor.h"
#include "td/net/UdpServer.h"
#include "td/utils/overloaded.h"

namespace ton {

Expand Down
5 changes: 2 additions & 3 deletions adnl/adnl-channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl-channel.hpp"
#include "adnl-peer.h"
#include "adnl-peer-table.h"

#include "td/utils/crypto.h"
#include "adnl-peer.h"
#include "crypto/Ed25519.h"
#include "td/utils/crypto.h"

namespace ton {

Expand Down
4 changes: 2 additions & 2 deletions adnl/adnl-channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#pragma once

#include "adnl-local-id.h"
#include "adnl-peer.h"
#include "adnl-peer-table.h"
#include "adnl-network-manager.h"
#include "adnl-peer-table.h"
#include "adnl-peer.h"

namespace ton {

Expand Down
3 changes: 1 addition & 2 deletions adnl/adnl-db.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
*/
#pragma once

#include "td/actor/actor.h"

#include "adnl.h"
#include "td/actor/actor.h"

namespace ton {

Expand Down
2 changes: 1 addition & 1 deletion adnl/adnl-ext-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl-ext-client.hpp"
#include "adnl-ext-client.h"
#include "adnl-ext-client.hpp"

namespace ton {

Expand Down
8 changes: 3 additions & 5 deletions adnl/adnl-local-id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@

Copyright 2017-2020 Telegram Systems LLP
*/
#include "td/utils/crypto.h"
#include "td/utils/Random.h"

#include "adnl-local-id.h"
#include "keys/encryptor.h"
#include "td/utils/Random.h"
#include "td/utils/crypto.h"
#include "utils.hpp"

namespace ton {
Expand All @@ -41,7 +40,7 @@ AdnlAddressList AdnlLocalId::get_addr_list() const {
}

void AdnlLocalId::receive(td::IPAddress addr, td::BufferSlice data) {
InboundRateLimiter& rate_limiter = inbound_rate_limiter_[addr];
InboundRateLimiter &rate_limiter = inbound_rate_limiter_[addr];
if (!rate_limiter.rate_limiter.take()) {
VLOG(ADNL_NOTICE) << this << ": dropping IN message: rate limit exceeded";
add_dropped_packet_stats(addr);
Expand Down Expand Up @@ -371,7 +370,6 @@ tl_object_ptr<ton_api::adnl_stats_localIdPackets> AdnlLocalId::PacketStats::tl(b
return obj;
}


} // namespace adnl

} // namespace ton
10 changes: 4 additions & 6 deletions adnl/adnl-local-id.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@

#include <map>

#include "td/actor/actor.h"
#include "td/utils/BufferedUdp.h"
#include "auto/tl/ton_api.h"
#include "keys/encryptor.h"
#include "adnl-peer-table.h"
#include "auto/tl/ton_api.h"
#include "dht/dht.h"

#include "adnl-peer-table.h"
#include "keys/encryptor.h"
#include "td/actor/actor.h"
#include "td/utils/BufferedUdp.h"
#include "utils.hpp"

namespace ton {
Expand Down
2 changes: 1 addition & 1 deletion adnl/adnl-message.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
#pragma once

#include "adnl/adnl.h"
#include "adnl/adnl-query.h"
#include "adnl/adnl.h"

namespace ton {

Expand Down
2 changes: 0 additions & 2 deletions adnl/adnl-network-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
*/
#include "adnl-network-manager.hpp"
#include "adnl-peer-table.h"

#include "auto/tl/ton_api.hpp"

#include "td/utils/overloaded.h"

namespace ton {
Expand Down
10 changes: 4 additions & 6 deletions adnl/adnl-network-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
*/
#pragma once

#include "td/actor/actor.h"

#include "td/actor/PromiseFuture.h"
#include "td/utils/port/IPAddress.h"
#include <bitset>

#include "adnl-node-id.hpp"
#include "adnl-proxy-types.h"

#include <bitset>
#include "td/actor/PromiseFuture.h"
#include "td/actor/actor.h"
#include "td/utils/port/IPAddress.h"

namespace td {
class UdpServer;
Expand Down
1 change: 0 additions & 1 deletion adnl/adnl-node-id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

#include "adnl-node-id.hpp"

#include "common/util.h"

namespace ton {
Expand Down
4 changes: 2 additions & 2 deletions adnl/adnl-node.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
#pragma once

#include "auto/tl/ton_api.h"
#include "adnl-node-id.hpp"
#include "adnl-address-list.h"
#include "adnl-node-id.hpp"
#include "auto/tl/ton_api.h"

namespace ton {

Expand Down
2 changes: 1 addition & 1 deletion adnl/adnl-packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
#pragma once

#include "adnl/adnl.h"
#include "adnl/adnl-message.h"
#include "adnl/adnl.h"

namespace ton {

Expand Down
94 changes: 45 additions & 49 deletions adnl/adnl-peer-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@

Copyright 2017-2020 Telegram Systems LLP
*/
#include "adnl-channel.h"
#include "adnl-ext-client.h"
#include "adnl-peer-table.hpp"
#include "adnl-peer.h"
#include "adnl-channel.h"
#include "utils.hpp"

#include "td/utils/tl_storers.h"
#include "adnl-query.h"
#include "adnl-tunnel.h"
#include "td/db/RocksDb.h"
#include "td/utils/Random.h"
#include "td/utils/crypto.h"
#include "td/utils/tl_parsers.h"
#include "td/utils/Random.h"
#include "td/db/RocksDb.h"

#include "td/utils/tl_storers.h"
#include "utils.hpp"
#include "adnl-query.h"
#include "adnl-ext-client.h"
#include "adnl-tunnel.h"

namespace ton {

Expand Down Expand Up @@ -87,22 +84,22 @@ void AdnlPeerTableImpl::receive_packet(td::IPAddress addr, AdnlCategoryMask cat_
void AdnlPeerTableImpl::update_id(AdnlPeerTableImpl::PeerInfo &peer_info, AdnlNodeIdFull &&peer_id) {
if (peer_info.peer_id.empty()) {
peer_info.peer_id = std::move(peer_id);
for (auto &e: peer_info.peers) {
for (auto &e : peer_info.peers) {
td::actor::send_closure(e.second, &AdnlPeerPair::update_peer_id, peer_info.peer_id);
}
}
}

td::actor::ActorOwn<AdnlPeerPair> &AdnlPeerTableImpl::get_peer_pair(
AdnlNodeIdShort peer_id, AdnlPeerTableImpl::PeerInfo &peer_info,
AdnlNodeIdShort local_id, AdnlPeerTableImpl::LocalIdInfo &local_id_info) {
td::actor::ActorOwn<AdnlPeerPair> &AdnlPeerTableImpl::get_peer_pair(AdnlNodeIdShort peer_id,
AdnlPeerTableImpl::PeerInfo &peer_info,
AdnlNodeIdShort local_id,
AdnlPeerTableImpl::LocalIdInfo &local_id_info) {
auto it = peer_info.peers.find(local_id);
if (it == peer_info.peers.end()) {
it = peer_info.peers.emplace(local_id,
AdnlPeerPair::create(network_manager_, actor_id(this),
local_id_info.mode, local_id_info.local_id.get(),
dht_node_, local_id, peer_id))
.first;
it = peer_info.peers
.emplace(local_id, AdnlPeerPair::create(network_manager_, actor_id(this), local_id_info.mode,
local_id_info.local_id.get(), dht_node_, local_id, peer_id))
.first;
if (!peer_info.peer_id.empty()) {
td::actor::send_closure(it->second, &AdnlPeerPair::update_peer_id, peer_info.peer_id);
}
Expand Down Expand Up @@ -146,8 +143,8 @@ void AdnlPeerTableImpl::receive_decrypted_packet(AdnlNodeIdShort dst, AdnlPacket
update_id(it->second, packet.from());
}

td::actor::send_closure(get_peer_pair(src, it->second, dst, it2->second),
&AdnlPeerPair::receive_packet, std::move(packet), serialized_size);
td::actor::send_closure(get_peer_pair(src, it->second, dst, it2->second), &AdnlPeerPair::receive_packet,
std::move(packet), serialized_size);
}

void AdnlPeerTableImpl::add_peer(AdnlNodeIdShort local_id, AdnlNodeIdFull id, AdnlAddressList addr_list) {
Expand All @@ -160,8 +157,8 @@ void AdnlPeerTableImpl::add_peer(AdnlNodeIdShort local_id, AdnlNodeIdFull id, Ad
auto &peer_info = peers_[id_short];
update_id(peer_info, std::move(id));
if (!addr_list.empty()) {
td::actor::send_closure(get_peer_pair(id_short, peer_info, local_id, it2->second),
&AdnlPeerPair::update_addr_list, std::move(addr_list));
td::actor::send_closure(get_peer_pair(id_short, peer_info, local_id, it2->second), &AdnlPeerPair::update_addr_list,
std::move(addr_list));
}
}

Expand All @@ -185,8 +182,8 @@ void AdnlPeerTableImpl::send_message_in(AdnlNodeIdShort src, AdnlNodeIdShort dst

std::vector<OutboundAdnlMessage> messages;
messages.push_back(OutboundAdnlMessage{std::move(message), flags});
td::actor::send_closure(get_peer_pair(dst, peer_info, src, it2->second),
&AdnlPeerPair::send_messages, std::move(messages));
td::actor::send_closure(get_peer_pair(dst, peer_info, src, it2->second), &AdnlPeerPair::send_messages,
std::move(messages));
}

void AdnlPeerTableImpl::answer_query(AdnlNodeIdShort src, AdnlNodeIdShort dst, AdnlQueryId query_id,
Expand Down Expand Up @@ -214,8 +211,8 @@ void AdnlPeerTableImpl::send_query(AdnlNodeIdShort src, AdnlNodeIdShort dst, std
return;
}

td::actor::send_closure(get_peer_pair(dst, peer_info, src, it2->second),
&AdnlPeerPair::send_query, name, std::move(promise), timeout, std::move(data), 0);
td::actor::send_closure(get_peer_pair(dst, peer_info, src, it2->second), &AdnlPeerPair::send_query, name,
std::move(promise), timeout, std::move(data), 0);
}

void AdnlPeerTableImpl::add_id_ex(AdnlNodeIdFull id, AdnlAddressList addr_list, td::uint8 cat, td::uint32 mode) {
Expand Down Expand Up @@ -411,7 +408,7 @@ void AdnlPeerTableImpl::get_conn_ip_str(AdnlNodeIdShort l_id, AdnlNodeIdShort p_
}

void AdnlPeerTableImpl::get_stats_peer(AdnlNodeIdShort peer_id, AdnlPeerTableImpl::PeerInfo &peer_info, bool all,
td::Promise<std::vector<tl_object_ptr<ton_api::adnl_stats_peerPair>>> promise) {
td::Promise<std::vector<tl_object_ptr<ton_api::adnl_stats_peerPair>>> promise) {
class Cb : public td::actor::Actor {
public:
explicit Cb(td::Promise<std::vector<tl_object_ptr<ton_api::adnl_stats_peerPair>>> promise)
Expand Down Expand Up @@ -447,17 +444,17 @@ void AdnlPeerTableImpl::get_stats_peer(AdnlNodeIdShort peer_id, AdnlPeerTableImp

for (auto &[local_id, peer_pair] : peer_info.peers) {
td::actor::send_closure(callback, &Cb::inc_pending);
td::actor::send_closure(peer_pair, &AdnlPeerPair::get_stats, all,
[local_id = local_id, peer_id = peer_id,
callback](td::Result<tl_object_ptr<ton_api::adnl_stats_peerPair>> R) {
if (R.is_error()) {
VLOG(ADNL_NOTICE) << "failed to get stats for peer pair " << peer_id << "->" << local_id
<< " : " << R.move_as_error();
td::actor::send_closure(callback, &Cb::dec_pending);
} else {
td::actor::send_closure(callback, &Cb::got_peer_pair_stats, R.move_as_ok());
}
});
td::actor::send_closure(
peer_pair, &AdnlPeerPair::get_stats, all,
[local_id = local_id, peer_id = peer_id, callback](td::Result<tl_object_ptr<ton_api::adnl_stats_peerPair>> R) {
if (R.is_error()) {
VLOG(ADNL_NOTICE) << "failed to get stats for peer pair " << peer_id << "->" << local_id << " : "
<< R.move_as_error();
td::actor::send_closure(callback, &Cb::dec_pending);
} else {
td::actor::send_closure(callback, &Cb::got_peer_pair_stats, R.move_as_ok());
}
});
}
td::actor::send_closure(callback, &Cb::dec_pending);
}
Expand Down Expand Up @@ -530,16 +527,15 @@ void AdnlPeerTableImpl::get_stats(bool all, td::Promise<tl_object_ptr<ton_api::a
}
for (auto &[id, peer] : peers_) {
td::actor::send_closure(callback, &Cb::inc_pending);
get_stats_peer(
id, peer, all,
[id = id, callback](td::Result<std::vector<tl_object_ptr<ton_api::adnl_stats_peerPair>>> R) {
if (R.is_error()) {
VLOG(ADNL_NOTICE) << "failed to get stats for peer " << id << " : " << R.move_as_error();
td::actor::send_closure(callback, &Cb::dec_pending);
} else {
td::actor::send_closure(callback, &Cb::got_peer_stats, R.move_as_ok());
}
});
get_stats_peer(id, peer, all,
[id = id, callback](td::Result<std::vector<tl_object_ptr<ton_api::adnl_stats_peerPair>>> R) {
if (R.is_error()) {
VLOG(ADNL_NOTICE) << "failed to get stats for peer " << id << " : " << R.move_as_error();
td::actor::send_closure(callback, &Cb::dec_pending);
} else {
td::actor::send_closure(callback, &Cb::got_peer_stats, R.move_as_ok());
}
});
}
td::actor::send_closure(callback, &Cb::dec_pending);
}
Expand Down
15 changes: 6 additions & 9 deletions adnl/adnl-peer-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@
*/
#pragma once

#include "td/actor/actor.h"
#include "td/utils/BufferedUdp.h"

#include "adnl-packet.h"
#include "adnl.h"
#include "utils.hpp"
#include "adnl/adnl-query.h"
#include "adnl/adnl-db.h"
#include "common/io.hpp"

#include "adnl-packet.h"

#include "adnl/adnl-query.h"
#include "auto/tl/ton_api.h"
#include "common/io.hpp"
#include "td/actor/actor.h"
#include "td/utils/BufferedUdp.h"
#include "utils.hpp"

namespace ton {

Expand Down
Loading
Loading