Class ClientConnectionHandler
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.ThreeWayHandshakeClientHandler<JoinMessage,WelcomeMessage>
org.drasyl.peer.connection.client.ClientConnectionHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
,io.netty.channel.ChannelOutboundHandler
public class ClientConnectionHandler
extends ThreeWayHandshakeClientHandler<JoinMessage,WelcomeMessage>
This handler performs the handshake with the server and processes incoming messages during the
session.
The handshake is initiated by a JoinMessage
sent by the client, which is answered with a
WelcomeMessage
from the server. The client must then confirm this message with a SuccessMessage
.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
protected final CompletableFuture<Void>
protected final Identity
protected final int
protected final Pipeline
protected final Duration
protected io.netty.util.concurrent.ScheduledFuture<?>
Fields inherited from class org.drasyl.peer.connection.handler.ThreeWayHandshakeClientHandler
ATTRIBUTE_PUBLIC_KEY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
channelActive
(io.netty.channel.ChannelHandlerContext ctx) void
channelRead0
(io.netty.channel.ChannelHandlerContext ctx, Message msg) Is called for each message of typeSimpleChannelDuplexHandler
on inbound channel.protected void
channelWrite0
(io.netty.channel.ChannelHandlerContext ctx, Message msg, io.netty.channel.ChannelPromise promise) Is called for each message of typeSimpleChannelDuplexHandler
on the outbound channel.void
close
(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) protected void
createConnection
(io.netty.channel.ChannelHandlerContext ctx, WelcomeMessage offerMessage) void
exceptionCaught
(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) protected org.slf4j.Logger
protected void
processMessageAfterHandshake
(io.netty.channel.ChannelHandlerContext ctx, Message message) protected void
processUnexpectedMessageDuringHandshake
(io.netty.channel.ChannelHandlerContext ctx, Message message) protected void
rejectSession
(io.netty.channel.ChannelHandlerContext ctx, String error) protected void
startTimeoutGuard
(io.netty.channel.ChannelHandlerContext ctx) protected ErrorMessage.Error
validateSessionOffer
(WelcomeMessage offerMessage) This method validates the session offered by the server and must return anErrorMessage.Error
in case of error.Methods inherited from class org.drasyl.peer.connection.handler.ThreeWayHandshakeClientHandler
confirmSession, doHandshake, handlerAdded, requestSession
Methods inherited from class org.drasyl.peer.connection.handler.SimpleChannelDuplexHandler
acceptOutboundMessage, bind, connect, deregister, disconnect, flush, read, write
Methods inherited from class io.netty.channel.SimpleChannelInboundHandler
acceptInboundMessage, channelRead
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, 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
-
Field Details
-
CLIENT_CONNECTION_HANDLER
- See Also:
-
timeout
-
handshakeFuture
-
pipeline
-
networkId
protected final int networkId -
identity
-
timeoutFuture
protected io.netty.util.concurrent.ScheduledFuture<?> timeoutFuture
-
-
Constructor Details
-
ClientConnectionHandler
-
-
Method Details
-
getLogger
protected org.slf4j.Logger getLogger() -
validateSessionOffer
Description copied from class:ThreeWayHandshakeClientHandler
This method validates the session offered by the server and must return anErrorMessage.Error
in case of error. Otherwisenull
must be returned.- Specified by:
validateSessionOffer
in classThreeWayHandshakeClientHandler<JoinMessage,
WelcomeMessage> - Parameters:
offerMessage
- the message that should be validated- Returns:
ErrorMessage.Error
in case of error, otherwisenull
-
createConnection
protected void createConnection(io.netty.channel.ChannelHandlerContext ctx, WelcomeMessage offerMessage) - Specified by:
createConnection
in classThreeWayHandshakeClientHandler<JoinMessage,
WelcomeMessage>
-
processUnexpectedMessageDuringHandshake
protected void processUnexpectedMessageDuringHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message) -
channelRead0
Description copied from class:SimpleChannelDuplexHandler
Is called for each message of typeSimpleChannelDuplexHandler
on inbound channel.- Specified by:
channelRead0
in classSimpleChannelDuplexHandler<Message,
Message> - Parameters:
ctx
- theChannelHandlerContext
which thisSimpleChannelDuplexHandler
belongs tomsg
- the message to handle
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception - Specified by:
close
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
close
in 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:SimpleChannelDuplexHandler
Is called for each message of typeSimpleChannelDuplexHandler
on the outbound channel.- Specified by:
channelWrite0
in classSimpleChannelDuplexHandler<Message,
Message> - Parameters:
ctx
- theChannelHandlerContext
which thisSimpleChannelDuplexHandler
belongs tomsg
- the message to handlepromise
- the corresponding promise
-
processMessageAfterHandshake
protected void processMessageAfterHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message) -
channelActive
- Specified by:
channelActive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelActive
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
Exception
-
startTimeoutGuard
protected void startTimeoutGuard(io.netty.channel.ChannelHandlerContext ctx) -
rejectSession
-
exceptionCaught
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelHandler
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
exceptionCaught
in classio.netty.channel.ChannelInboundHandlerAdapter
-