Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <summary>We need to keep track of a current ConnectionList, so we
        /// listen to incoming connections.  We also use this opportunity to
        /// rebuild our LocalTA.</summary>
        protected void ConnectionHandler(object o, EventArgs ea)
        {
            ConnectionEventArgs cea = ea as ConnectionEventArgs;

            if (cea.ConnectionType != ConnectionType.Structured)
            {
                return;
            }

            ConnectionList cons = cea.CList;

            Interlocked.Exchange(ref _connections, cons);

            IList            addresses = GetNearest(_node.Address, cons);
            TransportAddress ta        = new TunnelTransportAddress(_node.Address, addresses);

            ArrayList tas = new ArrayList(1);

            tas.Add(ta);

            Interlocked.Exchange(ref _local_tas, tas);

            foreach (TunnelEdge te in _tunnels)
            {
                IDictionary sync_message = _ito.GetSyncMessage(te.Overlap, _node.Address, cons);
                Channel     chan         = new Channel(1);
                _node.Rpc.Invoke(te, chan, "tunnel.Sync", sync_message);
            }
        }
Ejemplo n.º 3
0
        public TunnelEdgeListener(Node node, ITunnelOverlap ito, IForwarderSelectorFactory iasf)
        {
            _ito          = ito;
            _iasf         = iasf;
            _oco          = new OverlapConnectionOverlord(node);
            _node         = node;
            _running      = 0;
            _started      = 0;
            _id_to_tunnel = new Dictionary <int, TunnelEdge>();
            _sync         = new object();

            TransportAddress ta        = new TunnelTransportAddress(node.Address, new List <Address>());
            ArrayList        local_tas = new ArrayList(1);

            local_tas.Add(ta);
            _local_tas = local_tas;

            _node.DemuxHandler.GetTypeSource(PType.Protocol.Tunneling).Subscribe(this, null);
            _node.ConnectionTable.ConnectionEvent    += ConnectionHandler;
            _node.ConnectionTable.DisconnectionEvent += DisconnectionHandler;

            ConnectionList cons = _node.ConnectionTable.GetConnections(ConnectionType.Structured);

            Interlocked.Exchange(ref _connections, cons);
            _node.Rpc.AddHandler("tunnel", this);
            _oco_trim_timer = Brunet.Util.FuzzyTimer.Instance.DoEvery(OcoTrim, _oco_trim_timeout, 0);
        }
Ejemplo n.º 4
0
 public TunnelEdgeCallbackAction(TunnelTransportAddress tta, EdgeCreationCallback ecb)
 {
     TunnelTA  = tta;
     Ecb       = ecb;
     Exception = new WriteOnce <Exception>();
     Success   = new WriteOnce <bool>();
     Edge      = new WriteOnce <Edge>();
 }
Ejemplo n.º 5
0
        /// <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));
        }
Ejemplo n.º 6
0
        /// <summary>Does not immediately create an edge to a remote node, instead,
        /// it tells a timer to wait 5 seconds prior to attempting an edge.</summary>
        public override void CreateEdgeTo(TransportAddress ta, EdgeCreationCallback ecb)
        {
            TunnelTransportAddress tta = ta as TunnelTransportAddress;

            if (tta == null)
            {
                ecb(false, null, new Exception("TA Type is not Tunnel!"));
            }
            else
            {
                TunnelEdgeCallbackAction teca     = new TunnelEdgeCallbackAction(tta, ecb);
                System.Action <DateTime> callback = delegate(DateTime now) {
                    CreateEdgeTo(teca);
                };
                Brunet.Util.FuzzyTimer.Instance.DoAfter(callback, 10000, 0);
            }
        }
Ejemplo n.º 7
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");
        }
Ejemplo n.º 8
0
    public TunnelEdgeListener(Node node, ITunnelOverlap ito, IForwarderSelectorFactory iasf)
    {
      _ito = ito;
      _iasf = iasf;
      _oco = new OverlapConnectionOverlord(node);
      _node = node;
      _running = 0;
      _started = 0;
      _id_to_tunnel = new Dictionary<int, TunnelEdge>();
      _sync = new object();

      TransportAddress ta = new TunnelTransportAddress(node.Address, new List<Address>());
      ArrayList local_tas = new ArrayList(1);
      local_tas.Add(ta);
      _local_tas = local_tas;

      _node.DemuxHandler.GetTypeSource(PType.Protocol.Tunneling).Subscribe(this, null);
      _node.ConnectionTable.ConnectionEvent += ConnectionHandler;
      _node.ConnectionTable.DisconnectionEvent += DisconnectionHandler;

      ConnectionList cons = _node.ConnectionTable.GetConnections(ConnectionType.Structured);
      Interlocked.Exchange(ref _connections, cons);
      _node.Rpc.AddHandler("tunnel", this);
      _oco_trim_timer = Brunet.Util.FuzzyTimer.Instance.DoEvery(OcoTrim, _oco_trim_timeout, 0);
    }
