Skip to content

OF-1927: Show TCP port for server-to-server (S2S) connections in admin console#3233

Open
MilanTyagi2004 wants to merge 3 commits intoigniterealtime:mainfrom
MilanTyagi2004:OF-1927-Show-TCP-port-used-for-server-to-server-connection
Open

OF-1927: Show TCP port for server-to-server (S2S) connections in admin console#3233
MilanTyagi2004 wants to merge 3 commits intoigniterealtime:mainfrom
MilanTyagi2004:OF-1927-Show-TCP-port-used-for-server-to-server-connection

Conversation

@MilanTyagi2004
Copy link
Copy Markdown
Collaborator

Summary

Enhances the Openfire administrative console by displaying the TCP port used for server-to-server (S2S) connections on the "Remote Server Connections Details" page. This allows administrators to distinguish between standard S2S connections (typically port 5269) and direct TLS connections (typically port 5270).


Changes

Backend (Connection & Session Layers)

  • Added default getRemotePort() method to the Connection interface
  • Implemented getRemotePort() in:
    • NettyConnection (extracts port from Netty Channel)
    • SocketConnection (delegates to existing getPort() method)
  • Added default getHostPort() method to Session interface
  • Updated LocalSession to delegate port retrieval to the underlying Connection
  • Extended RemoteSession and RemoteSessionTask to support port retrieval in clustered environments

Administrative UI

  • Updated server-session-details.jsp to include a new "Port" column
    • Applies to both Incoming and Outgoing session tables
  • Reused existing i18n key ports.port for column header

Verification

Build

  • Command:
    mvn clean install -DskipTests -pl xmppserver
  • Result: BUILD SUCCESS

Manual Testing

  • Full end-to-end S2S verification requires a publicly reachable domain with proper DNS (A + SRV) and open port 5269.
  • This setup is not available in the current development environment, so a live S2S connection could not be established.

Functional Validation

  • Code paths verified to correctly retrieve and expose the remote port from:
    • NettyConnection (via Channel)
    • SocketConnection (via existing port method)
  • UI rendering verified to correctly display the Port column when session data includes port values.

@MilanTyagi2004
Copy link
Copy Markdown
Collaborator Author

hey @guusdk manual test won't happen because to build connection btw servers, need hosting that's why i am not able to check

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances Openfire’s admin console “Remote Server Connections Details” page by exposing and displaying the TCP port used for S2S connections, enabling admins to distinguish standard S2S vs direct TLS connections.

