Beispiel #1
0
        public async Task IsAvailable()
        {
            using (var server = new MockNat())
            {
                server.RequestReceived += (s, req) => server.udp.Send(new byte[2], 2, req.RemoteEndPoint);
                var nat = new Client(server.Address);
                var q   = await nat.IsAvailableAsync();

                Assert.IsTrue(q);
            }
        }
Beispiel #2
0
        public async Task Unresponsive_Nat()
        {
            using (var server = new MockNat())
            {
                var nat = new Client(server.Address)
                {
                    MaxRetries = 1
                };
                var q = await nat.IsAvailableAsync();

                Assert.IsFalse(q);
            }
        }
Beispiel #3
0
        /// <summary>
        ///   Gets the NATs.
        /// </summary>
        /// <returns>
        ///   A sequence of NAT clients that can be talked to,
        /// </returns>
        /// <remarks>
        ///   Asks each <see cref="GetGateways">gateways</see> if it supports
        ///   PCP or PMP.  If true, then a <see cref="NatClient"/> is retuned.
        /// </remarks>
        public static IEnumerable <NatClient> GetNats()
        {
            foreach (var gateway in GetGateways())
            {
                NatClient nat = new Pcp.Client(gateway);
                if (nat.IsAvailableAsync().Result)
                {
                    yield return(nat);

                    continue;
                }

                nat = new Pmp.Client(gateway);
                if (nat.IsAvailableAsync().Result)
                {
                    yield return(nat);

                    continue;
                }
            }
        }