Port Forwarding Feature

Coordinator
Nov 1, 2010 at 5:03 PM

Just wanted everybody know that I currently working on port forwarding feature.

I did prove of concept and it all works. Unfortunately it takes me a little bit longer that I thought due to new features as I need to refactor some channel classes to ensure that everything will work correctly.

 

Thanks,

Oleg

Nov 3, 2010 at 4:26 AM

Thanks!!!

Nov 5, 2010 at 3:24 PM

One more thing I need for my stress client: is there a way to send a keep alive message as implemented in SharpSSH?

Tx

Coordinator
Nov 5, 2010 at 3:44 PM

How would you enable this feature in SharpSSH ?

Is there any function you need to call?

I just couldnt find it in the code.

 

Thanks,

Oleg

Nov 11, 2010 at 12:06 AM

in SharpSSH is 

session.sendKeepAliveMsg();

Anyway, I found that the port forwarding is having issues with 'large' data exchanges. The connection gets dropped always at the same point.

Coordinator
Nov 11, 2010 at 12:45 AM
Edited Nov 13, 2010 at 7:03 PM
How large data are you talking about? How many GB ?
Also, this keep alive message is this something that you call manually, I assume once in a while, cause from what I saw in the source code, at least the version that I have, I didn't see this method to be called from anywhere.
Nov 11, 2010 at 12:58 AM

Not really large, maybe a 70K webpage; I debugged it and found a fix for it.

This is basically what happens in your code

            //  Start reading data from the port and send to channel
                    using (var ns = new NetworkStream(this._socket))
                    {
                        do
                        {
                            var read = ns.Read(buffer, 0, buffer.Length);
                            this.SendMessage(new ChannelDataMessage
                            {
                                LocalChannelNumber = this.RemoteChannelNumber,
                                Data = buffer.Take(read).GetSshString(),
                            });
                        }
                        while (ns.DataAvailable);
                    }

The problem is that there might still be more data because it is sent on different buffers. What is happening is that you are closing the connection after the first buffer, while you should keep running forever until the stream is closed. A quick fix that seems to work pretty well:

            //  Start reading data from the port and send to channel
            while (true)
            {
                try
                {
                    using (var ns = new NetworkStream(this._socket))
                    {
                        do
                        {
                            var read = ns.Read(buffer, 0, buffer.Length);
                            this.SendMessage(new ChannelDataMessage
                            {
                                LocalChannelNumber = this.RemoteChannelNumber,
                                Data = buffer.Take(read).GetSshString(),
                            });
                        }
                        while (ns.DataAvailable);
                        Thread.Sleep(1000);
                    }
                }
                catch(IOException)
                {
                    break;
                }
            }

May be there is a better way to check if the stream is not closed besides catching the exception which you should anyway.  For the keep alive don't worry, I can put something together pretty fast.

HTH

Coordinator
Nov 11, 2010 at 7:21 PM

Hi,

I did some fixes to that code that you mentioned.

I used slight different technique, one I already use ion other places, so hope it works.

If not let me know your scenario so I could try to recreate it and to debug the problem. 

Feel free to contact me persnoally if you wish to share some sensative information.

 

Thanks,

Oleg

Nov 12, 2010 at 4:11 AM

nothing sensitive, I will test your fix tomorrow and stress test it for the whole weekend. 

Nov 13, 2010 at 4:57 PM

So far so good. Another bug I've found on my machine: when resolving "localhost" the first address in the array is "::1" and for whatever reason the rest of the code is unable to connect. I fixed it by special casing "localhost", you might want to take a look on a better fix?

Thanks for the good job so far, the library is very reliable.

Coordinator
Nov 13, 2010 at 5:04 PM
Edited Nov 13, 2010 at 7:02 PM
thanks, I actually found out out that I am missing some ability to specify which ip to bind, like ::1 or 127.0.0.1
so I am thinking about nice solution for that. So once I do that will let you know.

 

Dec 2, 2010 at 4:12 AM

Ok, I've sync'd to the last revision and everything looks better. I am attaching this patch to support KeepAlive, if I don't do this periodically the connection gets silently dropped and thus the port stops getting forwarded.

The patch is here: http://www.mediafire.com/?8y97ui72pgq8m2n

Thanks

Coordinator
Dec 2, 2010 at 1:30 PM

thanks,

 

I will integrate your change into next version.

 

Thanks,

Oleg

Dec 2, 2010 at 5:31 PM

One more thing: it seems like port forwarding is not working properly in the latest version. I will debug and report, RSync is complaining about protocol errors.

Coordinator
Dec 2, 2010 at 5:39 PM

ok, 

let me nknow what you find since I refactoring some parts of it so the latest version might not be always be the best.

 

trying to incorporate SFTP nicely and add asynch support so had to refactor some channeling mechanisms.

 

By the way where doest it report protocol error? in the library or some other tool? Also, how soon/often does it happens? 

Since last changes haven't chance to test key re-exchange after  number of packets has been sent, so has suspicious about that.

 

Thanks,

Oleg

Dec 2, 2010 at 6:04 PM

This is the error: rsync: connection unexpectedly closed 

I need to debug to give you more info.

I made a snapshot of the last known good, so I am not much worried. :)

Coordinator
Dec 2, 2010 at 6:05 PM

ok, thanks,

 

yea, let me know the debug info if you can, will give me more info.

Can you tell me which one you mean by last good one snapshot, so I could compare in case I need to?

Dec 2, 2010 at 7:11 PM

This is a regression. The code looks exactly like it was before the fix I proposed in this thread and the one you made later.

There you, this is the corrected version: http://www.mediafire.com/?bn2d8vg67cb0swd

Thanks

Dec 10, 2010 at 12:22 PM

Ping :)

Coordinator
Dec 10, 2010 at 12:31 PM

ops, sorry, 

I forgot to integrate it, I remember I was looking at it already and I think I got distructed by other work.

Let me add it today and I will post an update when its done.

Coordinator
Dec 10, 2010 at 1:11 PM

Hi,

 

I just checking your proposed fixes,

Please take a look and let me know if there is a problem.

Also, I have question, do you think it would make sence to have a KeepAlive property which will specify how often to send this message and client will send it automaticlly every x minutes?

 

Thanks,

Oleg

 

Dec 17, 2010 at 3:17 PM

Hi, I haven't been involved in this thread before, but I definitely think KeepAlive should be a property and we shouldn't need to worry about sending it manually in our code. 

 

I would say it should be in seconds, not in minutes, though.  Sometimes keep-alives need to be sent frequently just so firewalls keep the ports open even if there's no constant flow of data.

 

Keep up the good work, I've been looking for an SSH library for a while and the ones available were old and no longer maintained.  I have a couple of projects in mind, where I need SSH, SFTP and port tunneling, so I'm quite interested in this project.

Idel.

Coordinator
Dec 23, 2010 at 7:05 PM

idel,

 

Thanks for input,

 

I implemented it as a property now so you can check out latest release.

 

Thanks,

Oleg