Class ThreeWayHandshakeClientHandler<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.ThreeWayHandshakeClientHandler<R,O>
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
,io.netty.channel.ChannelOutboundHandler
- Direct Known Subclasses:
ClientConnectionHandler
public abstract class ThreeWayHandshakeClientHandler<R extends RequestMessage,O extends ResponseMessage<?>> extends SimpleChannelDuplexHandler<Message,Message>
This handler performs the client-side part of a three-way handshake to create a session. It automatically requests the server for a new session. The server must confirm this request and then offers the client a session. Then the client has to confirm the offered session again.
-
-
Field Summary
Fields Modifier and Type Field Description static io.netty.util.AttributeKey<CompressedPublicKey>
ATTRIBUTE_PUBLIC_KEY
protected CompletableFuture<Void>
handshakeFuture
protected Identity
identity
protected int
networkId
protected Pipeline
pipeline
protected Duration
timeout
protected io.netty.util.concurrent.ScheduledFuture<?>
timeoutFuture
-
Constructor Summary
Constructors Modifier Constructor Description protected
ThreeWayHandshakeClientHandler(int networkId, Identity identity, Duration timeout, Pipeline pipeline, CompletableFuture<Void> handshakeFuture, io.netty.util.concurrent.ScheduledFuture<?> timeoutFuture, R requestMessage)
protected
ThreeWayHandshakeClientHandler(int networkId, Identity identity, Duration timeout, Pipeline pipeline, R requestMessage)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
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
confirmSession(io.netty.channel.ChannelHandlerContext ctx, O offerMessage)
protected abstract void
createConnection(io.netty.channel.ChannelHandlerContext ctx, O offerMessage)
protected void
doHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message)
void
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
protected abstract org.slf4j.Logger
getLogger()
void
handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
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
requestSession(io.netty.channel.ChannelHandlerContext ctx)
protected void
startTimeoutGuard(io.netty.channel.ChannelHandlerContext ctx)
protected abstract ErrorMessage.Error
validateSessionOffer(O 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.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
-
-
-
-
Field Detail
-
ATTRIBUTE_PUBLIC_KEY
public static final io.netty.util.AttributeKey<CompressedPublicKey> ATTRIBUTE_PUBLIC_KEY
-
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
-
-
Method Detail
-
doHandshake
protected void doHandshake(io.netty.channel.ChannelHandlerContext ctx, Message message)
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception
- Specified by:
handlerAdded
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerAdded
in classio.netty.channel.ChannelHandlerAdapter
- Throws:
Exception
-
requestSession
protected void requestSession(io.netty.channel.ChannelHandlerContext ctx)
-
validateSessionOffer
protected abstract ErrorMessage.Error validateSessionOffer(O offerMessage)
This method validates the session offered by the server and must return anErrorMessage.Error
in case of error. Otherwisenull
must be returned.- Parameters:
offerMessage
- the message that should be validated- Returns:
ErrorMessage.Error
in case of error, otherwisenull
-
confirmSession
protected void confirmSession(io.netty.channel.ChannelHandlerContext ctx, O offerMessage)
-
createConnection
protected abstract void createConnection(io.netty.channel.ChannelHandlerContext ctx, O offerMessage)
-
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 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
public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
- 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
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 interfaceio.netty.channel.ChannelHandler
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
exceptionCaught
in classio.netty.channel.ChannelInboundHandlerAdapter
-
-