2024-08-06 13:56:42 +00:00
|
|
|
|
using CodexPlugin.OverwatchSupport;
|
|
|
|
|
using OverwatchTranscript;
|
|
|
|
|
|
2024-08-07 09:18:40 +00:00
|
|
|
|
namespace TranscriptAnalysis.Receivers
|
2024-08-06 13:56:42 +00:00
|
|
|
|
{
|
2024-08-07 09:18:40 +00:00
|
|
|
|
public class DuplicateBlocksReceived : BaseReceiver<OverwatchCodexEvent>
|
2024-08-06 13:56:42 +00:00
|
|
|
|
{
|
2024-08-07 09:18:40 +00:00
|
|
|
|
public override string Name => "BlocksReceived";
|
2024-08-06 13:56:42 +00:00
|
|
|
|
|
2024-08-07 09:18:40 +00:00
|
|
|
|
public override void Receive(ActivateEvent<OverwatchCodexEvent> @event)
|
2024-08-06 13:56:42 +00:00
|
|
|
|
{
|
2024-08-07 09:18:40 +00:00
|
|
|
|
if (@event.Payload.BlockReceived != null)
|
|
|
|
|
{
|
|
|
|
|
Handle(@event.Payload, @event.Payload.BlockReceived);
|
|
|
|
|
}
|
2024-08-06 13:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-07 09:18:40 +00:00
|
|
|
|
public override void Finish()
|
2024-08-06 13:56:42 +00:00
|
|
|
|
{
|
|
|
|
|
Log("Number of BlockReceived events seen: " + seen);
|
|
|
|
|
|
|
|
|
|
var totalReceived = peerIdBlockAddrCount.Sum(a => a.Value.Sum(p => p.Value));
|
|
|
|
|
var maxRepeats = peerIdBlockAddrCount.Max(a => a.Value.Max(p => p.Value));
|
2024-08-08 07:39:20 +00:00
|
|
|
|
var occurances = new OccuranceMap();
|
2024-08-06 13:56:42 +00:00
|
|
|
|
|
|
|
|
|
foreach (var peerPair in peerIdBlockAddrCount)
|
|
|
|
|
{
|
2024-08-08 07:39:20 +00:00
|
|
|
|
foreach (var blockCountPair in peerPair.Value)
|
2024-08-06 13:56:42 +00:00
|
|
|
|
{
|
2024-08-08 07:39:20 +00:00
|
|
|
|
occurances.Add(blockCountPair.Value);
|
2024-08-07 09:18:40 +00:00
|
|
|
|
}
|
2024-08-06 13:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float t = totalReceived;
|
2024-08-08 07:39:20 +00:00
|
|
|
|
occurances.PrintContinous((i, count) =>
|
2024-08-06 13:56:42 +00:00
|
|
|
|
{
|
2024-08-08 07:39:20 +00:00
|
|
|
|
float n = count;
|
2024-08-06 13:56:42 +00:00
|
|
|
|
float p = 100.0f * (n / t);
|
2024-08-08 07:39:20 +00:00
|
|
|
|
Log($"Block received {i} times = {count}x ({p}%)");
|
|
|
|
|
});
|
2024-08-06 13:56:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int seen = 0;
|
|
|
|
|
private readonly Dictionary<string, Dictionary<string, int>> peerIdBlockAddrCount = new Dictionary<string, Dictionary<string, int>>();
|
|
|
|
|
|
|
|
|
|
private void Handle(OverwatchCodexEvent payload, BlockReceivedEvent blockReceived)
|
|
|
|
|
{
|
2024-08-14 12:13:00 +00:00
|
|
|
|
var receiverPeerId = GetPeerId(payload.NodeIdentity);
|
2024-08-06 13:56:42 +00:00
|
|
|
|
var blockAddress = blockReceived.BlockAddress;
|
|
|
|
|
seen++;
|
|
|
|
|
|
|
|
|
|
if (!peerIdBlockAddrCount.ContainsKey(receiverPeerId))
|
|
|
|
|
{
|
|
|
|
|
peerIdBlockAddrCount.Add(receiverPeerId, new Dictionary<string, int>());
|
|
|
|
|
}
|
|
|
|
|
var blockAddCount = peerIdBlockAddrCount[receiverPeerId];
|
|
|
|
|
if (!blockAddCount.ContainsKey(blockAddress))
|
|
|
|
|
{
|
|
|
|
|
blockAddCount.Add(blockAddress, 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
blockAddCount[blockAddress]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|