Subject: Re: Multiple channels and epoll(7)

Re: Multiple channels and epoll(7)

From: Stef Bon <stefbon_at_gmail.com>
Date: Tue, 17 Nov 2020 05:54:56 +0100

Hi,

Goodmorning. How do you do?

I know the design of SSH and the connection protocol described in RFC
4254, and I know that by design only the ssh session has a fd.
I'm working on a FUSE network filesystem service which connects to SSH
servers in the network automatically,
using Avahi to detect the hosts/services, and mounts on
/run/network/$user, and offers there a browseable map to access
the shared folders (at least the home directory) like:

/run/network/sbon/bononline.nl/fileserver/home

The sftp client uses a hash table to wait for a response (a thread is
waiting some time after sending to wait for a response).
Under the hood the response on the channel data message is first
processed by the eventhandler, taken over by a separate thread to
decrypt,
then recognized as a channel data message, and the for that channel
specific receive data function is called. When setting up a channel,
this will queue it in a channel specific queue (for example the ssh
channel open conformation message) for the waiting thread to finish
the setup of a channel, for the sftp client (when channel is setup)
this will analyze the
channel payload (using
https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13 for sftp
version 6 for example), and signal the waiting thread which started
the request a response is there.

Now all these io functions use one set of mutex and cond, to make it
possible to react on all these events:

- a response has arrived
- no response causing a timeout
- response the received packet is invalid
- connection is closed/some error
- channel is closed
- ssh session is closed
- original request (by FUSE) is interrupted

To handle all these events well, one set of mutex/cond is used for the
mount point and all the services like ssh connection, channel and sftp
io.
See for example the wait for a response function for sftp in:

https://github.com/stefbon/fs-workspace/blob/master/sftp/request-hash.c#L352

I had to write my own ssh implementation cause no other library offers
this integration with the context (FUSE) sharing the mutex/cond
to signal for all kinds of io events, over multiple channels. Now like
I said I do not know libssh2 that well.

Stef
_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2020-11-17