Exemple #1
0
            public static void beginNetworkOperations()
            {
                if (netControllerThread != null)
                {
                    // already running
                    Logging.info("Network server thread is already running.");
                    return;
                }

                TLC = new ThreadLiveCheck();
                netControllerThread      = new Thread(networkOpsLoop);
                netControllerThread.Name = "Network_Server_Controller_Thread";
                connectedClients         = new List <RemoteEndpoint>();
                continueRunning          = true;

                // Read the server port from the configuration
                NetOpsData nod = new NetOpsData();

                nod.listenAddress = new IPEndPoint(IPAddress.Any, Config.serverPort);
                netControllerThread.Start(nod);

                // Retrieve the public-accessible IP address
                publicIPAddress = Config.publicServerIP; // CoreNetworkUtils.GetLocalIPAddress();


                Logging.info(string.Format("Public network node address: {0} port {1}", publicIPAddress, Config.serverPort));
            }
Exemple #2
0
        /// <summary>
        ///  Starts listening for and accepting network connections.
        /// </summary>
        public static void beginNetworkOperations()
        {
            if (netControllerThread != null)
            {
                // already running
                Logging.info("Network server thread is already running.");
                return;
            }

            if (IxianHandler.publicPort <= 0 || IxianHandler.publicPort > 65535)
            {
                Logging.error("Cannot start network server, public port is invalid");
                return;
            }

            if (CoreConfig.preventNetworkOperations)
            {
                Logging.warn("Not starting NetworkClientManager thread due to preventNetworkOperations flag being set.");
                return;
            }

            TLC = new ThreadLiveCheck();
            netControllerThread      = new Thread(networkOpsLoop);
            netControllerThread.Name = "Network_Server_Controller_Thread";
            connectedClients         = new List <RemoteEndpoint>();
            continueRunning          = true;

            // Read the server port from the configuration
            NetOpsData nod = new NetOpsData();

            nod.listenAddress = new IPEndPoint(IPAddress.Any, IxianHandler.publicPort);
            netControllerThread.Start(nod);

            Logging.info(string.Format("Public network node address: {0} port {1}", IxianHandler.publicIP, IxianHandler.publicPort));
        }
        // Start the network queue
        public static void start()
        {
            if (running)
            {
                return;
            }

            running = true;

            shouldStop = false;
            queueHighPriority.Clear();
            queueMediumPriority.Clear();
            queueLowPriority.Clear();

            TLC = new ThreadLiveCheck();

            queueHighPriorityThread      = new Thread(queueHighPriorityLoop);
            queueHighPriorityThread.Name = "Network_Queue_High_Priority_Thread";
            queueHighPriorityThread.Start();

            queueMediumPriorityThread      = new Thread(queueMediumPriorityLoop);
            queueMediumPriorityThread.Name = "Network_Queue_Medium_Priority_Thread";
            queueMediumPriorityThread.Start();

            queueLowPriorityThread      = new Thread(queueLowPriorityLoop);
            queueLowPriorityThread.Name = "Network_Queue_Low_Priority_Thread";
            queueLowPriorityThread.Start();

            Logging.info("Network queue thread started.");
        }
Exemple #4
0
        // Start the network queue
        public static void start()
        {
            if (running)
            {
                return;
            }

            running = true;

            shouldStop = false;
            queueMessages.Clear();
            txqueueMessages.Clear();

            TLC = new ThreadLiveCheck();
            // Multi-threaded network queue parsing
            for (int i = 0; i < 1; i++)
            {
                Thread queue_thread = new Thread(queueThreadLoop);
                queue_thread.Name = "Network_Queue_Thread_#" + i.ToString();
                queue_thread.Start();
            }

            Thread txqueue_thread = new Thread(txqueueThreadLoop);

            txqueue_thread.Name = "Network_Queue_TX_Thread";
            txqueue_thread.Start();

            Logging.info("Network queue thread started.");
        }
Exemple #5
0
        // Starts the mining threads
        public bool start()
        {
            if (Config.disableMiner)
            {
                return(false);
            }

            // Calculate the allowed number of threads based on logical processor count
            Config.miningThreads = calculateMiningThreadsCount(Config.miningThreads);
            Logging.info(String.Format("Starting miner with {0} threads on {1} logical processors.", Config.miningThreads, Environment.ProcessorCount));

            shouldStop = false;

            TLC = new ThreadLiveCheck();
            // Start primary mining thread
            Thread miner_thread = new Thread(threadLoop);

            miner_thread.Name = "Miner_Main_Thread";
            miner_thread.Start();

            // Start secondary worker threads
            for (int i = 0; i < Config.miningThreads - 1; i++)
            {
                Thread worker_thread = new Thread(secondaryThreadLoop);
                worker_thread.Name = "Miner_Worker_Thread_#" + i.ToString();
                worker_thread.Start();
            }

            return(true);
        }
