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


C# IncomingMessage.AssertPayload方法代码示例

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


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

示例1: ProcessMessageCore

        private void ProcessMessageCore(IncomingMessage message)
        {
            if(message.Message.Payload is VersionPayload)
            {
                var version = message.AssertPayload<VersionPayload>();
                var connectedToSelf = version.Nonce == Nonce;
                if(message.Node != null && connectedToSelf)
                {
                    NodeServerTrace.ConnectionToSelfDetected();
                    message.Node.Disconnect();
                    return;
                }
                if(message.Node == null)
                {
                    var remoteEndpoint = version.AddressFrom;
                    if(!remoteEndpoint.Address.IsRoutable(AllowLocalPeers))
                    {
                        //Send his own endpoint
                        remoteEndpoint = new IPEndPoint(((IPEndPoint)message.Socket.RemoteEndPoint).Address, Network.DefaultPort);
                    }

                    if(IsConnectedTo(remoteEndpoint))
                    {
                        NodeServerTrace.Warning("Ongoing connection with " + remoteEndpoint + " detected, aborting the incoming connection attempt");
                        Utils.SafeCloseSocket(message.Socket);
                        return;
                    }

                    var node = new Node(new Peer(PeerOrigin.Advertised, new NetworkAddress()
                    {
                        Endpoint = remoteEndpoint,
                        Time = DateTimeOffset.UtcNow
                    }), this, message.Socket, version);

                    if(connectedToSelf)
                    {
                        node.SendMessage(CreateVersionPayload(node.Peer, ExternalEndpoint, Version));
                        NodeServerTrace.ConnectionToSelfDetected();
                        node.Disconnect();
                        return;
                    }

                    CancellationTokenSource cancel = new CancellationTokenSource();
                    cancel.CancelAfter(TimeSpan.FromSeconds(10.0));
                    try
                    {
                        node.RespondToHandShake(cancel.Token);
                        AddNode(node);
                    }
                    catch(OperationCanceledException ex)
                    {
                        NodeServerTrace.Error("The remote node did not respond fast enough (10 seconds) to the handshake completion, dropping connection", ex);
                        node.Disconnect();
                        throw;
                    }
                    catch(Exception)
                    {
                        node.Disconnect();
                        throw;
                    }
                }
            }
        }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:63,代码来源:NodeServer.cs

示例2: ProcessMessageCore

		private void ProcessMessageCore(IncomingMessage message)
		{
			if(message.Message.Payload is VersionPayload)
			{
				var version = message.AssertPayload<VersionPayload>();
				var connectedToSelf = version.Nonce == Nonce;
				if(message.Node != null && connectedToSelf)
				{
					NodeServerTrace.ConnectionToSelfDetected();
					message.Node.DisconnectAsync();
					return;
				}

				if(message.Node == null)
				{
					var remoteEndpoint = version.AddressFrom;
					if(!remoteEndpoint.Address.IsRoutable(AllowLocalPeers))
					{
						//Send his own endpoint
						remoteEndpoint = new IPEndPoint(((IPEndPoint)message.Socket.RemoteEndPoint).Address, Network.DefaultPort);
					}

					var peer = new NetworkAddress()
					{
						Endpoint = remoteEndpoint,
						Time = DateTimeOffset.UtcNow
					};
					var node = new Node(peer, Network, CreateNodeConnectionParameters(), message.Socket, version);

					if(connectedToSelf)
					{
						node.SendMessage(CreateNodeConnectionParameters().CreateVersion(node.Peer.Endpoint, Network));
						NodeServerTrace.ConnectionToSelfDetected();
						node.Disconnect();
						return;
					}

					CancellationTokenSource cancel = new CancellationTokenSource();
					cancel.CancelAfter(TimeSpan.FromSeconds(10.0));
					try
					{
						ConnectedNodes.Add(node);
						node.StateChanged += node_StateChanged;
						node.RespondToHandShake(cancel.Token);
					}
					catch(OperationCanceledException ex)
					{
						NodeServerTrace.Error("The remote node did not respond fast enough (10 seconds) to the handshake completion, dropping connection", ex);
						node.DisconnectAsync();
						throw;
					}
					catch(Exception)
					{
						node.DisconnectAsync();
						throw;
					}
				}
			}

			var messageReceived = MessageReceived;
			if(messageReceived != null)
				messageReceived(this, message);
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:63,代码来源:NodeServer.cs


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