rippled
Loading...
Searching...
No Matches
TrafficCount.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/overlay/detail/TrafficCount.h>
21
22namespace ripple {
23
26 {protocol::mtPING, TrafficCount::category::base},
27 {protocol::mtSTATUS_CHANGE, TrafficCount::category::base},
28 {protocol::mtMANIFESTS, TrafficCount::category::manifests},
29 {protocol::mtENDPOINTS, TrafficCount::category::overlay},
30 {protocol::mtTRANSACTION, TrafficCount::category::transaction},
31 {protocol::mtVALIDATORLIST, TrafficCount::category::validatorlist},
32 {protocol::mtVALIDATORLISTCOLLECTION,
34 {protocol::mtVALIDATION, TrafficCount::category::validation},
35 {protocol::mtPROPOSE_LEDGER, TrafficCount::category::proposal},
36 {protocol::mtPROOF_PATH_REQ,
38 {protocol::mtPROOF_PATH_RESPONSE,
40 {protocol::mtREPLAY_DELTA_REQ,
42 {protocol::mtREPLAY_DELTA_RESPONSE,
44 {protocol::mtHAVE_TRANSACTIONS,
46 {protocol::mtTRANSACTIONS,
48 {protocol::mtSQUELCH, TrafficCount::category::squelch},
49};
50
53 ::google::protobuf::Message const& message,
54 protocol::MessageType type,
55 bool inbound)
56{
57 if (auto item = type_lookup.find(type); item != type_lookup.end())
58 return item->second;
59
60 if (type == protocol::mtHAVE_SET)
61 return inbound ? TrafficCount::category::get_set
63
64 if (auto msg = dynamic_cast<protocol::TMLedgerData const*>(&message))
65 {
66 if (msg->type() == protocol::liTS_CANDIDATE)
67 return (inbound && !msg->has_requestcookie())
70
71 if (msg->type() == protocol::liTX_NODE)
72 return (inbound && !msg->has_requestcookie())
75
76 if (msg->type() == protocol::liAS_NODE)
77 return (inbound && !msg->has_requestcookie())
80
81 return (inbound && !msg->has_requestcookie())
84 }
85
86 if (auto msg = dynamic_cast<protocol::TMGetLedger const*>(&message))
87 {
88 if (msg->itype() == protocol::liTS_CANDIDATE)
89 return (inbound || msg->has_requestcookie())
92
93 if (msg->itype() == protocol::liTX_NODE)
94 return (inbound || msg->has_requestcookie())
97
98 if (msg->itype() == protocol::liAS_NODE)
99 return (inbound || msg->has_requestcookie())
102
103 return (inbound || msg->has_requestcookie())
106 }
107
108 if (auto msg = dynamic_cast<protocol::TMGetObjectByHash const*>(&message))
109 {
110 if (msg->type() == protocol::TMGetObjectByHash::otLEDGER)
111 return (msg->query() == inbound)
114
115 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION)
116 return (msg->query() == inbound)
119
120 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION_NODE)
121 return (msg->query() == inbound)
124
125 if (msg->type() == protocol::TMGetObjectByHash::otSTATE_NODE)
126 return (msg->query() == inbound)
129
130 if (msg->type() == protocol::TMGetObjectByHash::otCAS_OBJECT)
131 return (msg->query() == inbound)
134
135 if (msg->type() == protocol::TMGetObjectByHash::otFETCH_PACK)
136 return (msg->query() == inbound)
139
140 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTIONS)
142
143 return (msg->query() == inbound) ? TrafficCount::category::share_hash
145 }
146
148}
149} // 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:25
std::unordered_map< protocol::MessageType, TrafficCount::category > const type_lookup