Esempio n. 1
0
        public void PeerDiscovered()
        {
            var swarm = new Swarm {
                LocalPeer = self
            };
            var peerCount = 0;

            swarm.PeerDiscovered += (s, e) =>
            {
                ++peerCount;
            };
            swarm.RegisterPeerAddress("/ip4/127.0.0.1/tcp/4001/ipfs/QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCM1h");
            swarm.RegisterPeerAddress("/ip4/127.0.0.2/tcp/4001/ipfs/QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCM1h");
            swarm.RegisterPeerAddress("/ip4/127.0.0.3/tcp/4001/ipfs/QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCM1h");
            swarm.RegisterPeerAddress("/ip4/127.0.0.1/tcp/4001/ipfs/QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCM1i");
            swarm.RegisterPeerAddress("/ip4/127.0.0.2/tcp/4001/ipfs/QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCM1i");
            swarm.RegisterPeerAddress("/ip4/127.0.0.3/tcp/4001/ipfs/QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCM1i");
            swarm.RegisterPeer(new Peer {
                Id = "QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCM1j"
            });
            swarm.RegisterPeer(new Peer {
                Id = "QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCM1j"
            });

            Assert.AreEqual(3, peerCount);
        }
Esempio n. 2
0
        public void DeregisterPeer()
        {
            var swarm = new Swarm {
                LocalPeer = self
            };

            swarm.RegisterPeer(other);
            Assert.IsTrue(swarm.KnownPeers.Contains(other));

            Peer removedPeer = null;

            swarm.PeerRemoved += (s, e) => removedPeer = e;
            swarm.DeregisterPeer(other);
            Assert.IsFalse(swarm.KnownPeers.Contains(other));
            Assert.AreEqual(other, removedPeer);
        }
Esempio n. 3
0
        public void RegisterPeer_BlackListed()
        {
            var swarm = new Swarm {
                LocalPeer = self
            };
            var peer = new Peer
            {
                Id        = "QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCM1h",
                Addresses = new MultiAddress[]
                {
                    "/ip4/127.0.0.1/ipfs/QmdpwjdB94eNm2Lcvp9JqoCxswo3AKQqjLuNZyLixmCM1h"
                }
            };

            swarm.BlackList.Add(peer.Addresses.First());
            ExceptionAssert.Throws <Exception>(() => swarm.RegisterPeer(peer));
        }