/// <summary>Attempt to find the overlap in a remote TunnelTransportAddress /// and our local node. This will be used to help communicate with a new /// tunneled peer.</summary> public virtual List<Connection> FindOverlap(TunnelTransportAddress ta, ConnectionList cons) { List<Connection> overlap = new List<Connection>(); foreach(Connection con in cons) { if(ta.ContainsForwarder(con.Address)) { overlap.Add(con); } } return GetOldest(overlap); }
public void Test() { AHAddress addr = new AHAddress(new System.Security.Cryptography.RNGCryptoServiceProvider()); TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://169.0.5.1:5000"); FakeEdge fe = new FakeEdge(ta, ta); Connection fcon = new Connection(fe, addr, "structured", null, null); List<Connection> overlap = new List<Connection>(); overlap.Add(fcon); TunnelTransportAddress tta = new TunnelTransportAddress(addr, overlap); TunnelEdge te1 = new TunnelEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); Connection t1con = new Connection(te1, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t1con); TunnelEdge te2 = new TunnelEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); Connection t2con = new Connection(te2, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t2con); TunnelEdge te3 = new TunnelEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); Connection t3con = new Connection(te3, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t3con); TunnelEdge te4 = new TunnelEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); Connection t4con = new Connection(te4, addr, "structured", null, null); overlap = new List<Connection>(); overlap.Add(t4con); TunnelEdge te5 = new TunnelEdge(null, tta, tta, new SimpleForwarderSelector(), overlap); Connection t5con = new Connection(te5, addr, "structured", null, null); Assert.AreEqual(te5.ShouldClose(), false, "Shouldn't close yet..."); te1.DisconnectionHandler(fcon); Assert.AreEqual(te5.ShouldClose(), true, "Should close..."); overlap.Add(t5con); overlap.Add(t3con); overlap.Add(t1con); te2.UpdateNeighborIntersection(overlap); Assert.AreEqual(te5.ShouldClose(), true, "Should close... 2"); }
/// <summary>Outgoing edge, since we don't know the RemoteID yet!</summary> public TunnelEdge(IEdgeSendHandler send_handler, TunnelTransportAddress local_ta, TunnelTransportAddress remote_ta, IForwarderSelector ias, List<Connection> overlap) : this(send_handler, local_ta, remote_ta, ias, overlap, -1) { }
/// <summary>Constructor for a TunnelEdge, RemoteID == -1 for out bound.</summary> public TunnelEdge(IEdgeSendHandler send_handler, TunnelTransportAddress local_ta, TunnelTransportAddress remote_ta, IForwarderSelector ias, List<Connection> overlap, int remote_id) : base(send_handler, remote_id != -1) { _remote_id = remote_id; lock(_rand) { LocalID = _rand.Next(); } byte[] bid = new byte[8]; NumberSerializer.WriteInt(LocalID, bid, 0); NumberSerializer.WriteInt(_remote_id, bid, 4); _mid = MemBlock.Reference(bid); _local_ta = local_ta; _remote_ta = remote_ta; _tunnels = new List<Connection>(overlap); _ias = ias; _ias.Update(_tunnels); AHHeader ahh = new AHHeader(1, 20, local_ta.Target, remote_ta.Target, AHHeader.Options.Exact); ICopyable header = new CopyList(PType.Protocol.AH, ahh, PType.Protocol.Tunneling); Header = MemBlock.Copy(header); }