On 10/27/2013 03:32 PM, Daniel Stenberg wrote: > On Mon, 21 Oct 2013, Salvador Fandino wrote: > >> The most controversial change is the way those new parameters are set >> as I have added a new unified interface for setting/retrieving all the >> session parameters "libssh2_session_config_(set|get)" and deprecated >> "libssh2_session_flag" and >> "libssh2_session_(set|get)_(timeout|blocking)". A more detailed >> explanation is on the commit message. > > We did have a discussion before (although I didn't actually bother to > try to find any links to it right now), about what the best API for this > kind of things is, and we then decided on the > libssh2_session_(set|get)_[what] approach. > > So, I don't think we should deprecate these functions but I'm open for > adding new ones for setting/getting other options and values.
Here there is a new version of the patches adding the channel_window_size and channel_packet_size slots into the session object and the corresponding accessors as separate functions.
>From d4e179748eed7761a9878670a6147502f44a7cd0 Mon Sep 17 00:00:00 2001 From: Salvador Fandino <sfand...@yahoo.com> Date: Mon, 21 Oct 2013 12:59:02 +0200 Subject: [PATCH 1/2] Set channel window and packet size from configurable values on the session object Currently, the channel and packet window sizes can only be configured when "libssh2_channel_open_ex" is used to create the channel. Unfortunatelly this is not always an option. For instance, for some channel types (i.e. tcp-ip) a different function must be used; in other cases, the channel is not created explicitly by the user. This patch adds two new slots into the session structure to store the default window and packet sizes. Every channel created in this session will use these values by default (unless a set of different ones are explicitly set). A new pair of constants (LIBSSH2_CHANNEL_WINDOW_CONFIGURED and LIBSSH2_CHANNEL_PACKET_CONFIGURED) are also defined. These can be used on function calls were the packet and/or window size are passed to indicate that the configured values are to be used. Note that this patch does not introduce any way to set or change the values on the session object yet. Signed-off-by: Salvador Fandino <sfand...@yahoo.com> --- include/libssh2.h | 6 ++++-- src/channel.c | 10 ++++++++-- src/libssh2_priv.h | 4 ++++ src/packet.c | 14 ++++++++------ src/session.c | 2 ++ 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/include/libssh2.h b/include/libssh2.h index 3cb2be5..08321c4 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -594,7 +594,9 @@ LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, /* Channel API */ #define LIBSSH2_CHANNEL_WINDOW_DEFAULT (2*1024*1024) +#define LIBSSH2_CHANNEL_WINDOW_CONFIGURED (~(unsigned int)0) #define LIBSSH2_CHANNEL_PACKET_DEFAULT 32768 +#define LIBSSH2_CHANNEL_PACKET_CONFIGURED (~(unsigned int)0) #define LIBSSH2_CHANNEL_MINADJUST 1024 /* Extended Data Handling */ @@ -615,8 +617,8 @@ libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type, #define libssh2_channel_open_session(session) \ libssh2_channel_open_ex((session), "session", sizeof("session") - 1, \ - LIBSSH2_CHANNEL_WINDOW_DEFAULT, \ - LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0) + LIBSSH2_CHANNEL_WINDOW_CONFIGURED, \ + LIBSSH2_CHANNEL_PACKET_CONFIGURED, NULL, 0) LIBSSH2_API LIBSSH2_CHANNEL * libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host, diff --git a/src/channel.c b/src/channel.c index d6bfb98..b208530 100644 --- a/src/channel.c +++ b/src/channel.c @@ -154,6 +154,12 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, memset(&session->open_packet_requirev_state, 0, sizeof(session->open_packet_requirev_state)); + if (window_size == LIBSSH2_CHANNEL_WINDOW_CONFIGURED) + window_size = session->channel_window_size; + + if (packet_size == LIBSSH2_CHANNEL_PACKET_CONFIGURED) + packet_size = session->channel_packet_size; + _libssh2_debug(session, LIBSSH2_TRACE_CONN, "Opening Channel - win %d pack %d", window_size, packet_size); @@ -375,8 +381,8 @@ channel_direct_tcpip(LIBSSH2_SESSION * session, const char *host, channel = _libssh2_channel_open(session, "direct-tcpip", sizeof("direct-tcpip") - 1, - LIBSSH2_CHANNEL_WINDOW_DEFAULT, - LIBSSH2_CHANNEL_PACKET_DEFAULT, + session->channel_window_size, + session->channel_packet_size, session->direct_message, session->direct_message_len); diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h index 461d14c..af09df7 100644 --- a/src/libssh2_priv.h +++ b/src/libssh2_priv.h @@ -638,6 +638,10 @@ struct _LIBSSH2_SESSION void* tracehandler_context; /* context for the trace handler */ #endif + /* configurable values */ + uint32_t channel_window_size; + uint32_t channel_packet_size; + /* State variables used in libssh2_banner_send() */ libssh2_nonblocking_states banner_TxRx_state; char banner_TxRx_banner[256]; diff --git a/src/packet.c b/src/packet.c index 47bbf2b..94df7bf 100644 --- a/src/packet.c +++ b/src/packet.c @@ -172,11 +172,11 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, channel->remote.id = listen_state->sender_channel; channel->remote.window_size_initial = - LIBSSH2_CHANNEL_WINDOW_DEFAULT; + session->channel_window_size; channel->remote.window_size = - LIBSSH2_CHANNEL_WINDOW_DEFAULT; + session->channel_window_size; channel->remote.packet_size = - LIBSSH2_CHANNEL_PACKET_DEFAULT; + session->channel_packet_size; channel->local.id = _libssh2_channel_nextid(session); channel->local.window_size_initial = @@ -323,9 +323,11 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, channel->remote.id = x11open_state->sender_channel; channel->remote.window_size_initial = - LIBSSH2_CHANNEL_WINDOW_DEFAULT; - channel->remote.window_size = LIBSSH2_CHANNEL_WINDOW_DEFAULT; - channel->remote.packet_size = LIBSSH2_CHANNEL_PACKET_DEFAULT; + session->channel_window_size; + channel->remote.window_size = + session->channel_window_size; + channel->remote.packet_size = + session->channel_packet_size; channel->local.id = _libssh2_channel_nextid(session); channel->local.window_size_initial = diff --git a/src/session.c b/src/session.c index 9838d2b..e00b132 100644 --- a/src/session.c +++ b/src/session.c @@ -493,6 +493,8 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), session->send = _libssh2_send; session->recv = _libssh2_recv; session->abstract = abstract; + session->channel_window_size = LIBSSH2_CHANNEL_WINDOW_DEFAULT; + session->channel_packet_size = LIBSSH2_CHANNEL_PACKET_DEFAULT; session->api_timeout = 0; /* timeout-free API by default */ session->api_block_mode = 1; /* blocking API by default */ _libssh2_debug(session, LIBSSH2_TRACE_TRANS, -- 1.8.3.2
>From c1960226335967d34518e9c86d53064b28d68522 Mon Sep 17 00:00:00 2001 From: Salvador Fandino <sfand...@yahoo.com> Date: Mon, 28 Oct 2013 16:31:30 +0100 Subject: [PATCH 2/2] Add libssh2_session_(set|get)_channel_(window|packet)_size accessors Add accessors for the session "channel_window_size" and "channel_packet_size" slots which are used to initialize new channels. Add also manual pages for them. Signed-off-by: Salvador Fandino <sfand...@yahoo.com> --- docs/Makefile.am | 4 +++ docs/libssh2_session_get_channel_packet_size.3 | 24 ++++++++++++++ docs/libssh2_session_get_channel_window_size.3 | 22 ++++++++++++ docs/libssh2_session_set_channel_packet_size.3 | 24 ++++++++++++++ docs/libssh2_session_set_channel_window_size.3 | 39 ++++++++++++++++++++++ include/libssh2.h | 11 ++++++ src/session.c | 46 ++++++++++++++++++++++++++ 7 files changed, 170 insertions(+) create mode 100644 docs/libssh2_session_get_channel_packet_size.3 create mode 100644 docs/libssh2_session_get_channel_window_size.3 create mode 100644 docs/libssh2_session_set_channel_packet_size.3 create mode 100644 docs/libssh2_session_set_channel_window_size.3 diff --git a/docs/Makefile.am b/docs/Makefile.am index e6ab394..7db2ec1 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -101,6 +101,8 @@ dist_man_MANS = \ libssh2_session_flag.3 \ libssh2_session_free.3 \ libssh2_session_get_blocking.3 \ + libssh2_session_get_channel_packet_size.3 \ + libssh2_session_get_channel_window_size.3 \ libssh2_session_get_timeout.3 \ libssh2_session_hostkey.3 \ libssh2_session_init.3 \ @@ -110,6 +112,8 @@ dist_man_MANS = \ libssh2_session_method_pref.3 \ libssh2_session_methods.3 \ libssh2_session_set_blocking.3 \ + libssh2_session_set_channel_packet_size.3 \ + libssh2_session_set_channel_window_size.3 \ libssh2_session_set_timeout.3 \ libssh2_session_startup.3 \ libssh2_session_supported_algs.3 \ diff --git a/docs/libssh2_session_get_channel_packet_size.3 b/docs/libssh2_session_get_channel_packet_size.3 new file mode 100644 index 0000000..ae6f67b --- /dev/null +++ b/docs/libssh2_session_get_channel_packet_size.3 @@ -0,0 +1,24 @@ +.TH libssh2_session_get_channel_packet_size 3 "28 Oct 2013" "libssh2 1.4.4" "libssh2 manual" +.SH NAME +libssh2_session_get_channel_packet_size - get default channel packet size for new channels +.SH SYNOPSIS +#include <libssh2.h> + +unsigned long +libssh2_session_get_channel_packet_size(LIBSSH2_SESSION *session); + +.SH DESCRIPTION +This function returns the maximum packet size used as the default when +new channels created over the given session are initialized. + +.SH RETURN VALUE +Returns the current default maximum packet size. + +.SH AVAILABILITY +This function has been available since version 1.4.4. + +.SH SEE ALSO + +.BR libssh2_session_set_channel_packet_size(3) + +RFC 4253, chapter 6.1. diff --git a/docs/libssh2_session_get_channel_window_size.3 b/docs/libssh2_session_get_channel_window_size.3 new file mode 100644 index 0000000..4bf5513 --- /dev/null +++ b/docs/libssh2_session_get_channel_window_size.3 @@ -0,0 +1,22 @@ +.TH libssh2_session_get_channel_window_size 3 "28 Oct 2013" "libssh2 1.4.4" "libssh2 manual" +.SH NAME +libssh2_session_get_channel_window_size - get default channel window size for new channels +.SH SYNOPSIS +#include <libssh2.h> + +unsigned long +libssh2_session_get_channel_window_size(LIBSSH2_SESSION *session); + +.SH DESCRIPTION +This function returns the window size used as the default when new +channels created over the given session are initialized. + +.SH RETURN VALUE +Returns the current default channel window size. + +.SH AVAILABILITY +This function has been available since version 1.4.4. + +.SH SEE ALSO + +.BR libssh2_session_set_channel_window_size(3) diff --git a/docs/libssh2_session_set_channel_packet_size.3 b/docs/libssh2_session_set_channel_packet_size.3 new file mode 100644 index 0000000..dd4d208 --- /dev/null +++ b/docs/libssh2_session_set_channel_packet_size.3 @@ -0,0 +1,24 @@ +.TH libssh2_session_set_channel_packet_size 3 "28 Oct 2013" "libssh2 1.4.4" "libssh2 manual" +.SH NAME +libssh2_session_set_channel_packet_size - set default channel packet size for new channels +.SH SYNOPSIS +#include <libssh2.h> + +unsigned long +libssh2_session_set_channel_packet_size(LIBSSH2_SESSION *session, unsigned long size); + +.SH DESCRIPTION +This function sets the maximum packet size used as the default when +new channels created over the given session are initialized. + +.SH RETURN VALUE +Returns the new maximum packet size. + +.SH AVAILABILITY +This function has been available since version 1.4.4. + +.SH SEE ALSO + +.BR libssh2_session_get_channel_packet_size(3) + +RFC 4253, chapter 6.1. diff --git a/docs/libssh2_session_set_channel_window_size.3 b/docs/libssh2_session_set_channel_window_size.3 new file mode 100644 index 0000000..7522007 --- /dev/null +++ b/docs/libssh2_session_set_channel_window_size.3 @@ -0,0 +1,39 @@ +.TH libssh2_session_set_channel_window_size 3 "28 Oct 2013" "libssh2 1.4.4" "libssh2 manual" +.SH NAME +libssh2_session_set_channel_window_size - get default channel window size for new channels +.SH SYNOPSIS +#include <libssh2.h> + +unsigned long +libssh2_session_set_channel_window_size(LIBSSH2_SESSION *session, unsigned long size); + +.SH DESCRIPTION +This function sets the window size used as the default when new +channels created over the given session are initialized. + +The window size determines the maximum amount of data that can be +flying from the server to the client at any moment, without being +acknowledged by the client, before the channel blocks. + +A value too small limits the throughput of the channel. A value too +big will waste the client memory in useless buffers. + +As of version 1.4.4 of libssh2 the default window size value +(LIBSSH2_CHANNEL_WINDOW_DEFAULT) is 2MB which, in our opinion, +represents a good compromise between transfer speed and memory usage +for today real-life networks. + +Note that every channel has its own window/buffers. Also, if +compression is enabled, additional memory would be wasted due to the +impossibility to accurately predict the size of the inflated packets a +priori. + +.SH RETURN VALUE +Returns the new default channel window size. + +.SH AVAILABILITY +This function has been available since version 1.4.4. + +.SH SEE ALSO + +.BR libssh2_session_get_channel_window_size(3) diff --git a/include/libssh2.h b/include/libssh2.h index 08321c4..03c4712 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -748,6 +748,17 @@ LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel, LIBSSH2_API void libssh2_session_set_timeout(LIBSSH2_SESSION* session, long timeout); LIBSSH2_API long libssh2_session_get_timeout(LIBSSH2_SESSION* session); + +LIBSSH2_API unsigned long +libssh2_session_set_channel_window_size(LIBSSH2_SESSION *session, + unsigned long size); +LIBSSH2_API unsigned long +libssh2_session_get_channel_window_size(LIBSSH2_SESSION *session); +LIBSSH2_API unsigned long +libssh2_session_set_channel_packet_size(LIBSSH2_SESSION *session, + unsigned long size); +LIBSSH2_API unsigned long +libssh2_session_get_channel_packet_size(LIBSSH2_SESSION *session); /* libssh2_channel_handle_extended_data is DEPRECATED, do not use! */ LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel, diff --git a/src/session.c b/src/session.c index e00b132..9bc7852 100644 --- a/src/session.c +++ b/src/session.c @@ -1353,6 +1353,52 @@ libssh2_session_get_timeout(LIBSSH2_SESSION * session) return session->api_timeout; } +/* libssh2_session_set_channel_window_size + * + * Sets the default window size for new channels created over the + * given session. + */ +LIBSSH2_API unsigned long +libssh2_session_set_channel_window_size(LIBSSH2_SESSION *session, + unsigned long size) +{ + return session->channel_window_size = size; +} + +/* libssh2_session_set_channel_window_size + * + * Gets the default window size for new channels created over the + * given session. + */ +LIBSSH2_API unsigned long +libssh2_session_get_channel_window_size(LIBSSH2_SESSION *session) +{ + return session->channel_window_size; +} + +/* libssh2_session_set_channel_packet_size + * + * Sets the default maximum packet size for channels created over the + * given session. + */ +LIBSSH2_API unsigned long +libssh2_session_set_channel_packet_size(LIBSSH2_SESSION *session, + unsigned long size) +{ + return session->channel_packet_size = size; +} + +/* libssh2_session_set_channel_packet_size + * + * Gets the default maximum packet size for channels created over the + * given session. + */ +LIBSSH2_API unsigned long +libssh2_session_get_channel_packet_size(LIBSSH2_SESSION *session) +{ + return session->channel_packet_size; +} + /* * libssh2_poll_channel_read * -- 1.8.3.2
_______________________________________________ libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel