Add option of connecting to the vnc server through a ssh tunnel
ClosedPublic

Authored by aacid on Jun 21 2018, 2:48 PM.

Details

Summary

Introduces an optional dependency on libssh

Test Plan

Connect to VNC servers both via SSH tunnel and via regular connection

Diff Detail

Repository
R436 KRDC
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
aacid requested review of this revision.Jun 21 2018, 2:48 PM
aacid created this revision.
aacid updated this revision to Diff 36464.Jun 21 2018, 2:52 PM

port -> Port

aacid updated this revision to Diff 36465.Jun 21 2018, 2:54 PM

Don't change height accelerator

Thanks, this looks like a nice feature addition to KRDC! I have not tested it - but code looks good.

core/remoteview.cpp
211

(unnecessary empty line)

vnc/vncclientthread.cpp
547

Have you tested if this change keeps backward compatibility (I have seen that you have moved this part to a new location)? For example when starting KRDC from cli with an url without port.

vnc/vncsshtunnelthread.cpp
121

(whitespace after 'if' is not consistent with other parts of this file)

vnc/vncview.cpp
216

What happens if you have multiple sessions with tunnels open?

aacid added inline comments.Jun 25 2018, 9:35 PM
core/remoteview.cpp
211

will fix on commit/if i upload a new revision, just don't feel there's a need to upload a new change because just of this.

vnc/vncclientthread.cpp
547

I have not tested it, but the only place m_port in VncClientThread is set is in VncView::start and the only place m_port is set for VncView is on its constructor, so i did the move with relatively high confidence that it would not cause a regression.

vnc/vncsshtunnelthread.cpp
121

will fix on commit/if i upload a new revision, just don't feel there's a need to upload a new change because just of this.

vnc/vncview.cpp
216

That's fine the

setsockopt(m_server_sock , SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(sockopt));

call makes it work (or so did on my tests)

dfaure requested changes to this revision.Jun 28 2018, 10:56 AM
dfaure added a subscriber: dfaure.
dfaure added inline comments.
vnc/vnchostpreferences.cpp
30

static const char quality_config_key[] =
so that it goes into the rodata section.

(I just rechecked with a small test program, and yes, this is still valid, a const char* goes into .data while a const char[] goes into .rodata)

64

the connect could move under #ifdef LIBSSH_FOUND

vnc/vncsshtunnelthread.cpp
57

I would add a comment here, for the next reader.

// This is called by the main thread, but from a slot connected to our signal via BlockingQueuedConnection, so this is safe even without a mutex, the semaphore in BlockingQueuedConnection takes care of the synchronization.

130

(missing space after if, here as well)

133

You could use a local RAII class to avoid duplicating close+ssh_disconnect+ssh_free in every return code path (initialize m_server_sock to -1 in the constructor so you can test for it before calling close).

As a benefit this huge method would be a little bit less huge ;)

148

"any error here will propagate" confused me, I was wondering how those two threads would communicate then.
After your clarification over chat, I think this comment should say something like "any socket error here will be detected by the vnc thread".

189

missing space after while
one space too many after eof...

Should this also say while (!error && ...)? I'm not sure, but it looks like the current code might go into an infinite loop if FD_ISSET always return false for some reason.
OTOH I'm not sure if you want to abort on first error...

233

Instead of the if+continue above, this line could say if (!error && !channel_read_buffer), to match the next if() which also does if (!error && ...). It just seems asymetric to use continue in one case and if in the other.

269

On error, this delete[] might never happen. Maybe do it at end of block too?

285

This is for sure a race on m_server_sock. I guess this is here in order to wake up ssh_select in the thread?

In that case, m_server_sock needs to be mutex-protected, everywhere it's used.
But the run() method could use a local variable with a copy of that socket value, so that it only needs mutex-protection to write into the member variable, once, when the value is first known.

But actually, ssh_select has a timeout of 200ms so m_stop_thread is checked every 200ms, no?
(not sure why it needs to wake up so often, though, especially if we can stop the thread by closing the socket).

It seems to me that either the timeout stays short and stop() can just wait 200ms, or the timeout becomes much longer and we do need to shutdown here. Am I missing something?

This revision now requires changes to proceed.Jun 28 2018, 10:56 AM
aacid marked 7 inline comments as done.Jun 29 2018, 9:30 AM
aacid added inline comments.
vnc/vncsshtunnelthread.cpp
189

spacing fixed, about adding the error to the while, i really don't know, i *think* if something fails here, the actual vnc part of the code will fail too since it won't get reads/writes and everything will end up failing nicely at some point.

But it's one of this things that are really hard to test since i don't really know how to make it fail properly, so i'd like to leave it as is.

269

Added outside the while

285

Actually i don't think i need the shutdown call anymore, i think it's back from when i had a bit of a different code structure and the thread was getting blocked in accept() if i could not connect and i needed to nudge it out to be able to stop the thread, but i reworked that a while ago and i don't really need it anymore (or at least could not reproduce it getting stuck and previously was very easy)

So i've just removed the shutdown and then the race is gone :)

aacid updated this revision to Diff 36874.Jun 29 2018, 9:30 AM

Addressed David's comments

dfaure accepted this revision.Jun 29 2018, 10:03 AM
This revision is now accepted and ready to land.Jun 29 2018, 10:03 AM
uwolfer accepted this revision.Jul 4 2018, 6:59 PM
This revision was automatically updated to reflect the committed changes.