[ 
https://issues.apache.org/jira/browse/SSHD-534?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Goldstein Lyor resolved SSHD-534.
---------------------------------
    Resolution: Not A Problem
      Assignee: Goldstein Lyor

It's not clear how you reached this conclusion - can you send test code that 
shows this problem (see test example below). Please note that if you create 
channels on different *sessions*, then indeed they might have the same id. 
Specifically, if you create one channel per session, then indeed all of them 
will have the value 0. This however is totally in line with the SSH 
specification - the channel id is unique only within the *same session* - there 
is no cross-session uniqueness guarantee. Furthermore, if you read [RFC 
4254|https://tools.ietf.org/html/rfc4254] you will not find any such 
requirement - it is even theoretically possible to re-use a channel id if that 
channel has been closed (it's not a good idea for other reasons, but not 
because of the RFC...). The channel identifier (sender/receiver) are similar to 
the ephemeral ports used for a TCP/IP connections - these ports can (and are 
re-used) for *new* connections - like in the case of tearing down and opening a 
new SSH channel.

Here is a test that *proves* that different ID(s) are assigned to different 
channels on the *same session* - you can try it out by checking out the 0.14 
code and adding this to the _ClientTest_ class:
{code:java}

    @Test
    public void testCreateChannelByType() throws Exception {
        client.start();

        ClientSession session = client.connect(getCurrentTestName(), 
"localhost", port).await().getSession();
        try {
            session.addPasswordIdentity(getCurrentTestName());
            session.auth().verify();

            try {
                Collection<ClientChannel> channels = new LinkedList<>();
                try {
                    
channels.add(session.createChannel(ClientChannel.CHANNEL_SUBSYSTEM, "sftp"));
                    
channels.add(session.createChannel(ClientChannel.CHANNEL_EXEC, 
getCurrentTestName()));
                    
channels.add(session.createChannel(ClientChannel.CHANNEL_SHELL, 
getClass().getSimpleName()));
                    
                    Set<Integer> ids = new HashSet<Integer>(channels.size());
                    for (ClientChannel c : channels) {
                        int id = ((AbstractChannel) c).getId();
                        assertTrue("Channel ID repeated: " + id, 
ids.add(Integer.valueOf(id)));
                    }
                } finally {
                    for (ClientChannel c : channels) {
                        c.close(true);
                    }
                }
            } finally {
                session.close(true);
            }
        } finally {
            client.stop();
        }
    }
{code}
If you place a debug breakpoint at the _assertTrue_ statement you will see that 
each channel was assigned a consecutive channel id number.

> SSHClient Channel id ( channel.getId() ) always returned as 0 , no matter how 
> many channels are created.
> --------------------------------------------------------------------------------------------------------
>
>                 Key: SSHD-534
>                 URL: https://issues.apache.org/jira/browse/SSHD-534
>             Project: MINA SSHD
>          Issue Type: Bug
>    Affects Versions: 0.14.0
>            Reporter: Preshit Maheshwari
>            Assignee: Goldstein Lyor
>             Fix For: 1.0.0
>
>
> Using SSHClient , if we are creating more than one channels using same 
> client. Channel id return is 0 for all channels.
> It can be due to below check-in :
> https://github.com/apache/mina-sshd/commit/b971c90ca49b100bc8f6c8936b65aea90933a7ec
> nextChannelId is changed from static  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to