/// <summary>
 /// Initializes a new instance of the object.
 /// </summary>
 /// <param name="nodeSettings">User defined node settings.</param>
 /// <param name="dataFolder">Locations of important folders and files on disk.</param>
 /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
 /// <param name="nodeLifetime">Global application life cycle control - triggers when application shuts down.</param>
 /// <param name="chain">Thread safe chain of block headers from genesis.</param>
 /// <param name="chainState">Information about node's chain.</param>
 /// <param name="connectionManager">Manager of node's network connections.</param>
 /// <param name="chainRepository">Access to the database of blocks.</param>
 /// <param name="dateTimeProvider">Provider of time functions.</param>
 /// <param name="asyncLoopFactory">Factory for creating background async loop tasks.</param>
 /// <param name="timeSyncBehaviorState">State of time synchronization feature that stores collected data samples.</param>
 /// <param name="dbreezeSerializer">Provider of binary (de)serialization for data stored in the database.</param>
 /// <param name="loggerFactory">Factory to be used to create logger for the node.</param>
 public BaseFeature(
     NodeSettings nodeSettings,
     DataFolder dataFolder,
     Network network,
     INodeLifetime nodeLifetime,
     ConcurrentChain chain,
     ChainState chainState,
     IConnectionManager connectionManager,
     ChainRepository chainRepository,
     IDateTimeProvider dateTimeProvider,
     IAsyncLoopFactory asyncLoopFactory,
     TimeSyncBehaviorState timeSyncBehaviorState,
     DBreezeSerializer dbreezeSerializer,
     ILoggerFactory loggerFactory,
     IPeerBanning peerBanning)
 {
     this.chainState            = Guard.NotNull(chainState, nameof(chainState));
     this.chainRepository       = Guard.NotNull(chainRepository, nameof(chainRepository));
     this.nodeSettings          = Guard.NotNull(nodeSettings, nameof(nodeSettings));
     this.dataFolder            = Guard.NotNull(dataFolder, nameof(dataFolder));
     this.network               = Guard.NotNull(network, nameof(network));
     this.nodeLifetime          = Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
     this.chain                 = Guard.NotNull(chain, nameof(chain));
     this.connectionManager     = Guard.NotNull(connectionManager, nameof(connectionManager));
     this.peerBanning           = Guard.NotNull(peerBanning, nameof(peerBanning));
     this.dateTimeProvider      = dateTimeProvider;
     this.asyncLoopFactory      = asyncLoopFactory;
     this.timeSyncBehaviorState = timeSyncBehaviorState;
     this.loggerFactory         = loggerFactory;
     this.dbreezeSerializer     = dbreezeSerializer;
     this.logger                = loggerFactory.CreateLogger(this.GetType().FullName);
 }
 public PeerBanningBehavior(ILoggerFactory loggerFactory, IPeerBanning peerBanning, NodeSettings nodeSettings)
 {
     this.logger        = loggerFactory.CreateLogger("Impleum.Bitcoin.Fullnode");
     this.loggerFactory = loggerFactory;
     this.peerBanning   = peerBanning;
     this.nodeSettings  = nodeSettings;
 }
 public FederationGatewayController(
     IAsyncProvider asyncProvider,
     ChainIndexer chainIndexer,
     IConnectionManager connectionManager,
     ICrossChainTransferStore crossChainTransferStore,
     IMaturedBlocksProvider maturedBlocksProvider,
     Network network,
     IFederatedPegSettings federatedPegSettings,
     IFederationWalletManager federationWalletManager,
     IFullNode fullNode,
     IPeerBanning peerBanning,
     IFederationManager federationManager = null)
 {
     this.asyncProvider           = asyncProvider;
     this.chainIndexer            = chainIndexer;
     this.connectionManager       = connectionManager;
     this.crossChainTransferStore = crossChainTransferStore;
     this.federatedPegSettings    = federatedPegSettings;
     this.federationWalletManager = federationWalletManager;
     this.federationManager       = federationManager;
     this.fullNode = fullNode;
     this.logger   = LogManager.GetCurrentClassLogger();
     this.maturedBlocksProvider = maturedBlocksProvider;
     this.network     = network;
     this.peerBanning = peerBanning;
 }
