fixes concurrency issue in http, fixes peer-dropped event

This commit is contained in:
benbierens 2024-08-01 11:19:05 +02:00
parent d16b8cb011
commit fd65e1f022
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
4 changed files with 15 additions and 5 deletions

View File

@ -13,6 +13,7 @@ namespace Core
internal class Http : IHttp
{
private static object lockLock = new object();
private static readonly Dictionary<string, object> httpLocks = new Dictionary<string, object>();
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()

View File

@ -171,9 +171,10 @@ namespace CodexPlugin
public TrackedFile? DownloadContent(ContentId contentId, Action<Failure> 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();

View File

@ -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;

View File

@ -2,11 +2,11 @@
{
public class PeerDroppedLineConverter : ILineConverter
{
public string Interest => "Peer dropped";
public string Interest => "Dropping peer";
public void Process(CodexLogLine line, Action<Action<OverwatchCodexEvent>> addEvent)
{
var peerId = line.Attributes["peerId"];
var peerId = line.Attributes["peer"];
addEvent(e =>
{