Example #1
0
    public static void Main(string []args) {
      if (args.Length < 1) {
	Console.WriteLine("please specify the number edge protocol."); 
        Environment.Exit(0);
      }
      if (args.Length < 2) {
        Console.WriteLine("please specify the number of p2p nodes."); 
        Environment.Exit(0);
      }
      if (args.Length < 3) {
        Console.WriteLine("please specify the number of missing edges."); 
        Environment.Exit(0);
      }
      string proto = "function";
      try {
	proto = args[0].Trim();
      } catch(Exception) {}

      bool tunnel = false;
      int base_port = 54000;
      int network_size = Int32.Parse(args[1]);
      int missing_count = Int32.Parse(args[2]);
      try {
	tunnel = args[3].Trim().Equals("tunnel");
      } catch (Exception) {}

      Console.WriteLine("use tunnel edges: {0}", tunnel);

      Random rand = new Random();

      ArrayList missing_edges = new ArrayList();
      for (int i = 0; i < missing_count; i++) {
	int idx = -1;
	int left, right;
	do {
	  idx = rand.Next(0, network_size);
	  left = (idx + 1)%network_size;
	  if (idx == 0) {
	    right = network_size - 1;
	  } else {
	    right = idx - 1;
	  }
	} while (missing_edges.Contains(idx));// ||
	//missing_edges.Contains(left) ||
	//missing_edges.Contains(right));
	
	Console.WriteLine("Will drop a left edge on idx {0}: ", idx);
	missing_edges.Add(idx);
      }
      
      //
      // Sort missing edges.
      //
      missing_edges.Sort();
      SortedList dist = new SortedList();
      //
      // Compute the average distance between missing edges. 
      //
      if (missing_count > 1) {
	for (int i = 0; i < missing_count; i++) {
	  int idx = (int) missing_edges[i];
	  int idx_next;
	  int d;
	  if (i == missing_count - 1) {
	    idx_next = (int) missing_edges[0];
	    d = (network_size - 1) - idx + idx_next;
	  } else {
	    idx_next = (int) missing_edges[i+1];
	    d = idx_next - idx - 1;
	  }
	  if (!dist.Contains(d)) {
	    dist[d] = 0;
	  } else {
	    int c = (int) dist[d];
	    dist[d] = c + 1;
	  }
	}
      }
      double sum = 0.0;
      int num = 0;
      Console.WriteLine("distribution of missing edges separation");
      foreach(DictionaryEntry de in dist) {
	int k = (int) de.Key;
	int c = (int) de.Value;
	Console.WriteLine("{0} {1}", k, c);
	sum = sum + k*c;
	num = num + c;
      }

      Console.WriteLine("average separation: {0}", (double) sum/num);
      string brunet_namespace = "testing";
      Console.WriteLine("Initializing...");

      ArrayList RemoteTA = new ArrayList();
      for(int i = 0; i < network_size; i++) {
	if (proto.Equals("udp")) {
	  RemoteTA.Add(TransportAddressFactory.CreateInstance("brunet.udp://localhost:" + (base_port + i)));
	} else if (proto.Equals("function")) { 
	  RemoteTA.Add(TransportAddressFactory.CreateInstance("brunet.function://localhost:" + (base_port + i)));
	}
      }

      for(int i = 0; i < network_size; i++) {
        AHAddress address = new AHAddress(new RNGCryptoServiceProvider());
        Node node = new StructuredNode(address, brunet_namespace);
        _sorted_node_list.Add((Address) address, node);
	_node_list.Add(node);
	RouteTestHandler test_handler = new RouteTestHandler();
	node.GetTypeSource(new PType(routing_test)).Subscribe(test_handler, address.ToMemBlock());
	RpcManager rpc_man = node.Rpc;
	rpc_man.AddHandler("rpc_routing_test", new  RpcRoutingTestHandler(node));
      }

      for (int i = 0; i < network_size; i++) {
	Node node = (Node) _sorted_node_list.GetByIndex(i);
	Console.WriteLine("Configuring node: {0} ", node.Address);
	TAAuthorizer ta_auth = null;
	if (missing_edges.Contains(i)) {
	  int remote_port;
	  if (i == network_size - 1) {
	    remote_port = base_port;
	  } else {
	    remote_port = base_port + i + 1;
	  }

	  PortTAAuthorizer port_auth = new PortTAAuthorizer(remote_port);
	  Console.WriteLine("Adding a port TA authorizer at: {0} for remote port: {1}", base_port + i, remote_port);
	  ArrayList arr_tas = new ArrayList();
	  arr_tas.Add(port_auth);
	  arr_tas.Add(new ConstantAuthorizer(TAAuthorizer.Decision.Allow));
	  ta_auth = new SeriesTAAuthorizer(arr_tas);
	}
	
	if (proto.Equals("udp")) { 
	  node.AddEdgeListener(new UdpEdgeListener(base_port + i, null, ta_auth));
	} else if(proto.Equals("function")) {
	  node.AddEdgeListener(new FunctionEdgeListener(base_port + i, -1.00, ta_auth));
	}
	
	if (tunnel) {
	  Console.WriteLine("Adding a tunnel edge listener");
	  node.AddEdgeListener(new Tunnel.TunnelEdgeListener(node));
	}
	_node_to_port[node] = base_port + i;
        node.RemoteTAs = RemoteTA;	
      }

      //start nodes one by one.
      for (int i  = 0; i < network_size; i++) {
	Node node = (Node) _node_list[i];
	Console.WriteLine("Starting node: {0}, {1}", i, node.Address);
        node.Connect();
	Console.WriteLine("Going to sleep for 2 seconds.");
        System.Threading.Thread.Sleep(2000);
      }

      //wait for 300000 more seconds
      Console.WriteLine("Going to sleep for 300000 seconds.");
      System.Threading.Thread.Sleep(300000);
      bool complete = CheckStatus();

      int count = 0;
      //
      // Send a large number of packets as exact packets to random destinations
      // and make sure exact routing is perfect.
      //
      
      for (int i = 0; i < network_size; i++) {
	for (int j = 0; j < network_size; j++) {
	  
	  int src_idx = i;
	  int dest_idx = j;
	  Node src_node = (Node) _sorted_node_list.GetByIndex(src_idx);
	  Node dest_node = (Node) _sorted_node_list.GetByIndex(dest_idx);
	  //Console.WriteLine("{0} -> {1}", src_idx, dest_idx);
	  Address dest_address = (Address) dest_node.Address;
	  ISender s = new AHExactSender(src_node, dest_address);
	  MemBlock p = dest_address.ToMemBlock();
	  s.Send(new CopyList(new PType(routing_test), p));
	  _sent++;
	  //System.Threading.Thread.Sleep(10);
	  s.Send(new CopyList(new PType(routing_test), p));
	  _sent++;
	  //System.Threading.Thread.Sleep(10);
	}
      }
      //wait for 10 more seconds
      Console.WriteLine("Going to sleep for 10 seconds.");
      System.Threading.Thread.Sleep(10000);      
      Console.WriteLine("Final statistics");
      lock(_class_lock) {
	Console.WriteLine("Sent: {0}, Received: {1}, Wrongly routed: {2}", 
			  _sent, _received, _wrongly_routed);
      }

      int missing_rpcs = 0;
      int correct_rpcs = 0;
      int incorrect_rpcs = 0;
      Hashtable queue_to_address = new Hashtable();
      for (int i = 0; i < network_size; i++) {
	for (int j = 0; j < network_size; j++) {
	  
	  int src_idx = i;
	  int dest_idx = j;
	  Node src_node = (Node) _sorted_node_list.GetByIndex(src_idx);
	  Node dest_node = (Node) _sorted_node_list.GetByIndex(dest_idx);
	  //Console.WriteLine("{0} -> {1}", src_idx, dest_idx);
	  Address dest_address = (Address) dest_node.Address;
	  ISender s = new AHExactSender(src_node, dest_address);
	  RpcManager rpc_man = src_node.Rpc;
	  Channel q = new Channel();
	  lock (_class_lock) {
	    queue_to_address[q] = dest_address;
	  }
	  q.CloseAfterEnqueue();
	  q.CloseEvent += delegate(object o, EventArgs cargs) {
	    lock(_class_lock) {
	      Channel qu = (Channel) o;
	      if (qu.Count == 0) {
		missing_rpcs++;
	      }
	      queue_to_address.Remove(qu);
	    }
	  };
	  q.EnqueueEvent += delegate(object o, EventArgs cargs) {
	    lock(_class_lock) {
	      Channel qu = (Channel) o;
	      RpcResult rpc_reply = (RpcResult) qu.Peek();
	      byte []result = (byte[]) rpc_reply.Result;
	      Address target = new AHAddress(result);
	      if (target.Equals(queue_to_address[qu])) {
		correct_rpcs++;
	      } else {
		incorrect_rpcs++;
	      }
	    }
	  };
	  rpc_man.Invoke(s, q, "rpc_routing_test.GetIdentification", new object[]{});
	}
      }
      
      //wait for 10 more seconds
      while (true) {
	int c = -1;
	lock(_class_lock) {
	  c = incorrect_rpcs + missing_rpcs + correct_rpcs;
	}
	if (c < network_size*network_size) {
	  Console.WriteLine("Going to sleep for 10 seconds.");
	  System.Threading.Thread.Sleep(10000);
	} else {
	  break;
	}
      }
      
      Console.WriteLine("Final statistics");
      Console.WriteLine("correct rpcs: {0}, incorrect rpcs: {1}, missing rpcs: {2}", 
			correct_rpcs, incorrect_rpcs, missing_rpcs);
      
      System.Environment.Exit(1);
    }
