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
26 ::google::protobuf::Message const& message,
27 protocol::MessageType type,
28 bool inbound)
29{
30 if (auto item = type_lookup.find(type); item != type_lookup.end())
31 return item->second;
32
33 if (type == protocol::mtHAVE_SET)
35
36 if (auto msg = dynamic_cast<protocol::TMLedgerData const*>(&message))
37 {
38 if (msg->type() == protocol::liTS_CANDIDATE)
39 {
40 return (inbound && !msg->has_requestcookie()) ? TrafficCount::category::ld_tsc_get
42 }
43
44 if (msg->type() == protocol::liTX_NODE)
45 {
46 return (inbound && !msg->has_requestcookie()) ? TrafficCount::category::ld_txn_get
48 }
49
50 if (msg->type() == protocol::liAS_NODE)
51 {
52 return (inbound && !msg->has_requestcookie()) ? TrafficCount::category::ld_asn_get
54 }
55
56 return (inbound && !msg->has_requestcookie()) ? TrafficCount::category::ld_get
58 }
59
60 if (auto msg = dynamic_cast<protocol::TMGetLedger const*>(&message))
61 {
62 if (msg->itype() == protocol::liTS_CANDIDATE)
63 {
64 return (inbound || msg->has_requestcookie()) ? TrafficCount::category::gl_tsc_share
66 }
67
68 if (msg->itype() == protocol::liTX_NODE)
69 {
70 return (inbound || msg->has_requestcookie()) ? TrafficCount::category::gl_txn_share
72 }
73
74 if (msg->itype() == protocol::liAS_NODE)
75 {
76 return (inbound || msg->has_requestcookie()) ? TrafficCount::category::gl_asn_share
78 }
79
80 return (inbound || msg->has_requestcookie()) ? TrafficCount::category::gl_share
82 }
83
84 if (auto msg = dynamic_cast<protocol::TMGetObjectByHash const*>(&message))
85 {
86 if (msg->type() == protocol::TMGetObjectByHash::otLEDGER)
87 {
88 return (msg->query() == inbound) ? TrafficCount::category::share_hash_ledger
90 }
91
92 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION)
93 {
94 return (msg->query() == inbound) ? TrafficCount::category::share_hash_tx
96 }
97
98 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION_NODE)
99 {
100 return (msg->query() == inbound) ? TrafficCount::category::share_hash_txnode
102 }
103
104 if (msg->type() == protocol::TMGetObjectByHash::otSTATE_NODE)
105 {
106 return (msg->query() == inbound) ? TrafficCount::category::share_hash_asnode
108 }
109
110 if (msg->type() == protocol::TMGetObjectByHash::otCAS_OBJECT)
111 {
112 return (msg->query() == inbound) ? TrafficCount::category::share_cas_object
114 }
115
116 if (msg->type() == protocol::TMGetObjectByHash::otFETCH_PACK)
117 {
118 return (msg->query() == inbound) ? TrafficCount::category::share_fetch_pack
120 }
121
122 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTIONS)
124
125 return (msg->query() == inbound) ? TrafficCount::category::share_hash
127 }
128
130}
131} // 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