Class ServerConnectionHandler
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<JoinMessage,WelcomeMessage>
org.drasyl.peer.connection.server.ServerConnectionHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler
public class ServerConnectionHandler
extends ThreeWayHandshakeServerHandler<JoinMessage,WelcomeMessage>
Acts as a guard for in- and outbound connections. A channel is only created, when a
JoinMessage was received. Outgoing messages are dropped unless a JoinMessage was
received. Every other incoming message is also dropped unless a JoinMessage was
received.
If a JoinMessage was not received in DrasylConfig.getServerHandshakeTimeout() the
connection will be closed.
This handler closes the channel if an exception occurs before a JoinMessage has been
received.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelActive(io.netty.channel.ChannelHandlerContext ctx) voidchannelRead0(io.netty.channel.ChannelHandlerContext ctx, Message msg) Is called for each message of typeSimpleChannelDuplexHandleron inbound channel.protected voidchannelWrite0(io.netty.channel.ChannelHandlerContext ctx, Message msg, io.netty.channel.ChannelPromise promise) Is called for each message of typeSimpleChannelDuplexHandleron the outbound channel.voidclose(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) protected voidcreateConnection(io.netty.channel.ChannelHandlerContext ctx, JoinMessage requestMessage) voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) protected org.slf4j.Loggerprotected WelcomeMessageofferSession(io.netty.channel.ChannelHandlerContext ctx, JoinMessage requestMessage) protected voidprocessMessageAfterHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message) protected voidprocessUnexpectedMessageDuringHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message) protected voidrejectSession(io.netty.channel.ChannelHandlerContext ctx, String error) protected voidstartTimeoutGuard(io.netty.channel.ChannelHandlerContext ctx) protected ErrorMessage.ErrorvalidateSessionRequest(JoinMessage requestMessage) Methods inherited from class org.drasyl.peer.connection.handler.ThreeWayHandshakeServerHandler
doHandshakeMethods inherited from class org.drasyl.peer.connection.handler.SimpleChannelDuplexHandler
acceptOutboundMessage, bind, connect, deregister, disconnect, flush, read, writeMethods inherited from class io.netty.channel.SimpleChannelInboundHandler
acceptInboundMessage, channelReadMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
SERVER_CONNECTION_HANDLER
- See Also:
-
timeout
-
handshakeFuture
-
pipeline
-
networkId
protected final int networkId -
identity
-
timeoutFuture
protected io.netty.util.concurrent.ScheduledFuture<?> timeoutFuture
-
-
Constructor Details
-
ServerConnectionHandler
-
-
Method Details
-
validateSessionRequest
- Specified by:
validateSessionRequestin classThreeWayHandshakeServerHandler<JoinMessage,WelcomeMessage>
-
offerSession
protected WelcomeMessage offerSession(io.netty.channel.ChannelHandlerContext ctx, JoinMessage requestMessage) - Specified by:
offerSessionin classThreeWayHandshakeServerHandler<JoinMessage,WelcomeMessage>
-
createConnection
protected void createConnection(io.netty.channel.ChannelHandlerContext ctx, JoinMessage requestMessage) - Specified by:
createConnectionin classThreeWayHandshakeServerHandler<JoinMessage,WelcomeMessage>
-
getLogger
protected org.slf4j.Logger getLogger() -
processUnexpectedMessageDuringHandshake
protected void processUnexpectedMessageDuringHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message) -
channelRead0
Description copied from class:SimpleChannelDuplexHandlerIs called for each message of typeSimpleChannelDuplexHandleron inbound channel.- Specified by:
channelRead0in classSimpleChannelDuplexHandler<Message,Message> - Parameters:
ctx- theChannelHandlerContextwhich thisSimpleChannelDuplexHandlerbelongs tomsg- the message to handle
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception - Specified by:
closein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
closein classSimpleChannelDuplexHandler<Message,Message> - Throws:
Exception
-
channelWrite0
protected void channelWrite0(io.netty.channel.ChannelHandlerContext ctx, Message msg, io.netty.channel.ChannelPromise promise) Description copied from class:SimpleChannelDuplexHandlerIs called for each message of typeSimpleChannelDuplexHandleron the outbound channel.- Specified by:
channelWrite0in classSimpleChannelDuplexHandler<Message,Message> - Parameters:
ctx- theChannelHandlerContextwhich thisSimpleChannelDuplexHandlerbelongs tomsg- the message to handlepromise- the corresponding promise
-
processMessageAfterHandshake
protected void processMessageAfterHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message) -
channelActive
- Specified by:
channelActivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelActivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
startTimeoutGuard
protected void startTimeoutGuard(io.netty.channel.ChannelHandlerContext ctx) -
rejectSession
-
exceptionCaught
- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter
-