-
Notifications
You must be signed in to change notification settings - Fork 470
Add Reverse Connect support #1716
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
Open
kevinherron
wants to merge
52
commits into
main
Choose a base branch
from
feature/reverse-connect
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
5f80e80
Add .mcp.json to .gitignore
kevinherron a5221ea
Add ReverseHello message type and transport layer support
kevinherron 0da25f2
Add Reverse Connect support to SDK client and server APIs
kevinherron fae23ff
Add Reverse Connect tests and examples
kevinherron d3a1549
Add Reverse Connect architecture documentation
kevinherron cb302dd
Update docs/architecture/reverse-connect.md
kevinherron a05753c
Update opc-ua-stack/stack-core/src/main/java/org/eclipse/milo/opcua/s…
kevinherron dfb1e0e
Update opc-ua-stack/stack-core/src/main/java/org/eclipse/milo/opcua/s…
kevinherron 60ee5b5
Handle keep-alive channel close for reverse-connect transport
kevinherron 179c15d
Fix thread safety and deadlock in reverse connect shutdown
kevinherron c54e3c9
Add reverse connect unit and integration tests
kevinherron 7003848
Document Maven module targeting flags
kevinherron 7be168d
Fix inaccuracies in reverse connect architecture documentation
kevinherron 3dda5de
Fire SecureChannelOpenedEvent only after successful write of OpenSecu…
Copilot 778977d
Replace `assert` with runtime checks in TcpMessageDecoder (#1718)
Copilot 669d136
Convert ReverseHelloMessage to a Java record
kevinherron 940e56d
Fix bind failure handling and disconnect pending future in reverse co…
kevinherron b178cb2
Add connect timeout for reverse connect discovery and client flows
kevinherron e43b5dc
Fix thread safety and restart robustness in ReverseConnectManager
kevinherron 6da156d
Update opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk…
kevinherron 561679e
Update opc-ua-stack/transport/src/main/java/org/eclipse/milo/opcua/st…
kevinherron 8191f72
Update opc-ua-sdk/sdk-server/src/main/java/org/eclipse/milo/opcua/sdk…
kevinherron 93e4523
Update test to match per-handle removal behavior in removeReverseConnect
kevinherron 5911667
Address PR review feedback for reverse connect cleanup and logging
kevinherron 58dff21
Reject duplicate inbound connections during reverse connect handshake
kevinherron 9c41b0a
Add multiplexed reverse connect transport for shared-port multi-serve…
kevinherron 3dd49a5
Fix flaky rateLimitingHandlerInstalled test
kevinherron bf6e61e
Fix reverse connect timeout race and add multiplexed transport to kee…
kevinherron 9339084
Fix ReDoS vulnerability in endpoint URL regex
kevinherron 2da99db
Update reverse connect architecture doc
kevinherron 745151e
Fix flaky reconnectionAfterChannelDrop secure channel race
kevinherron 8da4b29
Clean up auto-spawned idle FSMs on reverse connect handle removal
kevinherron 7f02fd3
Fix IntelliJ inspection warnings across reverse connect files
kevinherron 3eaae84
Merge branch 'main' into feature/reverse-connect
kevinherron 4dd8294
flowmark
kevinherron d6fd97f
Move vendor-specific client examples into subpackages
kevinherron b1406f1
Add self-contained reverse connect examples
kevinherron 57bf473
Use 3-arg ExampleServer constructor in ReverseConnectExample
kevinherron 42d2bad
Fix deadlock in ReverseConnectManager ensureIdleConnection callback
kevinherron 6542ca3
Add null checks for type definition nodes in NodeFactory
kevinherron 348f40e
Fix FSM race conditions in ReverseConnectChannelFsm
kevinherron 01dfffe
Fix deadlock in OpcTcpReverseConnectTransport disconnect
kevinherron 3b23d98
Prevent duplicate idle FSM creation in ReverseConnectManager
kevinherron ed5943d
Release discarded reverse connect test messages
kevinherron 03719a5
Fail fast on ReverseHello write errors
kevinherron 83468ed
Clean up reverse connect child sockets
kevinherron 5bd92fd
Avoid duplicate idle spawn on handle replacement
kevinherron 7aefba8
Guard reverse connect registration on stop
kevinherron 6d2ee79
Honor stop during reverse connect connect
kevinherron 6d29f03
Serialize reverse connect manager lifecycle
kevinherron ab30d85
Close orphaned reverse connect channels
kevinherron d140b26
Enforce reverse connect limit atomically
kevinherron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,3 +34,6 @@ CLAUDE.local.md | |
|
|
||
| # External src and other files | ||
| external/ | ||
|
|
||
| # Claude project MCP configuration | ||
| .mcp.json | ||
Large diffs are not rendered by default.
Oops, something went wrong.
114 changes: 114 additions & 0 deletions
114
...-examples/src/main/java/org/eclipse/milo/examples/client/ReverseConnectExampleProsys.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * Copyright (c) 2026 the Eclipse Milo Authors | ||
| * | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
|
|
||
| package org.eclipse.milo.examples.client; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| import java.net.InetSocketAddress; | ||
| import java.security.Security; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.bouncycastle.jce.provider.BouncyCastleProvider; | ||
| import org.eclipse.milo.opcua.sdk.client.OpcUaClient; | ||
| import org.eclipse.milo.opcua.stack.core.NodeIds; | ||
| import org.eclipse.milo.opcua.stack.core.Stack; | ||
| import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy; | ||
| import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; | ||
| import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText; | ||
| import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId; | ||
| import org.eclipse.milo.opcua.stack.core.types.enumerated.MessageSecurityMode; | ||
| import org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState; | ||
| import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn; | ||
| import org.eclipse.milo.opcua.stack.transport.client.tcp.OpcTcpReverseConnectTransportConfig; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Example demonstrating OPC UA Reverse Connect with the Prosys OPC UA Simulation Server. | ||
| * | ||
| * <p>In Reverse Connect, the client listens for inbound connections from the server. The Prosys | ||
| * Simulation Server must be configured to initiate reverse connections to this client's listen | ||
| * address (default: opc.tcp://localhost:48060). | ||
| * | ||
| * <p>Setup steps for the Prosys OPC UA Simulation Server: | ||
| * | ||
| * <ol> | ||
| * <li>Open the Prosys OPC UA Simulation Server. | ||
| * <li>Navigate to the Endpoints tab, Reverse Connections section. | ||
| * <li>Add a new reverse connection with Client URL: opc.tcp://localhost:48060 | ||
| * <li>Restart the server. | ||
| * <li>Run this example — it will wait for the server to connect. | ||
| * </ol> | ||
| * | ||
| * <p>This example uses {@link SecurityPolicy#None} for simplicity. For secured connections, see | ||
| * {@link KeyStoreLoader} and the certificate setup in {@link ClientExampleRunner}. | ||
| */ | ||
| public class ReverseConnectExampleProsys { | ||
|
|
||
| /** | ||
| * The address this client listens on for inbound server connections. Configure the Prosys server | ||
| * to reverse-connect to this address. | ||
| */ | ||
| private static final InetSocketAddress LISTEN_ADDRESS = new InetSocketAddress("localhost", 48060); | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(ReverseConnectExampleProsys.class); | ||
|
|
||
| static { | ||
| Security.addProvider(new BouncyCastleProvider()); | ||
| } | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| OpcUaClient client = createClient(); | ||
|
|
||
| try { | ||
| logger.info("Waiting for Prosys server to reverse-connect to {}...", LISTEN_ADDRESS); | ||
|
|
||
| client.connectAsync().get(30, TimeUnit.SECONDS); | ||
|
|
||
| logger.info("Connected via Reverse Connect."); | ||
|
|
||
| // Read server state and current time | ||
| List<NodeId> nodeIds = | ||
| List.of(NodeIds.Server_ServerStatus_State, NodeIds.Server_ServerStatus_CurrentTime); | ||
|
|
||
| List<DataValue> values = | ||
| client.readValuesAsync(0.0, TimestampsToReturn.Both, nodeIds).get(5, TimeUnit.SECONDS); | ||
|
|
||
| DataValue stateValue = values.get(0); | ||
| DataValue timeValue = values.get(1); | ||
|
|
||
| logger.info( | ||
| "State={}", ServerState.from((Integer) requireNonNull(stateValue.value().value()))); | ||
| logger.info("CurrentTime={}", timeValue.value().value()); | ||
| } finally { | ||
| client.disconnectAsync().get(5, TimeUnit.SECONDS); | ||
| Stack.releaseSharedResources(); | ||
| } | ||
| } | ||
|
|
||
| private static OpcUaClient createClient() throws Exception { | ||
| var transportConfig = | ||
| OpcTcpReverseConnectTransportConfig.newBuilder().setListenAddress(LISTEN_ADDRESS).build(); | ||
|
|
||
| return OpcUaClient.createReverseConnect( | ||
| transportConfig, | ||
| endpoints -> | ||
| endpoints.stream() | ||
| .filter(e -> SecurityPolicy.None.getUri().equals(e.getSecurityPolicyUri())) | ||
| .filter(e -> e.getSecurityMode() == MessageSecurityMode.None) | ||
| .findFirst(), | ||
| clientConfig -> | ||
| clientConfig | ||
| .setApplicationName(LocalizedText.english("eclipse milo opc-ua client")) | ||
| .setApplicationUri("urn:eclipse:milo:examples:client")) | ||
| .get(60, TimeUnit.SECONDS); | ||
| } | ||
| } |
176 changes: 176 additions & 0 deletions
176
...on-tests/src/test/java/org/eclipse/milo/opcua/sdk/client/ReverseConnectDiscoveryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| /* | ||
| * Copyright (c) 2025 the Eclipse Milo Authors | ||
| * | ||
| * This program and the accompanying materials are made | ||
| * available under the terms of the Eclipse Public License 2.0 | ||
| * which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
|
|
||
| package org.eclipse.milo.opcua.sdk.client; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.net.InetSocketAddress; | ||
| import java.time.Duration; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.eclipse.milo.opcua.sdk.server.EndpointConfig; | ||
| import org.eclipse.milo.opcua.sdk.server.OpcUaServer; | ||
| import org.eclipse.milo.opcua.sdk.server.ReverseConnectHandle; | ||
| import org.eclipse.milo.opcua.sdk.server.ReverseConnectManager; | ||
| import org.eclipse.milo.opcua.sdk.test.TestServer; | ||
| import org.eclipse.milo.opcua.stack.core.types.structured.ApplicationDescription; | ||
| import org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription; | ||
| import org.eclipse.milo.opcua.stack.transport.client.tcp.OpcTcpReverseConnectTransportConfig; | ||
| import org.eclipse.milo.opcua.stack.transport.server.tcp.OpcTcpServerTransportConfig; | ||
| import org.eclipse.milo.opcua.stack.transport.server.tcp.ReverseConnectConfig; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.TestInstance; | ||
|
|
||
| /** | ||
| * Integration tests for the {@link DiscoveryClient} static Reverse Connect discovery methods: | ||
| * {@link DiscoveryClient#getEndpoints(OpcTcpReverseConnectTransportConfig)} and {@link | ||
| * DiscoveryClient#findServers(OpcTcpReverseConnectTransportConfig)}. | ||
| * | ||
| * <p>A fixed listen port is used because the static methods create and manage the transport | ||
| * internally, so the test cannot extract an OS-assigned ephemeral port via reflection. The server's | ||
| * retry loop (500ms interval) quickly finds the client once the listening socket opens. | ||
| */ | ||
| @TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
| class ReverseConnectDiscoveryTest { | ||
|
|
||
| /** | ||
| * Fixed listen port. The static {@link DiscoveryClient} methods manage the transport internally, | ||
| * so the test cannot read an OS-assigned ephemeral port. See class Javadoc. | ||
| */ | ||
| private static final int LISTEN_PORT = 48070; | ||
|
|
||
| private static final long TIMEOUT_SECONDS = 30; | ||
|
kevinherron marked this conversation as resolved.
|
||
|
|
||
| private OpcUaServer server; | ||
|
|
||
| @BeforeAll | ||
| void setUp() throws Exception { | ||
| TestServer testServer = TestServer.create(); | ||
| server = testServer.getServer(); | ||
|
|
||
| ReverseConnectConfig rcConfig = | ||
| ReverseConnectConfig.newBuilder() | ||
| .setConnectInterval(Duration.ofMillis(500)) | ||
| .setConnectTimeout(Duration.ofSeconds(5)) | ||
| .setRejectBackoff(Duration.ofMillis(500)) | ||
| .setMaxReconnectDelay(Duration.ofSeconds(2)) | ||
| .build(); | ||
|
|
||
| OpcTcpServerTransportConfig transportConfig = OpcTcpServerTransportConfig.newBuilder().build(); | ||
|
|
||
| var manager = new ReverseConnectManager(rcConfig, transportConfig); | ||
| server.setReverseConnectManager(manager); | ||
| server.startup().get(); | ||
| } | ||
|
|
||
| @AfterAll | ||
| void tearDown() throws Exception { | ||
| server.shutdown().get(10, TimeUnit.SECONDS); | ||
| } | ||
|
|
||
| @Test | ||
| void getEndpointsViaReverseConnect() throws Exception { | ||
| var config = | ||
| OpcTcpReverseConnectTransportConfig.newBuilder() | ||
| .setListenAddress(new InetSocketAddress("localhost", LISTEN_PORT)) | ||
| .build(); | ||
|
|
||
| ReverseConnectHandle handle = | ||
| server.addReverseConnect("opc.tcp://localhost:" + LISTEN_PORT, getServerEndpointUrl()); | ||
|
|
||
| try { | ||
| List<EndpointDescription> endpoints = | ||
| DiscoveryClient.getEndpoints(config).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); | ||
|
|
||
| assertFalse(endpoints.isEmpty(), "expected at least one endpoint"); | ||
|
|
||
| String serverAppUri = server.getConfig().getApplicationUri(); | ||
| assertTrue( | ||
| endpoints.stream() | ||
| .anyMatch( | ||
| e -> | ||
| e.getServer() != null | ||
| && serverAppUri.equals(e.getServer().getApplicationUri())), | ||
| "expected an endpoint with the server's application URI"); | ||
| } finally { | ||
| server.removeReverseConnect(handle); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void findServersViaReverseConnect() throws Exception { | ||
| var config = | ||
| OpcTcpReverseConnectTransportConfig.newBuilder() | ||
| .setListenAddress(new InetSocketAddress("localhost", LISTEN_PORT)) | ||
| .build(); | ||
|
|
||
| ReverseConnectHandle handle = | ||
| server.addReverseConnect("opc.tcp://localhost:" + LISTEN_PORT, getServerEndpointUrl()); | ||
|
|
||
| try { | ||
| List<ApplicationDescription> servers = | ||
| DiscoveryClient.findServers(config).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); | ||
|
|
||
| assertFalse(servers.isEmpty(), "expected at least one server"); | ||
|
|
||
| String serverAppUri = server.getConfig().getApplicationUri(); | ||
| assertTrue( | ||
| servers.stream().anyMatch(s -> serverAppUri.equals(s.getApplicationUri())), | ||
| "expected a server with the server's application URI"); | ||
| } finally { | ||
| server.removeReverseConnect(handle); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void getEndpointsCleanup() throws Exception { | ||
| var config = | ||
| OpcTcpReverseConnectTransportConfig.newBuilder() | ||
| .setListenAddress(new InetSocketAddress("localhost", LISTEN_PORT)) | ||
| .build(); | ||
|
|
||
| // First call | ||
| ReverseConnectHandle handle1 = | ||
| server.addReverseConnect("opc.tcp://localhost:" + LISTEN_PORT, getServerEndpointUrl()); | ||
|
|
||
| try { | ||
| List<EndpointDescription> endpoints1 = | ||
| DiscoveryClient.getEndpoints(config).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); | ||
| assertFalse(endpoints1.isEmpty()); | ||
| } finally { | ||
| server.removeReverseConnect(handle1); | ||
| } | ||
|
|
||
| // Second call on the same port — would fail with a bind exception if the | ||
| // first call did not properly release the listening socket. | ||
| ReverseConnectHandle handle2 = | ||
| server.addReverseConnect("opc.tcp://localhost:" + LISTEN_PORT, getServerEndpointUrl()); | ||
|
|
||
| try { | ||
| List<EndpointDescription> endpoints2 = | ||
| DiscoveryClient.getEndpoints(config).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); | ||
| assertFalse(endpoints2.isEmpty()); | ||
| } finally { | ||
| server.removeReverseConnect(handle2); | ||
| } | ||
| } | ||
|
|
||
| private String getServerEndpointUrl() { | ||
| return server.getConfig().getEndpoints().stream() | ||
| .map(EndpointConfig::getEndpointUrl) | ||
| .filter(url -> url != null && !url.endsWith("/discovery")) | ||
| .findFirst() | ||
| .orElseThrow(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.