예제 #1
0
 /// <summary>Called when the Node changes state, stops the Test if necessary.</summary>
 protected void Stop(Node n, Node.ConnectionState cs)
 {
     if (cs == Node.ConnectionState.Leaving ||
         cs == Node.ConnectionState.Disconnected)
     {
         Stop();
     }
 }
예제 #2
0
 protected void StateChangeHandler(Node n, Node.ConnectionState state)
 {
     if (state == Node.ConnectionState.Connected)
     {
         lock (_sync) {
             _allow_localcons = true;
         }
     }
     else if (state == Node.ConnectionState.Leaving)
     {
         lock (_sync) {
             _active = false;
         }
     }
 }
예제 #3
0
파일: Dht.cs 프로젝트: pcbing/brunet
 /// <summary>We're online once we are seeking connections, we're offline
 /// once Disconnect has been called.</summary>
 protected void StateChangeHandler(Node n, Node.ConnectionState state)
 {
     lock (_sync) {
         if (state == Node.ConnectionState.Leaving ||
             state == Node.ConnectionState.Disconnected ||
             state == Node.ConnectionState.Offline)
         {
             _online = false;
         }
         else
         {
             _online = true;
         }
     }
 }
예제 #4
0
        /// <summary> Occassionally nodes will get a true return from a allocation
        /// attempt, in order to prevent this, we reissue all dhcp requests after
        /// getting "connected" to the overlay.</summary>
        protected void StateChangeHandler(Node n, Node.ConnectionState state)
        {
            List <MemBlock> ips = null;

            lock (_sync) {
                if (state == Node.ConnectionState.Connected)
                {
                    if (_connected)
                    {
                        return;
                    }
                    AppNode.Node.StateChangeEvent -= StateChangeHandler;
                    _connected = true;
                }
                else
                {
                    return;
                }

                ips = new List <MemBlock>(_ip_to_ether.Keys.Count);
                foreach (MemBlock ip in _ip_to_ether.Keys)
                {
                    ips.Add(ip);
                }
            }

            WaitCallback callback = delegate(object o) {
                // Get a new Dhcp server so we get new state!
                DhcpServer dhcp_server = GetDhcpServer();
                foreach (MemBlock ip in ips)
                {
                    try {
                        dhcp_server.RequestLease(ip, true, AppNode.Node.Address.ToString(),
                                                 _ipop_config.AddressData.Hostname);
                    } catch (Exception e) {
                        ProtocolLog.WriteIf(IpopLog.DhcpLog, e.Message);
                    }
                }
            };

            ThreadPool.QueueUserWorkItem(callback, null);
        }