Class NetherNetConstants

java.lang.Object
org.cloudburstmc.netty.channel.nethernet.NetherNetConstants

public class NetherNetConstants extends Object
The wire constants and helpers the transport and its signalings share. Nothing here is meant for a host, which never builds or reads a signal itself.
  • Field Details

  • Constructor Details

    • NetherNetConstants

      public NetherNetConstants()
  • Method Details

    • encryptDiscoveryPacket

      public static byte[] encryptDiscoveryPacket(io.netty.buffer.ByteBuf packet) throws Exception
      Encrypts a discovery packet using AES encryption and HMAC-SHA256 for integrity.
      Parameters:
      packet - The ByteBuf containing the discovery packet to encrypt.
      Returns:
      The encrypted byte array ready for transmission.
      Throws:
      Exception - if encryption fails.
    • decryptDiscoveryPacket

      public static io.netty.buffer.ByteBuf decryptDiscoveryPacket(io.netty.buffer.ByteBuf input) throws Exception
      Decrypts a discovery packet and verifies its integrity.
      Parameters:
      input - The ByteBuf containing the received discovery packet.
      Returns:
      A ByteBuf with the decrypted payload, or null if verification fails.
      Throws:
      Exception - if decryption fails.
    • segmentCount

      public static int segmentCount(int length, int maxPayload)
      Counts the segments a message is split into.
      Parameters:
      length - The message length in bytes
      maxPayload - The most payload one segment carries, excluding the header byte
      Returns:
      How many segments the message needs, 0 for an empty one
      Throws:
      IllegalArgumentException - if no payload fits a segment, or the message needs more segments than the countdown header can number
    • buildSignalConnectRequest

      public static String buildSignalConnectRequest(String connectionId, String sdp)
      Builds a signaling message for a CONNECTREQUEST.
      Parameters:
      connectionId - The connection id, the opaque token the initiator chose.
      sdp - The SDP payload.
      Returns:
      The formatted signaling message.
    • buildSignalConnectResponse

      public static String buildSignalConnectResponse(String connectionId, String sdp)
      Builds a signaling message for a CONNECTRESPONSE.
      Parameters:
      connectionId - The connection id, the opaque token the initiator chose.
      sdp - The SDP payload.
      Returns:
      The formatted signaling message.
    • buildSignalCandidateAdd

      public static String buildSignalCandidateAdd(String connectionId, String candidateSdp)
      Builds a signaling message for a CANDIDATEADD.
      Parameters:
      connectionId - The connection id, the opaque token the initiator chose.
      candidateSdp - The candidate SDP string.
      Returns:
      The formatted signaling message.
    • parseSignal

      public static NetherNetConstants.Signal parseSignal(String raw)
      Parameters:
      raw - The signal as received
      Returns:
      The parsed signal, or null when it has no type, no connection id, or a connection id that is not printable ASCII