public bool processInventoryItem(PendingInventoryItem pii) { if (pii == null) { Logging.error("Cannot process pendingInventoryItem, PendingInventoryItem is null."); return(false); } if (pii.processed) { return(false); } try { var endpoints = pii.endpoints.OrderBy(x => rnd.Next()); RemoteEndpoint endpoint = null; if (endpoints.Count() > 0) { foreach (var ep in endpoints) { if (ep.isConnected() && ep.helloReceived) { endpoint = ep; break; } else { pii.endpoints.Remove(ep); } } } if (sendInventoryRequest(pii.item, endpoint)) { pii.lastRequested = Clock.getTimestamp(); if (pii.retryCount > typeOptions[pii.item.type].maxRetries) { pii.processed = true; } pii.retryCount++; return(true); } else { pii.processed = true; } return(false); } catch (Exception e) { Logging.error("Exception occured in processInventoryItem: {0}", e); pii.processed = true; } return(false); }
public PendingInventoryItem add(InventoryItem item, RemoteEndpoint endpoint) { lock (inventory) { var inventory_list = inventory[item.type]; if (item.hash == null) { Logging.error("Error adding inventory item, hash is null."); return(null); } if (!inventory_list.ContainsKey(item.hash)) { PendingInventoryItem pii = new PendingInventoryItem(item); if (endpoint != null) { pii.endpoints.Add(endpoint); } inventory_list.Add(item.hash, pii); truncateInventory(item.type); return(pii); } else { PendingInventoryItem pii = inventory_list[item.hash]; pii.item = item; if (endpoint != null) { if (!pii.endpoints.Contains(endpoint)) { pii.endpoints.Add(endpoint); } } return(pii); } } }