Exemple #6
0
 public static void startKeepAlive()
 {
     TLC = new ThreadLiveCheck();
     // Start the keepalive thread
     autoKeepalive        = true;
     keepAliveThread      = new Thread(keepAlive);
     keepAliveThread.Name = "Presence_List_Keep_Alive_Thread";
     keepAliveThread.Start();
 }
Exemple #7
0
        public BlockSync()
        {
            synchronizing            = false;
            receivedAllMissingBlocks = false;

            running = true;
            TLC     = new ThreadLiveCheck();
            // Start the thread
            sync_thread      = new Thread(onUpdate);
            sync_thread.Name = "Block_Sync_Update_Thread";
            sync_thread.Start();
        }
Exemple #8
0
        // Starts the Network Client Manager. First it connects to one of the seed nodes in order to fetch the Presence List.
        // Afterwards, it starts the reconnect and keepalive threads
        public static void start()
        {
            if (running)
            {
                return;
            }

            if (CoreConfig.preventNetworkOperations)
            {
                Logging.warn("Not starting NetworkClientManager thread due to preventNetworkOperations flag being set.");
                return;
            }

            running        = true;
            networkClients = new List <NetworkClient>();

            PeerStorage.readPeersFile();

            // Now add the seed nodes to the list
            foreach (string[] addr in CoreNetworkUtils.getSeedNodes(CoreConfig.isTestNet))
            {
                byte[] wallet_addr = null;
                if (addr[1] != null)
                {
                    wallet_addr = Base58Check.Base58CheckEncoding.DecodePlain(addr[1]);
                }
                PeerStorage.addPeerToPeerList(addr[0], wallet_addr, false);
            }

            // Connect to a random node first
            bool firstSeedConnected = false;

            while (firstSeedConnected == false && IxianHandler.forceShutdown == false)
            {
                Peer p = PeerStorage.getRandomMasterNodeAddress();
                if (p != null)
                {
                    firstSeedConnected = connectTo(p.hostname, p.walletAddress);
                }
                if (firstSeedConnected == false)
                {
                    Thread.Sleep(1000);
                }
            }

            // Start the reconnect thread
            TLC                  = new ThreadLiveCheck();
            reconnectThread      = new Thread(reconnectClients);
            reconnectThread.Name = "Network_Client_Manager_Reconnect";
            autoReconnect        = true;
            reconnectThread.Start();
        }
        // Start the API server
        public void start(string listen_url, Dictionary <string, string> authorizedUsers = null)
        {
            continueRunning = true;

            listenURL = listen_url;

            this.authorizedUsers = authorizedUsers;

            apiControllerThread      = new Thread(apiLoop);
            apiControllerThread.Name = "API_Controller_Thread";
            TLC = new ThreadLiveCheck();
            apiControllerThread.Start();
        }
        // Starts the Network Client Manager. First it connects to one of the seed nodes in order to fetch the Presence List.
        // Afterwards, it starts the reconnect and keepalive threads
        public static void start()
        {
            if (running)
            {
                return;
            }
            running        = true;
            networkClients = new List <NetworkClient>();

            PeerStorage.readPeersFile();

            // Now add the seed nodes to the list
            foreach (string addr in CoreNetworkUtils.getSeedNodes(Config.isTestNet))
            {
                PeerStorage.addPeerToPeerList(addr, null, false);
            }

            // Connect to a random node first
            bool firstSeedConnected = false;

            while (firstSeedConnected == false)
            {
                string address = PeerStorage.getRandomMasterNodeAddress();
                if (address != "")
                {
                    firstSeedConnected = connectTo(address);
                }
                if (firstSeedConnected == false)
                {
                    Thread.Sleep(1000);
                }
            }

            // Start the reconnect thread
            TLC                  = new ThreadLiveCheck();
            reconnectThread      = new Thread(reconnectClients);
            reconnectThread.Name = "Network_Client_Manager_Reconnect";
            autoReconnect        = true;
            reconnectThread.Start();
        }
