Brunet.Tunnel.TunnelEdge.DisconnectionHandler C# (CSharp) Method

DisconnectionHandler() public method

We don't want to send on disconnected edges. So we remove said connections and edges!
public DisconnectionHandler ( Connection con ) : void
con Connection
return void
    public void DisconnectionHandler(Connection con)
    {
      bool close = false;
      List<Connection> tunnels = null;
      lock(_sync) {
        tunnels = new List<Connection>(_tunnels.Count);
        foreach(Connection ccon in _tunnels) {
          if(con.Edge.Equals(ccon.Edge)){
            continue;
          }
          tunnels.Add(ccon);
        }

        if(tunnels.Count == _tunnels.Count) {
          return;
        }

        _tunnels = tunnels;
        close = _tunnels.Count == 0;
      }

      if(close || ShouldClose()) {
        Close();
      }

      //_tunnels is immutable and if we don't pass the latest _tunnels to _ias
      //he will go into an inconsistent state.
      _ias.Update(tunnels);
    }

Usage Example

Example #1
0
        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");
        }
All Usage Examples Of Brunet.Tunnel.TunnelEdge::DisconnectionHandler