Exemple #1
0
        private void SendTimedRequest(Message message, BlockRequest br)
        {
            TimedBlockRequest blockRequest = new TimedBlockRequest(message, br, RequestTimeout);

            blockRequest.SetCurrentPeer(this);
            blockRequest.RequestTimedOut += TimedRequestOnRequestTimedOut;

            lock (_blockReqLock)
            {
                BlockRequests.Add(blockRequest);
            }

            EnqueueOutgoing(message, (_) =>
            {
                blockRequest.Start();

                if (blockRequest.IsById)
                {
                    _logger?.Trace($"[{this}] Block request sent {{ hash: {blockRequest.Id.ToHex()} }}");
                }
                else
                {
                    _logger?.Trace($"[{this}] Block request sent {{ height: {blockRequest.Height} }}");
                }
            });
        }
Exemple #2
0
        /// <summary>
        /// This method is used to stop the timer for a block request.
        /// </summary>
        /// <param name="block"></param>
        public void StopBlockTimer(Block block)
        {
            byte[] blockHash   = block.GetHashBytes();
            int    blockHeight = (int)block.Header.Index;

            _logger.Info($"Receiving block {block.BlockHashToHex} from {this} at height {blockHeight}, " +
                         $"with {block.Body.Transactions.Count} txns. (TransactionListCount = {block.Body.TransactionList.Count})");

            lock (_blockReqLock)
            {
                TimedBlockRequest req = BlockRequests.FirstOrDefault(b => (b.IsById && b.Id.BytesEqual(blockHash)) || (!b.IsById && b.Height == blockHeight));

                if (req != null)
                {
                    req.Cancel();
                    BlockRequests.Remove(req);
                }
            }
        }