private void RemoveMissingNeighbors(object o) { IEnumerable <NeighborEntry> list; lock (tablesLock) { list = NeighborhoodTable.Where(n => n.Hold.CompareTo(TimeSpan.Zero) < 0).ToList(); } foreach (NeighborEntry e in list) { Guid guid = Guid.NewGuid(); lock (tablesLock) { NeighborhoodTable.Remove(e); var top = TopologyTable.FirstOrDefault(t => t.Destination.Equals(e.Address) && t.Neighbor.Equals(e.Address)); if (top != null) { AddTopology(new TopologyEntry(e.Address, e.Address, -1, -1)); } } var neighbors = NeighborhoodTable.Where(n => list.FirstOrDefault(l => l.Address.Equals(n.Address)) == null).ToList(); foreach (var neighbor in neighbors) { var node = Nodes.FirstOrDefault(n => (n as RouterNode).Text.Equals(neighbor.Address)) as RouterNode; var link = Links.FirstOrDefault(l => l.ToNode.Equals(node) || l.FromNode.Equals(node)) as GoLabeledLink; if (node == null || link == null) { continue; } TopologyEntry fastest; lock (tablesLock) { fastest = TopologyTable.Where(t => t.Destination.Equals(e.Address)).OrderBy(t => t.Feasible).FirstOrDefault(); } node.AddTopology(new TopologyEntry(e.Address, Text, fastest == null ? -1 : fastest.Feasible + link.UserFlags, fastest == null ? -1 : fastest.Feasible)); } } }
public void AddTopology(TopologyEntry entry) { /* * if(entry.Feasible == -1) * { * //remove topology * lock(tablesLock) * { * var existing = TopologyTable.FirstOrDefault(t => t.Destination.Equals(entry.Destination) && t.Neighbor.Equals(entry.Neighbor)); * if(existing != null) * { * TopologyTable.Remove(existing); * UpdateRoute(entry); * } * return; * } * } */ if (entry.Destination.Equals(Text)) { return; } if (entry.Feasible != -1) { lock (tablesLock) { var fastest = TopologyTable.Where(t => t.Destination.Equals(entry.Destination))?.OrderBy(t => t.Feasible).FirstOrDefault(); if (fastest != null && entry.Advertised >= fastest.Feasible) { return; } var existing = TopologyTable.Where(t => t.Destination.Equals(entry.Destination) && t.Neighbor.Equals(entry.Neighbor) && t.Feasible == entry.Feasible).FirstOrDefault(); if (existing != null) { return; } TopologyTable.Add(entry); } } else { lock (tablesLock) { var existing = TopologyTable.FirstOrDefault(t => t.Destination.Equals(entry.Destination) && t.Neighbor.Equals(entry.Neighbor)); if (existing != null) { TopologyTable.Remove(existing); } } } UpdateRoute(entry); var neighbors = NeighborhoodTable.Where(n => !n.Address.Equals(entry.Neighbor)).ToList(); foreach (var neighbor in neighbors) { var node = Nodes.FirstOrDefault(n => (n as RouterNode).Text.Equals(neighbor.Address)) as RouterNode; var link = Links.FirstOrDefault(l => l.ToNode.Equals(node) || l.FromNode.Equals(node)) as GoLabeledLink; if (node == null || link == null) { continue; } TopologyEntry fastest; lock (tablesLock) { fastest = TopologyTable.Where(t => t.Destination.Equals(entry.Destination)).OrderBy(t => t.Feasible).FirstOrDefault(); } node.AddTopology(new TopologyEntry(entry.Destination, Text, fastest == null ? -1 : fastest.Feasible + link.UserFlags, fastest.Feasible)); } }