Ejemplo n.º 9
0
 public TunnelEdgeCallbackAction(TunnelTransportAddress tta, EdgeCreationCallback ecb)
 {
   TunnelTA = tta;
   Ecb = ecb;
   Exception = new WriteOnce<Exception>();
   Success = new WriteOnce<bool>();
   Edge = new WriteOnce<Edge>();
 }
Ejemplo n.º 10
0
    /// <summary>When a disconnection occurs, we must make sure that none of
    /// our tunnels use that faulty edge / connection any more.</summary>
    protected void DisconnectionHandler(object o, EventArgs ea)
    {
      ConnectionEventArgs cea = ea as ConnectionEventArgs;
      if(cea.ConnectionType != ConnectionType.Structured) {
        return;
      }

      ConnectionList cons = cea.CList;
      Interlocked.Exchange(ref _connections, cons);;

      IList addresses = GetNearest(_node.Address, cons);
      TransportAddress ta = new TunnelTransportAddress(_node.Address, addresses);

      ArrayList tas = new ArrayList(1);
      tas.Add(ta);

      Interlocked.Exchange(ref _local_tas, tas);


      foreach(TunnelEdge te in _tunnels) {
        te.DisconnectionHandler(cea.Connection);
        if(te.IsClosed) {
          continue;
        }

        IDictionary sync_message = _ito.GetSyncMessage(te.Overlap, _node.Address, cons);
        Channel chan = new Channel(1);
        _node.Rpc.Invoke(te, chan, "tunnel.Sync", sync_message);
      }
    }
Ejemplo n.º 11
0
 /// <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)
 {
 }
Ejemplo n.º 12
0
    public void Test() {
      string ta_string = "brunet.tunnel://UBU72YLHU5C3SY7JMYMJRTKK4D5BGW22/FE4QWASN+FE4QWASM";
      TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tunnel://UBU72YLHU5C3SY7JMYMJRTKK4D5BGW22/FE4QWASN+FE4QWASM");
      Assert.AreEqual(ta.ToString(), ta_string, "testing tunnel TA parsing");
      //Console.WriteLine(ta);

      TunnelTransportAddress tun_ta = (TunnelTransportAddress) TransportAddressFactory.CreateInstance("brunet.tunnel://OIHZCNNUAXTLLARQIOBNCUWXYNAS62LO/CADSL6GV+CADSL6GU");

      ArrayList fwd = new ArrayList();
      fwd.Add(new AHAddress(Base32.Decode("CADSL6GVVBM6V442CETP4JTEAWACLC5A")));
      fwd.Add(new AHAddress(Base32.Decode("CADSL6GUVBM6V442CETP4JTEAWACLC5A")));
      
      TunnelTransportAddress test_ta = new TunnelTransportAddress(tun_ta.Target, fwd);
      Assert.AreEqual(tun_ta, test_ta, "testing tunnel TA compression enhancements");
      //Console.WriteLine(tun_ta.ToString());
      //Console.WriteLine(test_ta.ToString());
      Assert.AreEqual(tun_ta.ToString(), test_ta.ToString(), "testing tunnel TA compression enhancements (toString)");

      Assert.AreEqual(tun_ta.ContainsForwarder(new AHAddress(Base32.Decode("CADSL6GVVBM6V442CETP4JTEAWACLC5A"))), true, 
          "testing tunnel TA contains forwarder (1)");

      Assert.AreEqual(tun_ta.ContainsForwarder(new AHAddress(Base32.Decode("CADSL6GUVBM6V442CETP4JTEAWACLC5A"))), true, 
          "testing tunnel TA contains forwarder (2)");
    }
Ejemplo n.º 13
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");
    }
Ejemplo n.º 14
0
    /// <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);
    }
Ejemplo n.º 15
0
 /// <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)
 {
 }