Example #2
0
        public static void Main(string [] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("please specify the number edge protocol.");
                Environment.Exit(0);
            }
            if (args.Length < 2)
            {
                Console.WriteLine("please specify the number of p2p nodes.");
                Environment.Exit(0);
            }
            if (args.Length < 3)
            {
                Console.WriteLine("please specify the number of missing edges.");
                Environment.Exit(0);
            }
            string proto = "function";

            try {
                proto = args[0].Trim();
            } catch (Exception) {}

            bool tunnel        = false;
            int  base_port     = 54000;
            int  network_size  = Int32.Parse(args[1]);
            int  missing_count = Int32.Parse(args[2]);

            try {
                tunnel = args[3].Trim().Equals("tunnel");
            } catch (Exception) {}

            Console.WriteLine("use tunnel edges: {0}", tunnel);

            Random rand = new Random();

            ArrayList missing_edges = new ArrayList();

            for (int i = 0; i < missing_count; i++)
            {
                int idx = -1;
                int left, right;
                do
                {
                    idx  = rand.Next(0, network_size);
                    left = (idx + 1) % network_size;
                    if (idx == 0)
                    {
                        right = network_size - 1;
                    }
                    else
                    {
                        right = idx - 1;
                    }
                } while (missing_edges.Contains(idx));// ||
                //missing_edges.Contains(left) ||
                //missing_edges.Contains(right));

                Console.WriteLine("Will drop a left edge on idx {0}: ", idx);
                missing_edges.Add(idx);
            }

            //
            // Sort missing edges.
            //
            missing_edges.Sort();
            SortedList dist = new SortedList();

            //
            // Compute the average distance between missing edges.
            //
            if (missing_count > 1)
            {
                for (int i = 0; i < missing_count; i++)
                {
                    int idx = (int)missing_edges[i];
                    int idx_next;
                    int d;
                    if (i == missing_count - 1)
                    {
                        idx_next = (int)missing_edges[0];
                        d        = (network_size - 1) - idx + idx_next;
                    }
                    else
                    {
                        idx_next = (int)missing_edges[i + 1];
                        d        = idx_next - idx - 1;
                    }
                    if (!dist.Contains(d))
                    {
                        dist[d] = 0;
                    }
                    else
                    {
                        int c = (int)dist[d];
                        dist[d] = c + 1;
                    }
                }
            }
            double sum = 0.0;
            int    num = 0;

            Console.WriteLine("distribution of missing edges separation");
            foreach (DictionaryEntry de in dist)
            {
                int k = (int)de.Key;
                int c = (int)de.Value;
                Console.WriteLine("{0} {1}", k, c);
                sum = sum + k * c;
                num = num + c;
            }

            Console.WriteLine("average separation: {0}", (double)sum / num);
            string brunet_namespace = "testing";

            Console.WriteLine("Initializing...");

            var RemoteTA = new List <TransportAddress>();

            for (int i = 0; i < network_size; i++)
            {
                if (proto.Equals("udp"))
                {
                    RemoteTA.Add(TransportAddressFactory.CreateInstance("brunet.udp://localhost:" + (base_port + i)));
                }
                else if (proto.Equals("function"))
                {
                    RemoteTA.Add(TransportAddressFactory.CreateInstance("brunet.function://localhost:" + (base_port + i)));
                }
            }

            for (int i = 0; i < network_size; i++)
            {
                AHAddress address = new AHAddress(new RNGCryptoServiceProvider());
                Node      node    = new StructuredNode(address, brunet_namespace);
                _sorted_node_list.Add((Address)address, node);
                _node_list.Add(node);
                RouteTestHandler test_handler = new RouteTestHandler();
                node.GetTypeSource(new PType(routing_test)).Subscribe(test_handler, address.ToMemBlock());
                RpcManager rpc_man = node.Rpc;
                rpc_man.AddHandler("rpc_routing_test", new  RpcRoutingTestHandler(node));
            }

            for (int i = 0; i < network_size; i++)
            {
                Node node = (Node)_sorted_node_list.GetByIndex(i);
                Console.WriteLine("Configuring node: {0} ", node.Address);
                TAAuthorizer ta_auth = null;
                if (missing_edges.Contains(i))
                {
                    int remote_port;
                    if (i == network_size - 1)
                    {
                        remote_port = base_port;
                    }
                    else
                    {
                        remote_port = base_port + i + 1;
                    }

                    PortTAAuthorizer port_auth = new PortTAAuthorizer(remote_port);
                    Console.WriteLine("Adding a port TA authorizer at: {0} for remote port: {1}", base_port + i, remote_port);
                    ArrayList arr_tas = new ArrayList();
                    arr_tas.Add(port_auth);
                    arr_tas.Add(new ConstantAuthorizer(TAAuthorizer.Decision.Allow));
                    ta_auth = new SeriesTAAuthorizer(arr_tas);
                }

                if (proto.Equals("udp"))
                {
                    node.AddEdgeListener(new UdpEdgeListener(base_port + i, null, ta_auth));
                }
                else if (proto.Equals("function"))
                {
                    node.AddEdgeListener(new FunctionEdgeListener(base_port + i, -1.00, ta_auth));
                }

                if (tunnel)
                {
                    Console.WriteLine("Adding a tunnel edge listener");
                    node.AddEdgeListener(new Relay.RelayEdgeListener(node));
                }
                _node_to_port[node] = base_port + i;
                node.RemoteTAs      = RemoteTA;
            }

            //start nodes one by one.
            for (int i = 0; i < network_size; i++)
            {
                Node node = (Node)_node_list[i];
                Console.WriteLine("Starting node: {0}, {1}", i, node.Address);
                node.Connect();
                Console.WriteLine("Going to sleep for 2 seconds.");
                System.Threading.Thread.Sleep(2000);
            }

            //wait for 300000 more seconds
            Console.WriteLine("Going to sleep for 300000 seconds.");
            System.Threading.Thread.Sleep(300000);
            bool complete = CheckStatus();

            int count = 0;

            //
            // Send a large number of packets as exact packets to random destinations
            // and make sure exact routing is perfect.
            //

            for (int i = 0; i < network_size; i++)
            {
                for (int j = 0; j < network_size; j++)
                {
                    int  src_idx   = i;
                    int  dest_idx  = j;
                    Node src_node  = (Node)_sorted_node_list.GetByIndex(src_idx);
                    Node dest_node = (Node)_sorted_node_list.GetByIndex(dest_idx);
                    //Console.WriteLine("{0} -> {1}", src_idx, dest_idx);
                    Address  dest_address = (Address)dest_node.Address;
                    ISender  s            = new AHExactSender(src_node, dest_address);
                    MemBlock p            = dest_address.ToMemBlock();
                    s.Send(new CopyList(new PType(routing_test), p));
                    _sent++;
                    //System.Threading.Thread.Sleep(10);
                    s.Send(new CopyList(new PType(routing_test), p));
                    _sent++;
                    //System.Threading.Thread.Sleep(10);
                }
            }
            //wait for 10 more seconds
            Console.WriteLine("Going to sleep for 10 seconds.");
            System.Threading.Thread.Sleep(10000);
            Console.WriteLine("Final statistics");
            lock (_class_lock) {
                Console.WriteLine("Sent: {0}, Received: {1}, Wrongly routed: {2}",
                                  _sent, _received, _wrongly_routed);
            }

            int       missing_rpcs     = 0;
            int       correct_rpcs     = 0;
            int       incorrect_rpcs   = 0;
            Hashtable queue_to_address = new Hashtable();

            for (int i = 0; i < network_size; i++)
            {
                for (int j = 0; j < network_size; j++)
                {
                    int  src_idx   = i;
                    int  dest_idx  = j;
                    Node src_node  = (Node)_sorted_node_list.GetByIndex(src_idx);
                    Node dest_node = (Node)_sorted_node_list.GetByIndex(dest_idx);
                    //Console.WriteLine("{0} -> {1}", src_idx, dest_idx);
                    Address    dest_address = (Address)dest_node.Address;
                    ISender    s            = new AHExactSender(src_node, dest_address);
                    RpcManager rpc_man      = src_node.Rpc;
                    Channel    q            = new Channel();
                    lock (_class_lock) {
                        queue_to_address[q] = dest_address;
                    }
                    q.CloseAfterEnqueue();
                    q.CloseEvent += delegate(object o, EventArgs cargs) {
                        lock (_class_lock) {
                            Channel qu = (Channel)o;
                            if (qu.Count == 0)
                            {
                                missing_rpcs++;
                            }
                            queue_to_address.Remove(qu);
                        }
                    };
                    q.EnqueueEvent += delegate(object o, EventArgs cargs) {
                        lock (_class_lock) {
                            Channel   qu        = (Channel)o;
                            RpcResult rpc_reply = (RpcResult)qu.Peek();
                            byte []   result    = (byte[])rpc_reply.Result;
                            Address   target    = new AHAddress(result);
                            if (target.Equals(queue_to_address[qu]))
                            {
                                correct_rpcs++;
                            }
                            else
                            {
                                incorrect_rpcs++;
                            }
                        }
                    };
                    rpc_man.Invoke(s, q, "rpc_routing_test.GetIdentification", new object[] {});
                }
            }

            //wait for 10 more seconds
            while (true)
            {
                int c = -1;
                lock (_class_lock) {
                    c = incorrect_rpcs + missing_rpcs + correct_rpcs;
                }
                if (c < network_size * network_size)
                {
                    Console.WriteLine("Going to sleep for 10 seconds.");
                    System.Threading.Thread.Sleep(10000);
                }
                else
                {
                    break;
                }
            }

            Console.WriteLine("Final statistics");
            Console.WriteLine("correct rpcs: {0}, incorrect rpcs: {1}, missing rpcs: {2}",
                              correct_rpcs, incorrect_rpcs, missing_rpcs);

            System.Environment.Exit(1);
        }
