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);
        }
Esempio n. 2
0
        /// <summary>Blocking may occur for two reasons, no data available or the
        /// handshake isn't complete.  If the handshake isn't complete, the timer
        /// will be set to >= 0, at 0, we need to call handshake to continue, if
        /// it is greater than 0, we need to schedule a timer to call handshake
        /// later.</summary>
        protected void HandleWouldBlock()
        {
            if (Closed)
            {
                return;
            }
            long to = _ssl.GetTimeout();

            if (to == 0)
            {
                _ssl.TimerExpired();
            }
            if (_read.BytesPending > 0)
            {
                HandleData(null, Sender, null);
            }
            if (_write.BytesPending > 0)
            {
                Send(null);
            }

#if !BRUNET_SIMULATOR
            if (to > 0 && Interlocked.Exchange(ref _fe_lock, 1) == 0)
            {
                _fe = FuzzyTimer.Instance.DoAfter(HandleWouldBlock, (int)to, 250);
            }
#endif
        }
Esempio n. 3
0
        /**
         * <summary>This method is registered as a delegate to Shutdown.OnExit and
         * will be called when ctrl-c is pressed by the user.  This stops services,
         * prevents the node from reincarnating, and then disconnects the node.
         * </summary>
         */
        public virtual void OnExit()
        {
            _running = false;

            if (_xrm != null)
            {
                _xrm.Stop();
                _xrm = null;
            }

            ApplicationNode appnode = _app_node;

            _app_node = null;

            NCService ncservice = null;

            if (appnode != null)
            {
                ncservice = appnode.NCService;
            }

            if (ncservice != null && _node_config.NCService.Checkpointing)
            {
                string checkpoint = ncservice.GetCheckpoint();
                string prev_cp    = _node_config.NCService.Checkpoint;
                string empty_cp   = (new Point()).ToString();
                if (!checkpoint.Equals(prev_cp) && !checkpoint.Equals(empty_cp))
                {
                    _node_config.NCService.Checkpoint = checkpoint;
                    _node_config.WriteConfig();
                }
            }

            _fe_stop_pem = Brunet.Util.FuzzyTimer.Instance.DoEvery(StopPem, 500, 500);
        }
Esempio n. 4
0
 /// <summary></summary>
 public SecurityOverlord(RSACryptoServiceProvider private_key,
     CertificateHandler ch)
 {
   _private_key = private_key;
   _ch = ch;
   _stopped = 0;
   _sa_check = FuzzyTimer.Instance.DoEvery(CheckSAs, CHECK_SA_PERIOD, 0);//CHECK_SA_PERIOD / 2);
 }
Esempio n. 5
0
 /// <summary></summary>
 public SecurityOverlord(RSACryptoServiceProvider private_key,
                         CertificateHandler ch)
 {
     _private_key = private_key;
     _ch          = ch;
     _stopped     = 0;
     _sa_check    = FuzzyTimer.Instance.DoEvery(CheckSAs, CHECK_SA_PERIOD, 0);//CHECK_SA_PERIOD / 2);
 }
Esempio n. 6
0
 public TimeBasedCache(int timer)
 {
     CleanupTime = timer;
     _sync       = new ReaderWriterLock();
     _first      = new Dictionary <K, V>();
     _second     = new Dictionary <K, V>();
     _fe         = Brunet.Util.FuzzyTimer.Instance.DoEvery(Recycle, CleanupTime, CleanupTime / 10);
     _stopped    = 0;
 }
Esempio n. 7
0
        /**
         * This is a System.Threading.ThreadStart delegate
         * We loop waiting for edges that need to send,
         * or data on the socket.
         *
         * This is the only thread that can touch the socket,
         * therefore, we do not need to lock the socket.
         */

        protected void MonitorLogOff()
        {
            Util.FuzzyEvent fe = _monitor_fe;
            _monitor_fe = null;
            if (fe != null)
            {
                fe.TryCancel();
            }
        }
Esempio n. 8
0
        /** Multiplex an EdgeListener using Pathing with the IActionQueue managing the
         * Rrm.
         * @param el the EdgeListener to multiplex
         */
        public PathELManager(EdgeListener el, IActionQueue queue) : this(el, false)
        {
            PathELManagerAction pema = new PathELManagerAction(this);

            Action <DateTime> torun = delegate(DateTime now) {
                queue.EnqueueAction(pema);
            };

            _fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(torun, _period, _period / 2 + 1);
        }
Esempio n. 9
0
    /// <summary>We need some TAs.</summary>
    virtual public bool BeginFindingTAs()
    {
      if(Interlocked.Exchange(ref _running, 1) == 1) {
        return false;
      }

      _fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(SeekTAs, DELAY_MS, DELAY_MS / 2);
      // If we don't execute this now, the first one won't be called for DELAY_MS
      SeekTAs(DateTime.UtcNow);
      return true;
    }
Esempio n. 10
0
 public NetworkTest(StructuredNode node)
 {
     _node    = node;
     _fe      = FuzzyTimer.Instance.DoEvery(Run, 30 * 60 * 1000, 500);
     _running = 0;
     _sync    = new object();
     _db_con  = String.Format("URI=file:{0}.{1}.db,version=3",
                              _node.Realm, GetAddress(_node.Address));
     _current_iter = InitializeDatabase();
     Thread.MemoryBarrier();
     _node.StateChangeEvent += Stop;
 }
Esempio n. 11
0
        /// <summary>We need some TAs.</summary>
        virtual public bool BeginFindingTAs()
        {
            if (Interlocked.Exchange(ref _running, 1) == 1)
            {
                return(false);
            }

            _fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(SeekTAs, DELAY_MS, DELAY_MS / 2);
            // If we don't execute this now, the first one won't be called for DELAY_MS
            SeekTAs(DateTime.UtcNow);
            return(true);
        }
Esempio n. 12
0
 public NetworkTest(StructuredNode node)
 {
   _node = node;
   _fe = FuzzyTimer.Instance.DoEvery(Run, 30 * 60 * 1000, 500);
   _running = 0;
   _sync = new object();
   _db_con = String.Format("URI=file:{0}.{1}.db,version=3",
       _node.Realm, GetAddress(_node.Address));
   _current_iter = InitializeDatabase();
   Thread.MemoryBarrier();
   _node.StateChangeEvent += Stop;
 }
Esempio n. 13
0
    /// <summary>Creates a DhtAddressResolver Object.</summary>
    /// <param name="dht">The dht object to use for dht interactions.</param>
    /// <param name="ipop_namespace">The ipop namespace where the dhcp server
    /// is storing names.</param>
    public DhtAddressResolver(IDht dht, string ipop_namespace)
    {
      _dht = dht;
      _ipop_namespace = ipop_namespace;

      _last_results = new Dictionary<MemBlock, Address>();
      _results = new Dictionary<MemBlock, Address>();
      _attempts = new Dictionary<MemBlock, int>();
      _queued = new Dictionary<MemBlock, bool>();
      _mapping = new Dictionary<Channel, MemBlock>();
      _fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(CleanUp, CLEANUP_TIME_MS, CLEANUP_TIME_MS / 10);
      _stopped = 0;
    }
Esempio n. 14
0
        /// <summary>No more TAs are necessary.</summary>
        virtual public bool EndFindingTAs()
        {
            FuzzyEvent fe = _fe;

            if (Interlocked.Exchange(ref _running, 0) == 0)
            {
                return(false);
            }

            if (fe != null)
            {
                fe.TryCancel();
            }
            return(true);
        }
Esempio n. 15
0
        /** Multiplex an EdgeListener using Pathing with the IActionQueue managing the
         * Rrm.
         * @param el the EdgeListener to multiplex
         */
        public PathELManager(EdgeListener el, IActionQueue queue) : this(el, false)
        {
            PathELManagerAction pema_rrm  = new PathELManagerAction(this, ReqrepTimeoutChecker);
            Action <DateTime>   torun_rrm = delegate(DateTime now) {
                queue.EnqueueAction(pema_rrm);
            };

            _rrm_fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(torun_rrm, RRM_PERIOD, (RRM_PERIOD / 2) + 1);

            PathELManagerAction pema_edge  = new PathELManagerAction(this, EdgeTimeoutChecker);
            Action <DateTime>   torun_edge = delegate(DateTime now) {
                queue.EnqueueAction(pema_edge);
            };

            _edge_fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(torun_edge, EDGE_PERIOD, (EDGE_PERIOD / 2) + 1);
        }
Esempio n. 16
0
        /// <summary>Stops publishing using the dht proxy.</summary>
        override public bool Stop()
        {
            _dht_proxy.Unregister(_private_dht_key, _p2p_address);

            bool first = base.EndFindingTAs();

            if (Interlocked.Exchange(ref _steady_state, 0) == 1)
            {
                FuzzyEvent fe = _fe;
                if (fe != null)
                {
                    _fe.TryCancel();
                }
                first = true;
            }

            return(first);
        }
Esempio n. 17
0
        override public bool BeginFindingTAs()
        {
            if (Interlocked.Exchange(ref _steady_state, 0) == 1)
            {
                FuzzyEvent fe = _fe;
                if (fe != null)
                {
                    _fe.TryCancel();
                }
            }

            if (base.BeginFindingTAs())
            {
                return(true);
            }

            return(false);
        }
Esempio n. 18
0
    /**
    <summary>This method is registered as a delegate to Shutdown.OnExit and
    will be called when ctrl-c is pressed by the user.  This stops services,
    prevents the node from reincarnating, and then disconnects the node.
    </summary>
    */
    public virtual void OnExit() {
      _running = false;

      if(_xrm != null) {
        _xrm.Stop();
        _xrm = null;
      }

      ApplicationNode appnode = _app_node;
      _app_node = null;

      NCService ncservice = null;
      if(appnode != null) {
        ncservice = appnode.NCService;
      }

      if(ncservice != null && _node_config.NCService.Checkpointing) {
        string checkpoint = ncservice.GetCheckpoint();
        string prev_cp = _node_config.NCService.Checkpoint;
        string empty_cp = (new Point()).ToString();
        if(!checkpoint.Equals(prev_cp) && !checkpoint.Equals(empty_cp))
        {
          _node_config.NCService.Checkpoint = checkpoint;
          _node_config.WriteConfig();
        }
      }

      _fe_stop_pem = Brunet.Util.FuzzyTimer.Instance.DoEvery(StopPem, 500, 500);
    }
Esempio n. 19
0
    /** Multiplex an EdgeListener using Pathing with the IActionQueue managing the
     * Rrm.
     * @param el the EdgeListener to multiplex
     */
    public PathELManager(EdgeListener el, IActionQueue queue) : this(el, false) {
      PathELManagerAction pema = new PathELManagerAction(this);

      Action<DateTime> torun = delegate(DateTime now) {
        queue.EnqueueAction(pema);
      };

      _fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(torun, _period, _period / 2 + 1);
    }
Esempio n. 20
0
    /** Multiplex an EdgeListener using Pathing with the IActionQueue managing the
     * Rrm.
     * @param el the EdgeListener to multiplex
     */
    public PathELManager(EdgeListener el, IActionQueue queue) : this(el, false) {
      PathELManagerAction pema_rrm = new PathELManagerAction(this, ReqrepTimeoutChecker);
      Action<DateTime> torun_rrm = delegate(DateTime now) {
        queue.EnqueueAction(pema_rrm);
      };
      _rrm_fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(torun_rrm, RRM_PERIOD, (RRM_PERIOD / 2) + 1);

      PathELManagerAction pema_edge = new PathELManagerAction(this, EdgeTimeoutChecker);
      Action<DateTime> torun_edge = delegate(DateTime now) {
        queue.EnqueueAction(pema_edge);
      };
      _edge_fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(torun_edge, EDGE_PERIOD, (EDGE_PERIOD / 2) + 1);
    }
Esempio n. 21
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);
    }
Esempio n. 22
0
    /// <summary>Blocking may occur for two reasons, no data available or the
    /// handshake isn't complete.  If the handshake isn't complete, the timer
    /// will be set to >= 0, at 0, we need to call handshake to continue, if
    /// it is greater than 0, we need to schedule a timer to call handshake
    /// later.</summary>
    protected void HandleWouldBlock()
    {
      if(Closed) {
        return;
      }
      long to = _ssl.GetTimeout();
      if(to == 0) {
        _ssl.TimerExpired();
      }
      if(_read.BytesPending > 0) {
        HandleData(null, Sender, null);
      }
      if(_write.BytesPending > 0) {
        Send(null);
      }

#if !BRUNET_SIMULATOR
      if(to > 0 && Interlocked.Exchange(ref _fe_lock, 1) == 0) {
        _fe = FuzzyTimer.Instance.DoAfter(HandleWouldBlock, (int) to, 250);
      }
#endif
    }
Esempio n. 23
0
    /**
     * This is a System.Threading.ThreadStart delegate
     * We loop waiting for edges that need to send,
     * or data on the socket.
     *
     * This is the only thread that can touch the socket,
     * therefore, we do not need to lock the socket.
     */

    protected void MonitorLogOff()
    {
      Util.FuzzyEvent fe = _monitor_fe;
      _monitor_fe = null;
      if(fe != null) {
        fe.TryCancel();
      }
    }
Esempio n. 24
0
 override public void Start()
 {
     _check_state = FuzzyTimer.Instance.DoEvery(Activate, 3600000, 500);
     base.Start();
 }
Esempio n. 25
0
 override public void Start() {
   _check_state = FuzzyTimer.Instance.DoEvery(Activate, 3600000, 500);
   base.Start();
 }