Esempio n. 1
0
        /// <summary>
        /// Asks the connected peer for the block of the given hash, and returns a Future representing the answer.
        /// If you want the block right away and don't mind waiting for it, just call .get() on the result. Your thread
        /// will block until the peer answers. You can also use the Future object to wait with a timeout, or just check
        /// whether it's done later.
        /// </summary>
        /// <param name="blockHash">Hash of the block you were requesting.</param>
        /// <exception cref="IOException"/>
        public IAsyncResult BeginGetBlock(Sha256Hash blockHash, AsyncCallback callback, object state)
        {
            var getdata       = new GetDataMessage(_params);
            var inventoryItem = new InventoryItem(InventoryItem.ItemType.Block, blockHash);

            getdata.AddItem(inventoryItem);
            var future = new GetDataFuture <Block>(inventoryItem, callback, state);

            // Add to the list of things we're waiting for. It's important this come before the network send to avoid
            // race conditions.
            lock (_pendingGetBlockFutures)
            {
                _pendingGetBlockFutures.Add(future);
            }
            _conn.WriteMessage(getdata);
            return(future);
        }
Esempio n. 2
0
        /// <summary>
        /// Asks the connected peer for the block of the given hash, and returns a Future representing the answer.
        /// If you want the block right away and don't mind waiting for it, just call .get() on the result. Your thread
        /// will block until the peer answers. You can also use the Future object to wait with a timeout, or just check
        /// whether it's done later.
        /// </summary>
        /// <param name="blockHash">Hash of the block you were requesting.</param>
        /// <exception cref="System.IO.IOException" />
        public GetDataFuture <Block> GetBlock(byte[] blockHash)
        {
            var getdata       = new InventoryMessage(_params);
            var inventoryItem = new InventoryItem(InventoryItem.ItemType.Block, blockHash);

            getdata.AddItem(inventoryItem);
            var future = new GetDataFuture <Block>(this, inventoryItem);

            // Add to the list of things we're waiting for. It's important this come before the network send to avoid
            // race conditions.
            lock (_pendingGetBlockFutures)
            {
                _pendingGetBlockFutures.Add(future);
            }
            _conn.WriteMessage(getdata);
            return(future);
        }
Esempio n. 3
0
 /// <summary>
 /// Asks the connected peer for the block of the given hash, and returns a Future representing the answer.
 /// If you want the block right away and don't mind waiting for it, just call .get() on the result. Your thread
 /// will block until the peer answers. You can also use the Future object to wait with a timeout, or just check
 /// whether it's done later.
 /// </summary>
 /// <param name="blockHash">Hash of the block you were requesting.</param>
 /// <exception cref="IOException"/>
 public IAsyncResult BeginGetBlock(Sha256Hash blockHash, AsyncCallback callback, object state)
 {
     var getdata = new GetDataMessage(_params);
     var inventoryItem = new InventoryItem(InventoryItem.ItemType.Block, blockHash);
     getdata.AddItem(inventoryItem);
     var future = new GetDataFuture<Block>(inventoryItem, callback, state);
     // Add to the list of things we're waiting for. It's important this come before the network send to avoid
     // race conditions.
     lock (_pendingGetBlockFutures)
     {
         _pendingGetBlockFutures.Add(future);
     }
     _conn.WriteMessage(getdata);
     return future;
 }