Пример #1
0
 internal async Task RelayAsync(Inventory data)
 {
     await SendMessageAsync("inv", InvPayload.Create(data.InventoryType, data.Hash));
 }
Пример #2
0
 private async Task<bool> RelayInternalAsync(Inventory data)
 {
     if (connectedPeers.Count == 0) return false;
     RemoteNode[] remoteNodes;
     lock (connectedPeers)
     {
         if (connectedPeers.Count == 0) return false;
         remoteNodes = connectedPeers.Values.ToArray();
     }
     if (remoteNodes.Length == 0) return false;
     RelayCache.Add(data);
     await Task.WhenAny(remoteNodes.Select(p => p.RelayAsync(data)));
     return true;
 }
Пример #3
0
 private void OnInventoryReceived(Inventory inventory)
 {
     lock (KnownHashes)
     {
         KnownHashes.Add(inventory.Hash);
     }
     lock (missions_global)
     {
         missions_global.Remove(inventory.Hash);
     }
     missions.Remove(inventory.Hash);
     if (inventory is Block)
     {
         if (BlockReceived != null) BlockReceived(this, (Block)inventory);
     }
     else if (inventory is Transaction)
     {
         if (TransactionReceived != null) TransactionReceived(this, (Transaction)inventory);
     }
 }
Пример #4
0
 public async Task<bool> RelayAsync(Inventory data)
 {
     bool result = await RelayInternalAsync(data);
     if (data is Block)
     {
         if (Blockchain.Default != null && !Blockchain.Default.ContainsBlock(data.Hash) && Blockchain.Default.AddBlock(data as Block))
         {
             if (NewInventory != null) NewInventory(this, data);
         }
     }
     else if (data is Transaction)
     {
         if (Blockchain.Default != null && !Blockchain.Default.ContainsTransaction(data.Hash) && Blockchain.Default.AddTransaction(data as Transaction))
         {
             if (NewInventory != null) NewInventory(this, data);
         }
     }
     return result;
 }