Commit ace9198a authored by Dave Cridland's avatar Dave Cridland

Merge pull request #463 from guusdk/OF-1008

OF-1008: Prevent loops of message failure
parents 17006e28 8f515822
...@@ -20,13 +20,6 @@ ...@@ -20,13 +20,6 @@
package org.jivesoftware.openfire; package org.jivesoftware.openfire;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.openfire.container.BasicModule; import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.handler.IQHandler; import org.jivesoftware.openfire.handler.IQHandler;
...@@ -43,11 +36,10 @@ import org.jivesoftware.util.TaskEngine; ...@@ -43,11 +36,10 @@ import org.jivesoftware.util.TaskEngine;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xmpp.component.IQResultListener; import org.xmpp.component.IQResultListener;
import org.xmpp.packet.IQ; import org.xmpp.packet.*;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import java.util.*;
import org.xmpp.packet.Packet; import java.util.concurrent.ConcurrentHashMap;
import org.xmpp.packet.PacketError;
/** /**
* Routes iq packets throughout the server. Routing is based on the recipient * Routes iq packets throughout the server. Routing is based on the recipient
...@@ -468,21 +460,19 @@ public class IQRouter extends BasicModule { ...@@ -468,21 +460,19 @@ public class IQRouter 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 recipient.
* *
* @param receipient address of the entity that failed to receive the packet. * @param recipient address of the entity that failed to receive the packet.
* @param packet IQ packet that failed to be sent to the receipient. * @param packet IQ packet that failed to be sent to the recipient.
*/ */
public void routingFailed(JID receipient, Packet packet) { public void routingFailed( JID recipient, Packet packet )
IQ iq = (IQ) packet; {
// If a route to the target address was not found then try to answer a Log.debug( "IQ sent to unreachable address: " + packet.toXML() );
// service_unavailable error code to the sender of the IQ packet final IQ iq = (IQ) packet;
if (IQ.Type.result != iq.getType() && IQ.Type.error != iq.getType()) { // If a route to the target address was not found then try to answer a service_unavailable error code to the sender of the IQ packet
Log.info("Packet sent to unreachable address " + packet.toXML()); if ( iq.isRequest() )
sendErrorPacket(iq, PacketError.Condition.service_unavailable); {
} sendErrorPacket( iq, PacketError.Condition.service_unavailable );
else {
Log.warn("Error or result packet could not be delivered " + packet.toXML());
} }
} }
......
...@@ -246,20 +246,21 @@ public class MessageRouter extends BasicModule { ...@@ -246,20 +246,21 @@ public class MessageRouter extends BasicModule {
* @param recipient address of the entity that failed to receive the packet. * @param recipient address of the entity that failed to receive the packet.
* @param packet Message packet that failed to be sent to the recipient. * @param packet Message packet that failed to be sent to the recipient.
*/ */
public void routingFailed(JID recipient, Packet packet) { public void routingFailed( JID recipient, Packet packet )
// If message was sent to an unavailable full JID of a user then retry using the bare JID {
if (serverName.equals(recipient.getDomain()) && recipient.getResource() != null && log.debug( "Message sent to unreachable address: " + packet.toXML() );
userManager.isRegisteredUser(recipient.getNode())) { final Message msg = (Message) packet;
Message msg = (Message)packet;
if (msg.getType().equals(Message.Type.chat)) { if ( msg.getType().equals( Message.Type.chat ) && serverName.equals( recipient.getDomain() ) && recipient.getResource() != null
routingTable.routePacket(recipient.asBareJID(), packet, false); && routingTable.hasClientRoute( recipient.asBareJID() ) )
} else { {
// Delegate to offline message strategy, which will either bounce or ignore the message depending on user settings. // If message was sent to an unavailable full JID of a user then retry using the bare JID.
messageStrategy.storeOffline((Message) packet); routingTable.routePacket( recipient.asBareJID(), packet, false );
} }
} else { else
// Just store the message offline {
messageStrategy.storeOffline((Message) packet); // Delegate to offline message strategy, which will either bounce or ignore the message depending on user settings.
messageStrategy.storeOffline( (Message) packet );
} }
} }
} }
...@@ -31,11 +31,7 @@ import org.jivesoftware.openfire.session.Session; ...@@ -31,11 +31,7 @@ import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID; import org.xmpp.packet.*;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence;
/** /**
* <p>Route presence packets throughout the server.</p> * <p>Route presence packets throughout the server.</p>
...@@ -219,12 +215,14 @@ public class PresenceRouter extends BasicModule { ...@@ -219,12 +215,14 @@ 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 recipient.
* *
* @param receipient address of the entity that failed to receive the packet. * @param recipient 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 recipient.
*/ */
public void routingFailed(JID receipient, Packet packet) { public void routingFailed( JID recipient, Packet packet )
{
Log.debug( "Presence sent to unreachable address: " + packet.toXML() );
// presence packets are dropped silently // presence packets are dropped silently
} }
} }
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