-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathNwTracer.h
153 lines (128 loc) · 4.22 KB
/
NwTracer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//==============================================================================
//
// NwTracer.h
//
// Copyright (C) 2013-2025 Greg Utas
//
// This file is part of the Robust Services Core (RSC).
//
// RSC is free software: you can redistribute it and/or modify it under the
// terms of the Lesser GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// RSC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the Lesser GNU General Public License
// along with RSC. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef NWTRACER_H_INCLUDED
#define NWTRACER_H_INCLUDED
#include "Permanent.h"
#include <cstddef>
#include <iosfwd>
#include "NbTypes.h"
#include "NwTypes.h"
#include "SysIpL3Addr.h"
#include "SysTypes.h"
#include "ToolTypes.h"
//------------------------------------------------------------------------------
namespace NetworkBase
{
// Interface for tracing messages to/from specific IP peers and ports.
//
class NwTracer : public NodeBase::Permanent
{
friend class NodeBase::Singleton<NwTracer>;
public:
// Deleted to prohibit copying.
//
NwTracer(const NwTracer& that) = delete;
// Deleted to prohibit copy assignment.
//
NwTracer& operator=(const NwTracer& that) = delete;
// Traces PEER according to STATUS.
//
NodeBase::TraceRc SelectPeer
(const SysIpL3Addr& peer, NodeBase::TraceStatus status);
// Traces PORT according to STATUS.
//
NodeBase::TraceRc SelectPort(ipport_t port, NodeBase::TraceStatus status);
// Returns true if no peers are included or excluded.
//
bool PeersEmpty() const;
// Returns true if no ports are included or excluded.
//
bool PortsEmpty() const;
// Returns the trace status of PEER.
//
NodeBase::TraceStatus PeerStatus(const SysIpL3Addr& peer) const;
// Returns the trace status of PORT.
//
NodeBase::TraceStatus PortStatus(ipport_t port) const;
// Displays, in STREAM, everything that has been included or excluded.
//
void QuerySelections(std::ostream& stream) const;
// Removes everything of type FILTER that has been included or excluded.
//
NodeBase::TraceRc ClearSelections(NodeBase::FlagId filter);
// Determines whether IPB, travelling in DIR, should be traced.
//
NodeBase::TraceStatus BuffStatus
(const IpBuffer& ipb, NodeBase::MsgDirection dir) const;
// Overridden for patching.
//
void Patch(sel_t selector, void* arguments) override;
private:
// Private because this is a singleton.
//
NwTracer();
// Private because this is a singleton.
//
~NwTracer();
//> The number of peers that can be specifically included or
// excluded from a trace.
//
static const size_t MaxPeerEntries = 8;
//> The number of ports that can be specifically included or
// excluded from a trace.
//
static const size_t MaxPortEntries = 8;
// The trace status of a peer IP address.
//
struct PeerFilter
{
PeerFilter();
PeerFilter(const SysIpL3Addr& a, NodeBase::TraceStatus s);
SysIpL3Addr peer; // peer
NodeBase::TraceStatus status; // whether included or excluded
};
// The trace status of a local IP port.
//
struct PortFilter
{
PortFilter();
PortFilter(ipport_t p, NodeBase::TraceStatus s);
ipport_t port; // host port
NodeBase::TraceStatus status; // whether included or excluded
};
// If PEER is included or excluded, returns its index in peers_.
// Returns -1 if PEER is neither included nor excluded.
//
int FindPeer(const SysIpL3Addr& peer) const;
// If PORT is included or excluded, returns its index in ports_.
// Returns -1 if PORT is neither included nor excluded.
//
int FindPort(ipport_t port) const;
// A list of included or excluded peers.
//
PeerFilter peers_[MaxPeerEntries];
// A list of included or excluded ports.
//
PortFilter ports_[MaxPortEntries];
};
}
#endif