Skip to content

Commit

Permalink
Update packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Rans4ckeR committed Jul 15, 2024
1 parent 12770c7 commit 2b66e37
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 79 deletions.
57 changes: 57 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ dotnet_diagnostic.CA1303.severity = none
dotnet_diagnostic.CA1008.severity = none
dotnet_diagnostic.API1002.severity = none
dotnet_diagnostic.API1003.severity = warning
dotnet_diagnostic.CA2263.severity = warning

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
Expand Down Expand Up @@ -563,5 +564,61 @@ dotnet_diagnostic.CA1062.severity = none
dotnet_diagnostic.MSTEST0001.severity = warning
dotnet_diagnostic.MSTEST0006.severity = warning
dotnet_diagnostic.MSTEST0004.severity = warning

# RS1015: Provide non-null 'helpLinkUri' value to diagnostic descriptor constructor
dotnet_diagnostic.RS1015.severity = warning

# RS1020: Category for analyzers must be from the specified values
dotnet_diagnostic.RS1020.severity = warning

# RS1028: Provide non-null 'customTags' value to diagnostic descriptor constructor
dotnet_diagnostic.RS1028.severity = warning

# CA1002: Do not expose generic lists
dotnet_diagnostic.CA1002.severity = warning

# CA1014: Mark assemblies with CLSCompliant
dotnet_diagnostic.CA1014.severity = warning

# CA1017: Mark assemblies with ComVisible
dotnet_diagnostic.CA1017.severity = warning

# CA1021: Avoid out parameters
dotnet_diagnostic.CA1021.severity = warning

# CA1045: Do not pass types by reference
dotnet_diagnostic.CA1045.severity = warning

# CA1060: Move pinvokes to native methods class
dotnet_diagnostic.CA1060.severity = warning

# CA1501: Avoid excessive inheritance
dotnet_diagnostic.CA1501.severity = warning

# CA1502: Avoid excessive complexity
dotnet_diagnostic.CA1502.severity = warning

# CA1505: Avoid unmaintainable code
dotnet_diagnostic.CA1505.severity = warning

# CA1506: Avoid excessive class coupling
dotnet_diagnostic.CA1506.severity = warning

# CA1509: Invalid entry in code metrics rule specification file
dotnet_diagnostic.CA1509.severity = warning
dotnet_diagnostic.MSTEST0015.severity = warning
dotnet_diagnostic.MSTEST0016.severity = warning
dotnet_diagnostic.CA1871.severity = warning
dotnet_diagnostic.MSTEST0007.severity = warning
dotnet_diagnostic.CA1872.severity = warning
dotnet_diagnostic.MSTEST0019.severity = warning
dotnet_diagnostic.MSTEST0020.severity = warning
dotnet_diagnostic.MSTEST0021.severity = warning
dotnet_diagnostic.MSTEST0022.severity = warning
dotnet_diagnostic.MSTEST0025.severity = warning
dotnet_diagnostic.MSTEST0017.severity = warning
dotnet_diagnostic.MSTEST0023.severity = warning
dotnet_diagnostic.MSTEST0024.severity = warning

[*.vb]
dotnet_diagnostic.CA1047.severity = warning
2 changes: 1 addition & 1 deletion CnCNet/Net/PeerToPeer/PeerToPeerUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private async ValueTask StartReceiverAsync(int listenPort, CancellationToken can
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
#pragma warning disable IDE0058 // Expression value is never used
ReceiveAsync(client, buffer, remoteSocketAddress, cancellationToken).ConfigureAwait(false);
ReceiveAsync(client, buffer, remoteSocketAddress, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
#pragma warning restore IDE0058 // Expression value is never used
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}
Expand Down
10 changes: 5 additions & 5 deletions CnCNet/Net/Tunnel/Tunnel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public virtual async ValueTask StartAsync(CancellationToken cancellationToken)
DoReceiveAsync(
buffer[..receivedBytes],
remoteSocketAddress,
cancellationToken).ConfigureAwait(false);
cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);
#pragma warning restore IDE0058 // Expression value is never used
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}
Expand Down Expand Up @@ -234,7 +234,7 @@ private async Task DoReceiveAsync(ReadOnlyMemory<byte> buffer, SocketAddress soc
private async ValueTask SendMasterServerHeartbeatAsync(int clients, CancellationToken cancellationToken)
{
var path = new Uri(
FormattableString.Invariant($"?version={Version}&name={Uri.EscapeDataString(ServiceOptions.Value.Name!)}") +
FormattableString.Invariant($"?version={Version}&name={Uri.EscapeDataString(ServiceOptions.Value.Name)}") +
FormattableString.Invariant($"&port={Port}&clients={clients}&maxclients={ServiceOptions.Value.MaxClients}") +
FormattableString.Invariant($"&masterpw={Uri.EscapeDataString(ServiceOptions.Value.MasterPassword ?? string.Empty)}") +
FormattableString.Invariant($"&maintenance={(MaintenanceModeEnabled ? 1 : 0)}") +
Expand All @@ -245,10 +245,10 @@ private async ValueTask SendMasterServerHeartbeatAsync(int clients, Cancellation
try
{
httpResponseMessage = await httpClientFactory.CreateClient(Options.DefaultName)
.GetAsync(path, cancellationToken).ConfigureAwait(false);
.GetAsync(path, cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);

string responseContent = await httpResponseMessage.EnsureSuccessStatusCode().Content
.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
.ReadAsStringAsync(cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);

if (!"OK".Equals(responseContent, StringComparison.OrdinalIgnoreCase))
throw new MasterServerException(responseContent);
Expand Down Expand Up @@ -326,7 +326,7 @@ protected virtual int CleanupConnections()
private int CleanupConnections()
#endif
{
foreach (KeyValuePair<uint, TunnelClient> mapping in Mappings!.Where(static x => x.Value.TimedOut).ToFrozenSet())
foreach (KeyValuePair<uint, TunnelClient> mapping in Mappings!.Where(static x => x.Value.TimedOut))
{
CleanupConnection(mapping.Value);
_ = Mappings!.Remove(mapping.Key, out _);
Expand Down
12 changes: 6 additions & 6 deletions CnCNetBackgroundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal sealed class CnCNetBackgroundService(
{
private const int StunPort1 = 3478;
private const int StunPort2 = 8054;
private const int ErrorExitCode = 1;

private bool started;
private bool stopping;
Expand All @@ -31,7 +32,7 @@ public override async Task StartAsync(CancellationToken cancellationToken)
if (logger.IsEnabled(LogLevel.Information))
logger.LogInfo(FormattableString.Invariant($"Server {options.Value.Name} starting."));

await base.StartAsync(cancellationToken).ConfigureAwait(false);
await base.StartAsync(cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);

if (logger.IsEnabled(LogLevel.Information))
logger.LogInfo(FormattableString.Invariant($"Server {options.Value.Name} started."));
Expand All @@ -58,7 +59,7 @@ public override async Task StopAsync(CancellationToken cancellationToken)
if (logger.IsEnabled(LogLevel.Information))
logger.LogInfo(FormattableString.Invariant($"Server {options.Value.Name} stopping."));

await base.StopAsync(cancellationToken).ConfigureAwait(false);
await base.StopAsync(cancellationToken).ConfigureAwait(ConfigureAwaitOptions.None);

if (logger.IsEnabled(LogLevel.Information))
logger.LogInfo(FormattableString.Invariant($"Server {options.Value.Name} stopped."));
Expand Down Expand Up @@ -111,18 +112,17 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
catch (Exception ex)
{
await logger.LogExceptionDetailsAsync(ex).ConfigureAwait(false);

throw;
Environment.Exit(ErrorExitCode);
}
}

private static async Task WhenAllSafe(IEnumerable<Task> tasks)
private static async ValueTask WhenAllSafe(IEnumerable<Task> tasks)
{
var whenAllTask = Task.WhenAll(tasks);

try
{
await whenAllTask.ConfigureAwait(false);
await whenAllTask.ConfigureAwait(ConfigureAwaitOptions.None);
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion Infrastructure/ExceptionMessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static string GetDetailedExceptionInfo(this Exception ex)

public static async ValueTask<string> GetHttpResponseMessageInfoAsync(this HttpResponseMessage httpResponseMessage)
{
string content = await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
string content = await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(ConfigureAwaitOptions.None);

return new StringBuilder()
.Append(FormattableString.Invariant($"{nameof(HttpResponseMessage)}: {httpResponseMessage}"))
Expand Down
1 change: 1 addition & 0 deletions Infrastructure/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal static class Startup
public static void UseSocketsHttpHandler(SocketsHttpHandler socketsHttpHandler, IServiceProvider serviceProvider)
{
socketsHttpHandler.AutomaticDecompression = DecompressionMethods.All;
socketsHttpHandler.PooledConnectionLifetime = TimeSpan.FromMinutes(15);
socketsHttpHandler.ConnectCallback = async (context, token) =>
{
Socket? socket = null;
Expand Down
13 changes: 8 additions & 5 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
.UseDefaults()
.UseHost(Host.CreateDefaultBuilder, static hostBuilder =>
hostBuilder
.UseWindowsService(static o => o.ServiceName = "CnCNetServer")
.UseSystemd()
.ConfigureServices(static services =>
{
services.AddOptions<ServiceOptions>().BindCommandLine();
services
.AddOptions<ServiceOptions>()
.BindCommandLine();
services
.AddWindowsService(static o => o.ServiceName = "CnCNetServer")
.AddSystemd()
.AddHostedService<CnCNetBackgroundService>()
.AddSingleton<TunnelV3>()
#if EnableLegacyVersion
Expand All @@ -22,9 +24,10 @@
.AddTransient<PeerToPeerUtil>()
.AddHttpClient(Options.DefaultName)
.ConfigureHttpClient(Startup.ConfigureHttpClient)
.UseSocketsHttpHandler(Startup.UseSocketsHttpHandler);
.UseSocketsHttpHandler(Startup.UseSocketsHttpHandler)
.SetHandlerLifetime(Timeout.InfiniteTimeSpan);
})
.ConfigureLogging(Startup.ConfigureLogging))
.Build()
.InvokeAsync(args)
.ConfigureAwait(false);
.ConfigureAwait(ConfigureAwaitOptions.None);
44 changes: 22 additions & 22 deletions ServiceOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,53 @@

internal sealed record ServiceOptions
{
public int TunnelPort { get; set; }
public required int TunnelPort { get; init; }
#if EnableLegacyVersion

public int TunnelV2Port { get; set; }
public required int TunnelV2Port { get; init; }
#endif

public string? Name { get; set; }
public required string Name { get; init; }

public int MaxClients { get; set; }
public required int MaxClients { get; init; }

public bool NoMasterAnnounce { get; set; }
public required bool NoMasterAnnounce { get; init; }

public string? MasterPassword { get; set; }
public required string? MasterPassword { get; init; }

public string? MaintenancePassword { get; set; }
public required string? MaintenancePassword { get; init; }

public Uri? MasterServerUrl { get; set; }
public required Uri MasterServerUrl { get; init; }

public int IpLimit { get; set; }
public required int IpLimit { get; init; }

public bool NoPeerToPeer { get; set; }
public required bool NoPeerToPeer { get; init; }

public bool TunnelV3Enabled { get; set; }
public required bool TunnelV3Enabled { get; init; }
#if EnableLegacyVersion

public bool TunnelV2Enabled { get; set; }
public required bool TunnelV2Enabled { get; init; }
#endif

public LogLevel ServerLogLevel { get; set; }
public required LogLevel ServerLogLevel { get; init; }

public LogLevel SystemLogLevel { get; set; }
public required LogLevel SystemLogLevel { get; init; }

public bool AnnounceIpV6 { get; set; }
public required bool AnnounceIpV6 { get; init; }

public bool AnnounceIpV4 { get; set; }
public required bool AnnounceIpV4 { get; init; }
#if EnableLegacyVersion

public bool TunnelV2Https { get; set; }
public required bool TunnelV2Https { get; init; }
#endif

public int MaxPacketSize { get; set; }
public required int MaxPacketSize { get; init; }

public ushort MaxPingsGlobal { get; set; }
public required ushort MaxPingsGlobal { get; init; }

public ushort MaxPingsPerIp { get; set; }
public required ushort MaxPingsPerIp { get; init; }

public ushort MasterAnnounceInterval { get; set; }
public required ushort MasterAnnounceInterval { get; init; }

public int ClientTimeout { get; set; }
public required int ClientTimeout { get; init; }
}
Loading

0 comments on commit 2b66e37

Please sign in to comment.