Skip to content

Expose the ChannelToPortHandler port property in TcpipServerChannel to users? #705

@JinHeap

Description

@JinHeap

Description

We have a use case that requires port forwarding, but we need to send a token ‌before‌ forwarding the port. After reviewing the source code, we found that a potential solution is to add a ChannelListener and send the token using the port when channelOpenSuccess is triggered.

However, the port property in TcpipServerChannel does not appear to be directly accessible to users. Could this property be exposed (e.g., via a public method or event argument) to allow developers to retrieve the port number during the channelOpenSuccess phase?

Welcome any suggestions

our demo

    private static ChannelListener getListener() {
        return new ChannelListener() {
            @Override
            public void channelOpenSuccess(Channel channel) {
                if (channel instanceof TcpipServerChannel) {
                    System.out.println("channel open success");
                    TcpipServerChannel direct = (TcpipServerChannel) channel;
                    try {
                        Buffer buf = new ByteArrayBuffer(token);
                        direct.getPort().getPortSession().writeBuffer(buf).addListener(future1 -> {
                            if (future1.isWritten()) {
                                System.out.println("write success");
                            } else {
                                System.err.println(future1.getException());
                            }
                        });
                    } catch (IOException e) {
                        System.err.println(e);
                    }
                }
            }
        };
    }

   // add to TcpipServerChannel
    public ChannelToPortHandler getPort() {
        return port;
    }

sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java
https://github.com/apache/mina-sshd/blob/7d29e3ed751b8520fbbfc3d678514f144efa40e3/sshd-core/src/main/java/org/apache/sshd/server/forward/TcpipServerChannel.java

Motivation

improve

Alternatives considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions