rippled
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 <ripple/overlay/impl/TrafficCount.h>
21 
22 namespace ripple {
23 
25  ::google::protobuf::Message const& message,
26  int type, bool inbound)
27 {
28  if ((type == protocol::mtPING) || (type == protocol::mtSTATUS_CHANGE))
29  return TrafficCount::category::base;
30 
31  if (type == protocol::mtCLUSTER)
32  return TrafficCount::category::cluster;
33 
34  if (type == protocol::mtMANIFESTS)
35  return TrafficCount::category::manifests;
36 
37  if (type == protocol::mtENDPOINTS)
38  return TrafficCount::category::overlay;
39 
40  if ((type == protocol::mtGET_SHARD_INFO) ||
41  (type == protocol::mtSHARD_INFO) ||
42  (type == protocol::mtGET_PEER_SHARD_INFO) ||
43  (type == protocol::mtPEER_SHARD_INFO))
44  return TrafficCount::category::shards;
45 
46  if (type == protocol::mtTRANSACTION)
47  return TrafficCount::category::transaction;
48 
49  if (type == protocol::mtVALIDATORLIST)
50  return TrafficCount::category::validatorlist;
51 
52  if (type == protocol::mtVALIDATION)
53  return TrafficCount::category::validation;
54 
55  if (type == protocol::mtPROPOSE_LEDGER)
56  return TrafficCount::category::proposal;
57 
58  if (type == protocol::mtHAVE_SET)
59  return inbound ?
60  TrafficCount::category::get_set:
61  TrafficCount::category::share_set;
62 
63  if (auto msg = dynamic_cast<protocol::TMLedgerData const*>(&message))
64  {
65  if (msg->type() == protocol::liTS_CANDIDATE)
66  return (inbound && !msg->has_requestcookie()) ?
67  TrafficCount::category::ld_tsc_get:
68  TrafficCount::category::ld_tsc_share;
69 
70  if (msg->type() == protocol::liTX_NODE)
71  return (inbound && !msg->has_requestcookie()) ?
72  TrafficCount::category::ld_txn_get :
73  TrafficCount::category::ld_txn_share;
74 
75  if (msg->type() == protocol::liAS_NODE)
76  return (inbound && !msg->has_requestcookie()) ?
77  TrafficCount::category::ld_asn_get :
78  TrafficCount::category::ld_asn_share;
79 
80  return (inbound && !msg->has_requestcookie()) ?
81  TrafficCount::category::ld_get :
82  TrafficCount::category::ld_share;
83  }
84 
85  if (auto msg = dynamic_cast<protocol::TMGetLedger const*>(&message))
86  {
87  if (msg->itype() == protocol::liTS_CANDIDATE)
88  return (inbound || msg->has_requestcookie()) ?
89  TrafficCount::category::gl_tsc_share :
90  TrafficCount::category::gl_tsc_get;
91 
92  if (msg->itype() == protocol::liTX_NODE)
93  return (inbound || msg->has_requestcookie()) ?
94  TrafficCount::category::gl_txn_share :
95  TrafficCount::category::gl_txn_get;
96 
97  if (msg->itype() == protocol::liAS_NODE)
98  return (inbound || msg->has_requestcookie()) ?
99  TrafficCount::category::gl_asn_share :
100  TrafficCount::category::gl_asn_get;
101 
102  return (inbound || msg->has_requestcookie()) ?
103  TrafficCount::category::gl_share :
104  TrafficCount::category::gl_get;
105  }
106 
107  if (auto msg = dynamic_cast<protocol::TMGetObjectByHash const*>(&message))
108  {
109  if (msg->type() == protocol::TMGetObjectByHash::otLEDGER)
110  return (msg->query() == inbound) ?
111  TrafficCount::category::share_hash_ledger :
112  TrafficCount::category::get_hash_ledger;
113 
114  if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION)
115  return (msg->query() == inbound) ?
116  TrafficCount::category::share_hash_tx :
117  TrafficCount::category::get_hash_tx;
118 
119  if (msg->type() == protocol::TMGetObjectByHash::otTRANSACTION_NODE)
120  return (msg->query() == inbound) ?
121  TrafficCount::category::share_hash_txnode :
122  TrafficCount::category::get_hash_txnode;
123 
124  if (msg->type() == protocol::TMGetObjectByHash::otSTATE_NODE)
125  return (msg->query() == inbound) ?
126  TrafficCount::category::share_hash_asnode :
127  TrafficCount::category::get_hash_asnode;
128 
129  if (msg->type() == protocol::TMGetObjectByHash::otCAS_OBJECT)
130  return (msg->query() == inbound) ?
131  TrafficCount::category::share_cas_object :
132  TrafficCount::category::get_cas_object;
133 
134  if (msg->type() == protocol::TMGetObjectByHash::otFETCH_PACK)
135  return (msg->query() == inbound) ?
136  TrafficCount::category::share_fetch_pack :
137  TrafficCount::category::get_fetch_pack;
138 
139  return (msg->query() == inbound) ?
140  TrafficCount::category::share_hash :
141  TrafficCount::category::get_hash;
142  }
143 
144  return TrafficCount::category::unknown;
145 }
146 
147 } // ripple
ripple::TrafficCount::categorize
static category categorize(::google::protobuf::Message const &message, int type, bool inbound)
Given a protocol message, determine which traffic category it belongs to.
Definition: TrafficCount.cpp:24
ripple::TrafficCount::category
category
Definition: TrafficCount.h:68
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29