コード例 #1
0
        public RelayEdgeListener(Node node, IRelayOverlap ito, IForwarderSelectorFactory iasf)
        {
            _ito          = ito;
            _iasf         = iasf;
            _oco          = new OverlapConnectionOverlord(node);
            _node         = node;
            _running      = 0;
            _started      = 0;
            _id_to_tunnel = new Dictionary <int, RelayEdge>();
            _sync         = new object();

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

            local_tas.Add(ta);
            _local_tas = local_tas;

            _node.DemuxHandler.GetTypeSource(PType.Protocol.Relaying).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);
        }
コード例 #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 RelayTransportAddress(_node.Address, addresses);

            ArrayList tas = new ArrayList(1);

            tas.Add(ta);

            Interlocked.Exchange(ref _local_tas, tas);

            foreach (RelayEdge 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);
            }
        }
コード例 #3
0
        /// <summary>Constructor for a RelayEdge, RemoteID == -1 for out bound.</summary>
        public RelayEdge(IEdgeSendHandler send_handler, RelayTransportAddress local_ta,
                         RelayTransportAddress 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.Relaying);

            Header = MemBlock.Copy(header);
        }
コード例 #4
0
        public override bool Equals(object o)
        {
            if (o == this)
            {
                return(true);
            }
            RelayTransportAddress other = o as RelayTransportAddress;

            if (other == null)
            {
                return(false);
            }

            bool same = _target.Equals(other._target);

            same &= (_forwarders.Count == other._forwarders.Count);
            if (!same)
            {
                return(false);
            }
            for (int i = 0; i < _forwarders.Count; i++)
            {
                same = _forwarders[i].Equals(other._forwarders[i]);
                if (!same)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #5
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);

            RelayTransportAddress tun_ta = (RelayTransportAddress)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")));

            RelayTransportAddress test_ta = new RelayTransportAddress(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)");
        }
コード例 #6
0
 public RelayEdgeCallbackAction(RelayTransportAddress tta, EdgeCreationCallback ecb)
 {
     RelayTA   = tta;
     Ecb       = ecb;
     Exception = new WriteOnce <Exception>();
     Success   = new WriteOnce <bool>();
     Edge      = new WriteOnce <Edge>();
 }
コード例 #7
0
ファイル: RelayOverlap.cs プロジェクト: kingctan/brunet
        /// <summary>Attempt to find the overlap in a remote RelayTransportAddress
        /// and our local node.  This will be used to help communicate with a new
        /// tunneled peer.</summary>
        public virtual List <Connection> FindOverlap(RelayTransportAddress 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));
        }
コード例 #8
0
        public void WrapperEdgeRegressionTest()
        {
            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);
            WrapperEdge      we_fe = new WrapperEdge(fe);
            Connection       fcon  = new Connection(we_fe, addr, "structured", null, null);

            List <Connection> overlap = new List <Connection>();

            overlap.Add(fcon);
            RelayTransportAddress tta    = new RelayTransportAddress(addr, overlap);
            RelayEdge             te1    = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap);
            WrapperEdge           we_te1 = new WrapperEdge(te1);
            Connection            t1con  = new Connection(we_te1, addr, "structured", null, null);

            overlap = new List <Connection>();
            overlap.Add(t1con);
            RelayEdge   te2    = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap);
            WrapperEdge we_te2 = new WrapperEdge(te2);
            Connection  t2con  = new Connection(we_te2, addr, "structured", null, null);

            overlap = new List <Connection>();
            overlap.Add(t2con);
            RelayEdge   te3    = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap);
            WrapperEdge we_te3 = new WrapperEdge(te3);
            Connection  t3con  = new Connection(we_te3, addr, "structured", null, null);

            overlap = new List <Connection>();
            overlap.Add(t3con);
            RelayEdge   te4    = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap);
            WrapperEdge we_te4 = new WrapperEdge(te4);
            Connection  t4con  = new Connection(we_te4, addr, "structured", null, null);

            overlap = new List <Connection>();
            overlap.Add(t4con);
            RelayEdge   te5    = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap);
            WrapperEdge we_te5 = new WrapperEdge(te5);
            Connection  t5con  = new Connection(we_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");
        }
コード例 #9
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)
        {
            RelayTransportAddress tta = ta as RelayTransportAddress;

            if (tta == null)
            {
                ecb(false, null, new Exception("TA Type is not Relay!"));
            }
            else
            {
                RelayEdgeCallbackAction  teca     = new RelayEdgeCallbackAction(tta, ecb);
                System.Action <DateTime> callback = delegate(DateTime now) {
                    CreateEdgeTo(teca);
                };
                Brunet.Util.FuzzyTimer.Instance.DoAfter(callback, 10000, 0);
            }
        }
コード例 #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 RelayTransportAddress(_node.Address, addresses);

            ArrayList tas = new ArrayList(1);

            tas.Add(ta);

            Interlocked.Exchange(ref _local_tas, tas);


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

                IDictionary sync_message = _ito.GetSyncMessage(te.Overlap, _node.Address, cons);
                //Just do our best here:
                try { _node.Rpc.Invoke(te, null, "tunnel.Sync", sync_message); }
                catch { }
            }
        }
コード例 #11
0
 /// <summary>Outgoing edge, since we don't know the RemoteID yet!</summary>
 public RelayEdge(IEdgeSendHandler send_handler, RelayTransportAddress local_ta,
                  RelayTransportAddress remote_ta, IForwarderSelector ias, List <Connection> overlap) :
     this(send_handler, local_ta, remote_ta, ias, overlap, -1)
 {
 }