Commit 35bb6b57 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

My little small refactoring.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8405 b35dd754-fafc-0310-a699-88a17e54d16e
parent 5515e869
...@@ -166,10 +166,7 @@ public class PresenceRouter extends BasicModule { ...@@ -166,10 +166,7 @@ public class PresenceRouter extends BasicModule {
Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e); Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e);
Session session = sessionManager.getSession(packet.getFrom()); Session session = sessionManager.getSession(packet.getFrom());
if (session != null) { if (session != null) {
Connection conn = session.getConnection(); session.close();
if (conn != null) {
conn.close();
}
} }
} }
} }
...@@ -188,9 +185,10 @@ public class PresenceRouter extends BasicModule { ...@@ -188,9 +185,10 @@ public class PresenceRouter extends BasicModule {
/** /**
* Notification message indicating that a packet has failed to be routed to the receipient. * Notification message indicating that a packet has failed to be routed to the receipient.
* *
* @param receipient address of the entity that failed to receive the packet.
* @param packet Presence packet that failed to be sent to the receipient. * @param packet Presence packet that failed to be sent to the receipient.
*/ */
public void routingFailed(Packet packet) { public void routingFailed(JID receipient, Packet packet) {
// presence packets are dropped silently // presence packets are dropped silently
} }
} }
...@@ -11,12 +11,15 @@ ...@@ -11,12 +11,15 @@
package org.jivesoftware.openfire; package org.jivesoftware.openfire;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.LocalClientSession;
import org.jivesoftware.openfire.session.LocalOutgoingServerSession;
import org.jivesoftware.openfire.session.OutgoingServerSession;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
...@@ -85,7 +88,7 @@ public interface RoutingTable { ...@@ -85,7 +88,7 @@ public interface RoutingTable {
* @param route the address associated to the route. * @param route the address associated to the route.
* @param destination the outgoing server session. * @param destination the outgoing server session.
*/ */
void addServerRoute(JID route, RoutableChannelHandler destination); void addServerRoute(JID route, LocalOutgoingServerSession destination);
/** /**
* Adds a route to the routing table for the specified internal or external component. When * Adds a route to the routing table for the specified internal or external component. When
...@@ -107,7 +110,7 @@ public interface RoutingTable { ...@@ -107,7 +110,7 @@ public interface RoutingTable {
* @param route the address associated to the route. * @param route the address associated to the route.
* @param destination the client session. * @param destination the client session.
*/ */
void addClientRoute(JID route, ClientSession destination); void addClientRoute(JID route, LocalClientSession destination);
/** /**
* Routes a packet to the specified address. The packet destination can be a * Routes a packet to the specified address. The packet destination can be a
...@@ -135,16 +138,17 @@ public interface RoutingTable { ...@@ -135,16 +138,17 @@ public interface RoutingTable {
* *
* @param jid the receipient of the packet to route. * @param jid the receipient of the packet to route.
* @param packet the packet to route. * @param packet the packet to route.
* @throws UnauthorizedException if not allowed to process the packet.
* @throws PacketException thrown if the packet is malformed (results in the sender's * @throws PacketException thrown if the packet is malformed (results in the sender's
* session being shutdown). * session being shutdown).
*/ */
void routePacket(JID jid, Packet packet) throws PacketException, UnauthorizedException; void routePacket(JID jid, Packet packet) throws PacketException;
/** /**
* Returns true if a registered user or anonymous user with the specified full JID is * Returns true if a registered user or anonymous user with the specified full JID is
* currently logged. When running inside of a cluster a true value will be returned * currently logged. When running inside of a cluster a true value will be returned
* as long as the user is connecte to any cluster node. * as long as the user is connected to any cluster node.
*
* // TODO Should we care about available or not available????
* *
* @param jid the full JID of the user. * @param jid the full JID of the user.
* @return true if a registered user or anonymous user with the specified full JID is * @return true if a registered user or anonymous user with the specified full JID is
...@@ -152,6 +156,16 @@ public interface RoutingTable { ...@@ -152,6 +156,16 @@ public interface RoutingTable {
*/ */
boolean hasClientRoute(JID jid); boolean hasClientRoute(JID jid);
/**
* Returns true if an anonymous user with the specified full JID is currently logged.
* When running inside of a cluster a true value will be returned as long as the
* user is connected to any cluster node.
*
* @param jid the full JID of the anonymous user.
* @return true if an anonymous user with the specified full JID is currently logged.
*/
boolean isAnonymousRoute(JID jid);
/** /**
* Returns true if an outgoing server session exists to the specified remote server. * Returns true if an outgoing server session exists to the specified remote server.
* The JID can be a full JID or a bare JID since only the domain of the specified * The JID can be a full JID or a bare JID since only the domain of the specified
...@@ -179,6 +193,47 @@ public interface RoutingTable { ...@@ -179,6 +193,47 @@ public interface RoutingTable {
*/ */
boolean hasComponentRoute(JID jid); boolean hasComponentRoute(JID jid);
/**
* Returns the client session associated to the specified XMPP address or <tt>null</tt>
* if none was found. When running inside of a cluster and a remote node is hosting
* the client session then a session surrage will be returned.
*
* @param jid the address of the session.
* @return the client session associated to the specified XMPP address or null if none was found.
*/
ClientSession getClientRoute(JID jid);
/**
* Returns collection of client sessions authenticated with the server. When running inside
* of a cluster the returned sessions will include sessions connected to this JVM and also
* other cluster nodes.
*
* TODO Prevent usage of this message and change original requirement to avoid having to load all sessions.
* TODO This may not scale when hosting millions of sessions.
*
* @return collection of client sessions authenticated with the server.
*/
Collection<ClientSession> getClientsRoutes();
/**
* Returns the outgoing server session associated to the specified XMPP address or <tt>null</tt>
* if none was found. When running inside of a cluster and a remote node is hosting
* the session then a session surrage will be returned.
*
* @param jid the address of the session.
* @return the outgoing server session associated to the specified XMPP address or null if none was found.
*/
OutgoingServerSession getServerRoute(JID jid);
/**
* Returns a collection with the hostnames of the remote servers that currently may receive
* packets sent from this server.
*
* @return a collection with the hostnames of the remote servers that currently may receive
* packets sent from this server.
*/
Collection<String> getServerHostnames();
/** /**
* Returns the list of routes associated to the specified route address. When asking * Returns the list of routes associated to the specified route address. When asking
* for routes to a remote server then the requested JID will be included as the only * for routes to a remote server then the requested JID will be included as the only
......
...@@ -13,7 +13,7 @@ package org.jivesoftware.openfire; ...@@ -13,7 +13,7 @@ package org.jivesoftware.openfire;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.openfire.multiplex.UnknownStanzaException; import org.jivesoftware.openfire.multiplex.UnknownStanzaException;
import org.jivesoftware.openfire.net.SASLAuthentication; import org.jivesoftware.openfire.net.SASLAuthentication;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.LocalClientSession;
import org.xmpp.packet.*; import org.xmpp.packet.*;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
...@@ -26,19 +26,13 @@ import java.io.UnsupportedEncodingException; ...@@ -26,19 +26,13 @@ import java.io.UnsupportedEncodingException;
*/ */
public class SessionPacketRouter implements PacketRouter { public class SessionPacketRouter implements PacketRouter {
private ClientSession session; private LocalClientSession session;
private PacketRouter router; private PacketRouter router;
private SessionManager sessionManager;
private boolean skipJIDValidation = false; private boolean skipJIDValidation = false;
public SessionPacketRouter() { public SessionPacketRouter(LocalClientSession session) {
this(null);
}
public SessionPacketRouter(ClientSession session) {
this.session = session; this.session = session;
router = XMPPServer.getInstance().getPacketRouter(); router = XMPPServer.getInstance().getPacketRouter();
sessionManager = SessionManager.getInstance();
} }
...@@ -100,36 +94,21 @@ public class SessionPacketRouter implements PacketRouter { ...@@ -100,36 +94,21 @@ public class SessionPacketRouter implements PacketRouter {
} }
public void route(IQ packet) { public void route(IQ packet) {
if(session == null) { router.route(packet);
session = sessionManager.getSession(packet.getFrom());
if(session == null) {
router.route(packet);
}
}
packet.setFrom(session.getAddress()); packet.setFrom(session.getAddress());
router.route(packet); router.route(packet);
session.incrementClientPacketCount(); session.incrementClientPacketCount();
} }
public void route(Message packet) { public void route(Message packet) {
if(session == null) { router.route(packet);
session = sessionManager.getSession(packet.getFrom());
if(session == null) {
router.route(packet);
}
}
packet.setFrom(session.getAddress()); packet.setFrom(session.getAddress());
router.route(packet); router.route(packet);
session.incrementClientPacketCount(); session.incrementClientPacketCount();
} }
public void route(Presence packet) { public void route(Presence packet) {
if(session == null) { router.route(packet);
session = sessionManager.getSession(packet.getFrom());
if(session == null) {
router.route(packet);
}
}
packet.setFrom(session.getAddress()); packet.setFrom(session.getAddress());
router.route(packet); router.route(packet);
session.incrementClientPacketCount(); session.incrementClientPacketCount();
......
...@@ -37,6 +37,7 @@ import org.jivesoftware.openfire.net.SSLConfig; ...@@ -37,6 +37,7 @@ import org.jivesoftware.openfire.net.SSLConfig;
import org.jivesoftware.openfire.net.ServerTrafficCounter; import org.jivesoftware.openfire.net.ServerTrafficCounter;
import org.jivesoftware.openfire.pubsub.PubSubModule; import org.jivesoftware.openfire.pubsub.PubSubModule;
import org.jivesoftware.openfire.roster.RosterManager; import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.RemoteSessionLocator;
import org.jivesoftware.openfire.spi.*; import org.jivesoftware.openfire.spi.*;
import org.jivesoftware.openfire.stun.STUNService; import org.jivesoftware.openfire.stun.STUNService;
import org.jivesoftware.openfire.transport.TransportHandler; import org.jivesoftware.openfire.transport.TransportHandler;
...@@ -119,6 +120,7 @@ public class XMPPServer { ...@@ -119,6 +120,7 @@ public class XMPPServer {
private PluginManager pluginManager; private PluginManager pluginManager;
private InternalComponentManager componentManager; private InternalComponentManager componentManager;
private RemoteSessionLocator remoteSessionLocator;
/** /**
* True if in setup mode * True if in setup mode
...@@ -1310,4 +1312,23 @@ public class XMPPServer { ...@@ -1310,4 +1312,23 @@ public class XMPPServer {
return (InternalComponentManager) modules.get(InternalComponentManager.class); return (InternalComponentManager) modules.get(InternalComponentManager.class);
} }
/**
* Returns the locator to use to find sessions hosted in other cluster nodes. When not running
* in a cluster a <tt>null</tt> value is returned.
*
* @return the locator to use to find sessions hosted in other cluster nodes.
*/
public RemoteSessionLocator getRemoteSessionLocator() {
return remoteSessionLocator;
}
/**
* Sets the locator to use to find sessions hosted in other cluster nodes. When not running
* in a cluster set a <tt>null</tt> value.
*
* @param remoteSessionLocator the locator to use to find sessions hosted in other cluster nodes.
*/
public void setRemoteSessionLocator(RemoteSessionLocator remoteSessionLocator) {
this.remoteSessionLocator = remoteSessionLocator;
}
} }
...@@ -117,7 +117,6 @@ public class MUCRoleImpl implements MUCRole { ...@@ -117,7 +117,6 @@ public class MUCRoleImpl implements MUCRole {
this.role = role; this.role = role;
this.affiliation = affiliation; this.affiliation = affiliation;
// Cache the user's session (will only work for local users) // Cache the user's session (will only work for local users)
//TODO Probably remove this instance variable that was added for optimization
this.session = XMPPServer.getInstance().getSessionManager().getSession(presence.getFrom()); this.session = XMPPServer.getInstance().getSessionManager().getSession(presence.getFrom());
extendedInformation = extendedInformation =
......
...@@ -18,7 +18,6 @@ import org.jivesoftware.openfire.session.ConnectionMultiplexerSession; ...@@ -18,7 +18,6 @@ import org.jivesoftware.openfire.session.ConnectionMultiplexerSession;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
/** /**
...@@ -92,17 +91,32 @@ public class ClientSessionConnection extends VirtualConnection { ...@@ -92,17 +91,32 @@ public class ClientSessionConnection extends VirtualConnection {
sb.append(text); sb.append(text);
sb.append("</route>"); sb.append("</route>");
// Deliver the wrapped stanza // Deliver the wrapped stanza
multiplexerSession.getConnection().deliverRawText(sb.toString()); multiplexerSession.deliverRawText(sb.toString());
} }
} }
public InetAddress getInetAddress() throws UnknownHostException { public byte[] getAddress() throws UnknownHostException {
return null;
}
public String getHostAddress() throws UnknownHostException {
//TODO Future version may return actual IP client address. We would need to pass this info
// Return IP address of the connection manager that the client used to log in
ConnectionMultiplexerSession multiplexerSession =
multiplexerManager.getMultiplexerSession(connectionManagerName);
if (multiplexerSession != null) {
return multiplexerSession.getHostAddress();
}
return null;
}
public String getHostName() throws UnknownHostException {
//TODO Future version may return actual IP client address. We would need to pass this info //TODO Future version may return actual IP client address. We would need to pass this info
// Return IP address of the connection manager that the client used to log in // Return IP address of the connection manager that the client used to log in
ConnectionMultiplexerSession multiplexerSession = ConnectionMultiplexerSession multiplexerSession =
multiplexerManager.getMultiplexerSession(connectionManagerName); multiplexerManager.getMultiplexerSession(connectionManagerName);
if (multiplexerSession != null) { if (multiplexerSession != null) {
return multiplexerSession.getConnection().getInetAddress(); return multiplexerSession.getHostName();
} }
return null; return null;
} }
......
...@@ -11,19 +11,19 @@ ...@@ -11,19 +11,19 @@
package org.jivesoftware.openfire.multiplex; package org.jivesoftware.openfire.multiplex;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.TaskEngine;
import org.jivesoftware.openfire.Connection; import org.jivesoftware.openfire.Connection;
import org.jivesoftware.openfire.SessionManager; import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.StreamID; import org.jivesoftware.openfire.StreamID;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.event.SessionEventDispatcher; import org.jivesoftware.openfire.event.SessionEventDispatcher;
import org.jivesoftware.openfire.event.SessionEventListener; import org.jivesoftware.openfire.event.SessionEventListener;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.ConnectionMultiplexerSession; import org.jivesoftware.openfire.session.ConnectionMultiplexerSession;
import org.jivesoftware.openfire.session.LocalClientSession;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.TaskEngine;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -60,8 +60,8 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -60,8 +60,8 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
* Map that keeps track of connection managers and hosted sessions. * Map that keeps track of connection managers and hosted sessions.
* Key: Domain of connection manager; Value: Map with Key: stream ID; Value: Client session * Key: Domain of connection manager; Value: Map with Key: stream ID; Value: Client session
*/ */
private Map<String, Map<String, ClientSession>> sessionsByManager = private Map<String, Map<String, LocalClientSession>> sessionsByManager =
new ConcurrentHashMap<String, Map<String, ClientSession>>(); new ConcurrentHashMap<String, Map<String, LocalClientSession>>();
private SessionManager sessionManager; private SessionManager sessionManager;
...@@ -103,10 +103,8 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -103,10 +103,8 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
TimerTask heartbeatTask = new TimerTask() { TimerTask heartbeatTask = new TimerTask() {
public void run() { public void run() {
try { try {
for (ConnectionMultiplexerSession session : sessionManager for (ConnectionMultiplexerSession session : sessionManager.getConnectionMultiplexerSessions()) {
.getConnectionMultiplexerSessions()) session.deliverRawText(" ");
{
session.getConnection().deliverRawText(" ");
} }
} }
catch(Exception e) { catch(Exception e) {
...@@ -114,8 +112,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -114,8 +112,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
} }
} }
}; };
TaskEngine.getInstance().schedule(heartbeatTask, 30*JiveConstants.SECOND, TaskEngine.getInstance().schedule(heartbeatTask, 30*JiveConstants.SECOND, 30*JiveConstants.SECOND);
30*JiveConstants.SECOND);
} }
/** /**
...@@ -129,17 +126,17 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -129,17 +126,17 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
public void createClientSession(String connectionManagerDomain, String streamID) { public void createClientSession(String connectionManagerDomain, String streamID) {
// TODO Consider that client session may return null when IP address is forbidden // TODO Consider that client session may return null when IP address is forbidden
Connection connection = new ClientSessionConnection(connectionManagerDomain); Connection connection = new ClientSessionConnection(connectionManagerDomain);
ClientSession session = SessionManager.getInstance() LocalClientSession session =
.createClientSession(connection, new BasicStreamID(streamID)); SessionManager.getInstance().createClientSession(connection, new BasicStreamID(streamID));
// Register that this streamID belongs to the specified connection manager // Register that this streamID belongs to the specified connection manager
streamIDs.put(streamID, connectionManagerDomain); streamIDs.put(streamID, connectionManagerDomain);
// Register which sessions are being hosted by the speicifed connection manager // Register which sessions are being hosted by the speicifed connection manager
Map<String, ClientSession> sessions = sessionsByManager.get(connectionManagerDomain); Map<String, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions == null) { if (sessions == null) {
synchronized (connectionManagerDomain.intern()) { synchronized (connectionManagerDomain.intern()) {
sessions = sessionsByManager.get(connectionManagerDomain); sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions == null) { if (sessions == null) {
sessions = new ConcurrentHashMap<String, ClientSession>(); sessions = new ConcurrentHashMap<String, LocalClientSession>();
sessionsByManager.put(connectionManagerDomain, sessions); sessionsByManager.put(connectionManagerDomain, sessions);
} }
} }
...@@ -155,12 +152,12 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -155,12 +152,12 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
* @param streamID the stream ID created by the connection manager for the session. * @param streamID the stream ID created by the connection manager for the session.
*/ */
public void closeClientSession(String connectionManagerDomain, String streamID) { public void closeClientSession(String connectionManagerDomain, String streamID) {
Map<String, ClientSession> sessions = sessionsByManager.get(connectionManagerDomain); Map<String, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions != null) { if (sessions != null) {
Session session = sessions.remove(streamID); Session session = sessions.remove(streamID);
if (session != null) { if (session != null) {
// Close the session // Close the session
session.getConnection().close(); session.close();
} }
} }
} }
...@@ -174,12 +171,12 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -174,12 +171,12 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
public void multiplexerAvailable(String connectionManagerName) { public void multiplexerAvailable(String connectionManagerName) {
// Add a new entry in the list of available managers. Here is where we are going to store // Add a new entry in the list of available managers. Here is where we are going to store
// which clients were connected through which connection manager // which clients were connected through which connection manager
Map<String, ClientSession> sessions = sessionsByManager.get(connectionManagerName); Map<String, LocalClientSession> sessions = sessionsByManager.get(connectionManagerName);
if (sessions == null) { if (sessions == null) {
synchronized (connectionManagerName.intern()) { synchronized (connectionManagerName.intern()) {
sessions = sessionsByManager.get(connectionManagerName); sessions = sessionsByManager.get(connectionManagerName);
if (sessions == null) { if (sessions == null) {
sessions = new ConcurrentHashMap<String, ClientSession>(); sessions = new ConcurrentHashMap<String, LocalClientSession>();
sessionsByManager.put(connectionManagerName, sessions); sessionsByManager.put(connectionManagerName, sessions);
} }
} }
...@@ -194,13 +191,13 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -194,13 +191,13 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
*/ */
public void multiplexerUnavailable(String connectionManagerName) { public void multiplexerUnavailable(String connectionManagerName) {
// Remove the connection manager and the hosted sessions // Remove the connection manager and the hosted sessions
Map<String, ClientSession> sessions = sessionsByManager.remove(connectionManagerName); Map<String, LocalClientSession> sessions = sessionsByManager.remove(connectionManagerName);
if (sessions != null) { if (sessions != null) {
for (String streamID : sessions.keySet()) { for (String streamID : sessions.keySet()) {
// Remove inverse track of connection manager hosting streamIDs // Remove inverse track of connection manager hosting streamIDs
streamIDs.remove(streamID); streamIDs.remove(streamID);
// Close the session // Close the session
sessions.get(streamID).getConnection().close(); sessions.get(streamID).close();
} }
} }
} }
...@@ -214,8 +211,8 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -214,8 +211,8 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
* @param streamID the stream ID created by the connection manager for the session. * @param streamID the stream ID created by the connection manager for the session.
* @return the ClientSession with the specified stream ID. * @return the ClientSession with the specified stream ID.
*/ */
public ClientSession getClientSession(String connectionManagerDomain, String streamID) { public LocalClientSession getClientSession(String connectionManagerDomain, String streamID) {
Map<String, ClientSession> sessions = sessionsByManager.get(connectionManagerDomain); Map<String, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions != null) { if (sessions != null) {
return sessions.get(streamID); return sessions.get(streamID);
} }
...@@ -261,7 +258,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -261,7 +258,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
* @return the number of connected clients to a specific connection manager. * @return the number of connected clients to a specific connection manager.
*/ */
public int getNumConnectedClients(String managerName) { public int getNumConnectedClients(String managerName) {
Map<String, ClientSession> clients = sessionsByManager.get(managerName); Map<String, LocalClientSession> clients = sessionsByManager.get(managerName);
if (clients == null) { if (clients == null) {
return 0; return 0;
} }
...@@ -292,7 +289,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -292,7 +289,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
String connectionManagerDomain = streamIDs.remove(streamID); String connectionManagerDomain = streamIDs.remove(streamID);
// Remove trace indicating that a connection manager is hosting a session // Remove trace indicating that a connection manager is hosting a session
if (connectionManagerDomain != null) { if (connectionManagerDomain != null) {
Map<String, ClientSession> sessions = sessionsByManager.get(connectionManagerDomain); Map<String, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions != null) { if (sessions != null) {
sessions.remove(streamID); sessions.remove(streamID);
} }
......
...@@ -12,14 +12,14 @@ ...@@ -12,14 +12,14 @@
package org.jivesoftware.openfire.multiplex; package org.jivesoftware.openfire.multiplex;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.OfflineMessageStrategy; import org.jivesoftware.openfire.OfflineMessageStrategy;
import org.jivesoftware.openfire.PacketDeliverer; import org.jivesoftware.openfire.PacketDeliverer;
import org.jivesoftware.openfire.PacketException; import org.jivesoftware.openfire.PacketException;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.ConnectionMultiplexerSession; import org.jivesoftware.openfire.session.ConnectionMultiplexerSession;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
...@@ -63,7 +63,7 @@ public class MultiplexerPacketDeliverer implements PacketDeliverer { ...@@ -63,7 +63,7 @@ public class MultiplexerPacketDeliverer implements PacketDeliverer {
// Try getting another session to the same connection manager // Try getting another session to the same connection manager
ConnectionMultiplexerSession session = ConnectionMultiplexerSession session =
multiplexerManager.getMultiplexerSession(connectionManagerDomain); multiplexerManager.getMultiplexerSession(connectionManagerDomain);
if (session == null || session.getConnection().isClosed()) { if (session == null || session.isClosed()) {
// No other session was found so handle unprocessed packet // No other session was found so handle unprocessed packet
handleUnprocessedPacket(packet); handleUnprocessedPacket(packet);
} }
......
...@@ -14,11 +14,12 @@ package org.jivesoftware.openfire.multiplex; ...@@ -14,11 +14,12 @@ package org.jivesoftware.openfire.multiplex;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.QName; import org.dom4j.QName;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.SessionPacketRouter; import org.jivesoftware.openfire.SessionPacketRouter;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.ConnectionMultiplexerSession; import org.jivesoftware.openfire.session.ConnectionMultiplexerSession;
import org.jivesoftware.openfire.session.LocalClientSession;
import org.jivesoftware.util.Log;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
...@@ -149,8 +150,7 @@ public class MultiplexerPacketHandler { ...@@ -149,8 +150,7 @@ public class MultiplexerPacketHandler {
"id-required", "http://jabber.org/protocol/connectionmanager#errors")); "id-required", "http://jabber.org/protocol/connectionmanager#errors"));
sendErrorPacket(route, PacketError.Condition.bad_request, extraError); sendErrorPacket(route, PacketError.Condition.bad_request, extraError);
} }
ClientSession session = multiplexerManager LocalClientSession session = multiplexerManager.getClientSession(connectionManagerDomain, streamID);
.getClientSession(connectionManagerDomain, streamID);
if (session == null) { if (session == null) {
// Specified Client Session does not exist // Specified Client Session does not exist
sendErrorPacket(route, PacketError.Condition.item_not_found, null); sendErrorPacket(route, PacketError.Condition.item_not_found, null);
......
...@@ -91,7 +91,7 @@ class BlockingReadingMode extends SocketReadingMode { ...@@ -91,7 +91,7 @@ class BlockingReadingMode extends SocketReadingMode {
Log.debug("Logging off " + socketReader.session.getAddress() + " on " + socketReader.connection); Log.debug("Logging off " + socketReader.session.getAddress() + " on " + socketReader.connection);
} }
try { try {
socketReader.session.getConnection().close(); socketReader.session.close();
} }
catch (Exception e) { catch (Exception e) {
Log.warn(LocaleUtils.getLocalizedString("admin.error.connection") Log.warn(LocaleUtils.getLocalizedString("admin.error.connection")
......
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
package org.jivesoftware.openfire.net; package org.jivesoftware.openfire.net;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.openfire.Connection; import org.jivesoftware.openfire.Connection;
import org.jivesoftware.openfire.PacketRouter; import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.LocalClientSession;
import org.jivesoftware.util.JiveGlobals;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
...@@ -67,7 +67,7 @@ public class ClientStanzaHandler extends StanzaHandler { ...@@ -67,7 +67,7 @@ public class ClientStanzaHandler extends StanzaHandler {
throws XmlPullParserException { throws XmlPullParserException {
if ("jabber:client".equals(namespace)) { if ("jabber:client".equals(namespace)) {
// The connected client is a regular client so create a ClientSession // The connected client is a regular client so create a ClientSession
session = ClientSession.createSession(serverName, xpp, connection); session = LocalClientSession.createSession(serverName, xpp, connection);
return true; return true;
} }
return false; return false;
......
...@@ -12,12 +12,13 @@ ...@@ -12,12 +12,13 @@
package org.jivesoftware.openfire.net; package org.jivesoftware.openfire.net;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.PacketRouter; import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.RoutingTable; import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.component.InternalComponentManager; import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.session.ComponentSession; import org.jivesoftware.openfire.session.ComponentSession;
import org.jivesoftware.openfire.session.LocalComponentSession;
import org.jivesoftware.util.Log;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.component.ComponentException; import org.xmpp.component.ComponentException;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
...@@ -49,7 +50,7 @@ public class ComponentSocketReader extends SocketReader { ...@@ -49,7 +50,7 @@ public class ComponentSocketReader extends SocketReader {
protected boolean processUnknowPacket(Element doc) { protected boolean processUnknowPacket(Element doc) {
// Handle subsequent bind packets // Handle subsequent bind packets
if ("bind".equals(doc.getName())) { if ("bind".equals(doc.getName())) {
ComponentSession componentSession = (ComponentSession) session; LocalComponentSession componentSession = (LocalComponentSession) session;
// Get the external component of this session // Get the external component of this session
ComponentSession.ExternalComponent component = componentSession.getExternalComponent(); ComponentSession.ExternalComponent component = componentSession.getExternalComponent();
String initialDomain = component.getInitialSubdomain(); String initialDomain = component.getInitialSubdomain();
...@@ -113,7 +114,7 @@ public class ComponentSocketReader extends SocketReader { ...@@ -113,7 +114,7 @@ public class ComponentSocketReader extends SocketReader {
IOException { IOException {
if ("jabber:component:accept".equals(namespace)) { if ("jabber:component:accept".equals(namespace)) {
// The connected client is a component so create a ComponentSession // The connected client is a component so create a ComponentSession
session = ComponentSession.createSession(serverName, reader, connection); session = LocalComponentSession.createSession(serverName, reader, connection);
return true; return true;
} }
return false; return false;
......
...@@ -16,7 +16,7 @@ import org.jivesoftware.openfire.PacketRouter; ...@@ -16,7 +16,7 @@ import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.multiplex.MultiplexerPacketHandler; import org.jivesoftware.openfire.multiplex.MultiplexerPacketHandler;
import org.jivesoftware.openfire.multiplex.Route; import org.jivesoftware.openfire.multiplex.Route;
import org.jivesoftware.openfire.session.ConnectionMultiplexerSession; import org.jivesoftware.openfire.session.LocalConnectionMultiplexerSession;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
...@@ -95,15 +95,13 @@ public class MultiplexerStanzaHandler extends StanzaHandler { ...@@ -95,15 +95,13 @@ public class MultiplexerStanzaHandler extends StanzaHandler {
// Process stanza wrapped by the route packet // Process stanza wrapped by the route packet
processRoute(new Route(doc)); processRoute(new Route(doc));
return true; return true;
} } else if ("handshake".equals(tag)) {
else if ("handshake".equals(tag)) { if (!((LocalConnectionMultiplexerSession) session).authenticate(doc.getStringValue())) {
if (!((ConnectionMultiplexerSession)session).authenticate(doc.getStringValue())) { session.close();
session.getConnection().close();
} }
return true; return true;
} } else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) {
else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) { session.close();
session.getConnection().close();
return true; return true;
} }
return false; return false;
...@@ -125,7 +123,7 @@ public class MultiplexerStanzaHandler extends StanzaHandler { ...@@ -125,7 +123,7 @@ public class MultiplexerStanzaHandler extends StanzaHandler {
throws XmlPullParserException { throws XmlPullParserException {
if (getNamespace().equals(namespace)) { if (getNamespace().equals(namespace)) {
// The connected client is a connection manager so create a ConnectionMultiplexerSession // The connected client is a connection manager so create a ConnectionMultiplexerSession
session = ConnectionMultiplexerSession.createSession(serverName, xpp, connection); session = LocalConnectionMultiplexerSession.createSession(serverName, xpp, connection);
if (session != null) { if (session != null) {
packetHandler = new MultiplexerPacketHandler(session.getAddress().getDomain()); packetHandler = new MultiplexerPacketHandler(session.getAddress().getDomain());
} }
......
...@@ -15,17 +15,15 @@ import org.dom4j.DocumentHelper; ...@@ -15,17 +15,15 @@ import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.Namespace; import org.dom4j.Namespace;
import org.dom4j.QName; import org.dom4j.QName;
import org.jivesoftware.util.CertificateManager;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.AuthFactory; import org.jivesoftware.openfire.auth.AuthFactory;
import org.jivesoftware.openfire.auth.AuthToken; import org.jivesoftware.openfire.auth.AuthToken;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.*;
import org.jivesoftware.openfire.session.IncomingServerSession; import org.jivesoftware.util.CertificateManager;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLPeerUnverifiedException;
...@@ -127,7 +125,7 @@ public class SASLAuthentication { ...@@ -127,7 +125,7 @@ public class SASLAuthentication {
sb.append("<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"); sb.append("<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
if (session instanceof IncomingServerSession) { if (session instanceof IncomingServerSession) {
// Server connections dont follow the same rules as clients // Server connections dont follow the same rules as clients
if (session.getConnection().isSecure()) { if (session.isSecure()) {
// Offer SASL EXTERNAL only if TLS has already been negotiated // Offer SASL EXTERNAL only if TLS has already been negotiated
sb.append("<mechanism>EXTERNAL</mechanism>"); sb.append("<mechanism>EXTERNAL</mechanism>");
} }
...@@ -152,7 +150,7 @@ public class SASLAuthentication { ...@@ -152,7 +150,7 @@ public class SASLAuthentication {
new Namespace("", "urn:ietf:params:xml:ns:xmpp-sasl"))); new Namespace("", "urn:ietf:params:xml:ns:xmpp-sasl")));
if (session instanceof IncomingServerSession) { if (session instanceof IncomingServerSession) {
// Server connections dont follow the same rules as clients // Server connections dont follow the same rules as clients
if (session.getConnection().isSecure()) { if (session.isSecure()) {
// Offer SASL EXTERNAL only if TLS has already been negotiated // Offer SASL EXTERNAL only if TLS has already been negotiated
Element mechanism = mechs.addElement("mechanism"); Element mechanism = mechs.addElement("mechanism");
mechanism.setText("EXTERNAL"); mechanism.setText("EXTERNAL");
...@@ -179,7 +177,7 @@ public class SASLAuthentication { ...@@ -179,7 +177,7 @@ public class SASLAuthentication {
* or not or if the entity is expected to send a response to a challenge. * or not or if the entity is expected to send a response to a challenge.
* @throws UnsupportedEncodingException If UTF-8 charset is not supported. * @throws UnsupportedEncodingException If UTF-8 charset is not supported.
*/ */
public static Status handle(Session session, Element doc) throws UnsupportedEncodingException { public static Status handle(LocalSession session, Element doc) throws UnsupportedEncodingException {
Status status; Status status;
String mechanism; String mechanism;
if (doc.getNamespace().asXML().equals(SASL_NAMESPACE)) { if (doc.getNamespace().asXML().equals(SASL_NAMESPACE)) {
...@@ -386,7 +384,7 @@ public class SASLAuthentication { ...@@ -386,7 +384,7 @@ public class SASLAuthentication {
} }
private static Status doAnonymousAuthentication(Session session) { private static Status doAnonymousAuthentication(LocalSession session) {
if (XMPPServer.getInstance().getIQAuthHandler().isAnonymousAllowed()) { if (XMPPServer.getInstance().getIQAuthHandler().isAnonymousAllowed()) {
// Just accept the authentication :) // Just accept the authentication :)
authenticationSuccessful(session, null, null); authenticationSuccessful(session, null, null);
...@@ -399,7 +397,7 @@ public class SASLAuthentication { ...@@ -399,7 +397,7 @@ public class SASLAuthentication {
} }
} }
private static Status doPlainAuthentication(Session session, Element doc) private static Status doPlainAuthentication(LocalSession session, Element doc)
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
String username; String username;
String password; String password;
...@@ -444,7 +442,7 @@ public class SASLAuthentication { ...@@ -444,7 +442,7 @@ public class SASLAuthentication {
} }
} }
private static Status doExternalAuthentication(Session session, Element doc) private static Status doExternalAuthentication(LocalSession session, Element doc)
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
// Only accept EXTERNAL SASL for s2s. At this point the connection has already // Only accept EXTERNAL SASL for s2s. At this point the connection has already
// been secured using TLS // been secured using TLS
...@@ -486,7 +484,7 @@ public class SASLAuthentication { ...@@ -486,7 +484,7 @@ public class SASLAuthentication {
return Status.failed; return Status.failed;
} }
private static Status doSharedSecretAuthentication(Session session, Element doc) private static Status doSharedSecretAuthentication(LocalSession session, Element doc)
throws UnsupportedEncodingException throws UnsupportedEncodingException
{ {
String secretDigest; String secretDigest;
...@@ -524,10 +522,10 @@ public class SASLAuthentication { ...@@ -524,10 +522,10 @@ public class SASLAuthentication {
"<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"); "<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
reply.append(challenge_b64); reply.append(challenge_b64);
reply.append("</challenge>"); reply.append("</challenge>");
session.getConnection().deliverRawText(reply.toString()); session.deliverRawText(reply.toString());
} }
private static void authenticationSuccessful(Session session, String username, private static void authenticationSuccessful(LocalSession session, String username,
byte[] successData) { byte[] successData) {
StringBuilder reply = new StringBuilder(80); StringBuilder reply = new StringBuilder(80);
reply.append("<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\""); reply.append("<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"");
...@@ -538,10 +536,10 @@ public class SASLAuthentication { ...@@ -538,10 +536,10 @@ public class SASLAuthentication {
else { else {
reply.append("/>"); reply.append("/>");
} }
session.getConnection().deliverRawText(reply.toString()); session.deliverRawText(reply.toString());
// We only support SASL for c2s // We only support SASL for c2s
if (session instanceof ClientSession) { if (session instanceof ClientSession) {
((ClientSession) session).setAuthToken(new AuthToken(username)); ((LocalClientSession) session).setAuthToken(new AuthToken(username));
} }
else if (session instanceof IncomingServerSession) { else if (session instanceof IncomingServerSession) {
String hostname = username; String hostname = username;
...@@ -549,15 +547,15 @@ public class SASLAuthentication { ...@@ -549,15 +547,15 @@ public class SASLAuthentication {
session.setAddress(new JID(null, hostname, null)); session.setAddress(new JID(null, hostname, null));
// Add the validated domain as a valid domain. The remote server can // Add the validated domain as a valid domain. The remote server can
// now send packets from this address // now send packets from this address
((IncomingServerSession) session).addValidatedDomain(hostname); ((LocalIncomingServerSession) session).addValidatedDomain(hostname);
} }
} }
private static void authenticationFailed(Session session) { private static void authenticationFailed(LocalSession session) {
StringBuilder reply = new StringBuilder(80); StringBuilder reply = new StringBuilder(80);
reply.append("<failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"); reply.append("<failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
reply.append("<not-authorized/></failure>"); reply.append("<not-authorized/></failure>");
session.getConnection().deliverRawText(reply.toString()); session.deliverRawText(reply.toString());
// Give a number of retries before closing the connection // Give a number of retries before closing the connection
Integer retries = (Integer) session.getSessionData("authRetries"); Integer retries = (Integer) session.getSessionData("authRetries");
if (retries == null) { if (retries == null) {
...@@ -569,7 +567,7 @@ public class SASLAuthentication { ...@@ -569,7 +567,7 @@ public class SASLAuthentication {
session.setSessionData("authRetries", retries); session.setSessionData("authRetries", retries);
if (retries >= JiveGlobals.getIntProperty("xmpp.auth.retries", 3) ) { if (retries >= JiveGlobals.getIntProperty("xmpp.auth.retries", 3) ) {
// Close the connection // Close the connection
session.getConnection().close(); session.close();
} }
} }
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
package org.jivesoftware.openfire.net; package org.jivesoftware.openfire.net;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.PacketRouter; import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.RoutingTable; import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.interceptor.PacketRejectedException; import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.session.IncomingServerSession; import org.jivesoftware.openfire.session.LocalIncomingServerSession;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.*; import org.xmpp.packet.*;
...@@ -149,7 +149,7 @@ public class ServerSocketReader extends SocketReader { ...@@ -149,7 +149,7 @@ public class ServerSocketReader extends SocketReader {
protected boolean processUnknowPacket(Element doc) { protected boolean processUnknowPacket(Element doc) {
// Handle subsequent db:result packets // Handle subsequent db:result packets
if ("db".equals(doc.getNamespacePrefix()) && "result".equals(doc.getName())) { if ("db".equals(doc.getNamespacePrefix()) && "result".equals(doc.getName())) {
if (!((IncomingServerSession) session).validateSubsequentDomain(doc)) { if (!((LocalIncomingServerSession) session).validateSubsequentDomain(doc)) {
open = false; open = false;
} }
return true; return true;
...@@ -157,7 +157,7 @@ public class ServerSocketReader extends SocketReader { ...@@ -157,7 +157,7 @@ public class ServerSocketReader extends SocketReader {
else if ("db".equals(doc.getNamespacePrefix()) && "verify".equals(doc.getName())) { else if ("db".equals(doc.getNamespacePrefix()) && "verify".equals(doc.getName())) {
// The Receiving Server is reusing an existing connection for sending the // The Receiving Server is reusing an existing connection for sending the
// Authoritative Server a request for verification of a key // Authoritative Server a request for verification of a key
((IncomingServerSession) session).verifyReceivedKey(doc); ((LocalIncomingServerSession) session).verifyReceivedKey(doc);
return true; return true;
} }
return false; return false;
...@@ -184,7 +184,7 @@ public class ServerSocketReader extends SocketReader { ...@@ -184,7 +184,7 @@ public class ServerSocketReader extends SocketReader {
open = false; open = false;
throw new PacketRejectedException("Packet with no TO or FROM attributes"); throw new PacketRejectedException("Packet with no TO or FROM attributes");
} }
else if (!((IncomingServerSession) session).isValidDomain(packet.getFrom().getDomain())) { else if (!((LocalIncomingServerSession) session).isValidDomain(packet.getFrom().getDomain())) {
Log.debug("Closing IncomingServerSession due to packet with invalid domain: " + Log.debug("Closing IncomingServerSession due to packet with invalid domain: " +
packet.toXML()); packet.toXML());
// Send a stream error saying that the packet includes an invalid FROM // Send a stream error saying that the packet includes an invalid FROM
...@@ -208,7 +208,7 @@ public class ServerSocketReader extends SocketReader { ...@@ -208,7 +208,7 @@ public class ServerSocketReader extends SocketReader {
IOException { IOException {
if ("jabber:server".equals(namespace)) { if ("jabber:server".equals(namespace)) {
// The connected client is a server so create an IncomingServerSession // The connected client is a server so create an IncomingServerSession
session = IncomingServerSession.createSession(serverName, reader, connection); session = LocalIncomingServerSession.createSession(serverName, reader, connection);
return true; return true;
} }
return false; return false;
......
...@@ -19,6 +19,7 @@ import org.jivesoftware.openfire.PacketDeliverer; ...@@ -19,6 +19,7 @@ import org.jivesoftware.openfire.PacketDeliverer;
import org.jivesoftware.openfire.PacketException; import org.jivesoftware.openfire.PacketException;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.IncomingServerSession; import org.jivesoftware.openfire.session.IncomingServerSession;
import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
...@@ -30,8 +31,8 @@ import java.io.BufferedWriter; ...@@ -30,8 +31,8 @@ import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
...@@ -83,7 +84,7 @@ public class SocketConnection implements Connection { ...@@ -83,7 +84,7 @@ public class SocketConnection implements Connection {
*/ */
private PacketDeliverer backupDeliverer; private PacketDeliverer backupDeliverer;
private Session session; private LocalSession session;
private boolean secure; private boolean secure;
private boolean compressed; private boolean compressed;
private org.jivesoftware.util.XMLWriter xmlSerializer; private org.jivesoftware.util.XMLWriter xmlSerializer;
...@@ -224,7 +225,7 @@ public class SocketConnection implements Connection { ...@@ -224,7 +225,7 @@ public class SocketConnection implements Connection {
return !isClosed(); return !isClosed();
} }
public void init(Session owner) { public void init(LocalSession owner) {
session = owner; session = owner;
} }
...@@ -241,8 +242,16 @@ public class SocketConnection implements Connection { ...@@ -241,8 +242,16 @@ public class SocketConnection implements Connection {
listeners.remove(listener); listeners.remove(listener);
} }
public InetAddress getInetAddress() { public byte[] getAddress() throws UnknownHostException {
return socket.getInetAddress(); return socket.getInetAddress().getAddress();
}
public String getHostAddress() throws UnknownHostException {
return socket.getInetAddress().getHostAddress();
}
public String getHostName() throws UnknownHostException {
return socket.getInetAddress().getHostName();
} }
/** /**
......
...@@ -13,13 +13,10 @@ package org.jivesoftware.openfire.net; ...@@ -13,13 +13,10 @@ package org.jivesoftware.openfire.net;
import org.jivesoftware.openfire.*; import org.jivesoftware.openfire.*;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
/** /**
* This ChannelHandler writes packet data to connections. * This ChannelHandler writes packet data to connections.
...@@ -30,22 +27,11 @@ import org.xmpp.packet.Presence; ...@@ -30,22 +27,11 @@ import org.xmpp.packet.Presence;
public class SocketPacketWriteHandler implements ChannelHandler { public class SocketPacketWriteHandler implements ChannelHandler {
private XMPPServer server; private XMPPServer server;
private SessionManager sessionManager;
private OfflineMessageStrategy messageStrategy;
private RoutingTable routingTable; private RoutingTable routingTable;
private IQRouter iqRouter;
private MessageRouter messageRouter;
private PresenceRouter presenceRouter;
public SocketPacketWriteHandler(SessionManager sessionManager, RoutingTable routingTable, public SocketPacketWriteHandler(RoutingTable routingTable) {
OfflineMessageStrategy messageStrategy) {
this.sessionManager = sessionManager;
this.messageStrategy = messageStrategy;
this.routingTable = routingTable; this.routingTable = routingTable;
this.server = XMPPServer.getInstance(); this.server = XMPPServer.getInstance();
iqRouter = server.getIQRouter();
messageRouter = server.getMessageRouter();
presenceRouter = server.getPresenceRouter();
} }
public void process(Packet packet) throws UnauthorizedException, PacketException { public void process(Packet packet) throws UnauthorizedException, PacketException {
...@@ -61,34 +47,11 @@ public class SocketPacketWriteHandler implements ChannelHandler { ...@@ -61,34 +47,11 @@ public class SocketPacketWriteHandler implements ChannelHandler {
routingTable.routePacket(packet.getFrom(), packet); routingTable.routePacket(packet.getFrom(), packet);
} }
else { else {
Session session = sessionManager.getBestRoute(recipient); routingTable.routePacket(recipient, packet);
if (session == null) {
handleUnprocessedPacket(packet);
}
else {
try {
session.process(packet);
}
catch (Exception e) {
// do nothing
}
}
} }
} }
catch (Exception e) { catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("admin.error.deliver") + "\n" + packet.toString(), e); Log.error(LocaleUtils.getLocalizedString("admin.error.deliver") + "\n" + packet.toString(), e);
} }
} }
private void handleUnprocessedPacket(Packet packet) {
if (packet instanceof Message) {
messageRouter.routingFailed(packet);
}
else if (packet instanceof Presence) {
presenceRouter.routingFailed(packet);
}
else {
iqRouter.routingFailed(packet);
}
}
} }
...@@ -17,6 +17,7 @@ import org.jivesoftware.openfire.Connection; ...@@ -17,6 +17,7 @@ import org.jivesoftware.openfire.Connection;
import org.jivesoftware.openfire.PacketRouter; import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.RoutingTable; import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
...@@ -49,7 +50,7 @@ public abstract class SocketReader implements Runnable { ...@@ -49,7 +50,7 @@ public abstract class SocketReader implements Runnable {
/** /**
* Session associated with the socket reader. * Session associated with the socket reader.
*/ */
protected Session session; protected LocalSession session;
/** /**
* Reference to the physical connection. * Reference to the physical connection.
*/ */
......
...@@ -15,6 +15,7 @@ import org.dom4j.io.XMPPPacketReader; ...@@ -15,6 +15,7 @@ import org.dom4j.io.XMPPPacketReader;
import org.jivesoftware.openfire.Connection; import org.jivesoftware.openfire.Connection;
import org.jivesoftware.openfire.PacketRouter; import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
...@@ -59,7 +60,7 @@ public abstract class StanzaHandler { ...@@ -59,7 +60,7 @@ public abstract class StanzaHandler {
/** /**
* Session associated with the socket reader. * Session associated with the socket reader.
*/ */
protected Session session; protected LocalSession session;
/** /**
* Server name for which we are attending clients. * Server name for which we are attending clients.
*/ */
...@@ -112,7 +113,7 @@ public abstract class StanzaHandler { ...@@ -112,7 +113,7 @@ public abstract class StanzaHandler {
// Verify if end of stream was requested // Verify if end of stream was requested
if (stanza.equals("</stream:stream>")) { if (stanza.equals("</stream:stream>")) {
session.getConnection().close(); session.close();
return; return;
} }
// Ignore <?xml version="1.0"?> stanzas sent by clients // Ignore <?xml version="1.0"?> stanzas sent by clients
...@@ -258,7 +259,7 @@ public abstract class StanzaHandler { ...@@ -258,7 +259,7 @@ public abstract class StanzaHandler {
if (!processUnknowPacket(doc)) { if (!processUnknowPacket(doc)) {
Log.warn(LocaleUtils.getLocalizedString("admin.error.packet.tag") + Log.warn(LocaleUtils.getLocalizedString("admin.error.packet.tag") +
doc.asXML()); doc.asXML());
session.getConnection().close(); session.close();
} }
} }
} }
......
...@@ -14,6 +14,7 @@ package org.jivesoftware.openfire.net; ...@@ -14,6 +14,7 @@ package org.jivesoftware.openfire.net;
import org.jivesoftware.openfire.Connection; import org.jivesoftware.openfire.Connection;
import org.jivesoftware.openfire.ConnectionCloseListener; import org.jivesoftware.openfire.ConnectionCloseListener;
import org.jivesoftware.openfire.PacketDeliverer; import org.jivesoftware.openfire.PacketDeliverer;
import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
...@@ -33,7 +34,7 @@ import java.util.Map; ...@@ -33,7 +34,7 @@ import java.util.Map;
*/ */
public abstract class VirtualConnection implements Connection { public abstract class VirtualConnection implements Connection {
protected Session session; protected LocalSession session;
final private Map<ConnectionCloseListener, Object> listeners = final private Map<ConnectionCloseListener, Object> listeners =
new HashMap<ConnectionCloseListener, Object>(); new HashMap<ConnectionCloseListener, Object>();
...@@ -129,7 +130,7 @@ public abstract class VirtualConnection implements Connection { ...@@ -129,7 +130,7 @@ public abstract class VirtualConnection implements Connection {
return true; return true;
} }
public void init(Session session) { public void init(LocalSession session) {
this.session = session; this.session = session;
} }
......
...@@ -24,6 +24,7 @@ import org.jivesoftware.openfire.net.SSLConfig; ...@@ -24,6 +24,7 @@ import org.jivesoftware.openfire.net.SSLConfig;
import org.jivesoftware.openfire.net.SSLJiveKeyManagerFactory; import org.jivesoftware.openfire.net.SSLJiveKeyManagerFactory;
import org.jivesoftware.openfire.net.SSLJiveTrustManagerFactory; import org.jivesoftware.openfire.net.SSLJiveTrustManagerFactory;
import org.jivesoftware.openfire.net.ServerTrustManager; import org.jivesoftware.openfire.net.ServerTrustManager;
import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
...@@ -33,7 +34,6 @@ import org.xmpp.packet.Packet; ...@@ -33,7 +34,6 @@ import org.xmpp.packet.Packet;
import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManager;
import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
...@@ -55,7 +55,7 @@ public class NIOConnection implements Connection { ...@@ -55,7 +55,7 @@ public class NIOConnection implements Connection {
*/ */
public static final String CHARSET = "UTF-8"; public static final String CHARSET = "UTF-8";
private Session session; private LocalSession session;
private IoSession ioSession; private IoSession ioSession;
private ConnectionCloseListener closeListener; private ConnectionCloseListener closeListener;
...@@ -123,8 +123,16 @@ public class NIOConnection implements Connection { ...@@ -123,8 +123,16 @@ public class NIOConnection implements Connection {
} }
} }
public InetAddress getInetAddress() throws UnknownHostException { public byte[] getAddress() throws UnknownHostException {
return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress(); return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress().getAddress();
}
public String getHostAddress() throws UnknownHostException {
return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress().getHostAddress();
}
public String getHostName() throws UnknownHostException {
return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress().getHostName();
} }
public PacketDeliverer getPacketDeliverer() { public PacketDeliverer getPacketDeliverer() {
...@@ -173,7 +181,7 @@ public class NIOConnection implements Connection { ...@@ -173,7 +181,7 @@ public class NIOConnection implements Connection {
} }
} }
public void init(Session owner) { public void init(LocalSession owner) {
session = owner; session = owner;
} }
......
...@@ -13,7 +13,6 @@ package org.jivesoftware.openfire.roster; ...@@ -13,7 +13,6 @@ package org.jivesoftware.openfire.roster;
import org.jivesoftware.database.JiveID; import org.jivesoftware.database.JiveID;
import org.jivesoftware.openfire.*; import org.jivesoftware.openfire.*;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.group.Group; import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager; import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.privacy.PrivacyList; import org.jivesoftware.openfire.privacy.PrivacyList;
...@@ -656,12 +655,7 @@ public class Roster implements Cacheable, Externalizable { ...@@ -656,12 +655,7 @@ public class Roster implements Cacheable, Externalizable {
if (sessionManager == null) { if (sessionManager == null) {
sessionManager = SessionManager.getInstance(); sessionManager = SessionManager.getInstance();
} }
try { sessionManager.userBroadcast(username, roster);
sessionManager.userBroadcast(username, roster);
}
catch (UnauthorizedException e) {
// Do nothing. We should never end here.
}
} }
/** /**
......
...@@ -14,7 +14,6 @@ package org.jivesoftware.openfire.roster; ...@@ -14,7 +14,6 @@ package org.jivesoftware.openfire.roster;
import org.jivesoftware.openfire.RoutingTable; import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.SharedGroupException; import org.jivesoftware.openfire.SharedGroupException;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.container.BasicModule; import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.event.GroupEventDispatcher; import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.event.GroupEventListener; import org.jivesoftware.openfire.event.GroupEventListener;
...@@ -717,12 +716,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us ...@@ -717,12 +716,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
else { else {
presence.setType(Presence.Type.unsubscribe); presence.setType(Presence.Type.unsubscribe);
} }
try { routingTable.routePacket(recipient, presence);
routingTable.routePacket(recipient, presence);
}
catch (UnauthorizedException e) {
// Do nothing
}
} }
private Collection<Group> getVisibleGroups(Group groupToCheck) { private Collection<Group> getVisibleGroups(Group groupToCheck) {
......
...@@ -13,8 +13,8 @@ package org.jivesoftware.openfire.server; ...@@ -13,8 +13,8 @@ package org.jivesoftware.openfire.server;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.io.XMPPPacketReader; import org.dom4j.io.XMPPPacketReader;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.session.OutgoingServerSession; import org.jivesoftware.openfire.session.OutgoingServerSession;
import org.jivesoftware.util.Log;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
...@@ -132,7 +132,7 @@ public class OutgoingServerSocketReader { ...@@ -132,7 +132,7 @@ public class OutgoingServerSocketReader {
private void closeSession() { private void closeSession() {
open = false; open = false;
if (session != null) { if (session != null) {
session.getConnection().close(); session.close();
} }
} }
} }
...@@ -14,8 +14,7 @@ package org.jivesoftware.openfire.server; ...@@ -14,8 +14,7 @@ package org.jivesoftware.openfire.server;
import org.jivesoftware.openfire.RoutableChannelHandler; import org.jivesoftware.openfire.RoutableChannelHandler;
import org.jivesoftware.openfire.RoutingTable; import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.session.LocalOutgoingServerSession;
import org.jivesoftware.openfire.session.OutgoingServerSession;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmpp.packet.*; import org.xmpp.packet.*;
...@@ -116,6 +115,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler { ...@@ -116,6 +115,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler {
} }
} }
catch (InterruptedException e) { catch (InterruptedException e) {
// Do nothing
} }
catch (Exception e) { catch (Exception e) {
Log.error(e); Log.error(e);
...@@ -195,7 +195,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler { ...@@ -195,7 +195,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler {
private void sendPacket(Packet packet) throws Exception { private void sendPacket(Packet packet) throws Exception {
// Create a connection to the remote server from the domain where the packet has been sent // Create a connection to the remote server from the domain where the packet has been sent
boolean created = OutgoingServerSession boolean created = LocalOutgoingServerSession
.authenticateDomain(packet.getFrom().getDomain(), packet.getTo().getDomain()); .authenticateDomain(packet.getFrom().getDomain(), packet.getTo().getDomain());
if (created) { if (created) {
// A connection to the remote server was created so get the route and send the packet // A connection to the remote server was created so get the route and send the packet
...@@ -222,7 +222,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler { ...@@ -222,7 +222,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler {
try { try {
if (packet instanceof IQ) { if (packet instanceof IQ) {
IQ reply = new IQ(); IQ reply = new IQ();
reply.setID(((IQ) packet).getID()); reply.setID(packet.getID());
reply.setTo(from); reply.setTo(from);
reply.setFrom(to); reply.setFrom(to);
reply.setChildElement(((IQ) packet).getChildElement().createCopy()); reply.setChildElement(((IQ) packet).getChildElement().createCopy());
...@@ -248,8 +248,6 @@ public class OutgoingSessionPromise implements RoutableChannelHandler { ...@@ -248,8 +248,6 @@ public class OutgoingSessionPromise implements RoutableChannelHandler {
routingTable.routePacket(reply.getTo(), reply); routingTable.routePacket(reply.getTo(), reply);
} }
} }
catch (UnauthorizedException e) {
}
catch (Exception e) { catch (Exception e) {
Log.warn("Error returning error to sender. Original packet: " + packet, e); Log.warn("Error returning error to sender. Original packet: " + packet, e);
} }
......
...@@ -11,12 +11,12 @@ ...@@ -11,12 +11,12 @@
package org.jivesoftware.openfire.server; package org.jivesoftware.openfire.server;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.ConnectionManager; import org.jivesoftware.openfire.ConnectionManager;
import org.jivesoftware.openfire.SessionManager; import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.server.RemoteServerConfiguration.Permission; import org.jivesoftware.openfire.server.RemoteServerConfiguration.Permission;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -70,11 +70,11 @@ public class RemoteServerManager { ...@@ -70,11 +70,11 @@ public class RemoteServerManager {
addConfiguration(config); addConfiguration(config);
// Check if the remote server was connected and proceed to close the connection // Check if the remote server was connected and proceed to close the connection
for (Session session : SessionManager.getInstance().getIncomingServerSessions(domain)) { for (Session session : SessionManager.getInstance().getIncomingServerSessions(domain)) {
session.getConnection().close(); session.close();
} }
Session session = SessionManager.getInstance().getOutgoingServerSession(domain); Session session = SessionManager.getInstance().getOutgoingServerSession(domain);
if (session != null) { if (session != null) {
session.getConnection().close(); session.close();
} }
} }
...@@ -103,21 +103,11 @@ public class RemoteServerManager { ...@@ -103,21 +103,11 @@ public class RemoteServerManager {
if (PermissionPolicy.blacklist == getPermissionPolicy()) { if (PermissionPolicy.blacklist == getPermissionPolicy()) {
// Anyone can access except those entities listed in the blacklist // Anyone can access except those entities listed in the blacklist
if (Permission.blocked == permission) { return Permission.blocked != permission;
return false;
}
else {
return true;
}
} }
else { else {
// Access is limited to those present in the whitelist // Access is limited to those present in the whitelist
if (Permission.allowed == permission) { return Permission.allowed == permission;
return true;
}
else {
return false;
}
} }
} }
...@@ -330,16 +320,15 @@ public class RemoteServerManager { ...@@ -330,16 +320,15 @@ public class RemoteServerManager {
// Check if the connected servers can remain connected to the server // Check if the connected servers can remain connected to the server
for (String hostname : SessionManager.getInstance().getIncomingServers()) { for (String hostname : SessionManager.getInstance().getIncomingServers()) {
if (!canAccess(hostname)) { if (!canAccess(hostname)) {
for (Session session : SessionManager.getInstance() for (Session session : SessionManager.getInstance().getIncomingServerSessions(hostname)) {
.getIncomingServerSessions(hostname)) { session.close();
session.getConnection().close();
} }
} }
} }
for (String hostname : SessionManager.getInstance().getOutgoingServers()) { for (String hostname : SessionManager.getInstance().getOutgoingServers()) {
if (!canAccess(hostname)) { if (!canAccess(hostname)) {
Session session = SessionManager.getInstance().getOutgoingServerSession(hostname); Session session = SessionManager.getInstance().getOutgoingServerSession(hostname);
session.getConnection().close(); session.close();
} }
} }
} }
......
...@@ -21,7 +21,8 @@ import org.jivesoftware.openfire.net.MXParser; ...@@ -21,7 +21,8 @@ import org.jivesoftware.openfire.net.MXParser;
import org.jivesoftware.openfire.net.ServerTrafficCounter; import org.jivesoftware.openfire.net.ServerTrafficCounter;
import org.jivesoftware.openfire.net.SocketConnection; import org.jivesoftware.openfire.net.SocketConnection;
import org.jivesoftware.openfire.session.IncomingServerSession; import org.jivesoftware.openfire.session.IncomingServerSession;
import org.jivesoftware.openfire.session.OutgoingServerSession; import org.jivesoftware.openfire.session.LocalIncomingServerSession;
import org.jivesoftware.openfire.session.LocalOutgoingServerSession;
import org.jivesoftware.openfire.spi.BasicStreamIDFactory; import org.jivesoftware.openfire.spi.BasicStreamIDFactory;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
...@@ -137,7 +138,7 @@ public class ServerDialback { ...@@ -137,7 +138,7 @@ public class ServerDialback {
* @param port port of the Receiving Server. * @param port port of the Receiving Server.
* @return an OutgoingServerSession if the domain was authenticated or <tt>null</tt> if none. * @return an OutgoingServerSession if the domain was authenticated or <tt>null</tt> if none.
*/ */
public OutgoingServerSession createOutgoingSession(String domain, String hostname, int port) { public LocalOutgoingServerSession createOutgoingSession(String domain, String hostname, int port) {
String realHostname = null; String realHostname = null;
int realPort = port; int realPort = port;
try { try {
...@@ -186,8 +187,7 @@ public class ServerDialback { ...@@ -186,8 +187,7 @@ public class ServerDialback {
if (authenticateDomain(socketReader, domain, hostname, id)) { if (authenticateDomain(socketReader, domain, hostname, id)) {
// Domain was validated so create a new OutgoingServerSession // Domain was validated so create a new OutgoingServerSession
StreamID streamID = new BasicStreamIDFactory().createStreamID(id); StreamID streamID = new BasicStreamIDFactory().createStreamID(id);
OutgoingServerSession session = new OutgoingServerSession(domain, connection, LocalOutgoingServerSession session = new LocalOutgoingServerSession(domain, connection, socketReader, streamID);
socketReader, streamID);
connection.init(session); connection.init(session);
// Set the hostname as the address of the session // Set the hostname as the address of the session
session.setAddress(new JID(null, hostname, null)); session.setAddress(new JID(null, hostname, null));
...@@ -306,7 +306,7 @@ public class ServerDialback { ...@@ -306,7 +306,7 @@ public class ServerDialback {
* Returns a new {@link IncomingServerSession} with a domain validated by the Authoritative * Returns a new {@link IncomingServerSession} with a domain validated by the Authoritative
* Server. New domains may be added to the returned IncomingServerSession after they have * Server. New domains may be added to the returned IncomingServerSession after they have
* been validated. See * been validated. See
* {@link IncomingServerSession#validateSubsequentDomain(org.dom4j.Element)}. The remote * {@link LocalIncomingServerSession#validateSubsequentDomain(org.dom4j.Element)}. The remote
* server will be able to send packets through this session whose domains were previously * server will be able to send packets through this session whose domains were previously
* validated.<p> * validated.<p>
* *
...@@ -319,7 +319,7 @@ public class ServerDialback { ...@@ -319,7 +319,7 @@ public class ServerDialback {
* @throws IOException if an I/O error occurs while communicating with the remote server. * @throws IOException if an I/O error occurs while communicating with the remote server.
* @throws XmlPullParserException if an error occurs while parsing XML packets. * @throws XmlPullParserException if an error occurs while parsing XML packets.
*/ */
public IncomingServerSession createIncomingSession(XMPPPacketReader reader) throws IOException, public LocalIncomingServerSession createIncomingSession(XMPPPacketReader reader) throws IOException,
XmlPullParserException { XmlPullParserException {
XmlPullParser xpp = reader.getXPPParser(); XmlPullParser xpp = reader.getXPPParser();
StringBuilder sb; StringBuilder sb;
...@@ -343,7 +343,7 @@ public class ServerDialback { ...@@ -343,7 +343,7 @@ public class ServerDialback {
String hostname = doc.attributeValue("from"); String hostname = doc.attributeValue("from");
String recipient = doc.attributeValue("to"); String recipient = doc.attributeValue("to");
// Create a server Session for the remote server // Create a server Session for the remote server
IncomingServerSession session = sessionManager. LocalIncomingServerSession session = sessionManager.
createIncomingServerSession(connection, streamID); createIncomingServerSession(connection, streamID);
// Set the first validated domain as the address of the session // Set the first validated domain as the address of the session
session.setAddress(new JID(null, hostname, null)); session.setAddress(new JID(null, hostname, null));
...@@ -434,8 +434,7 @@ public class ServerDialback { ...@@ -434,8 +434,7 @@ public class ServerDialback {
else { else {
// Check if the remote server already has a connection to the target domain/subdomain // Check if the remote server already has a connection to the target domain/subdomain
boolean alreadyExists = false; boolean alreadyExists = false;
for (IncomingServerSession session : sessionManager for (IncomingServerSession session : sessionManager.getIncomingServerSessions(hostname)) {
.getIncomingServerSessions(hostname)) {
if (recipient.equals(session.getLocalDomain())) { if (recipient.equals(session.getLocalDomain())) {
alreadyExists = true; alreadyExists = true;
} }
......
...@@ -12,12 +12,16 @@ ...@@ -12,12 +12,16 @@
package org.jivesoftware.openfire.spi; package org.jivesoftware.openfire.spi;
import org.jivesoftware.openfire.RoutableChannelHandler; import org.jivesoftware.openfire.RoutableChannelHandler;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.OutgoingServerSession;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.TaskEngine;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
...@@ -56,11 +60,11 @@ class LocalRoutingTable { ...@@ -56,11 +60,11 @@ class LocalRoutingTable {
* *
* @return the client sessions that are connected to this JVM. * @return the client sessions that are connected to this JVM.
*/ */
Collection<RoutableChannelHandler> getClientRoutes() { Collection<ClientSession> getClientRoutes() {
List<RoutableChannelHandler> sessions = new ArrayList<RoutableChannelHandler>(); List<ClientSession> sessions = new ArrayList<ClientSession>();
for (RoutableChannelHandler route : routes.values()) { for (RoutableChannelHandler route : routes.values()) {
if (route instanceof ClientSession) { if (route instanceof ClientSession) {
sessions.add(route); sessions.add((ClientSession) route);
} }
} }
return sessions; return sessions;
...@@ -75,4 +79,61 @@ class LocalRoutingTable { ...@@ -75,4 +79,61 @@ class LocalRoutingTable {
routes.remove(address); routes.remove(address);
} }
public void start() {
// Run through the server sessions every 3 minutes after a 3 minutes server startup delay (default values)
int period = 3 * 60 * 1000;
TaskEngine.getInstance().scheduleAtFixedRate(new ServerCleanupTask(), period, period);
}
public void stop() {
try {
// Send the close stream header to all connected connections
for (RoutableChannelHandler route : routes.values()) {
if (route instanceof LocalSession) {
LocalSession session = (LocalSession) route;
try {
// Notify connected client that the server is being shut down
session.getConnection().systemShutdown();
}
catch (Throwable t) {
// Ignore.
}
}
}
}
catch (Exception e) {
// Ignore.
}
}
/**
* Task that closes idle server sessions.
*/
private class ServerCleanupTask extends TimerTask {
/**
* Close outgoing server sessions that have been idle for a long time.
*/
public void run() {
// Do nothing if this feature is disabled
int idleTime = SessionManager.getInstance().getServerSessionIdleTime();
if (idleTime == -1) {
return;
}
final long deadline = System.currentTimeMillis() - idleTime;
for (RoutableChannelHandler route : routes.values()) {
// Check outgoing server sessions
if (route instanceof OutgoingServerSession) {
Session session = (Session) route;
try {
if (session.getLastActiveDate().getTime() < deadline) {
session.close();
}
}
catch (Throwable e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
}
}
}
} }
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
package org.jivesoftware.openfire.spi; package org.jivesoftware.openfire.spi;
import org.jivesoftware.openfire.*; import org.jivesoftware.openfire.PacketDeliverer;
import org.jivesoftware.openfire.PacketException;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.container.BasicModule; import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.net.SocketPacketWriteHandler; import org.jivesoftware.openfire.net.SocketPacketWriteHandler;
...@@ -29,9 +31,6 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer ...@@ -29,9 +31,6 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer
*/ */
protected SocketPacketWriteHandler deliverHandler; protected SocketPacketWriteHandler deliverHandler;
private OfflineMessageStrategy messageStrategy;
private SessionManager sessionManager;
public PacketDelivererImpl() { public PacketDelivererImpl() {
super("Packet Delivery"); super("Packet Delivery");
} }
...@@ -48,17 +47,9 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer ...@@ -48,17 +47,9 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer
deliverHandler.process(packet); deliverHandler.process(packet);
} }
public void initialize(XMPPServer server) {
super.initialize(server);
messageStrategy = server.getOfflineMessageStrategy();
sessionManager = server.getSessionManager();
}
public void start() throws IllegalStateException { public void start() throws IllegalStateException {
super.start(); super.start();
deliverHandler = deliverHandler = new SocketPacketWriteHandler(XMPPServer.getInstance().getRoutingTable());
new SocketPacketWriteHandler(sessionManager,
XMPPServer.getInstance().getRoutingTable(), messageStrategy);
} }
public void stop() { public void stop() {
......
...@@ -9,14 +9,15 @@ package org.jivesoftware.openfire.stun; ...@@ -9,14 +9,15 @@ package org.jivesoftware.openfire.stun;
import de.javawi.jstun.test.demo.StunServer; import de.javawi.jstun.test.demo.StunServer;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.openfire.IQHandlerInfo;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.handler.IQHandler;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.PropertyEventDispatcher; import org.jivesoftware.util.PropertyEventDispatcher;
import org.jivesoftware.util.PropertyEventListener; import org.jivesoftware.util.PropertyEventListener;
import org.jivesoftware.openfire.*;
import org.jivesoftware.openfire.handler.IQHandler;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.container.BasicModule;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
...@@ -24,7 +25,10 @@ import java.net.InetAddress; ...@@ -24,7 +25,10 @@ import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.*; import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
/** /**
* STUN server and service module. It provides address discovery for p2p sessions to be * STUN server and service module. It provides address discovery for p2p sessions to be
...@@ -398,7 +402,7 @@ public class STUNService extends BasicModule { ...@@ -398,7 +402,7 @@ public class STUNService extends BasicModule {
server.addAttribute("udp", stunServerAddress.getPort()); server.addAttribute("udp", stunServerAddress.getPort());
} }
try { try {
String ip = sessionManager.getSession(iq.getFrom()).getConnection().getInetAddress().getHostAddress(); String ip = sessionManager.getSession(iq.getFrom()).getHostAddress();
if (ip != null) { if (ip != null) {
Element publicIp = childElementCopy.addElement("publicip"); Element publicIp = childElementCopy.addElement("publicip");
publicIp.addAttribute("ip", ip); publicIp.addAttribute("ip", ip);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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