/// <summary>Returns a list of missing nodes, while crawling the simulation. /// This is an example of a PassiveTask.</summary> public List <AHAddress> FindMissing(bool log) { if (log) { Console.WriteLine("Checking ring..."); } Dictionary <AHAddress, bool> found = new Dictionary <AHAddress, bool>(); if (Nodes.Count == 0) { return(new List <AHAddress>(0)); } Address start_addr = Nodes.Keys[0]; Address curr_addr = start_addr; while (found.Count < Nodes.Count) { found[curr_addr as AHAddress] = true; Node node = Nodes[curr_addr].Node; ConnectionTable con_table = node.ConnectionTable; Connection con = null; try { con = con_table.GetLeftStructuredNeighborOf((AHAddress)curr_addr); } catch { if (log) { Console.WriteLine("Found no connection."); } break; } if (log) { Console.WriteLine("Hop {2}\t Address {0}\n\t Connection to left {1}\n", curr_addr, con, found.Count); } Address next_addr = con.Address; Connection lc = null; try { Node tnode = Nodes[next_addr].Node; lc = tnode.ConnectionTable.GetRightStructuredNeighborOf((AHAddress)next_addr); } catch {} if ((lc == null) || !curr_addr.Equals(lc.Address)) { if (log) { if (lc != null) { Console.WriteLine(curr_addr + " != " + lc.Address); } Console.WriteLine("Right had edge, but left has no record of it!\n{0} != {1}", con, lc); } break; } curr_addr = next_addr; if (curr_addr.Equals(start_addr)) { break; } } List <AHAddress> missing = new List <AHAddress>(); if (found.Count == Nodes.Count) { if (log) { Console.WriteLine("Ring properly formed!"); } } else { foreach (AHAddress addr in Nodes.Keys) { if (!found.ContainsKey(addr)) { missing.Add(addr); } } } if (found.Count < CurrentNetworkSize) { // A node must be registered, but uncreated missing.Add(default(AHAddress)); } return(missing); }
// Checks the ring for completeness public bool CheckAllConnections() { Console.WriteLine("Checking ring..."); Address start_addr = (Address)nodes.GetKeyList()[0]; Address curr_addr = start_addr; for (int i = 0; i < network_size; i++) { Node node = (Node)nodes[curr_addr]; ConnectionTable con_table = node.ConnectionTable; Connection con = con_table.GetLeftStructuredNeighborOf((AHAddress)curr_addr); Console.WriteLine("Hop {2}\t Address {0}\n\t Connection to left {1}\n", curr_addr, con, i); if (con == null) { Console.WriteLine("Found disconnection at position {0}.", i); return(false); } Address next_addr = con.Address; if (next_addr == null) { Console.WriteLine("Found disconnection at position {0}.", i); return(false); } con = null; try { con = ((Node)nodes[next_addr]).ConnectionTable.GetRightStructuredNeighborOf((AHAddress)next_addr); } catch {} if (con == null) { Console.WriteLine("Found disconnection at position {0}.", i); return(false); } Address left_addr = con.Address; if (left_addr == null) { Console.WriteLine("Found disconnection."); } if (!curr_addr.Equals(left_addr)) { Console.WriteLine(curr_addr + " != " + left_addr); Console.WriteLine("Right had edge, but left has no record of it at {0}!", i); return(false); } else if (next_addr.Equals(start_addr) && i != network_size - 1) { Console.WriteLine("Completed circle too early. Only " + (i + 1) + " nodes in the ring."); return(false); } curr_addr = next_addr; } if (start_addr.Equals(curr_addr)) { Console.WriteLine("Ring properly formed!"); return(true); } return(false); }
/** * <summary>This is called whenever there is a disconnect or a connect, the * idea is to determine if there is a new left or right node, if there is and * here is a pre-existing transfer, we must interupt it, and start a new * transfer.</summary> * <remarks>The possible scenarios where this would be active: * - no change on left * - new left node with no previous node (from disc or new node) * - left disconnect and new left ready * - left disconnect and no one ready * - no change on right * - new right node with no previous node (from disc or new node) * - right disconnect and new right ready * - right disconnect and no one ready * </remarks> * <param name="o">Unimportant</param> * <param name="eargs">Contains the ConnectionEventArgs, which lets us know * if this was a Structured Connection change and if it is, we should check * the state of the system to see if we have a new left or right neighbor. * </param> */ protected void ConnectionHandler(object o, EventArgs eargs) { if (!_online) { return; } ConnectionEventArgs cargs = eargs as ConnectionEventArgs; Connection old_con = cargs.Connection; //first make sure that it is a new StructuredConnection if (old_con.MainType != ConnectionType.Structured) { return; } lock (_transfer_sync) { if (!_online) { return; } ConnectionTable tab = _node.ConnectionTable; Connection lc = null, rc = null; try { lc = tab.GetLeftStructuredNeighborOf((AHAddress)_node.Address); } catch (Exception) {} try { rc = tab.GetRightStructuredNeighborOf((AHAddress)_node.Address); } catch (Exception) {} if (lc != null) { if (lc.Address != _left_addr) { if (_left_transfer_state != null) { _left_transfer_state.Interrupt(); _left_transfer_state = null; } _left_addr = lc.Address; if (Count > 0) { _left_transfer_state = new TransferState(lc, this); } } } else if (_left_addr != null) { if (_left_transfer_state != null) { _left_transfer_state.Interrupt(); _left_transfer_state = null; } _left_addr = null; } if (rc != null) { if (rc.Address != _right_addr) { if (_right_transfer_state != null) { _right_transfer_state.Interrupt(); _right_transfer_state = null; } _right_addr = rc.Address; if (Count > 0) { _right_transfer_state = new TransferState(rc, this); } } } else if (_right_addr != null) { if (_right_transfer_state != null) { _right_transfer_state.Interrupt(); _right_transfer_state = null; } _right_addr = null; } } }
public List <AHAddress> FindMissing(bool log) { if (log) { Console.WriteLine("Checking ring..."); } Dictionary <AHAddress, bool> found = new Dictionary <AHAddress, bool>(); Address start_addr = (Address)Nodes.GetKeyList()[0]; Address curr_addr = start_addr; int count = 0; while (count < Nodes.Count) { found[curr_addr as AHAddress] = true; Node node = ((NodeMapping)Nodes[curr_addr]).Node; ConnectionTable con_table = node.ConnectionTable; Connection con = null; try { con = con_table.GetLeftStructuredNeighborOf((AHAddress)curr_addr); } catch { if (log) { Console.WriteLine("Found no connection."); } break; } if (log) { Console.WriteLine("Hop {2}\t Address {0}\n\t Connection to left {1}\n", curr_addr, con, count); } Address next_addr = con.Address; Connection lc = null; try { Node tnode = ((NodeMapping)Nodes[next_addr]).Node; lc = tnode.ConnectionTable.GetRightStructuredNeighborOf((AHAddress)next_addr); } catch {} if ((lc == null) || !curr_addr.Equals(lc.Address)) { if (log) { if (lc != null) { Console.WriteLine(curr_addr + " != " + lc.Address); } Console.WriteLine("Right had edge, but left has no record of it!\n{0} != {1}", con, lc); } break; } curr_addr = next_addr; count++; if (curr_addr.Equals(start_addr)) { break; } } List <AHAddress> missing = new List <AHAddress>(); if (count == Nodes.Count) { if (log) { Console.WriteLine("Ring properly formed!"); } } else { ICollection keys = Nodes.Keys; foreach (AHAddress addr in keys) { if (!found.ContainsKey(addr)) { missing.Add(addr); } } } return(missing); }