mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Enhance overlay stats output (#386)
* Expand overlay stats * Add scope and peer broadcast errors to stats * Add json output format Co-authored-by: EmelyanenkoK <emelyanenko.kirill@gmail.com>
This commit is contained in:
parent
fea912e05c
commit
e30049930a
30 changed files with 396 additions and 38 deletions
|
@ -80,6 +80,7 @@ td::Status BroadcastSimple::distribute() {
|
|||
|
||||
void BroadcastSimple::broadcast_checked(td::Result<td::Unit> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(actor_id(overlay_), &OverlayImpl::update_peer_err_ctr, src_peer_id_, false);
|
||||
return;
|
||||
}
|
||||
is_valid_ = true;
|
||||
|
@ -114,7 +115,7 @@ td::Status BroadcastSimple::run() {
|
|||
return run_continue();
|
||||
}
|
||||
|
||||
td::Status BroadcastSimple::create(OverlayImpl *overlay, tl_object_ptr<ton_api::overlay_broadcast> broadcast) {
|
||||
td::Status BroadcastSimple::create(OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id, tl_object_ptr<ton_api::overlay_broadcast> broadcast) {
|
||||
auto src = PublicKey{broadcast->src_};
|
||||
auto data_hash = sha256_bits256(broadcast->data_.as_slice());
|
||||
auto broadcast_hash = compute_broadcast_id(src, data_hash, broadcast->flags_);
|
||||
|
@ -125,7 +126,7 @@ td::Status BroadcastSimple::create(OverlayImpl *overlay, tl_object_ptr<ton_api::
|
|||
|
||||
auto B = std::make_unique<BroadcastSimple>(broadcast_hash, src, std::move(cert), broadcast->flags_,
|
||||
std::move(broadcast->data_), broadcast->date_,
|
||||
std::move(broadcast->signature_), false, overlay);
|
||||
std::move(broadcast->signature_), false, overlay, src_peer_id);
|
||||
TRY_STATUS(B->run());
|
||||
overlay->register_simple_broadcast(std::move(B));
|
||||
return td::Status::OK();
|
||||
|
@ -139,7 +140,7 @@ td::Status BroadcastSimple::create_new(td::actor::ActorId<OverlayImpl> overlay,
|
|||
auto date = static_cast<td::uint32>(td::Clocks::system());
|
||||
|
||||
auto B = std::make_unique<BroadcastSimple>(broadcast_hash, PublicKey{}, nullptr, flags, std::move(data), date,
|
||||
td::BufferSlice{}, false, nullptr);
|
||||
td::BufferSlice{}, false, nullptr, adnl::AdnlNodeIdShort::zero());
|
||||
|
||||
auto to_sign = B->to_sign();
|
||||
auto P = td::PromiseCreator::lambda(
|
||||
|
|
|
@ -49,6 +49,8 @@ class BroadcastSimple : public td::ListNode {
|
|||
|
||||
OverlayImpl *overlay_;
|
||||
|
||||
adnl::AdnlNodeIdShort src_peer_id_ = adnl::AdnlNodeIdShort::zero();
|
||||
|
||||
td::Status check_time();
|
||||
td::Status check_duplicate();
|
||||
td::Status check_source();
|
||||
|
@ -61,7 +63,7 @@ class BroadcastSimple : public td::ListNode {
|
|||
public:
|
||||
BroadcastSimple(Overlay::BroadcastHash broadcast_hash, PublicKey source, std::shared_ptr<Certificate> cert,
|
||||
td::uint32 flags, td::BufferSlice data, td::uint32 date, td::BufferSlice signature, bool is_valid,
|
||||
OverlayImpl *overlay)
|
||||
OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id)
|
||||
: broadcast_hash_(broadcast_hash)
|
||||
, source_(std::move(source))
|
||||
, cert_(std::move(cert))
|
||||
|
@ -70,7 +72,8 @@ class BroadcastSimple : public td::ListNode {
|
|||
, date_(date)
|
||||
, signature_(std::move(signature))
|
||||
, is_valid_(is_valid)
|
||||
, overlay_(overlay) {
|
||||
, overlay_(overlay)
|
||||
, src_peer_id_(src_peer_id) {
|
||||
}
|
||||
|
||||
Overlay::BroadcastHash get_hash() const {
|
||||
|
@ -98,7 +101,7 @@ class BroadcastSimple : public td::ListNode {
|
|||
void update_overlay(OverlayImpl *overlay);
|
||||
void broadcast_checked(td::Result<td::Unit> R);
|
||||
|
||||
static td::Status create(OverlayImpl *overlay, tl_object_ptr<ton_api::overlay_broadcast> broadcast);
|
||||
static td::Status create(OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id, tl_object_ptr<ton_api::overlay_broadcast> broadcast);
|
||||
static td::Status create_new(td::actor::ActorId<OverlayImpl> overlay, td::actor::ActorId<keyring::Keyring> keyring,
|
||||
PublicKeyHash local_id, td::BufferSlice data, td::uint32 flags);
|
||||
|
||||
|
|
|
@ -88,6 +88,7 @@ td::Status OverlayFecBroadcastPart::run_checks() {
|
|||
|
||||
void BroadcastFec::broadcast_checked(td::Result<td::Unit> R) {
|
||||
if (R.is_error()) {
|
||||
td::actor::send_closure(actor_id(overlay_), &OverlayImpl::update_peer_err_ctr, src_peer_id_, true);
|
||||
return;
|
||||
}
|
||||
overlay_->deliver_broadcast(get_source().compute_short_id(), data_.clone());
|
||||
|
@ -155,6 +156,7 @@ td::Status OverlayFecBroadcastPart::apply() {
|
|||
|
||||
if (!bcast_->finalized()) {
|
||||
bcast_->set_overlay(overlay_);
|
||||
bcast_->set_src_peer_id(src_peer_id_);
|
||||
TRY_STATUS(bcast_->add_part(seqno_, data_.clone(), export_serialized_short(), export_serialized()));
|
||||
auto R = bcast_->finish();
|
||||
if (R.is_error()) {
|
||||
|
@ -211,7 +213,7 @@ td::BufferSlice OverlayFecBroadcastPart::to_sign() {
|
|||
return serialize_tl_object(obj, true);
|
||||
}
|
||||
|
||||
td::Status OverlayFecBroadcastPart::create(OverlayImpl *overlay,
|
||||
td::Status OverlayFecBroadcastPart::create(OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id,
|
||||
tl_object_ptr<ton_api::overlay_broadcastFec> broadcast) {
|
||||
TRY_STATUS(overlay->check_date(broadcast->date_));
|
||||
auto source = PublicKey{broadcast->src_};
|
||||
|
@ -244,12 +246,13 @@ td::Status OverlayFecBroadcastPart::create(OverlayImpl *overlay,
|
|||
std::move(broadcast->signature_),
|
||||
false,
|
||||
overlay->get_fec_broadcast(broadcast_hash),
|
||||
overlay};
|
||||
overlay,
|
||||
src_peer_id};
|
||||
TRY_STATUS(B.run());
|
||||
return td::Status::OK();
|
||||
}
|
||||
|
||||
td::Status OverlayFecBroadcastPart::create(OverlayImpl *overlay,
|
||||
td::Status OverlayFecBroadcastPart::create(OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id,
|
||||
tl_object_ptr<ton_api::overlay_broadcastFecShort> broadcast) {
|
||||
auto bcast = overlay->get_fec_broadcast(broadcast->broadcast_hash_);
|
||||
if (!bcast) {
|
||||
|
@ -285,7 +288,8 @@ td::Status OverlayFecBroadcastPart::create(OverlayImpl *overlay,
|
|||
std::move(broadcast->signature_),
|
||||
true,
|
||||
bcast,
|
||||
overlay};
|
||||
overlay,
|
||||
src_peer_id};
|
||||
TRY_STATUS(B.run());
|
||||
return td::Status::OK();
|
||||
}
|
||||
|
@ -300,7 +304,7 @@ td::Status OverlayFecBroadcastPart::create_new(OverlayImpl *overlay, td::actor::
|
|||
|
||||
auto B = std::make_unique<OverlayFecBroadcastPart>(
|
||||
broadcast_hash, part_hash, PublicKey{}, overlay->get_certificate(local_id), data_hash, size, flags,
|
||||
part_data_hash, std::move(part), seqno, std::move(fec_type), date, td::BufferSlice{}, false, nullptr, overlay);
|
||||
part_data_hash, std::move(part), seqno, std::move(fec_type), date, td::BufferSlice{}, false, nullptr, overlay, adnl::AdnlNodeIdShort::zero());
|
||||
auto to_sign = B->to_sign();
|
||||
|
||||
auto P = td::PromiseCreator::lambda(
|
||||
|
|
|
@ -194,6 +194,9 @@ class BroadcastFec : public td::ListNode {
|
|||
void set_overlay(OverlayImpl *overlay) {
|
||||
overlay_ = overlay;
|
||||
}
|
||||
void set_src_peer_id(adnl::AdnlNodeIdShort src_peer_id) {
|
||||
src_peer_id_ = src_peer_id;
|
||||
}
|
||||
|
||||
td::Status distribute_part(td::uint32 seqno);
|
||||
|
||||
|
@ -220,6 +223,7 @@ class BroadcastFec : public td::ListNode {
|
|||
|
||||
std::map<td::uint32, std::pair<td::BufferSlice, td::BufferSlice>> parts_;
|
||||
OverlayImpl *overlay_;
|
||||
adnl::AdnlNodeIdShort src_peer_id_ = adnl::AdnlNodeIdShort::zero();
|
||||
td::BufferSlice data_;
|
||||
};
|
||||
|
||||
|
@ -245,6 +249,7 @@ class OverlayFecBroadcastPart : public td::ListNode {
|
|||
|
||||
BroadcastFec *bcast_;
|
||||
OverlayImpl *overlay_;
|
||||
adnl::AdnlNodeIdShort src_peer_id_ = adnl::AdnlNodeIdShort::zero();
|
||||
|
||||
td::Status check_time();
|
||||
td::Status check_duplicate();
|
||||
|
@ -260,7 +265,7 @@ class OverlayFecBroadcastPart : public td::ListNode {
|
|||
std::shared_ptr<Certificate> cert, Overlay::BroadcastDataHash data_hash, td::uint32 data_size,
|
||||
td::uint32 flags, Overlay::BroadcastDataHash part_data_hash, td::BufferSlice data,
|
||||
td::uint32 seqno, fec::FecType fec_type, td::uint32 date, td::BufferSlice signature,
|
||||
bool is_short, BroadcastFec *bcast, OverlayImpl *overlay)
|
||||
bool is_short, BroadcastFec *bcast, OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id)
|
||||
: broadcast_hash_(broadcast_hash)
|
||||
, part_hash_(part_hash)
|
||||
, source_(std::move(source))
|
||||
|
@ -276,7 +281,8 @@ class OverlayFecBroadcastPart : public td::ListNode {
|
|||
, signature_(std::move(signature))
|
||||
, is_short_(is_short)
|
||||
, bcast_(bcast)
|
||||
, overlay_(overlay) {
|
||||
, overlay_(overlay)
|
||||
, src_peer_id_(src_peer_id) {
|
||||
}
|
||||
|
||||
td::uint32 data_size() const {
|
||||
|
@ -310,8 +316,8 @@ class OverlayFecBroadcastPart : public td::ListNode {
|
|||
return td::Status::OK();
|
||||
}
|
||||
|
||||
static td::Status create(OverlayImpl *overlay, tl_object_ptr<ton_api::overlay_broadcastFec> broadcast);
|
||||
static td::Status create(OverlayImpl *overlay, tl_object_ptr<ton_api::overlay_broadcastFecShort> broadcast);
|
||||
static td::Status create(OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id, tl_object_ptr<ton_api::overlay_broadcastFec> broadcast);
|
||||
static td::Status create(OverlayImpl *overlay, adnl::AdnlNodeIdShort src_peer_id, tl_object_ptr<ton_api::overlay_broadcastFecShort> broadcast);
|
||||
static td::Status create_new(OverlayImpl *overlay, td::actor::ActorId<OverlayImpl> overlay_actor_id,
|
||||
PublicKeyHash local_id, Overlay::BroadcastDataHash data_hash, td::uint32 size,
|
||||
td::uint32 flags, td::BufferSlice part, td::uint32 seqno, fec::FecType fec_type,
|
||||
|
|
|
@ -90,12 +90,12 @@ void OverlayManager::delete_overlay(adnl::AdnlNodeIdShort local_id, OverlayIdSho
|
|||
}
|
||||
|
||||
void OverlayManager::create_public_overlay(adnl::AdnlNodeIdShort local_id, OverlayIdFull overlay_id,
|
||||
std::unique_ptr<Callback> callback, OverlayPrivacyRules rules) {
|
||||
std::unique_ptr<Callback> callback, OverlayPrivacyRules rules, td::string scope) {
|
||||
CHECK(!dht_node_.empty());
|
||||
auto id = overlay_id.compute_short_id();
|
||||
register_overlay(local_id, id,
|
||||
Overlay::create(keyring_, adnl_, actor_id(this), dht_node_, local_id, std::move(overlay_id),
|
||||
std::move(callback), std::move(rules)));
|
||||
std::move(callback), std::move(rules), scope));
|
||||
}
|
||||
|
||||
void OverlayManager::create_private_overlay(adnl::AdnlNodeIdShort local_id, OverlayIdFull overlay_id,
|
||||
|
@ -128,6 +128,7 @@ void OverlayManager::receive_message(adnl::AdnlNodeIdShort src, adnl::AdnlNodeId
|
|||
return;
|
||||
}
|
||||
|
||||
td::actor::send_closure(it2->second, &Overlay::update_throughput_in_ctr, src, (td::uint32)data.size(), false);
|
||||
td::actor::send_closure(it2->second, &Overlay::receive_message, src, std::move(data));
|
||||
}
|
||||
|
||||
|
@ -152,12 +153,12 @@ void OverlayManager::receive_query(adnl::AdnlNodeIdShort src, adnl::AdnlNodeIdSh
|
|||
}
|
||||
auto it2 = it->second.find(OverlayIdShort{M->overlay_});
|
||||
if (it2 == it->second.end()) {
|
||||
VLOG(OVERLAY_NOTICE) << this << ": query to localid not in overlay " << M->overlay_ << "@" << dst << " from "
|
||||
<< src;
|
||||
VLOG(OVERLAY_NOTICE) << this << ": query to localid not in overlay " << M->overlay_ << "@" << dst << " from " << src;
|
||||
promise.set_error(td::Status::Error(ErrorCode::protoviolation, PSTRING() << "bad overlay_id " << M->overlay_));
|
||||
return;
|
||||
}
|
||||
|
||||
td::actor::send_closure(it2->second, &Overlay::update_throughput_in_ctr, src, (td::uint32)data.size(), true);
|
||||
td::actor::send_closure(it2->second, &Overlay::receive_query, src, std::move(data), std::move(promise));
|
||||
}
|
||||
|
||||
|
@ -166,6 +167,15 @@ void OverlayManager::send_query_via(adnl::AdnlNodeIdShort dst, adnl::AdnlNodeIdS
|
|||
td::BufferSlice query, td::uint64 max_answer_size,
|
||||
td::actor::ActorId<adnl::AdnlSenderInterface> via) {
|
||||
CHECK(query.size() <= adnl::Adnl::huge_packet_max_size());
|
||||
|
||||
auto it = overlays_.find(src);
|
||||
if (it != overlays_.end()) {
|
||||
auto it2 = it->second.find(overlay_id);
|
||||
if (it2 != it->second.end()) {
|
||||
td::actor::send_closure(it2->second, &Overlay::update_throughput_out_ctr, dst, (td::uint32)query.size(), true);
|
||||
}
|
||||
}
|
||||
|
||||
td::actor::send_closure(
|
||||
via, &adnl::AdnlSenderInterface::send_query_ex, src, dst, std::move(name), std::move(promise), timeout,
|
||||
create_serialize_tl_object_suffix<ton_api::overlay_query>(query.as_slice(), overlay_id.tl()), max_answer_size);
|
||||
|
@ -174,6 +184,15 @@ void OverlayManager::send_query_via(adnl::AdnlNodeIdShort dst, adnl::AdnlNodeIdS
|
|||
void OverlayManager::send_message_via(adnl::AdnlNodeIdShort dst, adnl::AdnlNodeIdShort src, OverlayIdShort overlay_id,
|
||||
td::BufferSlice object, td::actor::ActorId<adnl::AdnlSenderInterface> via) {
|
||||
CHECK(object.size() <= adnl::Adnl::huge_packet_max_size());
|
||||
|
||||
auto it = overlays_.find(src);
|
||||
if (it != overlays_.end()) {
|
||||
auto it2 = it->second.find(overlay_id);
|
||||
if (it2 != it->second.end()) {
|
||||
td::actor::send_closure(it2->second, &Overlay::update_throughput_out_ctr, dst, (td::uint32)object.size(), false);
|
||||
}
|
||||
}
|
||||
|
||||
td::actor::send_closure(
|
||||
via, &adnl::AdnlSenderInterface::send_message, src, dst,
|
||||
create_serialize_tl_object_suffix<ton_api::overlay_message>(object.as_slice(), overlay_id.tl()));
|
||||
|
|
|
@ -51,7 +51,7 @@ class OverlayManager : public Overlays {
|
|||
void update_dht_node(td::actor::ActorId<dht::Dht> dht) override;
|
||||
|
||||
void create_public_overlay(adnl::AdnlNodeIdShort local_id, OverlayIdFull overlay_id,
|
||||
std::unique_ptr<Callback> callback, OverlayPrivacyRules rules) override;
|
||||
std::unique_ptr<Callback> callback, OverlayPrivacyRules rules, td::string scope) override;
|
||||
void create_private_overlay(adnl::AdnlNodeIdShort local_id, OverlayIdFull overlay_id,
|
||||
std::vector<adnl::AdnlNodeIdShort> nodes, std::unique_ptr<Callback> callback,
|
||||
OverlayPrivacyRules rules) override;
|
||||
|
|
|
@ -37,10 +37,10 @@ td::actor::ActorOwn<Overlay> Overlay::create(td::actor::ActorId<keyring::Keyring
|
|||
td::actor::ActorId<OverlayManager> manager,
|
||||
td::actor::ActorId<dht::Dht> dht_node, adnl::AdnlNodeIdShort local_id,
|
||||
OverlayIdFull overlay_id, std::unique_ptr<Overlays::Callback> callback,
|
||||
OverlayPrivacyRules rules) {
|
||||
OverlayPrivacyRules rules, td::string scope) {
|
||||
auto R = td::actor::create_actor<OverlayImpl>("overlay", keyring, adnl, manager, dht_node, local_id,
|
||||
std::move(overlay_id), true, std::vector<adnl::AdnlNodeIdShort>(),
|
||||
std::move(callback), std::move(rules));
|
||||
std::move(callback), std::move(rules), scope);
|
||||
return td::actor::ActorOwn<Overlay>(std::move(R));
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ OverlayImpl::OverlayImpl(td::actor::ActorId<keyring::Keyring> keyring, td::actor
|
|||
td::actor::ActorId<OverlayManager> manager, td::actor::ActorId<dht::Dht> dht_node,
|
||||
adnl::AdnlNodeIdShort local_id, OverlayIdFull overlay_id, bool pub,
|
||||
std::vector<adnl::AdnlNodeIdShort> nodes, std::unique_ptr<Overlays::Callback> callback,
|
||||
OverlayPrivacyRules rules)
|
||||
OverlayPrivacyRules rules, td::string scope)
|
||||
: keyring_(keyring)
|
||||
, adnl_(adnl)
|
||||
, manager_(manager)
|
||||
|
@ -69,7 +69,8 @@ OverlayImpl::OverlayImpl(td::actor::ActorId<keyring::Keyring> keyring, td::actor
|
|||
, id_full_(std::move(overlay_id))
|
||||
, callback_(std::move(callback))
|
||||
, public_(pub)
|
||||
, rules_(std::move(rules)) {
|
||||
, rules_(std::move(rules))
|
||||
, scope_(scope) {
|
||||
overlay_id_ = id_full_.compute_short_id();
|
||||
|
||||
VLOG(OVERLAY_INFO) << this << ": creating " << (public_ ? "public" : "private");
|
||||
|
@ -161,17 +162,17 @@ void OverlayImpl::receive_query(adnl::AdnlNodeIdShort src, td::BufferSlice data,
|
|||
|
||||
td::Status OverlayImpl::process_broadcast(adnl::AdnlNodeIdShort message_from,
|
||||
tl_object_ptr<ton_api::overlay_broadcast> bcast) {
|
||||
return BroadcastSimple::create(this, std::move(bcast));
|
||||
return BroadcastSimple::create(this, message_from, std::move(bcast));
|
||||
}
|
||||
|
||||
td::Status OverlayImpl::process_broadcast(adnl::AdnlNodeIdShort message_from,
|
||||
tl_object_ptr<ton_api::overlay_broadcastFec> b) {
|
||||
return OverlayFecBroadcastPart::create(this, std::move(b));
|
||||
return OverlayFecBroadcastPart::create(this, message_from, std::move(b));
|
||||
}
|
||||
|
||||
td::Status OverlayImpl::process_broadcast(adnl::AdnlNodeIdShort message_from,
|
||||
tl_object_ptr<ton_api::overlay_broadcastFecShort> b) {
|
||||
return OverlayFecBroadcastPart::create(this, std::move(b));
|
||||
return OverlayFecBroadcastPart::create(this, message_from, std::move(b));
|
||||
}
|
||||
|
||||
td::Status OverlayImpl::process_broadcast(adnl::AdnlNodeIdShort message_from,
|
||||
|
@ -236,6 +237,35 @@ void OverlayImpl::receive_message(adnl::AdnlNodeIdShort src, td::BufferSlice dat
|
|||
|
||||
void OverlayImpl::alarm() {
|
||||
bcast_gc();
|
||||
|
||||
if(update_throughput_at_.is_in_past()) {
|
||||
double t_elapsed = td::Time::now() - last_throughput_update_.at();
|
||||
|
||||
peers_.iterate([&](const adnl::AdnlNodeIdShort &key, OverlayPeer &peer) {
|
||||
peer.throughput_out_bytes = static_cast<td::uint32>(peer.throughput_out_bytes_ctr / t_elapsed);
|
||||
peer.throughput_in_bytes = static_cast<td::uint32>(peer.throughput_in_bytes_ctr / t_elapsed);
|
||||
|
||||
peer.throughput_out_packets = static_cast<td::uint32>(peer.throughput_out_packets_ctr / t_elapsed);
|
||||
peer.throughput_in_packets = static_cast<td::uint32>(peer.throughput_in_packets_ctr / t_elapsed);
|
||||
|
||||
peer.throughput_out_bytes_ctr = 0;
|
||||
peer.throughput_in_bytes_ctr = 0;
|
||||
|
||||
peer.throughput_out_packets_ctr = 0;
|
||||
peer.throughput_in_packets_ctr = 0;
|
||||
|
||||
auto P = td::PromiseCreator::lambda([SelfId = actor_id(this), peer_id = key](td::Result<td::string> result) {
|
||||
result.ensure();
|
||||
td::actor::send_closure(SelfId, &Overlay::update_peer_ip_str, peer_id, result.move_as_ok());
|
||||
});
|
||||
|
||||
td::actor::send_closure(adnl_, &adnl::AdnlSenderInterface::get_conn_ip_str, local_id_, key, std::move(P));
|
||||
});
|
||||
|
||||
update_throughput_at_ = td::Timestamp::in(50.0);
|
||||
last_throughput_update_ = td::Timestamp::now();
|
||||
}
|
||||
|
||||
if (public_) {
|
||||
if (peers_.size() > 0) {
|
||||
auto P = get_random_peer();
|
||||
|
@ -541,6 +571,17 @@ void OverlayImpl::check_broadcast(PublicKeyHash src, td::BufferSlice data, td::P
|
|||
callback_->check_broadcast(src, overlay_id_, std::move(data), std::move(promise));
|
||||
}
|
||||
|
||||
void OverlayImpl::update_peer_err_ctr(adnl::AdnlNodeIdShort peer_id, bool is_fec) {
|
||||
auto src_peer = peers_.get(peer_id);
|
||||
if(src_peer) {
|
||||
if(is_fec) {
|
||||
src_peer->fec_broadcast_errors++;
|
||||
} else {
|
||||
src_peer->broadcast_errors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OverlayImpl::broadcast_checked(Overlay::BroadcastHash hash, td::Result<td::Unit> R) {
|
||||
{
|
||||
auto it = broadcasts_.find(hash);
|
||||
|
@ -561,7 +602,26 @@ void OverlayImpl::get_stats(td::Promise<tl_object_ptr<ton_api::engine_validator_
|
|||
res->adnl_id_ = local_id_.bits256_value();
|
||||
res->overlay_id_ = overlay_id_.bits256_value();
|
||||
res->overlay_id_full_ = id_full_.pubkey().tl();
|
||||
peers_.iterate([&](const adnl::AdnlNodeIdShort &key, const OverlayPeer &peer) { res->nodes_.push_back(key.tl()); });
|
||||
res->scope_ = scope_;
|
||||
peers_.iterate([&](const adnl::AdnlNodeIdShort &key, const OverlayPeer &peer) {
|
||||
auto node_obj = create_tl_object<ton_api::engine_validator_overlayStatsNode>();
|
||||
node_obj->adnl_id_ = key.bits256_value();
|
||||
node_obj->t_out_bytes_ = peer.throughput_out_bytes;
|
||||
node_obj->t_in_bytes_ = peer.throughput_in_bytes;
|
||||
|
||||
node_obj->t_out_pckts_ = peer.throughput_out_packets;
|
||||
node_obj->t_in_pckts_ = peer.throughput_in_packets;
|
||||
|
||||
node_obj->ip_addr_ = peer.ip_addr_str;
|
||||
|
||||
node_obj->last_in_query_ = static_cast<td::uint32>(peer.last_in_query_at.at_unix());
|
||||
node_obj->last_out_query_ = static_cast<td::uint32>(peer.last_out_query_at.at_unix());
|
||||
|
||||
node_obj->bdcst_errors_ = peer.broadcast_errors;
|
||||
node_obj->fec_bdcst_errors_ = peer.fec_broadcast_errors;
|
||||
|
||||
res->nodes_.push_back(std::move(node_obj));
|
||||
});
|
||||
|
||||
res->stats_.push_back(
|
||||
create_tl_object<ton_api::engine_validator_oneStat>("neighbours_cnt", PSTRING() << neighbours_.size()));
|
||||
|
|
|
@ -42,7 +42,7 @@ class Overlay : public td::actor::Actor {
|
|||
td::actor::ActorId<OverlayManager> manager,
|
||||
td::actor::ActorId<dht::Dht> dht_node, adnl::AdnlNodeIdShort local_id,
|
||||
OverlayIdFull overlay_id, std::unique_ptr<Overlays::Callback> callback,
|
||||
OverlayPrivacyRules rules);
|
||||
OverlayPrivacyRules rules, td::string scope);
|
||||
static td::actor::ActorOwn<Overlay> create(td::actor::ActorId<keyring::Keyring> keyring,
|
||||
td::actor::ActorId<adnl::Adnl> adnl,
|
||||
td::actor::ActorId<OverlayManager> manager,
|
||||
|
@ -64,6 +64,9 @@ class Overlay : public td::actor::Actor {
|
|||
virtual void set_privacy_rules(OverlayPrivacyRules rules) = 0;
|
||||
virtual void receive_nodes_from_db(tl_object_ptr<ton_api::overlay_nodes> nodes) = 0;
|
||||
virtual void get_stats(td::Promise<tl_object_ptr<ton_api::engine_validator_overlayStats>> promise) = 0;
|
||||
virtual void update_throughput_out_ctr(adnl::AdnlNodeIdShort peer_id, td::uint32 msg_size, bool is_query) = 0;
|
||||
virtual void update_throughput_in_ctr(adnl::AdnlNodeIdShort peer_id, td::uint32 msg_size, bool is_query) = 0;
|
||||
virtual void update_peer_ip_str(adnl::AdnlNodeIdShort peer_id, td::string ip_str) = 0;
|
||||
//virtual void receive_broadcast(td::BufferSlice data) = 0;
|
||||
//virtual void subscribe(std::unique_ptr<Overlays::Callback> callback) = 0;
|
||||
};
|
||||
|
|
|
@ -79,6 +79,26 @@ class OverlayPeer {
|
|||
td::int32 get_version() const {
|
||||
return node_.version();
|
||||
}
|
||||
|
||||
td::uint32 throughput_out_bytes = 0;
|
||||
td::uint32 throughput_in_bytes = 0;
|
||||
|
||||
td::uint32 throughput_out_packets = 0;
|
||||
td::uint32 throughput_in_packets = 0;
|
||||
|
||||
td::uint32 throughput_out_bytes_ctr = 0;
|
||||
td::uint32 throughput_in_bytes_ctr = 0;
|
||||
|
||||
td::uint32 throughput_out_packets_ctr = 0;
|
||||
td::uint32 throughput_in_packets_ctr = 0;
|
||||
|
||||
td::uint32 broadcast_errors = 0;
|
||||
td::uint32 fec_broadcast_errors = 0;
|
||||
|
||||
td::Timestamp last_in_query_at = td::Timestamp::now();
|
||||
td::Timestamp last_out_query_at = td::Timestamp::now();
|
||||
|
||||
td::string ip_addr_str = "undefined";
|
||||
|
||||
private:
|
||||
OverlayNode node_;
|
||||
|
@ -93,7 +113,7 @@ class OverlayImpl : public Overlay {
|
|||
td::actor::ActorId<OverlayManager> manager, td::actor::ActorId<dht::Dht> dht_node,
|
||||
adnl::AdnlNodeIdShort local_id, OverlayIdFull overlay_id, bool pub,
|
||||
std::vector<adnl::AdnlNodeIdShort> nodes, std::unique_ptr<Overlays::Callback> callback,
|
||||
OverlayPrivacyRules rules);
|
||||
OverlayPrivacyRules rules, td::string scope = "{ \"type\": \"undefined\" }");
|
||||
void update_dht_node(td::actor::ActorId<dht::Dht> dht) override {
|
||||
dht_node_ = dht;
|
||||
}
|
||||
|
@ -109,6 +129,9 @@ class OverlayImpl : public Overlay {
|
|||
|
||||
void alarm() override;
|
||||
void start_up() override {
|
||||
update_throughput_at_ = td::Timestamp::in(50.0);
|
||||
last_throughput_update_ = td::Timestamp::now();
|
||||
|
||||
if (public_) {
|
||||
update_db_at_ = td::Timestamp::in(60.0);
|
||||
}
|
||||
|
@ -150,6 +173,8 @@ class OverlayImpl : public Overlay {
|
|||
void broadcast_checked(Overlay::BroadcastHash hash, td::Result<td::Unit> R);
|
||||
void check_broadcast(PublicKeyHash src, td::BufferSlice data, td::Promise<td::Unit> promise);
|
||||
|
||||
void update_peer_err_ctr(adnl::AdnlNodeIdShort peer_id, bool is_fec);
|
||||
|
||||
BroadcastFec *get_fec_broadcast(BroadcastHash hash);
|
||||
void register_fec_broadcast(std::unique_ptr<BroadcastFec> bcast);
|
||||
void register_simple_broadcast(std::unique_ptr<BroadcastSimple> bcast);
|
||||
|
@ -191,6 +216,39 @@ class OverlayImpl : public Overlay {
|
|||
td::Result<Encryptor *> get_encryptor(PublicKey source);
|
||||
|
||||
void get_stats(td::Promise<tl_object_ptr<ton_api::engine_validator_overlayStats>> promise) override;
|
||||
|
||||
void update_throughput_out_ctr(adnl::AdnlNodeIdShort peer_id, td::uint32 msg_size, bool is_query) override {
|
||||
auto out_peer = peers_.get(peer_id);
|
||||
if(out_peer) {
|
||||
out_peer->throughput_out_bytes_ctr += msg_size;
|
||||
out_peer->throughput_out_packets_ctr++;
|
||||
|
||||
if(is_query)
|
||||
{
|
||||
out_peer->last_out_query_at = td::Timestamp::now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void update_throughput_in_ctr(adnl::AdnlNodeIdShort peer_id, td::uint32 msg_size, bool is_query) override {
|
||||
auto in_peer = peers_.get(peer_id);
|
||||
if(in_peer) {
|
||||
in_peer->throughput_in_bytes_ctr += msg_size;
|
||||
in_peer->throughput_in_packets_ctr++;
|
||||
|
||||
if(is_query)
|
||||
{
|
||||
in_peer->last_in_query_at = td::Timestamp::now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void update_peer_ip_str(adnl::AdnlNodeIdShort peer_id, td::string ip_str) override {
|
||||
auto fpeer = peers_.get(peer_id);
|
||||
if(fpeer) {
|
||||
fpeer->ip_addr_str = ip_str;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
template <class T>
|
||||
|
@ -236,6 +294,8 @@ class OverlayImpl : public Overlay {
|
|||
td::DecTree<adnl::AdnlNodeIdShort, OverlayPeer> peers_;
|
||||
td::Timestamp next_dht_query_ = td::Timestamp::in(1.0);
|
||||
td::Timestamp update_db_at_;
|
||||
td::Timestamp update_throughput_at_;
|
||||
td::Timestamp last_throughput_update_;
|
||||
|
||||
std::unique_ptr<Overlays::Callback> callback_;
|
||||
|
||||
|
@ -291,6 +351,7 @@ class OverlayImpl : public Overlay {
|
|||
bool public_;
|
||||
bool semi_public_ = false;
|
||||
OverlayPrivacyRules rules_;
|
||||
td::string scope_;
|
||||
std::map<PublicKeyHash, std::shared_ptr<Certificate>> certs_;
|
||||
|
||||
class CachedEncryptor : public td::ListNode {
|
||||
|
|
|
@ -193,7 +193,7 @@ class Overlays : public td::actor::Actor {
|
|||
virtual void update_dht_node(td::actor::ActorId<dht::Dht> dht) = 0;
|
||||
|
||||
virtual void create_public_overlay(adnl::AdnlNodeIdShort local_id, OverlayIdFull overlay_id,
|
||||
std::unique_ptr<Callback> callback, OverlayPrivacyRules rules) = 0;
|
||||
std::unique_ptr<Callback> callback, OverlayPrivacyRules rules, td::string scope) = 0;
|
||||
virtual void create_private_overlay(adnl::AdnlNodeIdShort local_id, OverlayIdFull overlay_id,
|
||||
std::vector<adnl::AdnlNodeIdShort> nodes, std::unique_ptr<Callback> callback,
|
||||
OverlayPrivacyRules rules) = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue