xrpld
Loading...
Searching...
No Matches
TrafficCount.cpp
1#include <xrpld/overlay/detail/TrafficCount.h>
2
3#include <google/protobuf/message.h>
4
5#include <xrpl.pb.h>
6
7#include <unordered_map>
8
9namespace xrpl {
10
12 {protocol::mtPING, TrafficCount::Category::Base},
13 {protocol::mtSTATUS_CHANGE, TrafficCount::Category::Base},
14 {protocol::mtMANIFESTS, TrafficCount::Category::Manifests},
15 {protocol::mtENDPOINTS, TrafficCount::Category::Overlay},
16 {protocol::mtTRANSACTION, TrafficCount::Category::Transaction},
17 {protocol::mtVALIDATOR_LIST, TrafficCount::Category::Validatorlist},
18 {protocol::mtVALIDATOR_LIST_COLLECTION, TrafficCount::Category::Validatorlist},
19 {protocol::mtVALIDATION, TrafficCount::Category::Validation},
20 {protocol::mtPROPOSE_LEDGER, TrafficCount::Category::Proposal},
21 {protocol::mtPROOF_PATH_REQ, TrafficCount::Category::ProofPathRequest},
22 {protocol::mtPROOF_PATH_RESPONSE, TrafficCount::Category::ProofPathResponse},
23 {protocol::mtREPLAY_DELTA_REQ, TrafficCount::Category::ReplayDeltaRequest},
24 {protocol::mtREPLAY_DELTA_RESPONSE, TrafficCount::Category::ReplayDeltaResponse},
25 {protocol::mtHAVE_TRANSACTIONS, TrafficCount::Category::HaveTransactions},
26 {protocol::mtTRANSACTIONS, TrafficCount::Category::RequestedTransactions},
27 {protocol::mtSQUELCH, TrafficCount::Category::Squelch},
28};
29
32 ::google::protobuf::Message const& message,
33 protocol::MessageType type,
34 bool inbound)
35{
36 if (auto item = kTypeLookup.find(type); item != kTypeLookup.end())
37 return item->second;
38
39 if (type == protocol::mtHAVE_SET)
41
42 if (auto msg = dynamic_cast<protocol::TMLedgerData const*>(&message))
43 {
44 if (msg->type() == protocol::liTS_CANDIDATE)
45 {
46 return (inbound && !msg->has_requestcookie()) ? TrafficCount::Category::LdTscGet
48 }
49
50 if (msg->type() == protocol::liTX_NODE)
51 {
52 return (inbound && !msg->has_requestcookie()) ? TrafficCount::Category::LdTxnGet
54 }
55
56 if (msg->type() == protocol::liAS_NODE)
57 {
58 return (inbound && !msg->has_requestcookie()) ? TrafficCount::Category::LdAsnGet
60 }
61
62 return (inbound && !msg->has_requestcookie()) ? TrafficCount::Category::LdGet
64 }
65
66 if (auto msg = dynamic_cast<protocol::TMGetLedger const*>(&message))
67 {
68 if (msg->itype() == protocol::liTS_CANDIDATE)
69 {
70 return (inbound || msg->has_requestcookie()) ? TrafficCount::Category::GlTscShare
72 }
73
74 if (msg->itype() == protocol::liTX_NODE)
75 {
76 return (inbound || msg->has_requestcookie()) ? TrafficCount::Category::GlTxnShare
78 }
79
80 if (msg->itype() == protocol::liAS_NODE)
81 {
82 return (inbound || msg->has_requestcookie()) ? TrafficCount::Category::GlAsnShare
84 }
85
86 return (inbound || msg->has_requestcookie()) ? TrafficCount::Category::GlShare
88 }
89
90 if (auto msg = dynamic_cast<protocol::TMGetObjectByHash const*>(&message))
91 {
92 if (msg->type() == protocol::TMGetObjectByHash::otLEDGER)
93 {
94 return (msg->query() == inbound) ? TrafficCount::Category::ShareHashLedger
96 }
97
98 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION)
99 {
100 return (msg->query() == inbound) ? TrafficCount::Category::ShareHashTx
102 }
103
104 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION_NODE)
105 {
106 return (msg->query() == inbound) ? TrafficCount::Category::ShareHashTxnode
108 }
109
110 if (msg->type() == protocol::TMGetObjectByHash::otSTATE_NODE)
111 {
112 return (msg->query() == inbound) ? TrafficCount::Category::ShareHashAsnode
114 }
115
116 if (msg->type() == protocol::TMGetObjectByHash::otCAS_OBJECT)
117 {
118 return (msg->query() == inbound) ? TrafficCount::Category::ShareCasObject
120 }
121
122 if (msg->type() == protocol::TMGetObjectByHash::otFETCH_PACK)
123 {
124 return (msg->query() == inbound) ? TrafficCount::Category::ShareFetchPack
126 }
127
128 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTIONS)
130
131 return (msg->query() == inbound) ? TrafficCount::Category::ShareHash
133 }
134
136}
137} // 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 kTypeLookup