/// <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 !; await SendMessageAsync(minVersion : KnownVersion.V70012, new SendHeadersMessage()).ConfigureAwait(false); }
/// <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 ); }