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

feat: C SSHNPD --monitor-read-timeout flag #1458

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/c/cmake/atsdk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions packages/c/sshnpd/include/sshnpd/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion packages/c/sshnpd/src/background_jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <errno.h>
#include <pthread.h>
#include <sshnpd/background_jobs.h>
#include <sshnpd/sshnpd.h>
#include <sshnpd/main.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
2 changes: 1 addition & 1 deletion packages/c/sshnpd/src/handle_npt_request.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "sshnpd/main.h"
#include "sshnpd/params.h"
#include "sshnpd/permitopen.h"
#include "sshnpd/sshnpd.h"
#include <atchops/aes.h>
#include <atchops/base64.h>
#include <atchops/iv.h>
Expand Down
8 changes: 4 additions & 4 deletions packages/c/sshnpd/src/handle_ping.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "sshnpd/main.h"
#include "sshnpd/params.h"
#include "sshnpd/sshnpd.h"
#include <atclient/atkey.h>
#include <atclient/monitor.h>
#include <atclient/notify.h>
Expand Down Expand Up @@ -29,17 +29,17 @@ void handle_ping(sshnpd_params *params, atclient_monitor_response *message, char

atclient_notify_params notify_params;
atclient_notify_params_init(&notify_params);
if((ret = atclient_notify_params_set_atkey(&notify_params, &pingkey)) != 0) {
if ((ret = atclient_notify_params_set_atkey(&notify_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(&notify_params, ATCLIENT_NOTIFY_OPERATION_UPDATE)) != 0) {
if ((ret = atclient_notify_params_set_operation(&notify_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(&notify_params, ping_response)) != 0) {
if ((ret = atclient_notify_params_set_value(&notify_params, ping_response)) != 0) {
atlogger_log(LOGGER_TAG, ATLOGGER_LOGGING_LEVEL_ERROR, "Failed to set value in notify params\n");
goto exit_ping;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/c/sshnpd/src/handle_ssh_request.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "sshnpd/main.h"
#include "sshnpd/params.h"
#include "sshnpd/sshnpd.h"
#include <atchops/aes.h>
#include <atchops/base64.h>
#include <atchops/iv.h>
Expand Down
4 changes: 3 additions & 1 deletion packages/c/sshnpd/src/main.c
Original file line number Diff line number Diff line change
@@ -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 <atchops/aes.h>
#include <atchops/iv.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion packages/c/sshnpd/src/params.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <sshnpd/main.h>
#include <sshnpd/params.h>
#include <sshnpd/permitopen.h>
#include <sshnpd/version.h>
Expand All @@ -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) {
Expand Down Expand Up @@ -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", &params->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(),
};

Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion packages/c/sshnpd/tools/debug_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading