Skip to content

Commit d8eef90

Browse files
committed
Updated dependencies. Try to allow forwards compatibility when runtime version is newer than app-bundled runtime libraries like System.Diagnostics.DiagnosticSource.
1 parent bd09aee commit d8eef90

File tree

7 files changed

+639
-1372
lines changed

7 files changed

+639
-1372
lines changed

GandiDynamicDns/DynamicDnsService.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using Gandi;
1+
using Gandi;
22
using Gandi.Dns;
33
using Microsoft.Extensions.Options;
44
using System.Diagnostics;
55
using System.Net;
6-
using ThrottleDebounce;
6+
using ThrottleDebounce.Retry;
77
using Unfucked;
88
using Unfucked.HTTP.Exceptions;
99
using Unfucked.STUN;
@@ -32,21 +32,25 @@ public class DynamicDnsServiceImpl(ILiveDns liveDns, ISelfWanAddressClient stun,
3232
null;
3333
#endif
3434

35+
/// <exception cref="GandiException"></exception>
3536
protected override async Task ExecuteAsync(CancellationToken ct) {
3637
try {
3738
foreach (string subdomain in configuration.Value.subdomains) {
3839
// this retry is to handle the case where the service starts before the computer connects to the network on bootup, not where Gandi's API servers are down
3940
await Retrier.Attempt(async _ => {
40-
IPAddress? initialRecordValue = null;
41-
if ((await liveDns.Get(RecordType.A, subdomain, ct))?.Values.First() is { } existingIpAddress) {
42-
try {
43-
initialRecordValue = IPAddress.Parse(existingIpAddress);
44-
} catch (FormatException) { }
45-
}
46-
initialRecordValues[subdomain] = initialRecordValue;
47-
}, maxAttempts: null, delay: Retrier.Delays.Constant(TimeSpan.FromSeconds(3)), ex => ex is not (OutOfMemoryException or GandiException { InnerException: ClientErrorException }),
48-
beforeRetry: async (i, e) =>
49-
logger.LogWarning("Failed to fetch existing DNS record from Gandi HTTP API server, retrying (attempt {attempt}): {message}", i + 2, e.MessageChain()), ct);
41+
IPAddress? initialRecordValue = null;
42+
if ((await liveDns.Get(RecordType.A, subdomain, ct))?.Values.First() is {} existingIpAddress) {
43+
try {
44+
initialRecordValue = IPAddress.Parse(existingIpAddress);
45+
} catch (FormatException) {}
46+
}
47+
initialRecordValues[subdomain] = initialRecordValue;
48+
}, new RetryOptions {
49+
Delay = Delays.Constant(TimeSpan.FromSeconds(3)),
50+
IsRetryAllowed = (ex, _) => ex is not (OutOfMemoryException or GandiException { InnerException: ClientErrorException }),
51+
BeforeRetry = (e, i) => logger.LogWarning("Failed to fetch existing DNS record from Gandi HTTP API server, retrying (attempt {attempt}): {message}", i + 2, e.MessageChain()),
52+
CancellationToken = ct
53+
});
5054

5155
logger.LogInformation("On startup, the {subdomain}.{domain} DNS A record is pointing to {address}", subdomain, configuration.Value.domain,
5256
initialRecordValues[subdomain]?.ToString() ?? "(nothing)");
@@ -79,6 +83,7 @@ await Retrier.Attempt(async _ => {
7983
}
8084
}
8185

86+
/// <exception cref="GandiException"></exception>
8287
private async Task updateDnsRecordIfNecessary(CancellationToken ct = default) {
8388
SelfWanAddressResponse originalResponse = await stun.GetSelfWanAddress(ct);
8489
if (originalResponse.SelfWanAddress != null) {
@@ -126,6 +131,7 @@ private async Task<bool> getUnanimousAgreement(SelfWanAddressResponse originalRe
126131
return extraResponses.All(extra => originalResponse.SelfWanAddress!.Equals(extra.SelfWanAddress));
127132
}
128133

134+
/// <exception cref="GandiException"></exception>
129135
private async Task updateDnsRecords(IPAddress currentIPAddress, CancellationToken ct = default) {
130136
foreach (string subdomain in configuration.Value.subdomains) {
131137
if (!configuration.Value.dryRun) {

GandiDynamicDns/GandiDynamicDns.csproj

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
1717
<ApplicationIcon>favicon.ico</ApplicationIcon>
1818
<ApplicationManifest>app.manifest</ApplicationManifest>
19-
<!-- <PublishSingleFile>true</PublishSingleFile> -->
2019
<SelfContained>false</SelfContained>
2120
<DebugType>embedded</DebugType>
21+
<RuntimeLibraryVersion>10.0.0</RuntimeLibraryVersion>
2222
</PropertyGroup>
2323

2424
<ItemGroup>
@@ -29,16 +29,19 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32-
<PackageReference Include="Gandi" Version="1.0.0" />
33-
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="9.0.4" />
34-
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="9.0.4" />
35-
<PackageReference Include="ThrottleDebounce" Version="3.0.0-beta2" />
36-
<PackageReference Include="Unfucked" Version="0.0.1-beta.1" />
37-
<PackageReference Include="Unfucked.DI" Version="0.0.1-beta.1" />
38-
<PackageReference Include="Unfucked.STUN" Version="0.0.1-beta.1" />
39-
<PackageReference Include="RuntimeUpgradeNotifier" Version="1.0.0-beta3" />
32+
<PackageReference Include="Gandi" Version="1.1.0" />
33+
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="$(RuntimeLibraryVersion)" />
34+
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="$(RuntimeLibraryVersion)" />
35+
<PackageReference Include="ThrottleDebounce" Version="3.0.0-beta5" />
36+
<PackageReference Include="Unfucked" Version="0.0.1-beta.25" />
37+
<PackageReference Include="Unfucked.DI" Version="0.0.1-beta.11" />
38+
<PackageReference Include="Unfucked.HTTP" Version="0.0.1-beta.21" />
39+
<PackageReference Include="Unfucked.STUN" Version="0.0.1-beta.3" />
40+
<PackageReference Include="RuntimeUpgradeNotifier" Version="1.0.0" />
4041
</ItemGroup>
4142

43+
<Import Project="UnfuckProvidedDependencies.props" />
44+
4245
<ItemGroup Condition="$(RuntimeIdentifier.StartsWith('win'))">
4346
<None Update="Install service.ps1" CopyToOutputDirectory="PreserveNewest" />
4447
</ItemGroup>

GandiDynamicDns/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Gandi;
1+
using Gandi;
22
using Gandi.Dns;
33
using GandiDynamicDns;
44
using GandiDynamicDns.Util;
@@ -43,7 +43,7 @@
4343
.SetExitCodeOnBackgroundServiceException()
4444
.AddSingleton<IGandiClient>(GandiClientFactory.createGandiClient)
4545
.AddSingleton<ILiveDns>(provider => provider.GetRequiredService<IGandiClient>().LiveDns(provider.GetRequiredService<IOptions<Configuration>>().Value.domain))
46-
.AddStunClient(ctx => new StunOptions { serverHostnameBlacklist = ctx.GetRequiredService<IOptions<Configuration>>().Value.stunServerBlacklist });
46+
.AddStunClient(ctx => new StunOptions { ServerHostnameBlacklist = ctx.GetRequiredService<IOptions<Configuration>>().Value.stunServerBlacklist });
4747

4848
using IHost app = appConfig.Build();
4949

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project>
2+
3+
<!-- .NET and ASP.NET Core Runtime provided dependencies, to prevent FileNotFoundException caused by latestVersion rollForward with PublishSingleFile when runtime version > dependency version -->
4+
<ItemGroup Label="Provided" Condition="'$(_IsPublishing)' == 'true'">
5+
<!-- .NET Runtime -->
6+
<PackageReference PrivateAssets="all" Version="$(RuntimeLibraryVersion)" Include="System.Diagnostics.DiagnosticSource" />
7+
<PackageReference PrivateAssets="all" Version="$(RuntimeLibraryVersion)" Include="System.IO.Pipelines" />
8+
<PackageReference PrivateAssets="all" Version="$(RuntimeLibraryVersion)" Include="System.Text.Encodings.Web" />
9+
<PackageReference PrivateAssets="all" Version="$(RuntimeLibraryVersion)" Include="System.Text.Json" />
10+
</ItemGroup>
11+
12+
</Project>

0 commit comments

Comments
 (0)