diff --git a/Tools/TranscriptAnalysis/Program.cs b/Tools/TranscriptAnalysis/Program.cs index 2759c50..7f67aef 100644 --- a/Tools/TranscriptAnalysis/Program.cs +++ b/Tools/TranscriptAnalysis/Program.cs @@ -1,4 +1,5 @@ -using Logging; +using CodexPlugin.OverwatchSupport; +using Logging; using OverwatchTranscript; using TranscriptAnalysis; @@ -31,7 +32,8 @@ public static class Program CloseReader(reader); }; - var receivers = new ReceiverSet(log, reader); + var header = reader.GetHeader("cdx_h"); + var receivers = new ReceiverSet(log, reader, header); receivers.InitAll(); var processor = new Processor(log, reader); diff --git a/Tools/TranscriptAnalysis/ReceiverSet.cs b/Tools/TranscriptAnalysis/ReceiverSet.cs index 036ccda..bdc6c3f 100644 --- a/Tools/TranscriptAnalysis/ReceiverSet.cs +++ b/Tools/TranscriptAnalysis/ReceiverSet.cs @@ -1,4 +1,5 @@ -using Logging; +using CodexPlugin.OverwatchSupport; +using Logging; using OverwatchTranscript; using TranscriptAnalysis.Receivers; @@ -6,7 +7,7 @@ namespace TranscriptAnalysis { public interface IEventReceiver { - void Init(ILog log); + void Init(ILog log, OverwatchCodexHeader header); void Finish(); } @@ -19,12 +20,14 @@ namespace TranscriptAnalysis { private readonly ILog log; private readonly ITranscriptReader reader; + private readonly OverwatchCodexHeader header; private readonly List receivers = new List(); - public ReceiverSet(ILog log, ITranscriptReader reader) + public ReceiverSet(ILog log, ITranscriptReader reader, OverwatchCodexHeader header) { this.log = log; this.reader = reader; + this.header = header; } public void InitAll() @@ -50,7 +53,7 @@ namespace TranscriptAnalysis mux.Add(receiver); receivers.Add(receiver); - receiver.Init(log); + receiver.Init(log, header); } // We use a mux here because, for each time we call reader.AddEventHandler, diff --git a/Tools/TranscriptAnalysis/Receivers/BaseReceiver.cs b/Tools/TranscriptAnalysis/Receivers/BaseReceiver.cs index 5a0e4ba..17e02d7 100644 --- a/Tools/TranscriptAnalysis/Receivers/BaseReceiver.cs +++ b/Tools/TranscriptAnalysis/Receivers/BaseReceiver.cs @@ -1,4 +1,5 @@ -using Logging; +using CodexPlugin.OverwatchSupport; +using Logging; using OverwatchTranscript; namespace TranscriptAnalysis.Receivers @@ -6,14 +7,31 @@ namespace TranscriptAnalysis.Receivers public abstract class BaseReceiver : IEventReceiver { protected ILog log { get; private set; } = new NullLog(); + protected OverwatchCodexHeader Header { get; private set; } = null!; public abstract string Name { get; } public abstract void Receive(ActivateEvent @event); public abstract void Finish(); - public void Init(ILog log) + public void Init(ILog log, OverwatchCodexHeader header) { this.log = new LogPrefixer(log, $"({Name}) "); + Header = header; + } + + protected string GetPeerId(int nodeIndex) + { + return GetIdentity(nodeIndex).PeerId; + } + + protected string GetName(int nodeIndex) + { + return GetIdentity(nodeIndex).Name; + } + + protected CodexNodeIdentity GetIdentity(int nodeIndex) + { + return Header.Nodes[nodeIndex]; } protected void Log(string msg) diff --git a/Tools/TranscriptAnalysis/Receivers/DuplicateBlocksReceived.cs b/Tools/TranscriptAnalysis/Receivers/DuplicateBlocksReceived.cs index a8229e5..6eeb38e 100644 --- a/Tools/TranscriptAnalysis/Receivers/DuplicateBlocksReceived.cs +++ b/Tools/TranscriptAnalysis/Receivers/DuplicateBlocksReceived.cs @@ -45,7 +45,7 @@ namespace TranscriptAnalysis.Receivers private void Handle(OverwatchCodexEvent payload, BlockReceivedEvent blockReceived) { - var receiverPeerId = payload.Identity.PeerId; + var receiverPeerId = GetPeerId(payload.NodeIdentity); var blockAddress = blockReceived.BlockAddress; seen++; diff --git a/Tools/TranscriptAnalysis/Receivers/LogReplaceReceiver.cs b/Tools/TranscriptAnalysis/Receivers/LogReplaceReceiver.cs index 8f0a6bd..caddc60 100644 --- a/Tools/TranscriptAnalysis/Receivers/LogReplaceReceiver.cs +++ b/Tools/TranscriptAnalysis/Receivers/LogReplaceReceiver.cs @@ -12,12 +12,15 @@ namespace TranscriptAnalysis.Receivers public override void Receive(ActivateEvent @event) { - if (!seen.Contains(@event.Payload.Identity.PeerId)) - { - seen.Add(@event.Payload.Identity.PeerId); + var peerId = GetPeerId(@event.Payload.NodeIdentity); + var name = GetName(@event.Payload.NodeIdentity); - log.AddStringReplace(@event.Payload.Identity.PeerId, @event.Payload.Name); - log.AddStringReplace(CodexUtils.ToShortId(@event.Payload.Identity.PeerId), @event.Payload.Name); + if (!seen.Contains(peerId)) + { + seen.Add(peerId); + + log.AddStringReplace(peerId, name); + log.AddStringReplace(CodexUtils.ToShortId(peerId), name); } } diff --git a/Tools/TranscriptAnalysis/Receivers/NodesDegree.cs b/Tools/TranscriptAnalysis/Receivers/NodesDegree.cs index 0f89eb5..1677fdf 100644 --- a/Tools/TranscriptAnalysis/Receivers/NodesDegree.cs +++ b/Tools/TranscriptAnalysis/Receivers/NodesDegree.cs @@ -53,7 +53,8 @@ namespace TranscriptAnalysis.Receivers { if (@event.Payload.DialSuccessful != null) { - AddDial(@event.Payload.Identity.PeerId, @event.Payload.DialSuccessful.TargetPeerId); + var peerId = GetPeerId(@event.Payload.NodeIdentity); + AddDial(peerId, @event.Payload.DialSuccessful.TargetPeerId); } }