Esempio n. 4
0
        public ProvenHeadersConsensusManagerBehavior(
            ChainIndexer chainIndexer,
            IInitialBlockDownloadState initialBlockDownloadState,
            IConsensusManager consensusManager,
            IPeerBanning peerBanning,
            ILoggerFactory loggerFactory,
            Network network,
            IChainState chainState,
            ICheckpoints checkpoints,
            IProvenBlockHeaderStore provenBlockHeaderStore,
            ConnectionManagerSettings connectionManagerSettings) : base(chainIndexer, initialBlockDownloadState, consensusManager, peerBanning, loggerFactory)
        {
            this.ChainIndexer = chainIndexer;
            this.initialBlockDownloadState = initialBlockDownloadState;
            this.consensusManager          = consensusManager;
            this.peerBanning            = peerBanning;
            this.network                = network;
            this.loggerFactory          = loggerFactory;
            this.logger                 = loggerFactory.CreateLogger(this.GetType().FullName, $"[{this.GetHashCode():x}] ");
            this.chainState             = chainState;
            this.checkpoints            = checkpoints;
            this.provenBlockHeaderStore = provenBlockHeaderStore;

            this.lastCheckpointHeight = this.checkpoints.GetLastCheckpointHeight();
            this.lastCheckpointInfo   = this.checkpoints.GetCheckpoint(this.lastCheckpointHeight);

            this.connectionManagerSettings = connectionManagerSettings;

            this.isGateway = this.connectionManagerSettings.IsGateway;
        }
Esempio n. 5
0
        public PosConsensusFeature(
            Network network,
            IChainState chainState,
            IConnectionManager connectionManager,
            IConsensusManager consensusManager,
            NodeDeployments nodeDeployments,
            ConcurrentChain chain,
            IInitialBlockDownloadState initialBlockDownloadState,
            IPeerBanning peerBanning,
            Signals.ISignals signals,
            ILoggerFactory loggerFactory,
            ICheckpoints checkpoints,
            IProvenBlockHeaderStore provenBlockHeaderStore,
            ConnectionManagerSettings connectionManagerSettings) : base(network, chainState, connectionManager, signals, consensusManager, nodeDeployments)
        {
            this.network                   = network;
            this.chainState                = chainState;
            this.connectionManager         = connectionManager;
            this.consensusManager          = consensusManager;
            this.nodeDeployments           = nodeDeployments;
            this.chain                     = chain;
            this.initialBlockDownloadState = initialBlockDownloadState;
            this.peerBanning               = peerBanning;
            this.loggerFactory             = loggerFactory;
            this.checkpoints               = checkpoints;
            this.provenBlockHeaderStore    = provenBlockHeaderStore;
            this.connectionManagerSettings = connectionManagerSettings;

            this.chainState.MaxReorgLength = network.Consensus.MaxReorgLength;
        }
Esempio n. 6
0
 public ConnectionManagerController(IConnectionManager connectionManager,
                                    ILoggerFactory loggerFactory, IPeerBanning peerBanning) : base(connectionManager: connectionManager)
 {
     Guard.NotNull(this.ConnectionManager, nameof(this.ConnectionManager));
     this.logger      = loggerFactory.CreateLogger(this.GetType().FullName);
     this.peerBanning = peerBanning;
 }
Esempio n. 7
0
 public PeerBanningBehavior(ILoggerFactory loggerFactory, IPeerBanning peerBanning, NodeSettings nodeSettings)
 {
     this.logger        = loggerFactory.CreateLogger(this.GetType().FullName);
     this.loggerFactory = loggerFactory;
     this.peerBanning   = peerBanning;
     this.nodeSettings  = nodeSettings;
 }
Esempio n. 8
0
        public ProvenHeadersConsensusManagerBehavior(
            ChainIndexer chainIndexer,
            IInitialBlockDownloadState initialBlockDownloadState,
            IConsensusManager consensusManager,
            IPeerBanning peerBanning,
            ILoggerFactory loggerFactory,
            Network network,
            IChainState chainState,
            ICheckpoints checkpoints,
            IProvenBlockHeaderStore provenBlockHeaderStore,
            ConnectionManagerSettings connectionManagerSettings) : base(chainIndexer, initialBlockDownloadState, consensusManager, peerBanning, loggerFactory)
        {
            this.network                = network;
            this.logger                 = loggerFactory.CreateLogger(this.GetType().FullName);
            this.chainState             = chainState;
            this.checkpoints            = checkpoints;
            this.provenBlockHeaderStore = provenBlockHeaderStore;

            this.lastCheckpointHeight = this.checkpoints.LastCheckpointHeight;
            this.lastCheckpointInfo   = this.checkpoints.GetCheckpoint(this.lastCheckpointHeight);

            this.connectionManagerSettings = connectionManagerSettings;

#pragma warning disable CS0618 // Type or member is obsolete
            this.isGateway = this.connectionManagerSettings.IsGateway;
#pragma warning restore CS0618 // Type or member is obsolete
        }
