コード例 #1
0
        public void NetworkPeerRequirementCheckForOutboundWithValidVersionAndInvalidServiceReturnsFalse()
        {
            NetworkPeerRequirement networkPeerRequirement = new NetworkPeerRequirement();

            networkPeerRequirement.MinVersion       = ProtocolVersion.POS_PROTOCOL_VERSION;
            networkPeerRequirement.RequiredServices = NetworkPeerServices.Network;
            Assert.False(networkPeerRequirement.Check(new VersionPayload()
            {
                Services = NetworkPeerServices.Nothing, Version = ProtocolVersion.POS_PROTOCOL_VERSION
            }, false, out string reason));
        }
コード例 #2
0
        public void NetworkPeerRequirementCheckForInboundWithValidVersionAndValidServiceReturnsTrue()
        {
            NetworkPeerRequirement networkPeerRequirement = new NetworkPeerRequirement();

            networkPeerRequirement.MinVersion       = ProtocolVersion.ALT_PROTOCOL_VERSION;
            networkPeerRequirement.RequiredServices = NetworkPeerServices.Network;
            Assert.True(networkPeerRequirement.Check(new VersionPayload()
            {
                Services = NetworkPeerServices.Network, Version = ProtocolVersion.ALT_PROTOCOL_VERSION
            }, true, out string reason));
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the object having a chain of block headers and a list of available nodes.
        /// </summary>
        /// <param name="chain">Chain of block headers.</param>
        /// <param name="nodes">Network peers of the node.</param>
        /// <param name="protocolVersion">Version of the protocol that the node supports.</param>
        /// <param name="loggerFactory">Factory to be used to create logger for the puller.</param>
        protected BlockPuller(ConcurrentChain chain, IReadOnlyNetworkPeerCollection nodes, ProtocolVersion protocolVersion, ILoggerFactory loggerFactory)
        {
            this.Chain                   = chain;
            this.Nodes                   = nodes;
            this.logger                  = loggerFactory.CreateLogger(this.GetType().FullName);
            this.downloadedBlocks        = new Dictionary <uint256, DownloadedBlock>();
            this.pendingInventoryVectors = new Queue <uint256>();
            this.assignedBlockTasks      = new Dictionary <uint256, BlockPullerBehavior>();
            this.peerQuality             = new QualityScore(QualityScoreHistoryLength, loggerFactory);

            // Set the default requirements.
            this.requirements = new NetworkPeerRequirement
            {
                MinVersion       = protocolVersion,
                RequiredServices = NetworkPeerServices.Network
            };
        }
コード例 #4
0
ファイル: BlockPuller.cs プロジェクト: emilm/city-chain
        public BlockPuller(IChainState chainState, NodeSettings nodeSettings, IDateTimeProvider dateTimeProvider, INodeStats nodeStats, ILoggerFactory loggerFactory)
        {
            this.reassignedJobsQueue = new Queue <DownloadJob>();
            this.downloadJobsQueue   = new Queue <DownloadJob>();

            this.assignedDownloadsByHash = new Dictionary <uint256, AssignedDownload>();
            this.assignedDownloadsSorted = new LinkedList <AssignedDownload>();
            this.assignedHeadersByPeerId = new Dictionary <int, List <ChainedHeader> >();

            this.averageBlockSizeBytes = new AverageCalculator(AverageBlockSizeSamplesCount);

            this.pullerBehaviorsByPeerId = new Dictionary <int, IBlockPullerBehavior>();

            this.processQueuesSignal = new AsyncManualResetEvent(false);
            this.queueLock           = new object();
            this.peerLock            = new object();
            this.assignedLock        = new object();
            this.nextJobId           = 0;

            ProtocolVersion protocolVersion = nodeSettings.ProtocolVersion;

            this.networkPeerRequirement = new NetworkPeerRequirement
            {
                MinVersion       = protocolVersion,
                RequiredServices = NetworkPeerServices.Network
            };

            this.cancellationSource = new CancellationTokenSource();
            this.random             = new Random();

            this.maxBlocksBeingDownloaded = MinimalCountOfBlocksBeingDownloaded;

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

            nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component);
        }
コード例 #5
0
 /// <summary>Parameterless constructor for dependency injection.</summary>
 protected PeerConnector(
     IAsyncLoopFactory asyncLoopFactory,
     IDateTimeProvider dateTimeProvider,
     ILoggerFactory loggerFactory,
     Network network,
     INetworkPeerFactory networkPeerFactory,
     INodeLifetime nodeLifetime,
     NodeSettings nodeSettings,
     IPeerAddressManager peerAddressManager)
 {
     this.asyncLoopFactory   = asyncLoopFactory;
     this.ConnectedPeers     = new NetworkPeerCollection();
     this.dateTimeProvider   = dateTimeProvider;
     this.loggerFactory      = loggerFactory;
     this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
     this.network            = network;
     this.networkPeerFactory = networkPeerFactory;
     this.nodeLifetime       = nodeLifetime;
     this.NodeSettings       = nodeSettings;
     this.peerAddressManager = peerAddressManager;
     this.Requirements       = new NetworkPeerRequirement {
         MinVersion = this.NodeSettings.ProtocolVersion
     };
 }
コード例 #6
0
        private IPeerConnector CreatePeerConnector(
            NetworkPeerConnectionParameters parameters,
            NetworkPeerServices requiredServices,
            Func <IPEndPoint, byte[]> peerSelector,
            PeerIntroductionType peerIntroductionType,
            int?maximumNodeConnections = 8)
        {
            this.logger.LogTrace("({0}:{1})", nameof(requiredServices), requiredServices);

            var nodeRequirement = new NetworkPeerRequirement
            {
                MinVersion       = this.NodeSettings.ProtocolVersion,
                RequiredServices = requiredServices,
            };

            var peerConnector = new PeerConnector(this.Network, this.nodeLifetime, parameters, nodeRequirement, peerSelector, this.asyncLoopFactory, this.peerAddressManager, peerIntroductionType, this.networkPeerFactory)
            {
                MaximumNodeConnections = maximumNodeConnections.Value
            };

            this.logger.LogTrace("(-)");

            return(peerConnector);
        }