Commit 4ba80e30 authored by Andre Freyssinet's avatar Andre Freyssinet

JORAM-343: Handles connection with bad protocol (errors or attacks).

parent 5e9649f0
/* /*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging * JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2010 ScalAgent Distributed Technologies * Copyright (C) 2001 - 2019 ScalAgent Distributed Technologies
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -29,6 +29,7 @@ import org.objectweb.util.monolog.api.BasicLevel; ...@@ -29,6 +29,7 @@ import org.objectweb.util.monolog.api.BasicLevel;
import fr.dyade.aaa.agent.AgentId; import fr.dyade.aaa.agent.AgentId;
import fr.dyade.aaa.agent.AgentServer; import fr.dyade.aaa.agent.AgentServer;
import fr.dyade.aaa.jndi2.msg.IOControl;
import fr.dyade.aaa.jndi2.server.AgentEntryPoint; import fr.dyade.aaa.jndi2.server.AgentEntryPoint;
import fr.dyade.aaa.jndi2.server.Container; import fr.dyade.aaa.jndi2.server.Container;
import fr.dyade.aaa.jndi2.server.JndiServer; import fr.dyade.aaa.jndi2.server.JndiServer;
...@@ -72,9 +73,14 @@ public class DistributedJndiServer { ...@@ -72,9 +73,14 @@ public class DistributedJndiServer {
int poolSize = AgentServer.getInteger(JndiServer.POOL_SIZE_PROP, JndiServer.DEFAULT_POOL_SIZE).intValue(); int poolSize = AgentServer.getInteger(JndiServer.POOL_SIZE_PROP, JndiServer.DEFAULT_POOL_SIZE).intValue();
int timeout = AgentServer.getInteger(JndiServer.SO_TIMEOUT_PROP, JndiServer.DEFAULT_SO_TIMEOUT).intValue(); // TODO (AF): To remove
if (AgentServer.getInteger(JndiServer.SO_TIMEOUT_PROP, -1).intValue() != -1) {
Trace.logger.log(BasicLevel.WARN,
"\n!! Be careful, property \"" + JndiServer.SO_TIMEOUT_PROP + "\" is no longer used." +
"\n!! Please use property \"" + IOControl.SO_TIMEOUT_PROP + "\" instead.");
}
tcpServer = new TcpServer(serverSocket, poolSize, timeout, getDefault()); tcpServer = new TcpServer(serverSocket, poolSize, getDefault());
if (firstTime) { if (firstTime) {
ReplicationManager manager = new ReplicationManager(serverIds); ReplicationManager manager = new ReplicationManager(serverIds);
......
/* /*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging * JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2010 ScalAgent Distributed Technologies * Copyright (C) 2001 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 1996 - 2000 Dyade * Copyright (C) 1996 - 2000 Dyade
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -30,6 +30,7 @@ import org.objectweb.util.monolog.api.BasicLevel; ...@@ -30,6 +30,7 @@ import org.objectweb.util.monolog.api.BasicLevel;
import fr.dyade.aaa.agent.AgentId; import fr.dyade.aaa.agent.AgentId;
import fr.dyade.aaa.agent.AgentServer; import fr.dyade.aaa.agent.AgentServer;
import fr.dyade.aaa.jndi2.impl.Trace; import fr.dyade.aaa.jndi2.impl.Trace;
import fr.dyade.aaa.jndi2.msg.IOControl;
import fr.dyade.aaa.util.management.MXWrapper; import fr.dyade.aaa.util.management.MXWrapper;
/** /**
...@@ -41,16 +42,14 @@ public class JndiServer { ...@@ -41,16 +42,14 @@ public class JndiServer {
* This property allows to Enable/disable SO_TIMEOUT with the specified timeout * This property allows to Enable/disable SO_TIMEOUT with the specified timeout
* in milliseconds, default value is 10.000L (10 second). * in milliseconds, default value is 10.000L (10 second).
* <p> * <p>
* Be careful, this property is no longer used.
* <p>
* This property can be fixed either from <code>java</code> launching * This property can be fixed either from <code>java</code> launching
* command, or in <code>a3servers.xml</code> configuration file. * command, or in <code>a3servers.xml</code> configuration file.
*/ */
@Deprecated
public static final String SO_TIMEOUT_PROP = "fr.dyade.aaa.jndi2.server.soTimeout"; public static final String SO_TIMEOUT_PROP = "fr.dyade.aaa.jndi2.server.soTimeout";
/**
* Default value for SO_TIMEOUT property.
*/
public static final int DEFAULT_SO_TIMEOUT = 10000;
/** /**
* This property allows to set the number of listening thread, default value is 3. * This property allows to set the number of listening thread, default value is 3.
* <p> * <p>
...@@ -79,9 +78,15 @@ public class JndiServer { ...@@ -79,9 +78,15 @@ public class JndiServer {
int poolSize = AgentServer.getInteger(POOL_SIZE_PROP, DEFAULT_POOL_SIZE).intValue(); int poolSize = AgentServer.getInteger(POOL_SIZE_PROP, DEFAULT_POOL_SIZE).intValue();
int timeout = AgentServer.getInteger(SO_TIMEOUT_PROP, DEFAULT_SO_TIMEOUT).intValue(); // TODO (AF): To remove
if (AgentServer.getInteger(SO_TIMEOUT_PROP, -1).intValue() != -1) {
Trace.logger.log(BasicLevel.WARN,
"\n!! Be careful, property \"" + SO_TIMEOUT_PROP + "\" is no longer used." +
"\n!! Please use property \"" + IOControl.SO_TIMEOUT_PROP + "\" instead.");
}
tcpServer = new TcpServer(serverSocket, poolSize, timeout, getDefault()); tcpServer = new TcpServer(serverSocket, poolSize, getDefault());
if (firstTime) { if (firstTime) {
RequestManager manager = new RequestManager(); RequestManager manager = new RequestManager();
......
/* /*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging * JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2012 ScalAgent Distributed Technologies * Copyright (C) 2001 - 2019 ScalAgent Distributed Technologies
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
...@@ -41,12 +41,12 @@ public class TcpServer implements TcpServerMBean { ...@@ -41,12 +41,12 @@ public class TcpServer implements TcpServerMBean {
private AgentId serverId; private AgentId serverId;
public TcpServer(ServerSocket listen, int poolSize, int timeout, AgentId serverId) { public TcpServer(ServerSocket listen, int poolSize, AgentId serverId) {
this.listen = listen; this.listen = listen;
this.monitors = new Monitor[poolSize]; this.monitors = new Monitor[poolSize];
this.serverId = serverId; this.serverId = serverId;
for (int i = 0; i < monitors.length; i++) { for (int i = 0; i < monitors.length; i++) {
monitors[i] = new Monitor("JndiServer.Monitor#" + i, timeout, this); monitors[i] = new Monitor("JndiServer.Monitor#" + i, this);
monitors[i].setDaemon(true); monitors[i].setDaemon(true);
monitors[i].setThreadGroup(AgentServer.getThreadGroup()); monitors[i].setThreadGroup(AgentServer.getThreadGroup());
} }
...@@ -101,16 +101,12 @@ public class TcpServer implements TcpServerMBean { ...@@ -101,16 +101,12 @@ public class TcpServer implements TcpServerMBean {
} }
public static class Monitor extends Daemon { public static class Monitor extends Daemon {
private int timeout;
private TcpServer tcpServer; private TcpServer tcpServer;
boolean stopping = false; boolean stopping = false;
protected Monitor(String name, int timeout, TcpServer tcpServer) { protected Monitor(String name, TcpServer tcpServer) {
super(name, Trace.logger); super(name, Trace.logger);
this.timeout = timeout;
this.tcpServer = tcpServer; this.tcpServer = tcpServer;
} }
...@@ -123,9 +119,8 @@ public class TcpServer implements TcpServerMBean { ...@@ -123,9 +119,8 @@ public class TcpServer implements TcpServerMBean {
ServerSocket listen = tcpServer.getListen(); ServerSocket listen = tcpServer.getListen();
if (listen != null) { if (listen != null) {
socket = listen.accept(); socket = listen.accept();
socket.setTcpNoDelay(true); // No longer configure TcpNoDelay, SoTimeout and SoLinger, it is done in
socket.setSoTimeout(timeout); // TcpRequestContext/IOControl.
socket.setSoLinger(true, 1000);
canStop = false; canStop = false;
} else { } else {
break loop; break loop;
...@@ -150,8 +145,8 @@ public class TcpServer implements TcpServerMBean { ...@@ -150,8 +145,8 @@ public class TcpServer implements TcpServerMBean {
if (!running) if (!running)
break loop; break loop;
if (Trace.logger.isLoggable(BasicLevel.DEBUG)) { if (Trace.logger.isLoggable(BasicLevel.INFO)) {
Trace.logger.log(BasicLevel.DEBUG, Trace.logger.log(BasicLevel.INFO,
this.getName() + ", connection from " + socket.getInetAddress() + ':' + socket.getPort()); this.getName() + ", connection from " + socket.getInetAddress() + ':' + socket.getPort());
} }
...@@ -159,7 +154,12 @@ public class TcpServer implements TcpServerMBean { ...@@ -159,7 +154,12 @@ public class TcpServer implements TcpServerMBean {
TcpRequestContext ctx = new TcpRequestContext(socket); TcpRequestContext ctx = new TcpRequestContext(socket);
Channel.sendTo(tcpServer.getServerId(), new TcpRequestNot(ctx)); Channel.sendTo(tcpServer.getServerId(), new TcpRequestNot(ctx));
} catch (Exception exc) { } catch (Exception exc) {
Trace.logger.log(BasicLevel.ERROR, this.getName() + ", error during send", exc); if (Trace.logger.isLoggable(BasicLevel.DEBUG))
Trace.logger.log(BasicLevel.ERROR,
this.getName() + ", error during connection from " + socket.getInetAddress() + ':' + socket.getPort(), exc);
else
Trace.logger.log(BasicLevel.ERROR,
this.getName() + ", error during connection from " + socket.getInetAddress() + ':' + socket.getPort());
if (socket != null) { if (socket != null) {
try { try {
socket.close(); socket.close();
......
/* /*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging * JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2001 - 2006 ScalAgent Distributed Technologies * Copyright (C) 2001 - 2019 ScalAgent Distributed Technologies
* Copyright (C) 1996 - 2000 Dyade * Copyright (C) 1996 - 2000 Dyade
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -33,12 +33,22 @@ import java.io.ObjectStreamConstants; ...@@ -33,12 +33,22 @@ import java.io.ObjectStreamConstants;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import fr.dyade.aaa.common.Configuration;
public class IOControl { public class IOControl {
/** /**
* This property allow to enable/disable SO_TIMEOUT with the specified * This property allows to Enable/disable SO_TIMEOUT with the specified timeout
* timeout in milliseconds. * in milliseconds, default value is 5.000L (5 seconds).
* <p>
* Server side this property can be fixed either from <code>java</code> launching
* command, or in <code>a3servers.xml</code> configuration file.
*/
public static final String SO_TIMEOUT_PROP = "fr.dyade.aaa.jndi2.socketTimeOut";
/**
* Default value for SO_TIMEOUT property.
*/ */
public static final String SOCKET_SOTIMEOUT = "fr.dyade.aaa.jndi2.socketTimeOut"; public static final int DEFAULT_SO_TIMEOUT = 5000;
/** /**
* Enable/disable SO_TIMEOUT with the specified timeout in milliseconds. * Enable/disable SO_TIMEOUT with the specified timeout in milliseconds.
...@@ -50,7 +60,7 @@ public class IOControl { ...@@ -50,7 +60,7 @@ public class IOControl {
* of time. * of time.
*/ */
private static int socketTimeOut = private static int socketTimeOut =
Integer.getInteger(SOCKET_SOTIMEOUT, 0).intValue(); Configuration.getInteger(SO_TIMEOUT_PROP, DEFAULT_SO_TIMEOUT).intValue();
private Socket socket; private Socket socket;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment