diff --git a/Iceshrimp.Backend/Core/Federation/ActivityPub/FederationControlService.cs b/Iceshrimp.Backend/Core/Federation/ActivityPub/FederationControlService.cs index 11f7c6b8..4729cbbd 100644 --- a/Iceshrimp.Backend/Core/Federation/ActivityPub/FederationControlService.cs +++ b/Iceshrimp.Backend/Core/Federation/ActivityPub/FederationControlService.cs @@ -37,4 +37,12 @@ public class FederationControlService( return await db.BlockedInstances.AnyAsync(p => finalHosts.Any(host => host == p.Host || host.EndsWith("." + p.Host))); } + + public async Task ShouldSkipAsync(string host) + { + return await db.Instances.AnyAsync(p => p.Host == host.ToLowerInvariant() && + ((p.IsNotResponding && + p.LastCommunicatedAt < DateTime.UtcNow - TimeSpan.FromDays(7)) || + p.IsSuspended)); + } } \ No newline at end of file diff --git a/Iceshrimp.Backend/Core/Queues/DeliverQueue.cs b/Iceshrimp.Backend/Core/Queues/DeliverQueue.cs index d5806f0f..7ac52bed 100644 --- a/Iceshrimp.Backend/Core/Queues/DeliverQueue.cs +++ b/Iceshrimp.Backend/Core/Queues/DeliverQueue.cs @@ -34,6 +34,12 @@ public class DeliverQueue return; } + if (await fedCtrl.ShouldSkipAsync(job.RecipientHost)) + { + logger.LogDebug("fedCtrl.ShouldSkipAsync returned true, skipping"); + return; + } + logger.LogDebug("Delivering activity to: {uri}", job.InboxUrl); var key = await cache.FetchAsync($"userPrivateKey:{job.UserId}", TimeSpan.FromMinutes(60), async () => @@ -53,8 +59,8 @@ public class DeliverQueue _ = followup.ExecuteTask("UpdateInstanceMetadata", async provider => { var instanceSvc = provider.GetRequiredService(); - var webDomain = new Uri(job.InboxUrl).Host; - await instanceSvc.UpdateInstanceStatusAsync(job.RecipientHost, webDomain, (int)response.StatusCode); + await instanceSvc.UpdateInstanceStatusAsync(job.RecipientHost, new Uri(job.InboxUrl).Host, + (int)response.StatusCode, response.IsSuccessStatusCode); }); response.EnsureSuccessStatusCode(); diff --git a/Iceshrimp.Backend/Core/Services/InstanceService.cs b/Iceshrimp.Backend/Core/Services/InstanceService.cs index 6cdcba27..59f9f5e8 100644 --- a/Iceshrimp.Backend/Core/Services/InstanceService.cs +++ b/Iceshrimp.Backend/Core/Services/InstanceService.cs @@ -78,22 +78,33 @@ public class InstanceService(DatabaseContext db, HttpClient httpClient) } } - public async Task UpdateInstanceStatusAsync(string host, string webDomain, int? statusCode = null) + public async Task UpdateInstanceStatusAsync(string host, string webDomain) { var instance = await GetUpdatedInstanceMetadataAsync(host, webDomain); - if (statusCode != null) + instance.LastCommunicatedAt = DateTime.UtcNow; + instance.LatestRequestReceivedAt = DateTime.UtcNow; + + await db.SaveChangesAsync(); + } + + public async Task UpdateInstanceStatusAsync(string host, string webDomain, int statusCode, bool notResponding) + { + var instance = await GetUpdatedInstanceMetadataAsync(host, webDomain); + + instance.LatestStatus = statusCode; + instance.LatestRequestSentAt = DateTime.UtcNow; + + if (notResponding) { - instance.LatestStatus = statusCode; - instance.LatestRequestSentAt = DateTime.UtcNow; + instance.IsNotResponding = true; } else { - instance.LatestRequestReceivedAt = DateTime.UtcNow; + instance.IsNotResponding = false; + instance.LastCommunicatedAt = DateTime.UtcNow; } - instance.LastCommunicatedAt = DateTime.UtcNow; - await db.SaveChangesAsync(); } } \ No newline at end of file