Пример #1
0
    private async Task CreateAndSendPingAsync(int counter = 1)
    {
        if (_nodeTable.MasterNode is null)
        {
            return;
        }

        PingMsg msg = new(ManagedNode.Address, CalculateExpirationTime(), _nodeTable.MasterNode.Address);

        msg.EnrSequence = _nodeRecord.EnrSequence;

        try
        {
            _lastSentPing = msg;
            _discoveryManager.SendMessage(msg);
            NodeStats.AddNodeStatsEvent(NodeStatsEventType.DiscoveryPingOut);

            bool result = await _discoveryManager.WasMessageReceived(ManagedNode.IdHash, MsgType.Pong, _discoveryConfig.PongTimeout);

            if (!result)
            {
                if (counter > 1)
                {
                    await CreateAndSendPingAsync(counter - 1);
                }

                UpdateState(NodeLifecycleState.Unreachable);
            }
        }
        catch (Exception e)
        {
            _logger.Error("Error during sending ping message", e);
        }
    }
Пример #2
0
        private async Task SendPingAsync(int counter)
        {
            try
            {
                var msg = _discoveryMessageFactory.CreateOutgoingMessage <PingMessage>(ManagedNode);
                msg.Version            = _discoveryConfig.PingMessageVersion;
                msg.SourceAddress      = _nodeTable.MasterNode.Address;
                msg.DestinationAddress = msg.FarAddress;
                _discoveryManager.SendMessage(msg);
                NodeStats.AddNodeStatsEvent(NodeStatsEventType.DiscoveryPingOut);

                var result = await _discoveryManager.WasMessageReceived(ManagedNode.IdHash, MessageType.Pong, _discoveryConfig.PongTimeout);

                if (!result)
                {
                    if (counter > 1)
                    {
                        await SendPingAsync(counter - 1);
                    }
                    else
                    {
                        UpdateState(NodeLifecycleState.Unreachable);
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Error("Error during sending ping message", e);
            }
        }
Пример #3
0
        private Result SendFindNodeSync(Node destinationNode, byte[] searchedNodeId)
        {
            var nodeManager = _discoveryManager.GetNodeLifecycleManager(destinationNode);

            nodeManager.SendFindNode(searchedNodeId ?? _masterNode.Id.Bytes);

            if (_discoveryManager.WasMessageReceived(destinationNode.IdHashText, MessageType.Neighbors, _configurationProvider.SendNodeTimeout))
            {
                return(Result.Success());
            }
            return(Result.Fail($"Did not receive Neighbors reponse in time from: {destinationNode.Host}"));
        }
Пример #4
0
    private async Task <Result> SendFindNode(Node destinationNode, byte[]?searchedNodeId)
    {
        try
        {
            INodeLifecycleManager?nodeManager = _discoveryManager.GetNodeLifecycleManager(destinationNode);

            nodeManager?.SendFindNode(searchedNodeId ?? _masterNode !.Id.Bytes);

            return(await _discoveryManager.WasMessageReceived(destinationNode.IdHash, MsgType.Neighbors, _discoveryConfig.SendNodeTimeout)
                ? Result.Success
                : Result.Fail($"Did not receive Neighbors response in time from: {destinationNode.Host}"));
        }
        catch (OperationCanceledException)
        {
            return(Result.Fail("Cancelled"));
        }
    }
Пример #5
0
        private async Task <Result> SendFindNode(Node destinationNode, byte[] searchedNodeId, CancellationToken cancellationToken)
        {
            try
            {
                var nodeManager = _discoveryManager.GetNodeLifecycleManager(destinationNode);
                nodeManager?.SendFindNode(searchedNodeId ?? _masterNode.Id.Bytes);

                if (await _discoveryManager.WasMessageReceived(destinationNode.IdHash, MessageType.Neighbors, _configurationProvider.SendNodeTimeout))
                {
                    return(Result.Success);
                }

                return(Result.Fail($"Did not receive Neighbors reponse in time from: {destinationNode.Host}"));
            }
            catch (OperationCanceledException)
            {
                return(Result.Fail("Cancelled"));
            }
        }