コード例 #1
0
ファイル: Swarm.cs プロジェクト: hanabi1224/peer-talk
        /// <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 BlackList <MultiAddress>();
            WhiteList = new WhiteList <MultiAddress>();

            log.Debug($"Stopped {LocalPeer}");
        }
コード例 #2
0
        public async Task Empty()
        {
            var policy = new BlackList <string>();

            Assert.IsTrue(await policy.IsAllowedAsync("a"));
            Assert.IsFalse(await policy.IsNotAllowedAsync("a"));
        }
コード例 #3
0
        public async Task NotAllowed()
        {
            var policy = new BlackList <string>();

            policy.Add("c");
            policy.Add("d");
            Assert.IsFalse(await policy.IsNotAllowedAsync("a"));
            Assert.IsFalse(await policy.IsNotAllowedAsync("b"));
            Assert.IsTrue(await policy.IsNotAllowedAsync("c"));
            Assert.IsTrue(await policy.IsNotAllowedAsync("d"));
        }
コード例 #4
0
        public void Allowed()
        {
            var policy = new BlackList <string>();

            policy.Add("c");
            policy.Add("d");
            Assert.IsTrue(policy.IsAllowed("a"));
            Assert.IsTrue(policy.IsAllowed("b"));
            Assert.IsFalse(policy.IsAllowed("c"));
            Assert.IsFalse(policy.IsAllowed("d"));
        }
コード例 #5
0
        /// <inheritdoc />
        public async Task StopAsync()
        {
            log.Debug($"Stoping {LocalPeer}");

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

            // Disconnect from remote peers.
            Manager.Clear();

            otherPeers.Clear();
            listeners.Clear();
            BlackList = new BlackList <MultiAddress>();
            WhiteList = new WhiteList <MultiAddress>();

            log.Debug($"Stoped {LocalPeer}");
        }
コード例 #6
0
ファイル: Swarm.cs プロジェクト: hanabi1224/peer-talk
 /// <inheritdoc />
 public async Task <bool> IsAllowedAsync(MultiAddress target, CancellationToken cancel = default(CancellationToken))
 {
     return(await BlackList.IsAllowedAsync(target, cancel).ConfigureAwait(false) &&
            await WhiteList.IsAllowedAsync(target, cancel).ConfigureAwait(false));
 }
コード例 #7
0
 /// <inheritdoc />
 public bool IsAllowed(MultiAddress target)
 {
     return(BlackList.IsAllowed(target) &&
            WhiteList.IsAllowed(target));
 }
コード例 #8
0
        public void Empty()
        {
            var policy = new BlackList <string>();

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