コード例 #1
0
        public Node()
        {
#if DEBUG
            Logging.warn("Testing language files");
            SpixiLocalization.testLanguageFiles("en-us");
#endif

            Logging.info("Initing node constructor");

            Instance = this;

            IxianHandler.init(Config.version, this, Config.networkType);

            // Prepare the wallet
            walletStorage = new WalletStorage(Path.Combine(Config.spixiUserFolder, Config.walletFile));

            PeerStorage.init(Config.spixiUserFolder);

            // Init TIV
            tiv = new TransactionInclusion();

            Logging.info("Initing local storage");

            // Prepare the local storage
            localStorage = new SPIXI.Storage.LocalStorage(Config.spixiUserFolder);

            customAppManager = new CustomAppManager(Config.spixiUserFolder);

            FriendList.init(Config.spixiUserFolder);

            Logging.info("Node init done");
        }
コード例 #2
0
ファイル: Node.cs プロジェクト: ProjectIxian/Ixian-S2
        // Perform basic initialization of node
        private void init()
        {
            running = true;

            CoreConfig.maximumServerMasterNodes = Config.maximumStreamClients;
            CoreConfig.maximumServerClients     = Config.maximumStreamClients;

            UpdateVerify.init(Config.checkVersionUrl, Config.checkVersionSeconds);

            // Network configuration
            NetworkUtils.configureNetwork(Config.externalIp, Config.serverPort);

            // Load or Generate the wallet
            if (!initWallet())
            {
                running            = false;
                S2.Program.noStart = true;
                return;
            }

            // Setup the stats console
            statsConsoleScreen = new StatsConsoleScreen();

            PeerStorage.init("");

            // Init TIV
            tiv = new TransactionInclusion();
        }
コード例 #3
0
        // Perform periodic cleanup tasks
        private static void performMaintenance()
        {
            while (running)
            {
                TLC.Report();
                // Sleep a while to prevent cpu usage
                Thread.Sleep(10000);

                try
                {
                    TransactionPool.processPendingTransactions();

                    // Cleanup the presence list
                    PresenceList.performCleanup();

                    inventoryCache.processCache();

                    if (update() == false)
                    {
                        IxianHandler.forceShutdown = true;
                    }

                    // Remove expired peers from blacklist
                    PeerStorage.updateBlacklist();
                }
                catch (Exception e)
                {
                    Logging.error("Exception occured in Node.performMaintenance: " + e);
                }
            }
        }
コード例 #4
0
ファイル: Node.cs プロジェクト: AyzeGamingFR/Ixian-LiteWallet
        // Perform basic initialization of node
        private void init()
        {
            Logging.consoleOutput = false;

            CoreConfig.isTestNet = false;

            running = true;

            // Load or Generate the wallet
            if (!initWallet())
            {
                running = false;
                IxianLiteWallet.Program.noStart = true;
                return;
            }

            Console.WriteLine("Connecting to Ixian network...");

            string headers_path = "";

            if (!CoreConfig.isTestNet)
            {
                headers_path = "headers";
            }
            else
            {
                headers_path = "testnet-headers";
                PeerStorage.init("", "testner-peers.ixi");
            }

            // Init TIV
            tiv = new TransactionInclusion(headers_path);
        }
