@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.
- package/.github/workflows/build.yml +4 -11
- package/binding.gyp +5 -3
- package/lib/close.js +29 -0
- package/lib/express-listener.js +253 -0
- package/lib/express.js +58 -0
- package/lib/index.js +1 -1
- package/lib/init.js +39 -0
- package/lib/listen.js +30 -0
- package/lib/write.js +48 -0
- package/lib/ziti-socket.js +119 -0
- package/lib/ziti.js +14 -4
- package/package.json +1 -1
- package/src/Ziti_https_request.c +1 -1
- package/src/Ziti_https_request_data.c +2 -2
- package/src/Ziti_https_request_end.c +1 -1
- package/src/stack_traces.c +1 -1
- package/src/utils.c +1 -1
- package/src/utils.h +1 -1
- package/src/ziti-add-on.c +8 -4
- package/src/ziti-nodejs.h +16 -1
- package/src/ziti_close.c +1 -1
- package/src/ziti_dial.c +4 -5
- package/src/ziti_enroll.c +2 -2
- package/src/ziti_hello.c +1 -1
- package/src/ziti_init.c +4 -25
- package/src/ziti_listen.c +764 -0
- package/src/ziti_service_available.c +1 -1
- package/src/ziti_shutdown.c +1 -1
- package/src/ziti_websocket_connect.c +1 -1
- package/src/ziti_websocket_write.c +1 -1
- package/src/ziti_write.c +9 -1
- package/tests/https-test.js +11 -9
|
@@ -30,7 +30,7 @@ jobs:
|
|
|
30
30
|
strategy:
|
|
31
31
|
matrix:
|
|
32
32
|
config:
|
|
33
|
-
# - {
|
|
33
|
+
# - { os: windows-latest, cc: "cl", cxx: "cl", node: '16' }
|
|
34
34
|
- { os: ubuntu-18.04, cc: "gcc", cxx: "g++", node: '12' }
|
|
35
35
|
- { os: ubuntu-18.04, cc: "gcc", cxx: "g++", node: '13' }
|
|
36
36
|
- { os: ubuntu-18.04, cc: "gcc", cxx: "g++", node: '14' }
|
|
@@ -197,19 +197,12 @@ jobs:
|
|
|
197
197
|
run: |
|
|
198
198
|
npm run build:cleanup
|
|
199
199
|
|
|
200
|
-
- name: Publish Binary to S3 (
|
|
200
|
+
- name: Publish Binary to S3 (for all OS's, Node versions, and architectures)
|
|
201
201
|
run: |
|
|
202
202
|
./node_modules/.bin/node-pre-gyp package unpublish publish
|
|
203
203
|
sleep 5
|
|
204
204
|
if: |
|
|
205
|
-
steps.extract_branch.outputs.branch == 'main'
|
|
206
|
-
|
|
207
|
-
- name: Publish Binary to S3 (Linux)
|
|
208
|
-
run: |
|
|
209
|
-
./node_modules/.bin/node-pre-gyp package unpublish publish
|
|
210
|
-
sleep 5
|
|
211
|
-
if: |
|
|
212
|
-
steps.extract_branch.outputs.branch == 'main' && matrix.config.os == 'ubuntu-18.04' && matrix.config.node != '14'
|
|
205
|
+
steps.extract_branch.outputs.branch == 'main'
|
|
213
206
|
|
|
214
207
|
- name: Install Binary
|
|
215
208
|
run: |
|
|
@@ -228,4 +221,4 @@ jobs:
|
|
|
228
221
|
token: ${{ secrets.NPM_TOKEN }}
|
|
229
222
|
access: public
|
|
230
223
|
if: |
|
|
231
|
-
matrix.config.os == 'ubuntu-18.04' && matrix.config.node == '
|
|
224
|
+
matrix.config.os == 'ubuntu-18.04' && matrix.config.node == '16' && matrix.architecture == 'x64' && steps.extract_branch.outputs.branch == 'main'
|
package/binding.gyp
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"./src/Ziti_https_request_data.c",
|
|
37
37
|
"./src/Ziti_https_request_end.c",
|
|
38
38
|
"./src/ziti_init.c",
|
|
39
|
+
"./src/ziti_listen.c",
|
|
39
40
|
"./src/ziti_service_available.c",
|
|
40
41
|
"./src/ziti_shutdown.c",
|
|
41
42
|
"./src/ziti_write.c",
|
|
@@ -105,18 +106,19 @@
|
|
|
105
106
|
"GCC_ENABLE_PASCAL_STRINGS": "NO", # No -mpascal-strings
|
|
106
107
|
"GCC_THREADSAFE_STATICS": "NO", # -fno-threadsafe-statics
|
|
107
108
|
"PREBINDING": "NO", # No -Wl,-prebind
|
|
108
|
-
"MACOSX_DEPLOYMENT_TARGET": "
|
|
109
|
+
"MACOSX_DEPLOYMENT_TARGET": "12", # -mmacosx-version-min=10.14
|
|
109
110
|
"USE_HEADERMAP": "NO",
|
|
110
111
|
"OTHER_CFLAGS": [
|
|
111
112
|
"-fno-strict-aliasing",
|
|
112
113
|
"-g",
|
|
113
114
|
"-fno-pie",
|
|
114
115
|
"-DSOURCE_PATH_SIZE=3",
|
|
115
|
-
"-DZITI_OS=macos"
|
|
116
|
+
"-DZITI_OS=macos",
|
|
117
|
+
"-DCXXFLAGS=-mmacosx-version-min=11",
|
|
116
118
|
],
|
|
117
119
|
"OTHER_LDFLAGS": [
|
|
118
120
|
"-g",
|
|
119
|
-
"-mmacosx-version-min=
|
|
121
|
+
"-mmacosx-version-min=11",
|
|
120
122
|
],
|
|
121
123
|
"WARNING_CFLAGS": [
|
|
122
124
|
"-Wall",
|
package/lib/close.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Netfoundry, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* close()
|
|
20
|
+
*
|
|
21
|
+
* @param {*} conn
|
|
22
|
+
*/
|
|
23
|
+
const close = ( conn, ) => {
|
|
24
|
+
|
|
25
|
+
ziti.ziti_close( conn );
|
|
26
|
+
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.close = close;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Netfoundry, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const zitiListen = require('./listen').listen;
|
|
18
|
+
const EventEmitter = require('events');
|
|
19
|
+
const { ZitiSocket } = require('./ziti-socket');
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const normalizedArgsSymbol = Symbol('normalizedArgs');
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
var _serversIndex = 1;
|
|
26
|
+
var _servers = new Map();
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* on_listen()
|
|
30
|
+
*
|
|
31
|
+
* @param {*} status
|
|
32
|
+
*/
|
|
33
|
+
Server.prototype.on_listen = ( status ) => {
|
|
34
|
+
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* on_listen_client()
|
|
39
|
+
*
|
|
40
|
+
* @param {*} obj
|
|
41
|
+
*/
|
|
42
|
+
Server.prototype.on_listen_client = ( obj ) => {
|
|
43
|
+
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* on_client_write()
|
|
48
|
+
*
|
|
49
|
+
* @param {*} obj
|
|
50
|
+
*/
|
|
51
|
+
Server.prototype.on_client_write = ( obj ) => {
|
|
52
|
+
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* on_listen_client_connect()
|
|
57
|
+
*
|
|
58
|
+
* @param {*} obj
|
|
59
|
+
*/
|
|
60
|
+
Server.prototype.on_listen_client_connect = ( obj ) => {
|
|
61
|
+
|
|
62
|
+
let self = _servers.get(obj.js_arb_data);
|
|
63
|
+
|
|
64
|
+
const socket = new ZitiSocket({ client: obj.client });
|
|
65
|
+
|
|
66
|
+
self._socket = socket;
|
|
67
|
+
|
|
68
|
+
self.emit('connection', socket);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* on_listen_client_data()
|
|
73
|
+
*
|
|
74
|
+
* @param {*} obj
|
|
75
|
+
*/
|
|
76
|
+
Server.prototype.on_listen_client_data = ( obj ) => {
|
|
77
|
+
|
|
78
|
+
let self = _servers.get(obj.js_arb_data);
|
|
79
|
+
let socket = self._socket;
|
|
80
|
+
|
|
81
|
+
socket.captureData(obj.app_data);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @param {*} args
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
function normalizeArgs(args) {
|
|
91
|
+
let arr;
|
|
92
|
+
|
|
93
|
+
if (args.length === 0) {
|
|
94
|
+
arr = [{}, null];
|
|
95
|
+
arr[normalizedArgsSymbol] = true;
|
|
96
|
+
return arr;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const arg0 = args[0];
|
|
100
|
+
let options = {};
|
|
101
|
+
if (typeof arg0 === 'object' && arg0 !== null) {
|
|
102
|
+
// (options[...][, cb])
|
|
103
|
+
options = arg0;
|
|
104
|
+
} else {
|
|
105
|
+
// ([port][, host][...][, cb])
|
|
106
|
+
options.port = arg0;
|
|
107
|
+
if (args.length > 1 && typeof args[1] === 'string') {
|
|
108
|
+
options.host = args[1];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const cb = args[args.length - 1];
|
|
113
|
+
if (typeof cb !== 'function')
|
|
114
|
+
arr = [options, null];
|
|
115
|
+
else
|
|
116
|
+
arr = [options, cb];
|
|
117
|
+
|
|
118
|
+
arr[normalizedArgsSymbol] = true;
|
|
119
|
+
return arr;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function Server(serviceName, options, connectionListener) {
|
|
123
|
+
|
|
124
|
+
if (!(this instanceof Server))
|
|
125
|
+
return new Server(options, connectionListener);
|
|
126
|
+
|
|
127
|
+
EventEmitter.call(this);
|
|
128
|
+
|
|
129
|
+
if (typeof options === 'function') {
|
|
130
|
+
connectionListener = options;
|
|
131
|
+
options = {};
|
|
132
|
+
this.on('connection', connectionListener);
|
|
133
|
+
} else if (options == null || typeof options === 'object') {
|
|
134
|
+
options = { ...options };
|
|
135
|
+
|
|
136
|
+
if (typeof connectionListener === 'function') {
|
|
137
|
+
this.on('connection', connectionListener);
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
|
|
141
|
+
}
|
|
142
|
+
if (typeof options.keepAliveInitialDelay !== 'undefined') {
|
|
143
|
+
validateNumber(
|
|
144
|
+
options.keepAliveInitialDelay, 'options.keepAliveInitialDelay'
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
if (options.keepAliveInitialDelay < 0) {
|
|
148
|
+
options.keepAliveInitialDelay = 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
this._serviceName = serviceName;
|
|
153
|
+
|
|
154
|
+
this._connections = 0;
|
|
155
|
+
|
|
156
|
+
// this[async_id_symbol] = -1;
|
|
157
|
+
this._handle = null;
|
|
158
|
+
this._usingWorkers = false;
|
|
159
|
+
this._workers = [];
|
|
160
|
+
this._unref = false;
|
|
161
|
+
|
|
162
|
+
this.allowHalfOpen = options.allowHalfOpen || false;
|
|
163
|
+
this.pauseOnConnect = !!options.pauseOnConnect;
|
|
164
|
+
this.noDelay = Boolean(options.noDelay);
|
|
165
|
+
this.keepAlive = Boolean(options.keepAlive);
|
|
166
|
+
this.keepAliveInitialDelay = ~~(options.keepAliveInitialDelay / 1000);
|
|
167
|
+
}
|
|
168
|
+
Object.setPrototypeOf(Server.prototype, EventEmitter.prototype);
|
|
169
|
+
Object.setPrototypeOf(Server, EventEmitter);
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
Server.prototype.listen = function( serviceName, ...args ) {
|
|
173
|
+
|
|
174
|
+
let normalized = normalizeArgs(args);
|
|
175
|
+
normalized = normalizeArgs(normalized[0]);
|
|
176
|
+
|
|
177
|
+
// let options = normalized[0]; // we currently ignore options (a.k.a. `port`)
|
|
178
|
+
let cb = normalized[1];
|
|
179
|
+
if (cb === null) { cb = this.on_listen; } // Use our on_listen cb is necessary, else use cb from teh calling app
|
|
180
|
+
|
|
181
|
+
let index = _serversIndex++;
|
|
182
|
+
_servers.set(index, this);
|
|
183
|
+
|
|
184
|
+
zitiListen( serviceName, index, cb, this.on_listen_client, this.on_listen_client_connect, this.on_listen_client_data );
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
Server.prototype.address = function() {
|
|
188
|
+
if (this._handle && this._handle.getsockname) {
|
|
189
|
+
const out = {};
|
|
190
|
+
const err = this._handle.getsockname(out);
|
|
191
|
+
if (err) {
|
|
192
|
+
throw errnoException(err, 'address');
|
|
193
|
+
}
|
|
194
|
+
return out;
|
|
195
|
+
} else if (this._pipeName) {
|
|
196
|
+
return this._pipeName;
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
Server.prototype.close = function(cb) {
|
|
202
|
+
if (typeof cb === 'function') {
|
|
203
|
+
if (!this._handle) {
|
|
204
|
+
this.once('close', function close() {
|
|
205
|
+
cb(new ERR_SERVER_NOT_RUNNING());
|
|
206
|
+
});
|
|
207
|
+
} else {
|
|
208
|
+
this.once('close', cb);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (this._handle) {
|
|
213
|
+
this._handle.close();
|
|
214
|
+
this._handle = null;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (this._usingWorkers) {
|
|
218
|
+
let left = this._workers.length;
|
|
219
|
+
const onWorkerClose = () => {
|
|
220
|
+
if (--left !== 0) return;
|
|
221
|
+
|
|
222
|
+
this._connections = 0;
|
|
223
|
+
this._emitCloseIfDrained();
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// Increment connections to be sure that, even if all sockets will be closed
|
|
227
|
+
// during polling of workers, `close` event will be emitted only once.
|
|
228
|
+
this._connections++;
|
|
229
|
+
|
|
230
|
+
// Poll workers
|
|
231
|
+
for (let n = 0; n < this._workers.length; n++)
|
|
232
|
+
this._workers[n].close(onWorkerClose);
|
|
233
|
+
} else {
|
|
234
|
+
this._emitCloseIfDrained();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return this;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
Object.defineProperty(Server.prototype, 'listening', {
|
|
241
|
+
__proto__: null,
|
|
242
|
+
get: function() {
|
|
243
|
+
return !!this._handle;
|
|
244
|
+
},
|
|
245
|
+
configurable: true,
|
|
246
|
+
enumerable: true
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
module.exports = {
|
|
251
|
+
Server,
|
|
252
|
+
};
|
|
253
|
+
|
package/lib/express.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Netfoundry, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const expressListener = require('./express-listener');
|
|
18
|
+
const { Server } = require('_http_server'); // from NodeJS internals
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* express()
|
|
24
|
+
*
|
|
25
|
+
* @param {*} express
|
|
26
|
+
* @param {*} serviceName
|
|
27
|
+
*/
|
|
28
|
+
const express = ( express, serviceName ) => {
|
|
29
|
+
|
|
30
|
+
var wrappedExpressApp = express();
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Listen for connections.
|
|
34
|
+
*
|
|
35
|
+
* A node `http.Server` is returned, with this
|
|
36
|
+
* application (which is a `Function`) as its
|
|
37
|
+
* callback.
|
|
38
|
+
*
|
|
39
|
+
* @return {http.Server}
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
wrappedExpressApp.listen = function() {
|
|
43
|
+
|
|
44
|
+
Object.setPrototypeOf(Server.prototype, expressListener.Server.prototype);
|
|
45
|
+
Object.setPrototypeOf(Server, expressListener.Server);
|
|
46
|
+
var server = new Server(this);
|
|
47
|
+
|
|
48
|
+
expressListener.Server.call( server, serviceName, { } );
|
|
49
|
+
|
|
50
|
+
return server.listen(serviceName, arguments);
|
|
51
|
+
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return wrappedExpressApp;
|
|
55
|
+
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
exports.express = express;
|
package/lib/index.js
CHANGED
package/lib/init.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Netfoundry, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* init()
|
|
20
|
+
*
|
|
21
|
+
* @param {*} identityPath
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
const init = ( identityPath ) => {
|
|
25
|
+
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
|
|
28
|
+
let rc = ziti.ziti_init( identityPath, ( result ) => {
|
|
29
|
+
return resolve( result );
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (rc < 0) {
|
|
33
|
+
return reject(`ziti.init() failed with return code ${rc}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.init = init;
|
package/lib/listen.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Netfoundry, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* listen()
|
|
20
|
+
*
|
|
21
|
+
* @param {*} identityPath
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
const listen = ( serviceName, js_arb_data, on_listen, on_listen_client, on_client_connect, on_client_data ) => {
|
|
25
|
+
|
|
26
|
+
ziti.ziti_listen( serviceName, js_arb_data, on_listen, on_listen_client, on_client_connect, on_client_data );
|
|
27
|
+
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.listen = listen;
|
package/lib/write.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Netfoundry, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* on_write()
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
const on_write = ( status ) => {
|
|
23
|
+
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* write()
|
|
29
|
+
*
|
|
30
|
+
* @param {*} conn
|
|
31
|
+
* @param {*} buf
|
|
32
|
+
* @param {*} on_write callback
|
|
33
|
+
*/
|
|
34
|
+
const write = ( conn, buf, on_write_cb ) => {
|
|
35
|
+
|
|
36
|
+
let cb;
|
|
37
|
+
|
|
38
|
+
if (typeof on_write_cb === 'undefined') {
|
|
39
|
+
cb = on_write;
|
|
40
|
+
} else {
|
|
41
|
+
cb = on_write_cb;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
ziti.ziti_write( conn, buf, cb );
|
|
45
|
+
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.write = write;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright Netfoundry, Inc.
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const EventEmitter = require('events');
|
|
18
|
+
const stream = require('node:stream');
|
|
19
|
+
const zitiWrite = require('./write').write;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class ZitiSocket extends EventEmitter {
|
|
24
|
+
|
|
25
|
+
constructor(opts) {
|
|
26
|
+
|
|
27
|
+
super();
|
|
28
|
+
|
|
29
|
+
if (typeof opts !== 'undefined') {
|
|
30
|
+
if (typeof opts.client !== 'undefined') {
|
|
31
|
+
this.client = opts.client;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this._writableState = new stream.Writable.WritableState({}, this, true);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* This stream is where we'll put any data returned from Ziti (see on_listen_client_data cb)
|
|
39
|
+
*/
|
|
40
|
+
let self = this;
|
|
41
|
+
this.readableZitiStream = new ReadableStream({
|
|
42
|
+
start(controller) {
|
|
43
|
+
self.readableZitiStreamController = controller;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
captureData(data) {
|
|
53
|
+
|
|
54
|
+
if ((typeof data !== 'undefined') && (data.byteLength > 0)) {
|
|
55
|
+
|
|
56
|
+
this.readableZitiStreamController.enqueue(data);
|
|
57
|
+
this.emit('data', data);
|
|
58
|
+
|
|
59
|
+
} else {
|
|
60
|
+
|
|
61
|
+
this.emit('close');
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Implements the writeable stream method `_write` by pushing the data onto the underlying Ziti connection.
|
|
69
|
+
*/
|
|
70
|
+
async write(chunk, encoding, cb) {
|
|
71
|
+
|
|
72
|
+
let buffer;
|
|
73
|
+
|
|
74
|
+
if (typeof chunk === 'string' || chunk instanceof String) {
|
|
75
|
+
buffer = Buffer.from(chunk, 'utf8');
|
|
76
|
+
} else if (Buffer.isBuffer(chunk)) {
|
|
77
|
+
buffer = chunk;
|
|
78
|
+
} else if (chunk instanceof Uint8Array) {
|
|
79
|
+
buffer = Buffer.from(chunk, 'utf8');
|
|
80
|
+
} else {
|
|
81
|
+
throw new Error('chunk type of [' + typeof chunk + '] is not a supported type');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (buffer.length > 0) {
|
|
85
|
+
zitiWrite(this.client, buffer);
|
|
86
|
+
}
|
|
87
|
+
if (cb) {
|
|
88
|
+
cb();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
_read() { /* NOP */ }
|
|
96
|
+
read() { /* NOP */ }
|
|
97
|
+
destroy() { /* NOP */ }
|
|
98
|
+
cork() { /* NOP */ }
|
|
99
|
+
uncork() { /* NOP */ }
|
|
100
|
+
pause() { /* NOP */ }
|
|
101
|
+
resume() { /* NOP */ }
|
|
102
|
+
destroy() { /* NOP */ }
|
|
103
|
+
end(data, encoding, callback) { /* NOP */ }
|
|
104
|
+
_final(cb) { cb(); }
|
|
105
|
+
setTimeout() { /* NOP */ }
|
|
106
|
+
setNoDelay() { /* NOP */ }
|
|
107
|
+
unshift(head) { /* NOP */ }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
Object.defineProperty(ZitiSocket.prototype, 'writable', {
|
|
111
|
+
get() {
|
|
112
|
+
return (
|
|
113
|
+
true
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
exports.ZitiSocket = ZitiSocket;
|
package/lib/ziti.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright
|
|
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.
|
|
@@ -18,14 +18,13 @@ var binding;
|
|
|
18
18
|
|
|
19
19
|
function importAll (r) {
|
|
20
20
|
r.keys().forEach(key => {
|
|
21
|
-
console.log('importAll() addon key is: ', key);
|
|
22
21
|
binding = r(key); // Load the addon
|
|
23
22
|
});
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
if (typeof require.context == 'function') {
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
importAll( require.context("../build/", true, /\.node$/) );
|
|
29
28
|
|
|
30
29
|
} else {
|
|
31
30
|
|
|
@@ -37,4 +36,15 @@ if (typeof require.context == 'function') {
|
|
|
37
36
|
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
ziti = module.exports = exports = binding;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Attach the external, app-facing, API to the 'ziti' object
|
|
45
|
+
*/
|
|
46
|
+
exports.close = require('./close').close;
|
|
47
|
+
exports.express = require('./express').express;
|
|
48
|
+
exports.init = require('./init').init;
|
|
49
|
+
exports.listen = require('./listen').listen;
|
|
50
|
+
exports.write = require('./write').write;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openziti/ziti-sdk-nodejs",
|
|
3
3
|
"description": "A NodeJS-based SDK for delivering secure applications over a Ziti Network",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.1",
|
|
5
5
|
"main": "./lib/ziti",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "npm run build:init; npm run build:c-sdk; npm install --build-from-source --clang=1",
|