rippled
Loading...
Searching...
No Matches
TrafficCount.cpp
1#include <xrpld/overlay/detail/TrafficCount.h>
2
3namespace xrpl {
4
6 {protocol::mtPING, TrafficCount::category::base},
7 {protocol::mtSTATUS_CHANGE, TrafficCount::category::base},
8 {protocol::mtMANIFESTS, TrafficCount::category::manifests},
9 {protocol::mtENDPOINTS, TrafficCount::category::overlay},
10 {protocol::mtTRANSACTION, TrafficCount::category::transaction},
11 {protocol::mtVALIDATOR_LIST, TrafficCount::category::validatorlist},
12 {protocol::mtVALIDATOR_LIST_COLLECTION, TrafficCount::category::validatorlist},
13 {protocol::mtVALIDATION, TrafficCount::category::validation},
14 {protocol::mtPROPOSE_LEDGER, TrafficCount::category::proposal},
15 {protocol::mtPROOF_PATH_REQ, TrafficCount::category::proof_path_request},
16 {protocol::mtPROOF_PATH_RESPONSE, TrafficCount::category::proof_path_response},
17 {protocol::mtREPLAY_DELTA_REQ, TrafficCount::category::replay_delta_request},
18 {protocol::mtREPLAY_DELTA_RESPONSE, TrafficCount::category::replay_delta_response},
19 {protocol::mtHAVE_TRANSACTIONS, TrafficCount::category::have_transactions},
20 {protocol::mtTRANSACTIONS, TrafficCount::category::requested_transactions},
21 {protocol::mtSQUELCH, TrafficCount::category::squelch},
22};
23
25TrafficCount::categorize(::google::protobuf::Message const& message, protocol::MessageType type, bool inbound)
26{
27 if (auto item = type_lookup.find(type); item != type_lookup.end())
28 return item->second;
29
30 if (type == protocol::mtHAVE_SET)
32
33 if (auto msg = dynamic_cast<protocol::TMLedgerData const*>(&message))
34 {
35 if (msg->type() == protocol::liTS_CANDIDATE)
36 return (inbound && !msg->has_requestcookie()) ? TrafficCount::category::ld_tsc_get
38
39 if (msg->type() == protocol::liTX_NODE)
40 return (inbound && !msg->has_requestcookie()) ? TrafficCount::category::ld_txn_get
42
43 if (msg->type() == protocol::liAS_NODE)
44 return (inbound && !msg->has_requestcookie()) ? TrafficCount::category::ld_asn_get
46
47 return (inbound && !msg->has_requestcookie()) ? TrafficCount::category::ld_get
49 }
50
51 if (auto msg = dynamic_cast<protocol::TMGetLedger const*>(&message))
52 {
53 if (msg->itype() == protocol::liTS_CANDIDATE)
54 return (inbound || msg->has_requestcookie()) ? TrafficCount::category::gl_tsc_share
56
57 if (msg->itype() == protocol::liTX_NODE)
58 return (inbound || msg->has_requestcookie()) ? TrafficCount::category::gl_txn_share
60
61 if (msg->itype() == protocol::liAS_NODE)
62 return (inbound || msg->has_requestcookie()) ? TrafficCount::category::gl_asn_share
64
65 return (inbound || msg->has_requestcookie()) ? TrafficCount::category::gl_share
67 }
68
69 if (auto msg = dynamic_cast<protocol::TMGetObjectByHash const*>(&message))
70 {
71 if (msg->type() == protocol::TMGetObjectByHash::otLEDGER)
72 return (msg->query() == inbound) ? TrafficCount::category::share_hash_ledger
74
75 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION)
76 return (msg->query() == inbound) ? TrafficCount::category::share_hash_tx
78
79 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION_NODE)
80 return (msg->query() == inbound) ? TrafficCount::category::share_hash_txnode
82
83 if (msg->type() == protocol::TMGetObjectByHash::otSTATE_NODE)
84 return (msg->query() == inbound) ? TrafficCount::category::share_hash_asnode
86
87 if (msg->type() == protocol::TMGetObjectByHash::otCAS_OBJECT)
88 return (msg->query() == inbound) ? TrafficCount::category::share_cas_object
90
91 if (msg->type() == protocol::TMGetObjectByHash::otFETCH_PACK)
92 return (msg->query() == inbound) ? TrafficCount::category::share_fetch_pack
94
95 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTIONS)
97
99 }
100
102}
103} // namespace xrpl
static category categorize(::google::protobuf::Message const &message, protocol::MessageType type, bool inbound)
Given a protocol message, determine which traffic category it belongs to.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::unordered_map< protocol::MessageType, TrafficCount::category > const type_lookup