iosignal 1.7.0 → 1.7.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.
Files changed (49) hide show
  1. package/README.md +254 -247
  2. package/auth_file.json +13 -13
  3. package/auth_file.mjs +23 -23
  4. package/dist/iosignal.esm.js.map +1 -1
  5. package/dist/iosignal.min.js.map +1 -1
  6. package/index.js +19 -19
  7. package/indexWebBrowser.js +13 -13
  8. package/package.json +60 -59
  9. package/rollup.config.js +69 -69
  10. package/src/api/RedisAPI.js +65 -65
  11. package/src/api/api_constant.js +7 -7
  12. package/src/api/api_reply.js +31 -31
  13. package/src/api/api_sudo.js +91 -91
  14. package/src/auth/Auth_Env.js +76 -76
  15. package/src/auth/Auth_File.js +71 -71
  16. package/src/auth/Auth_Redis.js +44 -44
  17. package/src/auth/BohoAuth.js +164 -164
  18. package/src/client/CongPacket.js +141 -141
  19. package/src/client/IOCongSocket.js +81 -81
  20. package/src/client/IOCore.js +822 -822
  21. package/src/client/IOWS.js +80 -80
  22. package/src/client/IOWebSocket.js +111 -111
  23. package/src/common/constants.js +148 -148
  24. package/src/common/payload.js +81 -81
  25. package/src/common/quotaTable.js +68 -68
  26. package/src/common/util.js +61 -61
  27. package/src/server/FileLogger.js +30 -30
  28. package/src/server/Manager.js +433 -433
  29. package/src/server/Metric.js +155 -155
  30. package/src/server/Remote.js +207 -207
  31. package/src/server/RemoteCore.js +439 -439
  32. package/src/server/Server.js +163 -163
  33. package/src/server/serverOption.js +56 -56
  34. package/test-browser/favicon.ico +0 -0
  35. package/test-browser/index.html +96 -96
  36. package/test-browser/server.js +11 -11
  37. package/test-client-nodejs/client.cjs +17 -17
  38. package/test-client-nodejs/client.mjs +17 -17
  39. package/test-client-nodejs/client_api_reply.mjs +15 -15
  40. package/test-client-nodejs/stateChange.mjs +19 -19
  41. package/test-server/server-Auth_Env.js +19 -19
  42. package/test-server/server-Auth_File.js +12 -12
  43. package/test-server/server-api_reply.js +6 -6
  44. package/test-server/server-api_sudo.js +7 -7
  45. package/test-server/server-commonjs.cjs +8 -8
  46. package/test-server/server-esm.mjs +20 -20
  47. package/test-server/simple-server.mjs +11 -11
  48. package/test-signal-payloadType/signalPack.js +34 -34
  49. package/test-signal-payloadType/signaling.js +60 -60
