wires up header node identity

This commit is contained in:
Ben 2024-08-14 14:13:00 +02:00
parent 38b987144e
commit b5c8c55c72
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
6 changed files with 42 additions and 15 deletions

View File

@ -1,4 +1,5 @@
using Logging; using CodexPlugin.OverwatchSupport;
using Logging;
using OverwatchTranscript; using OverwatchTranscript;
using TranscriptAnalysis; using TranscriptAnalysis;
@ -31,7 +32,8 @@ public static class Program
CloseReader(reader); CloseReader(reader);
}; };
var receivers = new ReceiverSet(log, reader); var header = reader.GetHeader<OverwatchCodexHeader>("cdx_h");
var receivers = new ReceiverSet(log, reader, header);
receivers.InitAll(); receivers.InitAll();
var processor = new Processor(log, reader); var processor = new Processor(log, reader);

View File

@ -1,4 +1,5 @@
using Logging; using CodexPlugin.OverwatchSupport;
using Logging;
using OverwatchTranscript; using OverwatchTranscript;
using TranscriptAnalysis.Receivers; using TranscriptAnalysis.Receivers;
@ -6,7 +7,7 @@ namespace TranscriptAnalysis
{ {
public interface IEventReceiver public interface IEventReceiver
{ {
void Init(ILog log); void Init(ILog log, OverwatchCodexHeader header);
void Finish(); void Finish();
} }
@ -19,12 +20,14 @@ namespace TranscriptAnalysis
{ {
private readonly ILog log; private readonly ILog log;
private readonly ITranscriptReader reader; private readonly ITranscriptReader reader;
private readonly OverwatchCodexHeader header;
private readonly List<IEventReceiver> receivers = new List<IEventReceiver>(); private readonly List<IEventReceiver> receivers = new List<IEventReceiver>();
public ReceiverSet(ILog log, ITranscriptReader reader) public ReceiverSet(ILog log, ITranscriptReader reader, OverwatchCodexHeader header)
{ {
this.log = log; this.log = log;
this.reader = reader; this.reader = reader;
this.header = header;
} }
public void InitAll() public void InitAll()
@ -50,7 +53,7 @@ namespace TranscriptAnalysis
mux.Add(receiver); mux.Add(receiver);
receivers.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, // We use a mux here because, for each time we call reader.AddEventHandler,

View File

@ -1,4 +1,5 @@
using Logging; using CodexPlugin.OverwatchSupport;
using Logging;
using OverwatchTranscript; using OverwatchTranscript;
namespace TranscriptAnalysis.Receivers namespace TranscriptAnalysis.Receivers
@ -6,14 +7,31 @@ namespace TranscriptAnalysis.Receivers
public abstract class BaseReceiver<T> : IEventReceiver<T> public abstract class BaseReceiver<T> : IEventReceiver<T>
{ {
protected ILog log { get; private set; } = new NullLog(); protected ILog log { get; private set; } = new NullLog();
protected OverwatchCodexHeader Header { get; private set; } = null!;
public abstract string Name { get; } public abstract string Name { get; }
public abstract void Receive(ActivateEvent<T> @event); public abstract void Receive(ActivateEvent<T> @event);
public abstract void Finish(); public abstract void Finish();
public void Init(ILog log) public void Init(ILog log, OverwatchCodexHeader header)
{ {
this.log = new LogPrefixer(log, $"({Name}) "); 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) protected void Log(string msg)

View File

@ -45,7 +45,7 @@ namespace TranscriptAnalysis.Receivers
private void Handle(OverwatchCodexEvent payload, BlockReceivedEvent blockReceived) private void Handle(OverwatchCodexEvent payload, BlockReceivedEvent blockReceived)
{ {
var receiverPeerId = payload.Identity.PeerId; var receiverPeerId = GetPeerId(payload.NodeIdentity);
var blockAddress = blockReceived.BlockAddress; var blockAddress = blockReceived.BlockAddress;
seen++; seen++;

View File

@ -12,12 +12,15 @@ namespace TranscriptAnalysis.Receivers
public override void Receive(ActivateEvent<OverwatchCodexEvent> @event) public override void Receive(ActivateEvent<OverwatchCodexEvent> @event)
{ {
if (!seen.Contains(@event.Payload.Identity.PeerId)) var peerId = GetPeerId(@event.Payload.NodeIdentity);
{ var name = GetName(@event.Payload.NodeIdentity);
seen.Add(@event.Payload.Identity.PeerId);
log.AddStringReplace(@event.Payload.Identity.PeerId, @event.Payload.Name); if (!seen.Contains(peerId))
log.AddStringReplace(CodexUtils.ToShortId(@event.Payload.Identity.PeerId), @event.Payload.Name); {
seen.Add(peerId);
log.AddStringReplace(peerId, name);
log.AddStringReplace(CodexUtils.ToShortId(peerId), name);
} }
} }

View File

@ -53,7 +53,8 @@ namespace TranscriptAnalysis.Receivers
{ {
if (@event.Payload.DialSuccessful != null) 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);
} }
} }