예제 #1
0
 public async Task AddSelf()
 {
     var          pubKey = new PrivateKey().PublicKey;
     RoutingTable table  = CreateTable(pubKey.ToAddress());
     var          peer   = new BoundPeer(pubKey, new DnsEndPoint("0.0.0.0", 1234), 0);
     await Assert.ThrowsAsync <ArgumentException>(() => table.AddPeerAsync(peer));
 }
예제 #2
0
        public async Task RemovePeer()
        {
            var pubKey1 = new PrivateKey().PublicKey;
            var pubKey2 = new PrivateKey().PublicKey;
            var table   = new RoutingTable(
                pubKey1.ToAddress(),
                1,
                2,
                new System.Random());
            var peer1 = new BoundPeer(pubKey1, new DnsEndPoint("0.0.0.0", 1234), 0);
            var peer2 = new BoundPeer(pubKey2, new DnsEndPoint("0.0.0.0", 1234), 0);

            await Assert.ThrowsAsync <ArgumentException>(() => table.RemovePeerAsync(peer1));

            await Assert.ThrowsAsync <ArgumentNullException>(() => table.RemovePeerAsync(null));

            bool ret = await table.RemovePeerAsync(peer2);

            Assert.False(ret);
            await table.AddPeerAsync(peer2);

            ret = await table.RemovePeerAsync(peer2);

            Assert.True(ret);
        }
예제 #3
0
        public async Task AddPeer()
        {
            var pubKey0 = new PrivateKey().PublicKey;
            var pubKey1 = new PrivateKey().PublicKey;
            var pubKey2 = new PrivateKey().PublicKey;
            var pubKey3 = new PrivateKey().PublicKey;
            var table   = new RoutingTable(
                pubKey0.ToAddress(),
                1,
                2,
                new System.Random());
            var  peer1 = new BoundPeer(pubKey1, new DnsEndPoint("0.0.0.0", 1234), 0);
            var  peer2 = new BoundPeer(pubKey2, new DnsEndPoint("0.0.0.0", 1234), 0);
            var  peer3 = new BoundPeer(pubKey3, new DnsEndPoint("0.0.0.0", 1234), 0);
            Peer evict = await table.AddPeerAsync(peer1);

            Assert.Null(evict);
            evict = await table.AddPeerAsync(peer1);

            Assert.Null(evict);
            evict = await table.AddPeerAsync(peer2);

            Assert.Null(evict);
            evict = await table.AddPeerAsync(peer3);

            Assert.NotNull(evict);
            Assert.Equal(peer1, evict);
            await table.AddPeerAsync(peer1);

            evict = await table.AddPeerAsync(peer3);

            Assert.Equal(peer2, evict);
        }
예제 #4
0
 public async Task AddNull()
 {
     var          pubKey = new PrivateKey().PublicKey;
     RoutingTable table  = CreateTable(pubKey.ToAddress());
     await Assert.ThrowsAsync <ArgumentNullException>(() => table.AddPeerAsync(null));
 }