@openziti/ziti-sdk-nodejs 0.6.0 → 0.9.0
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 +23 -12
- package/README.md +19 -4
- package/binding.gyp +12 -10
- 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 +2 -1
- 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 -3
- 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
|
@@ -31,12 +31,21 @@ jobs:
|
|
|
31
31
|
matrix:
|
|
32
32
|
config:
|
|
33
33
|
# - { name: "Win", os: windows-latest, cc: "cl", cxx: "cl" }
|
|
34
|
-
- {
|
|
35
|
-
- {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
34
|
+
- { os: ubuntu-18.04, cc: "gcc", cxx: "g++", node: '12' }
|
|
35
|
+
- { os: ubuntu-18.04, cc: "gcc", cxx: "g++", node: '13' }
|
|
36
|
+
- { os: ubuntu-18.04, cc: "gcc", cxx: "g++", node: '14' }
|
|
37
|
+
- { os: ubuntu-18.04, cc: "gcc", cxx: "g++", node: '15' }
|
|
38
|
+
- { os: ubuntu-18.04, cc: "gcc", cxx: "g++", node: '16' }
|
|
39
|
+
- { os: ubuntu-18.04, cc: "gcc", cxx: "g++", node: '17' }
|
|
40
|
+
- { os: ubuntu-20.04, cc: "gcc", cxx: "g++", node: '18' }
|
|
41
|
+
- { os: macos-latest, cc: "clang", cxx: "clang++", node: '12' }
|
|
42
|
+
- { os: macos-latest, cc: "clang", cxx: "clang++", node: '13' }
|
|
43
|
+
- { os: macos-latest, cc: "clang", cxx: "clang++", node: '14' }
|
|
44
|
+
- { os: macos-latest, cc: "clang", cxx: "clang++", node: '15' }
|
|
45
|
+
- { os: macos-latest, cc: "clang", cxx: "clang++", node: '16' }
|
|
46
|
+
- { os: macos-latest, cc: "clang", cxx: "clang++", node: '17' }
|
|
47
|
+
- { os: macos-latest, cc: "clang", cxx: "clang++", node: '18' }
|
|
48
|
+
architecture: [x64, arm64]
|
|
40
49
|
fail-fast: false
|
|
41
50
|
|
|
42
51
|
steps:
|
|
@@ -58,7 +67,7 @@ jobs:
|
|
|
58
67
|
- name: Node Version
|
|
59
68
|
uses: actions/setup-node@v2
|
|
60
69
|
with:
|
|
61
|
-
node-version: ${{ matrix.node }}
|
|
70
|
+
node-version: ${{ matrix.config.node }}
|
|
62
71
|
|
|
63
72
|
- name: Extract branch name
|
|
64
73
|
shell: bash
|
|
@@ -76,7 +85,7 @@ jobs:
|
|
|
76
85
|
|
|
77
86
|
- name: Install Ninja (Linux)
|
|
78
87
|
run: sudo apt-get install -y ninja-build
|
|
79
|
-
if: matrix.config.os == 'ubuntu-18.04'
|
|
88
|
+
if: matrix.config.os == 'ubuntu-18.04' || matrix.config.os == 'ubuntu-20.04'
|
|
80
89
|
|
|
81
90
|
- name: Install Ninja (Mac)
|
|
82
91
|
run: brew install ninja
|
|
@@ -111,7 +120,7 @@ jobs:
|
|
|
111
120
|
cd ${{ runner.workspace }}/${{ github.event.repository.name }}/deps/ziti-sdk-c/build
|
|
112
121
|
cmake -G Ninja -DUSE_OPENSSL=on -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} ..
|
|
113
122
|
if: |
|
|
114
|
-
matrix.config.os == 'ubuntu-18.04'
|
|
123
|
+
matrix.config.os == 'ubuntu-18.04' || matrix.config.os == 'ubuntu-20.04'
|
|
115
124
|
|
|
116
125
|
- name: Build (embedded) C-SDK Phase-I ( Mac)
|
|
117
126
|
run: |
|
|
@@ -146,7 +155,8 @@ jobs:
|
|
|
146
155
|
cd ${{ runner.workspace }}/${{ github.event.repository.name }}/deps/ziti-sdk-c/build
|
|
147
156
|
cmake --build . --target all
|
|
148
157
|
if: |
|
|
149
|
-
matrix.config.os == 'ubuntu-18.04' ||
|
|
158
|
+
matrix.config.os == 'ubuntu-18.04' ||
|
|
159
|
+
matrix.config.os == 'ubuntu-20.04' ||
|
|
150
160
|
matrix.config.os == 'macOS-latest'
|
|
151
161
|
|
|
152
162
|
# - name: Build (embedded) C-SDK Phase-II (Windows)
|
|
@@ -169,6 +179,7 @@ jobs:
|
|
|
169
179
|
BUILD_DATE: ${{ steps.date.outputs.date }}
|
|
170
180
|
if: |
|
|
171
181
|
matrix.config.os == 'ubuntu-18.04' ||
|
|
182
|
+
matrix.config.os == 'ubuntu-20.04' ||
|
|
172
183
|
matrix.config.os == 'macOS-latest'
|
|
173
184
|
|
|
174
185
|
- name: Build NodeJS-SDK (Windows)
|
|
@@ -198,7 +209,7 @@ jobs:
|
|
|
198
209
|
./node_modules/.bin/node-pre-gyp package unpublish publish
|
|
199
210
|
sleep 5
|
|
200
211
|
if: |
|
|
201
|
-
steps.extract_branch.outputs.branch == 'main' && matrix.config.os == 'ubuntu-18.04' && matrix.node != '14'
|
|
212
|
+
steps.extract_branch.outputs.branch == 'main' && matrix.config.os == 'ubuntu-18.04' && matrix.config.node != '14'
|
|
202
213
|
|
|
203
214
|
- name: Install Binary
|
|
204
215
|
run: |
|
|
@@ -217,4 +228,4 @@ jobs:
|
|
|
217
228
|
token: ${{ secrets.NPM_TOKEN }}
|
|
218
229
|
access: public
|
|
219
230
|
if: |
|
|
220
|
-
matrix.config.os == 'ubuntu-18.04' && matrix.node == '14' && steps.extract_branch.outputs.branch == 'main'
|
|
231
|
+
matrix.config.os == 'ubuntu-18.04' && matrix.config.node == '14' && matrix.architecture == 'x64' && steps.extract_branch.outputs.branch == 'main'
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
---
|
|
26
26
|
[]()
|
|
27
27
|
[]()
|
|
28
|
-
[](https://badge.fury.io/js/@openziti%2Fziti-sdk-nodejs)
|
|
28
|
+
[](https://badge.fury.io/js/@openziti%2Fziti-sdk-nodejs.svg)
|
|
29
29
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
30
30
|
[]()
|
|
31
31
|
[](CONTRIBUTING.md)
|
|
@@ -38,9 +38,16 @@
|
|
|
38
38
|
|
|
39
39
|
# Supported platforms
|
|
40
40
|
|
|
41
|
-
The
|
|
41
|
+
The `@openziti/ziti-sdk-nodejs` module works with the following Node.js versions:
|
|
42
|
+
- v12.x
|
|
43
|
+
- v13.x
|
|
44
|
+
- v14.x
|
|
45
|
+
- v15.x
|
|
46
|
+
- v16.x
|
|
47
|
+
- v17.x
|
|
48
|
+
- v18.x
|
|
42
49
|
|
|
43
|
-
Binaries for most Node versions and platforms are provided by default via [node-pre-gyp](https://github.com/mapbox/node-pre-gyp).
|
|
50
|
+
Binaries for most Node versions and platforms are provided by default via [@mapbox/node-pre-gyp](https://github.com/mapbox/node-pre-gyp).
|
|
44
51
|
|
|
45
52
|
# Installing
|
|
46
53
|
|
|
@@ -48,13 +55,21 @@ Binaries for most Node versions and platforms are provided by default via [node-
|
|
|
48
55
|
npm i @openziti/ziti-sdk-nodejs
|
|
49
56
|
```
|
|
50
57
|
|
|
58
|
+
Special note on previous package:
|
|
59
|
+
|
|
60
|
+
On June 7, 2020 @openziti/ziti-sdk-nodejs@0.6.0 was released. Older, unscoped versions that are not part of the @openziti org are deprecated and only @openziti/ziti-sdk-nodejs will see updates going forward. To upgrade to the new package do:
|
|
61
|
+
|
|
62
|
+
``` js
|
|
63
|
+
npm uninstall ziti-sdk-nodejs --save
|
|
64
|
+
npm install @openziti/ziti-sdk-nodejs --save
|
|
65
|
+
```
|
|
51
66
|
|
|
52
67
|
# Usage
|
|
53
68
|
|
|
54
69
|
**Note:** the module must be [installed](#installing) before use.
|
|
55
70
|
|
|
56
71
|
``` js
|
|
57
|
-
var ziti = require('ziti-sdk-nodejs');
|
|
72
|
+
var ziti = require('@openziti/ziti-sdk-nodejs');
|
|
58
73
|
|
|
59
74
|
const ziti_init = async (identity) => {
|
|
60
75
|
return new Promise((resolve) => {
|
package/binding.gyp
CHANGED
|
@@ -8,19 +8,18 @@
|
|
|
8
8
|
# node v0.6.x doesn't give us its build variables,
|
|
9
9
|
# but on Unix it was only possible to use the system OpenSSL library,
|
|
10
10
|
# so default the variable to "true", v0.8.x node and up will overwrite it.
|
|
11
|
-
'node_shared_openssl%': 'true'
|
|
11
|
+
'node_shared_openssl%': 'true',
|
|
12
12
|
|
|
13
13
|
},
|
|
14
14
|
|
|
15
15
|
"targets": [
|
|
16
16
|
{
|
|
17
17
|
'defines': [
|
|
18
|
-
'BUILD_DATE
|
|
19
|
-
'ZITI_BRANCH
|
|
20
|
-
'ZITI_COMMIT
|
|
21
|
-
'ZITI_VERSION
|
|
22
|
-
'
|
|
23
|
-
'ZITI_ARCH=<@(ZITI_ARCH)',
|
|
18
|
+
'BUILD_DATE=<!(echo <!(date))',
|
|
19
|
+
'ZITI_BRANCH=<!(git branch --show-current)',
|
|
20
|
+
'ZITI_COMMIT=<!(git rev-parse --short HEAD)',
|
|
21
|
+
'ZITI_VERSION=<!(jq -r .version package.json)',
|
|
22
|
+
'ZITI_ARCH=<!(arch)',
|
|
24
23
|
],
|
|
25
24
|
|
|
26
25
|
"target_name": "<(module_name)",
|
|
@@ -37,6 +36,7 @@
|
|
|
37
36
|
"./src/Ziti_https_request_data.c",
|
|
38
37
|
"./src/Ziti_https_request_end.c",
|
|
39
38
|
"./src/ziti_init.c",
|
|
39
|
+
"./src/ziti_listen.c",
|
|
40
40
|
"./src/ziti_service_available.c",
|
|
41
41
|
"./src/ziti_shutdown.c",
|
|
42
42
|
"./src/ziti_write.c",
|
|
@@ -106,17 +106,19 @@
|
|
|
106
106
|
"GCC_ENABLE_PASCAL_STRINGS": "NO", # No -mpascal-strings
|
|
107
107
|
"GCC_THREADSAFE_STATICS": "NO", # -fno-threadsafe-statics
|
|
108
108
|
"PREBINDING": "NO", # No -Wl,-prebind
|
|
109
|
-
"MACOSX_DEPLOYMENT_TARGET": "
|
|
109
|
+
"MACOSX_DEPLOYMENT_TARGET": "12", # -mmacosx-version-min=10.14
|
|
110
110
|
"USE_HEADERMAP": "NO",
|
|
111
111
|
"OTHER_CFLAGS": [
|
|
112
112
|
"-fno-strict-aliasing",
|
|
113
113
|
"-g",
|
|
114
114
|
"-fno-pie",
|
|
115
|
-
"-DSOURCE_PATH_SIZE=3"
|
|
115
|
+
"-DSOURCE_PATH_SIZE=3",
|
|
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;
|