Commit b369394d authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Refactoring to use NIO for c2s.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6576 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8485752d
......@@ -509,9 +509,8 @@ public class SessionManager extends BasicModule {
*
* @param conn the connection to create the session from.
* @return a newly created session.
* @throws UnauthorizedException
*/
public ClientSession createClientSession(Connection conn) throws UnauthorizedException {
public ClientSession createClientSession(Connection conn) {
return createClientSession(conn, nextStreamID());
}
......@@ -523,10 +522,9 @@ public class SessionManager extends BasicModule {
* @return a newly created session.
* @throws UnauthorizedException
*/
public ClientSession createClientSession(Connection conn, StreamID id)
throws UnauthorizedException {
public ClientSession createClientSession(Connection conn, StreamID id) {
if (serverName == null) {
throw new UnauthorizedException("Server not initialized");
throw new IllegalStateException("Server not initialized");
}
ClientSession session = new ClientSession(serverName, conn, id);
conn.init(session);
......
......@@ -19,7 +19,6 @@ import org.jivesoftware.wildfire.Connection;
import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.StreamID;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.event.SessionEventDispatcher;
import org.jivesoftware.wildfire.event.SessionEventListener;
import org.jivesoftware.wildfire.session.ClientSession;
......@@ -128,28 +127,24 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
* @param streamID the stream ID created by the connection manager for the new session.
*/
public void createClientSession(String connectionManagerDomain, String streamID) {
try {
Connection connection = new ClientSessionConnection(connectionManagerDomain);
ClientSession session = SessionManager.getInstance()
.createClientSession(connection, new BasicStreamID(streamID));
// Register that this streamID belongs to the specified connection manager
streamIDs.put(streamID, connectionManagerDomain);
// Register which sessions are being hosted by the speicifed connection manager
Map<String, ClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions == null) {
synchronized (connectionManagerDomain.intern()) {
sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions == null) {
sessions = new ConcurrentHashMap<String, ClientSession>();
sessionsByManager.put(connectionManagerDomain, sessions);
}
// TODO Consider that client session may return null when IP address is forbidden
Connection connection = new ClientSessionConnection(connectionManagerDomain);
ClientSession session = SessionManager.getInstance()
.createClientSession(connection, new BasicStreamID(streamID));
// Register that this streamID belongs to the specified connection manager
streamIDs.put(streamID, connectionManagerDomain);
// Register which sessions are being hosted by the speicifed connection manager
Map<String, ClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions == null) {
synchronized (connectionManagerDomain.intern()) {
sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions == null) {
sessions = new ConcurrentHashMap<String, ClientSession>();
sessionsByManager.put(connectionManagerDomain, sessions);
}
}
sessions.put(streamID, session);
}
catch (UnauthorizedException e) {
Log.error("Error creating virtual client session", e);
}
sessions.put(streamID, session);
}
/**
......
......@@ -53,6 +53,10 @@ public abstract class StanzaHandler {
// Flag that indicates that the client requested to be authenticated. Once the
// authentication process is over the value will return to false.
private boolean startedSASL = false;
/**
* SASL status based on the last SASL interaction
*/
private SASLAuthentication.Status saslStatus;
// DANIELE: Indicate if a stream:stream is arrived to complete compression
private boolean waitingCompressionACK = false;
......@@ -113,7 +117,7 @@ public abstract class StanzaHandler {
MXParser parser = (MXParser) factory.newPullParser();
parser.setInput(new StringReader(stanza));
createSession(parser);
} else if (startedSASL && session.getStatus() == Session.STATUS_AUTHENTICATED) {
} else if (startedSASL && saslStatus == SASLAuthentication.Status.authenticated) {
startedSASL = false;
saslSuccessful();
} else if (waitingCompressionACK) {
......@@ -151,8 +155,11 @@ public abstract class StanzaHandler {
} else if ("auth".equals(tag)) {
// User is trying to authenticate using SASL
startedSASL = true;
// Forward packet to the server
process(doc);
// Process authentication stanza
saslStatus = SASLAuthentication.handle(session, doc);
} else if (startedSASL && "response".equals(tag)) {
// User is responding to SASL challenge. Process response
saslStatus = SASLAuthentication.handle(session, doc);
} else if ("compress".equals(tag)) {
// Client is trying to initiate compression
if (compressClient(doc)) {
......
......@@ -13,8 +13,8 @@ package org.jivesoftware.wildfire.server;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.ConnectionManager;
import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.net.SocketAcceptThread;
import org.jivesoftware.wildfire.server.RemoteServerConfiguration.Permission;
import org.jivesoftware.wildfire.session.Session;
......@@ -283,15 +283,13 @@ public class RemoteServerManager {
* @return the remote port to connect for the specified remote server.
*/
public static int getPortForServer(String domain) {
int port = JiveGlobals.getIntProperty("xmpp.server.socket.remotePort",
SocketAcceptThread.DEFAULT_SERVER_PORT);
int port = JiveGlobals.getIntProperty("xmpp.server.socket.remotePort", ConnectionManager.DEFAULT_SERVER_PORT);
RemoteServerConfiguration config = getConfiguration(domain);
if (config != null) {
port = config.getRemotePort();
if (port == 0) {
port =
JiveGlobals.getIntProperty("xmpp.server.socket.remotePort",
SocketAcceptThread.DEFAULT_SERVER_PORT);
port = JiveGlobals
.getIntProperty("xmpp.server.socket.remotePort", ConnectionManager.DEFAULT_SERVER_PORT);
}
}
return port;
......
......@@ -8,16 +8,14 @@
- a copy of which is included in this distribution.
--%>
<%@ page import="org.jivesoftware.util.*,
org.jivesoftware.admin.AdminPageBean,
java.util.*,
<%@ page import="org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.ParamUtils,
org.jivesoftware.wildfire.ConnectionManager,
org.jivesoftware.wildfire.XMPPServer,
java.net.InetAddress,
org.jivesoftware.util.JiveGlobals,
org.jivesoftware.wildfire.net.SSLSocketAcceptThread,
org.jivesoftware.wildfire.net.SocketAcceptThread,
org.jivesoftware.wildfire.ConnectionManager"
java.util.HashMap"
%>
<%@ page import="java.util.Map" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
......@@ -30,14 +28,14 @@
<%
// Get parameters
String serverName = ParamUtils.getParameter(request,"serverName");
int port = ParamUtils.getIntParameter(request,"port",-1);
int sslPort = ParamUtils.getIntParameter(request,"sslPort",-1);
int embeddedPort = ParamUtils.getIntParameter(request,"embeddedPort",-1);
int embeddedSecurePort = ParamUtils.getIntParameter(request,"embeddedSecurePort",-1);
boolean sslEnabled = ParamUtils.getBooleanParameter(request,"sslEnabled");
int componentPort = ParamUtils.getIntParameter(request,"componentPort",-1);
int serverPort = ParamUtils.getIntParameter(request,"serverPort",-1);
String serverName = ParamUtils.getParameter(request, "serverName");
int port = ParamUtils.getIntParameter(request, "port", -1);
int sslPort = ParamUtils.getIntParameter(request, "sslPort", -1);
int embeddedPort = ParamUtils.getIntParameter(request, "embeddedPort", -1);
int embeddedSecurePort = ParamUtils.getIntParameter(request, "embeddedSecurePort", -1);
boolean sslEnabled = ParamUtils.getBooleanParameter(request, "sslEnabled");
int componentPort = ParamUtils.getIntParameter(request, "componentPort", -1);
int serverPort = ParamUtils.getIntParameter(request, "serverPort", -1);
boolean save = request.getParameter("save") != null;
boolean defaults = request.getParameter("defaults") != null;
boolean cancel = request.getParameter("cancel") != null;
......@@ -49,10 +47,10 @@
if (defaults) {
serverName = InetAddress.getLocalHost().getHostName();
port = SocketAcceptThread.DEFAULT_PORT;
sslPort = SSLSocketAcceptThread.DEFAULT_PORT;
componentPort = SocketAcceptThread.DEFAULT_COMPONENT_PORT;
serverPort = SocketAcceptThread.DEFAULT_SERVER_PORT;
port = ConnectionManager.DEFAULT_PORT;
sslPort = ConnectionManager.DEFAULT_SSL_PORT;
componentPort = ConnectionManager.DEFAULT_COMPONENT_PORT;
serverPort = ConnectionManager.DEFAULT_SERVER_PORT;
embeddedPort = 9090;
embeddedSecurePort = 9091;
sslEnabled = true;
......@@ -64,40 +62,39 @@
Map<String, String> errors = new HashMap<String, String>();
if (save) {
if (serverName == null) {
errors.put("serverName","");
errors.put("serverName", "");
}
if (port < 1) {
errors.put("port","");
errors.put("port", "");
}
if (sslPort < 1 && sslEnabled) {
errors.put("sslPort","");
errors.put("sslPort", "");
}
if (componentPort < 1) {
errors.put("componentPort","");
errors.put("componentPort", "");
}
if (serverPort < 1) {
errors.put("serverPort","");
errors.put("serverPort", "");
}
if (XMPPServer.getInstance().isStandAlone()) {
if (embeddedPort < 1) {
errors.put("embeddedPort","");
errors.put("embeddedPort", "");
}
if (embeddedSecurePort < 1) {
errors.put("embeddedSecurePort","");
errors.put("embeddedSecurePort", "");
}
if (embeddedPort > 0 && embeddedSecurePort > 0) {
if (embeddedPort == embeddedSecurePort) {
errors.put("embeddedPortsEqual","");
errors.put("embeddedPortsEqual", "");
}
}
}
else {
} else {
embeddedPort = -1;
embeddedSecurePort = -1;
}
if (port > 0 && sslPort > 0) {
if (port == sslPort) {
errors.put("portsEqual","");
errors.put("portsEqual", "");
}
}
if (errors.size() == 0) {
......@@ -121,22 +118,26 @@
}
if (needRestart) {
response.sendRedirect("server-props.jsp?success=true&restart=true");
}
else {
} else {
response.sendRedirect("server-props.jsp?success=true");
}
return;
}
}
else {
} else {
serverName = server.getServerInfo().getName();
sslEnabled = connectionManager.isClientSSLListenerEnabled();
port = connectionManager.getClientListenerPort();
sslPort = connectionManager.getClientSSLListenerPort();
componentPort = connectionManager.getComponentListenerPort();
serverPort = connectionManager.getServerListenerPort();
try { embeddedPort = Integer.parseInt(JiveGlobals.getXMLProperty("adminConsole.port")); } catch (Exception ignored) {}
try { embeddedSecurePort = Integer.parseInt(JiveGlobals.getXMLProperty("adminConsole.securePort")); } catch (Exception ignored) {}
try {
embeddedPort = Integer.parseInt(JiveGlobals.getXMLProperty("adminConsole.port"));
} catch (Exception ignored) {
}
try {
embeddedSecurePort = Integer.parseInt(JiveGlobals.getXMLProperty("adminConsole.securePort"));
} catch (Exception ignored) {
}
}
%>
......@@ -216,7 +217,7 @@
<br>
<span class="jive-error-text">
<fmt:message key="server.props.valid_port" />
<a href="#" onclick="document.editform.serverPort.value='<%=SocketAcceptThread.DEFAULT_SERVER_PORT%>';"
<a href="#" onclick="document.editform.serverPort.value='<%=ConnectionManager.DEFAULT_SERVER_PORT%>';"
><fmt:message key="server.props.valid_port1" /></a>.
</span>
<% } %>
......@@ -233,7 +234,7 @@
<br>
<span class="jive-error-text">
<fmt:message key="server.props.valid_port" />
<a href="#" onclick="document.editform.componentPort.value='<%=SocketAcceptThread.DEFAULT_COMPONENT_PORT%>';"
<a href="#" onclick="document.editform.componentPort.value='<%=ConnectionManager.DEFAULT_COMPONENT_PORT%>';"
><fmt:message key="server.props.valid_port1" /></a>.
</span>
<% } %>
......@@ -250,7 +251,7 @@
<br>
<span class="jive-error-text">
<fmt:message key="server.props.valid_port" />
<a href="#" onclick="document.editform.port.value='<%=SocketAcceptThread.DEFAULT_PORT%>';"
<a href="#" onclick="document.editform.port.value='<%=ConnectionManager.DEFAULT_PORT%>';"
><fmt:message key="server.props.valid_port1" /></a>.
</span>
<% } else if (errors.containsKey("portsEqual")) { %>
......@@ -297,7 +298,7 @@
<br>
<span class="jive-error-text">
<fmt:message key="server.props.ssl_valid" />
<a href="#" onclick="document.editform.sslPort.value='<%=SSLSocketAcceptThread.DEFAULT_PORT%>';"
<a href="#" onclick="document.editform.sslPort.value='<%=ConnectionManager.DEFAULT_SSL_PORT%>';"
><fmt:message key="server.props.ssl_valid1" /></a>.
</span>
<% } %>
......
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