Example #3
0
        //returns true if addr is in a given range including boundary.

        /**
         * This returns true if addr is between start and end in a ring.
         * IsBetweenFrom*() excludes both start and end, but InRange() includes both.
         * @param addr, this node's address
         * @param start, the beginning address of range
         * @param end, the ending address of range
         */
        public bool InRange(AHAddress addr, AHAddress start, AHAddress end)
        {
            return(addr.IsBetweenFromLeft(start, end) || addr.Equals(start) || addr.Equals(end));
        }
Example #4
0
        ///</summary>Creates a new Graph for simulate routing algorithms.</summary>
        ///<param name="count">The network size not including the clusters.</param>
        ///<param name="near">The amount of connections on the left or right of a
        ///node.</param>
        ///<param name="shortcuts">The amount of far connections had per node.</param>
        ///<param name="latency">(optional)count x count matrix containing the
        ///latency between ///two points.</param>
        ///<param name="cluster_count">A cluster is a 100 node network operating on
        ///a single point in the network.  A cluster cannot communicate directly
        ///with another cluster.</param>
        ///<param name="dataset">A square dataset consisting of pairwise latencies.</param>
        public Graph(int count, int near, int shortcuts, int random_seed, List <List <int> > dataset)
        {
            _rand = new Random(random_seed);

            if (dataset != null)
            {
                if (count >= dataset.Count)
                {
                    _latency_map = dataset;
                }
                else
                {
                    // If the count size is less than the data set, we may get inconclusive
                    // results as network size changes due to the table potentially being
                    // heavy set early and lighter later.  This randomly orders all entries
                    // so that multiple calls to the graph will provide a good distribution.
                    Dictionary <int, int> chosen = new Dictionary <int, int>(count);
                    for (int i = 0; i < count; i++)
                    {
                        int index = _rand.Next(0, dataset.Count - 1);
                        while (chosen.ContainsKey(index))
                        {
                            index = _rand.Next(0, dataset.Count - 1);
                        }
                        chosen.Add(i, index);
                    }

                    _latency_map = new List <List <int> >(dataset.Count);
                    for (int i = 0; i < count; i++)
                    {
                        List <int> map = new List <int>(count);
                        for (int j = 0; j < count; j++)
                        {
                            map.Add(dataset[chosen[i]][chosen[j]]);
                        }
                        _latency_map.Add(map);
                    }
                }
            }

            GraphNode.SetSeed(_rand.Next());

            _addr_to_node  = new Dictionary <AHAddress, GraphNode>(count);
            _addrs         = new List <AHAddress>(count);
            _addr_to_index = new Dictionary <AHAddress, int>(count);

            // first we create our regular network
            while (_addrs.Count < count)
            {
                AHAddress addr = GenerateAddress();
                _addr_to_node[addr] = CreateNode(addr);
                _addrs.Add(addr);
            }

            FixLists();

            for (int i = 0; i < count; i++)
            {
                GraphNode      cnode = _addr_to_node[_addrs[i]];
                ConnectionList cons  = cnode.ConnectionTable.GetConnections(ConnectionType.Structured);
                // We select our left and right neighbors up to near out (so we get 2*near connections)
                // Then we check to make sure we don't already have this connection, since the other guy
                // may have added it, if we don't we create one and add it.
                for (int j = 1; j <= near; j++)
                {
                    int left = i - j;
                    if (left < 0)
                    {
                        left += count;
                    }
                    GraphNode lnode = _addr_to_node[_addrs[left]];
                    if (!cons.Contains(lnode.Address))
                    {
                        int delay = CalculateDelay(cnode, lnode);
                        AddConnection(cnode, lnode, delay);
                        AddConnection(lnode, cnode, delay);
                    }

                    int right = i + j;
                    if (right >= count)
                    {
                        right -= count;
                    }
                    GraphNode rnode = _addr_to_node[_addrs[right]];
                    // No one has this connection, let's add it to both sides.
                    if (!cons.Contains(rnode.Address))
                    {
                        int delay = CalculateDelay(cnode, rnode);
                        AddConnection(cnode, rnode, delay);
                        AddConnection(rnode, cnode, delay);
                    }
                }

                // Let's add shortcuts so that we have at least the minimum number of shortcuts
                while (cnode.Shortcuts < shortcuts)
                {
                    cons = cnode.ConnectionTable.GetConnections(ConnectionType.Structured);
                    AHAddress addr = ComputeShortcutTarget(cnode.Address);
                    addr = FindNodeNearestToAddress(addr);
                    if (cons.Contains(addr) || addr.Equals(cnode.Address))
                    {
                        continue;
                    }
                    GraphNode snode = _addr_to_node[addr];
                    cons = snode.ConnectionTable.GetConnections(ConnectionType.Structured);
                    int delay = CalculateDelay(cnode, snode);
                    if (delay == -1)
                    {
                        continue;
                    }
                    AddConnection(cnode, snode, delay);
                    AddConnection(snode, cnode, delay);
                    cnode.Shortcuts++;
                    snode.Shortcuts++;
                }
            }

            foreach (GraphNode gn in _addr_to_node.Values)
            {
                gn.UpdateSystem();
            }
        }
