xrpld
Loading...
Searching...
No Matches
xrpl::TrafficCount Class Reference

TrafficCount is used to count ingress and egress wire bytes and number of messages. More...

#include <TrafficCount.h>

Collaboration diagram for xrpl::TrafficCount:

Classes

class  TrafficStats

Public Types

enum class  Category : std::size_t {
  Base , Cluster , Overlay , Manifests ,
  Transaction , TransactionDuplicate , Proposal , ProposalUntrusted ,
  ProposalDuplicate , Validation , ValidationUntrusted , ValidationDuplicate ,
  Validatorlist , Squelch , SquelchSuppressed , SquelchIgnored ,
  GetSet , ShareSet , LdTscGet , LdTscShare ,
  LdTxnGet , LdTxnShare , LdAsnGet , LdAsnShare ,
  LdGet , LdShare , GlTscShare , GlTscGet ,
  GlTxnShare , GlTxnGet , GlAsnShare , GlAsnGet ,
  GlShare , GlGet , ShareHashLedger , GetHashLedger ,
  ShareHashTx , GetHashTx , ShareHashTxnode , GetHashTxnode ,
  ShareHashAsnode , GetHashAsnode , ShareCasObject , GetCasObject ,
  ShareFetchPack , GetFetchPack , GetTransactions , ShareHash ,
  GetHash , ProofPathRequest , ProofPathResponse , ReplayDeltaRequest ,
  ReplayDeltaResponse , HaveTransactions , RequestedTransactions , Total ,
  Unknown
}
enum class  IsFromCluster : bool { No = false , Yes }
 Whether a message's sender is a configured cluster member. More...

Public Member Functions

 TrafficCount ()=default
void addCount (Category cat, bool inbound, int bytes)
 Account for traffic associated with the given category.
auto const & getCounts () const
 An up-to-date copy of all the counters.

Static Public Member Functions

static Category categorize (::google::protobuf::Message const &message, protocol::MessageType type, bool inbound)
 Given a protocol message, determine which traffic category it belongs to.
static Category attribute (Category cat, IsFromCluster isFromCluster)
 Limits a category to what the sender can report.
static std::string toString (Category cat)

Protected Attributes

std::unordered_map< Category, TrafficStats > counts_

Detailed Description

TrafficCount is used to count ingress and egress wire bytes and number of messages.

The general intended usage is as follows:

  1. Determine the message category by callin TrafficCount::categorize
  2. Increment the counters for incoming or outgoing traffic by calling TrafficCount::addCount
  3. Optionally, TrafficCount::addCount can be called at any time to increment additional traffic categories, not captured by TrafficCount::categorize.

There are two special categories:

  1. category::total - this category is used to report the total traffic amount. It should be incremented once just after receiving a new message, and once just before sending a message to a peer. Messages whose category is not in TrafficCount::categorize are not included in the total.
  2. category::unknown - this category is used to report traffic for messages of unknown type.

Definition at line 35 of file TrafficCount.h.

Member Enumeration Documentation

◆ Category

Enumerator
Base 
Cluster 
Overlay 
Manifests 
Transaction 
TransactionDuplicate 
Proposal 
ProposalUntrusted 
ProposalDuplicate 
Validation 
ValidationUntrusted 
ValidationDuplicate 
Validatorlist 
Squelch 
SquelchSuppressed 
SquelchIgnored 
GetSet 
ShareSet 
LdTscGet 
LdTscShare 
LdTxnGet 
LdTxnShare 
LdAsnGet 
LdAsnShare 
LdGet 
LdShare 
GlTscShare 
GlTscGet 
GlTxnShare 
GlTxnGet 
GlAsnShare 
GlAsnGet 
GlShare 
GlGet 
ShareHashLedger 
GetHashLedger 
ShareHashTx 
GetHashTx 
ShareHashTxnode 
GetHashTxnode 
ShareHashAsnode 
GetHashAsnode 
ShareCasObject 
GetCasObject 
ShareFetchPack 
GetFetchPack 
GetTransactions 
ShareHash 
GetHash 
ProofPathRequest 
ProofPathResponse 
ReplayDeltaRequest 
ReplayDeltaResponse 
HaveTransactions 
RequestedTransactions 
Total 
Unknown 

Definition at line 72 of file TrafficCount.h.

◆ IsFromCluster

enum class xrpl::TrafficCount::IsFromCluster : bool
strong

Whether a message's sender is a configured cluster member.

Enumerator
No 
Yes 

Definition at line 201 of file TrafficCount.h.

Constructor & Destructor Documentation

◆ TrafficCount()

xrpl::TrafficCount::TrafficCount ( )
default

Member Function Documentation

◆ categorize()

TrafficCount::Category xrpl::TrafficCount::categorize ( ::google::protobuf::Message const & message,
protocol::MessageType type,
bool inbound )
static

Given a protocol message, determine which traffic category it belongs to.

Definition at line 31 of file TrafficCount.cpp.

◆ attribute()

TrafficCount::Category xrpl::TrafficCount::attribute ( Category cat,
IsFromCluster isFromCluster )
staticnodiscard

Limits a category to what the sender can report.

categorize reads the message and its type, which is all an outbound message can be judged by. Inbound, the sender is also known, and one category means more than the type it was derived from: Cluster is read as traffic between configured cluster members. Any peer can send that type, so a peer outside the cluster is held to Unknown instead, leaving the category to mean what an operator reads it to mean.

Parameters
catThe category the message's type belongs to.
isFromClusterWhether the sender is a configured cluster member.
Returns
The category to account the message under.

Definition at line 139 of file TrafficCount.cpp.

◆ addCount()

void xrpl::TrafficCount::addCount ( Category cat,
bool inbound,
int bytes )

Account for traffic associated with the given category.

Definition at line 224 of file TrafficCount.h.

◆ getCounts()

auto const & xrpl::TrafficCount::getCounts ( ) const
nodiscard

An up-to-date copy of all the counters.

Returns
an object which satisfies the requirements of Container

Definition at line 253 of file TrafficCount.h.

◆ toString()

std::string xrpl::TrafficCount::toString ( Category cat)
static

Definition at line 259 of file TrafficCount.h.

Member Data Documentation

◆ counts_

std::unordered_map<Category, TrafficStats> xrpl::TrafficCount::counts_
protected

Definition at line 326 of file TrafficCount.h.