Interface CipherPreferencePolicy

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface CipherPreferencePolicy
Picks the transport encryption mode of a voice session out of the ones offered by the voice server.
See Also:
  • Method Details

    • select

      @Nullable @Nullable String select(@NotNull @NotNull List<String> offered, @NotNull @NotNull Set<String> supported)
      Parameters:
      offered - encryption modes offered by the voice server, in the order it sent them
      supported - encryption modes implemented by Koe
      Returns:
      a mode that is both offered and supported, or null if none of them is acceptable, which fails the connection
    • serverOrder

      @NotNull static @NotNull CipherPreferencePolicy serverOrder()
      Returns:
      a policy which takes the first supported mode in the order the voice server sent them
    • preferring

      @NotNull static @NotNull CipherPreferencePolicy preferring(@NotNull @NotNull List<String> preference)
      Parameters:
      preference - encryption mode names, most preferred first
      Returns:
      a policy which takes the first mode from preference that the voice server offers, and falls back to serverOrder() if it offers none of them
    • heuristic

      @NotNull static @NotNull CipherPreferencePolicy heuristic()
      The default policy. Prefers AES-GCM if the JVM reports using hardware AES instructions (HotSpot), and XChaCha20-Poly1305 otherwise, which is several times faster than AES-GCM implemented in software. Never runs a benchmark, see benchmark() for that.
      Returns:
      a policy based on the current JVM and CPU
    • benchmark

      @NotNull static @NotNull CipherPreferencePolicy benchmark()
      Measures every supported encryption mode on this JVM and prefers the fastest ones. Blocks the calling thread for about half a second, so call it once at startup, never on an event loop thread. Use CipherBenchmark directly to configure how long it runs or to store the results.
      Returns:
      a policy preferring modes from the fastest to the slowest
      See Also: