diff --git a/NetTunnel.Library/Constants.cs b/NetTunnel.Library/Constants.cs index 106cb03..dd2cfcb 100644 --- a/NetTunnel.Library/Constants.cs +++ b/NetTunnel.Library/Constants.cs @@ -1,10 +1,34 @@ -namespace NetTunnel.Library +using NetTunnel.Library.Payloads; + +namespace NetTunnel.Library { public static class Constants { public const string FriendlyName = "NetTunnel"; public const string EventSourceName = "NetTunnel"; + public enum NtHTTPHeaderResult + { + WaitOnData, + Present, + NotPresent + } + + public enum NtEdgeStatus + { + Normal, //This is a persistent connection. + New, //This is a new connection. + Expire //The connection is gone. + } + + public class NtEdgeState + { + public NtEdgeStatus Status { get; set; } + public DirectionalKey TunnelKey { get; set; } = new(); + public DirectionalKey EndpointKey { get; set; } = new(); + public Guid EdgeId { get; set; } + } + public enum NtTrafficType { Raw, diff --git a/NetTunnel.Library/ReliablePayloads/Query/UIOrService/UOSQueryRequestKeyExchange.cs b/NetTunnel.Library/ReliablePayloads/Query/UIOrService/UOSQueryRequestKeyExchange.cs index 89b4c15..e3a46ac 100644 --- a/NetTunnel.Library/ReliablePayloads/Query/UIOrService/UOSQueryRequestKeyExchange.cs +++ b/NetTunnel.Library/ReliablePayloads/Query/UIOrService/UOSQueryRequestKeyExchange.cs @@ -8,7 +8,7 @@ public class UOSQueryRequestKeyExchange : IRmQuery(); } public UOSQueryRequestKeyExchange(byte[] negotiationToken) @@ -24,7 +24,7 @@ public class UOSQueryReplyKeyExchangeReply : IRmQueryReply public UOSQueryReplyKeyExchangeReply() { - NegotiationToken = new byte[0]; + NegotiationToken = Array.Empty(); } public UOSQueryReplyKeyExchangeReply(Guid connectionId, byte[] negotiationToken) diff --git a/NetTunnel.Library/ServiceClient.cs b/NetTunnel.Library/ServiceClient.cs index 9924319..0d99dac 100644 --- a/NetTunnel.Library/ServiceClient.cs +++ b/NetTunnel.Library/ServiceClient.cs @@ -19,31 +19,27 @@ namespace NetTunnel.Library /// public class ServiceClient { + private readonly ILogger _logger; + private readonly int _port; private readonly ServiceConfiguration _configuration; private readonly string _address; - private readonly int _port; - private readonly string _userName; private readonly string _passwordHash; + private readonly string _userName; - public NtUserRole Role { get; private set; } = NtUserRole.Undefined; - - public string Address { get { return _address; } } + public bool IsLoggedIn { get; private set; } = false; + public delegate void ConnectedEvent(RmContext context); + public delegate void DisconnectedEvent(RmContext context); + public delegate void ExceptionEvent(RmContext? context, Exception ex, IRmPayload? payload); + public event ConnectedEvent? OnConnected; + public event DisconnectedEvent? OnDisconnected; + public event ExceptionEvent? OnException; /// /// The id of the service that we are logged into. /// public Guid ServiceId { get; private set; } + public NtUserRole Role { get; private set; } = NtUserRole.Undefined; public RmClient Client { get; private set; } - public bool IsLoggedIn { get; private set; } = false; - public ILogger _logger; - - public event ExceptionEvent? OnException; - public delegate void ExceptionEvent(RmContext? context, Exception ex, IRmPayload? payload); - - public event ConnectedEvent? OnConnected; - public delegate void ConnectedEvent(RmContext context); - - public event DisconnectedEvent? OnDisconnected; - public delegate void DisconnectedEvent(RmContext context); + public string Address { get { return _address; } } public ServiceClient(ILogger logger, ServiceConfiguration configuration, RmClient client, string address, int port, string userName, string passwordHash) { diff --git a/NetTunnel.Service/ReliableHandlers/Service/Notifications/ServiceNotificationHandlers.cs b/NetTunnel.Service/ReliableHandlers/Service/Notifications/ServiceNotificationHandlers.cs index 875b845..a095943 100644 --- a/NetTunnel.Service/ReliableHandlers/Service/Notifications/ServiceNotificationHandlers.cs +++ b/NetTunnel.Service/ReliableHandlers/Service/Notifications/ServiceNotificationHandlers.cs @@ -18,8 +18,6 @@ internal class ServiceNotificationHandlers : ServiceHandlerBase, IRmMessageHandl /// The remote service is letting us know that they are about to start using the cryptography provider, /// so we need to apply the one that we have ready on this end. /// - /// - /// public void OnNotify(RmContext context, UOSNotificationApplyCryptography notification) { try @@ -57,8 +55,6 @@ public void OnNotify(RmContext context, S2SNotificationEndpointConnect notificat /// The remote service is letting us know that edge data has been received on an endpoint and is giving /// it to the local service to that it can be delivered to the associated endpoint edge connection. /// - /// - /// public void OnNotify(RmContext context, S2SNotificationEndpointDataExchange notification) { try @@ -78,8 +74,6 @@ public void OnNotify(RmContext context, S2SNotificationEndpointDataExchange noti /// /// The remote service is letting us know that it is deleting the given tunnel. /// - /// - /// public void OnNotify(RmContext context, S2SNotificationTunnelDeletion notification) { try @@ -98,8 +92,6 @@ public void OnNotify(RmContext context, S2SNotificationTunnelDeletion notificati /// /// The remote service is letting us know that it is deleting the given endpoint. /// - /// - /// public void OnNotify(RmContext context, S2SNotificationEndpointDeletion notification) { try @@ -118,8 +110,6 @@ public void OnNotify(RmContext context, S2SNotificationEndpointDeletion notifica /// /// The remote service is letting us know that an edge connection has been terminated to the given endpoint. /// - /// - /// public void OnNotify(RmContext context, S2SNotificationEndpointDisconnect notification) { try @@ -138,8 +128,6 @@ public void OnNotify(RmContext context, S2SNotificationEndpointDisconnect notifi /// /// The UI is requesting that the local service disconnect the given endpoint edge connection. /// - /// - /// public void OnNotify(RmContext context, UINotifyTerminateEndpointEdgeConnection notification) { try diff --git a/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForServiceToService.cs b/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForServiceToService.cs index e01a91d..a0b0652 100644 --- a/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForServiceToService.cs +++ b/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForServiceToService.cs @@ -17,9 +17,6 @@ internal class ServiceQueryHandlersForServiceToService : ServiceHandlerBase, IRm /// /// The remote service is requesting that this service respond to a ping request. /// - /// - /// - /// public S2SQueryPingReply OnQuery(RmContext context, S2SQueryPing query) { try @@ -44,9 +41,6 @@ public S2SQueryPingReply OnQuery(RmContext context, S2SQueryPing query) /// The remote outbound service is asking this service to register the given tunnel. /// The service will connect the tunnel and send back the endpoints for the logged in user. /// - /// - /// - /// public S2SQueryRegisterTunnelReply OnQuery(RmContext context, S2SQueryRegisterTunnel query) { try @@ -94,9 +88,6 @@ public S2SQueryRegisterTunnelReply OnQuery(RmContext context, S2SQueryRegisterTu /// /// A new endpoint has been added to the remote service, so that remote service is asking this service to add the endpoint locally too. /// - /// - /// - /// public S2SQueryUpsertEndpointReply OnQuery(RmContext context, S2SQueryUpsertEndpoint query) { try diff --git a/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForServiceToServiceOrUI.cs b/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForServiceToServiceOrUI.cs index 89bcefb..d28ade4 100644 --- a/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForServiceToServiceOrUI.cs +++ b/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForServiceToServiceOrUI.cs @@ -21,9 +21,6 @@ internal class ServiceQueryHandlersForServiceToServiceOrUI : ServiceHandlerBase, /// sends the NotificationApplyCryptography notification. This is because if we apply the cryptography now, then /// the reply will be encrypted before the remote service has the data it needs to decrypt it. /// - /// - /// - /// public UOSQueryReplyKeyExchangeReply OnQuery(RmContext context, UOSQueryRequestKeyExchange query) { try @@ -48,9 +45,6 @@ public UOSQueryReplyKeyExchangeReply OnQuery(RmContext context, UOSQueryRequestK /// /// A UI client or remote service is requesting to login. /// - /// - /// - /// public UOSQueryLoginReply OnQuery(RmContext context, UOSQueryLogin query) { try diff --git a/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForUI.cs b/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForUI.cs index 95a20db..407b9d4 100644 --- a/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForUI.cs +++ b/NetTunnel.Service/ReliableHandlers/Service/Queries/ServiceQueryHandlersForUI.cs @@ -17,9 +17,6 @@ internal class ServiceQueryHandlersForUI : ServiceHandlerBase, IRmMessageHandler /// /// A UI client is requesting a list of tunnels. /// - /// - /// - /// public UIQueryGetTunnelsReply UIQueryGetTunnels(RmContext context, UIQueryGetTunnels query) { try @@ -40,9 +37,6 @@ public UIQueryGetTunnelsReply UIQueryGetTunnels(RmContext context, UIQueryGetTun /// /// A user is asking the service to create a tunnel with the given configuration. /// - /// - /// - /// public UIQueryCreateTunnelReply UIQueryCreateTunnel(RmContext context, UIQueryCreateTunnel query) { try @@ -70,9 +64,6 @@ public UIQueryCreateTunnelReply UIQueryCreateTunnel(RmContext context, UIQueryCr /// A user is asking that a new endpoint be added to the local tunnel and also sent through the connected tunnel /// to the other service on the other end so that it can also add associated endpoint to its tunnel. /// - /// - /// - /// public UIQueryDistributeUpsertEndpointReply UIQueryDistributeUpsertEndpoint(RmContext context, UIQueryDistributeUpsertEndpoint query) { try @@ -99,9 +90,6 @@ public UIQueryDistributeUpsertEndpointReply UIQueryDistributeUpsertEndpoint(RmCo /// /// A user is asking the service to upsert an endpoint associated with a user. /// - /// - /// - /// public UIQueryUpsertUserEndpointReply UIQueryUpsertUserEndpoint(RmContext context, UIQueryUpsertUserEndpoint query) { try @@ -128,9 +116,6 @@ public UIQueryUpsertUserEndpointReply UIQueryUpsertUserEndpoint(RmContext contex /// /// The UI is requesting general tunnel statistics. /// - /// - /// - /// public UIQueryGetTunnelStatisticsReply UIQueryGetTunnelStatistics(RmContext context, UIQueryGetTunnelStatistics query) { try @@ -154,9 +139,6 @@ public UIQueryGetTunnelStatisticsReply UIQueryGetTunnelStatistics(RmContext cont /// /// The UI is requesting that a tunnel be disconnected, but not deleted from the associated remote service. /// - /// - /// - /// public UIQueryDisconnectTunnelReply UIQueryDisconnectTunnel(RmContext context, UIQueryDisconnectTunnel query) { try @@ -180,9 +162,6 @@ public UIQueryDisconnectTunnelReply UIQueryDisconnectTunnel(RmContext context, U /// /// The UI is requesting that a tunnel be deleted. /// - /// - /// - /// public UIQueryDeleteTunnelReply UIQueryDeleteTunnel(RmContext context, UIQueryDeleteTunnel query) { try @@ -210,9 +189,6 @@ public UIQueryDeleteTunnelReply UIQueryDeleteTunnel(RmContext context, UIQueryDe /// /// The UI is requesting a list of all users. /// - /// - /// - /// public UIQueryGetUsersReply UIQueryGetUsers(RmContext context, UIQueryGetUsers query) { try @@ -240,9 +216,6 @@ public UIQueryGetUsersReply UIQueryGetUsers(RmContext context, UIQueryGetUsers q /// /// The UI is requesting to delete a given user. /// - /// - /// - /// public UIQueryDeleteUserReply UIQueryDeleteUser(RmContext context, UIQueryDeleteUser query) { try @@ -269,9 +242,6 @@ public UIQueryDeleteUserReply UIQueryDeleteUser(RmContext context, UIQueryDelete /// /// The UI is requesting that a user be altered with the given information (password, role, etc.) /// - /// - /// - /// public UIQueryEditUserReply UIQueryEditUser(RmContext context, UIQueryEditUser query) { Singletons.Logger.Verbose(NTDLS.Helpers.Text.SeperateCamelCase(MethodBase.GetCurrentMethod()?.Name ?? string.Empty)); @@ -298,9 +268,6 @@ public UIQueryEditUserReply UIQueryEditUser(RmContext context, UIQueryEditUser q /// /// The UI is requesting that a user be created with the given information. /// - /// - /// - /// public UIQueryCreateUserReply UIQueryCreateUser(RmContext context, UIQueryCreateUser query) { Singletons.Logger.Verbose(NTDLS.Helpers.Text.SeperateCamelCase(MethodBase.GetCurrentMethod()?.Name ?? string.Empty)); @@ -327,9 +294,6 @@ public UIQueryCreateUserReply UIQueryCreateUser(RmContext context, UIQueryCreate /// /// The UI is requesting the local service configuration. /// - /// - /// - /// public UIQueryGetServiceConfigurationReply UIQueryGetServiceConfiguration(RmContext context, UIQueryGetServiceConfiguration query) { Singletons.Logger.Verbose(NTDLS.Helpers.Text.SeperateCamelCase(MethodBase.GetCurrentMethod()?.Name ?? string.Empty)); @@ -357,9 +321,6 @@ public UIQueryGetServiceConfigurationReply UIQueryGetServiceConfiguration(RmCont /// /// The UI is requesting that the local service configuration be changed. /// - /// - /// - /// public UIQueryPutServiceConfigurationReply UIQueryPutServiceConfiguration(RmContext context, UIQueryPutServiceConfiguration query) { Singletons.Logger.Verbose(NTDLS.Helpers.Text.SeperateCamelCase(MethodBase.GetCurrentMethod()?.Name ?? string.Empty)); @@ -387,9 +348,6 @@ public UIQueryPutServiceConfigurationReply UIQueryPutServiceConfiguration(RmCont /// The UI is requesting that an endpoint be deleted and that we let the /// remote service connected to the tunnel know so it can do the same. /// - /// - /// - /// public UIQueryDeleteEndpointReply UIQueryDeleteEndpoint(RmContext context, UIQueryDeleteEndpoint query) { Singletons.Logger.Verbose(NTDLS.Helpers.Text.SeperateCamelCase(MethodBase.GetCurrentMethod()?.Name ?? string.Empty)); @@ -416,9 +374,6 @@ public UIQueryDeleteEndpointReply UIQueryDeleteEndpoint(RmContext context, UIQue /// /// The UI is requesting that a tunnel be started. /// - /// - /// - /// public UIQueryStartTunnelReply UIQueryStartTunnel(RmContext context, UIQueryStartTunnel query) { Singletons.Logger.Verbose(NTDLS.Helpers.Text.SeperateCamelCase(MethodBase.GetCurrentMethod()?.Name ?? string.Empty)); @@ -440,9 +395,6 @@ public UIQueryStartTunnelReply UIQueryStartTunnel(RmContext context, UIQueryStar /// /// The UI is requesting that a tunnel be stopped. /// - /// - /// - /// public UIQueryStopTunnelReply UIQueryStopTunnel(RmContext context, UIQueryStopTunnel query) { Singletons.Logger.Verbose(NTDLS.Helpers.Text.SeperateCamelCase(MethodBase.GetCurrentMethod()?.Name ?? string.Empty)); @@ -464,9 +416,6 @@ public UIQueryStopTunnelReply UIQueryStopTunnel(RmContext context, UIQueryStopTu /// /// The UI is requesting general tunnel properties. /// - /// - /// - /// public UIQueryGetTunnelPropertiesReply UIQueryGetTunnelProperties(RmContext context, UIQueryGetTunnelProperties query) { Singletons.Logger.Debug(NTDLS.Helpers.Text.SeperateCamelCase(MethodBase.GetCurrentMethod()?.Name ?? string.Empty)); @@ -490,9 +439,6 @@ public UIQueryGetTunnelPropertiesReply UIQueryGetTunnelProperties(RmContext cont /// /// The UI is requesting general endpoint properties. /// - /// - /// - /// public UIQueryGetEndpointPropertiesReply UIQueryGetEndpointProperties(RmContext context, UIQueryGetEndpointProperties query) { Singletons.Logger.Debug(NTDLS.Helpers.Text.SeperateCamelCase(MethodBase.GetCurrentMethod()?.Name ?? string.Empty)); @@ -516,9 +462,6 @@ public UIQueryGetEndpointPropertiesReply UIQueryGetEndpointProperties(RmContext /// /// The UI is requesting a list of edge connections to a given endpoint. /// - /// - /// - /// public UIQueryGetEndpointEdgeConnectionsReply UIQueryGetEndpointEdgeConnections(RmContext context, UIQueryGetEndpointEdgeConnections query) { Singletons.Logger.Debug(NTDLS.Helpers.Text.SeperateCamelCase(MethodBase.GetCurrentMethod()?.Name ?? string.Empty)); diff --git a/NetTunnel.Service/ReliableHandlers/ServiceClient/Notifications/TunnelOutboundNotificationHandlers.cs b/NetTunnel.Service/ReliableHandlers/ServiceClient/Notifications/TunnelOutboundNotificationHandlers.cs index debb60c..4a74083 100644 --- a/NetTunnel.Service/ReliableHandlers/ServiceClient/Notifications/TunnelOutboundNotificationHandlers.cs +++ b/NetTunnel.Service/ReliableHandlers/ServiceClient/Notifications/TunnelOutboundNotificationHandlers.cs @@ -13,8 +13,6 @@ internal class TunnelOutboundNotificationHandlers : TunnelOutboundHandlersBase, ///SEARCH FOR: Process:Endpoint:Connect:004: The remote service has communicated though the tunnel that we need to /// establish an associated outbound endpoint connection. /// - /// - /// public void OnNotify(RmContext context, S2SNotificationEndpointConnect notification) { try @@ -37,8 +35,6 @@ public void OnNotify(RmContext context, S2SNotificationEndpointConnect notificat /// The remote service is letting us know that edge data has been received on an endpoint and is giving /// it to the local service to that it can be delivered to the associated endpoint edge connection. /// - /// - /// public void OnNotify(RmContext context, S2SNotificationEndpointDataExchange notification) { try @@ -57,8 +53,6 @@ public void OnNotify(RmContext context, S2SNotificationEndpointDataExchange noti /// /// The remote service is letting us know that it is deleting the given tunnel. /// - /// - /// public void OnNotify(RmContext context, S2SNotificationTunnelDeletion notification) { try @@ -77,8 +71,6 @@ public void OnNotify(RmContext context, S2SNotificationTunnelDeletion notificati /// /// The remote service is letting us know that it is deleting the given endpoint. /// - /// - /// public void OnNotify(RmContext context, S2SNotificationEndpointDeletion notification) { try @@ -97,8 +89,6 @@ public void OnNotify(RmContext context, S2SNotificationEndpointDeletion notifica /// /// The remote service is letting us know that an edge connection has been terminated to the given endpoint. /// - /// - /// public void OnNotify(RmContext context, S2SNotificationEndpointDisconnect notification) { try diff --git a/NetTunnel.Service/TunnelEngine/Endpoints/BaseEndpoint.cs b/NetTunnel.Service/TunnelEngine/Endpoints/BaseEndpoint.cs index a567001..f44467f 100644 --- a/NetTunnel.Service/TunnelEngine/Endpoints/BaseEndpoint.cs +++ b/NetTunnel.Service/TunnelEngine/Endpoints/BaseEndpoint.cs @@ -12,23 +12,20 @@ namespace NetTunnel.Service.TunnelEngine.Endpoints { internal class BaseEndpoint { - private readonly object _statisticsLock = new(); - - public ulong BytesReceived { get; internal set; } - public ulong BytesSent { get; internal set; } - public ulong TotalConnections { get; internal set; } - public ulong CurrentConnections { get; internal set; } - public Guid EndpointId { get; private set; } - - internal readonly IServiceEngine _serviceEngine; - internal readonly ITunnel _tunnel; - public bool KeepRunning { get; internal set; } = false; - private readonly Thread _heartbeatThread; + private readonly object _statisticsLock = new(); internal readonly PessimisticCriticalResource> _edgeConnections = new(); + internal readonly ITunnel _tunnel; + internal readonly IServiceEngine _serviceEngine; + public bool KeepRunning { get; internal set; } = false; public EndpointConfiguration Configuration { get; private set; } + public Guid EndpointId { get; private set; } + public ulong BytesReceived { get; internal set; } + public ulong BytesSent { get; internal set; } + public ulong CurrentConnections { get; internal set; } + public ulong TotalConnections { get; internal set; } public BaseEndpoint(IServiceEngine serviceEngine, ITunnel tunnel, Guid endpointId, EndpointConfiguration configuration) diff --git a/NetTunnel.Service/TunnelEngine/Endpoints/EndpointEdgeConnection.cs b/NetTunnel.Service/TunnelEngine/Endpoints/EndpointEdgeConnection.cs index e8f2e8e..e5fef58 100644 --- a/NetTunnel.Service/TunnelEngine/Endpoints/EndpointEdgeConnection.cs +++ b/NetTunnel.Service/TunnelEngine/Endpoints/EndpointEdgeConnection.cs @@ -6,16 +6,16 @@ namespace NetTunnel.Service.TunnelEngine.Endpoints { internal class EndpointEdgeConnection : IDisposable { - public ulong BytesReceived { get; internal set; } - public ulong BytesSent { get; internal set; } - public DateTime StartDateTime { get; private set; } = DateTime.UtcNow; + private readonly NetworkStream _stream; + + public bool IsConnected { get; private set; } public DateTime LastActivityDateTime { get; private set; } = DateTime.UtcNow; + public DateTime StartDateTime { get; private set; } = DateTime.UtcNow; public Guid EdgeId { get; private set; } public TcpClient TcpClient { get; private set; } public Thread Thread { get; private set; } - public bool IsConnected { get; private set; } - - private readonly NetworkStream _stream; + public ulong BytesReceived { get; internal set; } + public ulong BytesSent { get; internal set; } public double ActivityAgeInMilliseconds => (DateTime.UtcNow - LastActivityDateTime).TotalMilliseconds; diff --git a/NetTunnel.Service/TunnelEngine/Endpoints/EndpointInbound.cs b/NetTunnel.Service/TunnelEngine/Endpoints/EndpointInbound.cs index 7f05c2b..1c52069 100644 --- a/NetTunnel.Service/TunnelEngine/Endpoints/EndpointInbound.cs +++ b/NetTunnel.Service/TunnelEngine/Endpoints/EndpointInbound.cs @@ -12,19 +12,15 @@ namespace NetTunnel.Service.TunnelEngine.Endpoints /// internal class EndpointInbound : BaseEndpoint, IEndpoint { - private Thread? _inboundConnectionThread; - private TcpListener? _listener; - - public NtDirection Direction { get => NtDirection.Inbound; } + private Thread? _inboundConnectionThread; /// /// Unique ID that takes the direction and the ID into account. /// public DirectionalKey EndpointKey => new(this); - - public override int GetHashCode() - => Configuration.GetHashCode(); + public NtDirection Direction { get => NtDirection.Inbound; } + public override int GetHashCode() => Configuration.GetHashCode(); public EndpointInbound(IServiceEngine serviceEngine, ITunnel tunnel, EndpointConfiguration configuration) : base(serviceEngine, tunnel, configuration.EndpointId, configuration) diff --git a/NetTunnel.Service/TunnelEngine/Endpoints/EndpointOutbound.cs b/NetTunnel.Service/TunnelEngine/Endpoints/EndpointOutbound.cs index 301903c..9b60477 100644 --- a/NetTunnel.Service/TunnelEngine/Endpoints/EndpointOutbound.cs +++ b/NetTunnel.Service/TunnelEngine/Endpoints/EndpointOutbound.cs @@ -11,15 +11,12 @@ namespace NetTunnel.Service.TunnelEngine.Endpoints /// internal class EndpointOutbound : BaseEndpoint, IEndpoint { - public override int GetHashCode() - => Configuration.GetHashCode(); - - public NtDirection Direction { get => NtDirection.Outbound; } - /// /// Unique ID that takes the direction and the ID into account. /// public DirectionalKey EndpointKey => new(this); + public NtDirection Direction { get => NtDirection.Outbound; } + public override int GetHashCode() => Configuration.GetHashCode(); public EndpointOutbound(IServiceEngine serviceEngine, ITunnel tunnel, EndpointConfiguration configuration) : base(serviceEngine, tunnel, configuration.EndpointId, configuration) diff --git a/NetTunnel.Service/TunnelEngine/HttpUtility.cs b/NetTunnel.Service/TunnelEngine/HttpUtility.cs index 9cf8725..85e7089 100644 --- a/NetTunnel.Service/TunnelEngine/HttpUtility.cs +++ b/NetTunnel.Service/TunnelEngine/HttpUtility.cs @@ -9,19 +9,12 @@ namespace NetTunnel.Service { public static class HttpUtility { - public static readonly List HttpVerbStrings = new() - { - "connect","delete","get","head","options","patch","post","put","trace" - }; + public static readonly List HttpVerbStrings = + [ + "connect", "delete", "get", "head", "options", "patch", "post", "put", "trace" + ]; - public enum HTTPHeaderResult - { - WaitOnData, - Present, - NotPresent - } - - public static HTTPHeaderResult Process(ref StringBuilder httpHeaderBuilder, EndpointConfiguration endpointConfig, PumpBuffer buffer) + public static NtHTTPHeaderResult Process(ref StringBuilder httpHeaderBuilder, EndpointConfiguration endpointConfig, PumpBuffer buffer) { try { @@ -56,7 +49,7 @@ public static HTTPHeaderResult Process(ref StringBuilder httpHeaderBuilder, Endp var endOfHeaderIndex = GetHttpHeaderEnd(httpHeaderBuilder.ToString(), out headerDelimiter); if (endOfHeaderIndex < 0) { - return HTTPHeaderResult.WaitOnData; //We have a HTTP header but its a fragment. Wait on the remaining header. + return NtHTTPHeaderResult.WaitOnData; //We have a HTTP header but its a fragment. Wait on the remaining header. } else { @@ -93,7 +86,7 @@ public static HTTPHeaderResult Process(ref StringBuilder httpHeaderBuilder, Endp httpHeaderBuilder = new StringBuilder( ApplyHttpHeaderRules(endpointConfig, httpHeaderBuilder.ToString(), headerType, requestVerb, headerDelimiter)); - return HTTPHeaderResult.Present; + return NtHTTPHeaderResult.Present; } } } @@ -103,8 +96,9 @@ public static HTTPHeaderResult Process(ref StringBuilder httpHeaderBuilder, Endp Singletons.Logger.Exception(ex, "An error occurred while parsing the HTTP request header."); } - return HTTPHeaderResult.NotPresent; + return NtHTTPHeaderResult.NotPresent; } + public static int FindDelimiterIndexInByteArray(byte[] buffer, int bufferLength, string delimiter) { for (int bufIdx = 0; bufIdx <= bufferLength - delimiter.Length; bufIdx++) @@ -188,7 +182,7 @@ public static bool StartsWithHTTPVerb(byte[] bytes) public static string? GetNextHeaderToken(string str, ref int position) { - int spacePos = str.IndexOfAny(new char[] { ' ', '\n' }, position); + int spacePos = str.IndexOfAny([' ', '\n'], position); if (spacePos >= position) { string token = str.Substring(position, spacePos - position).Trim(); @@ -241,7 +235,7 @@ public static NtHttpHeaderType IsHttpHeader(string httpHeader, out string? verb) { //Not much to do... } - else if (httpHeader.StartsWith("Http/")) + else if (httpHeader.StartsWith("Http/", StringComparison.InvariantCultureIgnoreCase)) { //Is response header. verb = string.Empty; @@ -262,7 +256,7 @@ public static NtHttpHeaderType IsHttpHeader(string httpHeader, out string? verb) return NtHttpHeaderType.None; } - if (token.ToUpper().StartsWith("HTTP/")) + if (token.StartsWith("HTTP/", StringComparison.InvariantCultureIgnoreCase)) { //Is request header return NtHttpHeaderType.Request; diff --git a/NetTunnel.Service/TunnelEngine/Managers/TunnelManager.cs b/NetTunnel.Service/TunnelEngine/Managers/TunnelManager.cs index 582af60..68eb68c 100644 --- a/NetTunnel.Service/TunnelEngine/Managers/TunnelManager.cs +++ b/NetTunnel.Service/TunnelEngine/Managers/TunnelManager.cs @@ -328,7 +328,7 @@ public List CloneOutbound() { return Collection.Use((o) => { - List clones = new(); + var clones = new List(); foreach (var tunnel in o.OfType()) { clones.Add(tunnel.CloneConfiguration()); @@ -341,7 +341,7 @@ public List GetForDisplay() { return Collection.Use((o) => { - List results = new(); + var results = new List(); foreach (var tunnel in o) { results.Add(new TunnelDisplay diff --git a/NetTunnel.Service/TunnelEngine/ServiceConnectionState.cs b/NetTunnel.Service/TunnelEngine/ServiceConnectionState.cs index 98b4c4a..be66342 100644 --- a/NetTunnel.Service/TunnelEngine/ServiceConnectionState.cs +++ b/NetTunnel.Service/TunnelEngine/ServiceConnectionState.cs @@ -7,23 +7,22 @@ namespace NetTunnel.Service.TunnelEngine { public class ServiceConnectionState { - public Guid ConnectionId { get; set; } - public CryptoStream? StreamCryptography { get; private set; } - public bool IsKeyExchangeComplete { get; private set; } public bool IsAuthenticated { get; private set; } - public string UserName { get; private set; } = string.Empty; - public NtUserRole UserRole { get; set; } = NtUserRole.Undefined; - public NtLoginType LoginType { get; set; } = NtLoginType.Undefined; - public string ClientIpAddress { get; private set; } + public bool IsKeyExchangeComplete { get; private set; } + public CryptoStream? StreamCryptography { get; private set; } public DateTime LoginTime { get; private set; } = DateTime.UtcNow; - public string KeyHash { get; private set; } = string.Empty; - public int KeyLength { get; private set; } - /// /// If the Service Connection is associated with a tunnel connection, this will be set at tunnel registration. /// Remember that the UI also makes connections to the ServiceEngine, and those connections do not use a tunnel. /// public DirectionalKey? TunnelKey { get; set; } + public Guid ConnectionId { get; set; } + public int KeyLength { get; private set; } + public NtLoginType LoginType { get; set; } = NtLoginType.Undefined; + public NtUserRole UserRole { get; set; } = NtUserRole.Undefined; + public string ClientIpAddress { get; private set; } + public string KeyHash { get; private set; } = string.Empty; + public string UserName { get; private set; } = string.Empty; public ServiceConnectionState(Guid connectionId, string clientIpAddress) { diff --git a/NetTunnel.Service/TunnelEngine/ServiceEngine.cs b/NetTunnel.Service/TunnelEngine/ServiceEngine.cs index fd81322..fd85c93 100644 --- a/NetTunnel.Service/TunnelEngine/ServiceEngine.cs +++ b/NetTunnel.Service/TunnelEngine/ServiceEngine.cs @@ -15,6 +15,11 @@ namespace NetTunnel.Service.TunnelEngine { internal class ServiceEngine : IServiceEngine { + /// + /// The message server that accepts all inbound tunnel connections and sends/receives all messages for all tunnels. + /// + private readonly RmServer _messageServer; + /// /// Contains a list of the connections that have been made TO the local service and their connection state info. /// @@ -31,11 +36,6 @@ internal class ServiceEngine : IServiceEngine /// public UserManager Users { get; private set; } - /// - /// The message server that accepts all inbound tunnel connections and sends/receives all messages for all tunnels. - /// - private readonly RmServer _messageServer; - public ServiceEngine() { Tunnels = new(this); @@ -79,9 +79,6 @@ public ServiceEngine() }; } - - - public bool TryGetServiceConnectionState(Guid connectionId, [NotNullWhen(true)] out ServiceConnectionState? outState) { var state = ServiceConnectionStates.Use(o => @@ -95,7 +92,6 @@ public bool TryGetServiceConnectionState(Guid connectionId, [NotNullWhen(true)] return state != null; } - #region Interface: IServiceEngine public void UINotifyLog(Guid connectionId, DateTime timestamp, NtLogSeverity severity, string text) diff --git a/NetTunnel.Service/TunnelEngine/Singletons.cs b/NetTunnel.Service/TunnelEngine/Singletons.cs index 51fd7ed..23e1ab0 100644 --- a/NetTunnel.Service/TunnelEngine/Singletons.cs +++ b/NetTunnel.Service/TunnelEngine/Singletons.cs @@ -33,7 +33,7 @@ public static ILogger Logger public static void UpdateConfiguration(ServiceConfiguration configuration) { _configuration = configuration; - CommonApplicationData.SaveToDisk(Library.Constants.FriendlyName, _configuration); + CommonApplicationData.SaveToDisk(Constants.FriendlyName, _configuration); } private static ServiceConfiguration? _configuration = null; @@ -43,13 +43,13 @@ public static ServiceConfiguration Configuration { if (_configuration == null) { - _configuration = CommonApplicationData.LoadFromDisk(Library.Constants.FriendlyName); + _configuration = CommonApplicationData.LoadFromDisk(Constants.FriendlyName); if (_configuration == null) { //We didn't find a config file, create one with default values. _configuration = new ServiceConfiguration(); - CommonApplicationData.SaveToDisk(Library.Constants.FriendlyName, _configuration); + CommonApplicationData.SaveToDisk(Constants.FriendlyName, _configuration); } if (_configuration == null) diff --git a/NetTunnel.Service/TunnelEngine/TunnelBase.cs b/NetTunnel.Service/TunnelEngine/TunnelBase.cs index c276cf4..8c538bb 100644 --- a/NetTunnel.Service/TunnelEngine/TunnelBase.cs +++ b/NetTunnel.Service/TunnelEngine/TunnelBase.cs @@ -18,8 +18,8 @@ internal class TunnelBase : ITunnel public virtual NtDirection Direction { get => throw new NotImplementedException("This function should be overridden."); } public DirectionalKey TunnelKey => new(Configuration.TunnelId, Direction); - public int ChangeHash - => Configuration.TunnelId.GetHashCode() + public int ChangeHash => + Configuration.TunnelId.GetHashCode() + Configuration.Name.GetHashCode(); #region Public Properties. diff --git a/NetTunnel.Service/TunnelEngine/TunnelInbound.cs b/NetTunnel.Service/TunnelEngine/TunnelInbound.cs index 10e1191..1cf7b5d 100644 --- a/NetTunnel.Service/TunnelEngine/TunnelInbound.cs +++ b/NetTunnel.Service/TunnelEngine/TunnelInbound.cs @@ -15,9 +15,7 @@ internal class TunnelInbound : TunnelBase, ITunnel /// The ID of the RmServer connection.This is also stored in the ServiceEngine.ServiceConnectionState. /// public Guid ConnectionId { get; private set; } - public override NtDirection Direction { get => NtDirection.Inbound; } - public bool IsLoggedIn => true; //The existence of a TunnelInbound means that is is connected. /// diff --git a/NetTunnel.Service/TunnelEngine/TunnelOutbound.cs b/NetTunnel.Service/TunnelEngine/TunnelOutbound.cs index 0c19806..88b82fd 100644 --- a/NetTunnel.Service/TunnelEngine/TunnelOutbound.cs +++ b/NetTunnel.Service/TunnelEngine/TunnelOutbound.cs @@ -16,7 +16,6 @@ internal class TunnelOutbound : TunnelBase, ITunnel private Thread? _establishConnectionThread; public override NtDirection Direction { get => NtDirection.Outbound; } - public bool IsLoggedIn => _client.IsLoggedIn; public TunnelOutbound(ServiceEngine serviceEngine, TunnelConfiguration configuration) diff --git a/NetTunnel.UI/Forms/FormAbout.Designer.cs b/NetTunnel.UI/Forms/FormAbout.Designer.cs index fe2d2b0..9a1b50e 100644 --- a/NetTunnel.UI/Forms/FormAbout.Designer.cs +++ b/NetTunnel.UI/Forms/FormAbout.Designer.cs @@ -95,7 +95,7 @@ private void InitializeComponent() linkWebsite.TabIndex = 9; linkWebsite.TabStop = true; linkWebsite.Text = "www.NetworkDLS.com"; - linkWebsite.LinkClicked += linkWebsite_LinkClicked; + linkWebsite.LinkClicked += LinkWebsite_LinkClicked; // // FormAbout // diff --git a/NetTunnel.UI/Forms/FormAbout.cs b/NetTunnel.UI/Forms/FormAbout.cs index cf600e1..1b22c2a 100644 --- a/NetTunnel.UI/Forms/FormAbout.cs +++ b/NetTunnel.UI/Forms/FormAbout.cs @@ -68,7 +68,7 @@ private void AddApplication(string appPath) if (componentAssembly.Version != null && companyName?.ToLower()?.Contains("networkdls") == true) { - listViewVersions.Items.Add(new ListViewItem(new string[] { componentAssembly.Name ?? "", componentAssembly.Version.ToString() })); + listViewVersions.Items.Add(new ListViewItem([componentAssembly.Name ?? "", componentAssembly.Version.ToString()])); } } catch @@ -76,7 +76,7 @@ private void AddApplication(string appPath) } } - private void linkWebsite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + private void LinkWebsite_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { try { diff --git a/NetTunnel.UI/Forms/FormAddEditEndpoint.cs b/NetTunnel.UI/Forms/FormAddEditEndpoint.cs index b773f5a..53204b8 100644 --- a/NetTunnel.UI/Forms/FormAddEditEndpoint.cs +++ b/NetTunnel.UI/Forms/FormAddEditEndpoint.cs @@ -8,10 +8,10 @@ namespace NetTunnel.UI.Forms { public partial class FormAddEditEndpoint : Form { + private readonly EndpointConfiguration? _existingEndpoint; + private readonly NtDirection _direction = NtDirection.Undefined; private readonly ServiceClient? _client; private readonly TunnelDisplay? _tunnel; - private readonly NtDirection _direction = NtDirection.Undefined; - private readonly EndpointConfiguration? _existingEndpoint; public EndpointConfiguration Endpoint { get; private set; } = new(); diff --git a/NetTunnel.UI/Forms/FormAddEditUser.cs b/NetTunnel.UI/Forms/FormAddEditUser.cs index c735cac..643932b 100644 --- a/NetTunnel.UI/Forms/FormAddEditUser.cs +++ b/NetTunnel.UI/Forms/FormAddEditUser.cs @@ -9,9 +9,10 @@ namespace NetTunnel.UI.Forms { public partial class FormAddEditUser : Form { + private readonly bool _isCreatingNewUser; private readonly ServiceClient? _client; + public User? User { get; private set; } - private readonly bool _isCreatingNewUser; public FormAddEditUser() { diff --git a/NetTunnel.UI/Forms/FormConnectTunnel.cs b/NetTunnel.UI/Forms/FormConnectTunnel.cs index 25e6264..39a9a76 100644 --- a/NetTunnel.UI/Forms/FormConnectTunnel.cs +++ b/NetTunnel.UI/Forms/FormConnectTunnel.cs @@ -12,9 +12,9 @@ namespace NetTunnel.UI.Forms { public partial class FormConnectTunnel : Form { - private readonly ServiceClient? _client; private readonly DelegateLogger _delegateLogger = UIUtility.CreateActiveWindowMessageBoxLogger(NtLogSeverity.Exception); - private readonly Utility.ServiceLogDelegate _serviceLogDelegate; + private readonly ServiceClient? _client; + private readonly ServiceLogDelegate _serviceLogDelegate; public FormConnectTunnel(ServiceClient client, ServiceLogDelegate serviceLogDelegate) { diff --git a/NetTunnel.UI/Forms/FormEndpointEdgeConnections.cs b/NetTunnel.UI/Forms/FormEndpointEdgeConnections.cs index d9c9f1f..3db88a7 100644 --- a/NetTunnel.UI/Forms/FormEndpointEdgeConnections.cs +++ b/NetTunnel.UI/Forms/FormEndpointEdgeConnections.cs @@ -9,13 +9,13 @@ namespace NetTunnel.UI.Forms { public partial class FormEndpointEdgeConnections : Form { - private readonly ServiceClient? _client; - private readonly DirectionalKey _tunnelKey; - private readonly DirectionalKey _endpointKey; private bool _firstShown = true; private bool _inTimerTick = false; - private System.Windows.Forms.Timer? _timer; private ListViewColumnMap? _connectionsGridColumnMap; + private readonly DirectionalKey _endpointKey; + private readonly DirectionalKey _tunnelKey; + private readonly ServiceClient? _client; + private System.Windows.Forms.Timer? _timer; public FormEndpointEdgeConnections() { @@ -171,7 +171,7 @@ private void ListViewConnections_MouseUp(object? sender, MouseEventArgs e) { try { - if (selectedItem.Tag is EdgeState tag) + if (selectedItem.Tag is NtEdgeState tag) { _client.EnsureNotNull().UINotifyTerminateEndpointEdgeConnection(tag.TunnelKey, tag.EndpointKey.Id, tag.EdgeId); } @@ -234,22 +234,6 @@ public void AutoResizeColumns() } } - - enum EdgeStatus - { - Normal, //This is a persistent connection. - New, //This is a new connection. - Expire //The connection is gone. - } - - class EdgeState - { - public EdgeStatus Status { get; set; } - public DirectionalKey TunnelKey { get; set; } = new(); - public DirectionalKey EndpointKey { get; set; } = new(); - public Guid EdgeId { get; set; } - } - public void PopulateListView(List connections) { _connectionsGridColumnMap.EnsureNotNull(); @@ -262,12 +246,12 @@ public void PopulateListView(List connections) foreach (ListViewItem item in listViewConnections.Items) { - var tag = (EdgeState)item.Tag.EnsureNotNull(); + var tag = (NtEdgeState)item.Tag.EnsureNotNull(); var edgeId = Guid.Parse(_connectionsGridColumnMap.SubItem(item, "EdgeId").Text); idLookup.Add(edgeId, item.Index); - if (tag.Status == EdgeStatus.Expire) + if (tag.Status == NtEdgeStatus.Expire) { expiredItems.Add(item); } @@ -275,7 +259,7 @@ public void PopulateListView(List connections) if (connections.Any(o => o.EdgeId == edgeId) == false) { item.BackColor = Color.FromArgb(255, 200, 200); - tag.Status = EdgeStatus.Expire; + tag.Status = NtEdgeStatus.Expire; } } @@ -285,7 +269,7 @@ public void PopulateListView(List connections) { var item = listViewConnections.Items[index]; - var tag = (EdgeState)item.Tag.EnsureNotNull(); + var tag = (NtEdgeState)item.Tag.EnsureNotNull(); _connectionsGridColumnMap.SubItem(item, "AddressFamily").Text = connection.AddressFamily; _connectionsGridColumnMap.SubItem(item, "Address").Text = connection.Address; @@ -300,7 +284,7 @@ public void PopulateListView(List connections) item.BackColor = Color.Transparent; - tag.Status = EdgeStatus.Normal; + tag.Status = NtEdgeStatus.Normal; } else { @@ -317,9 +301,9 @@ public void PopulateListView(List connections) item.BackColor = Color.FromArgb(200, 255, 200); - item.Tag = new EdgeState + item.Tag = new NtEdgeState { - Status = EdgeStatus.New, + Status = NtEdgeStatus.New, EdgeId = connection.EdgeId, TunnelKey = connection.TunnelKey, EndpointKey = connection.EndpointKey diff --git a/NetTunnel.UI/Forms/FormEndpointProperties.cs b/NetTunnel.UI/Forms/FormEndpointProperties.cs index 817db15..ea5e980 100644 --- a/NetTunnel.UI/Forms/FormEndpointProperties.cs +++ b/NetTunnel.UI/Forms/FormEndpointProperties.cs @@ -8,11 +8,11 @@ namespace NetTunnel.UI.Forms { public partial class FormEndpointProperties : Form { - private readonly ServiceClient? _client; - private readonly DirectionalKey _tunnelKey; - private readonly DirectionalKey _endpointKey; private bool _firstShown = true; private bool _inTimerTick = false; + private readonly DirectionalKey _endpointKey; + private readonly DirectionalKey _tunnelKey; + private readonly ServiceClient? _client; private System.Windows.Forms.Timer? _timer; public FormEndpointProperties() diff --git a/NetTunnel.UI/Forms/FormLogin.cs b/NetTunnel.UI/Forms/FormLogin.cs index cd6dac2..0c8a79c 100644 --- a/NetTunnel.UI/Forms/FormLogin.cs +++ b/NetTunnel.UI/Forms/FormLogin.cs @@ -60,10 +60,10 @@ private void ButtonLogin_Click(object sender, EventArgs e) { try { - int port = textBoxPort.GetAndValidateNumeric(1, 65535, "A port number between [min] and [max] is required."); - string username = textBoxUsername.GetAndValidateText("A username is required."); - string passwordHash = Utility.ComputeSha256Hash(textBoxPassword.Text); - string address = textBoxAddress.GetAndValidateText("A hostname or IP address is required."); + var port = textBoxPort.GetAndValidateNumeric(1, 65535, "A port number between [min] and [max] is required."); + var username = textBoxUsername.GetAndValidateText("A username is required."); + var passwordHash = Utility.ComputeSha256Hash(textBoxPassword.Text); + var address = textBoxAddress.GetAndValidateText("A hostname or IP address is required."); var progressForm = new ProgressForm(FriendlyName, "Logging in..."); diff --git a/NetTunnel.UI/Forms/FormMain.cs b/NetTunnel.UI/Forms/FormMain.cs index c94f21e..e847b2c 100644 --- a/NetTunnel.UI/Forms/FormMain.cs +++ b/NetTunnel.UI/Forms/FormMain.cs @@ -11,29 +11,24 @@ namespace NetTunnel.UI.Forms public partial class FormMain : Form { private bool _formClosing = false; - private int _changeDetectionHash = -1; private bool _needToRepopulateTunnels = false; - private ListViewColumnMap? _tunnelsGridColumnMap; + private int _changeDetectionHash = -1; private ListViewColumnMap? _endpointsGridColumnMap; + private ListViewColumnMap? _tunnelsGridColumnMap; - private Library.ServiceClient? _client; - - private volatile int _gridPopulationScope = 0; private bool _inTimerTick = false; - private System.Windows.Forms.Timer? _timer; + private Library.ServiceClient? _client; private ListViewItemComparer? _endpointsListViewItemComparer; private ListViewItemComparer? _tunnelsListViewItemComparer; private readonly Stack _visualLogEntries = new(); - - #region Constructor / Deconstructor. + private System.Windows.Forms.Timer? _timer; + private volatile int _gridPopulationScope = 0; public FormMain() { InitializeComponent(); } - #endregion - private void FormMain_Load(object sender, EventArgs e) { Shown += (object? sender, EventArgs e) => @@ -209,8 +204,8 @@ private void ChangeConnection() Text = $"{FriendlyName} : {_client.Address}"; - configurationToolStripMenuItem.Enabled = IsAdministrator(_client); - usersToolStripMenuItem.Enabled = IsAdministrator(_client); + configurationToolStripMenuItem.Enabled = IsAdministrator(); + usersToolStripMenuItem.Enabled = IsAdministrator(); RepopulateTunnelsGrid(); return; @@ -407,6 +402,7 @@ void PopulateTunnelStatistics(List statistics) } }).Start(); } + private void ListViewTunnels_SelectedIndexChanged(object? sender, EventArgs e) { _client.EnsureNotNull(); @@ -460,13 +456,13 @@ private void ListViewEndpoints_MouseUp(object? sender, MouseEventArgs e) if (tTag.Tunnel.Direction == NtDirection.Outbound || (tTag.Tunnel.Direction == NtDirection.Inbound && tTag.Tunnel.IsLoggedIn)) { - menu.Items.Add("Add Inbound Endpoint").Enabled = IsAdministrator(_client); - menu.Items.Add("Add Outbound Endpoint").Enabled = IsAdministrator(_client); + menu.Items.Add("Add Inbound Endpoint").Enabled = IsAdministrator(); + menu.Items.Add("Add Outbound Endpoint").Enabled = IsAdministrator(); if (eTag != null) { menu.Items.Add(new ToolStripSeparator()); - menu.Items.Add("Delete Endpoint").Enabled = IsAdministrator(_client); + menu.Items.Add("Delete Endpoint").Enabled = IsAdministrator(); menu.Items.Add(new ToolStripSeparator()); menu.Items.Add("Edge Connections"); menu.Items.Add("Properties"); @@ -575,8 +571,8 @@ private void ListViewTunnels_MouseUp(object? sender, MouseEventArgs e) if (_client != null && tTag.Tunnel.IsLoggedIn) { menu.Items.Add(new ToolStripSeparator()); - menu.Items.Add("Add Inbound Endpoint").Enabled = IsAdministrator(_client); - menu.Items.Add("Add Outbound Endpoint").Enabled = IsAdministrator(_client); + menu.Items.Add("Add Inbound Endpoint").Enabled = IsAdministrator(); + menu.Items.Add("Add Outbound Endpoint").Enabled = IsAdministrator(); } if (tTag.Tunnel.Direction == NtDirection.Outbound) @@ -594,7 +590,7 @@ private void ListViewTunnels_MouseUp(object? sender, MouseEventArgs e) } menu.Items.Add(new ToolStripSeparator()); - menu.Items.Add("Delete Tunnel").Enabled = IsAdministrator(_client); + menu.Items.Add("Delete Tunnel").Enabled = IsAdministrator(); menu.Items.Add("Disconnect Tunnel").Enabled = tTag.Tunnel.Direction == NtDirection.Outbound; menu.Items.Add(new ToolStripSeparator()); menu.Items.Add("Properties"); @@ -740,7 +736,7 @@ private void ListViewTunnels_MouseUp(object? sender, MouseEventArgs e) } } - public bool IsAdministrator(Library.ServiceClient? client) + public bool IsAdministrator() { if (_client == null) { @@ -896,9 +892,13 @@ private void ListViewTunnels_ColumnClick(object? sender, ColumnClickEventArgs e) if (e.Column == _tunnelsListViewItemComparer.SortColumn) { if (_tunnelsListViewItemComparer.SortOrder == SortOrder.Ascending) + { _tunnelsListViewItemComparer.SortOrder = SortOrder.Descending; + } else + { _tunnelsListViewItemComparer.SortOrder = SortOrder.Ascending; + } } else { @@ -919,9 +919,13 @@ private void ListViewEndpoints_ColumnClick(object? sender, ColumnClickEventArgs if (e.Column == _endpointsListViewItemComparer.SortColumn) { if (_endpointsListViewItemComparer.SortOrder == SortOrder.Ascending) + { _endpointsListViewItemComparer.SortOrder = SortOrder.Descending; + } else + { _endpointsListViewItemComparer.SortOrder = SortOrder.Ascending; + } } else { diff --git a/NetTunnel.UI/Forms/FormTunnelProperties.cs b/NetTunnel.UI/Forms/FormTunnelProperties.cs index ab34242..cc04494 100644 --- a/NetTunnel.UI/Forms/FormTunnelProperties.cs +++ b/NetTunnel.UI/Forms/FormTunnelProperties.cs @@ -8,11 +8,11 @@ namespace NetTunnel.UI.Forms { public partial class FormTunnelProperties : Form { + private readonly System.Windows.Forms.Timer? _timer; private readonly ServiceClient? _client; private readonly DirectionalKey _tunnelKey; - private bool _firstShown = true; private bool _inTimerTick = false; - private System.Windows.Forms.Timer? _timer; + private bool _firstShown = true; public FormTunnelProperties() { diff --git a/NetTunnel.UI/Forms/FormUsers.cs b/NetTunnel.UI/Forms/FormUsers.cs index 93c96e4..a95ad63 100644 --- a/NetTunnel.UI/Forms/FormUsers.cs +++ b/NetTunnel.UI/Forms/FormUsers.cs @@ -8,8 +8,8 @@ namespace NetTunnel.UI.Forms { public partial class FormUsers : Form { - private readonly ServiceClient? _client; private bool _firstShown = true; + private readonly ServiceClient? _client; public FormUsers() {