Class ThreeWayHandshakeServerHandler<R extends RequestMessage,O extends ResponseMessage<?>>

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<I>
org.drasyl.peer.connection.handler.SimpleChannelDuplexHandler<Message,Message>
org.drasyl.peer.connection.handler.ThreeWayHandshakeServerHandler<R,O>
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler
Direct Known Subclasses:
ServerConnectionHandler

public abstract class ThreeWayHandshakeServerHandler<R extends RequestMessage,O extends ResponseMessage<?>> extends SimpleChannelDuplexHandler<Message,Message>
This handler performs the server-side part of a three-way handshake to create a session. It waits for a request message for a new session from the client. The request is then confirmed by sending an offer message to the client. It then waits for the client to confirm the offer.
  • Field Details

    • timeout

      protected final Duration timeout
    • handshakeFuture

      protected final CompletableFuture<Void> handshakeFuture
    • pipeline

      protected final Pipeline pipeline
    • networkId

      protected final int networkId
    • identity

      protected final Identity identity
    • timeoutFuture

      protected io.netty.util.concurrent.ScheduledFuture<?> timeoutFuture
  • Constructor Details

    • ThreeWayHandshakeServerHandler

      protected ThreeWayHandshakeServerHandler(Duration timeout, Pipeline pipeline, int networkId, Identity identity)
    • ThreeWayHandshakeServerHandler

      protected ThreeWayHandshakeServerHandler(Duration timeout, Pipeline pipeline, CompletableFuture<Void> handshakeFuture, io.netty.util.concurrent.ScheduledFuture<?> timeoutFuture, R requestMessage, O offerMessage, int networkId, Identity identity)
  • Method Details

    • doHandshake

      protected void doHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message)
    • validateSessionRequest

      protected abstract ErrorMessage.Error validateSessionRequest(R requestMessage)
    • offerSession

      protected abstract O offerSession(io.netty.channel.ChannelHandlerContext ctx, R requestMessage)
    • createConnection

      protected abstract void createConnection(io.netty.channel.ChannelHandlerContext ctx, R requestMessage)
    • processUnexpectedMessageDuringHandshake

      protected void processUnexpectedMessageDuringHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message)
    • getLogger

      protected abstract org.slf4j.Logger getLogger()
    • channelRead0

      public void channelRead0(io.netty.channel.ChannelHandlerContext ctx, Message msg)
      Description copied from class: SimpleChannelDuplexHandler
      Is called for each message of type SimpleChannelDuplexHandler on inbound channel.
      Specified by:
      channelRead0 in class SimpleChannelDuplexHandler<Message,Message>
      Parameters:
      ctx - the ChannelHandlerContext which this SimpleChannelDuplexHandler belongs to
      msg - the message to handle
    • close

      public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception
      Specified by:
      close in interface io.netty.channel.ChannelOutboundHandler
      Overrides:
      close in class SimpleChannelDuplexHandler<Message,Message>
      Throws:
      Exception
    • channelWrite0

      protected void channelWrite0(io.netty.channel.ChannelHandlerContext ctx, Message msg, io.netty.channel.ChannelPromise promise)
      Description copied from class: SimpleChannelDuplexHandler
      Is called for each message of type SimpleChannelDuplexHandler on the outbound channel.
      Specified by:
      channelWrite0 in class SimpleChannelDuplexHandler<Message,Message>
      Parameters:
      ctx - the ChannelHandlerContext which this SimpleChannelDuplexHandler belongs to
      msg - the message to handle
      promise - the corresponding promise
    • processMessageAfterHandshake

      protected void processMessageAfterHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message)
    • 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
    • startTimeoutGuard

      protected void startTimeoutGuard(io.netty.channel.ChannelHandlerContext ctx)
    • rejectSession

      protected void rejectSession(io.netty.channel.ChannelHandlerContext ctx, String error)
    • exceptionCaught

      public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelHandler
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter