Skip to content

Commit

Permalink
fallback: try to connect to parent xmpp domain if no dns entry for su…
Browse files Browse the repository at this point in the history
…bdomain (service) was found...

add configuration property to enable/disable the fallback
  • Loading branch information
mightymop committed Dec 23, 2021
1 parent 6ebee74 commit 4aa803c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions i18n/src/main/resources/openfire_i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,8 @@ system_property.xmpp.taskengine.threadpool.size.core=The number of threads to ke
system_property.xmpp.taskengine.threadpool.size.max=The maximum number of threads to allow in the thread pool that is used to execute tasks of Openfire's TaskEngine.
system_property.xmpp.taskengine.threadpool.keepalive=The number of threads in the thread pool that is used to execute tasks of Openfire's TaskEngine is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.
system_property.xmpp.muc.allowpm.blockall=Toggles whether to block all packets from users or just messages if they do not have permission to send private messages.
system_property.xmpp.dns.usefallback=Use XMPP Domain host for service subdomains as fallback, if no dns entrys for subdomains were set.

# Server properties Page

server.properties.title=System Properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jivesoftware.openfire.net;

import org.jivesoftware.openfire.server.RemoteServerManager;
import org.jivesoftware.util.SystemProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -20,6 +21,11 @@ public class SocketUtil
{
private final static Logger Log = LoggerFactory.getLogger( SocketUtil.class );

public static final SystemProperty<Boolean> USE_FALLBACK = SystemProperty.Builder.ofType(Boolean.class)
.setKey("xmpp.dns.usefallback")
.setDefaultValue(false)
.setDynamic(true)
.build();
/**
* Creates a socket connection to an XMPP domain.
*
Expand All @@ -34,10 +40,11 @@ public class SocketUtil
*
* @param xmppDomain The XMPP domain to connect to.
* @param port The port to connect to when DNS resolution fails.
* @param tryparent try parent domain, if no connection could be established and fallback is enabled.
* @return a Socket instance that is connected, or null.
* @see DNSUtil#resolveXMPPDomain(String, int)
*/
public static Map.Entry<Socket, Boolean> createSocketToXmppDomain( String xmppDomain, int port )
public static Map.Entry<Socket, Boolean> createSocketToXmppDomain( String xmppDomain, int port, boolean tryparent)
{
Log.debug( "Creating a socket connection to XMPP domain '{}' ...", xmppDomain );

Expand Down Expand Up @@ -80,10 +87,25 @@ public static Map.Entry<Socket, Boolean> createSocketToXmppDomain( String xmppDo
{
Log.debug( "An additional exception occurred while trying to close a socket when creating a connection to {}:{} failed.", realHostname, realPort, ex );
}

/*
* Fallback: If no dns entry was found for xmpp service subdomain, try the xmpp (parent) domain itself.
* */
if (USE_FALLBACK.getValue()&&tryparent&&xmppDomain.contains("."))
{
String xmppDomainWithoutSubdomain = xmppDomain.substring(xmppDomain.indexOf(".")+1);
Log.info("Try to connect to parent domain {}:{}",xmppDomainWithoutSubdomain,port);
return createSocketToXmppDomain(xmppDomainWithoutSubdomain,port,false);
}
}
}

Log.warn( "Unable to create a socket connection to XMPP domain '{}': Unable to connect to any of its remote hosts.", xmppDomain );
return null;
}

public static Map.Entry<Socket, Boolean> createSocketToXmppDomain( String xmppDomain, int port )
{
return createSocketToXmppDomain(xmppDomain,port,true);
}
}

0 comments on commit 4aa803c

Please sign in to comment.