コード例 #1
0
 void Ping(object state)
 {
     ListenerTrace.Verbose("Ping");
     _Node.SendMessage(new PingPayload());
     ListenerTrace.Verbose("Ping");
     _SenderNode.SendMessage(new PingPayload());
 }
コード例 #2
0
 private void DeleteExpiredBroadcasted(CloudTableEvent evt, uint256 hash)
 {
     if (evt.AddedEntity != null)
     {
         if (DateTimeOffset.UtcNow - evt.AddedEntity.Timestamp > TimeSpan.FromHours(24.0))
         {
             ListenerTrace.Verbose("Cleaning expired broadcasted " + hash);
             DeleteBroadcasted(evt.AddedEntity, hash);
         }
     }
 }
コード例 #3
0
 void _SenderNode_MessageReceived(Node node, IncomingMessage message)
 {
     if (message.Message.Payload is GetDataPayload)
     {
         var getData = (GetDataPayload)message.Message.Payload;
         foreach (var data in getData.Inventory)
         {
             if (data.Type == InventoryType.MSG_TX && _BroadcastedTransactions.ContainsKey(data.Hash))
             {
                 var result = _BroadcastedTransactions[data.Hash];
                 var tx     = new TxPayload(result.Transaction);
                 node.SendMessage(tx);
                 ListenerTrace.Info("Broadcasted " + data.Hash);
                 try
                 {
                     Configuration.GetBroadcastedTransactionsListenable().CloudTable.Execute(TableOperation.Delete(result.ToEntity()));
                 }
                 catch (StorageException)
                 {
                 }
             }
         }
     }
     if (message.Message.Payload is RejectPayload)
     {
         var     reject = (RejectPayload)message.Message.Payload;
         uint256 txId   = reject.Hash;
         if (txId != null && _BroadcastedTransactions.ContainsKey(txId))
         {
             ListenerTrace.Info("Broadcasted transaction rejected (" + reject.Code + ") " + txId);
             DeleteBroadcasted(txId);
             if (reject.Code != RejectCode.DUPLICATE)
             {
                 UpdateBroadcastState(txId, reject.Code.ToString());
             }
         }
     }
     if (message.Message.Payload is PongPayload)
     {
         ListenerTrace.Verbose("Pong");
     }
 }
コード例 #4
0
        void node_MessageReceived(Node node, IncomingMessage message)
        {
            if (message.Message.Payload is InvPayload)
            {
                var inv = (InvPayload)message.Message.Payload;
                foreach (var inventory in inv.Inventory.Where(i => _BroadcastedTransactions.ContainsKey(i.Hash)))
                {
                    ListenerTrace.Info("Broadcasted reached mempool " + inventory);
                }
                node.SendMessage(new GetDataPayload(inv.Inventory.ToArray()));
            }
            if (message.Message.Payload is TxPayload)
            {
                var tx = ((TxPayload)message.Message.Payload).Object;
                ListenerTrace.Verbose("Received Transaction " + tx.GetHash());
                RunTask("New transaction", () =>
                {
                    var txId = tx.GetHash();
                    _Indexer.Index(new TransactionEntry.Entity(txId, tx, null));
                    _Indexer.IndexOrderedBalance(tx);
                    RunTask("New transaction", () =>
                    {
                        var balances =
                            OrderedBalanceChange
                            .ExtractWalletBalances(txId, tx, null, null, int.MaxValue, _Wallets)
                            .GroupBy(b => b.PartitionKey);
                        foreach (var b in balances)
                        {
                            _Indexer.Index(b);
                        }
                    }, true);
                }, false);
            }
            if (message.Message.Payload is BlockPayload)
            {
                var block = ((BlockPayload)message.Message.Payload).Object;
                ListenerTrace.Info("Received block " + block.GetHash());
                RunTask("New block", () =>
                {
                    var blockId = block.GetHash();
                    node.SynchronizeChain(_Chain);
                    _Indexer.IndexChain(_Chain);
                    ListenerTrace.Info("New height : " + _Chain.Height);
                    var header = _Chain.GetBlock(blockId);
                    if (header == null)
                    {
                        return;
                    }
                    _Indexer.IndexWalletOrderedBalance(header.Height, block, _Wallets);

                    RunTask("New block", () =>
                    {
                        _Indexer.Index(block);
                    }, false);
                    RunTask("New block", () =>
                    {
                        _Indexer.IndexTransactions(header.Height, block);
                    }, false);
                    RunTask("New block", () =>
                    {
                        _Indexer.IndexOrderedBalance(header.Height, block);
                    }, false);
                }, true);
            }
            if (message.Message.Payload is PongPayload)
            {
                ListenerTrace.Verbose("Pong");
            }
        }