@@ -1,82 +1,82 @@
1
- import { MBP } from 'meta-buffer-pack'
2
- import { PAYLOAD_TYPE, IOMsg } from "./constants.js";
3
- const encoder = new TextEncoder()
4
-
5
-
6
- export function getSignalPack(tag, ...args) {
7
- if (typeof tag !== 'string') throw TypeError('tag should be string.')
8
- let tagEncoded = encoder.encode(tag)
9
- let payload = parsePayload(args)
10
-
11
- let sigPack;
12
- if (payload.type == PAYLOAD_TYPE.EMPTY) {
13
- sigPack = MBP.pack(
14
- MBP.MB('#MsgType', '8', IOMsg.SIGNAL),
15
- MBP.MB('#tagLen', '8', tagEncoded.byteLength),
16
- MBP.MB('#tag', tagEncoded),
17
- MBP.MB('#payloadType', '8', payload.type)
18
- )
19
- } else if (payload.type == PAYLOAD_TYPE.MBA) {
20
- let mbaBuffer = MBP.pack(MBP.MBA(...args))
21
- sigPack = MBP.pack(
22
- MBP.MB('#MsgType', '8', IOMsg.SIGNAL),
23
- MBP.MB('#tagLen', '8', tagEncoded.byteLength),
24
- MBP.MB('#tag', tagEncoded),
25
- MBP.MB('#payloadType', '8', payload.type),
26
- MBP.MB('#mbaBuffer', mbaBuffer)
27
- )
28
- } else {
29
- sigPack = MBP.pack(
30
- MBP.MB('#MsgType', '8', IOMsg.SIGNAL),
31
- MBP.MB('#tagLen', '8', tagEncoded.byteLength),
32
- MBP.MB('#tag', tagEncoded),
33
- MBP.MB('#payloadType', '8', payload.type),
34
- MBP.MB('#payload', payload.buffer)
35
- )
36
- }
37
- return sigPack
38
- }
39
-
40
-
41
- export function parsePayload(args) {
42
- let type, pack;
43
- if (args.length == 0) {
44
- type = PAYLOAD_TYPE.EMPTY
45
- pack = null
46
- } else if (args.length == 1) {
47
- if (typeof args[0] === 'string' || typeof args[0] === 'number') {
48
- type = PAYLOAD_TYPE.TEXT
49
- pack = encoder.encode(args[0] + ".") // add null byte area.
50
- pack[pack.byteLength - 1] = 0 // set byte-zero : '\0' in C/C++
51
-
52
- } else if (ArrayBuffer.isView(args[0]) || args[0] instanceof ArrayBuffer) {
53
- type = PAYLOAD_TYPE.BINARY
54
- pack = MBP.B8(args[0])
55
- } else if (typeof args[0] === 'object') {
56
- type = PAYLOAD_TYPE.OBJECT
57
- pack = encoder.encode(JSON.stringify(args[0]))
58
- } else {
59
- throw new Error('unknown payload arguments')
60
- }
61
- } else { // two or more arguments.
62
- let containsBuffer = false
63
- args.forEach(item => {
64
- if (ArrayBuffer.isView(item) || item instanceof ArrayBuffer) containsBuffer = true;
65
- })
66
-
67
- if (containsBuffer) {
68
- type = PAYLOAD_TYPE.MBA;
69
- } else {
70
- type = PAYLOAD_TYPE.MJSON;
71
- pack = encoder.encode(JSON.stringify(args))
72
- }
73
-
74
- }
75
-
76
- return { type: type, buffer: pack }
77
- }
78
-
79
- export function getPayloadFromSignalPack(signalPack) {
80
- let tagLen = signalPack.readUint8(1)
81
- return signalPack.subarray(3 + tagLen)
1
+ import { MBP } from 'meta-buffer-pack'
2
+ import { PAYLOAD_TYPE, IOMsg } from "./constants.js";
3
+ const encoder = new TextEncoder()
4
+
5
+
6
+ export function getSignalPack(tag, ...args) {
7
+ if (typeof tag !== 'string') throw TypeError('tag should be string.')
8
+ let tagEncoded = encoder.encode(tag)
9
+ let payload = parsePayload(args)
10
+
11
+ let sigPack;
12
+ if (payload.type == PAYLOAD_TYPE.EMPTY) {
13
+ sigPack = MBP.pack(
14
+ MBP.MB('#MsgType', '8', IOMsg.SIGNAL),
15
+ MBP.MB('#tagLen', '8', tagEncoded.byteLength),
16
+ MBP.MB('#tag', tagEncoded),
17
+ MBP.MB('#payloadType', '8', payload.type)
18
+ )
19
+ } else if (payload.type == PAYLOAD_TYPE.MBA) {
20
+ let mbaBuffer = MBP.pack(MBP.MBA(...args))
21
+ sigPack = MBP.pack(
22
+ MBP.MB('#MsgType', '8', IOMsg.SIGNAL),
23
+ MBP.MB('#tagLen', '8', tagEncoded.byteLength),
24
+ MBP.MB('#tag', tagEncoded),
25
+ MBP.MB('#payloadType', '8', payload.type),
26
+ MBP.MB('#mbaBuffer', mbaBuffer)
27
+ )
28
+ } else {
29
+ sigPack = MBP.pack(
30
+ MBP.MB('#MsgType', '8', IOMsg.SIGNAL),
31
+ MBP.MB('#tagLen', '8', tagEncoded.byteLength),
32
+ MBP.MB('#tag', tagEncoded),
33
+ MBP.MB('#payloadType', '8', payload.type),
34
+ MBP.MB('#payload', payload.buffer)
35
+ )
36
+ }
37
+ return sigPack
38
+ }
39
+
40
+
41
+ export function parsePayload(args) {
42
+ let type, pack;
43
+ if (args.length == 0) {
44
+ type = PAYLOAD_TYPE.EMPTY
45
+ pack = null
46
+ } else if (args.length == 1) {
47
+ if (typeof args[0] === 'string' || typeof args[0] === 'number') {
48
+ type = PAYLOAD_TYPE.TEXT
49
+ pack = encoder.encode(args[0] + ".") // add null byte area.
50
+ pack[pack.byteLength - 1] = 0 // set byte-zero : '\0' in C/C++
51
+
52
+ } else if (ArrayBuffer.isView(args[0]) || args[0] instanceof ArrayBuffer) {
53
+ type = PAYLOAD_TYPE.BINARY
54
+ pack = MBP.B8(args[0])
55
+ } else if (typeof args[0] === 'object') {
56
+ type = PAYLOAD_TYPE.OBJECT
57
+ pack = encoder.encode(JSON.stringify(args[0]))
58
+ } else {
59
+ throw new Error('unknown payload arguments')
60
+ }
61
+ } else { // two or more arguments.
62
+ let containsBuffer = false
63
+ args.forEach(item => {
64
+ if (ArrayBuffer.isView(item) || item instanceof ArrayBuffer) containsBuffer = true;
65
+ })
66
+
67
+ if (containsBuffer) {
68
+ type = PAYLOAD_TYPE.MBA;
69
+ } else {
70
+ type = PAYLOAD_TYPE.MJSON;
71
+ pack = encoder.encode(JSON.stringify(args))
72
+ }
73
+
74
+ }
75
+
76
+ return { type: type, buffer: pack }
77
+ }
78
+
79
+ export function getPayloadFromSignalPack(signalPack) {
80
+ let tagLen = signalPack.readUint8(1)
81
+ return signalPack.subarray(3 + tagLen)
82
82
  }
@@ -1,68 +1,68 @@
1
- // table index related with:
2
- // - AUTH database level
3
- // - serverOption.defaultQuotaIndex
4
-
5
- // quota example
6
- // index range: 0~255.
7
- export let quotaTable = {
8
- // CongSocket
9
- 0: { // default. anonymouse:
10
- signalSize: 1500,
11
- publishCounter: 10,
12
- trafficRate: 10000
13
- },
14
- 1: { // auth_ultralight: eg. Arduino Uno.
15
- signalSize: 255,
16
- publishCounter: 10,
17
- trafficRate: 100000
18
- },
19
- 2: { // auth_light: eg. authorized ESP.
20
- signalSize: 65535,
21
- publishCounter: 10,
22
- trafficRate: 1048576
23
- },
24
-
25
- // WebSocket (browser and node app)
26
- 3: { // authorized basic.
27
- signalSize: 1048576,
28
- publishCounter: 10,
29
- trafficRate: 1048576 * 20
30
- },
31
-
32
- // WebSocket (browser and node app)
33
- 10: { // anonymouse
34
- signalSize: 1500,
35
- publishCounter: 5,
36
- trafficRate: 1048576 * 20
37
- },
38
-
39
- 11: { // authorized basic.
40
- signalSize: 65535,
41
- publishCounter: 10,
42
- trafficRate: 1048576 * 20
43
- },
44
-
45
- 12: { // authorized power.
46
- signalSize: 1048576,
47
- publishCounter: 100,
48
- trafficRate: 1048576 * 20
49
- },
50
-
51
- // you can add your custom quota levels.
52
-
53
- // Remote service node
54
- // High Quota, No root permission.
55
- 200: {
56
- signalSize: 1048576 * 20,
57
- publishCounter: 10000,
58
- trafficRate: 1048576 * 100
59
- },
60
- // super admin or root user.
61
- // to monitor, metric, sudo command, db access.
62
- 255: {
63
- signalSize: 1048576 * 20,
64
- publishCounter: 10000,
65
- trafficRate: 1048576 * 100
66
- }
67
- }
68
-
1
+ // table index related with:
2
+ // - AUTH database level
3
+ // - serverOption.defaultQuotaIndex
4
+
5
+ // quota example
6
+ // index range: 0~255.
7
+ export let quotaTable = {
8
+ // CongSocket
9
+ 0: { // default. anonymouse:
10
+ signalSize: 1500,
11
+ publishCounter: 10,
12
+ trafficRate: 10000
13
+ },
14
+ 1: { // auth_ultralight: eg. Arduino Uno.
15
+ signalSize: 255,
16
+ publishCounter: 10,
17
+ trafficRate: 100000
18
+ },
19
+ 2: { // auth_light: eg. authorized ESP.
20
+ signalSize: 65535,
21
+ publishCounter: 10,
22
+ trafficRate: 1048576
23
+ },
24
+
25
+ // WebSocket (browser and node app)
26
+ 3: { // authorized basic.
27
+ signalSize: 1048576,
28
+ publishCounter: 10,
29
+ trafficRate: 1048576 * 20
30
+ },
31
+
32
+ // WebSocket (browser and node app)
33
+ 10: { // anonymouse
34
+ signalSize: 1500,
35
+ publishCounter: 5,
36
+ trafficRate: 1048576 * 20
37
+ },
38
+
39
+ 11: { // authorized basic.
40
+ signalSize: 65535,
41
+ publishCounter: 10,
42
+ trafficRate: 1048576 * 20
43
+ },
44
+
45
+ 12: { // authorized power.
46
+ signalSize: 1048576,
47
+ publishCounter: 100,
48
+ trafficRate: 1048576 * 20
49
+ },
50
+
51
+ // you can add your custom quota levels.
52
+
53
+ // Remote service node
54
+ // High Quota, No root permission.
55
+ 200: {
56
+ signalSize: 1048576 * 20,
57
+ publishCounter: 10000,
58
+ trafficRate: 1048576 * 100
59
+ },
60
+ // super admin or root user.
61
+ // to monitor, metric, sudo command, db access.
62
+ 255: {
63
+ signalSize: 1048576 * 20,
64
+ publishCounter: 10000,
65
+ trafficRate: 1048576 * 100
66
+ }
67
+ }
68
+
@@ -1,61 +1,61 @@
1
- import { networkInterfaces } from 'os';
2
-
3
- export function isPrivateIP(ip) {
4
- if (ip.indexOf("0.0.0.0") === 0) return true
5
- if (ip.indexOf("127.0.0.1") === 0) return true
6
- if (ip.indexOf("192.168.") === 0) return true
7
- if (ip.indexOf("10.") === 0) return true
8
- if (ip.indexOf("172.") === 0) {
9
- if (ip.indexOf("172.16.") === 0) return true
10
- if (ip.indexOf("172.17.") === 0) return true
11
- if (ip.indexOf("172.18.") === 0) return true
12
- if (ip.indexOf("172.19.") === 0) return true
13
- if (ip.indexOf("172.20.") === 0) return true
14
- if (ip.indexOf("172.21.") === 0) return true
15
- if (ip.indexOf("172.22.") === 0) return true
16
- if (ip.indexOf("172.23.") === 0) return true
17
- if (ip.indexOf("172.24.") === 0) return true
18
- if (ip.indexOf("172.25.") === 0) return true
19
- if (ip.indexOf("172.26.") === 0) return true
20
- if (ip.indexOf("172.27.") === 0) return true
21
- if (ip.indexOf("172.28.") === 0) return true
22
- if (ip.indexOf("172.29.") === 0) return true
23
- if (ip.indexOf("172.30.") === 0) return true
24
- if (ip.indexOf("172.31.") === 0) return true
25
- }
26
-
27
- return false
28
- }
29
-
30
- export function numberWithCommas(x) {
31
- return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
32
- }
33
-
34
- export function getIPv4HexString(ipStr) {
35
- let ipv4 = ipStr.split('.')
36
- return Buffer.from(ipv4).toString('hex')
37
- }
38
-
39
- export function getLocalAddress() {
40
- const nets = networkInterfaces();
41
- // console.log(nets)
42
- const results = Object.create(null); // Or just '{}', an empty object
43
- let localAddress = ''
44
- for (const name of Object.keys(nets)) {
45
- for (const net of nets[name]) {
46
- // Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
47
- // 'IPv4' is in Node <= 17, from 18 it's a number 4 or 6
48
- const familyV4Value = typeof net.family === 'string' ? 'IPv4' : 4
49
- if (net.family === familyV4Value && !net.internal) {
50
- if (!results[name]) {
51
- results[name] = [];
52
- }
53
- results[name].push(net.address);
54
- localAddress = net.address
55
- }
56
- }
57
- }
58
-
59
- // console.log('localAddress:', localAddress)
60
- return localAddress
61
- }
1
+ import { networkInterfaces } from 'os';
2
+
3
+ export function isPrivateIP(ip) {
4
+ if (ip.indexOf("0.0.0.0") === 0) return true
5
+ if (ip.indexOf("127.0.0.1") === 0) return true
6
+ if (ip.indexOf("192.168.") === 0) return true
7
+ if (ip.indexOf("10.") === 0) return true
8
+ if (ip.indexOf("172.") === 0) {
9
+ if (ip.indexOf("172.16.") === 0) return true
10
+ if (ip.indexOf("172.17.") === 0) return true
11
+ if (ip.indexOf("172.18.") === 0) return true
12
+ if (ip.indexOf("172.19.") === 0) return true
13
+ if (ip.indexOf("172.20.") === 0) return true
14
+ if (ip.indexOf("172.21.") === 0) return true
15
+ if (ip.indexOf("172.22.") === 0) return true
16
+ if (ip.indexOf("172.23.") === 0) return true
17
+ if (ip.indexOf("172.24.") === 0) return true
18
+ if (ip.indexOf("172.25.") === 0) return true
19
+ if (ip.indexOf("172.26.") === 0) return true
20
+ if (ip.indexOf("172.27.") === 0) return true
21
+ if (ip.indexOf("172.28.") === 0) return true
22
+ if (ip.indexOf("172.29.") === 0) return true
23
+ if (ip.indexOf("172.30.") === 0) return true
24
+ if (ip.indexOf("172.31.") === 0) return true
25
+ }
26
+
27
+ return false
28
+ }
29
+
30
+ export function numberWithCommas(x) {
31
+ return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
32
+ }
33
+
34
+ export function getIPv4HexString(ipStr) {
35
+ let ipv4 = ipStr.split('.')
36
+ return Buffer.from(ipv4).toString('hex')
37
+ }
38
+
39
+ export function getLocalAddress() {
40
+ const nets = networkInterfaces();
41
+ // console.log(nets)
42
+ const results = Object.create(null); // Or just '{}', an empty object
43
+ let localAddress = ''
44
+ for (const name of Object.keys(nets)) {
45
+ for (const net of nets[name]) {
46
+ // Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
47
+ // 'IPv4' is in Node <= 17, from 18 it's a number 4 or 6
48
+ const familyV4Value = typeof net.family === 'string' ? 'IPv4' : 4
49
+ if (net.family === familyV4Value && !net.internal) {
50
+ if (!results[name]) {
51
+ results[name] = [];
52
+ }
53
+ results[name].push(net.address);
54
+ localAddress = net.address
55
+ }
56
+ }
57
+ }
58
+
59
+ // console.log('localAddress:', localAddress)
60
+ return localAddress
61
+ }
@@ -1,30 +1,30 @@
1
- import fs from 'fs'
2
-
3
- const formatter = new Intl.DateTimeFormat('ko-KR', {
4
- // hour12: true,
5
- // hour: 'numeric',
6
- // minute: '2-digit',
7
- // second: '2-digit'
8
- year: 'numeric', month: 'numeric', day: 'numeric',
9
- hour: 'numeric', minute: 'numeric',
10
- hour12: false,
11
- timeZone: 'Asia/Seoul'
12
- });
13
-
14
-
15
- export class FileLogger {
16
- constructor(path) {
17
- this.file = fs.openSync(path, 'a+')
18
- console.log('new FileLogger logFile: ', path, this.file)
19
- }
20
-
21
- log(msg) {
22
- let format = formatter.format(new Date()) + " " + msg + '\n';
23
- fs.write(this.file, format, (err) => {
24
- if (err) throw err;
25
- })
26
-
27
- }
28
-
29
-
30
- }
1
+ import fs from 'fs'
2
+
3
+ const formatter = new Intl.DateTimeFormat('ko-KR', {
4
+ // hour12: true,
5
+ // hour: 'numeric',
6
+ // minute: '2-digit',
7
+ // second: '2-digit'
8
+ year: 'numeric', month: 'numeric', day: 'numeric',
9
+ hour: 'numeric', minute: 'numeric',
10
+ hour12: false,
11
+ timeZone: 'Asia/Seoul'
12
+ });
13
+
14
+
15
+ export class FileLogger {
16
+ constructor(path) {
17
+ this.file = fs.openSync(path, 'a+')
18
+ console.log('new FileLogger logFile: ', path, this.file)
19
+ }
20
+
21
+ log(msg) {
22
+ let format = formatter.format(new Date()) + " " + msg + '\n';
23
+ fs.write(this.file, format, (err) => {
24
+ if (err) throw err;
25
+ })
26
+
27
+ }
28
+
29
+
30
+ }