diff --git a/packages/c/cmake/atsdk.cmake b/packages/c/cmake/atsdk.cmake index aaaccedee..ad80ba282 100644 --- a/packages/c/cmake/atsdk.cmake +++ b/packages/c/cmake/atsdk.cmake @@ -3,7 +3,7 @@ if(NOT atsdk_FOUND) FetchContent_Declare( atsdk GIT_REPOSITORY https://github.com/atsign-foundation/at_c.git - GIT_TAG 292e3842bf13e1479ed45e1a02821b806156218d + GIT_TAG 86c2e2fe3334050501f8ff820437227bd0a95488 ) FetchContent_MakeAvailable(atsdk) install(TARGETS atclient atchops atlogger) diff --git a/packages/c/sshnpd/include/sshnpd/sshnpd.h b/packages/c/sshnpd/include/sshnpd/main.h similarity index 100% rename from packages/c/sshnpd/include/sshnpd/sshnpd.h rename to packages/c/sshnpd/include/sshnpd/main.h diff --git a/packages/c/sshnpd/include/sshnpd/params.h b/packages/c/sshnpd/include/sshnpd/params.h index d87fec7d3..12af43ad8 100644 --- a/packages/c/sshnpd/include/sshnpd/params.h +++ b/packages/c/sshnpd/include/sshnpd/params.h @@ -41,6 +41,8 @@ struct _sshnpd_params { char *key_file; char *storage_path; + + int monitor_read_timeout; // the amount of time that the monitor connection will wait for data before giving up and then sending a noop:0 to check if we're still connected }; typedef struct _sshnpd_params sshnpd_params; diff --git a/packages/c/sshnpd/src/background_jobs.c b/packages/c/sshnpd/src/background_jobs.c index 52fd55a6d..88e0158a8 100644 --- a/packages/c/sshnpd/src/background_jobs.c +++ b/packages/c/sshnpd/src/background_jobs.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/packages/c/sshnpd/src/handle_npt_request.c b/packages/c/sshnpd/src/handle_npt_request.c index 6e42f3a66..c1ce3a08f 100644 --- a/packages/c/sshnpd/src/handle_npt_request.c +++ b/packages/c/sshnpd/src/handle_npt_request.c @@ -1,6 +1,6 @@ +#include "sshnpd/main.h" #include "sshnpd/params.h" #include "sshnpd/permitopen.h" -#include "sshnpd/sshnpd.h" #include #include #include diff --git a/packages/c/sshnpd/src/handle_ping.c b/packages/c/sshnpd/src/handle_ping.c index f6b233b7c..1194a00b2 100644 --- a/packages/c/sshnpd/src/handle_ping.c +++ b/packages/c/sshnpd/src/handle_ping.c @@ -1,5 +1,5 @@ +#include "sshnpd/main.h" #include "sshnpd/params.h" -#include "sshnpd/sshnpd.h" #include #include #include @@ -29,17 +29,17 @@ void handle_ping(sshnpd_params *params, atclient_monitor_response *message, char atclient_notify_params notify_params; atclient_notify_params_init(¬ify_params); - if((ret = atclient_notify_params_set_atkey(¬ify_params, &pingkey)) != 0) { + if ((ret = atclient_notify_params_set_atkey(¬ify_params, &pingkey)) != 0) { atlogger_log(LOGGER_TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set atkey in notify params\n"); goto exit_ping; } - if((ret = atclient_notify_params_set_operation(¬ify_params, ATCLIENT_NOTIFY_OPERATION_UPDATE)) != 0) { + if ((ret = atclient_notify_params_set_operation(¬ify_params, ATCLIENT_NOTIFY_OPERATION_UPDATE)) != 0) { atlogger_log(LOGGER_TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set operation in notify params\n"); goto exit_ping; } - if((ret = atclient_notify_params_set_value(¬ify_params, ping_response)) != 0) { + if ((ret = atclient_notify_params_set_value(¬ify_params, ping_response)) != 0) { atlogger_log(LOGGER_TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set value in notify params\n"); goto exit_ping; } diff --git a/packages/c/sshnpd/src/handle_ssh_request.c b/packages/c/sshnpd/src/handle_ssh_request.c index 34be62bda..9e210bc13 100644 --- a/packages/c/sshnpd/src/handle_ssh_request.c +++ b/packages/c/sshnpd/src/handle_ssh_request.c @@ -1,5 +1,5 @@ +#include "sshnpd/main.h" #include "sshnpd/params.h" -#include "sshnpd/sshnpd.h" #include #include #include diff --git a/packages/c/sshnpd/src/main.c b/packages/c/sshnpd/src/main.c index 5d08271a6..c0a7befaf 100644 --- a/packages/c/sshnpd/src/main.c +++ b/packages/c/sshnpd/src/main.c @@ -1,10 +1,10 @@ +#include "sshnpd/main.h" #include "sshnpd/background_jobs.h" #include "sshnpd/handle_npt_request.h" #include "sshnpd/handle_ping.h" #include "sshnpd/handle_ssh_request.h" #include "sshnpd/handle_sshpublickey.h" #include "sshnpd/permitopen.h" -#include "sshnpd/sshnpd.h" #include "sshnpd/version.h" #include #include @@ -188,6 +188,7 @@ int main(int argc, char **argv) { exit_res = res; goto cancel_monitor_ctx; } + atclient_monitor_set_read_timeout(&monitor_ctx, params.monitor_read_timeout * 1000); // 7.b Initialize the worker atclient atclient_init(&worker); @@ -438,6 +439,7 @@ void main_loop() { sleep(1); break; } + atclient_monitor_set_read_timeout(&monitor_ctx, params.monitor_read_timeout * 1000); ret = atclient_monitor_start(&monitor_ctx, regex); if (ret != 0) { diff --git a/packages/c/sshnpd/src/params.c b/packages/c/sshnpd/src/params.c index ab48d8a63..815273967 100644 --- a/packages/c/sshnpd/src/params.c +++ b/packages/c/sshnpd/src/params.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -20,6 +21,7 @@ void apply_default_values_to_sshnpd_params(sshnpd_params *params) { params->root_domain = "root.atsign.org"; params->local_sshd_port = 22; params->storage_path = NULL; + params->monitor_read_timeout = 45; } int parse_sshnpd_params(sshnpd_params *params, int argc, const char **argv) { @@ -53,6 +55,9 @@ int parse_sshnpd_params(sshnpd_params *params, int argc, const char **argv) { // Doesn't do anything more, added in case old config would cause a parsing issue OPT_BOOLEAN('u', "un-hide", NULL, NULL), + OPT_INTEGER(0, "monitor-read-timeout", ¶ms->monitor_read_timeout, + "Seconds to block and wait for data to arrive in monitor connection before sending a noop:0 to ping " + "connection if alive (defaults to 45)"), OPT_END(), }; @@ -174,6 +179,5 @@ int parse_sshnpd_params(sshnpd_params *params, int argc, const char **argv) { params->manager_list_len = 0; } - // Repeat for permit-open return 0; } diff --git a/packages/c/sshnpd/tools/debug_build.sh b/packages/c/sshnpd/tools/debug_build.sh index f7b9bfaab..277e36d89 100755 --- a/packages/c/sshnpd/tools/debug_build.sh +++ b/packages/c/sshnpd/tools/debug_build.sh @@ -5,6 +5,6 @@ SCRIPT_DIRECTORY="$(dirname "$FULL_PATH_TO_SCRIPT")" cd "$SCRIPT_DIRECTORY" cd .. -cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DBUILD_SHARED_LIBS=off -DCMAKE_C_FLAGS="-Wno-calloc-transposed-args -Wno-error -pthread -lrt" +cmake -S . -B build -DENABLE_PROGRAMS=OFF -DENABLE_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DBUILD_SHARED_LIBS=off -DCMAKE_C_FLAGS="-Wno-calloc-transposed-args -Wno-error -pthread -lrt" cmake --build build