Beispiel #1
0
 /// <summary>
 /// Task that runs until the application ends (or the passed cancellation token is canceled).
 /// </summary>
 /// <param name="cancellation"></param>
 public virtual async Task StartConnectionLoopAsync(CancellationToken cancellation)
 {
     await connectionLoop.StartAsync(
         label : "connectionLoop",
         work : ConnectionLoopAsync,
         ComputeDelayAdjustment,
         cancellation
         ).ConfigureAwait(false);
 }
        protected override ValueTask OnPeerHandshakedAsync()
        {
            _ = _periodicPing.StartAsync(
                label: $"{nameof(_periodicPing)}-{PeerContext.PeerId}",
                work: PingAsync,
                interval: TimeSpan.FromSeconds(PING_INTERVAL),
                cancellation: PeerContext.ConnectionCancellationTokenSource.Token
                );

            return(default);
Beispiel #3
0
        public override Task StartAsync(CancellationToken cancellationToken)
        {
            _ = _periodicPeerHealthCheck.StartAsync(
                label: nameof(_periodicPeerHealthCheck),
                work: StartCheckingPeerHealthAsync,
                interval: TimeSpan.FromSeconds(10),
                cancellation: cancellationToken
                );

            return(base.StartAsync(cancellationToken));
        }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            _blockValidationRules.SetupRules();

            // starts the consumer loop of header validation
            _validationLoop.StartAsync(
                label: nameof(BlockValidator),
                work: ValidationWorkAsync,
                interval: TimeSpan.Zero,
                cancellationToken
                );

            return(Task.CompletedTask);
        }
Beispiel #5
0
        /// <summary>
        /// When the peer handshake, sends <see cref="SendCmpctMessage" />  and <see cref="SendHeadersMessage" /> if the
        /// negotiated protocol allow that and update peer status based on its version message.
        /// </summary>
        /// <returns></returns>
        protected override async ValueTask OnPeerHandshakedAsync()
        {
            HandshakeProcessor.HandshakeProcessorStatus handshakeStatus = PeerContext.Features.Get <HandshakeProcessor.HandshakeProcessorStatus>();

            VersionMessage peerVersion = handshakeStatus.PeerVersion !;

            _status.IsLimitedNode = PeerContext.IsLimitedNode;
            _status.IsClient      = PeerContext.IsClient;

            _status.PeerStartingHeight = peerVersion.StartHeight;
            _status.CanServeWitness    = PeerContext.CanServeWitness;

            await SendMessageAsync(minVersion : KnownVersion.V70012, new SendHeadersMessage()).ConfigureAwait(false);

            if (IsSupported(KnownVersion.V70014))
            {
                // Tell our peer we are willing to provide version 1 or 2 cmpctblocks.
                // However, we do not request new block announcements using cmpctblock messages.
                // We send this to non-NODE NETWORK peers as well, because they may wish to request compact blocks from us.
                if (_localServiceProvider.HasServices(NodeServices.Witness))
                {
                    await SendMessageAsync(new SendCmpctMessage { AnnounceUsingCompactBlock = false, Version = 2 }).ConfigureAwait(false);
                }

                await SendMessageAsync(new SendCmpctMessage { AnnounceUsingCompactBlock = false, Version = 1 }).ConfigureAwait(false);
            }


            // if this peer is able to serve blocks, register it
            if (!_status.IsClient)
            {
                _blockFetcherManager.RegisterFetcher(this);
            }

            // starts the header sync loop
            _ = _headerSyncLoop.StartAsync(
                label: $"{nameof(_headerSyncLoop)}-{PeerContext.PeerId}",
                work: SyncLoopAsync,
                interval: TimeSpan.FromMilliseconds(SYNC_LOOP_INTERVAL),
                cancellation: PeerContext.ConnectionCancellationTokenSource.Token
                );
        }