protected override Message ReceiveAuthenticatedMessage(AuthenticatedMessage message) { if (message is BlocksParityRequest) { var blockParityRequestMessage = message as BlocksParityRequest; var blocksPayload = message.Payload as Blocks; for (int i = 0; i < blocksPayload.BlocksArray.Length; i++) { var block = blocksPayload.BlocksArray[i]; var parity = Cascade.Parity(DestilationBuffer.GetBits(block.Index, block.Length)); blocksPayload.BlocksArray[i].Parity = parity; } var mac = MessageAuthenticator.GetMAC(blocksPayload.GetBytes()); return(new BlocksParityResponse(mac, blocksPayload)); } if (message is CheckParity) { var checkParityMessage = message as CheckParity; var blockIdentification = checkParityMessage.Payload as BlockIdentifiaction; var parity = Cascade.Parity(DestilationBuffer.GetBits(blockIdentification.Index, blockIdentification.Length)); var payload = new ParityPayload(blockIdentification.Index, blockIdentification.Length, parity); var mac = MessageAuthenticator.GetMAC(payload.GetBytes()); return(new Parity(mac, payload)); } if (message is RequestBits) { var requestBitsMessage = message as RequestBits; var blockIdentification = requestBitsMessage.Payload as BlockIdentifiaction; var bytes = DestilationBuffer.GetBytes(blockIdentification.Index, blockIdentification.Length); var payload = new BitsAsBytes(blockIdentification.Index, blockIdentification.Length, bytes); var mac = MessageAuthenticator.GetMAC(payload.GetBytes()); return(new Bytes(mac, payload, requestBitsMessage.Demand)); } if (message is AddKey) { var addKeyMessage = message as AddKey; var messagPayload = (addKeyMessage.Payload as BlockIdAndKeyAllocation); if (messagPayload.BlockId == _currentKeyChunk + 1) { var key = LocalKeyStore.GetKey(); CommonKeyStore.AddNewKey(key, messagPayload.KeyAllocation); _currentKeyChunk += 1; return(PrepareAckForCommonKeyProposition(_currentKeyChunk)); } else { if (messagPayload.BlockId == _currentKeyChunk) { return(PrepareAckForCommonKeyProposition(_currentKeyChunk)); } else { return(new NOP()); } } } return(new NOP()); }