Esempio n. 9
0
        public BaseFeature(NodeSettings nodeSettings,
                           DataFolder dataFolder,
                           INodeLifetime nodeLifetime,
                           ChainIndexer chainIndexer,
                           IChainState chainState,
                           IConnectionManager connectionManager,
                           IChainRepository chainRepository,
                           IFinalizedBlockInfoRepository finalizedBlockInfo,
                           IDateTimeProvider dateTimeProvider,
                           IAsyncProvider asyncProvider,
                           ITimeSyncBehaviorState timeSyncBehaviorState,
                           ILoggerFactory loggerFactory,
                           IInitialBlockDownloadState initialBlockDownloadState,
                           IPeerBanning peerBanning,
                           IPeerAddressManager peerAddressManager,
                           IConsensusManager consensusManager,
                           IConsensusRuleEngine consensusRules,
                           IPartialValidator partialValidator,
                           IBlockPuller blockPuller,
                           IBlockStore blockStore,
                           Network network,
                           ITipsManager tipsManager,
                           NodeDeployments nodeDeployments,
                           IKeyValueRepository keyValueRepo,
                           INodeStats nodeStats,
                           IBroadcasterManager broadcasterManager,
                           IProvenBlockHeaderStore provenBlockHeaderStore = null)
        {
            this.chainState      = Guard.NotNull(chainState, nameof(chainState));
            this.chainRepository = Guard.NotNull(chainRepository, nameof(chainRepository));
            this.finalizedBlockInfoRepository = Guard.NotNull(finalizedBlockInfo, nameof(finalizedBlockInfo));
            this.nodeSettings           = Guard.NotNull(nodeSettings, nameof(nodeSettings));
            this.dataFolder             = Guard.NotNull(dataFolder, nameof(dataFolder));
            this.nodeLifetime           = Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            this.chainIndexer           = Guard.NotNull(chainIndexer, nameof(chainIndexer));
            this.connectionManager      = Guard.NotNull(connectionManager, nameof(connectionManager));
            this.consensusManager       = consensusManager;
            this.consensusRules         = consensusRules;
            this.blockPuller            = blockPuller;
            this.blockStore             = blockStore;
            this.network                = network;
            this.nodeStats              = nodeStats;
            this.broadcasterManager     = broadcasterManager;
            this.provenBlockHeaderStore = provenBlockHeaderStore;
            this.partialValidator       = partialValidator;
            this.peerBanning            = Guard.NotNull(peerBanning, nameof(peerBanning));
            this.tipsManager            = Guard.NotNull(tipsManager, nameof(tipsManager));
            this.keyValueRepo           = Guard.NotNull(keyValueRepo, nameof(keyValueRepo));
            this.nodeDeployments        = nodeDeployments;

            this.peerAddressManager = Guard.NotNull(peerAddressManager, nameof(peerAddressManager));
            this.peerAddressManager.PeerFilePath = this.dataFolder;

            this.initialBlockDownloadState = initialBlockDownloadState;
            this.dateTimeProvider          = dateTimeProvider;
            this.asyncProvider             = asyncProvider;
            this.timeSyncBehaviorState     = timeSyncBehaviorState;
            this.loggerFactory             = loggerFactory;
            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
        }
 public ConnectionManagerController(IConnectionManager connectionManager,
                                    ILoggerFactory loggerFactory, IPeerBanning peerBanning) : base(connectionManager: connectionManager)
 {
     Guard.NotNull(this.ConnectionManager, nameof(this.ConnectionManager));
     this.logger      = loggerFactory.CreateLogger("Impleum.Bitcoin.FullNode");
     this.peerBanning = peerBanning;
 }
        public static bool AddNode(IConnectionManager connectionManager, IPeerBanning peerBanning, string endpointStr, string command)
        {
            IPEndPoint endpoint = endpointStr.ToIPEndPoint(connectionManager.Network.DefaultPort);

            switch (command)
            {
            case "add":
                if (peerBanning.IsBanned(endpoint))
                {
                    throw new InvalidOperationException("Can't perform 'add' for a banned peer.");
                }

                connectionManager.AddNodeAddress(endpoint);
                break;

            case "remove":
                connectionManager.RemoveNodeAddress(endpoint);
                break;

            case "onetry":
                if (peerBanning.IsBanned(endpoint))
                {
                    throw new InvalidOperationException("Can't connect to a banned peer.");
                }

                connectionManager.ConnectAsync(endpoint).GetAwaiter().GetResult();
                break;

            default:
                throw new ArgumentException("command");
            }

            return(true);
        }
        /// <summary>
        /// Initialize a new instance of <see cref="ConsensusLoop"/>.
        /// </summary>
        /// <param name="asyncLoopFactory">The async loop we need to wait upon before we can shut down this feature.</param>
        /// <param name="validator">The validation logic for the consensus rules.</param>
        /// <param name="nodeLifetime">Contain information about the life time of the node, its used on startup and shutdown.</param>
        /// <param name="chain">A chain of headers all the way to genesis.</param>
        /// <param name="utxoSet">The consensus db, containing all unspent UTXO in the chain.</param>
        /// <param name="puller">A puller that can pull blocks from peers on demand.</param>
        /// <param name="nodeDeployments">Contain information about deployment and activation of features in the chain.</param>
        /// <param name="loggerFactory">A factory to provide logger instances.</param>
        /// <param name="chainState">Holds state related to the block chain.</param>
        /// <param name="connectionManager">Connection manager of all the currently connected peers.</param>
        /// <param name="dateTimeProvider">Provider of time functions.</param>
        /// <param name="signals">A signaler that used to signal messages between features.</param>
        /// <param name="checkpoints">Provider of block header hash checkpoints.</param>
        /// <param name="consensusSettings">Consensus settings for the full node.</param>
        /// <param name="nodeSettings">Settings for the full node.</param>
        /// <param name="peerBanning">Handles the banning of peers.</param>
        /// <param name="consensusRules">The consensus rules to validate.</param>
        /// <param name="stakeChain">Information holding POS data chained.</param>
        public ConsensusLoop(
            IAsyncLoopFactory asyncLoopFactory,
            PowConsensusValidator validator,
            INodeLifetime nodeLifetime,
            ConcurrentChain chain,
            CoinView utxoSet,
            LookaheadBlockPuller puller,
            NodeDeployments nodeDeployments,
            ILoggerFactory loggerFactory,
            ChainState chainState,
            IConnectionManager connectionManager,
            IDateTimeProvider dateTimeProvider,
            Signals.Signals signals,
            ICheckpoints checkpoints,
            ConsensusSettings consensusSettings,
            NodeSettings nodeSettings,
            IPeerBanning peerBanning,
            IConsensusRules consensusRules,
            StakeChain stakeChain = null)
        {
            Guard.NotNull(asyncLoopFactory, nameof(asyncLoopFactory));
            Guard.NotNull(validator, nameof(validator));
            Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            Guard.NotNull(chain, nameof(chain));
            Guard.NotNull(utxoSet, nameof(utxoSet));
            Guard.NotNull(puller, nameof(puller));
            Guard.NotNull(nodeDeployments, nameof(nodeDeployments));
            Guard.NotNull(connectionManager, nameof(connectionManager));
            Guard.NotNull(chainState, nameof(chainState));
            Guard.NotNull(signals, nameof(signals));
            Guard.NotNull(consensusSettings, nameof(consensusSettings));
            Guard.NotNull(nodeSettings, nameof(nodeSettings));
            Guard.NotNull(peerBanning, nameof(peerBanning));
            Guard.NotNull(consensusRules, nameof(consensusRules));

            this.consensusLock = new AsyncLock();

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);

            this.asyncLoopFactory  = asyncLoopFactory;
            this.Validator         = validator;
            this.nodeLifetime      = nodeLifetime;
            this.chainState        = chainState;
            this.connectionManager = connectionManager;
            this.signals           = signals;
            this.Chain             = chain;
            this.UTXOSet           = utxoSet;
            this.Puller            = puller;
            this.NodeDeployments   = nodeDeployments;
            this.checkpoints       = checkpoints;
            this.dateTimeProvider  = dateTimeProvider;
            this.consensusSettings = consensusSettings;
            this.nodeSettings      = nodeSettings;
            this.peerBanning       = peerBanning;
            this.consensusRules    = consensusRules;

            // chain of stake info can be null if POS is not enabled
            this.StakeChain = stakeChain;
        }
 public PeerBanningBehavior(ILoggerFactory loggerFactory, IPeerBanning peerBanning, NodeSettings nodeSettings)
 {
     this.logger                 = loggerFactory.CreateLogger(this.GetType().FullName);
     this.loggerFactory          = loggerFactory;
     this.peerBanning            = peerBanning;
     this.nodeSettings           = nodeSettings;
     this.eventHandlerRegistered = false;
 }
 public ProvenHeaderConsenusManagerBehaviorTests() : base(new StratisTest())
 {
     this.chainState  = new Mock <IChainState>().Object;
     this.checkpoints = new Mock <ICheckpoints>().Object;
     this.connectionManagerSettings = new ConnectionManagerSettings(NodeSettings.Default(this.Network));
     this.extendedLoggerFactory     = new ExtendedLoggerFactory(); this.extendedLoggerFactory.AddConsoleWithFilters();
     this.initialBlockDownloadState = new Mock <IInitialBlockDownloadState>().Object;
     this.peerBanning            = new Mock <IPeerBanning>().Object;
     this.provenBlockHeaderStore = new Mock <IProvenBlockHeaderStore>().Object;
 }
 public RateLimitingBehavior(
     IDateTimeProvider dateTimeProvider,
     ILoggerFactory loggerFactory,
     IPeerBanning peerBanning)
 {
     this.dateTimeProvider = dateTimeProvider;
     this.loggerFactory    = loggerFactory;
     this.logger           = loggerFactory.CreateLogger("Impleum.Bitcoin.FullNode");
     this.peerBanning      = peerBanning;
 }
