public async Task DoHandshake_AlreadyInHandshaking_Test()
        {
            AElfPeerEndpointHelper.TryParse(NetworkTestConstants.GoodPeerEndpoint, out var endpoint);
            var handshake = CreateHandshake();

            _peerPool.AddHandshakingPeer(endpoint.Host, handshake.HandshakeData.Pubkey.ToHex());

            var result = await _connectionService.DoHandshakeAsync(endpoint, handshake);

            result.Error.ShouldBe(HandshakeError.ConnectionRefused);

            _peerPool.GetHandshakingPeers().ShouldNotContainKey(endpoint.Host);
        }
Пример #2
0
        public void AddHandshakingPeer_WithSameIp_ShouldAddToList()
        {
            var commonIp      = IPAddress.Parse("12.34.56.64");
            var mockPubkeyOne = "pub1";
            var mockPubkeyTwo = "pub2";

            _peerPool.AddHandshakingPeer(commonIp, mockPubkeyOne);
            _peerPool.AddHandshakingPeer(commonIp, mockPubkeyTwo);

            _peerPool.GetHandshakingPeers().TryGetValue(commonIp, out var peers);
            peers.Values.Count.ShouldBe(2);
            peers.Values.ShouldContain(mockPubkeyOne, mockPubkeyTwo);
        }
Пример #3
0
        public async Task DoHandshake_MaxPeersPerHostReached_Test()
        {
            var peerEndpoint = new IPEndPoint(IPAddress.Parse("1.2.3.4"), 1234);

            var firstPeerFromHostResp = await _connectionService.DoHandshakeAsync(peerEndpoint, GetHandshake("pubKey1"));

            firstPeerFromHostResp.Error.ShouldBe(HandshakeError.HandshakeOk);

            var secondPeerFromHostResp = await _connectionService.DoHandshakeAsync(peerEndpoint, GetHandshake("pubKey2"));

            secondPeerFromHostResp.Error.ShouldBe(HandshakeError.ConnectionRefused);

            _peerPool.GetPeers(true).Count.ShouldBe(1);
            _peerPool.GetHandshakingPeers().Values.Count.ShouldBe(0);
        }
        public void AddHandshakingPeer_LoopbackAddress_Test()
        {
            var handshakingPeerHost = "127.0.0.1";

            for (int i = 0; i < 3; i++)
            {
                var pubkey    = "pubkey" + i;
                var addResult = _peerPool.AddHandshakingPeer(handshakingPeerHost, pubkey);
                addResult.ShouldBeTrue();

                var handshakingPeers = _peerPool.GetHandshakingPeers();
                handshakingPeers.ShouldContainKey(handshakingPeerHost);
                handshakingPeers[handshakingPeerHost].ShouldContainKey(pubkey);
            }
        }