xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
overlay
detail
TrafficCount.cpp
1
#include <xrpld/overlay/detail/TrafficCount.h>
2
3
#include <google/protobuf/message.h>
4
5
#include <xrpl.pb.h>
6
7
#include <
unordered_map
>
8
9
namespace
xrpl
{
10
11
std::unordered_map<protocol::MessageType, TrafficCount::Category>
const
kTypeLookup
= {
12
{protocol::mtPING,
TrafficCount::Category::Base
},
13
{protocol::mtSTATUS_CHANGE,
TrafficCount::Category::Base
},
14
{protocol::mtCLUSTER,
TrafficCount::Category::Cluster
},
15
{protocol::mtMANIFESTS,
TrafficCount::Category::Manifests
},
16
{protocol::mtENDPOINTS,
TrafficCount::Category::Overlay
},
17
{protocol::mtTRANSACTION,
TrafficCount::Category::Transaction
},
18
{protocol::mtVALIDATOR_LIST_COLLECTION,
TrafficCount::Category::Validatorlist
},
19
{protocol::mtVALIDATION,
TrafficCount::Category::Validation
},
20
{protocol::mtPROPOSE_LEDGER,
TrafficCount::Category::Proposal
},
21
{protocol::mtPROOF_PATH_REQ,
TrafficCount::Category::ProofPathRequest
},
22
{protocol::mtPROOF_PATH_RESPONSE,
TrafficCount::Category::ProofPathResponse
},
23
{protocol::mtREPLAY_DELTA_REQ,
TrafficCount::Category::ReplayDeltaRequest
},
24
{protocol::mtREPLAY_DELTA_RESPONSE,
TrafficCount::Category::ReplayDeltaResponse
},
25
{protocol::mtHAVE_TRANSACTIONS,
TrafficCount::Category::HaveTransactions
},
26
{protocol::mtTRANSACTIONS,
TrafficCount::Category::RequestedTransactions
},
27
{protocol::mtSQUELCH,
TrafficCount::Category::Squelch
},
28
};
29
30
TrafficCount::Category
31
TrafficCount::categorize
(
32
::google::protobuf::Message
const
& message,
33
protocol::MessageType type,
34
bool
inbound)
35
{
36
if
(
auto
item =
kTypeLookup
.find(type); item !=
kTypeLookup
.end())
37
return
item->second;
38
39
if
(type == protocol::mtHAVE_SET)
40
return
inbound ?
TrafficCount::Category::GetSet
:
TrafficCount::Category::ShareSet
;
41
42
if
(
auto
msg =
dynamic_cast<
protocol::TMLedgerData const*
>
(&message))
43
{
44
if
(msg->type() == protocol::liTS_CANDIDATE)
45
{
46
return
(inbound && !msg->has_requestcookie()) ?
TrafficCount::Category::LdTscGet
47
:
TrafficCount::Category::LdTscShare
;
48
}
49
50
if
(msg->type() == protocol::liTX_NODE)
51
{
52
return
(inbound && !msg->has_requestcookie()) ?
TrafficCount::Category::LdTxnGet
53
:
TrafficCount::Category::LdTxnShare
;
54
}
55
56
if
(msg->type() == protocol::liAS_NODE)
57
{
58
return
(inbound && !msg->has_requestcookie()) ?
TrafficCount::Category::LdAsnGet
59
:
TrafficCount::Category::LdAsnShare
;
60
}
61
62
return
(inbound && !msg->has_requestcookie()) ?
TrafficCount::Category::LdGet
63
:
TrafficCount::Category::LdShare
;
64
}
65
66
if
(
auto
msg =
dynamic_cast<
protocol::TMGetLedger const*
>
(&message))
67
{
68
if
(msg->itype() == protocol::liTS_CANDIDATE)
69
{
70
return
(inbound || msg->has_requestcookie()) ?
TrafficCount::Category::GlTscShare
71
:
TrafficCount::Category::GlTscGet
;
72
}
73
74
if
(msg->itype() == protocol::liTX_NODE)
75
{
76
return
(inbound || msg->has_requestcookie()) ?
TrafficCount::Category::GlTxnShare
77
:
TrafficCount::Category::GlTxnGet
;
78
}
79
80
if
(msg->itype() == protocol::liAS_NODE)
81
{
82
return
(inbound || msg->has_requestcookie()) ?
TrafficCount::Category::GlAsnShare
83
:
TrafficCount::Category::GlAsnGet
;
84
}
85
86
return
(inbound || msg->has_requestcookie()) ?
TrafficCount::Category::GlShare
87
:
TrafficCount::Category::GlGet
;
88
}
89
90
if
(
auto
msg =
dynamic_cast<
protocol::TMGetObjectByHash const*
>
(&message))
91
{
92
if
(msg->type() == protocol::TMGetObjectByHash::otLEDGER)
93
{
94
return
(msg->query() == inbound) ?
TrafficCount::Category::ShareHashLedger
95
:
TrafficCount::Category::GetHashLedger
;
96
}
97
98
if
(msg->type() == protocol::TMGetObjectByHash::otTRANSACTION)
99
{
100
return
(msg->query() == inbound) ?
TrafficCount::Category::ShareHashTx
101
:
TrafficCount::Category::GetHashTx
;
102
}
103
104
if
(msg->type() == protocol::TMGetObjectByHash::otTRANSACTION_NODE)
105
{
106
return
(msg->query() == inbound) ?
TrafficCount::Category::ShareHashTxnode
107
:
TrafficCount::Category::GetHashTxnode
;
108
}
109
110
if
(msg->type() == protocol::TMGetObjectByHash::otSTATE_NODE)
111
{
112
return
(msg->query() == inbound) ?
TrafficCount::Category::ShareHashAsnode
113
:
TrafficCount::Category::GetHashAsnode
;
114
}
115
116
if
(msg->type() == protocol::TMGetObjectByHash::otCAS_OBJECT)
117
{
118
return
(msg->query() == inbound) ?
TrafficCount::Category::ShareCasObject
119
:
TrafficCount::Category::GetCasObject
;
120
}
121
122
if
(msg->type() == protocol::TMGetObjectByHash::otFETCH_PACK)
123
{
124
return
(msg->query() == inbound) ?
TrafficCount::Category::ShareFetchPack
125
:
TrafficCount::Category::GetFetchPack
;
126
}
127
128
if
(msg->type() == protocol::TMGetObjectByHash::otTRANSACTIONS)
129
return
TrafficCount::Category::GetTransactions
;
130
131
return
(msg->query() == inbound) ?
TrafficCount::Category::ShareHash
132
:
TrafficCount::Category::GetHash
;
133
}
134
135
return
TrafficCount::Category::Unknown
;
136
}
137
138
TrafficCount::Category
139
TrafficCount::attribute
(
Category
cat,
IsFromCluster
isFromCluster)
140
{
141
if
(cat !=
Category::Cluster
)
142
return
cat;
143
144
return
(isFromCluster ==
IsFromCluster::Yes
) ?
Category::Cluster
:
Category::Unknown
;
145
}
146
}
// namespace xrpl
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::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::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::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::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::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::GlTxnGet
@ GlTxnGet
Definition
TrafficCount.h:126
xrpl::TrafficCount::Category::ShareFetchPack
@ ShareFetchPack
Definition
TrafficCount.h:157
xrpl::TrafficCount::Category::LdTscGet
@ LdTscGet
Definition
TrafficCount.h:105
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::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
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::kTypeLookup
std::unordered_map< protocol::MessageType, TrafficCount::Category > const kTypeLookup
Definition
TrafficCount.cpp:11
unordered_map
Generated by
1.17.0