Esempio n. 16
0
 public RateLimitingBehavior(
     IDateTimeProvider dateTimeProvider,
     ILoggerFactory loggerFactory,
     IPeerBanning peerBanning)
 {
     this.dateTimeProvider = dateTimeProvider;
     this.loggerFactory    = loggerFactory;
     this.logger           = loggerFactory.CreateLogger(this.GetType().FullName);
     this.peerBanning      = peerBanning;
 }
Esempio n. 17
0
 public NetworkController(
     IConnectionManager connectionManager,
     ILoggerFactory loggerFactory,
     Network network,
     IPeerBanning peerBanning)
 {
     this.connectionManager = connectionManager;
     this.network           = network;
     this.logger            = loggerFactory.CreateLogger(this.GetType().FullName);
     this.peerBanning       = peerBanning;
 }
 public NetworkController(
     IConnectionManager connectionManager,
     ILoggerFactory loggerFactory,
     Network network,
     IPeerBanning peerBanning)
 {
     this.connectionManager = connectionManager;
     this.network           = network;
     this.logger            = loggerFactory.CreateLogger("Impleum.Bitcoin.Fullnode");
     this.peerBanning       = peerBanning;
 }
Esempio n. 19
0
        public ProvenHeaderConsenusManagerBehaviorTests() : base(new StratisTest())
        {
            this.chainState  = new Mock <IChainState>().Object;
            this.checkpoints = new Mock <ICheckpoints>().Object;
            this.connectionManagerSettings = new ConnectionManagerSettings(NodeSettings.Default(this.Network));
            this.extendedLoggerFactory     = ExtendedLoggerFactory.Create();
            this.initialBlockDownloadState = new Mock <IInitialBlockDownloadState>().Object;
            this.peerBanning            = new Mock <IPeerBanning>().Object;
            this.provenBlockHeaderStore = new Mock <IProvenBlockHeaderStore>().Object;

            this.signals       = new Signals.Signals(this.extendedLoggerFactory, null);
            this.asyncProvider = new AsyncProvider(this.extendedLoggerFactory, this.signals, new Mock <INodeLifetime>().Object);
        }
