public NodeInformation GetDelta(NodeInformationSynopsis otherSynopsis, ILogger logger) { var result = new NodeInformation { Endpoint = this.Endpoint, NodeVersion = this.NodeVersion }; if (this.NodeVersion < otherSynopsis.NodeVersion) { logger.LogError( new InvalidOperationException(), "Node {0} current known version ({1}) is lower than peer required node version ({2})", Endpoint, NodeVersion, otherSynopsis.NodeVersion); } else if (this.NodeVersion > otherSynopsis.NodeVersion) { result.Properties.Add(this.Properties); } else { foreach (var p in this.Properties) { if (p.Value.Version > otherSynopsis.LastKnownPropertyVersion) { result.Properties.Add(p.Key, p.Value); } } } return(result); }
public void TestGetDeltaFromOldNode() { var n = NodeInformation.CreateSelfNode(endpoint); n.Properties.Add(new Dictionary <string, VersionedProperty> { { "test_key", new VersionedProperty { Version = 5, StringProperty = "test_value" } }, { "test_key2", new VersionedProperty { Version = 9, StringProperty = "test_value2" } } }); var n2 = new NodeInformationSynopsis { Endpoint = endpoint, LastKnownPropertyVersion = 100, NodeVersion = n.NodeVersion - 1 }; var deltaN = n.GetDelta(n2, logger); Assert.Equal(n, deltaN); }