xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
overlay
detail
TrafficCount.h
1
#pragma once
2
3
#include <xrpl/beast/utility/instrumentation.h>
4
5
#include <google/protobuf/message.h>
6
7
#include <xrpl.pb.h>
8
9
#include <
atomic
>
10
#include <
cstddef
>
11
#include <
cstdint
>
12
#include <
string
>
13
#include <
unordered_map
>
14
15
namespace
xrpl
{
16
35
class
TrafficCount
36
{
37
public
:
38
enum class
Category
:
std::size_t
;
39
40
class
TrafficStats
41
{
42
public
:
43
std::string
name
;
44
45
std::atomic<std::uint64_t>
bytesIn
{0};
46
std::atomic<std::uint64_t>
bytesOut
{0};
47
std::atomic<std::uint64_t>
messagesIn
{0};
48
std::atomic<std::uint64_t>
messagesOut
{0};
49
50
TrafficStats
(
TrafficCount::Category
cat) :
name
(
TrafficCount
::
toString
(cat))
51
{
52
}
53
54
TrafficStats
(
TrafficStats
const
& ts)
55
:
name
(ts.
name
)
56
,
bytesIn
(ts.
bytesIn
.load())
57
,
bytesOut
(ts.
bytesOut
.load())
58
,
messagesIn
(ts.
messagesIn
.load())
59
,
messagesOut
(ts.
messagesOut
.load())
60
{
61
}
62
63
operator
bool()
const
64
{
65
return
(
messagesIn
!= 0u) || (
messagesOut
!= 0u);
66
}
67
};
68
69
// If you add entries to this enum, you need to update the initialization
70
// of the arrays at the bottom of this file which map array numbers to
71
// human-readable, monitoring-tool friendly names.
72
enum class
Category
:
std::size_t
{
73
Base,
// basic peer overhead, must be first
74
75
Cluster
,
// cluster overhead
76
Overlay
,
// overlay management
77
Manifests
,
// manifest management
78
79
Transaction
,
// transaction messages
80
// The following categories breakdown transaction message type
81
TransactionDuplicate
,
// duplicate transaction messages
82
83
Proposal
,
// proposal messages
84
// The following categories breakdown proposal message type
85
ProposalUntrusted
,
// proposals from untrusted validators
86
ProposalDuplicate
,
// proposals seen previously
87
88
Validation
,
// validation messages
89
// The following categories breakdown validation message type
90
ValidationUntrusted
,
// validations from untrusted validators
91
ValidationDuplicate
,
// validations seen previously
92
93
Validatorlist
,
94
95
Squelch
,
96
SquelchSuppressed
,
// egress traffic amount suppressed by squelching
97
SquelchIgnored
,
// the traffic amount that came from peers ignoring
98
// squelch messages
99
100
// TMHaveSet message:
101
GetSet
,
// transaction sets we try to get
102
ShareSet
,
// transaction sets we get
103
104
// TMLedgerData: transaction set candidate
105
LdTscGet
,
106
LdTscShare
,
107
108
// TMLedgerData: transaction node
109
LdTxnGet
,
110
LdTxnShare
,
111
112
// TMLedgerData: account state node
113
LdAsnGet
,
114
LdAsnShare
,
115
116
// TMLedgerData: generic
117
LdGet
,
118
LdShare
,
119
120
// TMGetLedger: transaction set candidate
121
GlTscShare
,
122
GlTscGet
,
123
124
// TMGetLedger: transaction node
125
GlTxnShare
,
126
GlTxnGet
,
127
128
// TMGetLedger: account state node
129
GlAsnShare
,
130
GlAsnGet
,
131
132
// TMGetLedger: generic
133
GlShare
,
134
GlGet
,
135
136
// TMGetObjectByHash:
137
ShareHashLedger
,
138
GetHashLedger
,
139
140
// TMGetObjectByHash:
141
ShareHashTx
,
142
GetHashTx
,
143
144
// TMGetObjectByHash: transaction node
145
ShareHashTxnode
,
146
GetHashTxnode
,
147
148
// TMGetObjectByHash: account state node
149
ShareHashAsnode
,
150
GetHashAsnode
,
151
152
// TMGetObjectByHash: CAS
153
ShareCasObject
,
154
GetCasObject
,
155
156
// TMGetObjectByHash: fetch packs
157
ShareFetchPack
,
158
GetFetchPack
,
159
160
// TMGetObjectByHash: transactions
161
GetTransactions
,
162
163
// TMGetObjectByHash: generic
164
ShareHash
,
165
GetHash
,
166
167
// TMProofPathRequest and TMProofPathResponse
168
ProofPathRequest
,
169
ProofPathResponse
,
170
171
// TMReplayDeltaRequest and TMReplayDeltaResponse
172
ReplayDeltaRequest
,
173
ReplayDeltaResponse
,
174
175
// TMHaveTransactions
176
HaveTransactions
,
177
178
// TMTransactions
179
RequestedTransactions
,
180
181
// The total p2p bytes sent and received on the wire
182
Total
,
183
184
Unknown
// must be last
185
};
186
187
TrafficCount
() =
default
;
188
192
static
Category
193
categorize
(
194
::google::protobuf::Message
const
& message,
195
protocol::MessageType type,
196
bool
inbound);
197
201
enum class
IsFromCluster
:
bool
{
No
=
false
,
Yes
};
202
217
[[nodiscard]]
static
Category
218
attribute
(
Category
cat,
IsFromCluster
isFromCluster);
219
223
void
224
addCount
(
Category
cat,
bool
inbound,
int
bytes)
225
{
226
XRPL_ASSERT(
227
cat <=
Category::Unknown
,
"xrpl::TrafficCount::addCount : valid category input"
);
228
229
auto
it =
counts_
.find(cat);
230
231
// nothing to do, the category does not exist
232
if
(it ==
counts_
.end())
233
return
;
234
235
if
(inbound)
236
{
237
it->second.bytesIn += bytes;
238
++it->second.messagesIn;
239
}
240
else
241
{
242
it->second.bytesOut += bytes;
243
++it->second.messagesOut;
244
}
245
}
246
252
[[nodiscard]]
auto
const
&
253
getCounts
()
const
254
{
255
return
counts_
;
256
}
257
258
static
std::string
259
toString
(
Category
cat)
260
{
261
static
std::unordered_map<Category, std::string>
const
kCategoryMap = {
262
{
Category::Base
,
"overhead"
},
263
{
Category::Cluster
,
"overhead_cluster"
},
264
{
Category::Overlay
,
"overhead_overlay"
},
265
{
Category::Manifests
,
"overhead_manifest"
},
266
{
Category::Transaction
,
"transactions"
},
267
{
Category::TransactionDuplicate
,
"transactions_duplicate"
},
268
{
Category::Proposal
,
"proposals"
},
269
{
Category::ProposalUntrusted
,
"proposals_untrusted"
},
270
{
Category::ProposalDuplicate
,
"proposals_duplicate"
},
271
{
Category::Validation
,
"validations"
},
272
{
Category::ValidationUntrusted
,
"validations_untrusted"
},
273
{
Category::ValidationDuplicate
,
"validations_duplicate"
},
274
{
Category::Validatorlist
,
"validator_lists"
},
275
{
Category::Squelch
,
"squelch"
},
276
{
Category::SquelchSuppressed
,
"squelch_suppressed"
},
277
{
Category::SquelchIgnored
,
"squelch_ignored"
},
278
{
Category::GetSet
,
"set_get"
},
279
{
Category::ShareSet
,
"set_share"
},
280
{
Category::LdTscGet
,
"ledger_data_Transaction_Set_candidate_get"
},
281
{
Category::LdTscShare
,
"ledger_data_Transaction_Set_candidate_share"
},
282
{
Category::LdTxnGet
,
"ledger_data_Transaction_Node_get"
},
283
{
Category::LdTxnShare
,
"ledger_data_Transaction_Node_share"
},
284
{
Category::LdAsnGet
,
"ledger_data_Account_State_Node_get"
},
285
{
Category::LdAsnShare
,
"ledger_data_Account_State_Node_share"
},
286
{
Category::LdGet
,
"ledger_data_get"
},
287
{
Category::LdShare
,
"ledger_data_share"
},
288
{
Category::GlTscShare
,
"ledger_Transaction_Set_candidate_share"
},
289
{
Category::GlTscGet
,
"ledger_Transaction_Set_candidate_get"
},
290
{
Category::GlTxnShare
,
"ledger_Transaction_node_share"
},
291
{
Category::GlTxnGet
,
"ledger_Transaction_node_get"
},
292
{
Category::GlAsnShare
,
"ledger_Account_State_node_share"
},
293
{
Category::GlAsnGet
,
"ledger_Account_State_node_get"
},
294
{
Category::GlShare
,
"ledger_share"
},
295
{
Category::GlGet
,
"ledger_get"
},
296
{
Category::ShareHashLedger
,
"getobject_Ledger_share"
},
297
{
Category::GetHashLedger
,
"getobject_Ledger_get"
},
298
{
Category::ShareHashTx
,
"getobject_Transaction_share"
},
299
{
Category::GetHashTx
,
"getobject_Transaction_get"
},
300
{
Category::ShareHashTxnode
,
"getobject_Transaction_node_share"
},
301
{
Category::GetHashTxnode
,
"getobject_Transaction_node_get"
},
302
{
Category::ShareHashAsnode
,
"getobject_Account_State_node_share"
},
303
{
Category::GetHashAsnode
,
"getobject_Account_State_node_get"
},
304
{
Category::ShareCasObject
,
"getobject_CAS_share"
},
305
{
Category::GetCasObject
,
"getobject_CAS_get"
},
306
{
Category::ShareFetchPack
,
"getobject_Fetch_Pack_share"
},
307
{
Category::GetFetchPack
,
"getobject_Fetch Pack_get"
},
308
{
Category::GetTransactions
,
"getobject_Transactions_get"
},
309
{
Category::ShareHash
,
"getobject_share"
},
310
{
Category::GetHash
,
"getobject_get"
},
311
{
Category::ProofPathRequest
,
"proof_path_request"
},
312
{
Category::ProofPathResponse
,
"proof_path_response"
},
313
{
Category::ReplayDeltaRequest
,
"replay_delta_request"
},
314
{
Category::ReplayDeltaResponse
,
"replay_delta_response"
},
315
{
Category::HaveTransactions
,
"have_transactions"
},
316
{
Category::RequestedTransactions
,
"requested_transactions"
},
317
{
Category::Total
,
"total"
}};
318
319
if
(
auto
it = kCategoryMap.
find
(cat); it != kCategoryMap.
end
())
320
return
it->second;
321
322
return
"unknown"
;
323
}
324
325
protected
:
326
std::unordered_map<Category, TrafficStats>
counts_
{
327
{
Category::Base
, {
Category::Base
}},
328
{
Category::Cluster
, {
Category::Cluster
}},
329
{
Category::Overlay
, {
Category::Overlay
}},
330
{
Category::Manifests
, {
Category::Manifests
}},
331
{
Category::Transaction
, {
Category::Transaction
}},
332
{
Category::TransactionDuplicate
, {
Category::TransactionDuplicate
}},
333
{
Category::Proposal
, {
Category::Proposal
}},
334
{
Category::ProposalUntrusted
, {
Category::ProposalUntrusted
}},
335
{
Category::ProposalDuplicate
, {
Category::ProposalDuplicate
}},
336
{
Category::Validation
, {
Category::Validation
}},
337
{
Category::ValidationUntrusted
, {
Category::ValidationUntrusted
}},
338
{
Category::ValidationDuplicate
, {
Category::ValidationDuplicate
}},
339
{
Category::Validatorlist
, {
Category::Validatorlist
}},
340
{
Category::Squelch
, {
Category::Squelch
}},
341
{
Category::SquelchSuppressed
, {
Category::SquelchSuppressed
}},
342
{
Category::SquelchIgnored
, {
Category::SquelchIgnored
}},
343
{
Category::GetSet
, {
Category::GetSet
}},
344
{
Category::ShareSet
, {
Category::ShareSet
}},
345
{
Category::LdTscGet
, {
Category::LdTscGet
}},
346
{
Category::LdTscShare
, {
Category::LdTscShare
}},
347
{
Category::LdTxnGet
, {
Category::LdTxnGet
}},
348
{
Category::LdTxnShare
, {
Category::LdTxnShare
}},
349
{
Category::LdAsnGet
, {
Category::LdAsnGet
}},
350
{
Category::LdAsnShare
, {
Category::LdAsnShare
}},
351
{
Category::LdGet
, {
Category::LdGet
}},
352
{
Category::LdShare
, {
Category::LdShare
}},
353
{
Category::GlTscShare
, {
Category::GlTscShare
}},
354
{
Category::GlTscGet
, {
Category::GlTscGet
}},
355
{
Category::GlTxnShare
, {
Category::GlTxnShare
}},
356
{
Category::GlTxnGet
, {
Category::GlTxnGet
}},
357
{
Category::GlAsnShare
, {
Category::GlAsnShare
}},
358
{
Category::GlAsnGet
, {
Category::GlAsnGet
}},
359
{
Category::GlShare
, {
Category::GlShare
}},
360
{
Category::GlGet
, {
Category::GlGet
}},
361
{
Category::ShareHashLedger
, {
Category::ShareHashLedger
}},
362
{
Category::GetHashLedger
, {
Category::GetHashLedger
}},
363
{
Category::ShareHashTx
, {
Category::ShareHashTx
}},
364
{
Category::GetHashTx
, {
Category::GetHashTx
}},
365
{
Category::ShareHashTxnode
, {
Category::ShareHashTxnode
}},
366
{
Category::GetHashTxnode
, {
Category::GetHashTxnode
}},
367
{
Category::ShareHashAsnode
, {
Category::ShareHashAsnode
}},
368
{
Category::GetHashAsnode
, {
Category::GetHashAsnode
}},
369
{
Category::ShareCasObject
, {
Category::ShareCasObject
}},
370
{
Category::GetCasObject
, {
Category::GetCasObject
}},
371
{
Category::ShareFetchPack
, {
Category::ShareFetchPack
}},
372
{
Category::GetFetchPack
, {
Category::GetFetchPack
}},
373
{
Category::GetTransactions
, {
Category::GetTransactions
}},
374
{
Category::ShareHash
, {
Category::ShareHash
}},
375
{
Category::GetHash
, {
Category::GetHash
}},
376
{
Category::ProofPathRequest
, {
Category::ProofPathRequest
}},
377
{
Category::ProofPathResponse
, {
Category::ProofPathResponse
}},
378
{
Category::ReplayDeltaRequest
, {
Category::ReplayDeltaRequest
}},
379
{
Category::ReplayDeltaResponse
, {
Category::ReplayDeltaResponse
}},
380
{
Category::HaveTransactions
, {
Category::HaveTransactions
}},
381
{
Category::RequestedTransactions
, {
Category::RequestedTransactions
}},
382
{
Category::Total
, {
Category::Total
}},
383
{
Category::Unknown
, {
Category::Unknown
}},
384
};
385
};
386
387
}
// namespace xrpl
atomic
std::string
xrpl::Cluster
Definition
Cluster.h:22
xrpl::Overlay
Manages the set of connected peers.
Definition
Overlay.h:38
xrpl::TrafficCount::TrafficStats::bytesIn
std::atomic< std::uint64_t > bytesIn
Definition
TrafficCount.h:45
xrpl::TrafficCount::TrafficStats::TrafficStats
TrafficStats(TrafficStats const &ts)
Definition
TrafficCount.h:54
xrpl::TrafficCount::TrafficStats::messagesIn
std::atomic< std::uint64_t > messagesIn
Definition
TrafficCount.h:47
xrpl::TrafficCount::TrafficStats::messagesOut
std::atomic< std::uint64_t > messagesOut
Definition
TrafficCount.h:48
xrpl::TrafficCount::TrafficStats::name
std::string name
Definition
TrafficCount.h:43
xrpl::TrafficCount::TrafficStats::bytesOut
std::atomic< std::uint64_t > bytesOut
Definition
TrafficCount.h:46
xrpl::TrafficCount::TrafficStats::TrafficStats
TrafficStats(TrafficCount::Category cat)
Definition
TrafficCount.h:50
xrpl::TrafficCount::TrafficCount
TrafficCount()=default
xrpl::TrafficCount::IsFromCluster
IsFromCluster
Whether a message's sender is a configured cluster member.
Definition
TrafficCount.h:201
xrpl::TrafficCount::IsFromCluster::Yes
@ Yes
Definition
TrafficCount.h:201
xrpl::TrafficCount::IsFromCluster::No
@ No
Definition
TrafficCount.h:201
xrpl::TrafficCount::attribute
static Category attribute(Category cat, IsFromCluster isFromCluster)
Limits a category to what the sender can report.
Definition
TrafficCount.cpp:139
xrpl::TrafficCount::categorize
static Category categorize(::google::protobuf::Message const &message, protocol::MessageType type, bool inbound)
Given a protocol message, determine which traffic category it belongs to.
Definition
TrafficCount.cpp:31
xrpl::TrafficCount::getCounts
auto const & getCounts() const
An up-to-date copy of all the counters.
Definition
TrafficCount.h:253
xrpl::TrafficCount::counts_
std::unordered_map< Category, TrafficStats > counts_
Definition
TrafficCount.h:326
xrpl::TrafficCount::addCount
void addCount(Category cat, bool inbound, int bytes)
Account for traffic associated with the given category.
Definition
TrafficCount.h:224
xrpl::TrafficCount::Category
Category
Definition
TrafficCount.h:72
xrpl::TrafficCount::Category::GetFetchPack
@ GetFetchPack
Definition
TrafficCount.h:158
xrpl::TrafficCount::Category::LdTxnGet
@ LdTxnGet
Definition
TrafficCount.h:109
xrpl::TrafficCount::Category::GlGet
@ GlGet
Definition
TrafficCount.h:134
xrpl::TrafficCount::Category::ValidationDuplicate
@ ValidationDuplicate
Definition
TrafficCount.h:91
xrpl::TrafficCount::Category::GetHashLedger
@ GetHashLedger
Definition
TrafficCount.h:138
xrpl::TrafficCount::Category::Base
@ Base
Definition
TrafficCount.h:73
xrpl::TrafficCount::Category::ShareHashAsnode
@ ShareHashAsnode
Definition
TrafficCount.h:149
xrpl::TrafficCount::Category::Validation
@ Validation
Definition
TrafficCount.h:88
xrpl::TrafficCount::Category::Transaction
@ Transaction
Definition
TrafficCount.h:79
xrpl::TrafficCount::Category::GlShare
@ GlShare
Definition
TrafficCount.h:133
xrpl::TrafficCount::Category::Cluster
@ Cluster
Definition
TrafficCount.h:75
xrpl::TrafficCount::Category::ShareHash
@ ShareHash
Definition
TrafficCount.h:164
xrpl::TrafficCount::Category::ReplayDeltaResponse
@ ReplayDeltaResponse
Definition
TrafficCount.h:173
xrpl::TrafficCount::Category::LdGet
@ LdGet
Definition
TrafficCount.h:117
xrpl::TrafficCount::Category::GlTxnShare
@ GlTxnShare
Definition
TrafficCount.h:125
xrpl::TrafficCount::Category::RequestedTransactions
@ RequestedTransactions
Definition
TrafficCount.h:179
xrpl::TrafficCount::Category::GetHashTx
@ GetHashTx
Definition
TrafficCount.h:142
xrpl::TrafficCount::Category::ShareHashLedger
@ ShareHashLedger
Definition
TrafficCount.h:137
xrpl::TrafficCount::Category::LdAsnGet
@ LdAsnGet
Definition
TrafficCount.h:113
xrpl::TrafficCount::Category::ProposalDuplicate
@ ProposalDuplicate
Definition
TrafficCount.h:86
xrpl::TrafficCount::Category::GlAsnGet
@ GlAsnGet
Definition
TrafficCount.h:130
xrpl::TrafficCount::Category::ShareHashTxnode
@ ShareHashTxnode
Definition
TrafficCount.h:145
xrpl::TrafficCount::Category::GetSet
@ GetSet
Definition
TrafficCount.h:101
xrpl::TrafficCount::Category::LdTxnShare
@ LdTxnShare
Definition
TrafficCount.h:110
xrpl::TrafficCount::Category::Squelch
@ Squelch
Definition
TrafficCount.h:95
xrpl::TrafficCount::Category::Overlay
@ Overlay
Definition
TrafficCount.h:76
xrpl::TrafficCount::Category::Validatorlist
@ Validatorlist
Definition
TrafficCount.h:93
xrpl::TrafficCount::Category::GetHashAsnode
@ GetHashAsnode
Definition
TrafficCount.h:150
xrpl::TrafficCount::Category::GlAsnShare
@ GlAsnShare
Definition
TrafficCount.h:129
xrpl::TrafficCount::Category::GetTransactions
@ GetTransactions
Definition
TrafficCount.h:161
xrpl::TrafficCount::Category::GlTscShare
@ GlTscShare
Definition
TrafficCount.h:121
xrpl::TrafficCount::Category::Unknown
@ Unknown
Definition
TrafficCount.h:184
xrpl::TrafficCount::Category::SquelchSuppressed
@ SquelchSuppressed
Definition
TrafficCount.h:96
xrpl::TrafficCount::Category::ProofPathResponse
@ ProofPathResponse
Definition
TrafficCount.h:169
xrpl::TrafficCount::Category::ShareSet
@ ShareSet
Definition
TrafficCount.h:102
xrpl::TrafficCount::Category::Manifests
@ Manifests
Definition
TrafficCount.h:77
xrpl::TrafficCount::Category::ProofPathRequest
@ ProofPathRequest
Definition
TrafficCount.h:168
xrpl::TrafficCount::Category::GetCasObject
@ GetCasObject
Definition
TrafficCount.h:154
xrpl::TrafficCount::Category::Total
@ Total
Definition
TrafficCount.h:182
xrpl::TrafficCount::Category::GlTxnGet
@ GlTxnGet
Definition
TrafficCount.h:126
xrpl::TrafficCount::Category::ShareFetchPack
@ ShareFetchPack
Definition
TrafficCount.h:157
xrpl::TrafficCount::Category::ValidationUntrusted
@ ValidationUntrusted
Definition
TrafficCount.h:90
xrpl::TrafficCount::Category::LdTscGet
@ LdTscGet
Definition
TrafficCount.h:105
xrpl::TrafficCount::Category::ProposalUntrusted
@ ProposalUntrusted
Definition
TrafficCount.h:85
xrpl::TrafficCount::Category::ReplayDeltaRequest
@ ReplayDeltaRequest
Definition
TrafficCount.h:172
xrpl::TrafficCount::Category::ShareCasObject
@ ShareCasObject
Definition
TrafficCount.h:153
xrpl::TrafficCount::Category::ShareHashTx
@ ShareHashTx
Definition
TrafficCount.h:141
xrpl::TrafficCount::Category::LdAsnShare
@ LdAsnShare
Definition
TrafficCount.h:114
xrpl::TrafficCount::Category::SquelchIgnored
@ SquelchIgnored
Definition
TrafficCount.h:97
xrpl::TrafficCount::Category::Proposal
@ Proposal
Definition
TrafficCount.h:83
xrpl::TrafficCount::Category::GetHash
@ GetHash
Definition
TrafficCount.h:165
xrpl::TrafficCount::Category::LdShare
@ LdShare
Definition
TrafficCount.h:118
xrpl::TrafficCount::Category::HaveTransactions
@ HaveTransactions
Definition
TrafficCount.h:176
xrpl::TrafficCount::Category::GetHashTxnode
@ GetHashTxnode
Definition
TrafficCount.h:146
xrpl::TrafficCount::Category::LdTscShare
@ LdTscShare
Definition
TrafficCount.h:106
xrpl::TrafficCount::Category::GlTscGet
@ GlTscGet
Definition
TrafficCount.h:122
xrpl::TrafficCount::Category::TransactionDuplicate
@ TransactionDuplicate
Definition
TrafficCount.h:81
xrpl::TrafficCount::toString
static std::string toString(Category cat)
Definition
TrafficCount.h:259
xrpl::Transaction
Definition
Transaction.h:55
cstddef
cstdint
std::unordered_map::end
T end(T... args)
std::unordered_map::find
T find(T... args)
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
std::size_t
string
unordered_map
Generated by
1.17.0