Пример #1
0
        /// <inheritdoc />
        public async Task StopAsync()
        {
            IsRunning = false;
            swarmCancellation?.Cancel(true);

            log.Debug($"Stopping {LocalPeer}");

            // Stop the listeners.
            while (listeners.Count > 0)
            {
                await StopListeningAsync(listeners.Keys.First()).ConfigureAwait(false);
            }

            // Disconnect from remote peers.
            Manager.Clear();
            Manager.PeerDisconnected -= OnPeerDisconnected;

            otherPeers.Clear();
            listeners.Clear();
            pendingConnections.Clear();
            pendingRemoteConnections.Clear();
            BlackList = new MultiAddressBlackList();
            WhiteList = new MultiAddressWhiteList();

            log.Debug($"Stopped {LocalPeer}");
        }
        public void Allowed_Alias()
        {
            var policy = new MultiAddressWhiteList();

            policy.Add(a);
            Assert.IsTrue(policy.IsAllowed(a));
            Assert.IsTrue(policy.IsAllowed(a1));
            Assert.IsTrue(policy.IsAllowed(b));
            Assert.IsFalse(policy.IsAllowed(c));
            Assert.IsFalse(policy.IsAllowed(d));
        }
        public void Collection()
        {
            MultiAddress a = "/ip4/127.0.0.1";
            MultiAddress b = "/ip4/127.0.0.2";

            var policy = new MultiAddressWhiteList();

            Assert.IsFalse(policy.IsReadOnly);
            Assert.AreEqual(0, policy.Count);
            Assert.IsFalse(policy.Contains(a));
            Assert.IsFalse(policy.Contains(b));

            policy.Add(a);
            Assert.AreEqual(1, policy.Count);
            Assert.IsTrue(policy.Contains(a));
            Assert.IsFalse(policy.Contains(b));

            policy.Add(a);
            Assert.AreEqual(1, policy.Count);
            Assert.IsTrue(policy.Contains(a));
            Assert.IsFalse(policy.Contains(b));

            policy.Add(b);
            Assert.AreEqual(2, policy.Count);
            Assert.IsTrue(policy.Contains(a));
            Assert.IsTrue(policy.Contains(b));

            policy.Remove(b);
            Assert.AreEqual(1, policy.Count);
            Assert.IsTrue(policy.Contains(a));
            Assert.IsFalse(policy.Contains(b));

            var array = new MultiAddress[1];

            policy.CopyTo(array, 0);
            Assert.AreSame(a, array[0]);

            foreach (var filter in policy)
            {
                Assert.AreSame(a, filter);
            }

            policy.Clear();
            Assert.AreEqual(0, policy.Count);
            Assert.IsFalse(policy.Contains(a));
            Assert.IsFalse(policy.Contains(b));
        }
        public void Empty()
        {
            var policy = new MultiAddressWhiteList();

            Assert.IsTrue(policy.IsAllowed(a));
        }