コード例 #5
0
        public Node()
        {
            Instance = this;

            CoreConfig.productVersion = Config.version;
            IxianHandler.setHandler(this);

            CoreConfig.isTestNet = Config.isTestNet;

            // Initialize the crypto manager
            CryptoManager.initLib();

            // Prepare the wallet
            walletStorage = new WalletStorage(Path.Combine(Config.spixiUserFolder, Config.walletFile));

            string peers_filename = "peers.ixi";

            if (CoreConfig.isTestNet)
            {
                peers_filename = "testnet-peers.ixi";
            }

            PeerStorage.init(Config.spixiUserFolder, peers_filename);

            ulong block_height = 1;

            byte[] block_checksum = null;

            if (!walletStorage.walletExists())
            {
                block_height   = Config.bakedBlockHeight;
                block_checksum = Config.bakedBlockChecksum;
            }

            string headers_path = "";

            if (!Config.isTestNet)
            {
                headers_path = Path.Combine(Config.spixiUserFolder, "headers");
            }
            else
            {
                // Temporary hack for our beta testers, remove before release
                string tmp_path = Path.Combine(Config.spixiUserFolder, "headers");
                BlockHeaderStorage.init(tmp_path);
                BlockHeaderStorage.deleteCache();
                BlockHeaderStorage.stop();
                // End of hack

                headers_path = Path.Combine(Config.spixiUserFolder, "testnet-headers");
            }
            // Init TIV
            tiv = new TransactionInclusion(headers_path, block_height, block_checksum);

            // Prepare the local storage
            localStorage = new SPIXI.Storage.LocalStorage(Config.spixiUserFolder);

            customAppManager = new CustomAppManager(Config.spixiUserFolder);
        }
コード例 #6
0
        private async Task InitPeerManager()
        {
            _logger.Info("Initializing peer manager");

            var peerStorage = new PeerStorage(_configProvider, _nodeFactory, _logManager, _perfService);
            var peerManager = new PeerManager(_localPeer, _discoveryManager, _syncManager, _nodeStatsProvider, peerStorage, _nodeFactory, _configProvider, _perfService, _logManager);
            await peerManager.Start();

            _logger.Info("Peer manager initialization completed");
        }
コード例 #7
0
        private static void handleDisconnectedClients()
        {
            List <NetworkClient> netClients = null;

            lock (networkClients)
            {
                netClients = new List <NetworkClient>(networkClients);
            }

            // Prepare a list of failed clients
            List <NetworkClient> failed_clients = new List <NetworkClient>();

            List <NetworkClient> dup_clients = new List <NetworkClient>();

            foreach (NetworkClient client in netClients)
            {
                if (dup_clients.Find(x => x.getFullAddress(true) == client.getFullAddress(true)) != null)
                {
                    failed_clients.Add(client);
                    continue;
                }
                dup_clients.Add(client);
                if (client.isConnected())
                {
                    continue;
                }
                // Check if we exceeded the maximum reconnect count
                if (client.getTotalReconnectsCount() >= CoreConfig.maximumNeighborReconnectCount || client.fullyStopped)
                {
                    // Remove this client so we can search for a new neighbor
                    failed_clients.Add(client);
                    PeerStorage.decreaseRating(client.getFullAddress(true), 1);
                }
                else
                {
                    // Reconnect
                    client.reconnect();
                }
            }

            // Go through the list of failed clients and remove them
            foreach (NetworkClient client in failed_clients)
            {
                client.stop();
                lock (networkClients)
                {
                    networkClients.Remove(client);
                }
                // Remove this node from the connecting clients list
                lock (connectingClients)
                {
                    connectingClients.Remove(client.getFullAddress(true));
                }
            }
        }
コード例 #8
0
        // Cleans the storage cache and logs
        public static bool cleanCacheAndLogs()
        {
            ActivityStorage.deleteCache();

            PeerStorage.deletePeersFile();

            Logging.clear();

            Logging.info("Cleaned cache and logs.");
            return(true);
        }
