Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: try to connect to parent xmpp domain #1876

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}