当前位置: 首页>>代码示例>>C#>>正文


C# Node.SendMessageAsync方法代码示例

本文整理汇总了C#中Node.SendMessageAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Node.SendMessageAsync方法的具体用法?C# Node.SendMessageAsync怎么用?C# Node.SendMessageAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Node的用法示例。


在下文中一共展示了Node.SendMessageAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AttachedNode_MessageReceived

		void AttachedNode_MessageReceived(Node node, IncomingMessage message)
		{
			var getaddr = message.Message.Payload as GetAddrPayload;
			if(getaddr != null)
			{
				node.SendMessageAsync(new AddrPayload(AddressManager.GetAddr().Take(1000).ToArray()));
			}
			var addr = message.Message.Payload as AddrPayload;
			if(addr != null)
			{
				AddressManager.Add(addr.Addresses, node.RemoteSocketAddress);
			}
		}
开发者ID:crowar,项目名称:NBitcoin,代码行数:13,代码来源:AddressManagerBehavior.cs

示例2: AttachedNode_MessageReceived

		void AttachedNode_MessageReceived(Node node, IncomingMessage message)
		{
			var filterload = message.Message.Payload as FilterLoadPayload;
			if(filterload != null)
			{
				_Filter = filterload.Object;
			}
			var filteradd = message.Message.Payload as FilterAddPayload;
			if(filteradd != null)
			{
				_Filter.Insert(filteradd.Data);
			}
			var getdata = message.Message.Payload as GetDataPayload;
			if(getdata != null)
			{
				foreach(var inv in getdata.Inventory)
				{
					if(inv.Type == InventoryType.MSG_FILTERED_BLOCK && _Filter != null)
					{
						var merkle = new MerkleBlock(_Blocks[inv.Hash], _Filter);
						AttachedNode.SendMessageAsync(new MerkleBlockPayload(merkle));
						foreach(var tx in merkle.PartialMerkleTree.GetMatchedTransactions())
						{
							if(_Known.TryAdd(tx, tx))
							{
								AttachedNode.SendMessageAsync(new InvPayload(InventoryType.MSG_TX, tx));
							}
						}
					}
					var found = FindTransaction(inv.Hash);
					if(inv.Type == InventoryType.MSG_TX && found != null)
						AttachedNode.SendMessageAsync(new TxPayload(found));
				}
			}
			var mempool = message.Message.Payload as MempoolPayload;
			if(mempool != null)
			{
				foreach(var tx in _Builder.Mempool)
				{
					BroadcastCore(tx.Value);
				}
			}

			var invs = message.Message.Payload as InvPayload;
			if(invs != null)
			{
				node.SendMessageAsync(new GetDataPayload(invs.ToArray()));
			}

			var txPayload = message.Message.Payload as TxPayload;
			if(txPayload != null)
			{
				if(!_ReceivedTransactions.TryAdd(txPayload.Object.GetHash(), txPayload.Object))
				{
					node.SendMessageAsync(new RejectPayload()
					{
						Hash = txPayload.Object.GetHash(),
						Code = RejectCode.DUPLICATE,
						Message = "tx"
					});
				}
				else
				{
					foreach(var other in Nodes.Where(n => n != node))
					{
						other.SendMessageAsync(new InvPayload(txPayload.Object));
					}
				}
			}
		}
开发者ID:vebin,项目名称:NBitcoin,代码行数:70,代码来源:spv_tests.cs

示例3: AttachedNode_MessageReceived

		void AttachedNode_MessageReceived(Node node, IncomingMessage message)
		{
			if(!PingVersion())
				return;
			var ping = message.Message.Payload as PingPayload;
			if(ping != null && Mode.HasFlag(PingPongMode.RespondPong))
			{
				node.SendMessageAsync(new PongPayload()
				{
					Nonce = ping.Nonce
				});
			}
			var pong = message.Message.Payload as PongPayload;
			if(pong != null &&
				Mode.HasFlag(PingPongMode.SendPing) &&
				_CurrentPing != null &&
				_CurrentPing.Nonce == pong.Nonce)
			{
				Latency = DateTimeOffset.UtcNow - _DateSent;
				ClearCurrentPing();
			}
		}
开发者ID:crowar,项目名称:NBitcoin,代码行数:22,代码来源:PingPongBehavior.cs

示例4: AttachedNode_MessageReceived

			void AttachedNode_MessageReceived(Node node, IncomingMessage message)
			{
				TxPayload txPayload = message.Message.Payload as TxPayload;
				if(txPayload != null)
				{
					Transaction tx;
					var hash = txPayload.Object.GetHash();
					if(_Wallet._BroadcastedTransaction.TryRemove(hash, out tx))
					{
						_Broadcasting.TryRemove(hash, out tx);
						_Wallet.OnTransactionBroadcasted(tx, node);
					}
				}
				RejectPayload reject = message.Message.Payload as RejectPayload;
				if(reject != null)
				{
					Transaction tx;
					if(_Broadcasting.TryRemove(reject.Hash, out tx))
					{
						_Wallet.OnTransactionRejected(tx, node);
					}
				}

				GetDataPayload getData = message.Message.Payload as GetDataPayload;
				if(getData != null)
				{
					foreach(var inventory in getData.Inventory.Where(i => i.Type == InventoryType.MSG_TX))
					{
						Transaction tx;
						if(_Broadcasting.TryRemove(inventory.Hash, out tx))
							node.SendMessageAsync(new TxPayload(tx));
					}
				}
			}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:34,代码来源:Wallet.cs

示例5: AttachedNode_MessageReceived

		void AttachedNode_MessageReceived(Node node, IncomingMessage message)
		{
			InvPayload invPayload = message.Message.Payload as InvPayload;
			if(invPayload != null)
			{

				foreach(var hash in invPayload.Where(i => i.Type == InventoryType.MSG_TX).Select(i => i.Hash))
				{
					var tx = GetTransaction(hash, true);
					if(tx != null)
						tx.State = BroadcastState.Accepted;
					Transaction unused;
					if(_BroadcastHub.BroadcastedTransaction.TryRemove(hash, out unused))
					{
						_BroadcastHub.OnTransactionBroadcasted(tx.Transaction);
					}
				}
			}
			RejectPayload reject = message.Message.Payload as RejectPayload;
			if(reject != null && reject.Message == "tx")
			{
				var tx = GetTransaction(reject.Hash, true);
				if(tx != null)
					tx.State = BroadcastState.Rejected;
				Transaction tx2;
				if(_BroadcastHub.BroadcastedTransaction.TryRemove(reject.Hash, out tx2))
				{
					_BroadcastHub.OnTransactionRejected(tx2, reject);
				}

			}

			GetDataPayload getData = message.Message.Payload as GetDataPayload;
			if(getData != null)
			{
				foreach(var inventory in getData.Inventory.Where(i => i.Type == InventoryType.MSG_TX))
				{
					var tx = GetTransaction(inventory.Hash, false);
					if(tx != null)
					{
						tx.State = BroadcastState.Broadcasted;
						var ping = new PingPayload();
						tx.PingValue = ping.Nonce;
						_PingToTransaction.TryAdd(tx.PingValue, tx);
						node.SendMessageAsync(new TxPayload(tx.Transaction));
						node.SendMessageAsync(ping);
					}
				}
			}

			PongPayload pong = message.Message.Payload as PongPayload;
			if(pong != null)
			{
				var tx = GetTransaction(pong.Nonce, true);
				if(tx != null)
				{
					tx.State = BroadcastState.Accepted;
					Transaction unused;
					if(_BroadcastHub.BroadcastedTransaction.TryRemove(tx.Transaction.GetHash(), out unused))
					{
						_BroadcastHub.OnTransactionBroadcasted(tx.Transaction);
					}
				}
			}
		}
开发者ID:n1rvana,项目名称:NBitcoin,代码行数:65,代码来源:BroadcastTransactionBehavior.cs


注:本文中的Node.SendMessageAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。