Skip to content

Commit e981588

Browse files
committed
feat(wip): checking in v2 of C srv
1 parent 2717787 commit e981588

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+4371
-1172
lines changed

dev_docs/socket_connector_design_H1-2025.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ connector into an application directly.
108108

109109
There are more types to of channel IO to consider below.
110110

111-
#### Directional Typing
111+
#### Directional Typing ("Class")
112112

113113
- Inbound IO like tcp bind sockets, which accept a connection to be used
114+
- Accepted IO like tcp accepted sockets
114115
- Outbound IO like tcp clients, which make connections to bind sockets
115116

116117
#### Remote IO vs Local IO
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Streaming Between Dart and C
2+
3+
Date: 04/04/2025
4+
5+
## Overview
6+
7+
The main purpose of being able to stream between C and Dart is so that we can
8+
embed C srv into NoPorts Desktop and possibly npt/sshnp.
9+
10+
C srv already has a standalone ring buffer implementation, so it seems that
11+
exposing the ring buffer as a control_io in C may be the simplest path forward.
12+
With it exposed, we can wrap it in Dart ffi, and wrap that into a Dart stream.
13+
14+
Any further difficulties or considerations will be documented as they appear.

packages/c/.clang-format

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
---
22
Language: Cpp # Covers C and C++
33
BasedOnStyle: LLVM # Added this to ensure a sane set of defaults
4-
ColumnLimit: 120 # LLVM uses 80, but we mostly use 120 at Atsign

packages/c/justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ configure-dev:
108108
-DSSHNPD_ENABLE_TESTING_SHUTDOWN_NOTIFICATION=ON
109109

110110
configure-strict:
111-
cmake -B {{ dev_dir }} \
111+
cmake -B {{ strict_dir }} \
112112
-S $PWD \
113113
-G "$GENERATOR" \
114114
--preset dev \

packages/c/srv/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
just.env

packages/c/srv/CMakeLists.txt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ project(srv VERSION 1.0.4 LANGUAGES C)
1010
# globs are known as bad practice, so we do not use them here
1111
set(
1212
SRV_SRCS
13+
${CMAKE_CURRENT_LIST_DIR}/src/authenticate.c
14+
${CMAKE_CURRENT_LIST_DIR}/src/channel.c
15+
${CMAKE_CURRENT_LIST_DIR}/src/channel_io.c
16+
${CMAKE_CURRENT_LIST_DIR}/src/channel_io_tcp.c
17+
${CMAKE_CURRENT_LIST_DIR}/src/channel_sink.c
18+
${CMAKE_CURRENT_LIST_DIR}/src/channel_transformer.c
19+
${CMAKE_CURRENT_LIST_DIR}/src/channel_transformer_aes_ctr.c
1320
${CMAKE_CURRENT_LIST_DIR}/src/params.c
14-
${CMAKE_CURRENT_LIST_DIR}/src/side.c
21+
${CMAKE_CURRENT_LIST_DIR}/src/pthread_handle.c
22+
${CMAKE_CURRENT_LIST_DIR}/src/ring.c
23+
${CMAKE_CURRENT_LIST_DIR}/src/session.c
24+
${CMAKE_CURRENT_LIST_DIR}/src/session_control.c
25+
${CMAKE_CURRENT_LIST_DIR}/src/session_single.c
26+
${CMAKE_CURRENT_LIST_DIR}/src/session_stacking.c
1527
${CMAKE_CURRENT_LIST_DIR}/src/srv.c
1628
)
1729

@@ -67,16 +79,16 @@ endif()
6779
# 5. Create srv_lib library target
6880

6981
add_compile_options("-pthread")
70-
add_library(${PROJECT_NAME}-lib STATIC ${SRV_SRCS})
82+
add_library(lib${PROJECT_NAME} STATIC ${SRV_SRCS})
7183

7284
target_link_libraries(
73-
${PROJECT_NAME}-lib
85+
lib${PROJECT_NAME}
7486
PRIVATE argparse::argparse-static atlogger atchops mbedtls
7587
)
7688

