// Check if pending items must be received private void UpdatePendingItems() { for (int i = pendingItems.Count - 1; i >= 0; i--) { PendingInventoryItem pendingItem = pendingItems[i]; if (pendingItem == null || pendingItem.TimeRemaining > 0.0f) { continue; } currencyBonus += pendingItem.ItemData.CurrencyBonus; OnDeliveredItem(pendingItem.ItemData); pendingItems.RemoveAt(i); } }
static void handleInventory2(byte[] data, RemoteEndpoint endpoint) { using (MemoryStream m = new MemoryStream(data)) { using (BinaryReader reader = new BinaryReader(m)) { ulong item_count = reader.ReadIxiVarUInt(); if (item_count > (ulong)CoreConfig.maxInventoryItems) { Logging.warn("Received {0} inventory items, max items is {1}", item_count, CoreConfig.maxInventoryItems); item_count = (ulong)CoreConfig.maxInventoryItems; } ulong last_block_height = IxianHandler.getLastBlockHeight(); Dictionary <ulong, List <InventoryItemSignature> > sig_lists = new Dictionary <ulong, List <InventoryItemSignature> >(); List <InventoryItemKeepAlive> ka_list = new List <InventoryItemKeepAlive>(); List <byte[]> tx_list = new List <byte[]>(); bool request_next_block = false; for (ulong i = 0; i < item_count; i++) { ulong len = reader.ReadIxiVarUInt(); byte[] item_bytes = reader.ReadBytes((int)len); InventoryItem item = InventoryCache.decodeInventoryItem(item_bytes); if (item.type == InventoryItemTypes.transaction) { PendingTransactions.increaseReceivedCount(item.hash, endpoint.presence.wallet); } PendingInventoryItem pii = Node.inventoryCache.add(item, endpoint); if (!pii.processed && pii.lastRequested == 0) { // first time we're seeing this inventory item switch (item.type) { case InventoryItemTypes.keepAlive: ka_list.Add((InventoryItemKeepAlive)item); pii.lastRequested = Clock.getTimestamp(); break; case InventoryItemTypes.transaction: tx_list.Add(item.hash); pii.lastRequested = Clock.getTimestamp(); break; case InventoryItemTypes.blockSignature: var iis = (InventoryItemSignature)item; if (iis.blockNum < last_block_height - 5 && iis.blockNum > last_block_height + 6) { continue; } if (!sig_lists.ContainsKey(iis.blockNum)) { sig_lists.Add(iis.blockNum, new List <InventoryItemSignature>()); } sig_lists[iis.blockNum].Add(iis); pii.lastRequested = Clock.getTimestamp(); break; case InventoryItemTypes.block: var iib = ((InventoryItemBlock)item); if (iib.blockNum <= last_block_height) { Node.inventoryCache.processInventoryItem(pii); } else { pii.lastRequested = Clock.getTimestamp(); request_next_block = true; if (iib.blockNum > endpoint.blockHeight) { endpoint.blockHeight = iib.blockNum; } if (iib.blockNum > Node.blockProcessor.highestNetworkBlockNum) { Node.blockProcessor.highestNetworkBlockNum = iib.blockNum; } } break; default: Node.inventoryCache.processInventoryItem(pii); break; } } } PresenceProtocolMessages.broadcastGetKeepAlives(ka_list, endpoint); if (Node.blockSync.synchronizing) { return; } TransactionProtocolMessages.broadcastGetTransactions(tx_list, 0, endpoint); if (request_next_block) { byte include_tx = 2; if (Node.isMasterNode()) { include_tx = 0; } BlockProtocolMessages.broadcastGetBlock(last_block_height + 1, null, endpoint, include_tx, true); } foreach (var sig_list in sig_lists) { SignatureProtocolMessages.broadcastGetSignatures(sig_list.Key, sig_list.Value, endpoint); } } } }