rippled
Loading...
Searching...
No Matches
TrafficCount.cpp
1#include <xrpld/overlay/detail/TrafficCount.h>
2
3namespace ripple {
4
7 {protocol::mtPING, TrafficCount::category::base},
8 {protocol::mtSTATUS_CHANGE, TrafficCount::category::base},
9 {protocol::mtMANIFESTS, TrafficCount::category::manifests},
10 {protocol::mtENDPOINTS, TrafficCount::category::overlay},
11 {protocol::mtTRANSACTION, TrafficCount::category::transaction},
12 {protocol::mtVALIDATORLIST, TrafficCount::category::validatorlist},
13 {protocol::mtVALIDATORLISTCOLLECTION,
15 {protocol::mtVALIDATION, TrafficCount::category::validation},
16 {protocol::mtPROPOSE_LEDGER, TrafficCount::category::proposal},
17 {protocol::mtPROOF_PATH_REQ,
19 {protocol::mtPROOF_PATH_RESPONSE,
21 {protocol::mtREPLAY_DELTA_REQ,
23 {protocol::mtREPLAY_DELTA_RESPONSE,
25 {protocol::mtHAVE_TRANSACTIONS,
27 {protocol::mtTRANSACTIONS,
29 {protocol::mtSQUELCH, TrafficCount::category::squelch},
30};
31
34 ::google::protobuf::Message const& message,
35 protocol::MessageType type,
36 bool inbound)
37{
38 if (auto item = type_lookup.find(type); item != type_lookup.end())
39 return item->second;
40
41 if (type == protocol::mtHAVE_SET)
42 return inbound ? TrafficCount::category::get_set
44
45 if (auto msg = dynamic_cast<protocol::TMLedgerData const*>(&message))
46 {
47 if (msg->type() == protocol::liTS_CANDIDATE)
48 return (inbound && !msg->has_requestcookie())
51
52 if (msg->type() == protocol::liTX_NODE)
53 return (inbound && !msg->has_requestcookie())
56
57 if (msg->type() == protocol::liAS_NODE)
58 return (inbound && !msg->has_requestcookie())
61
62 return (inbound && !msg->has_requestcookie())
65 }
66
67 if (auto msg = dynamic_cast<protocol::TMGetLedger const*>(&message))
68 {
69 if (msg->itype() == protocol::liTS_CANDIDATE)
70 return (inbound || msg->has_requestcookie())
73
74 if (msg->itype() == protocol::liTX_NODE)
75 return (inbound || msg->has_requestcookie())
78
79 if (msg->itype() == protocol::liAS_NODE)
80 return (inbound || msg->has_requestcookie())
83
84 return (inbound || msg->has_requestcookie())
87 }
88
89 if (auto msg = dynamic_cast<protocol::TMGetObjectByHash const*>(&message))
90 {
91 if (msg->type() == protocol::TMGetObjectByHash::otLEDGER)
92 return (msg->query() == inbound)
95
96 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION)
97 return (msg->query() == inbound)
100
101 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION_NODE)
102 return (msg->query() == inbound)
105
106 if (msg->type() == protocol::TMGetObjectByHash::otSTATE_NODE)
107 return (msg->query() == inbound)
110
111 if (msg->type() == protocol::TMGetObjectByHash::otCAS_OBJECT)
112 return (msg->query() == inbound)
115
116 if (msg->type() == protocol::TMGetObjectByHash::otFETCH_PACK)
117 return (msg->query() == inbound)
120
121 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTIONS)
123
124 return (msg->query() == inbound) ? TrafficCount::category::share_hash
126 }
127
129}
130} // namespace ripple
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:6
std::unordered_map< protocol::MessageType, TrafficCount::category > const type_lookup