diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs index 19a100d..860180e 100644 --- a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexLogConverter.cs @@ -8,11 +8,13 @@ namespace CodexPlugin.OverwatchSupport public class CodexLogConverter { private readonly ITranscriptWriter writer; + private readonly CodexTranscriptWriterConfig config; private readonly IdentityMap identityMap; - public CodexLogConverter(ITranscriptWriter writer, IdentityMap identityMap) + public CodexLogConverter(ITranscriptWriter writer, CodexTranscriptWriterConfig config, IdentityMap identityMap) { this.writer = writer; + this.config = config; this.identityMap = identityMap; } @@ -20,7 +22,7 @@ namespace CodexPlugin.OverwatchSupport { var name = DetermineName(log); var identityIndex = identityMap.GetIndex(name); - var runner = new ConversionRunner(writer, identityMap, log.ContainerName, identityIndex); + var runner = new ConversionRunner(writer, config, identityMap, identityIndex); runner.Run(log); } @@ -37,22 +39,27 @@ namespace CodexPlugin.OverwatchSupport { private readonly ITranscriptWriter writer; private readonly IdentityMap nameIdMap; - private readonly string name; private readonly int nodeIdentityIndex; - private readonly ILineConverter[] converters = new ILineConverter[] - { - new BlockReceivedLineConverter(), - new BootstrapLineConverter(), - new DialSuccessfulLineConverter(), - new PeerDroppedLineConverter() - }; + private readonly ILineConverter[] converters; - public ConversionRunner(ITranscriptWriter writer, IdentityMap nameIdMap, string name, int nodeIdentityIndex) + public ConversionRunner(ITranscriptWriter writer, CodexTranscriptWriterConfig config, IdentityMap nameIdMap, int nodeIdentityIndex) { - this.name = name; this.nodeIdentityIndex = nodeIdentityIndex; this.writer = writer; this.nameIdMap = nameIdMap; + + converters = CreateConverters(config).ToArray(); + } + + private IEnumerable CreateConverters(CodexTranscriptWriterConfig config) + { + if (config.IncludeBlockReceivedEvents) + { + yield return new BlockReceivedLineConverter(); + } + yield return new BootstrapLineConverter(); + yield return new DialSuccessfulLineConverter(); + yield return new PeerDroppedLineConverter(); } public void Run(IDownloadedLog log) diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs index f836fa3..1bfc7cf 100644 --- a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs @@ -10,16 +10,18 @@ namespace CodexPlugin.OverwatchSupport { private const string CodexHeaderKey = "cdx_h"; private readonly ILog log; + private readonly CodexTranscriptWriterConfig config; private readonly ITranscriptWriter writer; private readonly CodexLogConverter converter; private readonly IdentityMap identityMap = new IdentityMap(); private readonly KademliaPositionFinder positionFinder = new KademliaPositionFinder(); - public CodexTranscriptWriter(ILog log, ITranscriptWriter transcriptWriter) + public CodexTranscriptWriter(ILog log, CodexTranscriptWriterConfig config, ITranscriptWriter transcriptWriter) { this.log = log; + this.config = config; writer = transcriptWriter; - converter = new CodexLogConverter(writer, identityMap); + converter = new CodexLogConverter(writer, config, identityMap); } public void Finalize(string outputFilepath) diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriterConfig.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriterConfig.cs new file mode 100644 index 0000000..247494c --- /dev/null +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriterConfig.cs @@ -0,0 +1,12 @@ +namespace CodexPlugin.OverwatchSupport +{ + public class CodexTranscriptWriterConfig + { + public CodexTranscriptWriterConfig(bool includeBlockReceivedEvents) + { + IncludeBlockReceivedEvents = includeBlockReceivedEvents; + } + + public bool IncludeBlockReceivedEvents { get; } + } +} diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/IdentityMap.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/IdentityMap.cs index d6ca184..d272e9c 100644 --- a/ProjectPlugins/CodexPlugin/OverwatchSupport/IdentityMap.cs +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/IdentityMap.cs @@ -27,7 +27,7 @@ nodes.Add(identity); shortToLong.Add(CodexUtils.ToShortId(identity.PeerId), identity.PeerId); - shortToLong.Add(CodexUtils.ToShortId(identity.NodeId), identity.NodeId); + shortToLong.Add(CodexUtils.ToNodeIdShortId(identity.NodeId), identity.NodeId); } public CodexNodeIdentity[] Get() diff --git a/Tests/CodexTests/BasicTests/MarketplaceTests.cs b/Tests/CodexTests/BasicTests/MarketplaceTests.cs index e4d51b1..596476e 100644 --- a/Tests/CodexTests/BasicTests/MarketplaceTests.cs +++ b/Tests/CodexTests/BasicTests/MarketplaceTests.cs @@ -13,6 +13,7 @@ namespace CodexTests.BasicTests { [Test] [Combinatorial] + [CreateTranscript(nameof(MarketplaceTests), includeBlockReceivedEvents: false)] public void MarketplaceExample( [Values(64)] int numBlocks, [Values(0)] int plusSizeKb, diff --git a/Tests/CodexTests/CodexDistTest.cs b/Tests/CodexTests/CodexDistTest.cs index 876e035..b17a37a 100644 --- a/Tests/CodexTests/CodexDistTest.cs +++ b/Tests/CodexTests/CodexDistTest.cs @@ -136,10 +136,15 @@ namespace CodexTests private void SetupTranscript(TestLifecycle lifecycle) { - if (GetTranscriptAttributeOfCurrentTest() == null) return; + var attr = GetTranscriptAttributeOfCurrentTest(); + if (attr == null) return; + + var config = new CodexTranscriptWriterConfig( + attr.IncludeBlockReceivedEvents + ); var log = new LogPrefixer(lifecycle.Log, "(Transcript) "); - var writer = new CodexTranscriptWriter(log, Transcript.NewWriter(log)); + var writer = new CodexTranscriptWriter(log, config, Transcript.NewWriter(log)); Ci.SetCodexHooksProvider(writer); writers.Add(lifecycle, writer); } @@ -190,11 +195,13 @@ namespace CodexTests [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class CreateTranscriptAttribute : PropertyAttribute { - public CreateTranscriptAttribute(string outputFilename) + public CreateTranscriptAttribute(string outputFilename, bool includeBlockReceivedEvents = true) { OutputFilename = outputFilename; + IncludeBlockReceivedEvents = includeBlockReceivedEvents; } public string OutputFilename { get; } + public bool IncludeBlockReceivedEvents { get; } } }