コード例 #9
0
ファイル: Node.cs プロジェクト: AyzeGamingFR/Spixi
        public Node()
        {
            Instance = this;

            CoreConfig.productVersion = Config.version;
            IxianHandler.setHandler(this);

            CoreConfig.isTestNet = Config.isTestNet;

            // Prepare the wallet
            walletStorage = new WalletStorage(Path.Combine(Config.spixiUserFolder, Config.walletFile));

            string peers_filename = "peers.ixi";

            if (CoreConfig.isTestNet)
            {
                peers_filename = "testnet-peers.ixi";
            }

            PeerStorage.init(Config.spixiUserFolder, peers_filename);

            ulong block_height = 1;

            byte[] block_checksum = null;

            string headers_path;

            if (Config.isTestNet)
            {
                headers_path = Path.Combine(Config.spixiUserFolder, "testnet-headers");
            }
            else
            {
                headers_path = Path.Combine(Config.spixiUserFolder, "headers");
                if (!walletStorage.walletExists())
                {
                    block_height   = Config.bakedBlockHeight;
                    block_checksum = Config.bakedBlockChecksum;
                }
                else
                {
                    block_height   = Config.bakedRecoveryBlockHeight;
                    block_checksum = Config.bakedRecoveryBlockChecksum;
                }
            }
            // Init TIV
            tiv = new TransactionInclusion(headers_path, block_height, block_checksum);

            // Prepare the local storage
            localStorage = new SPIXI.Storage.LocalStorage(Config.spixiUserFolder);

            customAppManager = new CustomAppManager(Config.spixiUserFolder);
        }
コード例 #10
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();
        }
コード例 #11
0
        // Perform basic initialization of node
        public void init()
        {
            running = true;

            // First create the data folder if it does not already exist
            checkDataFolder();

            renameStorageFiles(); // this function will be here temporarily for the next few version, then it will be removed to keep a cleaner code base

            // debug
            if (Config.networkDumpFile != "")
            {
                NetDump.Instance.start(Config.networkDumpFile);
            }

            UpdateVerify.init(Config.checkVersionUrl, Config.checkVersionSeconds);

            // Initialize storage
            if (storage is null)
            {
                storage = IStorage.create(Config.blockStorageProvider);
            }
            if (!storage.prepareStorage())
            {
                Logging.error("Error while preparing block storage! Aborting.");
                Program.noStart = true;
                return;
            }

            NetworkUtils.configureNetwork(Config.externalIp, Config.serverPort);

            // Load or Generate the wallet
            if (!initWallet())
            {
                storage.stopStorage();
                running = false;
                DLTNode.Program.noStart = true;
                return;
            }

            // Setup the stats console
            statsConsoleScreen = new StatsConsoleScreen();

            // Initialize the wallet state
            walletState = new WalletState();

            inventoryCache = new InventoryCacheDLT();

            PeerStorage.init("");
        }
コード例 #12
0
        // Perform basic initialization of node
        private void init()
        {
            running = true;

            CoreConfig.maximumServerMasterNodes = Config.maximumStreamClients;
            CoreConfig.maximumServerClients     = Config.maximumStreamClients;

            UpdateVerify.init(Config.checkVersionUrl, Config.checkVersionSeconds);

            // Network configuration
            NetworkUtils.configureNetwork(Config.externalIp, Config.serverPort);

            // Load or Generate the wallet
            if (!initWallet())
            {
                running = false;
                SpixiBot.Program.noStart = true;
                return;
            }

            // Setup the stats console
            statsConsoleScreen = new StatsConsoleScreen();

            PeerStorage.init("");

            // Init TIV
            tiv = new TransactionInclusion();

            string avatarPath = Path.Combine(Config.dataDirectory, "Avatars");

            users = new BotUsers(Path.Combine(Config.dataDirectory, "contacts.dat"), avatarPath, false);
            users.loadContactsFromFile();

            groups = new BotGroups(Path.Combine(Config.dataDirectory, "groups.dat"));
            groups.loadGroupsFromFile();

            channels = new BotChannels(Path.Combine(Config.dataDirectory, "channels.dat"));
            channels.loadChannelsFromFile();

            StreamProcessor.init(Path.Combine(Config.dataDirectory, "Messages"));
        }
