[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: example of a server


Hi Tomasz,

I've been working on a libssh server that can do X forwarding - this
is my primary interest in terms of server capabilities. I intend to
eventually use this code as part of my open source eBrainPool project
(ebrain.in). Just noticed your original mail and I'm not sure if my
server code is a fit in terms of what you are looking for. However if
you would like you could go through the code (currently standalone C
code) and hopefully use it as an example :) I'd also be more than
happy to polish this up and share the code as an example with the
libssh project if it is of interest :) - let me know.

For now you can get the code with a git clone git://ebrain.in/libssh-server.git

I've worked on making the server multithreaded so it can handle
multiple connections. Unfortunately there are still some issues since
sophisticated X clients typically open up multiple channels over the
same session. Multithreading for a single session isn't supported in
libssh at the moment therefore I have to device some other mechanism
to handle this.

Bye for now
Jeetu
ebrain.in | Beehive Computing
Discover and run software from devices around you. Software and
Computing as a shared resource. An open source (GPLv3) project.

On Mon, Apr 16, 2012 at 3:35 PM, Tomasz Mikolajczyk
<tmmikolajczyk@xxxxxxxxx> wrote:
> Hi,
>
> Recently I started investigation of the libssh capabilities. I
> analyzed tutorial and various examples but couldn't find a sufficient
> example how to implement a non-blocking SSH server. I would like to
> achieve the following:
>
> 1) listening on a TCP socket on a predefined port
>
> 2) When there is a new connection on the socket I assume that it is a
> new ssh client's connection. Then I would like to pass the socket fd
> to the libssh saying "handle this connection as the ssh connection".
> Is the following pseudo code correct in order to do that?:
>
> ssh_bind_struct* b = ssh_bind_new()
> ssh_bind_set_blocking(b, 0)
> ssh_bind_listen(b)
>
> TCPSocket tcp;
> select(tcp.fd);
> ssh_bind_set_fd(tcp.fd);
>
> ssh_session_struct* ses = ssh_new()
> ssh_bind_accept(b, ses)
>
> 3) In the next step I would like to wait on another select and handle
> all the requests, like SSH_REQUEST_AUTH, SSH_REQUEST_CHANNEL_OPEN,
> SSH_REQUEST_CHANNEL and so on, but in the same time I would like to
> check/receive (in a non-blocking mode by waiting on the same select) a
> user-passed data. How to achieve that? The "ssh_message_get" is
> blocking so I cannot use it. I also found an example of
> reading/writing data using ssh_channel_read/ssh_channel_write
> functions, however the examples do not show how to receive user data
> (channel data) and in the same time handle messages such as
> pty-request.
>
> /Tomek
>

Archive administrator: postmaster@lists.cynapses.org