Commit f4ae954e 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/pep@8913 b35dd754-fafc-0310-a699-88a17e54d16e
parent b56639ef
......@@ -108,6 +108,15 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
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";
public IQPEPHandler() {
......@@ -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.
JID newlyAvailableJID = presence.getFrom();
PresenceManager presenceManager = XMPPServer.getInstance().getPresenceManager();
for (PEPService pepService : pepServices.values()) {
......@@ -452,12 +461,12 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
lastPublishedItem = leafLastPublishedItem;
continue;
}
if (leafLastPublishedItem.getCreationDate().compareTo(lastPublishedItem.getCreationDate()) > 0) {
lastPublishedItem = leafLastPublishedItem;
}
}
// Send last published item to the newly-available resource.
NodeSubscription subscription = rootNode.getSubscription(newlyAvailableJID);
if (subscription == null) {
......@@ -537,7 +546,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
if (featureVar == null) {
continue;
}
supportedNodesSet.add(featureVar);
}
......@@ -572,11 +581,11 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
else {
// Remove the nodeID from the sender's filteredNodesSet if nodeIDPlusNotify
// is not in supportedNodesSet.
HashSet<String> filteredNodesSet = filteredNodesMap.get(jidFrom);
HashSet<String> filteredNodesSet = filteredNodesMap.get(jidFrom);
if (filteredNodesSet == null) {
return;
}
String nodeIDPlusNotify = nodeID + "+notify";
if (!supportedNodesSet.contains(nodeIDPlusNotify) && filteredNodesSet.remove(nodeIDPlusNotify)) {
......@@ -594,31 +603,44 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
else if (incoming && processed && packet instanceof Presence) {
// Cache newly-available presence resources for remote users (since the PresenceEventDispatcher
// methods are not called for remote presence events).
JID jidFrom = packet.getFrom();
if (!XMPPServer.getInstance().isLocal(jidFrom) && packet.getTo() != null) {
JID jidFrom = packet.getFrom();
JID jidTo = packet.getTo();
if (!XMPPServer.getInstance().isLocal(jidFrom) && jidTo != null) {
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()) {
if (service.getAddress().toString().equals(packet.getTo().toString())) {
Presence.Type type = ((Presence) packet).getType();
if (type != null && type == Presence.Type.unavailable) {
if (service.removeRemotePresence(jidFrom)) {
if (Log.isDebugEnabled()) {
Log.debug("PEP: removed " + jidFrom + " from " + service.getAddress() + "'s knownRemotePresences");
}
HashSet<JID> remotePresenceSet = knownRemotePresences.get(jidTo.toBareJID());
Presence.Type type = ((Presence) packet).getType();
if (type != null && type == Presence.Type.unavailable) {
if (remotePresenceSet != null && remotePresenceSet.remove(jidFrom)) {
if (Log.isDebugEnabled()) {
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()) {
Log.debug("PEP: added " + jidFrom + " to " + service.getAddress() + "'s knownRemotePresences");
Log.debug("PEP: added " + jidFrom + " to " + jidTo + "'s knownRemotePresences");
}
// Send last published item for newly-available remote resource.
availableSession((ClientSession) session, (Presence) packet);
knownRemotePresences.put(jidTo.toBareJID(), remotePresenceSet);
}
}
// 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,
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 {
*/
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 {
fastDateFormat = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", TimeZone.getTimeZone("UTC"));
}
......@@ -350,9 +343,15 @@ public class PEPService implements PubSubService {
else {
// Since recipientJID is not local, try to get presence info from cached known remote
// presences.
for (JID remotePresence : knownRemotePresences) {
if (recipientJID.toBareJID().equals(remotePresence.toBareJID())) {
recipientFullJIDs.add(remotePresence);
Map<String, HashSet<JID>> knownRemotePresences =
XMPPServer.getInstance().getIQPEPHandler().getKnownRemotePresenes();
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 {
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