コード例 #13
0
        // Perform basic initialization of node
        private void init()
        {
            Logging.consoleOutput = false;

            running = true;

            // Load or Generate the wallet
            if (!initWallet())
            {
                running = false;
                IxianLiteWallet.Program.running = false;
                return;
            }

            Console.WriteLine("Connecting to Ixian network...");

            PeerStorage.init("");

            // Init TIV
            tiv = new TransactionInclusion();
        }
コード例 #14
0
        // Cleans the storage cache and logs
        public static bool cleanCacheAndLogs()
        {
            ActivityStorage.deleteCache();

            // deleting block storage is a special case
            // we have to instantiate whatever implementation we are using and remove its data files

            /*storage = IStorage.create(Config.blockStorageProvider);
             * storage.deleteData();*/

            Storage.deleteCache();

            WalletStateStorage.deleteCache();

            PeerStorage.deletePeersFile();

            Logging.clear();

            Logging.info("Cleaned cache and logs.");
            return(true);
        }
コード例 #15
0
        public Node()
        {
            CoreConfig.productVersion = Config.version;
            IxianHandler.setHandler(this);

            CoreConfig.isTestNet = Config.isTestNet;

            // Initialize the crypto manager
            CryptoManager.initLib();

            // Prepare the wallet
            walletStorage = new WalletStorage(Path.Combine(Config.spixiUserFolder, Config.walletFile));

            string peers_filename = "peers.ixi";

            if (CoreConfig.isTestNet)
            {
                peers_filename = "testnet-peers.ixi";
            }

            PeerStorage.init(Config.spixiUserFolder, peers_filename);
        }
コード例 #16
0
ファイル: Node.cs プロジェクト: tomaszlt/Spixi
        public Node()
        {
#if DEBUG
            Logging.warn("Testing language files");
            Lang.SpixiLocalization.testLanguageFiles("en-us");
#endif


            Logging.info("Initing node constructor");

            Instance = this;

            CoreConfig.simultaneousConnectedNeighbors = 6;

            IxianHandler.init(Config.version, this, Config.networkType);

            PeerStorage.init(Config.spixiUserFolder);

            // Init TIV
            tiv = new TransactionInclusion();

            Logging.info("Initing local storage");

            // Prepare the local storage
            localStorage = new SPIXI.Storage.LocalStorage(Config.spixiUserFolder);

            customAppManager = new CustomAppManager(Config.spixiUserFolder);

            FriendList.init(Config.spixiUserFolder);

            Logging.info("Node init done");

            string backup_file_name = Path.Combine(Config.spixiUserFolder, "spixi.account.backup.ixi");
            if (File.Exists(backup_file_name))
            {
                File.Delete(backup_file_name);
            }
        }
