Beispiel #1
0
        public async Task RefreshNode_Test()
        {
            var node1 = new NodeInfo
            {
                Endpoint = "192.168.100.1:8000",
                Pubkey   = ByteString.CopyFromUtf8("node1")
            };
            await _peerDiscoveryService.AddNodeAsync(node1);

            var node2 = new NodeInfo
            {
                Endpoint = "192.168.100.1:8001",
                Pubkey   = ByteString.CopyFromUtf8("node2")
            };
            await _peerDiscoveryService.AddNodeAsync(node2);

            await _peerDiscoveryService.RefreshNodeAsync();

            var nodeList = await _nodeManager.GetRandomNodesAsync(10);

            nodeList.Nodes.Count.ShouldBe(2);
            nodeList.Nodes.ShouldContain(node1);
            nodeList.Nodes.ShouldContain(node2);

            await _peerDiscoveryService.RefreshNodeAsync();

            nodeList = await _nodeManager.GetRandomNodesAsync(10);

            nodeList.Nodes.Count.ShouldBe(1);
            nodeList.Nodes[0].ShouldBe(node1);

            _discoveredNodeCacheProvider.TryTake(out var endpoint);
            endpoint.ShouldBe(node1.Endpoint);

            _discoveredNodeCacheProvider.TryTake(out endpoint);
            endpoint.ShouldBeNull();
        }
        public async Task HandleEventAsync(PeerConnectedEventData eventData)
        {
            Logger.LogDebug($"Peer connection event {eventData.NodeInfo}");

            await _peerDiscoveryService.AddNodeAsync(eventData.NodeInfo);

            var blockAnnouncement = new BlockAnnouncement {
                BlockHash   = eventData.BestChainHash,
                BlockHeight = eventData.BestChainHeight
            };

            var announcement = new AnnouncementReceivedEventData(blockAnnouncement, eventData.NodeInfo.Pubkey.ToHex());

            await LocalEventBus.PublishAsync(announcement);
        }
        public async Task AddNode_And_GetNodes_Test()
        {
            var node = new NodeInfo
            {
                Endpoint = "http://192.168.197.1:8000",
                Pubkey   = ByteString.CopyFromUtf8("test")
            };

            await _peerDiscoveryService.AddNodeAsync(node);

            var result = await _nodeManager.GetRandomNodesAsync(1);

            result.Nodes.Contains(node).ShouldBeTrue();

            var nodes = await _peerDiscoveryService.GetNodesAsync(1);

            nodes.Nodes.Contains(node).ShouldBeTrue();
        }
Beispiel #4
0
        public async Task ProcessPeerDiscoveryJob_Test()
        {
            var node1 = new NodeInfo
            {
                Endpoint = "192.168.100.1:8001",
                Pubkey   = ByteString.CopyFromUtf8("node1")
            };
            await _peerDiscoveryService.AddNodeAsync(node1);

            await RunDiscoveryWorkerAsync();

            var endpointString = "192.168.100.100:8003";
            var nodeList       = await _peerDiscoveryService.GetNodesAsync(10);

            nodeList.Nodes.Count.ShouldBe(1);
            nodeList.Nodes[0].Endpoint.ShouldBe(endpointString);
            nodeList.Nodes[0].Pubkey.ShouldBe(ByteString.CopyFromUtf8(endpointString));

            AElfPeerEndpointHelper.TryParse(endpointString, out var aelEndpoint);
            var peer = _peerPool.FindPeerByEndpoint(aelEndpoint);

            peer.ShouldNotBeNull();
        }