コード例 #1
0
ファイル: Node.cs プロジェクト: fexra/CantiLib
        public Node(NetworkConfig Configuration)
        {
            // Assign configuration
            Globals = Configuration;

            // Setup logger
            Logger = new Logger()
            {
                LogFile        = Globals.LOG_FILE,
                LogLevel       = Globals.LOG_LEVEL,
                CustomPrefix   = Globals.CUSTOM_PREFIX,
                InfoColor      = Globals.INFO_COLOR,
                ImportantColor = Globals.IMPORTANT_COLOR,
                DebugColor     = Globals.DEBUG_COLOR,
                WarningColor   = Globals.WARNING_COLOR,
                ErrorColor     = Globals.ERROR_COLOR
            };

            // Show ascii art, strictly vanity
            if (!string.IsNullOrEmpty(Globals.ASCII_ART))
            {
                Logger?.Important(Globals.ASCII_ART);
            }
            Logger.ShowPrefix = true;

            // Setup our blockchain handler
            Logger?.WriteLine("Setting up blockchain handler...");
            Blockchain = new BlockchainStorage();

            // Create our P2P server
            Logger?.WriteLine("Setting up P2P server...");
            P2pServer = new P2pServer(Globals.P2P_MAX_PEER_CONNECTIONS);

            // Assign P2P event handlers
            Logger?.WriteLine("Assigning P2P callbacks...");
            AssignCallbacks();

            // Setup our API server
            Logger?.WriteLine("Setting up API server...");
            ApiServer = new ApiServer(Globals.API_MAX_WORKERS)
            {
                Logger = Logger
            };

            // Create an API context
            Logger?.WriteLine("Assigning API method context...");
            ApiServer.AssignMethodContext(new ApiMethods(this));

            // Setup our peer list
            Logger?.WriteLine("Setting up local peer list...");
            SetupPeerList();

            // Assign a unique identifier
            Logger?.WriteLine("Generating identifier...");
            Id = SecureRandom.Integer <ulong>();
        }
コード例 #2
0
ファイル: Node.cs プロジェクト: BrandonT42/CantiLib
        /// <summary>
        /// Initializes this node with the specified network configuration
        /// </summary>
        /// <param name="Configuration">A class containing all global information this node needs to operate</param>
        public Node(NetworkConfig Configuration)
        {
            // Assign configuration
            Globals = Configuration;

            // Setup logger
            Logger = new Logger()
            {
                LogFile        = Globals.LOG_FILE,
                LogLevel       = Globals.LOG_LEVEL,
                CustomPrefix   = Globals.CUSTOM_PREFIX,
                InfoColor      = Globals.INFO_COLOR,
                ImportantColor = Globals.IMPORTANT_COLOR,
                DebugColor     = Globals.DEBUG_COLOR,
                WarningColor   = Globals.WARNING_COLOR,
                ErrorColor     = Globals.ERROR_COLOR
            };

            // Show ascii art, strictly vanity
            if (!string.IsNullOrEmpty(Globals.ASCII_ART))
            {
                Logger?.Important(Globals.ASCII_ART);
            }
            Logger.ShowPrefix = true;

            // Setup our database
            Logger?.WriteLine("Setting up local storage...");
            if (!Directory.Exists(Globals.DATABASE_DIRECTORY))
            {
                Logger?.WriteLine("Creating directories...");
                Directory.CreateDirectory(Globals.DATABASE_DIRECTORY);
            }
            switch (Globals.DATABASE_TYPE)
            {
            case DatabaseType.SQLITE:
                DatabaseLocation = CombinePath(Globals.DATABASE_DIRECTORY, Globals.DATABASE_LOCATION);
                Database         = new Sqlite(DatabaseLocation);
                break;

            default:
                throw new ArgumentException("Invalid or non-specified database type");
            }

            // Setup our blockchain handler
            Logger?.WriteLine("Setting up blockchain handler...");
            Blockchain = new Blockchain()
            {
                Logger = Logger
            };

            // Create our P2P server
            Logger?.WriteLine("Setting up P2P server...");
            P2pServer = new P2pServer(Globals.P2P_MAX_PEER_CONNECTIONS);

            // Assign P2P event handlers
            Logger?.WriteLine("Assigning P2P callbacks...");
            AssignCallbacks();

            // Setup our API server
            Logger?.WriteLine("Setting up API server...");
            ApiServer = new ApiServer(Globals.API_MAX_WORKERS)
            {
                Logger = Logger
            };

            // Create an API context
            Logger?.WriteLine("Assigning API method context...");
            ApiServer.AssignMethodContext(new ApiMethods(this));

            // Setup our peer list
            Logger?.WriteLine("Setting up local peer list...");
            SetupPeerList();

            // Assign a unique identifier
            Logger?.WriteLine("Generating identifier...");
            Id = SecureRandom.Integer <ulong>();
        }