Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssh: add ability to enable compression (for SCP/SFTP) #1735

Closed
wants to merge 1 commit into from
Closed

ssh: add ability to enable compression (for SCP/SFTP) #1735

wants to merge 1 commit into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Aug 5, 2017

Add the ability to enable compression for SCP/SFTP.

The required low-level logic was already available as part of libssh2 (via LIBSSH2_FLAG_COMPRESS libssh2_session_flag() option.)

This patch adds the new libcurl option CURLOPT_SSH_COMPRESSION (boolean) and the new curl command-line option --compressed-ssh to request this libssh2 feature. To have compression enabled, it is required that the SSH server supports a (zlib) compatible compression method and that libssh2 was built with zlib support enabled.

Ref: #1732


Use case: When transferring well-compressible (f.e. plaintext) data which is either large and/or the bandwidth is relatively low. For small transfers and/or fast connections, it may even result in slightly worse performance. See also: https://askubuntu.com/questions/6770/does-ssh-use-any-compression

@mention-bot
Copy link

@vszakats, thanks for your PR! By analyzing the history of the files in this pull request, we identified @Lekensteyn, @bagder and @yangtse to be potential reviewers.

@vszakats vszakats changed the title add ability to enable SSH compression add ability to enable SSH compression (for SCP/SFTP) Aug 5, 2017
@vszakats vszakats changed the title add ability to enable SSH compression (for SCP/SFTP) ssh: add ability to enable compression (for SCP/SFTP) Aug 5, 2017
@vszakats vszakats requested a review from jay August 5, 2017 10:29
@vszakats
Copy link
Member Author

vszakats commented Aug 5, 2017

I've created the patch assuming it would make it only into 7.56.0. That is to say I'd be quite glad if it could be included in 7.55.0 next week. Given, of course that all eyes find it alright.

@curl curl deleted a comment from coveralls Aug 5, 2017
@curl curl deleted a comment from coveralls Aug 5, 2017
@bagder
Copy link
Member

bagder commented Aug 5, 2017

We only merge features when the feature window is open. That's 4 weeks following a release, so too late for 7.55.0

@vszakats
Copy link
Member Author

vszakats commented Aug 5, 2017

Ok, it's clearly too late for that, thanks for clarifying!

vszakats added a commit to vszakats/hb that referenced this pull request Aug 9, 2017
  * contrib/hbcurl/easy.c
  * contrib/hbcurl/hbcurl.ch
    + add tentative support for CURLOPT_SSH_COMPRESSION when built
      against upper than libcurl 7.55.0
      curl/curl#1735
vszakats added a commit to curl/curl-for-win that referenced this pull request Aug 9, 2017
@vszakats vszakats removed the request for review from jay August 9, 2017 11:31
@vszakats
Copy link
Member Author

vszakats commented Aug 9, 2017

My real world tests were conclusively positive. Here are test binaries (for Windows) with this patch applied including a libssh2 library with zlib enabled: https://bintray.com/vszakats/generic/curl-test/7.55.1

(NOTE: these binaries are not for production use or distribution, their sole purpose is testing this specific feature on that platform.)

@vszakats
Copy link
Member Author

Any suggestions or anything missing to have this approved?

Copy link
Member

@bagder bagder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@@ -1091,6 +1091,10 @@ static CURLcode operate_do(struct GlobalConfig *global,
to fail if we are not talking to who we think we should */
my_setopt_str(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5,
config->hostpubmd5);

/* new in libcurl 7.56.0 */
my_setopt_str(curl, CURLOPT_SSH_COMPRESSION,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be my_setopt and you have to pass it a long like if(config->ssh_compression) my_setopt(curl, CURLOPT_SSH_COMPRESSION, 1L). Also the example should use 1L

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Member Author

@vszakats vszakats Aug 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed both.

SFTP retrieval
</name>
<command>
--key curl_client_key --pubkey curl_client_key.pub -u %USER: --compressed-ssh sftp://%HOSTIP:%SSHPORT%PWD/log/file642.txt --insecure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test doesn't do anything to see if the compression is enabled, is that right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. It tests if download is still (transparently) working.

Copy link
Member Author

@vszakats vszakats Aug 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found no obvious way to verify if compression is indeed used in a libcurl transfer. It also requires support from the server-side, not sure if the test server supports it. For local, manual tests, I was timing the transfers and watching the process with a network monitor.

The required low-level logic was already available as part of
`libssh2` (via `LIBSSH2_FLAG_COMPRESS` `libssh2_session_flag()`[1]
option.)

This patch adds the new `libcurl` option `CURLOPT_SSH_COMPRESSION`
(boolean) and the new `curl` command-line option `--compressed-ssh`
to request this `libssh2` feature. To have compression enabled, it
is required that the SSH server supports a (zlib) compatible
compression method and that `libssh2` was built with `zlib` support
enabled.

[1] https://www.libssh2.org/libssh2_session_flag.html
Ref: #1732
@vszakats
Copy link
Member Author

vszakats commented Aug 16, 2017

Squashed and rebased on current master.

@vszakats
Copy link
Member Author

vszakats commented Aug 16, 2017

Slightly off, but the Travis CI queue may be eased a bit by enabling both 'Auto cancel' options on https://travis-ci.org/curl/curl/settings. This would drop any pending commits from the queue if a newer commit lands.

There is a similar option on AppVeyor CI, called 'Rolling builds', which could be enabled for a similar effect, but in this case, by default it will even cancel running builds on the same branch on any new commit (this can be disabled to match Travis CI.)

With these set, there would be less strain on the CI servers and the queue could finish faster.

What do you think about it?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 73.158% when pulling fa7b3a1 on vszakats:ssh_compress into 870d849 on curl:master.

@curl curl deleted a comment from coveralls Aug 16, 2017
@jay jay closed this in b7b4dc0 Aug 17, 2017
@jay
Copy link
Member

jay commented Aug 17, 2017

Thanks. I landed this with a slight change so that the error message will be shown even if libssh2_session_flag isn't available. Also note infof should end in a linefeed

  if(data->set.ssh_compression) {
#if LIBSSH2_VERSION_NUM >= 0x010208
    if(libssh2_session_flag(ssh->ssh_session, LIBSSH2_FLAG_COMPRESS, 1) < 0)
#endif
      infof(data, "Failed to enable compression for ssh session\n");
  }

@vszakats
Copy link
Member Author

Good idea, thank you @jay! (Noted the infof() issue – what happened is that I copied that line from the preceding failf() which doesn't need the \n)

@vszakats vszakats deleted the ssh_compress branch August 17, 2017 07:43
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

None yet

5 participants