Class TCPMixedBabelSocketCodec

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.handler.codec.ByteToMessageCodec<BabelMessage>
pt.unl.fct.di.novasys.babel2.channels.tcp_tls.TCPMixedBabelSocketCodec
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public class TCPMixedBabelSocketCodec extends io.netty.handler.codec.ByteToMessageCodec<BabelMessage>
Netty codec that frames both standard (unsigned) and cryptographically signed Babel messages over the same TCP connection.

Used when a AbstractTCPBabelChannel is configured with AbstractTCPBabelChannel.TCPBabelChannelAuthMode.MIXED_AUTH, allowing protocols on this channel to exchange both BabelMessage and SignedBabelMessage instances dynamically.

Wire format per message (written on top of length-framing added by LengthFieldPrepender):

  [ 4-byte magic (0xBABE12) ] [ 4-byte message-type ID ] [ 1-byte boolean signed flag ] [ serialized payload ]

Decode: reads and verifies the Babel magic number, reads the message-type ID, and reads the signed boolean flag. Depending on the flag:

The payload is then deserialized into a BabelMessage (or SignedBabelMessage) instance.

Encode: detects whether the outbound message is an instance of SignedBabelMessage. If so, wraps the inner message serializer in a FullSignedBabelMessageSerializer and writes signed = true. Otherwise, resolves the standard serializer and writes signed = false.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out)
     
    protected void
    encode(io.netty.channel.ChannelHandlerContext ctx, BabelMessage msg, io.netty.buffer.ByteBuf out)
     

    Methods inherited from class io.netty.handler.codec.ByteToMessageCodec

    acceptOutboundMessage, channelInactive, channelRead, channelReadComplete, decodeLast, handlerAdded, handlerRemoved, write

    Methods inherited from class io.netty.channel.ChannelDuplexHandler

    bind, close, connect, deregister, disconnect, flush, read

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, isSharable

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • decode

      protected void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out) throws Exception
      Specified by:
      decode in class io.netty.handler.codec.ByteToMessageCodec<BabelMessage>
      Throws:
      Exception
    • encode

      protected void encode(io.netty.channel.ChannelHandlerContext ctx, BabelMessage msg, io.netty.buffer.ByteBuf out) throws Exception
      Specified by:
      encode in class io.netty.handler.codec.ByteToMessageCodec<BabelMessage>
      Throws:
      Exception