7789
# Set include directories for srv target
7890
target_include_directories(
79-
${PROJECT_NAME}-lib
91+
lib${PROJECT_NAME}
8092
PUBLIC
8193
$<BUILD_INTERFACE:${SRV_INCLUDE_DIR}>
8294
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
@@ -85,13 +97,13 @@ target_include_directories(
8597
# 6 Install srv library
8698
# This step configures running `cmake --build build --target install` (which is the same thing as `make install`)
8799
# This work also helps other CMake projects use `find_package(atclient)` to find our library, once installed.
88-
list(APPEND SRV_TARGETS_TO_INSTALL ${PROJECT_NAME}-lib) # install srv_lib
100+
list(APPEND SRV_TARGETS_TO_INSTALL lib${PROJECT_NAME}) # install srv_lib
89101

90102
foreach(target ${SRV_TARGETS_TO_INSTALL})
91103
message(STATUS "[SRV] Installing ${target}..")
92104
install(
93105
TARGETS ${target}
94-
EXPORT ${PROJECT_NAME}-lib-config
106+
EXPORT lib${PROJECT_NAME}-config
95107
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
96108
)
97109
endforeach()
@@ -102,11 +114,11 @@ install(
102114
)
103115

104116
# 7. Create srv executable target
105-
add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/src/main.c)
117+
add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/src/srv.c)
106118

107119
target_link_libraries(
108120
${PROJECT_NAME}
109-
PRIVATE ${PROJECT_NAME}-lib atlogger atchops mbedtls argparse::argparse-static
121+
PRIVATE lib${PROJECT_NAME} atlogger atchops mbedtls argparse::argparse-static
110122
)
111123

112124
# 8. Build tests

packages/c/srv/include/srv/params.h

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,60 @@
11
#ifndef SRV_PARAMS_H
22
#define SRV_PARAMS_H
3-
#define SRV_VERSION "0.1.0"
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
46

5-
#include <argparse/argparse.h>
6-
#include <getopt.h>
7-
#include <stdbool.h>
87
#include <stdint.h>
98

10-
typedef struct {
11-
char *rvd_auth_string;
12-
char *session_aes_key_string;
13-
char *session_aes_iv_string;
14-
} srv_env_t;
15-
16-
/**
17-
* @brief Free the memory allocated for a single side of the socket connection.
18-
*
19-
* @param side a pointer to the side struture which will be freed by this function.
20-
*/
21-
typedef struct {
9+
enum srv_io_type {
10+
srv_io_type_tcp_client = 0,
11+
srv_io_type_tcp_bind = 1,
12+
};
13+
14+
enum srv_transformer_type {
15+
srv_transformer_none = 0,
16+
srv_transformer_aes_ctr = 1,
17+
};
18+
19+
enum srv_auth_type {
20+
srv_auth_type_none = 0,
21+
srv_auth_type_payload = 1,
22+
};
23+
24+
enum srv_channel_mode {
25+
srv_mode_single = 0,
26+
srv_mode_stacking = 1,
27+
srv_mode_control = 2,
28+
};
29+
30+
struct srv_params {
2231
char *host;
23-
uint16_t port;
24-
uint16_t local_port;
32+
char *port;
2533
char *local_host;
34+
char *local_port;
2635

27-
bool bind_local_port;
28-
bool rv_auth;
29-
bool rv_e2ee;
30-
bool multi;
3136
int timeout;
3237

33-
char *rvd_auth_string;
34-
char *session_aes_key_string;
35-
char *session_aes_iv_string;
36-
} srv_params_t;
37-
38-
/**
39-
* @brief Apply the default values to a params structure
40-
*
41-
* @param params a pointer to the parameters structure to apply the defaults to.
42-
*/
43-
void apply_default_values_to_srv_params(srv_params_t *params);
44-
45-
/**
46-
* @brief Parse parameters into a params structure
47-
*
48-
* @param params a pointer ot the parameters structure
49-
* @param argc the count of arguments
50-
* @param argv the list of arguments
51-
*/
52-
int parse_srv_params(srv_params_t *params, int argc, const char **argv, srv_env_t *environment);
53-
38+
enum srv_channel_mode mode;
39+
enum srv_io_type remote_io;
40+
enum srv_io_type local_io;
41+
enum srv_transformer_type transformer;
42+
enum srv_auth_type remote_auth;
43+
uint8_t verbose : 1;
44+
};
45+
46+
#define srv_params_initializer \
47+
(struct srv_params) { \
48+
.host = NULL, .port = NULL, .local_host = "localhost", .local_port = "0", \
49+
.timeout = 60, .mode = srv_mode_single, \
50+
.remote_io = srv_io_type_tcp_client, .local_io = srv_io_type_tcp_client, \
51+
.transformer = srv_transformer_aes_ctr, \
52+
.remote_auth = srv_auth_type_payload, .verbose = 0, \
53+
}
54+
55+
int parse_srv_params(int argc, char **argv, struct srv_params *params);
56+
57+
#ifdef __cplusplus
58+
}
59+
#endif
5460
#endif

packages/c/srv/include/srv/side.h

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)