Exemple #1
0
 public void FireNodeUpdated()
 {
     if (NodeUpdated != null)
     {
         NodeUpdated.Invoke(this);
     }
 }
Exemple #2
0
        private void UpdateNodes(IPAddress address, DateTime timestamp, Stream stream)
        {
            // Read the source's state and generation
            var sourceState      = stream.ReadState();
            var sourceGeneration = stream.ReadGeneration();

            // Read the source's version of our state and generation
            var localState      = stream.ReadState();
            var localGeneration = stream.ReadGeneration();

            // If the source has outdated information about the local node, or
            // the source thinks the local node is no longer alive, update the source
            if (localNode.IsLaterGeneration(localGeneration) ||
                (localState != NodeState.Alive && localGeneration == localNode.Generation))
            {
                // FIXME what is happening here?
                localNode.Generation = (byte)(localGeneration + 1);
            }

            // Handle the source node, then the rest of the nodes in the stream
            Node remoteNode = new Node {
                Address    = address,
                State      = sourceState,
                Generation = sourceGeneration
            };

            while (remoteNode != null)
            {
                lock (nodes) {
                    // Process this remote node if:
                    //   1. we are aware of it, and
                    //   2. the incoming information is newer than the information we have, or
                    //   3. we have the same information, but the state has changed
                    if (nodes.TryGetValue(remoteNode.Address, out var node) &&
                        (node.IsLaterGeneration(remoteNode.Generation) ||
                         (node.Generation == remoteNode.Generation && node.IsSupersededState(remoteNode.State))))
                    {
                        // Stop escalation
                        if (node.State == NodeState.Alive && remoteNode.IsLaterGeneration(node.Generation))
                        {
                            // Remove any pending ACK
                            acks.TryRemove(node.Address, out var _);
                        }

                        // Update and notify
                        node.State      = remoteNode.State;
                        node.Generation = remoteNode.Generation;
                        NodeUpdated?.Invoke(node);
                    }
                    else if (node == null)
                    {
                        node = remoteNode;
                        nodes.Add(node.Address, node);
                        NodeUpdated?.Invoke(node);
                    }

                    if (node.State != NodeState.Alive)
                    {
                        acks.TryAdd(node.Address, DateTime.UtcNow);
                    }
                }

                // Process next node in the stream
                remoteNode = Node.ReadFrom(stream);
            }
        }
Exemple #3
0
 private void HandleDataChanged(object sender, DataTreeNode e)
 {
     NodeUpdated?.Invoke(this, new TreeViewEventArgs(e));
 }
Exemple #4
0
 private void OnNodeUpdated(FileNode node)
 {
     NodeUpdated?.Invoke(node);
 }
Exemple #5
0
 /// <summary>
 /// <inheritdoc />
 /// </summary>
 public void OnNodeUpdated(NodeSetup nodeSetup)
 {
     NodeUpdated?.Invoke(nodeSetup);
 }