Moved UDP close hint to it's own class and into the EndPoint (similar to

how Ping works)
This commit is contained in:
nathan 2018-04-03 14:38:52 +02:00
parent f50b218ac1
commit 5d2fa50de2
5 changed files with 43 additions and 14 deletions

View File

@ -32,7 +32,6 @@ import org.bouncycastle.crypto.params.ParametersWithIV;
import org.slf4j.Logger;
import dorkbox.network.Client;
import dorkbox.network.connection.Listener.OnMessageReceived;
import dorkbox.network.connection.bridge.ConnectionBridge;
import dorkbox.network.connection.idle.IdleBridge;
import dorkbox.network.connection.idle.IdleSender;
@ -58,7 +57,6 @@ import dorkbox.network.serialization.CryptoSerializationManager;
import dorkbox.util.collections.LockFreeHashMap;
import dorkbox.util.collections.LockFreeIntMap;
import dorkbox.util.generics.ClassHelper;
import io.netty.bootstrap.DatagramCloseMessage;
import io.netty.bootstrap.DatagramSessionChannel;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler.Sharable;
@ -201,15 +199,6 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements CryptoConne
if (channelWrapper.udp() != null) {
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?
@ -570,6 +559,10 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements CryptoConne
super.userEventTriggered(context, event);
}
/**
* @param context can be NULL when running deferred messages from registration process.
* @param message the received message
*/
@Override
public
void channelRead(ChannelHandlerContext context, Object message) throws Exception {

View File

@ -46,6 +46,7 @@ import dorkbox.util.Property;
import dorkbox.util.crypto.CryptoECC;
import dorkbox.util.entropy.Entropy;
import dorkbox.util.exceptions.SecurityException;
import io.netty.bootstrap.DatagramCloseListener;
import io.netty.channel.local.LocalAddress;
import io.netty.util.NetUtil;
@ -261,6 +262,12 @@ class EndPoint extends Shutdownable {
// add the ping listener (internal use only!)
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) {
rmiHandler = null;
localRmiHandler = new RmiObjectLocalHandler(logger);

View File

@ -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"
*/
public

View 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();
}
}

View File

@ -16,7 +16,7 @@
package io.netty.bootstrap;
/**
*
* Used as a hint to close remote UDP connections
*/
public
class DatagramCloseMessage {}