From 37611bdc660636a63d399b581417ea379a370a82 Mon Sep 17 00:00:00 2001 From: benbierens Date: Thu, 1 Aug 2024 09:09:30 +0200 Subject: [PATCH] peer dropped and starting/started events for upload and download --- Framework/Utils/ByteSize.cs | 1 - ProjectPlugins/CodexPlugin/CodexNode.cs | 14 +++++-- .../CodexPlugin/CodexStartupConfig.cs | 4 +- .../CodexPlugin/Hooks/CodexHooksFactory.cs | 18 +++++++-- .../CodexPlugin/Hooks/CodexNodeHooks.cs | 10 +++-- .../OverwatchSupport/CodexLogConverter.cs | 1 + .../OverwatchSupport/CodexTranscriptWriter.cs | 39 +++++++++++++++---- .../DialSuccessfulLineConverter.cs | 2 +- .../PeerDroppedLineConverter.cs | 20 ++++++++++ .../OverwatchSupport/ModelExtensions.cs | 35 ++++++++++++++--- 10 files changed, 116 insertions(+), 28 deletions(-) create mode 100644 ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/PeerDroppedLineConverter.cs diff --git a/Framework/Utils/ByteSize.cs b/Framework/Utils/ByteSize.cs index 1184607..9b0f7c8 100644 --- a/Framework/Utils/ByteSize.cs +++ b/Framework/Utils/ByteSize.cs @@ -13,7 +13,6 @@ public long SizeInBytes { get; } - public long ToMB() { return SizeInBytes / (1024 * 1024); diff --git a/ProjectPlugins/CodexPlugin/CodexNode.cs b/ProjectPlugins/CodexPlugin/CodexNode.cs index 4d6cfd6..f8a65b0 100644 --- a/ProjectPlugins/CodexPlugin/CodexNode.cs +++ b/ProjectPlugins/CodexPlugin/CodexNode.cs @@ -136,6 +136,10 @@ namespace CodexPlugin public ContentId UploadFile(TrackedFile file, Action 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 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; } diff --git a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs index 6894911..d6ab162 100644 --- a/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs +++ b/ProjectPlugins/CodexPlugin/CodexStartupConfig.cs @@ -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" diff --git a/ProjectPlugins/CodexPlugin/Hooks/CodexHooksFactory.cs b/ProjectPlugins/CodexPlugin/Hooks/CodexHooksFactory.cs index b29173d..f668057 100644 --- a/ProjectPlugins/CodexPlugin/Hooks/CodexHooksFactory.cs +++ b/ProjectPlugins/CodexPlugin/Hooks/CodexHooksFactory.cs @@ -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) { } diff --git a/ProjectPlugins/CodexPlugin/Hooks/CodexNodeHooks.cs b/ProjectPlugins/CodexPlugin/Hooks/CodexNodeHooks.cs index d16e4f3..9e8e354 100644 --- a/ProjectPlugins/CodexPlugin/Hooks/CodexNodeHooks.cs +++ b/ProjectPlugins/CodexPlugin/Hooks/CodexNodeHooks.cs @@ -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); } } diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs index 1dbdf47..a5d6749 100644 --- a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs @@ -58,6 +58,7 @@ namespace CodexPlugin.OverwatchSupport new BlockReceivedLineConverter(), new BootstrapLineConverter(), new DialSuccessfulLineConverter(), + new PeerDroppedLineConverter() }; public ConversionRunner(ITranscriptWriter writer, string name, string peerId) diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs index 7b4b3fd..4965592 100644 --- a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs @@ -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 }; }); } diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/DialSuccessfulLineConverter.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/DialSuccessfulLineConverter.cs index 3858633..0d9f1a7 100644 --- a/ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/DialSuccessfulLineConverter.cs +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/DialSuccessfulLineConverter.cs @@ -10,7 +10,7 @@ addEvent(e => { - e.DialSuccessful = new DialSuccessfulEvent + e.DialSuccessful = new PeerDialSuccessfulEvent { TargetPeerId = peerId }; diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/PeerDroppedLineConverter.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/PeerDroppedLineConverter.cs new file mode 100644 index 0000000..24b2c7c --- /dev/null +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/LineConverters/PeerDroppedLineConverter.cs @@ -0,0 +1,20 @@ +namespace CodexPlugin.OverwatchSupport.LineConverters +{ + public class PeerDroppedLineConverter : ILineConverter + { + public string Interest => "Peer dropped"; + + public void Process(CodexLogLine line, Action> addEvent) + { + var peerId = line.Attributes["peerId"]; + + addEvent(e => + { + e.PeerDropped = new PeerDroppedEvent + { + DroppedPeerId = peerId + }; + }); + } + } +} diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/ModelExtensions.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/ModelExtensions.cs index 6be3825..5f06a8d 100644 --- a/ProjectPlugins/CodexPlugin/OverwatchSupport/ModelExtensions.cs +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/ModelExtensions.cs @@ -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 }