Package org.drasyl.channel
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).-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
ConnectionChannelInitializer
(boolean doServer, int port, ConnectionConfig config) protected
ConnectionChannelInitializer
(int localPort, int remotePort) protected
ConnectionChannelInitializer
(int localPort, int remotePort, ConnectionConfig config) protected
ConnectionChannelInitializer
(Boolean doServer, int port) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
handshakeCompleted
(io.netty.channel.ChannelHandlerContext ctx) protected abstract void
handshakeFailed
(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) protected void
Methods inherited from class io.netty.channel.ChannelInitializer
channelRegistered, exceptionCaught, handlerAdded, handlerRemoved
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelRead, channelReadComplete, channelUnregistered, channelWritabilityChanged, userEventTriggered
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Field Details
-
DEFAULT_SERVER_PORT
public static final int DEFAULT_SERVER_PORT- See Also:
-
config
-
-
Constructor Details
-
ConnectionChannelInitializer
-
ConnectionChannelInitializer
protected ConnectionChannelInitializer(int localPort, int remotePort) -
ConnectionChannelInitializer
- Parameters:
doServer
- Determines the server behavior:
true
sets this channel to server mode, listening on the specifiedport
.false
sets this channel to client mode, listening on a random port while assuming the peer listens onport
.
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
- Parameters:
doServer
- Determines the server behavior:
true
sets this channel to server mode, listening on the specifiedport
.false
sets this channel to client mode, listening on a random port while assuming the peer listens onport
.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
- Specified by:
initChannel
in classio.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)
-