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 ::google::protobuf::Message const& message,
27 int type,
28 bool inbound)
29{
30 if ((type == protocol::mtPING) || (type == protocol::mtSTATUS_CHANGE))
32
33 if (type == protocol::mtCLUSTER)
35
36 if (type == protocol::mtMANIFESTS)
38
39 if (type == protocol::mtENDPOINTS)
41
42 if (type == protocol::mtTRANSACTION)
44
45 if (type == protocol::mtVALIDATORLIST ||
46 type == protocol::mtVALIDATORLISTCOLLECTION)
48
49 if (type == protocol::mtVALIDATION)
51
52 if (type == protocol::mtPROPOSE_LEDGER)
54
55 if (type == protocol::mtHAVE_SET)
56 return inbound ? TrafficCount::category::get_set
58
59 if (auto msg = dynamic_cast<protocol::TMLedgerData const*>(&message))
60 {
61 if (msg->type() == protocol::liTS_CANDIDATE)
62 return (inbound && !msg->has_requestcookie())
65
66 if (msg->type() == protocol::liTX_NODE)
67 return (inbound && !msg->has_requestcookie())
70
71 if (msg->type() == protocol::liAS_NODE)
72 return (inbound && !msg->has_requestcookie())
75
76 return (inbound && !msg->has_requestcookie())
79 }
80
81 if (auto msg = dynamic_cast<protocol::TMGetLedger const*>(&message))
82 {
83 if (msg->itype() == protocol::liTS_CANDIDATE)
84 return (inbound || msg->has_requestcookie())
87
88 if (msg->itype() == protocol::liTX_NODE)
89 return (inbound || msg->has_requestcookie())
92
93 if (msg->itype() == protocol::liAS_NODE)
94 return (inbound || msg->has_requestcookie())
97
98 return (inbound || msg->has_requestcookie())
101 }
102
103 if (auto msg = dynamic_cast<protocol::TMGetObjectByHash const*>(&message))
104 {
105 if (msg->type() == protocol::TMGetObjectByHash::otLEDGER)
106 return (msg->query() == inbound)
109
110 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION)
111 return (msg->query() == inbound)
114
115 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION_NODE)
116 return (msg->query() == inbound)
119
120 if (msg->type() == protocol::TMGetObjectByHash::otSTATE_NODE)
121 return (msg->query() == inbound)
124
125 if (msg->type() == protocol::TMGetObjectByHash::otCAS_OBJECT)
126 return (msg->query() == inbound)
129
130 if (msg->type() == protocol::TMGetObjectByHash::otFETCH_PACK)
131 return (msg->query() == inbound)
134
135 if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTIONS)
137
138 return (msg->query() == inbound) ? TrafficCount::category::share_hash
140 }
141
142 if (type == protocol::mtPROOF_PATH_REQ)
144
145 if (type == protocol::mtPROOF_PATH_RESPONSE)
147
148 if (type == protocol::mtREPLAY_DELTA_REQ)
150
151 if (type == protocol::mtREPLAY_DELTA_RESPONSE)
153
154 if (type == protocol::mtHAVE_TRANSACTIONS)
156
157 if (type == protocol::mtTRANSACTIONS)
159
161}
162
163} // namespace ripple
static category categorize(::google::protobuf::Message const &message, int 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:26