示例#1
0
        public void Dispatch(ConsensusMessage message, int from)
        {
            if (_terminated)
            {
                Logger.LogTrace($"Era {_era} is already finished, skipping Dispatch");
                return;
            }

            if (message.Validator.Era != _era)
            {
                throw new InvalidOperationException(
                          $"Message for era {message.Validator.Era} dispatched to era {_era}");
            }

            if (!ValidateMessage(message))
            {
                Logger.LogWarning(
                    $"Faulty behaviour: null value in required field of the consensus message from validator: {from}"
                    + $" ({GetPublicKeyById(from)!.ToHex()}). Discarding message as it could crash targeted protocol.");
                return;
            }

            switch (message.PayloadCase)
            {
            case ConsensusMessage.PayloadOneofCase.Bval:
                var idBval = new BinaryBroadcastId(message.Validator.Era, message.Bval.Agreement,
                                                   message.Bval.Epoch);
                EnsureProtocol(idBval)?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.Aux:
                var idAux = new BinaryBroadcastId(message.Validator.Era, message.Aux.Agreement, message.Aux.Epoch);
                EnsureProtocol(idAux)?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.Conf:
                var idConf = new BinaryBroadcastId(message.Validator.Era, message.Conf.Agreement,
                                                   message.Conf.Epoch);
                EnsureProtocol(idConf)?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.Coin:
                var idCoin = new CoinId(message.Validator.Era, message.Coin.Agreement, message.Coin.Epoch);
                EnsureProtocol(idCoin)?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.Decrypted:
                var hbbftId = new HoneyBadgerId((int)message.Validator.Era);
                EnsureProtocol(hbbftId)?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.ValMessage:
                var reliableBroadcastId = new ReliableBroadcastId(message.ValMessage.SenderId, (int)message.Validator.Era);
                EnsureProtocol(reliableBroadcastId)?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.EchoMessage:
                var rbIdEchoMsg = new ReliableBroadcastId(message.EchoMessage.SenderId, (int)message.Validator.Era);
                EnsureProtocol(rbIdEchoMsg)?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.ReadyMessage:
                var rbIdReadyMsg = new ReliableBroadcastId(message.ReadyMessage.SenderId, (int)message.Validator.Era);
                EnsureProtocol(rbIdReadyMsg)?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.SignedHeaderMessage:
                var rootId = new RootProtocolId(message.Validator.Era);
                EnsureProtocol(rootId)?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            default:
                throw new InvalidOperationException($"Unknown message type {message}");
            }
        }
示例#2
0
        public void Dispatch(ConsensusMessage message, int from)
        {
            if (_silenced.Contains(from))
            {
                return;
            }
            if (_silenced.Contains(GetMyId()))
            {
                return;
            }

            switch (message.PayloadCase)
            {
            case ConsensusMessage.PayloadOneofCase.Bval:
                var idBval = new BinaryBroadcastId(message.Validator.Era, message.Bval.Agreement,
                                                   message.Bval.Epoch);
                CheckRequest(idBval);
                Registry[idBval]?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.Aux:
                var idAux = new BinaryBroadcastId(message.Validator.Era, message.Aux.Agreement, message.Aux.Epoch);
                CheckRequest(idAux);
                Registry[idAux]?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.Conf:
                var idConf = new BinaryBroadcastId(message.Validator.Era, message.Conf.Agreement,
                                                   message.Conf.Epoch);
                CheckRequest(idConf);
                Registry[idConf]?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.Coin:
                var idCoin = new CoinId(message.Validator.Era, message.Coin.Agreement, message.Coin.Epoch);
                CheckRequest(idCoin);
                Registry[idCoin]?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.Decrypted:
                var hbbftId = new HoneyBadgerId((int)message.Validator.Era);
                CheckRequest(hbbftId);
                Registry[hbbftId]?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.ReadyMessage:
                var rbIdReadyMsg =
                    new ReliableBroadcastId(message.ReadyMessage.SenderId, (int)message.Validator.Era);
                CheckRequest(rbIdReadyMsg);
                Registry[rbIdReadyMsg]?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.ValMessage:
                var reliableBroadcastId =
                    new ReliableBroadcastId(message.ValMessage.SenderId, (int)message.Validator.Era);
                CheckRequest(reliableBroadcastId);
                Registry[reliableBroadcastId]?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.EchoMessage:
                var rbIdEchoMsg =
                    new ReliableBroadcastId(message.EchoMessage.SenderId, (int)message.Validator.Era);
                CheckRequest(rbIdEchoMsg);
                Registry[rbIdEchoMsg]?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            case ConsensusMessage.PayloadOneofCase.SignedHeaderMessage:
                var idRoot = new RootProtocolId(message.Validator.Era);
                CheckRequest(idRoot);
                Registry[idRoot]?.ReceiveMessage(new MessageEnvelope(message, from));
                break;

            default:
                throw new InvalidOperationException($"Unknown message type {message.PayloadCase}");
            }
        }