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_COLLECTION, TrafficCount::Category::Validatorlist},
18 {protocol::mtVALIDATION, TrafficCount::Category::Validation},
19 {protocol::mtPROPOSE_LEDGER, TrafficCount::Category::Proposal},
20 {protocol::mtPROOF_PATH_REQ, TrafficCount::Category::ProofPathRequest},
21 {protocol::mtPROOF_PATH_RESPONSE, TrafficCount::Category::ProofPathResponse},
22 {protocol::mtREPLAY_DELTA_REQ, TrafficCount::Category::ReplayDeltaRequest},
23 {protocol::mtREPLAY_DELTA_RESPONSE, TrafficCount::Category::ReplayDeltaResponse},
24 {protocol::mtHAVE_TRANSACTIONS, TrafficCount::Category::HaveTransactions},
25 {protocol::mtTRANSACTIONS, TrafficCount::Category::RequestedTransactions},
26 {protocol::mtSQUELCH, TrafficCount::Category::Squelch},
27};
28
31 ::google::protobuf::Message const& message,
32 protocol::MessageType type,
33 bool inbound)
34{
35 if (auto item = kTypeLookup.find(type); item != kTypeLookup.end())
36 return item->second;
37
38 if (type == protocol::mtHAVE_SET)
40
41 if (auto msg = dynamic_cast<protocol::TMLedgerData const*>(&message))
42 {
43 if (msg->type() == protocol::liTS_CANDIDATE)
44 {
45 return (inbound && !msg->has_requestcookie()) ? TrafficCount::Category::LdTscGet
47 }
48
49 if (msg->type() == protocol::liTX_NODE)
50 {
51 return (inbound && !msg->has_requestcookie()) ? TrafficCount::Category::LdTxnGet
53 }
54
55 if (msg->type() == protocol::liAS_NODE)
56 {
57 return (inbound && !msg->has_requestcookie()) ? TrafficCount::Category::LdAsnGet
59 }
60
61 return (inbound && !msg->has_requestcookie()) ? TrafficCount::Category::LdGet
63 }
64
65 if (auto msg = dynamic_cast<protocol::TMGetLedger const*>(&message))
66 {
67 if (msg->itype() == protocol::liTS_CANDIDATE)
68 {
69 return (inbound || msg->has_requestcookie()) ? TrafficCount::Category::GlTscShare
71 }
72
73 if (msg->itype() == protocol::liTX_NODE)
74 {
75 return (inbound || msg->has_requestcookie()) ? TrafficCount::Category::GlTxnShare
77 }
78
79 if (msg->itype() == protocol::liAS_NODE)
80 {
81 return (inbound || msg->has_requestcookie()) ? TrafficCount::Category::GlAsnShare
83 }
84
85 return (inbound || msg->has_requestcookie()) ? TrafficCount::Category::GlShare
87 }
88
89 if (auto msg = dynamic_cast<protocol::TMGetObjectByHash const*>(&message))
90 {
91 if (msg->type() == protocol::TMGetObjectByHash::otLEDGER)
92 {
93 return (msg->query() == inbound) ? TrafficCount::Category::ShareHashLedger
95 }
96
97 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION)
98 {
99 return (msg->query() == inbound) ? TrafficCount::Category::ShareHashTx
101 }
102
103 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION_NODE)
104 {
105 return (msg->query() == inbound) ? TrafficCount::Category::ShareHashTxnode
107 }
108
109 if (msg->type() == protocol::TMGetObjectByHash::otSTATE_NODE)
110 {
111 return (msg->query() == inbound) ? TrafficCount::Category::ShareHashAsnode
113 }
114
115 if (msg->type() == protocol::TMGetObjectByHash::otCAS_OBJECT)
116 {
117 return (msg->query() == inbound) ? TrafficCount::Category::ShareCasObject
119 }
120
121 if (msg->type() == protocol::TMGetObjectByHash::otFETCH_PACK)
122 {
123 return (msg->query() == inbound) ? TrafficCount::Category::ShareFetchPack
125 }
126
127 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTIONS)
129
130 return (msg->query() == inbound) ? TrafficCount::Category::ShareHash
132 }
133
135}
136} // 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