Class GoBackNArqHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
org.drasyl.handler.arq.gobackn.GoBackNArqHandler
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public class GoBackNArqHandler extends io.netty.channel.ChannelDuplexHandler
Performs the Go-Back-N ARQ protocol.

It also updates the writability of the associated Channel. This update allows pending write operations to determine the writability.

This handler changes the behavior of the Promises returned by ChannelOutboundInvoker.write(Object): The promise is not complemented until the message's recipient has acknowledged arrival of the message.

If you abort the promise, this handler will discard the message. Aborting a promise for a message that is waiting to be acknowledged can cause the sender and receiver to no longer have the same message sequence. This occurs when the acknowledgement of a message is lost and the promise of that message was manually aborted.

This handler tries to automatically synchronize the sequence numbers.

This handler should be used together with GoBackNArqCodec and ByteToGoBackNArqDataCodec.

  ChannelPipeline p = ...;
  ...
  p.addLast("arq_codec", new GoBackNArqCodec());
  p.addLast("arq_handler", new GoBackNArqHandler(150, Duration.ofMillis(100), Duration.ofMills(100).dividedBy(10)));
  p.addLast("buf_codec", new ByteToGoBackNArqDataCodec());
  ...
  p.addLast("handler", new HttpRequestHandler());
  
  • Nested Class Summary

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

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

    Constructors
    Constructor
    Description
    GoBackNArqHandler(int windowSize, Duration retryTimeout, boolean windowShouldAffectWritability, Duration ackClock)
    Creates a new GoBackNArqHandler.
    GoBackNArqHandler(int windowSize, Duration retryTimeout, Duration ackClock)
    Creates a new GoBackNArqHandler.
    GoBackNArqHandler(int windowSize, Duration retryTimeout, UnsignedInteger base, UnsignedInteger nextSeqNum, UnsignedInteger nextInboundSequenceNo, boolean windowShouldAffectWritability, Duration ackClock)
    Creates a new GoBackNArqHandler.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelActive(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    channelInactive(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
     
    void
    handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)
     

    Methods inherited from class io.netty.channel.ChannelDuplexHandler

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

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, handlerRemoved, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerRemoved
  • Constructor Details

    • GoBackNArqHandler

      public GoBackNArqHandler(int windowSize, Duration retryTimeout, UnsignedInteger base, UnsignedInteger nextSeqNum, UnsignedInteger nextInboundSequenceNo, boolean windowShouldAffectWritability, Duration ackClock)
      Creates a new GoBackNArqHandler.

      When specifying the window size, you should take the MTU in bytes, the maximum link capacity (LC) in bytes, and the RTT in ms into account. For example, a good window size could be (LC * RTT) / (MTU * 2000).

      The retry timeout should be at least twice as large as the time needed to transfer a single frame.

      Parameters:
      windowSize - the window size
      retryTimeout - the retry timeout
      base - the first unacknowledged sequence number
      nextSeqNum - the next sequence number, that was not already send
      nextInboundSequenceNo - the next expected inbound sequence number
      windowShouldAffectWritability - if the window should be added to the channels pending bytes
      ackClock - the frequency of sending ACKs for received packages
    • GoBackNArqHandler

      public GoBackNArqHandler(int windowSize, Duration retryTimeout, Duration ackClock)
      Creates a new GoBackNArqHandler.

      When specifying the window size, you should take the MTU, the maximum link capacity (LC), and the RTT into account. For example, a good window size could be (LC*RTT) / (1000*MTU).

      The retry timeout should be at least twice as large as the time needed to transfer a single window.

      Parameters:
      windowSize - the window size
      retryTimeout - the retry timeout
      ackClock - the frequency of sending ACKs for received packages
    • GoBackNArqHandler

      public GoBackNArqHandler(int windowSize, Duration retryTimeout, boolean windowShouldAffectWritability, Duration ackClock)
      Creates a new GoBackNArqHandler.

      When specifying the window size, you should take the MTU, the maximum link capacity (LC), and the RTT into account. For example, a good window size could be (LC*RTT) / (1000*MTU).

      The retry timeout should be at least twice as large as the time needed to transfer a single window.

      Parameters:
      windowSize - the window size
      retryTimeout - the retry timeout
      windowShouldAffectWritability - if the window should be added to the channels pending bytes
      ackClock - the frequency of sending ACKs for received packages
  • Method Details

    • handlerAdded

      public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
      Specified by:
      handlerAdded in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerAdded in class io.netty.channel.ChannelHandlerAdapter
    • channelActive

      public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelActive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • channelInactive

      public void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
      Specified by:
      channelInactive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelInactive in class io.netty.channel.ChannelInboundHandlerAdapter
    • channelRead

      public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
      Specified by:
      channelRead in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
    • write

      public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)
      Specified by:
      write in interface io.netty.channel.ChannelOutboundHandler
      Overrides:
      write in class io.netty.channel.ChannelDuplexHandler