Exemplo n.º 1
0
        private void update_cloudlist_threadstart()
        {
            DateTime last_update = DateTime.MinValue;
            TimeSpan ts          = new TimeSpan();

            xbs_messages.addInfoMessage(" x started cloudlist updater", xbs_message_sender.CLOUDLIST);
#if !DEBUG
            try
            {
#endif
            while (part_of_cloud)
            {
                ts = DateTime.Now - last_update;
                if (ts.TotalSeconds > xbs_cloudlist.UPDATE_INTERVAL_SECONDS)
                {
                    sendUpdateToCloudlistserver();
                    last_update = DateTime.Now;
                }
                Thread.Sleep(1000);
            }
#if !DEBUG
        }

        catch (Exception ex)
        {
            ExceptionMessage.ShowExceptionDialog("update_cloudlist service", ex);
        }
#endif
        }
Exemplo n.º 2
0
        public void dispatcher()
        {
            xbs_messages.addInfoMessage(" * udp listener dispatcher thread starting...", xbs_message_sender.UDP_LISTENER);
#if !DEBUG
            try
            {
#endif
            while (!exiting)
            {
                lock (_locker)
                {
                    Monitor.Wait(_locker);
                }
                if (!exiting)
                {
                    dispatch_in_qeue();
                }
            }
#if !DEBUG
        }

        catch (Exception ex)
        {
            ExceptionMessage.ShowExceptionDialog("udp dispatcher service", ex);
        }
#endif
#if DEBUG
            xbs_messages.addDebugMessage(" * udp listener dispatcher thread stopped.", xbs_message_sender.UDP_LISTENER);
#endif
        }
Exemplo n.º 3
0
        private void ping_nodes_thread()
        {
            xbs_messages.addInfoMessage(" + starting node survey service", xbs_message_sender.NODELIST);
#if !DEBUG
            try
            {
#endif
            while (run_ping_nodes_loop)
            {
                if (xbs_udp_listener.getInstance() != null)
                {
                    refreshAllNodes();
                }
                checkNodesInAddingList();
                if (run_ping_nodes_loop)
                {
                    Thread.Sleep(1000);
                }
            }
#if !DEBUG
        }

        catch (Exception ex)
        {
            ExceptionMessage.ShowExceptionDialog("node survey service", ex);
        }
#endif
        }
Exemplo n.º 4
0
        public void dispatcher()
        {
            xbs_messages.addInfoMessage(" - sniffer dispatcher thread starting...", xbs_message_sender.SNIFFER);
            int        count = 0;
            RawCapture p     = null;

#if !DEBUG
            try
            {
#endif
            // loop dispatcher thread until exiting flag is raised
            while (exiting == false)
            {
                lock (packets)
                    count = packets.Count;

                // dispatch all packets in queue
                while (count > 0 && exiting == false)
                {
                    lock (packets)
                        p = packets.Dequeue();
                    dispatch_packet(ref p);
                    lock (packets)
                        count = packets.Count;
                }

                // goto sleep until new packets arrive
                if (!exiting)
                {
                    lock (packets)
                        Monitor.Wait(packets);
                }
            }
#if !DEBUG
        }

        catch (Exception ex)
        {
            ExceptionMessage.ShowExceptionDialog("sniffer dispatcher service", ex);
        }
#endif
        }
Exemplo n.º 5
0
        public void udp_receiver()
        {
            xbs_messages.addInfoMessage(" * udp receiver thread started", xbs_message_sender.UDP_LISTENER);
            byte[]          data            = new byte[2048];
            IPEndPoint      remote_endpoint = new IPEndPoint(IPAddress.Any, 0);
            EndPoint        ep             = (EndPoint)remote_endpoint;
            int             bytes_received = 0;
            xbs_udp_message msg            = null;

#if !DEBUG
            try
            {
#endif
            while (!exiting)
            {
                try
                {
                    bytes_received = udp_socket.ReceiveFrom(data, ref ep);
                }
                catch (SocketException)
                {
                    bytes_received = 0;
                }
                if (!exiting && bytes_received > 0)
                {
                    xbs_node_message_type command = xbs_node_message.getMessageTypeFromUDPPacket(data);
                    msg          = new xbs_udp_message();
                    msg.msg_type = command;
                    if (bytes_received > 3)
                    {
                        msg.data_len = xbs_node_message.getDataLengthFromUDPPacket(data);
                        if (msg.data_len + sizeof(UInt16) + sizeof(xbs_node_message_type) == bytes_received)
                        {
                            msg.data = new byte[msg.data_len];
                            Buffer.BlockCopy(data, xbs_udp_message.HEADER_LENGTH, msg.data, 0, msg.data_len);
                        }
                        else
                        {
#if DEBUG
                            xbs_messages.addInfoMessage("received packet with wrong length! expected " + msg.data_len + " but got " + (bytes_received - sizeof(UInt16) - sizeof(xbs_node_message_type)) + " bytes.", xbs_message_sender.UDP_LISTENER, xbs_message_type.ERROR);
#endif
                            msg = null;
                        }
                    }
                    else
                    {
                        msg.data_len = 0;
                    }

                    if (msg != null)
                    {
                        remote_endpoint = (IPEndPoint)ep;
                        msg.src_ip      = remote_endpoint.Address;
                        msg.src_port    = remote_endpoint.Port;
                        lock (_locker)
                        {
                            if (command == xbs_node_message_type.DATA)
                            {
                                lock (in_msgs_high_prio)
                                    in_msgs_high_prio.Enqueue(msg);
                            }
                            else
                            {
                                lock (in_msgs)
                                    in_msgs.Enqueue(msg);
                            }
                            Monitor.PulseAll(_locker);
                        }
                    }
                }
            }
#if !DEBUG
        }

        catch (Exception ex)
        {
            ExceptionMessage.ShowExceptionDialog("udp_receiver service", ex);
        }
#endif
#if DEBUG
            xbs_messages.addDebugMessage(" * udp receiver thread stopped", xbs_message_sender.UDP_LISTENER);
#endif
        }