private void HandleAlive(IPEndPoint remoteEndPoint, AliveMessage message) { TrackedGossipNode node; GossipNodeState oldState; lock (_lock) { if (!_nodes.TryGetValue(message.Name, out node)) { node = new TrackedGossipNode(message.Name, message.IPEndPoint, message.Metadata) { Incarnation = int.MinValue, State = GossipNodeState.Dead, UpdatedAtUtc = DateTime.MinValue }; if (_nodes.Count > 0) { int randomIndex = _random.Next(0, _nodes.Count - 1); var temp = _nodes[randomIndex]; _nodes[randomIndex] = node; _nodes.Add(temp); } else { _nodes.Add(node); } } if (!node.IPEndPoint.Equals(message.IPEndPoint)) { _configuration.Logger.Error("Conflicting endpoints for {Name}. Mine: {MyEndPoint} Theirs: {TheirEndPoint}", node.Name, node.IPEndPoint, message.IPEndPoint); return; } if (node.Incarnation >= message.Incarnation) { _configuration.Logger.Verbose("Received old incarnation alive request for {Name}. Mine: {MyIncarnation} Theirs: {TheirIncarnation}", node.Name, node.Incarnation, message.Incarnation); return; } oldState = node.State; node.State = GossipNodeState.Alive; node.Incarnation = message.Incarnation; node.UpdatedAtUtc = DateTime.UtcNow; } _messagePump.Broadcast(message, null); if (oldState == GossipNodeState.Dead) { if (NodeJoined != null) { NodeJoined(node); } } }