Example #1
0
        /// <summary>
        /// Send a announcement to the peer using the stream call.
        /// Note: this method is not thread safe.
        /// </summary>
        private async Task SendAnnouncementAsync(BlockAnnouncement header)
        {
            if (_announcementStreamCall == null)
            {
                _announcementStreamCall = _client.AnnouncementBroadcastStream(new Metadata {
                    { GrpcConstants.SessionIdMetadataKey, OutboundSessionId }
                });
            }

            try
            {
                await _announcementStreamCall.RequestStream.WriteAsync(header);
            }
            catch (RpcException)
            {
                _announcementStreamCall.Dispose();
                _announcementStreamCall = null;

                throw;
            }
        }
Example #2
0
        /// <summary>
        /// Send a announcement to the peer using the stream call.
        /// Note: this method is not thread safe.
        /// </summary>
        public async Task SendAnnouncementAsync(BlockAnnouncement header)
        {
            if (!IsConnected)
            {
                return;
            }

            if (_announcementStreamCall == null)
            {
                _announcementStreamCall = _client.AnnouncementBroadcastStream();
            }

            try
            {
                await _announcementStreamCall.RequestStream.WriteAsync(header);
            }
            catch (RpcException e)
            {
                _announcementStreamCall.Dispose();
                _announcementStreamCall = null;

                HandleFailure(e, $"Error during announcement broadcast: {header.BlockHash}.");
            }
        }