Пример #1
0
        protected override bool ProcessInventoryVector(InventoryVector inv, EndPoint remoteSocketEndpoint)
        {
            if (inv.Type.HasFlag(InventoryType.MSG_TX))
            {
                if (MempoolService.TryGetFromBroadcastStore(inv.Hash, out TransactionBroadcastEntry entry))                 // If we have the transaction then adjust confirmation.
                {
                    if (entry.NodeRemoteSocketEndpoint == remoteSocketEndpoint.ToString())
                    {
                        return(false);                        // Wtf, why are you trying to broadcast it back to us?
                    }

                    entry.ConfirmPropagationForGood();
                }

                // If we already processed it continue.
                if (MempoolService.IsProcessed(inv.Hash))
                {
                    return(false);
                }

                return(true);
            }

            if (inv.Type.HasFlag(InventoryType.MSG_BLOCK))
            {
                BlockInv?.Invoke(this, inv.Hash);
            }

            return(false);
        }
        private async void AttachedNode_MessageReceivedAsync(Node node, IncomingMessage message)
        {
            try
            {
                if (message.Message.Payload is TxPayload txPayload)
                {
                    Transaction?.Invoke(this, new SmartTransaction(txPayload.Object, Height.Mempool));
                }
                else if (message.Message.Payload is BlockPayload blockPayload)
                {
                    Block?.Invoke(this, blockPayload.Object);
                }
                else if (message.Message.Payload is InvPayload invPayload)
                {
                    var getDataPayload = new GetDataPayload();
                    foreach (var inv in invPayload.Inventory)
                    {
                        if (inv.Type.HasFlag(InventoryType.MSG_TX))
                        {
                            TransactionInv?.Invoke(this, inv.Hash);
                            getDataPayload.Inventory.Add(inv);
                        }

                        if (inv.Type.HasFlag(InventoryType.MSG_BLOCK))
                        {
                            BlockInv?.Invoke(this, inv.Hash);
                            getDataPayload.Inventory.Add(inv);
                        }
                    }

                    if (getDataPayload.Inventory.Any() && node.IsConnected)
                    {
                        // ask for the whole transaction
                        await node.SendMessageAsync(getDataPayload).ConfigureAwait(false);
                    }
                }
            }
            catch (OperationCanceledException ex)
            {
                Logger.LogDebug(ex);
            }
            catch (Exception ex)
            {
                Logger.LogInfo($"Ignoring {ex.GetType()}: {ex.Message}");
                Logger.LogDebug(ex);
            }
        }
        private async void AttachedNode_MessageReceivedAsync(Node node, IncomingMessage message)
        {
            try
            {
                if (message.Message.Payload is InvPayload invPayload)
                {
                    var payload = new GetDataPayload();
                    foreach (var inv in invPayload.Inventory)
                    {
                        if (inv.Type.HasFlag(InventoryType.MSG_TX))
                        {
                            TransactionInv?.Invoke(this, inv.Hash);
                            payload.Inventory.Add(inv);
                        }
                        else if (inv.Type.HasFlag(InventoryType.MSG_BLOCK))
                        {
                            BlockInv?.Invoke(this, inv.Hash);
                            payload.Inventory.Add(inv);
                        }
                    }

                    if (payload.Inventory.Any() && node.IsConnected)
                    {
                        // ask for the whole transaction
                        await node.SendMessageAsync(payload);
                    }
                }
                else if (message.Message.Payload is TxPayload txPayload)
                {
                    Transaction?.Invoke(this, txPayload.Object);
                }
                else if (message.Message.Payload is BlockPayload blockPayload)
                {
                    Block?.Invoke(this, blockPayload.Object);
                }
            }
            catch (OperationCanceledException ex)
            {
                Logger.LogDebug <TrustedNodeNotifyingBehavior>(ex);
            }
            catch (Exception ex)
            {
                Logger.LogInfo <TrustedNodeNotifyingBehavior>($"Ignoring {ex.GetType()}: {ex.Message}");
                Logger.LogDebug <TrustedNodeNotifyingBehavior>(ex);
            }
        }
Пример #4
0
 private void TrustedP2pBehavior_BlockInv(object?sender, uint256 e)
 {
     BlockInv?.Invoke(this, e);
 }