Esempio n. 20
0
        public BaseFeature(
            NodeSettings nodeSettings,
            DataFolder dataFolder,
            INodeLifetime nodeLifetime,
            ConcurrentChain chain,
            IChainState chainState,
            IConnectionManager connectionManager,
            IChainRepository chainRepository,
            IFinalizedBlockInfoRepository finalizedBlockInfo,
            IDateTimeProvider dateTimeProvider,
            IAsyncLoopFactory asyncLoopFactory,
            ITimeSyncBehaviorState timeSyncBehaviorState,
            DBreezeSerializer dbreezeSerializer,
            ILoggerFactory loggerFactory,
            IInitialBlockDownloadState initialBlockDownloadState,
            IPeerBanning peerBanning,
            IPeerAddressManager peerAddressManager,
            IConsensusManager consensusManager,
            IConsensusRuleEngine consensusRules,
            IPartialValidator partialValidator,
            IBlockPuller blockPuller,
            IBlockStore blockStore,
            Network network)
        {
            this.chainState      = Guard.NotNull(chainState, nameof(chainState));
            this.chainRepository = Guard.NotNull(chainRepository, nameof(chainRepository));
            this.finalizedBlockInfoRepository = Guard.NotNull(finalizedBlockInfo, nameof(finalizedBlockInfo));
            this.nodeSettings      = Guard.NotNull(nodeSettings, nameof(nodeSettings));
            this.dataFolder        = Guard.NotNull(dataFolder, nameof(dataFolder));
            this.nodeLifetime      = Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            this.chain             = Guard.NotNull(chain, nameof(chain));
            this.connectionManager = Guard.NotNull(connectionManager, nameof(connectionManager));
            this.consensusManager  = consensusManager;
            this.consensusRules    = consensusRules;
            this.blockPuller       = blockPuller;
            this.blockStore        = blockStore;
            this.network           = network;
            this.partialValidator  = partialValidator;
            this.peerBanning       = Guard.NotNull(peerBanning, nameof(peerBanning));

            this.peerAddressManager = Guard.NotNull(peerAddressManager, nameof(peerAddressManager));
            this.peerAddressManager.PeerFilePath = this.dataFolder;

            this.initialBlockDownloadState = initialBlockDownloadState;
            this.dateTimeProvider          = dateTimeProvider;
            this.asyncLoopFactory          = asyncLoopFactory;
            this.timeSyncBehaviorState     = timeSyncBehaviorState;
            this.loggerFactory             = loggerFactory;
            this.dbreezeSerializer         = dbreezeSerializer;
            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
        }
