fixes concurrency issue in http, fixes peer-dropped event
This commit is contained in:
parent
d16b8cb011
commit
fd65e1f022
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 =>
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue