From b3ee5cd381b679876f4e8f0f06b996cd0e5ef617 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Sun, 16 Oct 2016 12:11:50 -0700 Subject: [PATCH] Send channel window adjust update when the receive buffer has processed at least half of its available space. By default, the receive window is 1MB, and the window size is increased every 512kB. --- src/internal.c | 12 +----------- src/ssh.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/internal.c b/src/internal.c index dc82b002..2ce8f19e 100644 --- a/src/internal.c +++ b/src/internal.c @@ -3676,11 +3676,6 @@ int SendChannelWindowAdjust(WOLFSSH* ssh, uint32_t peerChannel, WLOG(WS_LOG_DEBUG, "Invalid peer channel"); ret = WS_INVALID_CHANID; } -#if 0 - /* Check bytesToAdd against the buffer size */ - if (bytesToAdd > ssh->inputBuffer.bufferSz - ssh->inputBuffer.length) - ret = WS_BAD_ARGUMENT; -#endif if (ret == WS_SUCCESS) ret = PreparePacket(ssh, MSG_ID_SZ + (UINT32_SZ * 2)); @@ -3699,14 +3694,9 @@ int SendChannelWindowAdjust(WOLFSSH* ssh, uint32_t peerChannel, ret = BundlePacket(ssh); } - if (ret == WS_SUCCESS) { + if (ret == WS_SUCCESS) ret = SendBuffered(ssh); - WLOG(WS_LOG_INFO, " bytesToAdd = %u", bytesToAdd); - WLOG(WS_LOG_INFO, " windowSz = %u", channel->windowSz); - channel->windowSz += bytesToAdd; - WLOG(WS_LOG_INFO, " update windowSz = %u", channel->windowSz); - } WLOG(WS_LOG_DEBUG, "Leaving SendChannelWindowAdjust(), ret = %d", ret); return ret; } diff --git a/src/ssh.c b/src/ssh.c index bb186c23..b751073f 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -408,6 +408,33 @@ int wolfSSH_stream_read(WOLFSSH* ssh, uint8_t* buf, uint32_t bufSz) WMEMCPY(buf, inputBuffer->buffer + inputBuffer->idx, bufSz); inputBuffer->idx += bufSz; + if (inputBuffer->length > inputBuffer->bufferSz / 2) { + uint32_t usedSz = inputBuffer->length - inputBuffer->idx; + uint32_t bytesToAdd = inputBuffer->idx; + int sendResult; + + WLOG(WS_LOG_DEBUG, "Making more room: %u", usedSz); + if (usedSz) { + WLOG(WS_LOG_DEBUG, " ...moving data down"); + WMEMMOVE(inputBuffer->buffer, + inputBuffer->buffer + bytesToAdd, usedSz); + } + + sendResult = SendChannelWindowAdjust(ssh, + ssh->channelList->peerChannel, + bytesToAdd); + if (sendResult != WS_SUCCESS) + bufSz = sendResult; + + WLOG(WS_LOG_INFO, " bytesToAdd = %u", bytesToAdd); + WLOG(WS_LOG_INFO, " windowSz = %u", ssh->channelList->windowSz); + ssh->channelList->windowSz += bytesToAdd; + WLOG(WS_LOG_INFO, " update windowSz = %u", ssh->channelList->windowSz); + + inputBuffer->length = usedSz; + inputBuffer->idx = 0; + } + WLOG(WS_LOG_DEBUG, "Leaving wolfSSH_stream_read(), rxd = %u", bufSz); return bufSz; }