/// <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); }