Beispiel #1
0
        public async Task PermanentlyDead()
        {
            var peer = new Peer
            {
                Id        = "QmXFX2P5ammdmXQgfqGkfswtEVFsZUJ5KeHRXQYCTdiTAb",
                Addresses = new MultiAddress[]
                {
                    "/ip4/127.0.0.1/tcp/4040/ipfs/QmXFX2P5ammdmXQgfqGkfswtEVFsZUJ5KeHRXQYCTdiTAb"
                }
            };
            var swarm = new Swarm {
                LocalPeer = self
            };
            var manager = new PeerManager
            {
                Swarm          = swarm,
                InitialBackoff = TimeSpan.FromMilliseconds(100),
                MaxBackoff     = TimeSpan.FromMilliseconds(200),
            };

            Assert.AreEqual(0, manager.DeadPeers.Count);

            try
            {
                await swarm.StartAsync();

                await manager.StartAsync();

                try
                {
                    await swarm.ConnectAsync(peer);
                }
                catch { }
                Assert.AreEqual(1, manager.DeadPeers.Count);

                var end = DateTime.Now + TimeSpan.FromSeconds(6);
                while (DateTime.Now <= end)
                {
                    if (manager.DeadPeers[peer].NextAttempt == DateTime.MaxValue)
                    {
                        return;
                    }
                }
                Assert.Fail("not truely dead");
            }
            finally
            {
                await swarm.StopAsync();

                await manager.StopAsync();
            }
        }
Beispiel #2
0
        public async Task Backoff_Increases()
        {
            var peer = new Peer
            {
                Id        = "QmXFX2P5ammdmXQgfqGkfswtEVFsZUJ5KeHRXQYCTdiTxx",
                Addresses = new MultiAddress[]
                {
                    "/ip4/127.0.0.1/tcp/4040/ipfs/QmXFX2P5ammdmXQgfqGkfswtEVFsZUJ5KeHRXQYCTdiTxx"
                }
            };
            var swarm = new Swarm {
                LocalPeer = self
            };
            var manager = new PeerManager
            {
                Swarm          = swarm,
                InitialBackoff = TimeSpan.FromMilliseconds(100),
            };

            Assert.AreEqual(0, manager.DeadPeers.Count);

            try
            {
                await swarm.StartAsync();

                await manager.StartAsync();

                try
                {
                    await swarm.ConnectAsync(peer);
                }
                catch { }
                Assert.AreEqual(1, manager.DeadPeers.Count);

                var end = DateTime.Now + TimeSpan.FromSeconds(4);
                while (DateTime.Now <= end)
                {
                    if (manager.DeadPeers[peer].Backoff > manager.InitialBackoff)
                    {
                        return;
                    }
                }
                Assert.Fail("backoff did not increase");
            }
            finally
            {
                await swarm.StopAsync();

                await manager.StopAsync();
            }
        }