From ca3595e81edb67cf3a64f009031676ac65263a21 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 18 Feb 2025 10:31:29 +0000 Subject: [PATCH 1/8] Update myStatusCb to output once per second Modified the myStatusCb function in sftpclient.c to only output status updates once per second by tracking the last output time and comparing it with the current time. This reduces the frequency of status updates while maintaining all existing functionality. Co-Authored-By: andrew@wolfssl.com --- examples/sftpclient/sftpclient.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/sftpclient/sftpclient.c b/examples/sftpclient/sftpclient.c index b31eb69e0..e7c5553e7 100644 --- a/examples/sftpclient/sftpclient.c +++ b/examples/sftpclient/sftpclient.c @@ -148,19 +148,25 @@ static void err_msg(const char* s) static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name) { + static word32 lastOutputTime = 0; word32 currentTime; char buf[80]; word64 longBytes = ((word64)bytes[1] << 32) | bytes[0]; #ifndef WOLFSSH_NO_TIMESTAMP + currentTime = current_time(0); + if (currentTime == lastOutputTime) { + return; + } + lastOutputTime = currentTime; if (WSTRNCMP(currentFile, name, WSTRLEN(name)) != 0) { startTime = current_time(1); WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME); WSTRNCPY(currentFile, name, WOLFSSH_MAX_FILENAME); } - currentTime = current_time(0) - startTime; + word32 elapsedTime = currentTime - startTime; WSNPRINTF(buf, sizeof(buf), "Processed %8llu\t bytes in %d seconds\r", - (unsigned long long)longBytes, currentTime); + (unsigned long long)longBytes, elapsedTime); #ifndef WOLFSSH_NO_SFTP_TIMEOUT if (currentTime > TIMEOUT_VALUE) { WSNPRINTF(buf, sizeof(buf), "\nProcess timed out at %d seconds, " From b45a51000d054a90ac639e1640112942d7e9c9d1 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 18 Feb 2025 10:36:42 +0000 Subject: [PATCH 2/8] Reset status output timer when starting new file transfer When starting a new file transfer, reset the lastOutputTime to ensure the first status update for the new file is shown immediately. Co-Authored-By: andrew@wolfssl.com --- examples/sftpclient/sftpclient.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/sftpclient/sftpclient.c b/examples/sftpclient/sftpclient.c index e7c5553e7..899716feb 100644 --- a/examples/sftpclient/sftpclient.c +++ b/examples/sftpclient/sftpclient.c @@ -161,6 +161,7 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name) lastOutputTime = currentTime; if (WSTRNCMP(currentFile, name, WSTRLEN(name)) != 0) { startTime = current_time(1); + lastOutputTime = 0; /* Reset timer for new file transfer */ WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME); WSTRNCPY(currentFile, name, WOLFSSH_MAX_FILENAME); } From 4e91d6509700f77aabc8ba9a5386ea763872936e Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 18 Feb 2025 10:45:12 +0000 Subject: [PATCH 3/8] Fix Zephyr build by guarding lastOutputTime with WOLFSSH_NO_TIMESTAMP The lastOutputTime variable is only used when timestamps are enabled, so it should be guarded by the same macro to avoid unused variable warnings in builds where timestamps are disabled. Co-Authored-By: andrew@wolfssl.com --- examples/sftpclient/sftpclient.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/sftpclient/sftpclient.c b/examples/sftpclient/sftpclient.c index 899716feb..5e5ede4c1 100644 --- a/examples/sftpclient/sftpclient.c +++ b/examples/sftpclient/sftpclient.c @@ -148,7 +148,9 @@ static void err_msg(const char* s) static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name) { +#ifndef WOLFSSH_NO_TIMESTAMP static word32 lastOutputTime = 0; +#endif word32 currentTime; char buf[80]; word64 longBytes = ((word64)bytes[1] << 32) | bytes[0]; From 4ce971002c9b7432597ad6e11b3fa2e4f678ca51 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 21 Feb 2025 18:20:12 +0000 Subject: [PATCH 4/8] Move elapsedTime declaration to function scope Per wolfSSL coding standards, declare all variables at function scope. Added comment explaining that modern compilers optimize variable access regardless of declaration placement. Co-Authored-By: andrew@wolfssl.com --- examples/sftpclient/sftpclient.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/sftpclient/sftpclient.c b/examples/sftpclient/sftpclient.c index 5e5ede4c1..7fe42c2e8 100644 --- a/examples/sftpclient/sftpclient.c +++ b/examples/sftpclient/sftpclient.c @@ -148,10 +148,14 @@ static void err_msg(const char* s) static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name) { + /* Variables declared at function scope per wolfSSL coding standards. + * Modern compilers optimize variable access regardless of declaration + * placement, so there is no performance impact. */ #ifndef WOLFSSH_NO_TIMESTAMP static word32 lastOutputTime = 0; #endif word32 currentTime; + word32 elapsedTime; char buf[80]; word64 longBytes = ((word64)bytes[1] << 32) | bytes[0]; @@ -167,7 +171,7 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name) WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME); WSTRNCPY(currentFile, name, WOLFSSH_MAX_FILENAME); } - word32 elapsedTime = currentTime - startTime; + elapsedTime = currentTime - startTime; WSNPRINTF(buf, sizeof(buf), "Processed %8llu\t bytes in %d seconds\r", (unsigned long long)longBytes, elapsedTime); #ifndef WOLFSSH_NO_SFTP_TIMEOUT From 67a381c0c2201107447f17e5672ad56008a39b0d Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 21 Feb 2025 18:27:41 +0000 Subject: [PATCH 5/8] Fix timeout check to use elapsed time instead of current time Co-Authored-By: andrew@wolfssl.com --- examples/sftpclient/sftpclient.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sftpclient/sftpclient.c b/examples/sftpclient/sftpclient.c index 7fe42c2e8..b04d4bbd8 100644 --- a/examples/sftpclient/sftpclient.c +++ b/examples/sftpclient/sftpclient.c @@ -175,7 +175,7 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name) WSNPRINTF(buf, sizeof(buf), "Processed %8llu\t bytes in %d seconds\r", (unsigned long long)longBytes, elapsedTime); #ifndef WOLFSSH_NO_SFTP_TIMEOUT - if (currentTime > TIMEOUT_VALUE) { + if (elapsedTime > TIMEOUT_VALUE) { WSNPRINTF(buf, sizeof(buf), "\nProcess timed out at %d seconds, " "stopping\r", currentTime); WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME); From f5a32fe2df6d5188c235dff2b8f201cb82bb834a Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 21 Feb 2025 18:27:57 +0000 Subject: [PATCH 6/8] Use elapsed time in timeout error message for consistency Co-Authored-By: andrew@wolfssl.com --- examples/sftpclient/sftpclient.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sftpclient/sftpclient.c b/examples/sftpclient/sftpclient.c index b04d4bbd8..234ff6f79 100644 --- a/examples/sftpclient/sftpclient.c +++ b/examples/sftpclient/sftpclient.c @@ -177,7 +177,7 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name) #ifndef WOLFSSH_NO_SFTP_TIMEOUT if (elapsedTime > TIMEOUT_VALUE) { WSNPRINTF(buf, sizeof(buf), "\nProcess timed out at %d seconds, " - "stopping\r", currentTime); + "stopping\r", elapsedTime); WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME); wolfSSH_SFTP_Interrupt(ssh); } From 8c1cbe06401a9edef9e91e4a3a9b5e78530bdb8a Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 24 Feb 2025 08:25:30 +0000 Subject: [PATCH 7/8] Move elapsedTime inside WOLFSSH_NO_TIMESTAMP guard Co-Authored-By: andrew@wolfssl.com --- examples/sftpclient/sftpclient.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sftpclient/sftpclient.c b/examples/sftpclient/sftpclient.c index 234ff6f79..f7d55c6be 100644 --- a/examples/sftpclient/sftpclient.c +++ b/examples/sftpclient/sftpclient.c @@ -153,9 +153,9 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name) * placement, so there is no performance impact. */ #ifndef WOLFSSH_NO_TIMESTAMP static word32 lastOutputTime = 0; -#endif word32 currentTime; word32 elapsedTime; +#endif char buf[80]; word64 longBytes = ((word64)bytes[1] << 32) | bytes[0]; From 05d9a22571e1879f6c1f12d44c4f7993d349027e Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 24 Feb 2025 08:29:12 +0000 Subject: [PATCH 8/8] Move currentTime outside WOLFSSH_NO_TIMESTAMP guard Co-Authored-By: andrew@wolfssl.com --- examples/sftpclient/sftpclient.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sftpclient/sftpclient.c b/examples/sftpclient/sftpclient.c index f7d55c6be..12fb7ecd5 100644 --- a/examples/sftpclient/sftpclient.c +++ b/examples/sftpclient/sftpclient.c @@ -151,9 +151,9 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name) /* Variables declared at function scope per wolfSSL coding standards. * Modern compilers optimize variable access regardless of declaration * placement, so there is no performance impact. */ + word32 currentTime; #ifndef WOLFSSH_NO_TIMESTAMP static word32 lastOutputTime = 0; - word32 currentTime; word32 elapsedTime; #endif char buf[80];