iosignal 3.3.0 → 4.5.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/.vscode/settings.json +3 -0
- package/README.md +38 -559
- package/dist/io.d.ts +16 -9
- package/dist/io.js +5 -5
- package/dist/io.js.map +1 -1
- package/dist/io.min.js +5 -5
- package/dist/io.min.js.map +1 -1
- package/dist/iosignal.js +339 -268
- package/dist/types/client/IOCore.d.ts +17 -10
- package/dist/types/common/constants.d.ts +27 -37
- package/index.js +4 -3
- package/package.json +3 -4
- package/src/auth/BohoAuth.js +48 -11
- package/src/auth/{Auth_File.js → key_providers/FileKeyProvider.js} +8 -20
- package/src/auth/{Auth_Redis.js → key_providers/RedisKeyProvider.js} +4 -7
- package/src/auth/key_providers/StringKeyProvider.js +54 -0
- package/src/client/IOCongSocket.js +5 -3
- package/src/client/IOCore.js +118 -89
- package/src/client/IOWS.js +5 -3
- package/src/client/browser/IOWebSocket.js +5 -3
- package/src/common/constants.js +31 -44
- package/src/common/util.js +3 -0
- package/src/server/Manager.js +13 -12
- package/src/server/Remote.js +4 -1
- package/src/server/RemoteCore.js +23 -17
- package/src/server/Server.js +7 -7
- package/README.ko.md +0 -566
- package/auth_file.js +0 -23
- package/auth_file.json +0 -13
- package/docs/iosignal_architecture.png +0 -0
- package/examples/react-chat-js/dist/assets/index-Cy4qaVcJ.js +0 -56
- package/examples/react-chat-js/dist/assets/index-NETrjYhz.css +0 -1
- package/examples/react-chat-js/dist/assets/index-e2KOTYW8.js +0 -65
- package/examples/react-chat-js/dist/index.html +0 -14
- package/examples/react-chat-js/index.html +0 -13
- package/examples/react-chat-js/package-lock.json +0 -1723
- package/examples/react-chat-js/package.json +0 -20
- package/examples/react-chat-js/src/App.css +0 -61
- package/examples/react-chat-js/src/App.jsx +0 -125
- package/examples/react-chat-js/src/index.css +0 -13
- package/examples/react-chat-js/src/main.jsx +0 -13
- package/examples/react-chat-js/src/shared_io.js +0 -12
- package/examples/react-chat-js/vite.config.js +0 -7
- package/examples/server/index.js +0 -65
- package/examples/server/package-lock.json +0 -878
- package/examples/server/package.json +0 -13
- package/examples/server/public/index.html +0 -26
- package/examples/svelte-chat-js/.devtools +0 -3
- package/examples/svelte-chat-js/README.md +0 -38
- package/examples/svelte-chat-js/package-lock.json +0 -1421
- package/examples/svelte-chat-js/package.json +0 -23
- package/examples/svelte-chat-js/src/app.css +0 -105
- package/examples/svelte-chat-js/src/app.d.ts +0 -13
- package/examples/svelte-chat-js/src/app.html +0 -13
- package/examples/svelte-chat-js/src/lib/images/github.svg +0 -1
- package/examples/svelte-chat-js/src/lib/images/svelte-logo.svg +0 -1
- package/examples/svelte-chat-js/src/lib/images/svelte-welcome.png +0 -0
- package/examples/svelte-chat-js/src/lib/images/svelte-welcome.webp +0 -0
- package/examples/svelte-chat-js/src/lib/shared_io.js +0 -12
- package/examples/svelte-chat-js/src/routes/+layout.svelte +0 -5
- package/examples/svelte-chat-js/src/routes/+page.js +0 -3
- package/examples/svelte-chat-js/src/routes/+page.svelte +0 -167
- package/examples/svelte-chat-js/static/favicon.svg +0 -1
- package/examples/svelte-chat-js/static/global.css +0 -19
- package/examples/svelte-chat-js/static/robots.txt +0 -3
- package/examples/svelte-chat-js/svelte.config.js +0 -23
- package/examples/svelte-chat-js/vite.config.js +0 -6
- package/src/auth/Auth_Env.js +0 -76
- package/test-browser/favicon.ico +0 -0
- package/test-browser/index.html +0 -95
- package/test-browser/server.js +0 -12
- package/test-nodejs/client-playToggle.js +0 -19
- package/test-nodejs/client.js +0 -17
- package/test-nodejs/client_api_reply.js +0 -15
- package/test-nodejs/server-Auth_Env.js +0 -19
- package/test-nodejs/server-Auth_File.js +0 -12
- package/test-nodejs/server-api_reply.js +0 -6
- package/test-nodejs/server-api_sudo.js +0 -7
- package/test-nodejs/server.js +0 -20
- package/test-nodejs/signalPack.js +0 -34
- package/test-nodejs/signaling.js +0 -61
- package/test-nodejs/simple-server.js +0 -13
|
@@ -159,7 +159,7 @@ export class IOCore extends EventEmitter<string | symbol, any> {
|
|
|
159
159
|
/**
|
|
160
160
|
* Disables auto-reconnect and closes the current connection.
|
|
161
161
|
* The instance can be re-opened manually later. For complete cleanup, use destroy().
|
|
162
|
-
|
|
162
|
+
*/
|
|
163
163
|
stop(): void;
|
|
164
164
|
/**
|
|
165
165
|
* Permanently destroys the instance, cleaning up all resources.
|
|
@@ -191,18 +191,18 @@ export class IOCore extends EventEmitter<string | symbol, any> {
|
|
|
191
191
|
onClose(): void;
|
|
192
192
|
/**
|
|
193
193
|
* Manually logs in with provided ID and key.
|
|
194
|
-
* @param {string} id - The user ID.
|
|
194
|
+
* @param {string} id - The user ID. or 'id.key'
|
|
195
195
|
* @param {string} key - The user key.
|
|
196
|
-
* @returns {
|
|
196
|
+
* @returns {this}
|
|
197
197
|
*/
|
|
198
|
-
login(id: string, key: string):
|
|
198
|
+
login(id: string, key: string): this;
|
|
199
199
|
/**
|
|
200
200
|
* Sets up authentication for auto-login.
|
|
201
|
-
* @param {string} id - The user ID.
|
|
201
|
+
* @param {string} id - The user ID. or 'id.Key'
|
|
202
202
|
* @param {string} key - The user key.
|
|
203
|
-
* @returns {
|
|
203
|
+
* @returns {this}
|
|
204
204
|
*/
|
|
205
|
-
auth(id: string, key: string):
|
|
205
|
+
auth(id: string, key: string): this;
|
|
206
206
|
/**
|
|
207
207
|
* Handles incoming data from the WebSocket.
|
|
208
208
|
* @param {Buffer} buffer - The incoming data buffer.
|
|
@@ -261,10 +261,12 @@ export class IOCore extends EventEmitter<string | symbol, any> {
|
|
|
261
261
|
*/
|
|
262
262
|
testPromise(buffer: Buffer): void;
|
|
263
263
|
/**
|
|
264
|
-
*
|
|
264
|
+
* alias of signal()
|
|
265
|
+
* Sends a signal with a tag and arguments.
|
|
266
|
+
* @param {string} tag - The signal tag.
|
|
265
267
|
* @param {...any} args - Arguments for the signal.
|
|
266
268
|
*/
|
|
267
|
-
publish(...args: any[]): void;
|
|
269
|
+
publish(tag: string, ...args: any[]): void;
|
|
268
270
|
/**
|
|
269
271
|
* Sends a signal with a tag and arguments.
|
|
270
272
|
* @param {string} tag - The signal tag.
|
|
@@ -395,6 +397,11 @@ export class IOCore extends EventEmitter<string | symbol, any> {
|
|
|
395
397
|
* Changes the connection state and emits events.
|
|
396
398
|
* @param {string} state - The new state name (e.g., 'ready', 'closed').
|
|
397
399
|
* @param {string} [emitEventAndMessage] - Optional message to emit with the state change event.
|
|
400
|
+
*
|
|
401
|
+
* 주의.
|
|
402
|
+
* 1. 상태가 변경 될 때만 'change' 이벤트 호출된다.
|
|
403
|
+
* 2. emitEventAndMessage 옵션 값이 지정되야 해당 이벤트 이름이 호출된다.
|
|
404
|
+
* 보통 이벤트 이름과 동일하게 적거나 이벤트 상황 안내문을 넣는다.
|
|
398
405
|
*/
|
|
399
406
|
stateChange(state: string, emitEventAndMessage?: string): void;
|
|
400
407
|
}
|
|
@@ -403,7 +410,7 @@ export type IOMsg = import("../common/constants.js").IOMsg;
|
|
|
403
410
|
export type PAYLOAD_TYPE = import("../common/constants.js").PAYLOAD_TYPE;
|
|
404
411
|
export type SIZE_LIMIT = import("../common/constants.js").SIZE_LIMIT;
|
|
405
412
|
export type ENC_MODE = import("../common/constants.js").ENC_MODE;
|
|
406
|
-
export type
|
|
413
|
+
export type STATE = import("../common/constants.js").STATE;
|
|
407
414
|
export type quotaTable = any;
|
|
408
415
|
export type Boho = import("boho").Boho;
|
|
409
416
|
export type Buffer = import("boho").Buffer;
|
|
@@ -1,47 +1,34 @@
|
|
|
1
|
-
export type
|
|
2
|
-
|
|
1
|
+
export type STATE = {
|
|
2
|
+
CONNECTING: number;
|
|
3
3
|
OPEN: number;
|
|
4
|
-
CLOSING: number;
|
|
5
|
-
CLOSED: number;
|
|
6
4
|
SERVER_READY: number;
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
AUTH_ACK: number;
|
|
6
|
+
CLOSING: number;
|
|
9
7
|
READY: number;
|
|
8
|
+
AUTH_FAIL: number;
|
|
9
|
+
AUTH_CLEAR: number;
|
|
10
|
+
CLOSED: number;
|
|
11
|
+
STOP: number;
|
|
10
12
|
REDIRECTING: number;
|
|
11
13
|
};
|
|
12
|
-
export namespace
|
|
13
|
-
let
|
|
14
|
+
export namespace STATE {
|
|
15
|
+
let CONNECTING: number;
|
|
14
16
|
let OPEN: number;
|
|
15
|
-
let CLOSING: number;
|
|
16
|
-
let CLOSED: number;
|
|
17
17
|
let SERVER_READY: number;
|
|
18
|
+
let AUTH_REQ: number;
|
|
19
|
+
let AUTH_NONCE: number;
|
|
20
|
+
let AUTH_HMAC: number;
|
|
21
|
+
let AUTH_ACK: number;
|
|
18
22
|
let AUTH_FAIL: number;
|
|
19
|
-
let
|
|
23
|
+
let AUTH_CLEAR: number;
|
|
24
|
+
let CID_REQ: number;
|
|
25
|
+
let CID_RES: number;
|
|
20
26
|
let READY: number;
|
|
27
|
+
let CLOSING: number;
|
|
28
|
+
let CLOSED: number;
|
|
29
|
+
let STOP: number;
|
|
21
30
|
let REDIRECTING: number;
|
|
22
31
|
}
|
|
23
|
-
export type CLIENT_STATE = {
|
|
24
|
-
INIT: number;
|
|
25
|
-
SENT_SERVER_READY: number;
|
|
26
|
-
RECV_AUTH_REQ: number;
|
|
27
|
-
SENT_SERVER_NONCE: number;
|
|
28
|
-
RECV_AUTH_HMAC: number;
|
|
29
|
-
AUTH_FAIL: number;
|
|
30
|
-
AUTH_READY: number;
|
|
31
|
-
CID_READY: number;
|
|
32
|
-
};
|
|
33
|
-
export namespace CLIENT_STATE {
|
|
34
|
-
export let INIT: number;
|
|
35
|
-
export let SENT_SERVER_READY: number;
|
|
36
|
-
export let RECV_AUTH_REQ: number;
|
|
37
|
-
export let SENT_SERVER_NONCE: number;
|
|
38
|
-
export let RECV_AUTH_HMAC: number;
|
|
39
|
-
let AUTH_FAIL_1: number;
|
|
40
|
-
export { AUTH_FAIL_1 as AUTH_FAIL };
|
|
41
|
-
let AUTH_READY_1: number;
|
|
42
|
-
export { AUTH_READY_1 as AUTH_READY };
|
|
43
|
-
export let CID_READY: number;
|
|
44
|
-
}
|
|
45
32
|
export type ENC_MODE = {
|
|
46
33
|
NO: number;
|
|
47
34
|
YES: number;
|
|
@@ -89,7 +76,7 @@ export type IOMsg = {
|
|
|
89
76
|
CID_REQ: number;
|
|
90
77
|
CID_RES: number;
|
|
91
78
|
QUOTA_LEVEL: number;
|
|
92
|
-
|
|
79
|
+
AUTH_CLEAR: number;
|
|
93
80
|
SERVER_REDIRECT: number;
|
|
94
81
|
LOOP: number;
|
|
95
82
|
ECHO: number;
|
|
@@ -120,10 +107,13 @@ export type IOMsg = {
|
|
|
120
107
|
export namespace IOMsg {
|
|
121
108
|
let SERVER_READY_1: number;
|
|
122
109
|
export { SERVER_READY_1 as SERVER_READY };
|
|
123
|
-
|
|
124
|
-
export
|
|
110
|
+
let CID_REQ_1: number;
|
|
111
|
+
export { CID_REQ_1 as CID_REQ };
|
|
112
|
+
let CID_RES_1: number;
|
|
113
|
+
export { CID_RES_1 as CID_RES };
|
|
125
114
|
export let QUOTA_LEVEL: number;
|
|
126
|
-
|
|
115
|
+
let AUTH_CLEAR_1: number;
|
|
116
|
+
export { AUTH_CLEAR_1 as AUTH_CLEAR };
|
|
127
117
|
export let SERVER_REDIRECT: number;
|
|
128
118
|
export let LOOP: number;
|
|
129
119
|
export let ECHO: number;
|
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { serverOption } from './src/server/serverOption.js'
|
|
|
8
8
|
export { FileLogger } from './src/server/FileLogger.js'
|
|
9
9
|
export { getSignalPack, parsePayload, getPayloadFromSignalPack } from './src/common/payload.js'
|
|
10
10
|
export * from './src/common/constants.js'
|
|
11
|
+
export * from './src/common/util.js'
|
|
11
12
|
|
|
12
13
|
// MBP
|
|
13
14
|
export { default as MBP } from 'meta-buffer-pack'
|
|
@@ -15,9 +16,9 @@ export { default as MBP } from 'meta-buffer-pack'
|
|
|
15
16
|
// boho auth
|
|
16
17
|
export { default as Boho} from 'boho'
|
|
17
18
|
export { BohoAuth } from './src/auth/BohoAuth.js'
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
19
|
+
export { FileKeyProvider } from './src/auth/key_providers/FileKeyProvider.js'
|
|
20
|
+
export { RedisKeyProvider } from './src/auth/key_providers/RedisKeyProvider.js'
|
|
21
|
+
export { StringKeyProvider } from './src/auth/key_providers/StringKeyProvider.js'
|
|
21
22
|
|
|
22
23
|
// api
|
|
23
24
|
export * as api_reply from './src/api/api_reply.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iosignal",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "iosignal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -18,11 +18,10 @@
|
|
|
18
18
|
"unpkg": "./dist/io.min.js",
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "rollup -c && npm run build:types",
|
|
21
|
-
"build:types": "tsc --project tsconfig.json"
|
|
22
|
-
"start": "node ./test-browser/server.js"
|
|
21
|
+
"build:types": "tsc --project tsconfig.json"
|
|
23
22
|
},
|
|
24
23
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
24
|
+
"node": ">=22.0.0"
|
|
26
25
|
},
|
|
27
26
|
"author": {
|
|
28
27
|
"name": "Taeo Lee",
|
package/src/auth/BohoAuth.js
CHANGED
|
@@ -2,12 +2,17 @@ import MBP from 'meta-buffer-pack'
|
|
|
2
2
|
import Boho from 'boho'
|
|
3
3
|
import { quotaTable } from '../common/quotaTable.js'
|
|
4
4
|
import { serverOption } from '../server/serverOption.js'
|
|
5
|
-
import { IOMsg,
|
|
5
|
+
import { IOMsg, STATE } from '../common/constants.js'
|
|
6
6
|
import { FileLogger } from '../server/FileLogger.js'
|
|
7
7
|
|
|
8
8
|
const decoder = new TextDecoder()
|
|
9
9
|
export class BohoAuth {
|
|
10
|
-
constructor() {
|
|
10
|
+
constructor(keyProvider) {
|
|
11
|
+
if (!keyProvider) {
|
|
12
|
+
throw new Error('BohoAuth must be initialized with a keyProvider.');
|
|
13
|
+
}
|
|
14
|
+
this.keyProvider = keyProvider;
|
|
15
|
+
|
|
11
16
|
this.authLogger;
|
|
12
17
|
if (serverOption.fileLogger.auth.use) {
|
|
13
18
|
this.authLogger = new FileLogger(serverOption.fileLogger.auth.path)
|
|
@@ -21,11 +26,11 @@ export class BohoAuth {
|
|
|
21
26
|
this.authLogger.log(peerInfo)
|
|
22
27
|
}
|
|
23
28
|
// console.log('##### AUTH_FAIL reason: ', reason)
|
|
24
|
-
peer.setState(
|
|
29
|
+
peer.setState(STATE.AUTH_FAIL)
|
|
30
|
+
peer.send(Buffer.from([Boho.BohoMsg.AUTH_FAIL]))
|
|
25
31
|
// add some delay time.
|
|
26
|
-
setTimeout(e => {
|
|
27
|
-
|
|
28
|
-
}, serverOption.auth.delay_auth_fail)
|
|
32
|
+
// setTimeout(e => {
|
|
33
|
+
// }, serverOption.auth.delay_auth_fail)
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
async verify_auth_hmac(auth_hmac, peer) {
|
|
@@ -46,7 +51,7 @@ export class BohoAuth {
|
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
//2. get key of id from DB
|
|
49
|
-
let authInfo = await this.getAuth(id)
|
|
54
|
+
let authInfo = await this.keyProvider.getAuth(id)
|
|
50
55
|
|
|
51
56
|
if (!authInfo) {
|
|
52
57
|
this.send_auth_fail(peer, 'NO ID:' + id);
|
|
@@ -97,9 +102,13 @@ export class BohoAuth {
|
|
|
97
102
|
console.log('## trying RELOGIN with SAME ID. ignored.')
|
|
98
103
|
return
|
|
99
104
|
}
|
|
100
|
-
console.log('###
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
console.log('### DUPLICATE_LOGIN detected.', old.cid)
|
|
106
|
+
let sigPack = MBP.pack(
|
|
107
|
+
MBP.MB('#MsgType', '8', IOMsg.AUTH_CLEAR),
|
|
108
|
+
MBP.MB('#reason', 'duplicate login.')
|
|
109
|
+
)
|
|
110
|
+
old.send( sigPack)
|
|
111
|
+
// old.close() client will close and stop.
|
|
103
112
|
peer.close() // auto relogin
|
|
104
113
|
return
|
|
105
114
|
}
|
|
@@ -146,7 +155,7 @@ export class BohoAuth {
|
|
|
146
155
|
// console.log("LOGIN: ", `id: ${ peer.did}(${peer.cid})` )
|
|
147
156
|
//10. send ack.
|
|
148
157
|
peer.send(auth_ack)
|
|
149
|
-
peer.setState(
|
|
158
|
+
peer.setState(STATE.AUTH_ACK)
|
|
150
159
|
if (this.authLogger) {
|
|
151
160
|
let peerInfo = `OK #${peer.ssid} cid: ${peer.cid} did:${peer.did}`
|
|
152
161
|
if (peer.isAdmin) peerInfo = "#ADMIN# " + peerInfo
|
|
@@ -159,6 +168,34 @@ export class BohoAuth {
|
|
|
159
168
|
|
|
160
169
|
}
|
|
161
170
|
|
|
171
|
+
async getAuth(id) {
|
|
172
|
+
return this.keyProvider.getAuth(id);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async getAuthIdList() {
|
|
176
|
+
if (typeof this.keyProvider.getAuthIdList === 'function') {
|
|
177
|
+
return this.keyProvider.getAuthIdList();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async addAuth(id, keyStr, cid, level = 0) {
|
|
182
|
+
if (typeof this.keyProvider.addAuth === 'function') {
|
|
183
|
+
return this.keyProvider.addAuth(id, keyStr, cid, level);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async delAuth(id) {
|
|
188
|
+
if (typeof this.keyProvider.delAuth === 'function') {
|
|
189
|
+
return this.keyProvider.delAuth(id);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async save() {
|
|
194
|
+
if (typeof this.keyProvider.save === 'function') {
|
|
195
|
+
return this.keyProvider.save();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
162
199
|
|
|
163
200
|
}
|
|
164
201
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { BohoAuth } from './BohoAuth.js';
|
|
2
1
|
import { readFileSync } from 'fs'
|
|
3
2
|
import Boho from 'boho'
|
|
4
3
|
import path from 'path'
|
|
5
4
|
|
|
6
|
-
export class
|
|
5
|
+
export class FileKeyProvider {
|
|
7
6
|
constructor(_path) {
|
|
8
|
-
super()
|
|
9
7
|
this.AUTH = new Map();
|
|
10
8
|
let pathObj = path.parse(_path)
|
|
11
9
|
this.path = path.resolve(_path)
|
|
@@ -23,20 +21,9 @@ export class Auth_File extends BohoAuth {
|
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
async getAuth(id) {
|
|
28
|
-
return this.AUTH.get(id)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async getAuthIdList() {
|
|
32
|
-
return Array.from(this.AUTH.keys())
|
|
33
|
-
}
|
|
34
|
-
|
|
35
24
|
//loaded when server start.
|
|
36
25
|
loadAuthInfoFile_JS(path) {
|
|
37
|
-
|
|
38
26
|
import(path).then((file) => {
|
|
39
|
-
|
|
40
27
|
console.log(file.authInfo);
|
|
41
28
|
file.authInfo.forEach(item => {
|
|
42
29
|
this.addAuth(...item)
|
|
@@ -45,8 +32,6 @@ export class Auth_File extends BohoAuth {
|
|
|
45
32
|
}).catch(e => {
|
|
46
33
|
console.log(e)
|
|
47
34
|
})
|
|
48
|
-
|
|
49
|
-
|
|
50
35
|
}
|
|
51
36
|
|
|
52
37
|
loadAuthInfoFile_JSON(path) {
|
|
@@ -57,15 +42,18 @@ export class Auth_File extends BohoAuth {
|
|
|
57
42
|
this.addAuth(...item)
|
|
58
43
|
})
|
|
59
44
|
console.log('total AUTH INFO size: ', this.AUTH.size)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getAuth(id) {
|
|
48
|
+
return this.AUTH.get(id)
|
|
49
|
+
}
|
|
60
50
|
|
|
51
|
+
async getAuthIdList() {
|
|
52
|
+
return Array.from(this.AUTH.keys())
|
|
61
53
|
}
|
|
62
54
|
|
|
63
55
|
addAuth(id, keyStr, cid, level = 0) {
|
|
64
56
|
let Base64hashKey = Buffer.from(Boho.sha256.hash(keyStr)).toString('base64')
|
|
65
57
|
this.AUTH.set(id, { key: Base64hashKey, cid: cid, level: level })
|
|
66
58
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
59
|
}
|
|
71
|
-
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { BohoAuth } from './BohoAuth.js';
|
|
2
1
|
import Boho from 'boho'
|
|
3
2
|
const DEVICE_PREFIX = "device:"
|
|
4
3
|
|
|
5
|
-
export class
|
|
4
|
+
export class RedisKeyProvider {
|
|
6
5
|
constructor(redisClient) {
|
|
7
|
-
super()
|
|
8
6
|
if (!redisClient) {
|
|
9
|
-
throw new Error("
|
|
7
|
+
throw new Error("RedisKeyProvider constructor: no redisClient")
|
|
10
8
|
}
|
|
11
9
|
this.redis = redisClient
|
|
12
10
|
}
|
|
@@ -15,7 +13,8 @@ export class Auth_Redis extends BohoAuth {
|
|
|
15
13
|
async getAuth(id) {
|
|
16
14
|
try {
|
|
17
15
|
let result = await this.redis.hGetAll(DEVICE_PREFIX + id)
|
|
18
|
-
if (result.key) return result
|
|
16
|
+
if (result && result.key) return result
|
|
17
|
+
else return null;
|
|
19
18
|
} catch (error) {
|
|
20
19
|
console.log('getAuth', error)
|
|
21
20
|
}
|
|
@@ -44,6 +43,4 @@ export class Auth_Redis extends BohoAuth {
|
|
|
44
43
|
async save(id) {
|
|
45
44
|
return this.redis.save()
|
|
46
45
|
}
|
|
47
|
-
|
|
48
46
|
}
|
|
49
|
-
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StringKeyProvider.js
|
|
3
|
+
*
|
|
4
|
+
* authInfo <String>
|
|
5
|
+
* id: max 8chars
|
|
6
|
+
* key: ~44 base64 chars recomended
|
|
7
|
+
* cid:
|
|
8
|
+
* level: range: 0~255
|
|
9
|
+
* separator: ',' for multiple devices.
|
|
10
|
+
*
|
|
11
|
+
* example => authInfo = 'id1.key1.cid1.255,id2.key2.cid2.200'
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import Boho from 'boho'
|
|
15
|
+
|
|
16
|
+
export class StringKeyProvider {
|
|
17
|
+
constructor(authInfo) {
|
|
18
|
+
|
|
19
|
+
if (!authInfo) {
|
|
20
|
+
throw TypeError("StringKeyProvider constructor() missing authInfo.")
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let id_keys = authInfo.split(',')
|
|
24
|
+
|
|
25
|
+
this.AUTH = new Map();
|
|
26
|
+
|
|
27
|
+
if (id_keys.length >= 1) {
|
|
28
|
+
id_keys.forEach(v => {
|
|
29
|
+
let [ did, key, cid, level ] = v.split('.')
|
|
30
|
+
level = parseInt(level)
|
|
31
|
+
if (did && key && cid && typeof level == 'number') {
|
|
32
|
+
this.addAuth(did, key, cid, level)
|
|
33
|
+
} else {
|
|
34
|
+
throw TypeError("StringKeyProvider invalid authInfo.")
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
} else {
|
|
38
|
+
throw TypeError("StringKeyProvider invalid authInfo.")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async getAuth(id) {
|
|
44
|
+
return this.AUTH.get(id)
|
|
45
|
+
}
|
|
46
|
+
async getAuthIdList() {
|
|
47
|
+
return Array.from(this.AUTH.keys())
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
addAuth(id, keyStr, cid, level = 0) {
|
|
51
|
+
let Base64hashKey = Buffer.from(Boho.sha256.hash(keyStr)).toString('base64')
|
|
52
|
+
this.AUTH.set(id, { key: Base64hashKey, cid: cid, level: level })
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IOCore } from "./IOCore.js"
|
|
2
|
-
import {
|
|
2
|
+
import { STATE } from "../common/constants.js";
|
|
3
3
|
import { pack, CongRx } from './CongPacket.js'
|
|
4
4
|
import net from 'net'
|
|
5
5
|
|
|
@@ -33,8 +33,10 @@ export class IOCongSocket extends IOCore {
|
|
|
33
33
|
keepAlive() {
|
|
34
34
|
if (!this.autoReconnect) return;
|
|
35
35
|
// Reconnect only if the socket is fully destroyed and the state is closed.
|
|
36
|
-
if ((!this.socket || this.socket.destroyed)
|
|
36
|
+
if ((!this.socket || this.socket.destroyed)) {
|
|
37
37
|
this.open();
|
|
38
|
+
}else{
|
|
39
|
+
this.ping();
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
|
|
@@ -46,7 +48,7 @@ export class IOCongSocket extends IOCore {
|
|
|
46
48
|
urlObj = new URL('cong://' + url)
|
|
47
49
|
}
|
|
48
50
|
this.socket = net.createConnection(urlObj.port, urlObj.hostname)
|
|
49
|
-
this.stateChange('
|
|
51
|
+
this.stateChange('connecting','connecting')
|
|
50
52
|
|
|
51
53
|
this.socket.on('connect', () => {
|
|
52
54
|
this.congRx = new CongRx();
|