Changes:

  • Adds port accessors (Connection#getRemotePort() and Session#getHostPort()) with implementations for Socket- and Netty-based connections.
  • Extends clustered session plumbing (RemoteSession/RemoteSessionTask) to retrieve the port from remote cluster nodes.
  • Updates server-session-details.jsp to display a new “Port” column for incoming and outgoing server sessions.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
xmppserver/src/main/webapp/server-session-details.jsp Adds a Port column and renders ${session.hostPort} in incoming/outgoing S2S tables.
xmppserver/src/main/java/org/jivesoftware/openfire/session/Session.java Introduces default getHostPort() API.
xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalSession.java Implements getHostPort() by delegating to the underlying connection.
xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSession.java Caches and fetches host port via cluster task.
xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSessionTask.java Adds a new clustered operation to fetch host port.
xmppserver/src/main/java/org/jivesoftware/openfire/session/IncomingServerSessionTask.java Adds a default case to the operation switch.
xmppserver/src/main/java/org/jivesoftware/openfire/nio/NettyConnection.java Implements getRemotePort() using Netty channel remote address.
xmppserver/src/main/java/org/jivesoftware/openfire/net/SocketConnection.java Implements getRemotePort() by delegating to existing getPort().
xmppserver/src/main/java/org/jivesoftware/openfire/Connection.java Introduces default getRemotePort() API.
Comments suppressed due to low confidence (1)

xmppserver/src/main/java/org/jivesoftware/openfire/session/RemoteSessionTask.java:226

  • RemoteSessionTask serializes the operation using operation.ordinal() and deserializes using Operation.values()[...]. Adding the new enum constant getHostPort in the middle of the enum changes the ordinal values of all subsequent constants (e.g., validate/removeDetached/markNonResumable), which can cause nodes on different versions (or persisted/queued tasks) to execute the wrong operation. To keep cluster serialization stable, append new enum constants to the end (or switch serialization to a stable identifier like the enum name with backwards-compatible parsing).
    public void writeExternal(ObjectOutput out) throws IOException {
        ExternalizableUtil.getInstance().writeBoolean(out, operation != null);
        if (operation != null) {
            ExternalizableUtil.getInstance().writeInt(out, operation.ordinal());
        }
    }

    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        if (ExternalizableUtil.getInstance().readBoolean(in)) {
            operation = Operation.values()[ExternalizableUtil.getInstance().readInt(in)];
        }
    }

    public enum Operation {
        /**
         * Basic session operations
         */
        getStreamID,
        getServerName,
        getCreationDate,
        getLastActiveDate,
        getNumClientPackets,
        getNumServerPackets,
        getTLSProtocolName,
        getCipherSuiteName,
        getPeerCertificates,
        getSoftwareVersion,
        close,
        isClosed,
        isDetached,
        isEncrypted,
        getHostAddress,
        getHostName,
        getHostPort,
        validate,
        removeDetached,
        markNonResumable,
        
        /**

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

</c:choose>
<td><c:out value="${session.TLSProtocolName}"/></td>
<td><c:out value="${session.cipherSuiteName}"/></td>
<td><c:out value="${session.hostPort}"/></td>
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UI will render the integer returned by session.hostPort even when the backend uses 0 to mean "not available" (e.g., detached session / unknown remote address). This will show a confusing port value of 0 in the table. Consider rendering an empty value or placeholder when hostPort <= 0 to avoid implying a real TCP port.

Suggested change
<td><c:out value="${session.hostPort}"/></td>
<td>
<c:choose>
<c:when test="${session.hostPort gt 0}">
<c:out value="${session.hostPort}"/>
</c:when>
<c:otherwise>&nbsp;</c:otherwise>
</c:choose>
</td>

Copilot uses AI. Check for mistakes.
Comment on lines 197 to +206
String getHostAddress() throws UnknownHostException;

/**
* Returns the port that the connection uses.
*
* @return the port that the connection uses.
*/
default int getHostPort() {
return 0;
}
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Javadoc for getHostPort says "Returns the port that the connection uses" but does not document what the default implementation returning 0 means. Consider clarifying that 0 indicates that the port is unknown/unavailable, to match the Connection#getRemotePort contract and avoid callers treating 0 as a real port.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid that copilot cannot apply changes (even if it says it can) in this repository. You'll have to do that manually.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay Guus.

Comment thread xmppserver/src/main/java/org/jivesoftware/openfire/Connection.java Outdated
@guusdk
Copy link
Copy Markdown
Member

guusdk commented Apr 3, 2026

@MilanTyagi2004 thanks for doing this! Copilot found some small but good things to improve. If this relates to a JIRA issue, can you please mention the JIRA number in the commit message? That way, automation will link the ticket to the code change.

@MilanTyagi2004 MilanTyagi2004 changed the title Show TCP port for server-to-server (S2S) connections in admin console OF-1927: Show TCP port for server-to-server (S2S) connections in admin console Apr 4, 2026
@MilanTyagi2004
Copy link
Copy Markdown
Collaborator Author

@guusdk changes are done.

Copy link
Copy Markdown
Member

@guusdk guusdk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good, apart from the Copilot comment that you can address, I'd also like you to see if you can settle on either remotePort or hostPort to identify the port used by the peer (I think I prefer 'remote' as it clearly signals that we're talking about the post used by the other party). Having two different names for basically the same thing is a bit confusing.

Comment on lines 197 to +206
String getHostAddress() throws UnknownHostException;

/**
* Returns the port that the connection uses.
*
* @return the port that the connection uses.
*/
default int getHostPort() {
return 0;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid that copilot cannot apply changes (even if it says it can) in this repository. You'll have to do that manually.

@MilanTyagi2004
Copy link
Copy Markdown
Collaborator Author

sure, Guus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants