Commit 348af2f5 authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

PEP: Server to server, remote presence related functionality is now working...

PEP: Server to server, remote presence related functionality is now working correctly. Bugs related to lack of remote presence information are now all fixed.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches@8913 b35dd754-fafc-0310-a699-88a17e54d16e
parent ae3f3bc6
...@@ -108,6 +108,15 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -108,6 +108,15 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
private PubSubEngine pubSubEngine = null; private PubSubEngine pubSubEngine = null;
/**
* A map of all known full JIDs that have sent presences from a remote server.
* table: key Bare JID (String); value HashSet of JIDs
*
* This map is convenient for sending notifications to the full JID of remote users
* that have sent available presences to the PEP service.
*/
private Map<String, HashSet<JID>> knownRemotePresences = new ConcurrentHashMap<String, HashSet<JID>>();
private static final String GET_PEP_SERVICES = "SELECT DISTINCT serviceID FROM pubsubNode"; private static final String GET_PEP_SERVICES = "SELECT DISTINCT serviceID FROM pubsubNode";
public IQPEPHandler() { public IQPEPHandler() {
...@@ -432,7 +441,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -432,7 +441,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
// On newly-available presences, send the last published item if the resource is a subscriber. // On newly-available presences, send the last published item if the resource is a subscriber.
JID newlyAvailableJID = presence.getFrom(); JID newlyAvailableJID = presence.getFrom();
PresenceManager presenceManager = XMPPServer.getInstance().getPresenceManager(); PresenceManager presenceManager = XMPPServer.getInstance().getPresenceManager();
for (PEPService pepService : pepServices.values()) { for (PEPService pepService : pepServices.values()) {
...@@ -452,12 +461,12 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -452,12 +461,12 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
lastPublishedItem = leafLastPublishedItem; lastPublishedItem = leafLastPublishedItem;
continue; continue;
} }
if (leafLastPublishedItem.getCreationDate().compareTo(lastPublishedItem.getCreationDate()) > 0) { if (leafLastPublishedItem.getCreationDate().compareTo(lastPublishedItem.getCreationDate()) > 0) {
lastPublishedItem = leafLastPublishedItem; lastPublishedItem = leafLastPublishedItem;
} }
} }
// Send last published item to the newly-available resource. // Send last published item to the newly-available resource.
NodeSubscription subscription = rootNode.getSubscription(newlyAvailableJID); NodeSubscription subscription = rootNode.getSubscription(newlyAvailableJID);
if (subscription == null) { if (subscription == null) {
...@@ -537,7 +546,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -537,7 +546,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
if (featureVar == null) { if (featureVar == null) {
continue; continue;
} }
supportedNodesSet.add(featureVar); supportedNodesSet.add(featureVar);
} }
...@@ -572,11 +581,11 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -572,11 +581,11 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
else { else {
// Remove the nodeID from the sender's filteredNodesSet if nodeIDPlusNotify // Remove the nodeID from the sender's filteredNodesSet if nodeIDPlusNotify
// is not in supportedNodesSet. // is not in supportedNodesSet.
HashSet<String> filteredNodesSet = filteredNodesMap.get(jidFrom); HashSet<String> filteredNodesSet = filteredNodesMap.get(jidFrom);
if (filteredNodesSet == null) { if (filteredNodesSet == null) {
return; return;
} }
String nodeIDPlusNotify = nodeID + "+notify"; String nodeIDPlusNotify = nodeID + "+notify";
if (!supportedNodesSet.contains(nodeIDPlusNotify) && filteredNodesSet.remove(nodeIDPlusNotify)) { if (!supportedNodesSet.contains(nodeIDPlusNotify) && filteredNodesSet.remove(nodeIDPlusNotify)) {
...@@ -594,31 +603,44 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -594,31 +603,44 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
else if (incoming && processed && packet instanceof Presence) { else if (incoming && processed && packet instanceof Presence) {
// Cache newly-available presence resources for remote users (since the PresenceEventDispatcher // Cache newly-available presence resources for remote users (since the PresenceEventDispatcher
// methods are not called for remote presence events). // methods are not called for remote presence events).
JID jidFrom = packet.getFrom(); JID jidFrom = packet.getFrom();
if (!XMPPServer.getInstance().isLocal(jidFrom) && packet.getTo() != null) { JID jidTo = packet.getTo();
if (!XMPPServer.getInstance().isLocal(jidFrom) && jidTo != null) {
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("PEP: received presence from: " + packet.getFrom() + " to: " + packet.getTo()); Log.debug("PEP: received presence from: " + jidFrom + " to: " + jidTo);
} }
for (PEPService service : pepServices.values()) { HashSet<JID> remotePresenceSet = knownRemotePresences.get(jidTo.toBareJID());
if (service.getAddress().toString().equals(packet.getTo().toString())) { Presence.Type type = ((Presence) packet).getType();
Presence.Type type = ((Presence) packet).getType();
if (type != null && type == Presence.Type.unavailable) { if (type != null && type == Presence.Type.unavailable) {
if (service.removeRemotePresence(jidFrom)) { if (remotePresenceSet != null && remotePresenceSet.remove(jidFrom)) {
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("PEP: removed " + jidFrom + " from " + service.getAddress() + "'s knownRemotePresences"); Log.debug("PEP: removed " + jidFrom + " from " + jidTo + "'s knownRemotePresences");
} }
}
}
else if (jidFrom.getResource() != null) {
if (remotePresenceSet != null) {
if (remotePresenceSet.add(jidFrom)) {
if (Log.isDebugEnabled()) {
Log.debug("PEP: added " + jidFrom + " to " + jidTo + "'s knownRemotePresences");
} }
} }
else if (jidFrom.getResource() != null && service.addRemotePresence(jidFrom)) { }
else {
remotePresenceSet = new HashSet<JID>();
if (remotePresenceSet.add(jidFrom)) {
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("PEP: added " + jidFrom + " to " + service.getAddress() + "'s knownRemotePresences"); Log.debug("PEP: added " + jidFrom + " to " + jidTo + "'s knownRemotePresences");
} }
knownRemotePresences.put(jidTo.toBareJID(), remotePresenceSet);
// Send last published item for newly-available remote resource.
availableSession((ClientSession) session, (Presence) packet);
} }
} }
// Send last published item for newly-available remote resource.
availableSession((ClientSession) session, (Presence) packet);
} }
} }
} }
...@@ -633,4 +655,13 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -633,4 +655,13 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
return filteredNodesMap; return filteredNodesMap;
} }
/**
* Returns the knownRemotePresences map.
*
* @return the knownRemotePresences map
*/
public Map<String, HashSet<JID>> getKnownRemotePresenes() {
return knownRemotePresences;
}
} }
...@@ -152,13 +152,6 @@ public class PEPService implements PubSubService { ...@@ -152,13 +152,6 @@ public class PEPService implements PubSubService {
*/ */
private static final FastDateFormat fastDateFormat; private static final FastDateFormat fastDateFormat;
/**
* A cache of all known full JIDs that have sent presences from a remote server.
* This set is convenient for sending notifications to the full JID of remote users
* that have sent available presences to the PEP service.
*/
private HashSet<JID> knownRemotePresences = new HashSet<JID>();
static { static {
fastDateFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("UTC")); fastDateFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("UTC"));
} }
...@@ -350,9 +343,15 @@ public class PEPService implements PubSubService { ...@@ -350,9 +343,15 @@ public class PEPService implements PubSubService {
else { else {
// Since recipientJID is not local, try to get presence info from cached known remote // Since recipientJID is not local, try to get presence info from cached known remote
// presences. // presences.
for (JID remotePresence : knownRemotePresences) { Map<String, HashSet<JID>> knownRemotePresences =
if (recipientJID.toBareJID().equals(remotePresence.toBareJID())) { XMPPServer.getInstance().getIQPEPHandler().getKnownRemotePresenes();
recipientFullJIDs.add(remotePresence);
HashSet<JID> remotePresenceSet = knownRemotePresences.get(getAddress().toBareJID());
if (remotePresenceSet != null) {
for (JID remotePresence : remotePresenceSet) {
if (recipientJID.toBareJID().equals(remotePresence.toBareJID())) {
recipientFullJIDs.add(remotePresence);
}
} }
} }
} }
...@@ -562,12 +561,4 @@ public class PEPService implements PubSubService { ...@@ -562,12 +561,4 @@ public class PEPService implements PubSubService {
return false; return false;
} }
public boolean addRemotePresence(JID jidFrom) {
return knownRemotePresences.add(jidFrom);
}
public boolean removeRemotePresence(JID jidFrom) {
return knownRemotePresences.remove(jidFrom);
}
} }
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