Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NetSecurityTelemetry.cs
Go to the documentation of this file.
6
7namespace System.Net.Security;
8
9[EventSource(Name = "System.Net.Security")]
10internal sealed class NetSecurityTelemetry : EventSource
11{
12 public static readonly NetSecurityTelemetry Log = new NetSecurityTelemetry();
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
48 private long _sessionsOpen;
49
50 private long _sessionsOpenTls10;
51
52 private long _sessionsOpenTls11;
53
54 private long _sessionsOpenTls12;
55
56 private long _sessionsOpenTls13;
57
58 protected override void OnEventCommand(EventCommandEventArgs command)
59 {
60 if (command.Command != EventCommand.Enable)
61 {
62 return;
63 }
64 if (_tlsHandshakeRateCounter == null)
65 {
67 {
68 DisplayName = "TLS handshakes completed",
69 DisplayRateTimeScale = TimeSpan.FromSeconds(1.0)
70 };
71 }
73 {
74 _totalTlsHandshakesCounter = new PollingCounter("total-tls-handshakes", this, () => Interlocked.Read(ref _finishedTlsHandshakes))
75 {
76 DisplayName = "Total TLS handshakes completed"
77 };
78 }
80 {
82 {
83 DisplayName = "Current TLS handshakes"
84 };
85 }
87 {
88 _failedTlsHandshakesCounter = new PollingCounter("failed-tls-handshakes", this, () => Interlocked.Read(ref _failedTlsHandshakes))
89 {
90 DisplayName = "Total TLS handshakes failed"
91 };
92 }
93 if (_sessionsOpenCounter == null)
94 {
95 _sessionsOpenCounter = new PollingCounter("all-tls-sessions-open", this, () => Interlocked.Read(ref _sessionsOpen))
96 {
97 DisplayName = "All TLS Sessions Active"
98 };
99 }
100 if (_sessionsOpenTls10Counter == null)
101 {
102 _sessionsOpenTls10Counter = new PollingCounter("tls10-sessions-open", this, () => Interlocked.Read(ref _sessionsOpenTls10))
103 {
104 DisplayName = "TLS 1.0 Sessions Active"
105 };
106 }
107 if (_sessionsOpenTls11Counter == null)
108 {
109 _sessionsOpenTls11Counter = new PollingCounter("tls11-sessions-open", this, () => Interlocked.Read(ref _sessionsOpenTls11))
110 {
111 DisplayName = "TLS 1.1 Sessions Active"
112 };
113 }
114 if (_sessionsOpenTls12Counter == null)
115 {
116 _sessionsOpenTls12Counter = new PollingCounter("tls12-sessions-open", this, () => Interlocked.Read(ref _sessionsOpenTls12))
117 {
118 DisplayName = "TLS 1.2 Sessions Active"
119 };
120 }
121 if (_sessionsOpenTls13Counter == null)
122 {
123 _sessionsOpenTls13Counter = new PollingCounter("tls13-sessions-open", this, () => Interlocked.Read(ref _sessionsOpenTls13))
124 {
125 DisplayName = "TLS 1.3 Sessions Active"
126 };
127 }
128 if (_handshakeDurationCounter == null)
129 {
130 _handshakeDurationCounter = new EventCounter("all-tls-handshake-duration", this)
131 {
132 DisplayName = "TLS Handshake Duration",
133 DisplayUnits = "ms"
134 };
135 }
137 {
138 _handshakeDurationTls10Counter = new EventCounter("tls10-handshake-duration", this)
139 {
140 DisplayName = "TLS 1.0 Handshake Duration",
141 DisplayUnits = "ms"
142 };
143 }
145 {
146 _handshakeDurationTls11Counter = new EventCounter("tls11-handshake-duration", this)
147 {
148 DisplayName = "TLS 1.1 Handshake Duration",
149 DisplayUnits = "ms"
150 };
151 }
153 {
154 _handshakeDurationTls12Counter = new EventCounter("tls12-handshake-duration", this)
155 {
156 DisplayName = "TLS 1.2 Handshake Duration",
157 DisplayUnits = "ms"
158 };
159 }
161 {
162 _handshakeDurationTls13Counter = new EventCounter("tls13-handshake-duration", this)
163 {
164 DisplayName = "TLS 1.3 Handshake Duration",
165 DisplayUnits = "ms"
166 };
167 }
168 }
169
170 [Event(1, Level = EventLevel.Informational)]
171 public void HandshakeStart(bool isServer, string targetHost)
172 {
174 if (IsEnabled(EventLevel.Informational, EventKeywords.None))
175 {
176 WriteEvent(1, isServer, targetHost);
177 }
178 }
179
180 [Event(2, Level = EventLevel.Informational)]
181 private void HandshakeStop(SslProtocols protocol)
182 {
183 if (IsEnabled(EventLevel.Informational, EventKeywords.None))
184 {
185 WriteEvent(2, protocol);
186 }
187 }
188
189 [Event(3, Level = EventLevel.Error)]
190 private void HandshakeFailed(bool isServer, double elapsedMilliseconds, string exceptionMessage)
191 {
192 WriteEvent(3, isServer, elapsedMilliseconds, exceptionMessage);
193 }
194
195 [NonEvent]
196 public void HandshakeFailed(bool isServer, ValueStopwatch stopwatch, string exceptionMessage)
197 {
200 if (IsEnabled(EventLevel.Error, EventKeywords.None))
201 {
202 HandshakeFailed(isServer, stopwatch.GetElapsedTime().TotalMilliseconds, exceptionMessage);
203 }
205 }
206
207 [NonEvent]
208 public void HandshakeCompleted(SslProtocols protocol, ValueStopwatch stopwatch, bool connectionOpen)
209 {
211 long num = 0L;
212 ref long location = ref num;
213 EventCounter eventCounter = null;
214 switch (protocol)
215 {
216 case SslProtocols.Tls:
217 location = ref _sessionsOpenTls10;
218 eventCounter = _handshakeDurationTls10Counter;
219 break;
220 case SslProtocols.Tls11:
221 location = ref _sessionsOpenTls11;
222 eventCounter = _handshakeDurationTls11Counter;
223 break;
224 case SslProtocols.Tls12:
225 location = ref _sessionsOpenTls12;
226 eventCounter = _handshakeDurationTls12Counter;
227 break;
228 case SslProtocols.Tls13:
229 location = ref _sessionsOpenTls13;
230 eventCounter = _handshakeDurationTls13Counter;
231 break;
232 }
233 if (connectionOpen)
234 {
235 Interlocked.Increment(ref location);
237 }
238 double totalMilliseconds = stopwatch.GetElapsedTime().TotalMilliseconds;
239 eventCounter?.WriteMetric(totalMilliseconds);
240 _handshakeDurationCounter.WriteMetric(totalMilliseconds);
241 HandshakeStop(protocol);
242 }
243
244 [NonEvent]
245 public void ConnectionClosed(SslProtocols protocol)
246 {
247 long num = 0L;
248 switch (protocol)
249 {
250 case SslProtocols.Tls:
252 break;
253 case SslProtocols.Tls11:
255 break;
256 case SslProtocols.Tls12:
258 break;
259 case SslProtocols.Tls13:
261 break;
262 }
264 }
265
266 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
267 [NonEvent]
268 private unsafe void WriteEvent(int eventId, bool arg1, string arg2)
269 {
270 if (IsEnabled())
271 {
272 if (arg2 == null)
273 {
274 arg2 = string.Empty;
275 }
276 fixed (char* ptr2 = arg2)
277 {
278 EventData* ptr = stackalloc EventData[2];
279 *ptr = new EventData
280 {
281 DataPointer = (IntPtr)(&arg1),
282 Size = 4
283 };
284 ptr[1] = new EventData
285 {
286 DataPointer = (IntPtr)ptr2,
287 Size = (arg2.Length + 1) * 2
288 };
289 WriteEventCore(eventId, 2, ptr);
290 }
291 }
292 }
293
294 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
295 [NonEvent]
296 private unsafe void WriteEvent(int eventId, SslProtocols arg1)
297 {
298 if (IsEnabled())
299 {
300 EventData eventData = default(EventData);
301 eventData.DataPointer = (IntPtr)(&arg1);
302 eventData.Size = 4;
303 EventData eventData2 = eventData;
304 WriteEventCore(eventId, 1, &eventData2);
305 }
306 }
307
308 [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:UnrecognizedReflectionPattern", Justification = "Parameters to this method are primitive and are trimmer safe")]
309 [NonEvent]
310 private unsafe void WriteEvent(int eventId, bool arg1, double arg2, string arg3)
311 {
312 if (IsEnabled())
313 {
314 if (arg3 == null)
315 {
316 arg3 = string.Empty;
317 }
318 fixed (char* ptr2 = arg3)
319 {
320 EventData* ptr = stackalloc EventData[3];
321 *ptr = new EventData
322 {
323 DataPointer = (IntPtr)(&arg1),
324 Size = 4
325 };
326 ptr[1] = new EventData
327 {
328 DataPointer = (IntPtr)(&arg2),
329 Size = 8
330 };
331 ptr[2] = new EventData
332 {
333 DataPointer = (IntPtr)ptr2,
334 Size = (arg3.Length + 1) * 2
335 };
336 WriteEventCore(eventId, 3, ptr);
337 }
338 }
339 }
340}
unsafe void WriteEventCore(int eventId, int eventDataCount, EventData *data)
void HandshakeFailed(bool isServer, double elapsedMilliseconds, string exceptionMessage)
unsafe void WriteEvent(int eventId, SslProtocols arg1)
IncrementingPollingCounter _tlsHandshakeRateCounter
void HandshakeCompleted(SslProtocols protocol, ValueStopwatch stopwatch, bool connectionOpen)
void HandshakeStart(bool isServer, string targetHost)
unsafe void WriteEvent(int eventId, bool arg1, string arg2)
void HandshakeFailed(bool isServer, ValueStopwatch stopwatch, string exceptionMessage)
unsafe void WriteEvent(int eventId, bool arg1, double arg2, string arg3)
override void OnEventCommand(EventCommandEventArgs command)
static readonly NetSecurityTelemetry Log
static int Decrement(ref int location)
static long Read(ref long location)
static int Increment(ref int location)
static TimeSpan FromSeconds(double value)
Definition TimeSpan.cs:247