Esempio n. 21
0
        public ConsensusManagerBehavior(ConcurrentChain chain, IInitialBlockDownloadState initialBlockDownloadState, IConsensusManager consensusManager, IPeerBanning peerBanning, ILoggerFactory loggerFactory)
        {
            this.loggerFactory             = loggerFactory;
            this.initialBlockDownloadState = initialBlockDownloadState;
            this.consensusManager          = consensusManager;
            this.chain       = chain;
            this.peerBanning = peerBanning;

            this.cachedHeaders      = new List <BlockHeader>();
            this.asyncLock          = new AsyncLock();
            this.bestSentHeaderLock = new object();

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName, $"[{this.GetHashCode():x}] ");
        }
Esempio n. 22
0
        public PeerAddressManagerBehaviour(IDateTimeProvider dateTimeProvider, IPeerAddressManager peerAddressManager, IPeerBanning peerBanning, ILoggerFactory loggerFactory)
        {
            Guard.NotNull(dateTimeProvider, nameof(dateTimeProvider));
            Guard.NotNull(peerAddressManager, nameof(peerAddressManager));
            Guard.NotNull(peerAddressManager, nameof(peerBanning));
            Guard.NotNull(peerAddressManager, nameof(loggerFactory));

            this.dateTimeProvider   = dateTimeProvider;
            this.logger             = loggerFactory.CreateLogger(this.GetType().FullName, $"[{this.GetHashCode():x}] ");
            this.loggerFactory      = loggerFactory;
            this.peerBanning        = peerBanning;
            this.Mode               = PeerAddressManagerBehaviourMode.AdvertiseDiscover;
            this.peerAddressManager = peerAddressManager;
            this.addrPayloadSent    = false;
        }
Esempio n. 23
0
        public PoAFeature(FederationManager federationManager, PayloadProvider payloadProvider, IConnectionManager connectionManager, ConcurrentChain chain,
                          IInitialBlockDownloadState initialBlockDownloadState, IConsensusManager consensusManager, IPeerBanning peerBanning, ILoggerFactory loggerFactory,
                          IPoAMiner miner)
        {
            this.federationManager         = federationManager;
            this.connectionManager         = connectionManager;
            this.chain                     = chain;
            this.initialBlockDownloadState = initialBlockDownloadState;
            this.consensusManager          = consensusManager;
            this.peerBanning               = peerBanning;
            this.loggerFactory             = loggerFactory;
            this.miner                     = miner;

            payloadProvider.DiscoverPayloads(this.GetType().Assembly);
        }
Esempio n. 24
0
        public ConsensusManager(
            Network network,
            ILoggerFactory loggerFactory,
            IChainState chainState,
            IHeaderValidator headerValidator,
            IIntegrityValidator integrityValidator,
            IPartialValidation partialValidation,
            ICheckpoints checkpoints,
            ConsensusSettings consensusSettings,
            IConsensusRules consensusRules,
            IFinalizedBlockHeight finalizedBlockHeight,
            Signals.Signals signals,
            IPeerBanning peerBanning,
            NodeSettings nodeSettings,
            IDateTimeProvider dateTimeProvider,
            IInitialBlockDownloadState ibdState,
            ConcurrentChain chain,
            IBlockStore blockStore = null)
        {
            this.network              = network;
            this.chainState           = chainState;
            this.partialValidation    = partialValidation;
            this.consensusSettings    = consensusSettings;
            this.consensusRules       = consensusRules;
            this.signals              = signals;
            this.peerBanning          = peerBanning;
            this.blockStore           = blockStore;
            this.finalizedBlockHeight = finalizedBlockHeight;
            this.chain  = chain;
            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);

            this.chainedHeaderTree = new ChainedHeaderTree(network, loggerFactory, headerValidator, integrityValidator, checkpoints, chainState, finalizedBlockHeight, consensusSettings, signals);

            this.peerLock               = new object();
            this.reorgLock              = new AsyncLock();
            this.blockRequestedLock     = new object();
            this.expectedBlockDataBytes = 0;
            this.expectedBlockSizes     = new Dictionary <uint256, long>();

            this.callbacksByBlocksRequestedHash = new Dictionary <uint256, List <OnBlockDownloadedCallback> >();
            this.peersByPeerId   = new Dictionary <int, INetworkPeer>();
            this.toDownloadQueue = new Queue <BlockDownloadRequest>();
            this.ibdState        = ibdState;

            ProtocolVersion protocolVersion = nodeSettings.ProtocolVersion;

            this.blockPuller = new BlockPuller(this.BlockDownloaded, this.chainState, protocolVersion, dateTimeProvider, loggerFactory);
        }
