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:
- If
true, resolves the signed message serializer viaSerializerRegistry.getSignedBabelMessageSerializerById(int). - If
false, resolves the standard message serializer viaSerializerRegistry.getMessageSerializerById(int).
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 TypeMethodDescriptionprotected voidprotected voidencode(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, writeMethods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, readMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Method Details
-
decode
protected void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out) throws Exception - Specified by:
decodein classio.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:
encodein classio.netty.handler.codec.ByteToMessageCodec<BabelMessage>- Throws:
Exception
-