diff --git a/Meum.Client.CLI/Meum.Client.CLI.csproj b/Meum.Client.CLI/Meum.Client.CLI.csproj
index 903d585..4b9d26a 100644
--- a/Meum.Client.CLI/Meum.Client.CLI.csproj
+++ b/Meum.Client.CLI/Meum.Client.CLI.csproj
@@ -1,15 +1,14 @@
- net9.0
Exe
- 1.0.0
+ 0.0.1
+ net9.0
+ enable
+ disable
-
-
-
diff --git a/Meum.Client.CLI/Program.cs b/Meum.Client.CLI/Program.cs
index c4ede7c..cda9f4d 100644
--- a/Meum.Client.CLI/Program.cs
+++ b/Meum.Client.CLI/Program.cs
@@ -4,11 +4,11 @@ global using System.Threading;
global using System.Threading.Tasks;
global using Meum.Core;
using System.Net;
-using System.Net.Quic;
using System.Reflection;
using DTLib.Console;
using DTLib.Demystifier;
using DTLib.Extensions;
+using DTLib.Logging;
namespace Meum.Client.CLI;
@@ -34,15 +34,15 @@ class Program
{
Console.OutputEncoding = StringConverter.UTF8;
Console.InputEncoding = StringConverter.UTF8;
- ColoredConsole.ResetColor();
+ ColoredConsole.Clear();
+ var loggerRoot = new ConsoleLogger();
try
{
var v = Assembly.GetExecutingAssembly().GetName().Version;
string title = $"Meum CLI v{v?.ToString(3) ?? "Null"}";
Console.Title = title;
- if (!QuicConnection.IsSupported)
- throw new Exception("Quic is not supported, check for presence of libmsquic and openssl");
+ Functions.InitMsQuic(loggerRoot);
ColoredConsole.WriteTitle(title, '=', fg: ConsoleColor.Cyan);
ColoredConsole.WriteLine(greeting_art, fg: ConsoleColor.Magenta);
@@ -57,17 +57,18 @@ class Program
{
if (userAddress == null)
{
- var addrstr =
- ColoredConsole.ReadLine("enter user address (name@server.xyz)", ConsoleColor.Blue);
+ ColoredConsole.Write("enter user address (name@server.xyz): ", ConsoleColor.Blue);
+ var addrstr = ColoredConsole.ReadLine(ConsoleColor.Cyan);
if (string.IsNullOrEmpty(addrstr))
continue;
userAddress = new(addrstr);
}
- Client client = new();
+ Client client = new(loggerRoot);
if (serverEndPoint == null)
{
- serverAddress = ColoredConsole.ReadLine("enter server address (server.xyz)", ConsoleColor.Blue);
+ ColoredConsole.Write("enter server address (server.xyz): ", ConsoleColor.Blue);
+ serverAddress = ColoredConsole.ReadLine(ConsoleColor.Cyan);
if (string.IsNullOrEmpty(serverAddress))
{
ColoredConsole.WriteLine("null address", ConsoleColor.Red);
@@ -82,7 +83,6 @@ class Program
var conn = await client.ConnectToServerAsync(serverEndPoint);
ColoredConsole.WriteLine("Connected to server", ConsoleColor.Green);
- await conn.PingAsync();
await Task.Delay(-1);
}
catch (Exception ex)
diff --git a/Meum.Client/Client.cs b/Meum.Client/Client.cs
index ce186d4..b255b47 100644
--- a/Meum.Client/Client.cs
+++ b/Meum.Client/Client.cs
@@ -1,5 +1,6 @@
global using System;
global using System.Collections.Generic;
+global using System.Threading;
global using System.Threading.Tasks;
global using Meum.Core;
using System.Net;
@@ -36,7 +37,7 @@ public class Client
return Task.CompletedTask;
}
- public async Task ConnectToServerAsync(DnsEndPoint serverEndPoint)
+ public async Task ConnectToServerAsync(DnsEndPoint serverEndPoint, CancellationToken ct = default)
{
var quicConn = await QuicConnection.ConnectAsync(new QuicClientConnectionOptions
{
@@ -49,8 +50,15 @@ public class Client
ApplicationProtocols = Constants.ApplicationProtocols,
TargetHost = serverEndPoint.Host
}
- });
- var serv = new ServerConnection(quicConn, serverEndPoint, _logger);
+ }, ct);
+
+ var timeOutCts = CancellationTokenSource.CreateLinkedTokenSource(ct);
+ timeOutCts.CancelAfter(Constants.ConnectionTimeout);
+ var serv = await ServerConnection.OpenAsync(quicConn,
+ serverEndPoint,
+ _logger,
+ timeOutCts.Token);
+
if(!_connectedServers.Add(serv))
throw new Exception($"Is already connected to server '{serverEndPoint.Host}'");
return serv;
diff --git a/Meum.Client/Meum.Client.csproj b/Meum.Client/Meum.Client.csproj
index 42a8226..c6d1d0d 100644
--- a/Meum.Client/Meum.Client.csproj
+++ b/Meum.Client/Meum.Client.csproj
@@ -2,17 +2,12 @@
net9.0
- enable
enable
+ disable
-
-
-
-
-
diff --git a/Meum.Client/ServerConnection.cs b/Meum.Client/ServerConnection.cs
index 51903a3..080fdf2 100644
--- a/Meum.Client/ServerConnection.cs
+++ b/Meum.Client/ServerConnection.cs
@@ -1,7 +1,5 @@
using System.Net;
using System.Net.Quic;
-using System.Net.Security;
-using DTLib.Extensions;
using DTLib.Logging;
namespace Meum.Client;
@@ -14,14 +12,25 @@ public class ServerConnection : IAsyncDisposable
public DnsEndPoint ServerEndPoint { get; }
- public ServerConnection(QuicConnection quicConnection, DnsEndPoint serverEndPoint, ILogger logger)
+ private ServerConnection(QuicConnection quicConnection, DnsEndPoint serverEndPoint, ILogger logger)
{
ServerEndPoint = serverEndPoint;
_quicConnection = quicConnection;
_logger = logger;
}
-
+ public static async Task OpenAsync(QuicConnection quicConnection,
+ DnsEndPoint serverEndPoint,
+ ILogger logger,
+ CancellationToken ct)
+ {
+ var serverConnection = new ServerConnection(quicConnection, serverEndPoint, logger);
+
+ var systemStream = await quicConnection.OpenStreamAsync(QuicStreamType.Bidirectional, ct);
+ await systemStream.SendPingReceivePong();
+ return serverConnection;
+ }
+
public override int GetHashCode()
{
return _quicConnection.RemoteEndPoint.GetHashCode();
diff --git a/Meum.Core/Constants.cs b/Meum.Core/Constants.cs
index f64031d..fa2a23b 100644
--- a/Meum.Core/Constants.cs
+++ b/Meum.Core/Constants.cs
@@ -2,7 +2,6 @@
global using System.Collections.Generic;
global using System.Threading;
global using System.Threading.Tasks;
-using System.Net;
using System.Net.Security;
namespace Meum.Core;
@@ -17,4 +16,5 @@ public static class Constants
public const int ServerPortDefault = 9320;
public const long DefaultStreamErrorCode = 0xA;
public const long DefaultCloseErrorCode = 0xB;
+ public static readonly TimeSpan ConnectionTimeout = TimeSpan.FromSeconds(3);
}
\ No newline at end of file
diff --git a/Meum.Core/Functions.cs b/Meum.Core/Functions.cs
index 7fe6ab7..38d597b 100644
--- a/Meum.Core/Functions.cs
+++ b/Meum.Core/Functions.cs
@@ -1,9 +1,25 @@
using System.Net;
+using System.Net.Quic;
+using DTLib.Logging;
+using Unofficial.MsQuic;
namespace Meum.Core;
public static class Functions
{
+ public static void InitMsQuic(ILogger? logger)
+ {
+ if (logger != null)
+ {
+ HarmonyMsQuicLoadFix.Apply(msg => logger.LogInfo(nameof(HarmonyMsQuicLoadFix), msg));
+ using var netEventListener = new NetEventListener(logger);
+ }
+ else HarmonyMsQuicLoadFix.Apply();
+
+ if (!QuicConnection.IsSupported)
+ throw new Exception("Quic is not supported, check for presence of libmsquic and openssl");
+ }
+
public static bool IsValidDomainName(string name)
{
return Uri.CheckHostName(name) != UriHostNameType.Unknown;
diff --git a/Meum.Core/Meum.Core.csproj b/Meum.Core/Meum.Core.csproj
index f835e5a..a7a0380 100644
--- a/Meum.Core/Meum.Core.csproj
+++ b/Meum.Core/Meum.Core.csproj
@@ -1,9 +1,12 @@
net9.0
+ enable
+ disable
true
-
+
+
diff --git a/Meum.Core/NetEventListener.cs b/Meum.Core/NetEventListener.cs
new file mode 100644
index 0000000..00e96e1
--- /dev/null
+++ b/Meum.Core/NetEventListener.cs
@@ -0,0 +1,37 @@
+using System.Diagnostics.Tracing;
+using System.Linq;
+using DTLib.Logging;
+
+namespace Meum.Core;
+
+internal class NetEventListener(ILogger _logger) : EventListener
+{
+ protected override void OnEventSourceCreated(EventSource eventSource)
+ {
+ // Filter for NetEventSource
+ if (eventSource.Name.Contains("System.Net"))
+ {
+ EnableEvents(eventSource, EventLevel.LogAlways, EventKeywords.All);
+ }
+ }
+
+ protected override void OnEventWritten(EventWrittenEventArgs eventData)
+ {
+ LogSeverity severity = eventData.Level switch
+ {
+ EventLevel.LogAlways => LogSeverity.Info,
+ EventLevel.Critical => LogSeverity.Error,
+ EventLevel.Error => LogSeverity.Error,
+ EventLevel.Warning => LogSeverity.Warn,
+ EventLevel.Informational => LogSeverity.Info,
+ EventLevel.Verbose => LogSeverity.Debug,
+ _ => throw new ArgumentOutOfRangeException(eventData.Level.ToString())
+ };
+ IEnumerable