public static Node Create( string selfNodeEndpoint, IEnumerable <string> seedsEndpoint, Func <ILogger <Node> > loggerFactory) { var selfNodeInformation = NodeInformation.CreateSelfNode(selfNodeEndpoint); var seedsNodeInformation = seedsEndpoint .Where(n => n != selfNodeEndpoint) .Select(NodeInformation.CreateSeedNode) .ToArray(); var nodeInformationDictionary = new Dictionary <string, NodeInformation>(StringComparer.InvariantCultureIgnoreCase) { { selfNodeInformation.Endpoint, selfNodeInformation } }; foreach (var n in seedsNodeInformation) { nodeInformationDictionary.Add(n.Endpoint, n); } return(new Node( loggerFactory.Invoke(), selfNodeInformation, nodeInformationDictionary)); }
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 Node( ILogger <Node> logger, NodeInformation selfNodeInformation, IDictionary <string, NodeInformation> nodeInformationDictionary) { this.logger = logger; this.selfNodeInformation = selfNodeInformation; this.nodeInformationDictionary = nodeInformationDictionary; }
public void Update(NodeInformation other, ILogger logger) { using (logger.BeginScope("EndPoint={0}", this.Endpoint)) { if (this.NodeVersion == other.NodeVersion) { foreach (var p in other.Properties) { if (this.Properties.ContainsKey(p.Key)) { if (this.Properties[p.Key].Version < p.Value.Version) { this.Properties[p.Key] = p.Value; logger.LogDebug("Property {0} updated to value {1}", p.Key, p.Value); } else if (this.Properties[p.Key].Version > p.Value.Version) { logger.LogInformation( "Discard incoming node property {0} because our version is higher ({1} > {2})", p.Key, this.Properties[p.Key].Version, p.Value.Version); } else { logger.LogInformation( "Discard incoming node property {0} because the version is same ({1})", p.Key, p.Value.Version); } } else { this.Properties.Add(p.Key, p.Value); logger.LogDebug("Property {0} added to value {1}", p.Key, p.Value); } } } else if (this.NodeVersion < other.NodeVersion) { this.NodeVersion = other.NodeVersion; this.Properties.Clear(); this.Properties.Add(other.Properties); } else { logger.LogInformation( "Discard incoming node information because our node version is higher ({0} > {1})", this.NodeVersion, other.NodeVersion); } } }