From fd65e1f022c061dc62dbc7bd9f3e4f248a8f2144 Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 1 Aug 2024 11:19:05 +0200 Subject: [PATCH] fixes concurrency issue in http, fixes peer-dropped event --- Framework/Core/Http.cs | 8 ++++++-- ProjectPlugins/CodexPlugin/CodexNode.cs | 3 ++- ProjectPlugins/CodexPlugin/CodexTypes.cs | 5 +++++ .../LineConverters/PeerDroppedLineConverter.cs | 4 ++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Framework/Core/Http.cs b/Framework/Core/Http.cs index 1cb468ad..601d2f48 100644 --- a/Framework/Core/Http.cs +++ b/Framework/Core/Http.cs @@ -13,6 +13,7 @@ namespace Core internal class Http : IHttp { + private static object lockLock = new object(); private static readonly Dictionary httpLocks = new Dictionary(); private readonly ILog log; private readonly ITimeSet timeSet; @@ -74,8 +75,11 @@ namespace Core private object GetLock() { - if (!httpLocks.ContainsKey(id)) httpLocks.Add(id, new object()); - return httpLocks[id]; + lock (lockLock) // I had to. + { + if (!httpLocks.ContainsKey(id)) httpLocks.Add(id, new object()); + return httpLocks[id]; + } } private HttpClient GetClient() diff --git a/ProjectPlugins/CodexPlugin/CodexNode.cs b/ProjectPlugins/CodexPlugin/CodexNode.cs index cfea9722..22e6b999 100644 --- a/ProjectPlugins/CodexPlugin/CodexNode.cs +++ b/ProjectPlugins/CodexPlugin/CodexNode.cs @@ -171,9 +171,10 @@ namespace CodexPlugin public TrackedFile? DownloadContent(ContentId contentId, Action onFailure, string fileLabel = "") { var file = tools.GetFileManager().CreateEmptyFile(fileLabel); - var logMessage = $"Downloading '{contentId.Id}' to '{file.Filename}'"; hooks.OnFileDownloading(contentId); + Log($"Downloading '{contentId}'..."); + var logMessage = $"Downloaded '{contentId}' to '{file.Filename}'"; var measurement = Stopwatch.Measure(log, logMessage, () => DownloadToFile(contentId.Id, file, onFailure)); var size = file.GetFilesize(); diff --git a/ProjectPlugins/CodexPlugin/CodexTypes.cs b/ProjectPlugins/CodexPlugin/CodexTypes.cs index d40fb13b..be5b2295 100644 --- a/ProjectPlugins/CodexPlugin/CodexTypes.cs +++ b/ProjectPlugins/CodexPlugin/CodexTypes.cs @@ -95,6 +95,11 @@ namespace CodexPlugin public string Id { get; } + public override string ToString() + { + return Id; + } + public override bool Equals(object? obj) { return obj is ContentId id && Id == id.Id; diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/PeerDroppedLineConverter.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/PeerDroppedLineConverter.cs index 24b2c7c0..6ec30cd1 100644 --- a/ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/PeerDroppedLineConverter.cs +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/PeerDroppedLineConverter.cs @@ -2,11 +2,11 @@ { public class PeerDroppedLineConverter : ILineConverter { - public string Interest => "Peer dropped"; + public string Interest => "Dropping peer"; public void Process(CodexLogLine line, Action> addEvent) { - var peerId = line.Attributes["peerId"]; + var peerId = line.Attributes["peer"]; addEvent(e => {