private void OnPacketReceived(Packet packet) { if (packet is FragmentPacket fragmentPacket) { FragmentKey key = fragmentKeyFactory.FromBytes(fragmentPacket.GetKey()); state = state.CloneWith(key, fragmentFactory.FromBytes(fragmentPacket.GetPayload())); } else if (packet is MutationPacket mutationPacket) { // If mutation was requested by me, then this request is no longer pending if (mutationPacket.GetRequester().Equals(client.id)) { pending.Remove(mutationPacket.GetId()); } if (!TryApply(mutationPacket, out Mutation mutation, out MutationResult result)) { // This should never happen since the mutation has already been succesfully applied at the Oracle. This // indicates that replication state is corrupt. This is a good reason to directly disconnect from the server. string message = "Fatal Karmax replication failure"; log.Error($"{message}. Corrupt state detected while applying {mutation.GetType().Name} on fragment[{fragmentKeyFactory.FromBytes(mutationPacket.GetKey()).AsString()}]. Reason: {result.GetFailureReason()}"); client.Leave(message); return; } } else if (packet is MutationFailedPacket mutationFailedPacket) { var mutationId = mutationFailedPacket.GetId(); log.Warning($"Mutation[{mutationId}] failed. Reason: {mutationFailedPacket.GetFailureReason()}. Details: {pending[mutationId]}"); pending.Remove(mutationId); SafeInvoker.Invoke(log, OnMutationFailedCallback, mutationId, mutationFailedPacket.GetFailureReason()); } }
public void OnDestroy() { if (karmanClient.IsConnected()) { karmanClient.Leave("Client destroyed"); } }
public void Leave() { karmanClient.Leave("Client decision"); }