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 TranscriptAnalysis;
@ -31,7 +32,8 @@ public static class Program
CloseReader(reader);
};
var receivers = new ReceiverSet(log, reader);
var header = reader.GetHeader<OverwatchCodexHeader>("cdx_h");
var receivers = new ReceiverSet(log, reader, header);
receivers.InitAll();
var processor = new Processor(log, reader);

View File

@ -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<IEventReceiver> receivers = new List<IEventReceiver>();
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,

View File

@ -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<T> : IEventReceiver<T>
{
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<T> @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)

View File

@ -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++;

View File

@ -12,12 +12,15 @@ namespace TranscriptAnalysis.Receivers
public override void Receive(ActivateEvent<OverwatchCodexEvent> @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);
}
}

View File

@ -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);
}
}