This commit is contained in:
EonaCat authored and Jeroen Saey committed 2026-11-04 07:53:40 +01:00
1 parent 2c5b69bf2c
commit 22dee59f47
132 files changed
+19653 -7192

No files matched your search

@@ -0,0 +1,40 @@
using Grpc.Core;
using EonaCat.Connections.gRPC.Proto;
using System.Net;
namespace EonaCat.Connections.gRPC
{
public class GrpcClientConnection
{
public string Id { get; set; } = string.Empty;
public IServerStreamWriter<ConnectorMessage>? ResponseStream { get; set; }
public IPEndPoint? RemoteEndPoint { get; set; }
public SemaphoreSlim WriteLock { get; } = new(1, 1);
public CancellationTokenSource? CancellationSource { get; set; }
public DateTime ConnectedAt { get; set; }
public DateTime LastActive { get; set; }
public DateTime LastDataSent { get; set; }
public DateTime LastDataReceived { get; set; }
public DateTime LastPingSent { get; set; }
public DateTime LastPongReceived { get; set; }
public long BytesSent { get; set; }
public long BytesReceived { get; set; }
public long MessagesSent { get; set; }
public long MessagesReceived { get; set; }
public bool IsConnected => CancellationSource != null && !CancellationSource.IsCancellationRequested;
public TimeSpan ConnectedTime() => DateTime.UtcNow - ConnectedAt;
public TimeSpan IdleTime() => DateTime.UtcNow - (LastActive == default ? ConnectedAt : LastActive);
private string? _nickname;
public string Nickname
{
get => string.IsNullOrWhiteSpace(_nickname) ? Id : _nickname;
set => _nickname = string.IsNullOrWhiteSpace(value) ? Id : value;
}
public bool HasNickname => !string.IsNullOrWhiteSpace(_nickname) && _nickname != Id;
}
}