House rules: primary constructors, a cancellation token on every async call, and the rules fail the build
Build / Build (push) Successful in 30s

- Services, controllers and jobs take their dependencies through primary
  constructors and use them directly; where a method already named a local
  after a dependency, the dependency takes its type's name.
- Every async method takes a CancellationToken last and passes it down to
  MongoDB, HTTP and the job queue. The setup claim is still given back when
  a request is cancelled.
- The federation and media options are read through IOptionsMonitor.
- The Mastodon entities keep sending "" for empty strings, and every model
  field where null means something says so.
- The inbox's 503 with Retry-After, which other servers retry, is the one
  server error left, and says why.
- Arasaka.HouseRules.Analyzers checks all of this in every build, here and in
  PrivaPub.ClientModels as decePubClient builds it.

Checked against GoToSocial in the pasture: 64 passed, 0 failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W4YtEJrgxG12Pc39Fai8Bd
This commit is contained in:
thepraandClaude Opus 5.5 committed 2026-11-10 01:24:43 +01:00
1 parent f0a14c737f
commit 0f73f69239
176 files changed
+2789 -3974

No files matched your search

+13 -23
View File
@@ -33,31 +33,21 @@ namespace PrivaPub.Federation.Relays
// subscribes, and takes what they pass on: public posts, forwarded as their authors sent them (read again from their
// origin, as any forwarded post) or announced by the relay. A persona's public posts go to the relays that accepted us
// (owner decision 2026-10-06), as Mastodon sends them; nothing else of a persona's does.
public class Relays : IRelays
public class Relays(
IOptionsMonitor<FederationOptions> options,
IRemoteActorService remoteActors,
ILocalActorService localActors,
IDeliveryService delivery,
Domain.Instance.IInstanceSettings instanceSettings) : IRelays
{
static readonly TimeSpan AskAgain = TimeSpan.FromDays(1);
readonly IOptions<FederationOptions> _options;
readonly IRemoteActorService _remoteActors;
readonly ILocalActorService _localActors;
readonly IDeliveryService _delivery;
readonly Domain.Instance.IInstanceSettings _settings;
readonly SemaphoreSlim _reconciling = new(1, 1);//the hourly round and the administrator's page, one at a time
volatile HashSet<string> _accepted;
public Relays(IOptions<FederationOptions> options, IRemoteActorService remoteActors, ILocalActorService localActors, IDeliveryService delivery,
Domain.Instance.IInstanceSettings settings)
{
_options = options;
_remoteActors = remoteActors;
_localActors = localActors;
_delivery = delivery;
_settings = settings;
}
public IReadOnlyList<string> Configured => Clean(options.CurrentValue.Relays);
public IReadOnlyList<string> Configured => Clean(_options.Value.Relays);
public IReadOnlyList<string> Named => Clean(Configured.Concat(_settings.Current.Relays ?? new()));
public IReadOnlyList<string> Named => Clean(Configured.Concat(instanceSettings.Current.Relays ?? new()));
static List<string> Clean(IEnumerable<string> addresses) =>
(addresses ?? Array.Empty<string>()).Where(r => !string.IsNullOrWhiteSpace(r)).Select(r => r.Trim()).Distinct(StringComparer.Ordinal).ToList();
@@ -84,12 +74,12 @@ namespace PrivaPub.Federation.Relays
var known = await DB.Default.Find<RelaySubscription>().ExecuteAsync(token);
if (configured.Count == 0 && known.Count == 0)
return;
var instance = await _localActors.GetInstanceActor(token);
var instance = await localActors.GetInstanceActor(token);
var kept = known.Where(k => configured.Contains(k.Configured)).Select(k => k.ActorURI).Where(a => a != default).ToHashSet(StringComparer.Ordinal);
foreach (var gone in known.Where(k => !configured.Contains(k.Configured)))
{
if (gone.State != RelayState.Rejected && !string.IsNullOrEmpty(gone.InboxURL) && !kept.Contains(gone.ActorURI))
await _delivery.Enqueue(instance, new[] { gone.InboxURL }, Undo(instance, gone.FollowActivityURI), token);
await delivery.Enqueue(instance, new[] { gone.InboxURL }, Undo(instance, gone.FollowActivityURI), token: token);
await DB.Default.DeleteAsync<RelaySubscription>(gone.ID);
}
_accepted = default;
@@ -109,7 +99,7 @@ namespace PrivaPub.Federation.Relays
subscription.RequestedAt = DateTime.UtcNow;
subscription.AnsweredAt = default;
await DB.Default.SaveAsync(subscription, token);
await _delivery.Enqueue(instance, new[] { relay.InboxURL }, Follow(instance, subscription.FollowActivityURI), token);
await delivery.Enqueue(instance, new[] { relay.InboxURL }, Follow(instance, subscription.FollowActivityURI), token: token);
}
_accepted = default;
}
@@ -150,10 +140,10 @@ namespace PrivaPub.Federation.Relays
// the relay's actor, from its address or, for a relay named by its inbox, from the /actor beside it
async Task<ForeignAvatar> Resolve(string address, CancellationToken token)
{
var actor = await _remoteActors.GetActor(address, refresh: false, token);
var actor = await remoteActors.GetActor(address, refresh: false, token);
if (actor != default || !address.EndsWith("/inbox", StringComparison.Ordinal))
return actor;
return await _remoteActors.GetActor(address[..^"/inbox".Length] + "/actor", refresh: false, token);
return await remoteActors.GetActor(address[..^"/inbox".Length] + "/actor", refresh: false, token);
}
static JsonObject Follow(LocalActor instance, string id) => new()