peer dropped and starting/started events for upload and download

This commit is contained in:
benbierens 2024-08-01 09:09:30 +02:00
parent 7352cdf3fe
commit 37611bdc66
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
10 changed files with 116 additions and 28 deletions

View File

@ -13,7 +13,6 @@
public long SizeInBytes { get; }
public long ToMB()
{
return SizeInBytes / (1024 * 1024);

View File

@ -136,6 +136,10 @@ namespace CodexPlugin
public ContentId UploadFile(TrackedFile file, Action<Failure> onFailure)
{
using var fileStream = File.OpenRead(file.Filename);
var uniqueId = Guid.NewGuid().ToString();
var size = file.GetFilesize();
hooks.OnFileUploading(uniqueId, size);
var logMessage = $"Uploading file {file.Describe()}...";
Log(logMessage);
@ -145,7 +149,7 @@ namespace CodexPlugin
});
var response = measurement.Value;
transferSpeeds.AddUploadSample(file.GetFilesize(), measurement.Duration);
transferSpeeds.AddUploadSample(size, measurement.Duration);
if (string.IsNullOrEmpty(response)) FrameworkAssert.Fail("Received empty response.");
if (response.StartsWith(UploadFailedMessage)) FrameworkAssert.Fail("Node failed to store block.");
@ -153,7 +157,7 @@ namespace CodexPlugin
Log($"Uploaded file. Received contentId: '{response}'.");
var cid = new ContentId(response);
hooks.OnFileUploaded(cid);
hooks.OnFileUploaded(uniqueId, size, cid);
return cid;
}
@ -165,12 +169,14 @@ namespace CodexPlugin
public TrackedFile? DownloadContent(ContentId contentId, Action<Failure> onFailure, string fileLabel = "")
{
var logMessage = $"Downloading for contentId: '{contentId.Id}'...";
hooks.OnFileDownloading(contentId);
Log(logMessage);
var file = tools.GetFileManager().CreateEmptyFile(fileLabel);
var measurement = Stopwatch.Measure(tools.GetLog(), logMessage, () => DownloadToFile(contentId.Id, file, onFailure));
transferSpeeds.AddDownloadSample(file.GetFilesize(), measurement);
var size = file.GetFilesize();
transferSpeeds.AddDownloadSample(size, measurement);
Log($"Downloaded file {file.Describe()} to '{file.Filename}'.");
hooks.OnFileDownloaded(contentId);
hooks.OnFileDownloaded(size, contentId);
return file;
}

View File

@ -50,10 +50,10 @@ namespace CodexPlugin
"secure",
"chronosstream",
"connection",
"connmanager",
// Removed: "connmanager", is used for transcript peer-dropped event.
"websock",
"ws-session",
// Removed: "dialer", is used for transcript event generation.
// Removed: "dialer", is used for transcript successful-dial event.
"muxedupgrade",
"upgrade",
"identify"

View File

