@openziti/ziti-sdk-nodejs 0.7.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 Netfoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 Netfoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -73,7 +73,7 @@ static void CallJs_on_req_body(napi_env env, napi_value js_cb, void* context, vo
73
73
  ZITI_NODEJS_LOG(DEBUG, "status: %zd", item->status);
74
74
 
75
75
  // obj.body = body
76
- rc = napi_create_int32(env, (int32_t)item->body, &js_body);
76
+ rc = napi_create_int32(env, (int64_t)item->body, &js_body);
77
77
  if (rc != napi_ok) {
78
78
  napi_throw_error(env, "EINVAL", "failure to create resp.body");
79
79
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 Netfoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 Netfoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/src/utils.c CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 NetFoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/src/utils.h CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 NetFoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/src/ziti-add-on.c CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 Netfoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -21,9 +21,6 @@ extern void set_signal_handler();
21
21
 
22
22
  napi_value Init(napi_env env, napi_value exports) {
23
23
 
24
- //
25
- thread_loop = NULL;
26
-
27
24
  if (uv_mutex_init(&client_pool_lock))
28
25
  abort();
29
26
 
@@ -65,12 +62,19 @@ napi_value Init(napi_env env, napi_value exports) {
65
62
 
66
63
  #endif
67
64
 
65
+ napi_status status = napi_get_uv_event_loop(env, &thread_loop);
66
+ if (status != napi_ok) {
67
+ ZITI_NODEJS_LOG(ERROR, "napi_get_uv_event_loop failed, status: %d", status);
68
+ abort();
69
+ }
70
+
68
71
  // Expose some Ziti SDK functions to JavaScript
69
72
  expose_ziti_close(env, exports);
70
73
  expose_ziti_dial(env, exports);
71
74
  expose_ziti_enroll(env, exports);
72
75
  expose_ziti_hello(env, exports);
73
76
  expose_ziti_init(env, exports);
77
+ expose_ziti_listen(env, exports);
74
78
  expose_ziti_service_available(env, exports);
75
79
  expose_ziti_shutdown(env, exports);
76
80
  expose_ziti_write(env, exports);
package/src/ziti-nodejs.h CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 Netfoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -93,6 +93,20 @@ typedef struct {
93
93
  napi_threadsafe_function tsfn_on_service_available;
94
94
  } ConnAddonData;
95
95
 
96
+ /**
97
+ *
98
+ */
99
+ typedef struct {
100
+ char *service_name;
101
+ int64_t js_arb_data;
102
+ ziti_connection server;
103
+ napi_async_work work;
104
+ napi_threadsafe_function tsfn_on_listen;
105
+ napi_threadsafe_function tsfn_on_listen_client;
106
+ napi_threadsafe_function tsfn_on_listen_client_connect;
107
+ napi_threadsafe_function tsfn_on_listen_client_data;
108
+ } ListenAddonData;
109
+
96
110
  /**
97
111
  *
98
112
  */
@@ -189,6 +203,7 @@ extern void expose_ziti_dial(napi_env env, napi_value exports);
189
203
  extern void expose_ziti_enroll(napi_env env, napi_value exports);
190
204
  extern void expose_ziti_hello(napi_env env, napi_value exports);
191
205
  extern void expose_ziti_init(napi_env env, napi_value exports);
206
+ extern void expose_ziti_listen(napi_env env, napi_value exports);
192
207
  extern void expose_ziti_service_available(napi_env env, napi_value exports);
193
208
  extern void expose_ziti_shutdown(napi_env env, napi_value exports);
194
209
  extern void expose_ziti_write(napi_env env, napi_value exports);
package/src/ziti_close.c CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 Netfoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/src/ziti_dial.c CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 Netfoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ limitations under the License.
20
20
  // An item that will be generated here and passed into the JavaScript on_data callback
21
21
  typedef struct OnDataItem {
22
22
 
23
- uint8_t *buf;
23
+ const unsigned char *buf;
24
24
  int len;
25
25
 
26
26
  } OnDataItem;
@@ -139,11 +139,10 @@ static void CallJs_on_data(napi_env env, napi_value js_cb, void* context, void*
139
139
 
140
140
 
141
141
 
142
-
143
142
  /**
144
143
  * This function is the callback invoked by the C-SDK when data arrives on the connection.
145
144
  */
146
- ssize_t on_data(ziti_connection conn, uint8_t *buf, ssize_t len) {
145
+ long on_data(struct ziti_conn *conn, const unsigned char *buf, long len) {
147
146
  napi_status status;
148
147
 
149
148
  ConnAddonData* addon_data = (ConnAddonData*) ziti_conn_data(conn);
@@ -168,7 +167,7 @@ ssize_t on_data(ziti_connection conn, uint8_t *buf, ssize_t len) {
168
167
  OnDataItem* item = memset(malloc(sizeof(*item)), 0, sizeof(*item));
169
168
  item->buf = buf;
170
169
  item->buf = calloc(1, len);
171
- memcpy(item->buf, buf, len);
170
+ memcpy((void*)item->buf, buf, len);
172
171
  item->len = len;
173
172
 
174
173
  // if (addon_data->isWebsocket) {
package/src/ziti_enroll.c CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 Netfoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -110,7 +110,7 @@ static void CallJs_on_enroll(napi_env env, napi_value js_cb, void* context, void
110
110
  /**
111
111
  *
112
112
  */
113
- void on_ziti_enroll(ziti_config *cfg, int status, char *err, void *ctx) {
113
+ void on_ziti_enroll(const ziti_config *cfg, int status, const char *err, void *ctx) {
114
114
 
115
115
  ZITI_NODEJS_LOG(DEBUG, "\nstatus: %d, \nerr: %s,\nctx: %p", status, err, ctx);
116
116
 
package/src/ziti_hello.c CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 Netfoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
package/src/ziti_init.c CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2019-2020 Netfoundry, Inc.
2
+ Copyright Netfoundry, Inc.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -17,11 +17,6 @@ limitations under the License.
17
17
  #include "ziti-nodejs.h"
18
18
 
19
19
  ziti_context ztx = NULL;
20
- uv_loop_t *loop = NULL;
21
-
22
- uv_thread_t thread;
23
- uv_async_t async;
24
-
25
20
 
26
21
  typedef struct {
27
22
  napi_async_work work;
@@ -56,7 +51,7 @@ static void CallJs(napi_env env, napi_value js_cb, void* context, void* data) {
56
51
  status = napi_get_undefined(env, &undefined);
57
52
 
58
53
  // Retrieve the rc created by the worker thread.
59
- int rc = (int)data;
54
+ int64_t rc = (int64_t)data;
60
55
  status = napi_create_int64(env, (int64_t)rc, &js_rc);
61
56
  if (status != napi_ok) {
62
57
  napi_throw_error(env, NULL, "Failed to napi_create_int64");
@@ -185,16 +180,6 @@ static void on_ziti_event(ziti_context _ztx, const ziti_event_t *event) {
185
180
  }
186
181
 
187
182
 
188
-
189
- static void child_thread(void *data){
190
- uv_loop_t *thread_loop = (uv_loop_t *) data;
191
-
192
- //Start this loop
193
- uv_run(thread_loop, UV_RUN_DEFAULT);
194
- }
195
-
196
- static void consumer_notify(uv_async_t *handle, int status) { }
197
-
198
183
  /**
199
184
  *
200
185
  */
@@ -267,14 +252,6 @@ napi_value _ziti_init(napi_env env, const napi_callback_info info) {
267
252
  napi_throw_error(env, NULL, "Failed to napi_create_threadsafe_function");
268
253
  }
269
254
 
270
- // Create and set up the consumer thread
271
- if (NULL == thread_loop) { // Spawn the loop only once
272
- ZITI_NODEJS_LOG(DEBUG, "calling uv_loop_new()");
273
- thread_loop = uv_loop_new();
274
- uv_async_init(thread_loop, &async, (uv_async_cb)consumer_notify);
275
- uv_thread_create(&thread, (uv_thread_cb)child_thread, thread_loop);
276
- }
277
-
278
255
  // Light this candle!
279
256
  ziti_options *opts = calloc(1, sizeof(ziti_options));
280
257
 
@@ -289,6 +266,8 @@ napi_value _ziti_init(napi_env env, const napi_callback_info info) {
289
266
 
290
267
  int rc = ziti_init_opts(opts, thread_loop);
291
268
 
269
+ ZITI_NODEJS_LOG(DEBUG, "ziti_init_opts rc: %d", rc);
270
+
292
271
  status = napi_create_int32(env, rc, &jsRetval);
293
272
  if (status != napi_ok) {
294
273
  napi_throw_error(env, NULL, "Unable to create return value");