Esempio n. 25
0
        public UnreliablePeerBehavior(Network network, IChainState chainState, ILoggerFactory loggerFactory, IPeerBanning peerBanning, NodeSettings nodeSettings)
        {
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(chainState, nameof(chainState));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(peerBanning, nameof(nodeSettings));
            Guard.NotNull(nodeSettings, nameof(nodeSettings));

            this.network       = network;
            this.chainState    = chainState;
            this.loggerFactory = loggerFactory;
            this.peerBanning   = peerBanning;
            this.nodeSettings  = nodeSettings;

            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
        }
 public ProvenHeadersConsensusManagerBehavior(
     ConcurrentChain chain,
     IInitialBlockDownloadState initialBlockDownloadState,
     IConsensusManager consensusManager,
     IPeerBanning peerBanning,
     ILoggerFactory loggerFactory,
     Network network,
     IChainState chainState) : base(chain, initialBlockDownloadState, consensusManager, peerBanning, loggerFactory)
 {
     this.chain = chain;
     this.initialBlockDownloadState = initialBlockDownloadState;
     this.consensusManager          = consensusManager;
     this.peerBanning   = peerBanning;
     this.network       = network;
     this.loggerFactory = loggerFactory;
     this.logger        = loggerFactory.CreateLogger(this.GetType().FullName, $"[{this.GetHashCode():x}] ");
     this.chainState    = chainState;
 }