@ -1,4 +1,6 @@
namespace CodexPlugin.Hooks
using Utils;
namespace CodexPlugin.Hooks
{
public interface ICodexHooksProvider
{
@ -25,11 +27,19 @@
public class DoNothingCodexHooks : ICodexNodeHooks
{
public void OnFileDownloaded(ContentId cid)
public void OnFileDownloaded(ByteSize size, ContentId cid)
{
}
public void OnFileUploaded(ContentId cid)
public void OnFileDownloading(ContentId cid)
{
}
public void OnFileUploaded(string uid, ByteSize size, ContentId cid)
{
}
public void OnFileUploading(string uid, ByteSize size)
{
}
@ -37,7 +47,7 @@
{
}
public void OnNodeStarting(DateTime startUtc, string name)
public void OnNodeStarting(DateTime startUtc, string image)
{
}

View File

@ -1,11 +1,15 @@
namespace CodexPlugin.Hooks
using Utils;
namespace CodexPlugin.Hooks
{
public interface ICodexNodeHooks
{
void OnNodeStarting(DateTime startUtc, string image);
void OnNodeStarted(string peerId);
void OnNodeStopping();
void OnFileUploaded(ContentId cid);
void OnFileDownloaded(ContentId cid);
void OnFileUploading(string uid, ByteSize size);
void OnFileUploaded(string uid, ByteSize size, ContentId cid);
void OnFileDownloading(ContentId cid);
void OnFileDownloaded(ByteSize size, ContentId cid);
}
}

View File

@ -58,6 +58,7 @@ namespace CodexPlugin.OverwatchSupport
new BlockReceivedLineConverter(),
new BootstrapLineConverter(),
new DialSuccessfulLineConverter(),
new PeerDroppedLineConverter()
};
public ConversionRunner(ITranscriptWriter writer, string name, string peerId)

View File

@ -120,31 +120,56 @@ namespace CodexPlugin.OverwatchSupport
{
WriteCodexEvent(e =>
{
e.NodeStopped = new NodeStoppedEvent
{
Name = name
e.NodeStopping = new NodeStoppingEvent
{
};
});
}
public void OnFileDownloaded(ContentId cid)
public void OnFileDownloading(ContentId cid)
{
WriteCodexEvent(e =>
{
e.FileDownloaded = new FileDownloadedEvent
e.FileDownloading = new FileDownloadingEvent
{
Cid = cid.Id
};
});
}
public void OnFileUploaded(ContentId cid)
public void OnFileDownloaded(ByteSize size, ContentId cid)
{
WriteCodexEvent(e =>
{
e.FileDownloaded = new FileDownloadedEvent
{
Cid = cid.Id,
ByteSize = size.SizeInBytes
};
});
}
public void OnFileUploading(string uid, ByteSize size)
{
WriteCodexEvent(e =>
{
e.FileUploading = new FileUploadingEvent
{
UniqueId = uid,
ByteSize = size.SizeInBytes
};
});
}
public void OnFileUploaded(string uid, ByteSize size, ContentId cid)
{
WriteCodexEvent(e =>
{
e.FileUploaded = new FileUploadedEvent
{
Cid = cid.Id
UniqueId = uid,
Cid = cid.Id,
ByteSize = size.SizeInBytes
};
});
}

View File

@ -10,7 +10,7 @@
addEvent(e =>
{
e.DialSuccessful = new DialSuccessfulEvent
e.DialSuccessful = new PeerDialSuccessfulEvent
{
TargetPeerId = peerId
};

View File

@ -0,0 +1,20 @@
namespace CodexPlugin.OverwatchSupport.LineConverters
{
public class PeerDroppedLineConverter : ILineConverter
{
public string Interest => "Peer dropped";
public void Process(CodexLogLine line, Action<Action<OverwatchCodexEvent>> addEvent)
{
var peerId = line.Attributes["peerId"];
addEvent(e =>
{
e.PeerDropped = new PeerDroppedEvent
{
DroppedPeerId = peerId
};
});
}
}
}

View File

@ -16,12 +16,15 @@ namespace CodexPlugin.OverwatchSupport
public ScenarioFinishedEvent? ScenarioFinished { get; set; }
public NodeStartingEvent? NodeStarting { get; set; }
public NodeStartedEvent? NodeStarted { get; set; }
public NodeStoppedEvent? NodeStopped { get; set; }
public NodeStoppingEvent? NodeStopping { get; set; }
public BootstrapConfigEvent? BootstrapConfig { get; set; }
public FileUploadingEvent? FileUploading { get; set; }
public FileUploadedEvent? FileUploaded { get; set; }
public FileDownloadingEvent? FileDownloading { get; set; }
public FileDownloadedEvent? FileDownloaded { get; set; }
public BlockReceivedEvent? BlockReceived { get; set; }
public DialSuccessfulEvent? DialSuccessful { get; set; }
public PeerDialSuccessfulEvent? DialSuccessful { get; set; }
public PeerDroppedEvent? PeerDropped { get; set; }
public void Write(DateTime utc, ITranscriptWriter writer)
{
@ -62,9 +65,8 @@ namespace CodexPlugin.OverwatchSupport
}
[Serializable]
public class NodeStoppedEvent
public class NodeStoppingEvent
{
public string Name { get; set; } = string.Empty;
}
[Serializable]
@ -73,10 +75,24 @@ namespace CodexPlugin.OverwatchSupport
public string BootstrapPeerId { get; set; } = string.Empty;
}
[Serializable]
public class FileUploadingEvent
{
public string UniqueId { get; set;} = string.Empty;
public long ByteSize { get; set; }
}
[Serializable]
public class FileDownloadingEvent
{
public string Cid { get; set; } = string.Empty;
}
[Serializable]
public class FileUploadedEvent
{
public ulong ByteSize { get; set; }
public string UniqueId { get; set; } = string.Empty;
public long ByteSize { get; set; }
public string Cid { get; set; } = string.Empty;
}
@ -84,6 +100,7 @@ namespace CodexPlugin.OverwatchSupport
public class FileDownloadedEvent
{
public string Cid { get; set; } = string.Empty;
public long ByteSize { get; set; }
}
#endregion
@ -98,10 +115,16 @@ namespace CodexPlugin.OverwatchSupport
}
[Serializable]
public class DialSuccessfulEvent
public class PeerDialSuccessfulEvent
{
public string TargetPeerId { get; set; } = string.Empty;
}
[Serializable]
public class PeerDroppedEvent
{
public string DroppedPeerId { get; set; } = string.Empty;
}
#endregion
}