Exemple #11
0
 private NetDump()
 {
     TLC               = new ThreadLiveCheck();
     outputWriter      = new Thread(outputWriterWorker);
     outputWriter.Name = "Network_Dumper_Thread";
 }
        public void start(Socket socket = null)
        {
            if (fullyStopped)
            {
                Logging.error("Can't start a fully stopped RemoteEndpoint");
                return;
            }

            if (running)
            {
                return;
            }

            if (socket != null)
            {
                clientSocket = socket;
            }
            if (clientSocket == null)
            {
                Logging.error("Could not start NetworkRemoteEndpoint, socket is null");
                return;
            }

            prepareSocket(clientSocket);

            remoteIP        = (IPEndPoint)clientSocket.RemoteEndPoint;
            address         = remoteIP.Address.ToString();
            fullAddress     = address + ":" + remoteIP.Port;
            presence        = null;
            presenceAddress = null;

            connectionStartTime = Clock.getTimestamp();

            lock (subscribedAddresses)
            {
                subscribedAddresses.Clear();
            }

            lastDataReceivedTime = Clock.getTimestamp();
            lastDataSentTime     = Clock.getTimestamp();

            state = RemoteEndpointState.Established;

            timeDifference   = 0;
            timeSyncComplete = false;
            timeSyncs.Clear();

            running = true;

            // Abort all related threads
            if (recvThread != null)
            {
                recvThread.Abort();
                recvThread = null;
            }
            if (sendThread != null)
            {
                sendThread.Abort();
                sendThread = null;
            }
            if (parseThread != null)
            {
                parseThread.Abort();
                parseThread = null;
            }

            try
            {
                TLC = new ThreadLiveCheck();
                // Start receive thread
                recvThread      = new Thread(new ThreadStart(recvLoop));
                recvThread.Name = "Network_Remote_Endpoint_Receive_Thread";
                recvThread.Start();

                // Start send thread
                sendThread      = new Thread(new ThreadStart(sendLoop));
                sendThread.Name = "Network_Remote_Endpoint_Send_Thread";
                sendThread.Start();

                // Start parse thread
                parseThread      = new Thread(new ThreadStart(parseLoop));
                parseThread.Name = "Network_Remote_Endpoint_Parse_Thread";
                parseThread.Start();
            }
            catch (Exception e)
            {
                Logging.error("Exception start remote endpoint: {0}", e.Message);
            }
        }
Exemple #13
0
        // Starts the Network Client Manager.
        // If connections_to_wait_for parameter is bigger than 0, it waits until it connects to the specified number of nodes.
        // Afterwards, it starts the reconnect and keepalive threads
        public static void start(int connections_to_wait_for = 0)
        {
            if (running)
            {
                return;
            }

            if (CoreConfig.preventNetworkOperations)
            {
                Logging.warn("Not starting NetworkClientManager thread due to preventNetworkOperations flag being set.");
                return;
            }

            running           = true;
            networkClients    = new List <NetworkClient>();
            connectingClients = new List <string>();

            PeerStorage.readPeersFile();

            // Now add the seed nodes to the list
            foreach (string[] addr in CoreNetworkUtils.getSeedNodes(IxianHandler.networkType))
            {
                byte[] wallet_addr = null;
                if (addr[1] != null)
                {
                    wallet_addr = Base58Check.Base58CheckEncoding.DecodePlain(addr[1]);
                }
                PeerStorage.addPeerToPeerList(addr[0], wallet_addr, Clock.getTimestamp(), 0, 1, 0, false);
            }

            if (connections_to_wait_for > 0)
            {
                Random rnd = new Random();
                // Connect to a random node first
                int i = 0;
                while (getConnectedClients(true).Count() < connections_to_wait_for && IxianHandler.forceShutdown == false)
                {
                    new Thread(() =>
                    {
                        reconnectClients(rnd);
                    }).Start();
                    i++;
                    if (i > 10)
                    {
                        i = 0;
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        Thread.Sleep(200);
                    }
                    if (!running)
                    {
                        return;
                    }
                }
            }

            // Start the reconnect thread
            TLC = new ThreadLiveCheck();

            autoReconnect        = true;
            reconnectThread      = new Thread(reconnectLoop);
            reconnectThread.Name = "Network_Client_Manager_Reconnect";
            reconnectThread.Start();
        }