コード例 #17
0
        public static void readFromCommandLine(string[] args)
        {
            // first pass
            var cmd_parser = new FluentCommandLineParser();

            // help
            cmd_parser.SetupHelp("h", "help").Callback(text => outputHelp());

            // config file
            cmd_parser.Setup <string>("config").Callback(value => configFilename = value).Required();

            cmd_parser.Parse(args);

            if (S2.Program.noStart)
            {
                return;
            }

            readConfigFile(configFilename);



            // second pass
            cmd_parser = new FluentCommandLineParser();

            // testnet
            cmd_parser.Setup <bool>('t', "testnet").Callback(value => CoreConfig.isTestNet = true).Required();

            cmd_parser.Parse(args);

            if (CoreConfig.isTestNet)
            {
                Config.serverPort = defaultTestnetServerPort;
                apiPort           = testnetApiPort;
                PeerStorage.init(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "testnet-peers.dat");
            }
            else
            {
                Config.serverPort = defaultServerPort;
                PeerStorage.init(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
            }



            string seedNode = "";

            // third pass
            cmd_parser = new FluentCommandLineParser();

            bool start_clean = false; // Flag to determine if node should delete cache+logs

            // version
            cmd_parser.Setup <bool>('v', "version").Callback(text => outputVersion());

            // Check for password change
            cmd_parser.Setup <bool>('x', "changepass").Callback(value => changePass = value).Required();

            // Check for clean parameter
            cmd_parser.Setup <bool>('c', "clean").Callback(value => start_clean = value).Required();


            cmd_parser.Setup <int>('p', "port").Callback(value => Config.serverPort = value).Required();

            cmd_parser.Setup <int>('a', "apiport").Callback(value => apiPort = value).Required();

            cmd_parser.Setup <string>('i', "ip").Callback(value => externalIp = value).Required();

            cmd_parser.Setup <string>('w', "wallet").Callback(value => walletFile = value).Required();

            cmd_parser.Setup <string>('n', "node").Callback(value => seedNode = value).Required();

            cmd_parser.Setup <int>("maxLogSize").Callback(value => maxLogSize = value).Required();

            cmd_parser.Setup <int>("maxLogCount").Callback(value => maxLogCount = value).Required();

            cmd_parser.Setup <bool>("disableWebStart").Callback(value => disableWebStart = true).Required();

            cmd_parser.Setup <bool>("onlyShowAddresses").Callback(value => onlyShowAddresses = true).Required();


            // Debug
            cmd_parser.Setup <string>("netdump").Callback(value => networkDumpFile = value).SetDefault("");

            cmd_parser.Setup <int>("forceTimeOffset").Callback(value => CoreConfig.forceTimeOffset = value).Required();

            cmd_parser.Setup <bool>("generateWallet").Callback(value => generateWalletOnly = value).SetDefault(false);

            cmd_parser.Setup <string>("walletPassword").Callback(value => dangerCommandlinePasswordCleartextUnsafe = value).SetDefault("");

            cmd_parser.Setup <bool>("testClient").Callback(value => isTestClient = true).Required();

            cmd_parser.Parse(args);


            // Validate parameters

            if (start_clean)
            {
                Node.cleanCacheAndLogs();
            }

            if (seedNode != "")
            {
                if (CoreConfig.isTestNet)
                {
                    CoreNetworkUtils.seedTestNetNodes = new List <string[]>
                    {
                        new string[2] {
                            seedNode, null
                        }
                    };
                }
                else
                {
                    CoreNetworkUtils.seedNodes = new List <string[]>
                    {
                        new string[2] {
                            seedNode, null
                        }
                    };
                }
            }
        }
コード例 #18
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();
        }
コード例 #19
0
ファイル: Config.cs プロジェクト: AyzeGamingFR/Ixian-DLT
            public static void readFromCommandLine(string[] args)
            {
                // first pass
                var cmd_parser = new FluentCommandLineParser();

                // help
                cmd_parser.SetupHelp("h", "help").Callback(text => outputHelp());

                // config file
                cmd_parser.Setup <string>("config").Callback(value => configFilename = value).Required();

                cmd_parser.Parse(args);

                if (DLTNode.Program.noStart)
                {
                    return;
                }

                readConfigFile(configFilename);



                // second pass
                cmd_parser = new FluentCommandLineParser();

                // Block storage provider
                cmd_parser.Setup <string>("blockStorage").Callback(value => blockStorageProvider = value).Required();

                // testnet
                cmd_parser.Setup <bool>('t', "testnet").Callback(value => CoreConfig.isTestNet = true).Required();

                cmd_parser.Parse(args);

                if (CoreConfig.isTestNet)
                {
                    Config.serverPort = defaultTestnetServerPort;
                    apiPort           = testnetApiPort;
                    dataFolderPath    = "data-testnet";
                    PeerStorage.init(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "testnet-peers.dat");
                    genesisFile = "testnet-genesis.dat";
                }
                else
                {
                    Config.serverPort = defaultServerPort;
                    PeerStorage.init(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
                }



                string seedNode = "";

                // third pass
                cmd_parser = new FluentCommandLineParser();

                int start_clean = 0; // Flag to determine if node should delete cache+logs

                // version
                cmd_parser.Setup <bool>('v', "version").Callback(text => outputVersion());

                // Toggle between full history node and no history
                cmd_parser.Setup <bool>('s', "save-history").Callback(value => storeFullHistory = value).Required();

                // Toggle worker-only mode
                cmd_parser.Setup <bool>("worker").Callback(value => workerOnly = true).Required();

                // Check for password change
                cmd_parser.Setup <bool>('x', "changepass").Callback(value => changePass = value).Required();

                // Check for recovery parameter
                cmd_parser.Setup <bool>("recover").Callback(value => recoverFromFile = value).Required();

                // Check for clean parameter
                cmd_parser.Setup <bool>('c', "clean").Callback(value => start_clean = 1);
                cmd_parser.Setup <bool>('f', "force").Callback(value => { if (start_clean > 0)
                                                                          {
                                                                              start_clean += 1;
                                                                          }
                                                               });


                cmd_parser.Setup <int>('p', "port").Callback(value => Config.serverPort = value).Required();

                cmd_parser.Setup <int>('a', "apiport").Callback(value => apiPort = value).Required();

                cmd_parser.Setup <string>('i', "ip").Callback(value => externalIp = value).Required();

                cmd_parser.Setup <string>("genesis").Callback(value => genesisFunds = value).Required();

                cmd_parser.Setup <string>("genesis2").Callback(value => genesis2Address = value).Required();

                cmd_parser.Setup <int>("threads").Callback(value => miningThreads = (uint)value).Required();

                cmd_parser.Setup <string>('w', "wallet").Callback(value => walletFile = value).Required();

                cmd_parser.Setup <string>('n', "node").Callback(value => seedNode = value).Required();

                cmd_parser.Setup <int>("maxLogSize").Callback(value => maxLogSize = value).Required();

                cmd_parser.Setup <int>("maxLogCount").Callback(value => maxLogCount = value).Required();

                cmd_parser.Setup <long>("lastGoodBlock").Callback(value => lastGoodBlock = (ulong)value).Required();

                cmd_parser.Setup <bool>("disableWebStart").Callback(value => disableWebStart = true).Required();

                cmd_parser.Setup <string>("dataFolderPath").Callback(value => dataFolderPath = value).Required();

                cmd_parser.Setup <bool>("optimizeDBStorage").Callback(value => optimizeDBStorage = value).Required();

                cmd_parser.Setup <bool>("verifyStorage").Callback(value => fullStorageDataVerification = true).Required();

                cmd_parser.Setup <bool>("onlyShowAddresses").Callback(value => onlyShowAddresses = true).Required();


                // Debug
                cmd_parser.Setup <string>("netdump").Callback(value => networkDumpFile = value).SetDefault("");

                cmd_parser.Setup <int>("benchmarkKeys").Callback(value => benchmarkKeys = value).SetDefault(0);

                cmd_parser.Setup <bool>("generateWallet").Callback(value => generateWalletOnly = value).SetDefault(false);

                cmd_parser.Setup <string>("walletPassword").Callback(value => dangerCommandlinePasswordCleartextUnsafe = value).SetDefault("");

                cmd_parser.Setup <bool>("noNetworkSync").Callback(value => noNetworkSync = true).Required();

                cmd_parser.Setup <bool>("devInsertFromJson").Callback(value => devInsertFromJson = true).Required();

                cmd_parser.Setup <bool>("offline").Callback(value => CoreConfig.preventNetworkOperations = true).Required();

                cmd_parser.Parse(args);

                WalletStateStorage.path = dataFolderPath + Path.DirectorySeparatorChar + "ws";

                if (start_clean > 0)
                {
                    bool do_clean = false;
                    if (start_clean > 1)
                    {
                        Logging.warn("Ixian DLT node started with the forced clean parameter (-c -c).");
                        do_clean = true;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.WriteLine("You have started the Ixian DLT node with the '-c' parameter, indicating that you wish to clear all cache and log files.");
                        Console.Write("This will cause the node to re-download any neccessary data, which may take some time. Are you sure? (Y/N)");
                        Console.ResetColor();
                        var k = Console.ReadKey();
                        if (k.Key == ConsoleKey.Y)
                        {
                            do_clean = true;
                        }
                    }
                    if (do_clean)
                    {
                        Node.checkDataFolder();
                        Node.cleanCacheAndLogs();
                    }
                    else
                    {
                        DLTNode.Program.noStart = true;
                        return;
                    }
                }

                if (miningThreads < 1)
                {
                    miningThreads = 1;
                }

                if (seedNode != "")
                {
                    if (CoreConfig.isTestNet)
                    {
                        CoreNetworkUtils.seedTestNetNodes = new List <string[]>
                        {
                            new string[2] {
                                seedNode, null
                            }
                        };
                    }
                    else
                    {
                        CoreNetworkUtils.seedNodes = new List <string[]>
                        {
                            new string[2] {
                                seedNode, null
                            }
                        };
                    }
                }
            }
コード例 #20
0
        // Returns a random new potential neighbor. Returns null if no new neighbor is found.
        public static Peer scanForNeighbor()
        {
            Peer connectToPeer = null;

            // Find only masternodes
            while (connectToPeer == null)
            {
                Thread.Sleep(10);

                bool addr_valid = true;
                if (getConnectedClients(true).Count() == 0)
                {
                    PeerStorage.resetInitialConnectionCount();
                }
                Peer p = PeerStorage.getRandomMasterNodeAddress();

                if (p == null)
                {
                    break;
                }

                // Next, check if we're connecting to a self address of this node
                string[] server = p.hostname.Split(':');

                if (server.Length < 2)
                {
                    break;
                }

                // Resolve the hostname first
                string resolved_server_name           = NetworkUtils.resolveHostname(server[0]);
                string resolved_server_name_with_port = resolved_server_name + ":" + server[1];

                // Check if we are already connected to this address
                lock (networkClients)
                {
                    foreach (NetworkClient client in networkClients)
                    {
                        if (client.getFullAddress(true).Equals(resolved_server_name_with_port, StringComparison.Ordinal))
                        {
                            // Address is already in the client list
                            addr_valid = false;
                            break;
                        }
                    }
                }

                // Check if node is already in the server list
                string[] connectedClients = NetworkServer.getConnectedClients(true);
                for (int i = 0; i < connectedClients.Length; i++)
                {
                    if (connectedClients[i].Equals(resolved_server_name_with_port, StringComparison.Ordinal))
                    {
                        // Address is already in the client list
                        addr_valid = false;
                        break;
                    }
                }

                if (addr_valid == false)
                {
                    continue;
                }

                // Check against connecting clients list as well
                lock (connectingClients)
                {
                    foreach (string client in connectingClients)
                    {
                        if (resolved_server_name_with_port.Equals(client, StringComparison.Ordinal))
                        {
                            // Address is already in the connecting client list
                            addr_valid = false;
                            break;
                        }
                    }
                }

                if (addr_valid == false)
                {
                    continue;
                }

                if (NetworkServer.isRunning())
                {
                    // Get all self addresses and run through them
                    List <string> self_addresses = CoreNetworkUtils.GetAllLocalIPAddresses();
                    foreach (string self_address in self_addresses)
                    {
                        // Don't connect to self
                        if (resolved_server_name.Equals(self_address, StringComparison.Ordinal))
                        {
                            if (server[1].Equals(string.Format("{0}", IxianHandler.publicPort), StringComparison.Ordinal))
                            {
                                addr_valid = false;
                            }
                        }
                    }
                }

                // If the address is valid, add it to the candidates
                if (addr_valid)
                {
                    connectToPeer = p;
                }
            }

            return(connectToPeer);
        }