Moved UDP close hint to it's own class and into the EndPoint (similar to
how Ping works)
This commit is contained in:
parent
f50b218ac1
commit
5d2fa50de2
@ -32,7 +32,6 @@ import org.bouncycastle.crypto.params.ParametersWithIV;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import dorkbox.network.Client;
|
import dorkbox.network.Client;
|
||||||
import dorkbox.network.connection.Listener.OnMessageReceived;
|
|
||||||
import dorkbox.network.connection.bridge.ConnectionBridge;
|
import dorkbox.network.connection.bridge.ConnectionBridge;
|
||||||
import dorkbox.network.connection.idle.IdleBridge;
|
import dorkbox.network.connection.idle.IdleBridge;
|
||||||
import dorkbox.network.connection.idle.IdleSender;
|
import dorkbox.network.connection.idle.IdleSender;
|
||||||
@ -58,7 +57,6 @@ import dorkbox.network.serialization.CryptoSerializationManager;
|
|||||||
import dorkbox.util.collections.LockFreeHashMap;
|
import dorkbox.util.collections.LockFreeHashMap;
|
||||||
import dorkbox.util.collections.LockFreeIntMap;
|
import dorkbox.util.collections.LockFreeIntMap;
|
||||||
import dorkbox.util.generics.ClassHelper;
|
import dorkbox.util.generics.ClassHelper;
|
||||||
import io.netty.bootstrap.DatagramCloseMessage;
|
|
||||||
import io.netty.bootstrap.DatagramSessionChannel;
|
import io.netty.bootstrap.DatagramSessionChannel;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandler.Sharable;
|
import io.netty.channel.ChannelHandler.Sharable;
|
||||||
@ -201,15 +199,6 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements CryptoConne
|
|||||||
|
|
||||||
if (channelWrapper.udp() != null) {
|
if (channelWrapper.udp() != null) {
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
// we received a hint to close this channel from the remote end.
|
|
||||||
add(new OnMessageReceived<Connection, DatagramCloseMessage>() {
|
|
||||||
@Override
|
|
||||||
public
|
|
||||||
void received(final Connection connection, final DatagramCloseMessage message) {
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// when closing this connection, HOW MANY endpoints need to be closed?
|
// when closing this connection, HOW MANY endpoints need to be closed?
|
||||||
@ -570,6 +559,10 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements CryptoConne
|
|||||||
super.userEventTriggered(context, event);
|
super.userEventTriggered(context, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param context can be NULL when running deferred messages from registration process.
|
||||||
|
* @param message the received message
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void channelRead(ChannelHandlerContext context, Object message) throws Exception {
|
void channelRead(ChannelHandlerContext context, Object message) throws Exception {
|
||||||
|
@ -46,6 +46,7 @@ import dorkbox.util.Property;
|
|||||||
import dorkbox.util.crypto.CryptoECC;
|
import dorkbox.util.crypto.CryptoECC;
|
||||||
import dorkbox.util.entropy.Entropy;
|
import dorkbox.util.entropy.Entropy;
|
||||||
import dorkbox.util.exceptions.SecurityException;
|
import dorkbox.util.exceptions.SecurityException;
|
||||||
|
import io.netty.bootstrap.DatagramCloseListener;
|
||||||
import io.netty.channel.local.LocalAddress;
|
import io.netty.channel.local.LocalAddress;
|
||||||
import io.netty.util.NetUtil;
|
import io.netty.util.NetUtil;
|
||||||
|
|
||||||
@ -261,6 +262,12 @@ class EndPoint extends Shutdownable {
|
|||||||
// add the ping listener (internal use only!)
|
// add the ping listener (internal use only!)
|
||||||
connectionManager.add(new PingSystemListener());
|
connectionManager.add(new PingSystemListener());
|
||||||
|
|
||||||
|
// add the UDP "close hint" to close remote connections (internal use only!)
|
||||||
|
if (config.udpPort > 0) {
|
||||||
|
connectionManager.add(new DatagramCloseListener());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (rmiEnabled) {
|
if (rmiEnabled) {
|
||||||
rmiHandler = null;
|
rmiHandler = null;
|
||||||
localRmiHandler = new RmiObjectLocalHandler(logger);
|
localRmiHandler = new RmiObjectLocalHandler(logger);
|
||||||
|
@ -267,8 +267,6 @@ class RegistrationWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For UDP, this map "exists forever" because we have to look up each session on inbound coms
|
|
||||||
* <p>
|
|
||||||
* The session ID '0' is reserved to mean "no session ID yet"
|
* The session ID '0' is reserved to mean "no session ID yet"
|
||||||
*/
|
*/
|
||||||
public
|
public
|
||||||
|
31
src/io/netty/bootstrap/DatagramCloseListener.java
Normal file
31
src/io/netty/bootstrap/DatagramCloseListener.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 dorkbox, llc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package io.netty.bootstrap;
|
||||||
|
|
||||||
|
import dorkbox.network.connection.Connection;
|
||||||
|
import dorkbox.network.connection.Listener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses a hint to close remote UDP connections
|
||||||
|
*/
|
||||||
|
public
|
||||||
|
class DatagramCloseListener implements Listener.OnMessageReceived<Connection, DatagramCloseMessage> {
|
||||||
|
@Override
|
||||||
|
public
|
||||||
|
void received(final Connection connection, final DatagramCloseMessage message) {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@
|
|||||||
package io.netty.bootstrap;
|
package io.netty.bootstrap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Used as a hint to close remote UDP connections
|
||||||
*/
|
*/
|
||||||
public
|
public
|
||||||
class DatagramCloseMessage {}
|
class DatagramCloseMessage {}
|
||||||
|
Loading…
Reference in New Issue
Block a user