Esempio n. 27
0
        public UnreliablePeerBehavior(Network network, IChainState chainState, ILoggerFactory loggerFactory, IPeerBanning peerBanning, NodeSettings nodeSettings, ICheckpoints checkpoints)
        {
            Guard.NotNull(network, nameof(network));
            Guard.NotNull(chainState, nameof(chainState));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(peerBanning, nameof(nodeSettings));
            Guard.NotNull(nodeSettings, nameof(nodeSettings));
            Guard.NotNull(checkpoints, nameof(checkpoints));

            this.network       = network;
            this.chainState    = chainState;
            this.loggerFactory = loggerFactory;
            this.peerBanning   = peerBanning;
            this.nodeSettings  = nodeSettings;
            this.checkpoints   = checkpoints;

            this.logger = loggerFactory.CreateLogger("Impleum.Bitcoin.Fullnode");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="WhitelistManager"/> class.
        /// </summary>
        /// <param name="dateTimeProvider">The provider for datetime.</param>
        /// <param name="loggerFactory">The factory to create the logger.</param>
        /// <param name="peerAddressManager">The manager implementation for peer addresses.</param>
        /// <param name="dnsServer">The DNS server.</param>
        /// <param name="connectionSettings">The connection settings.</param>
        /// <param name="dnsSettings">The DNS settings.</param>
        /// <param name="peerBanning">Peer banning component.</param>
        public WhitelistManager(IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, IPeerAddressManager peerAddressManager, IDnsServer dnsServer, ConnectionManagerSettings connectionSettings, DnsSettings dnsSettings, IPeerBanning peerBanning)
        {
            Guard.NotNull(dateTimeProvider, nameof(dateTimeProvider));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(peerAddressManager, nameof(peerAddressManager));
            Guard.NotNull(dnsServer, nameof(dnsServer));
            Guard.NotNull(dnsSettings, nameof(dnsSettings));
            Guard.NotNull(connectionSettings, nameof(connectionSettings));
            Guard.NotNull(peerBanning, nameof(peerBanning));

            this.dateTimeProvider   = dateTimeProvider;
            this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
            this.peerAddressManager = peerAddressManager;
            this.dnsServer          = dnsServer;
            this.dnsSettings        = dnsSettings;
            this.externalEndpoint   = connectionSettings.ExternalEndpoint;
            this.peerBanning        = peerBanning;
        }
Esempio n. 29
0
        public PoAFeature(FederationManager federationManager, PayloadProvider payloadProvider, IConnectionManager connectionManager, ConcurrentChain chain,
                          IInitialBlockDownloadState initialBlockDownloadState, IConsensusManager consensusManager, IPeerBanning peerBanning, ILoggerFactory loggerFactory,
                          IPoAMiner miner, VotingManager votingManager, Network network, WhitelistedHashesRepository whitelistedHashesRepository)
        {
            this.federationManager           = federationManager;
            this.connectionManager           = connectionManager;
            this.chain                       = chain;
            this.initialBlockDownloadState   = initialBlockDownloadState;
            this.consensusManager            = consensusManager;
            this.peerBanning                 = peerBanning;
            this.loggerFactory               = loggerFactory;
            this.miner                       = miner;
            this.votingManager               = votingManager;
            this.whitelistedHashesRepository = whitelistedHashesRepository;
            this.network                     = network;

            payloadProvider.DiscoverPayloads(this.GetType().Assembly);
        }
Esempio n. 30
0
        /// <summary>
        /// Initializes a new instance of the object.
        /// </summary>
        /// <param name="nodeSettings">User defined node settings.</param>
        /// <param name="dataFolder">Locations of important folders and files on disk.</param>
        /// <param name="nodeLifetime">Global application life cycle control - triggers when application shuts down.</param>
        /// <param name="chain">Thread safe access to the best chain of block headers (that the node is aware of) from genesis.</param>
        /// <param name="chainState">Information about node's chain.</param>
        /// <param name="connectionManager">Manager of node's network connections.</param>
        /// <param name="finalizedBlockHeight"><inheritdoc cref="IFinalizedBlockHeight"/></param>
        /// <param name="chainRepository">Access to the database of blocks.</param>
        /// <param name="dateTimeProvider">Provider of time functions.</param>
        /// <param name="asyncLoopFactory">Factory for creating background async loop tasks.</param>
        /// <param name="timeSyncBehaviorState">State of time synchronization feature that stores collected data samples.</param>
        /// <param name="dbreezeSerializer">Provider of binary (de)serialization for data stored in the database.</param>
        /// <param name="loggerFactory">Factory to be used to create logger for the node.</param>
        /// <param name="initialBlockDownloadState">Provider of IBD state.</param>
        /// <param name="bestChainSelector">Selects the best available chain based on tips provided by the peers and switches to it.</param>
        public BaseFeature(
            NodeSettings nodeSettings,
            DataFolder dataFolder,
            INodeLifetime nodeLifetime,
            ConcurrentChain chain,
            IChainState chainState,
            IConnectionManager connectionManager,
            IChainRepository chainRepository,
            IFinalizedBlockHeight finalizedBlockHeight,
            IDateTimeProvider dateTimeProvider,
            IAsyncLoopFactory asyncLoopFactory,
            ITimeSyncBehaviorState timeSyncBehaviorState,
            DBreezeSerializer dbreezeSerializer,
            ILoggerFactory loggerFactory,
            IInitialBlockDownloadState initialBlockDownloadState,
            IPeerBanning peerBanning,
            IPeerAddressManager peerAddressManager,
            BestChainSelector bestChainSelector)
        {
            this.chainState           = Guard.NotNull(chainState, nameof(chainState));
            this.chainRepository      = Guard.NotNull(chainRepository, nameof(chainRepository));
            this.finalizedBlockHeight = Guard.NotNull(finalizedBlockHeight, nameof(finalizedBlockHeight));
            this.nodeSettings         = Guard.NotNull(nodeSettings, nameof(nodeSettings));
            this.dataFolder           = Guard.NotNull(dataFolder, nameof(dataFolder));
            this.nodeLifetime         = Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
            this.chain             = Guard.NotNull(chain, nameof(chain));
            this.connectionManager = Guard.NotNull(connectionManager, nameof(connectionManager));
            this.bestChainSelector = bestChainSelector;
            this.peerBanning       = Guard.NotNull(peerBanning, nameof(peerBanning));

            this.peerAddressManager = Guard.NotNull(peerAddressManager, nameof(peerAddressManager));
            this.peerAddressManager.PeerFilePath = this.dataFolder;

            this.initialBlockDownloadState = initialBlockDownloadState;
            this.dateTimeProvider          = dateTimeProvider;
            this.asyncLoopFactory          = asyncLoopFactory;
            this.timeSyncBehaviorState     = timeSyncBehaviorState;
            this.loggerFactory             = loggerFactory;
            this.dbreezeSerializer         = dbreezeSerializer;
            this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
            this.disposableResources = new List <IDisposable>();
        }