Esempio n. 1
0
 private void AddToTable(IProtocolNode node, int count)
 {
     node?.Connections.ForEach(c =>
     {
         if (!RoutingTable.Any(t => t.Item1.Contains(c)))
         {
             RoutingTable.Add(new Tuple <string, string, int>(c, node.Id, count));
         }
     });
 }
Esempio n. 2
0
        public bool FindRouteTo(string id, List <IProtocolNode> network, int ttl = 10)
        {
            if (RoutingTable.Any(t => t.Item1.Contains(id)))
            {
                return(true);
            }

            bool routeFound = false;

            for (int i = 1; i <= ttl; i++)
            {
                if (routeFound)
                {
                    break;
                }
                var before = RoutingTable.Count;
                var table  = new List <Tuple <string, string, int> >(GetRoutingTable());

                foreach (var t in table)
                {
                    if (routeFound)
                    {
                        break;
                    }
                    if (t.Item3.Equals(i))
                    {
                        var node = network.Find(n => n.Id.Equals(t.Item1));
                        List <Tuple <string, string, int> > tempTable = new List <Tuple <string, string, int> >(node.GetRoutingTable());
                        if (tempTable.Any(r => r.Item1.Contains(id)))
                        {
                            routeFound = true;
                        }
                        else
                        {
                            AddNodeRt(node, i + 1);
                        }
                    }
                }

                if (before == RoutingTable.Count)
                {
                    return(routeFound);
                }
            }

            return(routeFound);
        }
Esempio n. 3
0
        private void AddNodeRt(IProtocolNode node, int count)
        {
            if (node == null)
            {
                return;
            }

            List <Tuple <string, string, int> > tempTable = new List <Tuple <string, string, int> >(node.GetRoutingTable());

            if (tempTable.Count < 1)
            {
                return;
            }
            tempTable.ForEach(c =>
            {
                if (!RoutingTable.Any(t => t.Item1.Contains(c.Item1)))
                {
                    RoutingTable.Add(new Tuple <string, string, int>(c.Item1, node.Id, count));
                }
            });
        }