Beispiel #1
0
        public async Task Can_Challenge_Peer()
        {
            var recipientPeerId = PeerIdHelper.GetPeerId();
            await _peerChallengeRequest.ChallengePeerAsync(recipientPeerId).ConfigureAwait(false);

            var expectedDto = Substitute.For <IMessageDto <ProtocolMessage> >();

            expectedDto.RecipientPeerIdentifier.Returns(recipientPeerId);
            expectedDto.SenderPeerIdentifier.Returns(_testSettings.PeerId);
            _peerChallengeRequest.PeerClient.ReceivedWithAnyArgs(1).SendMessage(Arg.Is(expectedDto));
        }
Beispiel #2
0
        private void CheckHeartbeat()
        {
            foreach (var peer in _peerRepository.GetAll())
            {
                Task.Run(async() =>
                {
                    var result       = await _peerChallengeRequest.ChallengePeerAsync(peer.PeerId);
                    var counterValue = _nonResponsivePeerMap.GetOrAdd(peer.DocumentId, 0);
                    _logger.Verbose(
                        $"Heartbeat result: {result.ToString()} Peer: {peer.PeerId} Non-Responsive Counter: {counterValue}");
                    if (!result)
                    {
                        _nonResponsivePeerMap[peer.DocumentId] += 1;
                        counterValue += 1;

                        if (counterValue >= _maxNonResponsiveCounter)
                        {
                            _peerRepository.Delete(peer.DocumentId);
                            _nonResponsivePeerMap.TryRemove(peer.DocumentId, out _);
                            _logger.Verbose(
                                $"Peer reached maximum non-responsive count: {peer.PeerId}. Evicted from repository");
                        }
                    }
                    else
                    {
                        _nonResponsivePeerMap[peer.DocumentId] = 0;
                    }
                }).ConfigureAwait(false);
            }
        }
        private async Task <bool> RunPeerChallengeTask(string publicKey, IPAddress ip, int port)
        {
            TestContext.WriteLine(publicKey);
            TestContext.WriteLine(ip.ToString());
            TestContext.WriteLine(port.ToString());

            var recipient = publicKey.BuildPeerIdFromBase32Key(ip, port);

            return(await _peerChallengeRequest.ChallengePeerAsync(recipient));
        }
Beispiel #4
0
        private void CheckHeartbeat()
        {
            foreach (var peer in _peerRepository.GetAll())
            {
                Task.Run(async() =>
                {
                    var result       = await _peerChallengeRequest.ChallengePeerAsync(peer.PeerId);
                    var counterValue = _nonResponsivePeerMap.GetOrAdd(peer.DocumentId, 0);
                    _logger.Verbose(
                        $"Heartbeat result: {result.ToString()} Peer: {peer.PeerId} Non-Responsive Counter: {counterValue}");
                    if (!result)
                    {
                        // @TODO touch last seen on peer
                        _nonResponsivePeerMap[peer.DocumentId] += 1;
                        counterValue += 1;

                        if (counterValue >= _maxNonResponsiveCounter)
                        {
                            // Remove all non POA nodes at the moment until node is using same p2p discovery
                            if (!peer.IsPoaNode)
                            {
                                _peerRepository.Delete(peer.DocumentId);
                                _nonResponsivePeerMap.TryRemove(peer.DocumentId, out _);
                            }
                            _logger.Verbose(
                                $"Peer reached maximum non-responsive count: {peer.PeerId}. Evicted from repository");
                        }
                    }
                    else
                    {
                        peer.Touch();
                        _peerRepository.Update(peer);
                        _nonResponsivePeerMap[peer.DocumentId] = 0;
                    }
                }).ConfigureAwait(false);
            }
        }