Example #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}");
        }
Example #2
0
        public void Allowed_Alias()
        {
            var policy = new MultiAddressBlackList();

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

            var policy = new MultiAddressBlackList();

            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));
        }
Example #4
0
        public void Empty()
        {
            var policy = new MultiAddressBlackList();

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