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 {
Log.error(LocaleUtils.getLocalizedString("admin.error.routing"), e);
Session session = sessionManager.getSession(packet.getFrom());
if (session != null) {
Connection conn = session.getConnection();
if (conn != null) {
conn.close();
}
session.close();
}
}
}
......@@ -188,9 +185,10 @@ public class PresenceRouter extends BasicModule {
/**
* 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.
*/
public void routingFailed(Packet packet) {
public void routingFailed(JID receipient, Packet packet) {
// presence packets are dropped silently
}
}
......@@ -11,12 +11,15 @@
package org.jivesoftware.openfire;
import org.jivesoftware.openfire.auth.UnauthorizedException;
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.Message;
import org.xmpp.packet.Packet;
import java.util.Collection;
import java.util.List;
/**
......@@ -85,7 +88,7 @@ public interface RoutingTable {
* @param route the address associated to the route.
* @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
......@@ -107,7 +110,7 @@ public interface RoutingTable {
* @param route the address associated to the route.
* @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
......@@ -135,16 +138,17 @@ public interface RoutingTable {
*
* @param jid the receipient of 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
* 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
* 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.
* @return true if a registered user or anonymous user with the specified full JID is
......@@ -152,6 +156,16 @@ public interface RoutingTable {
*/
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.
* 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 {
*/
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
* for routes to a remote server then the requested JID will be included as the only
......
......@@ -13,7 +13,7 @@ package org.jivesoftware.openfire;
import org.dom4j.Element;
import org.jivesoftware.openfire.multiplex.UnknownStanzaException;
import org.jivesoftware.openfire.net.SASLAuthentication;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.LocalClientSession;
import org.xmpp.packet.*;
import java.io.UnsupportedEncodingException;
......@@ -26,19 +26,13 @@ import java.io.UnsupportedEncodingException;
*/
public class SessionPacketRouter implements PacketRouter {
private ClientSession session;
private LocalClientSession session;
private PacketRouter router;
private SessionManager sessionManager;
private boolean skipJIDValidation = false;
public SessionPacketRouter() {
this(null);
}
public SessionPacketRouter(ClientSession session) {
public SessionPacketRouter(LocalClientSession session) {
this.session = session;
router = XMPPServer.getInstance().getPacketRouter();
sessionManager = SessionManager.getInstance();
}
......@@ -100,36 +94,21 @@ public class SessionPacketRouter implements PacketRouter {
}
public void route(IQ packet) {
if(session == null) {
session = sessionManager.getSession(packet.getFrom());
if(session == null) {
router.route(packet);
}
}
packet.setFrom(session.getAddress());
router.route(packet);
session.incrementClientPacketCount();
}
public void route(Message packet) {
if(session == null) {
session = sessionManager.getSession(packet.getFrom());
if(session == null) {
router.route(packet);
}
}
packet.setFrom(session.getAddress());
router.route(packet);
session.incrementClientPacketCount();
}
public void route(Presence packet) {
if(session == null) {
session = sessionManager.getSession(packet.getFrom());
if(session == null) {
router.route(packet);
}
}
packet.setFrom(session.getAddress());
router.route(packet);
session.incrementClientPacketCount();
......
......@@ -37,6 +37,7 @@ import org.jivesoftware.openfire.net.SSLConfig;
import org.jivesoftware.openfire.net.ServerTrafficCounter;
import org.jivesoftware.openfire.pubsub.PubSubModule;
import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.RemoteSessionLocator;
import org.jivesoftware.openfire.spi.*;
import org.jivesoftware.openfire.stun.STUNService;
import org.jivesoftware.openfire.transport.TransportHandler;
......@@ -119,6 +120,7 @@ public class XMPPServer {
private PluginManager pluginManager;
private InternalComponentManager componentManager;
private RemoteSessionLocator remoteSessionLocator;
/**
* True if in setup mode
......@@ -1310,4 +1312,23 @@ public class XMPPServer {
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 {
this.role = role;
this.affiliation = affiliation;
// 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());
extendedInformation =
......
......@@ -18,7 +18,6 @@ import org.jivesoftware.openfire.session.ConnectionMultiplexerSession;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Packet;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
......@@ -92,17 +91,32 @@ public class ClientSessionConnection extends VirtualConnection {
sb.append(text);
sb.append("</route>");
// 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
// Return IP address of the connection manager that the client used to log in
ConnectionMultiplexerSession multiplexerSession =
multiplexerManager.getMultiplexerSession(connectionManagerName);
if (multiplexerSession != null) {
return multiplexerSession.getConnection().getInetAddress();
return multiplexerSession.getHostName();
}
return null;
}
......
......@@ -11,19 +11,19 @@
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.SessionManager;
import org.jivesoftware.openfire.StreamID;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.event.SessionEventDispatcher;
import org.jivesoftware.openfire.event.SessionEventListener;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.ConnectionMultiplexerSession;
import org.jivesoftware.openfire.session.LocalClientSession;
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.concurrent.ConcurrentHashMap;
......@@ -60,8 +60,8 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
* Map that keeps track of connection managers and hosted sessions.
* Key: Domain of connection manager; Value: Map with Key: stream ID; Value: Client session
*/
private Map<String, Map<String, ClientSession>> sessionsByManager =
new ConcurrentHashMap<String, Map<String, ClientSession>>();
private Map<String, Map<String, LocalClientSession>> sessionsByManager =
new ConcurrentHashMap<String, Map<String, LocalClientSession>>();
private SessionManager sessionManager;
......@@ -103,10 +103,8 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
TimerTask heartbeatTask = new TimerTask() {
public void run() {
try {
for (ConnectionMultiplexerSession session : sessionManager
.getConnectionMultiplexerSessions())
{
session.getConnection().deliverRawText(" ");
for (ConnectionMultiplexerSession session : sessionManager.getConnectionMultiplexerSessions()) {
session.deliverRawText(" ");
}
}
catch(Exception e) {
......@@ -114,8 +112,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
}
}
};
TaskEngine.getInstance().schedule(heartbeatTask, 30*JiveConstants.SECOND,
30*JiveConstants.SECOND);
TaskEngine.getInstance().schedule(heartbeatTask, 30*JiveConstants.SECOND, 30*JiveConstants.SECOND);
}
/**
......@@ -129,17 +126,17 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
public void createClientSession(String connectionManagerDomain, String streamID) {
// 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));
LocalClientSession 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);
Map<String, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions == null) {
synchronized (connectionManagerDomain.intern()) {
sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions == null) {
sessions = new ConcurrentHashMap<String, ClientSession>();
sessions = new ConcurrentHashMap<String, LocalClientSession>();
sessionsByManager.put(connectionManagerDomain, sessions);
}
}
......@@ -155,12 +152,12 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
* @param streamID the stream ID created by the connection manager for the session.
*/
public void closeClientSession(String connectionManagerDomain, String streamID) {
Map<String, ClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
Map<String, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions != null) {
Session session = sessions.remove(streamID);
if (session != null) {
// Close the session
session.getConnection().close();
session.close();
}
}
}
......@@ -174,12 +171,12 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
public void multiplexerAvailable(String connectionManagerName) {
// 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
Map<String, ClientSession> sessions = sessionsByManager.get(connectionManagerName);
Map<String, LocalClientSession> sessions = sessionsByManager.get(connectionManagerName);
if (sessions == null) {
synchronized (connectionManagerName.intern()) {
sessions = sessionsByManager.get(connectionManagerName);
if (sessions == null) {
sessions = new ConcurrentHashMap<String, ClientSession>();
sessions = new ConcurrentHashMap<String, LocalClientSession>();
sessionsByManager.put(connectionManagerName, sessions);
}
}
......@@ -194,13 +191,13 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
*/
public void multiplexerUnavailable(String connectionManagerName) {
// 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) {
for (String streamID : sessions.keySet()) {
// Remove inverse track of connection manager hosting streamIDs
streamIDs.remove(streamID);
// Close the session
sessions.get(streamID).getConnection().close();
sessions.get(streamID).close();
}
}
}
......@@ -214,8 +211,8 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
* @param streamID the stream ID created by the connection manager for the session.
* @return the ClientSession with the specified stream ID.
*/
public ClientSession getClientSession(String connectionManagerDomain, String streamID) {
Map<String, ClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
public LocalClientSession getClientSession(String connectionManagerDomain, String streamID) {
Map<String, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions != null) {
return sessions.get(streamID);
}
......@@ -261,7 +258,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
* @return the number of connected clients to a specific connection manager.
*/
public int getNumConnectedClients(String managerName) {
Map<String, ClientSession> clients = sessionsByManager.get(managerName);
Map<String, LocalClientSession> clients = sessionsByManager.get(managerName);
if (clients == null) {
return 0;
}
......@@ -292,7 +289,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
String connectionManagerDomain = streamIDs.remove(streamID);
// Remove trace indicating that a connection manager is hosting a session
if (connectionManagerDomain != null) {
Map<String, ClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
Map<String, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions != null) {
sessions.remove(streamID);
}
......
......@@ -12,14 +12,14 @@
package org.jivesoftware.openfire.multiplex;
import org.dom4j.Element;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.OfflineMessageStrategy;
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.session.ConnectionMultiplexerSession;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
......@@ -63,7 +63,7 @@ public class MultiplexerPacketDeliverer implements PacketDeliverer {
// Try getting another session to the same connection manager
ConnectionMultiplexerSession session =
multiplexerManager.getMultiplexerSession(connectionManagerDomain);
if (session == null || session.getConnection().isClosed()) {
if (session == null || session.isClosed()) {
// No other session was found so handle unprocessed packet
handleUnprocessedPacket(packet);
}
......
......@@ -14,11 +14,12 @@ package org.jivesoftware.openfire.multiplex;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.SessionPacketRouter;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.session.ClientSession;
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.Message;
import org.xmpp.packet.Packet;
......@@ -149,8 +150,7 @@ public class MultiplexerPacketHandler {
"id-required", "http://jabber.org/protocol/connectionmanager#errors"));
sendErrorPacket(route, PacketError.Condition.bad_request, extraError);
}
ClientSession session = multiplexerManager
.getClientSession(connectionManagerDomain, streamID);
LocalClientSession session = multiplexerManager.getClientSession(connectionManagerDomain, streamID);
if (session == null) {
// Specified Client Session does not exist
sendErrorPacket(route, PacketError.Condition.item_not_found, null);
......
......@@ -91,7 +91,7 @@ class BlockingReadingMode extends SocketReadingMode {
Log.debug("Logging off " + socketReader.session.getAddress() + " on " + socketReader.connection);
}
try {
socketReader.session.getConnection().close();
socketReader.session.close();
}
catch (Exception e) {
Log.warn(LocaleUtils.getLocalizedString("admin.error.connection")
......
......@@ -11,11 +11,11 @@
package org.jivesoftware.openfire.net;
import org.dom4j.Element;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.openfire.Connection;
import org.jivesoftware.openfire.PacketRouter;
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.XmlPullParserException;
import org.xmpp.packet.IQ;
......@@ -67,7 +67,7 @@ public class ClientStanzaHandler extends StanzaHandler {
throws XmlPullParserException {
if ("jabber:client".equals(namespace)) {
// 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 false;
......
......@@ -12,12 +12,13 @@
package org.jivesoftware.openfire.net;
import org.dom4j.Element;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.session.ComponentSession;
import org.jivesoftware.openfire.session.LocalComponentSession;
import org.jivesoftware.util.Log;
import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.component.ComponentException;
import org.xmpp.packet.PacketError;
......@@ -49,7 +50,7 @@ public class ComponentSocketReader extends SocketReader {
protected boolean processUnknowPacket(Element doc) {
// Handle subsequent bind packets
if ("bind".equals(doc.getName())) {
ComponentSession componentSession = (ComponentSession) session;
LocalComponentSession componentSession = (LocalComponentSession) session;
// Get the external component of this session
ComponentSession.ExternalComponent component = componentSession.getExternalComponent();
String initialDomain = component.getInitialSubdomain();
......@@ -113,7 +114,7 @@ public class ComponentSocketReader extends SocketReader {
IOException {
if ("jabber:component:accept".equals(namespace)) {
// 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 false;
......
......@@ -16,7 +16,7 @@ import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.multiplex.MultiplexerPacketHandler;
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.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
......@@ -95,15 +95,13 @@ public class MultiplexerStanzaHandler extends StanzaHandler {
// Process stanza wrapped by the route packet
processRoute(new Route(doc));
return true;
}
else if ("handshake".equals(tag)) {
if (!((ConnectionMultiplexerSession)session).authenticate(doc.getStringValue())) {
session.getConnection().close();
} else if ("handshake".equals(tag)) {
if (!((LocalConnectionMultiplexerSession) session).authenticate(doc.getStringValue())) {
session.close();
}
return true;
}
else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) {
session.getConnection().close();
} else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) {
session.close();
return true;
}
return false;
......@@ -125,7 +123,7 @@ public class MultiplexerStanzaHandler extends StanzaHandler {
throws XmlPullParserException {
if (getNamespace().equals(namespace)) {
// 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) {
packetHandler = new MultiplexerPacketHandler(session.getAddress().getDomain());
}
......
......@@ -15,17 +15,15 @@ import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Namespace;
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.auth.AuthFactory;
import org.jivesoftware.openfire.auth.AuthToken;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.IncomingServerSession;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.openfire.session.*;
import org.jivesoftware.util.CertificateManager;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils;
import org.xmpp.packet.JID;
import javax.net.ssl.SSLPeerUnverifiedException;
......@@ -127,7 +125,7 @@ public class SASLAuthentication {
sb.append("<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
if (session instanceof IncomingServerSession) {
// 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
sb.append("<mechanism>EXTERNAL</mechanism>");
}
......@@ -152,7 +150,7 @@ public class SASLAuthentication {
new Namespace("", "urn:ietf:params:xml:ns:xmpp-sasl")));
if (session instanceof IncomingServerSession) {
// 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
Element mechanism = mechs.addElement("mechanism");
mechanism.setText("EXTERNAL");
......@@ -179,7 +177,7 @@ public class SASLAuthentication {
* or not or if the entity is expected to send a response to a challenge.
* @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;
String mechanism;
if (doc.getNamespace().asXML().equals(SASL_NAMESPACE)) {
......@@ -386,7 +384,7 @@ public class SASLAuthentication {
}
private static Status doAnonymousAuthentication(Session session) {
private static Status doAnonymousAuthentication(LocalSession session) {
if (XMPPServer.getInstance().getIQAuthHandler().isAnonymousAllowed()) {
// Just accept the authentication :)
authenticationSuccessful(session, null, null);
......@@ -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 {
String username;
String password;
......@@ -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 {
// Only accept EXTERNAL SASL for s2s. At this point the connection has already
// been secured using TLS
......@@ -486,7 +484,7 @@ public class SASLAuthentication {
return Status.failed;
}
private static Status doSharedSecretAuthentication(Session session, Element doc)
private static Status doSharedSecretAuthentication(LocalSession session, Element doc)
throws UnsupportedEncodingException
{
String secretDigest;
......@@ -524,10 +522,10 @@ public class SASLAuthentication {
"<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
reply.append(challenge_b64);
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) {
StringBuilder reply = new StringBuilder(80);
reply.append("<success xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\"");
......@@ -538,10 +536,10 @@ public class SASLAuthentication {
else {
reply.append("/>");
}
session.getConnection().deliverRawText(reply.toString());
session.deliverRawText(reply.toString());
// We only support SASL for c2s
if (session instanceof ClientSession) {
((ClientSession) session).setAuthToken(new AuthToken(username));
((LocalClientSession) session).setAuthToken(new AuthToken(username));
}
else if (session instanceof IncomingServerSession) {
String hostname = username;
......@@ -549,15 +547,15 @@ public class SASLAuthentication {
session.setAddress(new JID(null, hostname, null));
// Add the validated domain as a valid domain. The remote server can
// 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);
reply.append("<failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
reply.append("<not-authorized/></failure>");
session.getConnection().deliverRawText(reply.toString());
session.deliverRawText(reply.toString());
// Give a number of retries before closing the connection
Integer retries = (Integer) session.getSessionData("authRetries");
if (retries == null) {
......@@ -569,7 +567,7 @@ public class SASLAuthentication {
session.setSessionData("authRetries", retries);
if (retries >= JiveGlobals.getIntProperty("xmpp.auth.retries", 3) ) {
// Close the connection
session.getConnection().close();
session.close();
}
}
......
......@@ -12,13 +12,13 @@
package org.jivesoftware.openfire.net;
import org.dom4j.Element;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.auth.UnauthorizedException;
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.xmpp.packet.*;
......@@ -149,7 +149,7 @@ public class ServerSocketReader extends SocketReader {
protected boolean processUnknowPacket(Element doc) {
// Handle subsequent db:result packets
if ("db".equals(doc.getNamespacePrefix()) && "result".equals(doc.getName())) {
if (!((IncomingServerSession) session).validateSubsequentDomain(doc)) {
if (!((LocalIncomingServerSession) session).validateSubsequentDomain(doc)) {
open = false;
}
return true;
......@@ -157,7 +157,7 @@ public class ServerSocketReader extends SocketReader {
else if ("db".equals(doc.getNamespacePrefix()) && "verify".equals(doc.getName())) {
// The Receiving Server is reusing an existing connection for sending the
// Authoritative Server a request for verification of a key
((IncomingServerSession) session).verifyReceivedKey(doc);
((LocalIncomingServerSession) session).verifyReceivedKey(doc);
return true;
}
return false;
......@@ -184,7 +184,7 @@ public class ServerSocketReader extends SocketReader {
open = false;
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: " +
packet.toXML());
// Send a stream error saying that the packet includes an invalid FROM
......@@ -208,7 +208,7 @@ public class ServerSocketReader extends SocketReader {
IOException {
if ("jabber:server".equals(namespace)) {
// 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 false;
......
......@@ -19,6 +19,7 @@ import org.jivesoftware.openfire.PacketDeliverer;
import org.jivesoftware.openfire.PacketException;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.IncomingServerSession;
import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
......@@ -30,8 +31,8 @@ import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.channels.Channels;
import java.util.Collection;
import java.util.Date;
......@@ -83,7 +84,7 @@ public class SocketConnection implements Connection {
*/
private PacketDeliverer backupDeliverer;
private Session session;
private LocalSession session;
private boolean secure;
private boolean compressed;
private org.jivesoftware.util.XMLWriter xmlSerializer;
......@@ -224,7 +225,7 @@ public class SocketConnection implements Connection {
return !isClosed();
}
public void init(Session owner) {
public void init(LocalSession owner) {
session = owner;
}
......@@ -241,8 +242,16 @@ public class SocketConnection implements Connection {
listeners.remove(listener);
}
public InetAddress getInetAddress() {
return socket.getInetAddress();
public byte[] getAddress() throws UnknownHostException {
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;
import org.jivesoftware.openfire.*;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
/**
* This ChannelHandler writes packet data to connections.
......@@ -30,22 +27,11 @@ import org.xmpp.packet.Presence;
public class SocketPacketWriteHandler implements ChannelHandler {
private XMPPServer server;
private SessionManager sessionManager;
private OfflineMessageStrategy messageStrategy;
private RoutingTable routingTable;
private IQRouter iqRouter;
private MessageRouter messageRouter;
private PresenceRouter presenceRouter;
public SocketPacketWriteHandler(SessionManager sessionManager, RoutingTable routingTable,
OfflineMessageStrategy messageStrategy) {
this.sessionManager = sessionManager;
this.messageStrategy = messageStrategy;
public SocketPacketWriteHandler(RoutingTable routingTable) {
this.routingTable = routingTable;
this.server = XMPPServer.getInstance();
iqRouter = server.getIQRouter();
messageRouter = server.getMessageRouter();
presenceRouter = server.getPresenceRouter();
}
public void process(Packet packet) throws UnauthorizedException, PacketException {
......@@ -61,34 +47,11 @@ public class SocketPacketWriteHandler implements ChannelHandler {
routingTable.routePacket(packet.getFrom(), packet);
}
else {
Session session = sessionManager.getBestRoute(recipient);
if (session == null) {
handleUnprocessedPacket(packet);
}
else {
try {
session.process(packet);
}
catch (Exception e) {
// do nothing
}
}
routingTable.routePacket(recipient, packet);
}
}
catch (Exception 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;
import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
......@@ -49,7 +50,7 @@ public abstract class SocketReader implements Runnable {
/**
* Session associated with the socket reader.
*/
protected Session session;
protected LocalSession session;
/**
* Reference to the physical connection.
*/
......
......@@ -15,6 +15,7 @@ import org.dom4j.io.XMPPPacketReader;
import org.jivesoftware.openfire.Connection;
import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
......@@ -59,7 +60,7 @@ public abstract class StanzaHandler {
/**
* Session associated with the socket reader.
*/
protected Session session;
protected LocalSession session;
/**
* Server name for which we are attending clients.
*/
......@@ -112,7 +113,7 @@ public abstract class StanzaHandler {
// Verify if end of stream was requested
if (stanza.equals("</stream:stream>")) {
session.getConnection().close();
session.close();
return;
}
// Ignore <?xml version="1.0"?> stanzas sent by clients
......@@ -258,7 +259,7 @@ public abstract class StanzaHandler {
if (!processUnknowPacket(doc)) {
Log.warn(LocaleUtils.getLocalizedString("admin.error.packet.tag") +
doc.asXML());
session.getConnection().close();
session.close();
}
}
}
......
......@@ -14,6 +14,7 @@ package org.jivesoftware.openfire.net;
import org.jivesoftware.openfire.Connection;
import org.jivesoftware.openfire.ConnectionCloseListener;
import org.jivesoftware.openfire.PacketDeliverer;
import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
......@@ -33,7 +34,7 @@ import java.util.Map;
*/
public abstract class VirtualConnection implements Connection {
protected Session session;
protected LocalSession session;
final private Map<ConnectionCloseListener, Object> listeners =
new HashMap<ConnectionCloseListener, Object>();
......@@ -129,7 +130,7 @@ public abstract class VirtualConnection implements Connection {
return true;
}
public void init(Session session) {
public void init(LocalSession session) {
this.session = session;
}
......
......@@ -24,6 +24,7 @@ import org.jivesoftware.openfire.net.SSLConfig;
import org.jivesoftware.openfire.net.SSLJiveKeyManagerFactory;
import org.jivesoftware.openfire.net.SSLJiveTrustManagerFactory;
import org.jivesoftware.openfire.net.ServerTrustManager;
import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
......@@ -33,7 +34,6 @@ import org.xmpp.packet.Packet;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
......@@ -55,7 +55,7 @@ public class NIOConnection implements Connection {
*/
public static final String CHARSET = "UTF-8";
private Session session;
private LocalSession session;
private IoSession ioSession;
private ConnectionCloseListener closeListener;
......@@ -123,8 +123,16 @@ public class NIOConnection implements Connection {
}
}
public InetAddress getInetAddress() throws UnknownHostException {
return ((InetSocketAddress) ioSession.getRemoteAddress()).getAddress();
public byte[] getAddress() throws UnknownHostException {
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() {
......@@ -173,7 +181,7 @@ public class NIOConnection implements Connection {
}
}
public void init(Session owner) {
public void init(LocalSession owner) {
session = owner;
}
......
......@@ -13,7 +13,6 @@ package org.jivesoftware.openfire.roster;
import org.jivesoftware.database.JiveID;
import org.jivesoftware.openfire.*;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.privacy.PrivacyList;
......@@ -656,13 +655,8 @@ public class Roster implements Cacheable, Externalizable {
if (sessionManager == null) {
sessionManager = SessionManager.getInstance();
}
try {
sessionManager.userBroadcast(username, roster);
}
catch (UnauthorizedException e) {
// Do nothing. We should never end here.
}
}
/**
* Broadcasts the RosterItem to all the connected resources of this user. Due to performance
......
......@@ -14,7 +14,6 @@ package org.jivesoftware.openfire.roster;
import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.SharedGroupException;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.event.GroupEventListener;
......@@ -717,13 +716,8 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
else {
presence.setType(Presence.Type.unsubscribe);
}
try {
routingTable.routePacket(recipient, presence);
}
catch (UnauthorizedException e) {
// Do nothing
}
}
private Collection<Group> getVisibleGroups(Group groupToCheck) {
Collection<Group> answer = new HashSet<Group>();
......
......@@ -13,8 +13,8 @@ package org.jivesoftware.openfire.server;
import org.dom4j.Element;
import org.dom4j.io.XMPPPacketReader;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.session.OutgoingServerSession;
import org.jivesoftware.util.Log;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
......@@ -132,7 +132,7 @@ public class OutgoingServerSocketReader {
private void closeSession() {
open = false;
if (session != null) {
session.getConnection().close();
session.close();
}
}
}
......@@ -14,8 +14,7 @@ package org.jivesoftware.openfire.server;
import org.jivesoftware.openfire.RoutableChannelHandler;
import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.session.OutgoingServerSession;
import org.jivesoftware.openfire.session.LocalOutgoingServerSession;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.xmpp.packet.*;
......@@ -116,6 +115,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler {
}
}
catch (InterruptedException e) {
// Do nothing
}
catch (Exception e) {
Log.error(e);
......@@ -195,7 +195,7 @@ public class OutgoingSessionPromise implements RoutableChannelHandler {
private void sendPacket(Packet packet) throws Exception {
// 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());
if (created) {
// 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 {
try {
if (packet instanceof IQ) {
IQ reply = new IQ();
reply.setID(((IQ) packet).getID());
reply.setID(packet.getID());
reply.setTo(from);
reply.setFrom(to);
reply.setChildElement(((IQ) packet).getChildElement().createCopy());
......@@ -248,8 +248,6 @@ public class OutgoingSessionPromise implements RoutableChannelHandler {
routingTable.routePacket(reply.getTo(), reply);
}
}
catch (UnauthorizedException e) {
}
catch (Exception e) {
Log.warn("Error returning error to sender. Original packet: " + packet, e);
}
......
......@@ -11,12 +11,12 @@
package org.jivesoftware.openfire.server;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.ConnectionManager;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.server.RemoteServerConfiguration.Permission;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
......@@ -70,11 +70,11 @@ public class RemoteServerManager {
addConfiguration(config);
// Check if the remote server was connected and proceed to close the connection
for (Session session : SessionManager.getInstance().getIncomingServerSessions(domain)) {
session.getConnection().close();
session.close();
}
Session session = SessionManager.getInstance().getOutgoingServerSession(domain);
if (session != null) {
session.getConnection().close();
session.close();
}
}
......@@ -103,21 +103,11 @@ public class RemoteServerManager {
if (PermissionPolicy.blacklist == getPermissionPolicy()) {
// Anyone can access except those entities listed in the blacklist
if (Permission.blocked == permission) {
return false;
}
else {
return true;
}
return Permission.blocked != permission;
}
else {
// Access is limited to those present in the whitelist
if (Permission.allowed == permission) {
return true;
}
else {
return false;
}
return Permission.allowed == permission;
}
}
......@@ -330,16 +320,15 @@ public class RemoteServerManager {
// Check if the connected servers can remain connected to the server
for (String hostname : SessionManager.getInstance().getIncomingServers()) {
if (!canAccess(hostname)) {
for (Session session : SessionManager.getInstance()
.getIncomingServerSessions(hostname)) {
session.getConnection().close();
for (Session session : SessionManager.getInstance().getIncomingServerSessions(hostname)) {
session.close();
}
}
}
for (String hostname : SessionManager.getInstance().getOutgoingServers()) {
if (!canAccess(hostname)) {
Session session = SessionManager.getInstance().getOutgoingServerSession(hostname);
session.getConnection().close();
session.close();
}
}
}
......
......@@ -21,7 +21,8 @@ import org.jivesoftware.openfire.net.MXParser;
import org.jivesoftware.openfire.net.ServerTrafficCounter;
import org.jivesoftware.openfire.net.SocketConnection;
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.util.JiveGlobals;
import org.jivesoftware.util.Log;
......@@ -137,7 +138,7 @@ public class ServerDialback {
* @param port port of the Receiving Server.
* @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;
int realPort = port;
try {
......@@ -186,8 +187,7 @@ public class ServerDialback {
if (authenticateDomain(socketReader, domain, hostname, id)) {
// Domain was validated so create a new OutgoingServerSession
StreamID streamID = new BasicStreamIDFactory().createStreamID(id);
OutgoingServerSession session = new OutgoingServerSession(domain, connection,
socketReader, streamID);
LocalOutgoingServerSession session = new LocalOutgoingServerSession(domain, connection, socketReader, streamID);
connection.init(session);
// Set the hostname as the address of the session
session.setAddress(new JID(null, hostname, null));
......@@ -306,7 +306,7 @@ public class ServerDialback {
* 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
* 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
* validated.<p>
*
......@@ -319,7 +319,7 @@ public class ServerDialback {
* @throws IOException if an I/O error occurs while communicating with the remote server.
* @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 {
XmlPullParser xpp = reader.getXPPParser();
StringBuilder sb;
......@@ -343,7 +343,7 @@ public class ServerDialback {
String hostname = doc.attributeValue("from");
String recipient = doc.attributeValue("to");
// Create a server Session for the remote server
IncomingServerSession session = sessionManager.
LocalIncomingServerSession session = sessionManager.
createIncomingServerSession(connection, streamID);
// Set the first validated domain as the address of the session
session.setAddress(new JID(null, hostname, null));
......@@ -434,8 +434,7 @@ public class ServerDialback {
else {
// Check if the remote server already has a connection to the target domain/subdomain
boolean alreadyExists = false;
for (IncomingServerSession session : sessionManager
.getIncomingServerSessions(hostname)) {
for (IncomingServerSession session : sessionManager.getIncomingServerSessions(hostname)) {
if (recipient.equals(session.getLocalDomain())) {
alreadyExists = true;
}
......
......@@ -12,12 +12,16 @@
package org.jivesoftware.openfire.spi;
import org.jivesoftware.openfire.RoutableChannelHandler;
import org.jivesoftware.openfire.SessionManager;
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.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
......@@ -56,11 +60,11 @@ class LocalRoutingTable {
*
* @return the client sessions that are connected to this JVM.
*/
Collection<RoutableChannelHandler> getClientRoutes() {
List<RoutableChannelHandler> sessions = new ArrayList<RoutableChannelHandler>();
Collection<ClientSession> getClientRoutes() {
List<ClientSession> sessions = new ArrayList<ClientSession>();
for (RoutableChannelHandler route : routes.values()) {
if (route instanceof ClientSession) {
sessions.add(route);
sessions.add((ClientSession) route);
}
}
return sessions;
......@@ -75,4 +79,61 @@ class LocalRoutingTable {
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 @@
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.container.BasicModule;
import org.jivesoftware.openfire.net.SocketPacketWriteHandler;
......@@ -29,9 +31,6 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer
*/
protected SocketPacketWriteHandler deliverHandler;
private OfflineMessageStrategy messageStrategy;
private SessionManager sessionManager;
public PacketDelivererImpl() {
super("Packet Delivery");
}
......@@ -48,17 +47,9 @@ public class PacketDelivererImpl extends BasicModule implements PacketDeliverer
deliverHandler.process(packet);
}
public void initialize(XMPPServer server) {
super.initialize(server);
messageStrategy = server.getOfflineMessageStrategy();
sessionManager = server.getSessionManager();
}
public void start() throws IllegalStateException {
super.start();
deliverHandler =
new SocketPacketWriteHandler(sessionManager,
XMPPServer.getInstance().getRoutingTable(), messageStrategy);
deliverHandler = new SocketPacketWriteHandler(XMPPServer.getInstance().getRoutingTable());
}
public void stop() {
......
......@@ -9,14 +9,15 @@ package org.jivesoftware.openfire.stun;
import de.javawi.jstun.test.demo.StunServer;
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.Log;
import org.jivesoftware.util.PropertyEventDispatcher;
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.PacketError;
......@@ -24,7 +25,10 @@ import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
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
......@@ -398,7 +402,7 @@ public class STUNService extends BasicModule {
server.addAttribute("udp", stunServerAddress.getPort());
}
try {
String ip = sessionManager.getSession(iq.getFrom()).getConnection().getInetAddress().getHostAddress();
String ip = sessionManager.getSession(iq.getFrom()).getHostAddress();
if (ip != null) {
Element publicIp = childElementCopy.addElement("publicip");
publicIp.addAttribute("ip", ip);
......
......@@ -68,6 +68,11 @@ public class DefaultLocalCacheStrategy implements CacheFactoryStrategy {
cacheNames.put("Routing Users Cache", "routeUser");
cacheNames.put("Routing AnonymousUsers Cache", "routeAnonymousUser");
cacheNames.put("Routing User Sessions", "routeUserSessions");
cacheNames.put("Session Manager Counters", "sessManagerCounters");
cacheNames.put("Components Sessions", "componentsSessions");
cacheNames.put("Connection Managers Sessions", "connManagerSessions");
cacheNames.put("Incoming Server Sessions", "incServerSessions");
cacheNames.put("Sessions by Hostname", "sessionsHostname");
cacheProps.put("cache.fileTransfer.size", 128 * 1024l);
cacheProps.put("cache.fileTransfer.expirationTime", 1000 * 60 * 10l);
......@@ -107,6 +112,16 @@ public class DefaultLocalCacheStrategy implements CacheFactoryStrategy {
cacheProps.put("cache.routeAnonymousUser.expirationTime", -1l);
cacheProps.put("cache.routeUserSessions.size", -1l);
cacheProps.put("cache.routeUserSessions.expirationTime", -1l);
cacheProps.put("cache.sessManagerCounters.size", -1l);
cacheProps.put("cache.sessManagerCounters.expirationTime", -1l);
cacheProps.put("cache.componentsSessions.size", -1l);
cacheProps.put("cache.componentsSessions.expirationTime", -1l);
cacheProps.put("cache.connManagerSessions.size", -1l);
cacheProps.put("cache.connManagerSessions.expirationTime", -1l);
cacheProps.put("cache.incServerSessions.size", -1l);
cacheProps.put("cache.incServerSessions.expirationTime", -1l);
cacheProps.put("cache.sessionsHostname.size", -1l);
cacheProps.put("cache.sessionsHostname.expirationTime", -1l);
}
......
......@@ -9,10 +9,10 @@
- a copy of which is included in this distribution.
--%>
<%@ page import="org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.ParamUtils,
org.jivesoftware.openfire.SessionManager,
org.jivesoftware.openfire.session.ComponentSession"
<%@ page import="org.jivesoftware.openfire.SessionManager,
org.jivesoftware.openfire.session.ComponentSession,
org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.ParamUtils"
errorPage="error.jsp"
%>
<%@ page import="java.text.NumberFormat" %>
......@@ -141,9 +141,9 @@
<fmt:message key="session.details.hostname" />
</td>
<td>
<%= componentSession.getConnection().getInetAddress().getHostAddress() %>
<%= componentSession.getHostAddress() %>
/
<%= componentSession.getConnection().getInetAddress().getHostName() %>
<%= componentSession.getHostName() %>
</td>
</tr>
</tbody>
......
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