Esempio n. 1
0
        public void PingPong(CancellationToken cancellation = default(CancellationToken))
        {
            using (var listener = CreateListener().OfType <PongPayload>())
            {
                var ping = new PingPayload()
                {
                    Nonce = RandomUtils.GetUInt64()
                };
                SendMessage(ping);

                while (listener.ReceivePayload <PongPayload>(cancellation).Nonce != ping.Nonce)
                {
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Emit a ping and wait the pong
        /// </summary>
        /// <param name="cancellation"></param>
        /// <returns>Latency</returns>
        public TimeSpan PingPong(CancellationToken cancellation = default(CancellationToken))
        {
            using (var listener = CreateListener().OfType <PongPayload>())
            {
                var ping = new PingPayload()
                {
                    Nonce = RandomUtils.GetUInt64()
                };
                var before = DateTimeOffset.UtcNow;
                SendMessageAsync(ping);

                while (listener.ReceivePayload <PongPayload>(cancellation).Nonce != ping.Nonce)
                {
                }
                var after = DateTimeOffset.UtcNow;
                return(after - before);
            }
        }
Esempio n. 3
0
		public void CanRespondToPong()
		{

			using(var tester = new NodeServerTester())
			{
				var toS2 = tester.Node1;
				toS2.VersionHandshake();
				var ping = new PingPayload();
				CancellationTokenSource cancel = new CancellationTokenSource();
				cancel.CancelAfter(10000);
				using(var list = toS2.CreateListener())
				{
					toS2.SendMessageAsync(ping);
					while(true)
					{
						var pong = list.ReceivePayload<PongPayload>(cancel.Token);
						if(ping.Nonce == pong.Nonce)
							break;
					}
				}

			}

		}
Esempio n. 4
0
		void SetBloomFilter()
		{
			var node = AttachedNode;
			if(node != null)
			{
				_RunningPing = null;
				var filter = _Tracker.CreateBloomFilter(FalsePositiveRate);
				_FilterState = SPV.FilterState.Unloaded;
				node.SendMessageAsync(new FilterLoadPayload(filter));
				_FilterState = SPV.FilterState.Loading;
				var ping = new PingPayload()
				{
					Nonce = RandomUtils.GetUInt64()
				};
				_RunningPing = ping;
				node.SendMessageAsync(ping);
			}
		}
Esempio n. 5
0
 public void CanRespondToPong()
 {
     using(var tester = new NodeServerTester())
     {
         var toS2 = tester.Server1.GetNodeByEndpoint(tester.Server2.ExternalEndpoint);
         toS2.VersionHandshake();
         var ping = new PingPayload();
         toS2.SendMessage(ping);
         var pong = toS2.RecieveMessage<PongPayload>(TimeSpan.FromSeconds(10.0));
         Assert.Equal(ping.Nonce, pong.Nonce);
     }
 }