Example #5
0
        /// <summary>Make sure there are no entries in the Dht, who we should be
        /// connected to, but aren't.</summary>
        protected void CheckAndUpdateRemoteTAs(List <TransportAddress> tas)
        {
            AHAddress  right = null, left = null;
            BigInteger right_dist = null, left_dist = null;
            AHAddress  addr = _node.Address as AHAddress;

            // Find the closest left and right nodes
            foreach (TransportAddress ta in tas)
            {
                AHAddress target = (ta as SubringTransportAddress).Target;
                if (target.Equals(addr))
                {
                    continue;
                }
                BigInteger ldist = addr.LeftDistanceTo(target);
                BigInteger rdist = addr.RightDistanceTo(target);

                if (left_dist == null || ldist < left_dist)
                {
                    left_dist = ldist;
                    left      = target;
                }

                if (right_dist == null || rdist < right_dist)
                {
                    right_dist = rdist;
                    right      = target;
                }
            }

            ConnectionList cl        = _node.ConnectionTable.GetConnections(ConnectionType.Structured);
            int            local_idx = ~cl.IndexOf(_node.Address);

            if (left != null)
            {
                int remote_idx = ~cl.IndexOf(left);
                // If we're not connected to the left closest and its closer than any
                // of our current peers, let's connect to it
                if (remote_idx > 0 && Math.Abs(local_idx - remote_idx) < 2)
                {
                    List <TransportAddress> tmp_tas = new List <TransportAddress>(1);
                    tmp_tas.Add(new SubringTransportAddress(left, _shared_namespace));
                    Linker linker = new Linker(_node, null, tmp_tas, "leaf", addr.ToString());
                    linker.Start();
                }
            }

            if (right != null && right != left)
            {
                int remote_idx = ~cl.IndexOf(right);
                // If we're not connected to the right closest and its closer than any
                // of our current peers, let's connect to it
                if (remote_idx > 0 && Math.Abs(local_idx - remote_idx) < 2)
                {
                    List <TransportAddress> tmp_tas = new List <TransportAddress>(1);
                    tas.Add(new SubringTransportAddress(right, _shared_namespace));
                    Linker linker = new Linker(_node, null, tmp_tas, "leaf", addr.ToString());
                    linker.Start();
                }
            }

            UpdateRemoteTAs(tas);
        }