public StatsConsoleScreen()
        {
            Console.Clear();

            Console.CursorVisible = Config.verboseConsoleOutput;

            // Start thread
            TLC         = new ThreadLiveCheck();
            running     = true;
            thread      = new Thread(new ThreadStart(threadLoop));
            thread.Name = "Stats_Console_Thread";
            thread.Start();

            startTime = DateTime.UtcNow;
        }
Beispiel #2
0
            public virtual bool prepareStorage()
            {
                if (!prepareStorageInternal())
                {
                    return(false);
                }
                // Start thread
                TLC         = new ThreadLiveCheck();
                running     = true;
                thread      = new Thread(new ThreadStart(threadLoop));
                thread.Name = "Storage_Thread";
                thread.Start();

                return(true);
            }
Beispiel #3
0
            // Setup and start the logging thread
            public static void start()
            {
                if (running)
                {
                    if (consoleOutput)
                    {
                        Console.WriteLine("Logging already started.");
                    }
                    return;
                }
                try
                {
                    // Obtain paths and cache them
                    folderpath      = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                    logfilepath     = Path.Combine(folderpath, Path.GetFileNameWithoutExtension(logfilename));
                    wildcard        = Path.GetFileNameWithoutExtension(logfilename) + "*" + Path.GetExtension(logfilename);
                    logfilepathpart = Path.Combine(folderpath, Path.GetFileNameWithoutExtension(logfilename));

                    // Roll the previous log
                    roll(true);

                    // Create the main log file
                    byte[] logMessage = Encoding.UTF8.GetBytes("Ixian Log" + Environment.NewLine);
                    logFileStream.Write(logMessage, 0, logMessage.Length);

                    // Start thread
                    TLC         = new ThreadLiveCheck();
                    running     = true;
                    thread      = new Thread(new ThreadStart(threadLoop));
                    thread.Name = "Logging_Thread";
                    thread.Start();
                }
                catch (Exception e)
                {
                    // Ignore all exception and start anyway with console only logging.
                    Console.WriteLine(String.Format("Unable to open log file. Error was: {0}. Logging to console only.", e.Message));
                }
            }
Beispiel #4
0
        // Start the node
        public void start(bool verboseConsoleOutput)
        {
            char node_type = 'M'; // TODO TODO TODO TODO change this to 'W' or 'C' after the upgrade

            if (Config.disableMiner)
            {
                node_type = 'M';
            }

            // Check if we're in worker-only mode
            if (Config.workerOnly)
            {
                // Enable miner
                Config.disableMiner = false;
                node_type           = 'W';
                CoreConfig.simultaneousConnectedNeighbors = 4;
            }

            // Generate presence list
            PresenceList.init(IxianHandler.publicIP, Config.serverPort, node_type);

            // Initialize storage
            Storage.prepareStorage();

            ActivityStorage.prepareStorage();

            // Initialize the block chain
            blockChain = new BlockChain();

            //runDiffTests();
            //return;

            // Create the block processor and sync
            blockProcessor = new BlockProcessor();
            blockSync      = new BlockSync();


            if (Config.devInsertFromJson)
            {
                Console.WriteLine("Inserting from JSON");
                devInsertFromJson();
                Program.noStart = true;
                return;
            }

            if (Config.apiBinds.Count == 0)
            {
                Config.apiBinds.Add("http://localhost:" + Config.apiPort + "/");
            }

            // Start the HTTP JSON API server
            apiServer = new APIServer(Config.apiBinds, Config.apiUsers, Config.apiAllowedIps);

            if (IXICore.Platform.onMono() == false && !Config.disableWebStart)
            {
                System.Diagnostics.Process.Start(Config.apiBinds[0]);
            }

            miner = new Miner();

            // Start the network queue
            NetworkQueue.start();

            // prepare stats screen
            ConsoleHelpers.verboseConsoleOutput = verboseConsoleOutput;
            Logging.consoleOutput = verboseConsoleOutput;
            Logging.flush();
            if (ConsoleHelpers.verboseConsoleOutput == false)
            {
                statsConsoleScreen.clearScreen();
            }

            // Distribute genesis funds
            IxiNumber genesisFunds = new IxiNumber(Config.genesisFunds);

            // Check if this is a genesis node
            if (genesisFunds > (long)0)
            {
                Logging.info(String.Format("Genesis {0} specified. Starting operation.", genesisFunds));

                distributeGenesisFunds(genesisFunds);

                genesisNode = true;
                blockProcessor.resumeOperation();
                serverStarted = true;
                if (!isMasterNode())
                {
                    Logging.info("Network server is not enabled in modes other than master node.");
                }
                else
                {
                    NetworkServer.beginNetworkOperations();
                }
            }
            else
            {
                if (File.Exists(Config.genesisFile))
                {
                    Block genesis = new Block(Crypto.stringToHash(File.ReadAllText(Config.genesisFile)));
                    blockChain.setGenesisBlock(genesis);
                }
                ulong lastLocalBlockNum = Meta.Storage.getLastBlockNum();
                if (lastLocalBlockNum > 6)
                {
                    lastLocalBlockNum = lastLocalBlockNum - 6;
                }
                if (Config.lastGoodBlock > 0 && Config.lastGoodBlock < lastLocalBlockNum)
                {
                    lastLocalBlockNum = Config.lastGoodBlock;
                }
                if (lastLocalBlockNum > 0)
                {
                    Block b = blockChain.getBlock(lastLocalBlockNum, true);
                    if (b != null)
                    {
                        ConsensusConfig.minRedactedWindowSize = ConsensusConfig.getRedactedWindowSize(b.version);
                        ConsensusConfig.redactedWindowSize    = ConsensusConfig.getRedactedWindowSize(b.version);
                    }
                }

                if (Config.recoverFromFile)
                {
                    Block b = Meta.Storage.getBlock(lastLocalBlockNum);
                    blockSync.onHelloDataReceived(b.blockNum, b.blockChecksum, b.version, b.walletStateChecksum, b.getSignatureCount(), lastLocalBlockNum);
                }
                else
                {
                    ulong blockNum = WalletStateStorage.restoreWalletState(lastLocalBlockNum);
                    if (blockNum > 0)
                    {
                        Block b = blockChain.getBlock(blockNum, true);
                        if (b != null)
                        {
                            blockSync.onHelloDataReceived(blockNum, b.blockChecksum, b.version, b.walletStateChecksum, b.getSignatureCount(), lastLocalBlockNum);
                        }
                        else
                        {
                            walletState.clear();
                        }
                    }
                    else
                    {
                        blockSync.lastBlockToReadFromStorage = lastLocalBlockNum;
                    }

                    // Start the server for ping purposes
                    serverStarted = true;
                    if (!isMasterNode())
                    {
                        Logging.info("Network server is not enabled in modes other than master node.");
                    }
                    else
                    {
                        NetworkServer.beginNetworkOperations();
                    }

                    // Start the network client manager
                    NetworkClientManager.start();
                }
            }

            PresenceList.startKeepAlive();

            TLC = new ThreadLiveCheck();
            // Start the maintenance thread
            maintenanceThread      = new Thread(performMaintenance);
            maintenanceThread.Name = "Node_Maintenance_Thread";
            maintenanceThread.Start();
        }