Class ConnectionChannelInitializer

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelInitializer<DrasylChannel>
org.drasyl.channel.ConnectionChannelInitializer
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler
Direct Known Subclasses:
DrasylNodeChannelInitializer

@UnstableApi public abstract class ConnectionChannelInitializer extends io.netty.channel.ChannelInitializer<DrasylChannel>
This ChannelInitializer create a channel providing reliable and ordered delivery of bytes between hosts. Handlers can either be added to the pipeline on channel creation time using initChannel(DrasylChannel) or after connection with the remote peer has been established using handshakeCompleted(ChannelHandlerContext). handshakeFailed(ChannelHandlerContext, Throwable) is called, when no connection could be established (e.g., because the other party has not responded within the time limit or has rejected the handshake).
  • Field Details

  • Constructor Details

    • ConnectionChannelInitializer

      protected ConnectionChannelInitializer(int localPort, int remotePort, ConnectionConfig config)
    • ConnectionChannelInitializer

      protected ConnectionChannelInitializer(int localPort, int remotePort)
    • ConnectionChannelInitializer

      protected ConnectionChannelInitializer(boolean doServer, int port, ConnectionConfig config)
      Parameters:
      doServer - Determines the server behavior:
      • true sets this channel to server mode, listening on the specified port.
      • false sets this channel to client mode, listening on a random port while assuming the peer listens on port.
      port - Specifies the port number. In server mode, the channel listens on this port. In client mode, the channel assumes the peer listens on this port.
      config - Configuration settings for connections.
    • ConnectionChannelInitializer

      protected ConnectionChannelInitializer(Boolean doServer, int port)
      Parameters:
      doServer - Determines the server behavior:
      • true sets this channel to server mode, listening on the specified port.
      • false sets this channel to client mode, listening on a random port while assuming the peer listens on port.
      • null decides the server/client role based on comparing local and remote public keys, with the "higher" key indicating a server.
      port - Specifies the port number. In server mode, the channel listens on this port. In client mode, the channel assumes the peer listens on this port.
  • Method Details

    • initChannel

      protected void initChannel(DrasylChannel ch) throws Exception
      Specified by:
      initChannel in class io.netty.channel.ChannelInitializer<DrasylChannel>
      Throws:
      Exception
    • handshakeCompleted

      protected abstract void handshakeCompleted(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Throws:
      Exception
    • handshakeFailed

      protected abstract void handshakeFailed(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)