Class QuicMessage

java.lang.Object
org.microproxy.quic.QuicMessage

public final class QuicMessage extends Object
One whole message of a stream of an intercepted QUIC connection, as QuicInterceptor.streamMessage(org.microproxy.quic.QuicMessage, org.microproxy.quic.QuicStreamContext) sees it: the payload a MessageFramer cut out of the stream (without its length prefix or delimiter), which side sent it, on which stream, and when it was complete.

Messages are immutable apart from data(), which a hook may change in place; the with methods make changed copies, which the hook returns to send instead. The decoders read the payload: dns() as DNS (DNS over QUIC), protobuf() as protobuf, and render() with the content views, for logging.

  • Constructor Details

    • QuicMessage

      public QuicMessage(byte[] data, boolean fromClient, long streamId, String alpn, Instant timestamp)
      A message.
      Parameters:
      data - the payload, which the message holds as it is (not copied)
      fromClient - whether the client sent it (it goes to the server), rather than the server
      streamId - the stream's ID on the client's connection
      alpn - the connection's ALPN protocol, or null
      timestamp - when the proxy had the whole message
  • Method Details

    • data

      public byte[] data()
      The payload. The array is the message's own, not a copy: a hook may change it in place and return the message.
      Returns:
      the payload
    • length

      public int length()
      Returns the payload's length in bytes.
      Returns:
      the payload's length in bytes
    • fromClient

      public boolean fromClient()
      Returns whether the client sent the message (it goes to the server), rather than the server.
      Returns:
      whether the client sent the message (it goes to the server), rather than the server
    • streamId

      public long streamId()
      Returns the stream's ID on the client's connection.
      Returns:
      the stream's ID on the client's connection
    • alpn

      public String alpn()
      Returns the connection's ALPN protocol, or null.
      Returns:
      the connection's ALPN protocol, or null
    • timestamp

      public Instant timestamp()
      Returns when the proxy had the whole message.
      Returns:
      when the proxy had the whole message
    • text

      public String text()
      The payload decoded as UTF-8, malformed sequences replaced with U+FFFD.
      Returns:
      the text
    • withData

      public QuicMessage withData(byte[] data)
      A copy of this message with another payload, the same direction, stream and timestamp.
      Parameters:
      data - the payload of the copy (not copied)
      Returns:
      the copy
    • withText

      public QuicMessage withText(String text)
      A copy of this message with the UTF-8 encoding of text.
      Parameters:
      text - the text of the copy
      Returns:
      the copy
    • withFromClient

      public QuicMessage withFromClient(boolean fromClient)
      A copy of this message going the other way, or the same: with fromClient it goes to the server, else to the client, on the same stream. A hook returns one to answer a side itself.
      Parameters:
      fromClient - whether the copy goes to the server
      Returns:
      the copy
    • dns

      public DnsMessage dns()
      The payload as a DNS message, as DNS over QUIC (doq) carries them.
      Returns:
      the DNS message
      Throws:
      IllegalArgumentException - if the payload is not a well-formed DNS message
    • withDns

      public QuicMessage withDns(DnsMessage dns)
      A copy of this message whose payload is dns, encoded.
      Parameters:
      dns - the DNS message
      Returns:
      the copy
    • protobuf

      public ProtoMessage protobuf() throws DecodeException
      The payload as a protobuf message, without a schema: fields by number.
      Returns:
      the message
      Throws:
      DecodeException - if the payload is not a protobuf message
    • protobuf

      public ProtoMessage protobuf(ProtoSchema schema, String messageType) throws DecodeException
      The payload as a protobuf message of messageType, its fields named by schema.
      Parameters:
      schema - the schema, as from ProtoSchema.load(java.nio.file.Path)
      messageType - the message type's full name, such as shop.Order
      Returns:
      the message
      Throws:
      DecodeException - if the payload is not a protobuf message
    • render

      public Optional<ContentViews.Rendered> render()
      The payload rendered by the best of the default content views that can: as DNS for DNS over QUIC, else as what the bytes look like (protobuf, JSON, ...).
      Returns:
      the rendering, or empty when no view could render the payload
    • render

      The payload rendered by the best of views that can. For DNS over QUIC, the views are told the payload is an application/dns-message.
      Parameters:
      views - the views
      Returns:
      the rendering, or empty when no view could render the payload
    • toString

      public String toString()
      Overrides:
      toString in class Object