/// <inheritdoc />
        public void Start()
        {
            this.State = FullNodeState.Starting;

            if (this.State == FullNodeState.Disposing || this.State == FullNodeState.Disposed)
            {
                throw new ObjectDisposedException(nameof(FullNode));
            }

            this.Signals.Publish(new FullNodeEvent()
            {
                Message = $"Full node starting on {this.Network.Name}.", State = this.State.ToString()
            });

            this.nodeRunningLock = new NodeRunningLock(this.DataFolder);

            if (!this.nodeRunningLock.TryLockNodeFolder())
            {
                this.logger.LogCritical("Node folder is being used by another instance of the application!");
                throw new Exception("Node folder is being used!");
            }

            this.nodeLifetime            = this.Services.ServiceProvider.GetRequiredService <INodeLifetime>() as NodeLifetime;
            this.fullNodeFeatureExecutor = this.Services.ServiceProvider.GetRequiredService <FullNodeFeatureExecutor>();

            if (this.nodeLifetime == null)
            {
                throw new InvalidOperationException($"{nameof(INodeLifetime)} must be set.");
            }

            if (this.fullNodeFeatureExecutor == null)
            {
                throw new InvalidOperationException($"{nameof(FullNodeFeatureExecutor)} must be set.");
            }

            this.logger.LogInformation("Starting node.");

            // Initialize all registered features.
            this.fullNodeFeatureExecutor.Initialize();

            // Initialize peer connection.
            var consensusManager = this.Services.ServiceProvider.GetRequiredService <IConsensusManager>();

            this.ConnectionManager.Initialize(consensusManager);

            // Fire INodeLifetime.Started.
            this.nodeLifetime.NotifyStarted();

            this.StartPeriodicLog();

            this.State = FullNodeState.Started;

            this.Signals.Publish(new FullNodeEvent()
            {
                Message = $"Full node started on {this.Network.Name}.", State = this.State.ToString()
            });
        }
        protected void StartFeatures()
        {
            this.applicationLifetime     = this.Services?.ServiceProvider.GetRequiredService <IApplicationLifetime>() as ApplicationLifetime;
            this.fullNodeFeatureExecutor = this.Services?.ServiceProvider.GetRequiredService <FullNodeFeatureExecutor>();

            // Fire IApplicationLifetime.Started
            this.applicationLifetime?.NotifyStarted();

            //start all registered features
            this.fullNodeFeatureExecutor?.Start();
        }
Example #3
0
        /// <inheritdoc />
        public void Start()
        {
            this.State = FullNodeState.Starting;

            if (this.State == FullNodeState.Disposing || this.State == FullNodeState.Disposed)
            {
                throw new ObjectDisposedException(nameof(FullNode));
            }

            if (this.Resources != null)
            {
                throw new InvalidOperationException("node has already started.");
            }

            this.Resources               = new List <IDisposable>();
            this.nodeLifetime            = this.Services.ServiceProvider.GetRequiredService <INodeLifetime>() as NodeLifetime;
            this.fullNodeFeatureExecutor = this.Services.ServiceProvider.GetRequiredService <FullNodeFeatureExecutor>();

            if (this.nodeLifetime == null)
            {
                throw new InvalidOperationException($"{nameof(INodeLifetime)} must be set.");
            }

            if (this.fullNodeFeatureExecutor == null)
            {
                throw new InvalidOperationException($"{nameof(FullNodeFeatureExecutor)} must be set.");
            }

            this.logger.LogInformation("Starting node.");

            // Initialize all registered features.
            this.fullNodeFeatureExecutor.Initialize();

            // Initialize peer connection.
            var consensusManager = this.Services.ServiceProvider.GetRequiredService <IConsensusManager>();

            this.ConnectionManager.Initialize(consensusManager);

            // Fire INodeLifetime.Started.
            this.nodeLifetime.NotifyStarted();

            this.StartPeriodicLog();

            this.State = FullNodeState.Started;
        }
        public FullNodeFeatureExecutorTest()
        {
            this.feature  = new Mock <IFullNodeFeature>();
            this.feature2 = new Mock <IFullNodeFeature>();

            this.fullNodeServiceProvider = new Mock <IFullNodeServiceProvider>();
            this.fullNode = new Mock <IFullNode>();

            this.fullNode.Setup(f => f.Services)
            .Returns(this.fullNodeServiceProvider.Object);

            this.fullNodeServiceProvider.Setup(f => f.Features)
            .Returns(new List <IFullNodeFeature> {
                this.feature.Object, this.feature2.Object
            });

            this.executor = new FullNodeFeatureExecutor(this.fullNode.Object, new LoggerFactory());
        }
        /// <inheritdoc />
        public void Start()
        {
            if (this.IsDisposed)
            {
                throw new ObjectDisposedException(nameof(FullNode));
            }

            if (this.Resources != null)
            {
                throw new InvalidOperationException("node has already started.");
            }

            this.Resources               = new List <IDisposable>();
            this.nodeLifetime            = this.Services.ServiceProvider.GetRequiredService <INodeLifetime>() as NodeLifetime;
            this.fullNodeFeatureExecutor = this.Services.ServiceProvider.GetRequiredService <FullNodeFeatureExecutor>();

            if (this.nodeLifetime == null)
            {
                throw new InvalidOperationException($"{nameof(INodeLifetime)} must be set.");
            }

            if (this.fullNodeFeatureExecutor == null)
            {
                throw new InvalidOperationException($"{nameof(FullNodeFeatureExecutor)} must be set.");
            }

            this.logger.LogInformation("Starting node...");

            // start all registered features
            this.fullNodeFeatureExecutor.Start();

            // start connecting to peers
            this.ConnectionManager.Start();

            // Fire INodeLifetime.Started
            this.nodeLifetime.NotifyStarted();

            this.StartPeriodicLog();
        }