iosignal 1.4.2 → 1.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.
Files changed (50) hide show
  1. package/README.md +247 -240
  2. package/auth_file.json +13 -13
  3. package/auth_file.mjs +23 -23
  4. package/dist/iosignal.cjs +1 -1
  5. package/dist/iosignal.esm.js.map +1 -1
  6. package/dist/iosignal.min.js.map +1 -1
  7. package/index.js +19 -19
  8. package/indexWebBrowser.js +13 -13
  9. package/package.json +59 -60
  10. package/rollup.config.js +69 -69
  11. package/src/api/RedisAPI.js +68 -68
  12. package/src/api/api_constant.js +7 -7
  13. package/src/api/api_reply.js +34 -34
  14. package/src/api/api_sudo.js +96 -96
  15. package/src/auth/Auth_Env.js +78 -78
  16. package/src/auth/Auth_File.js +75 -75
  17. package/src/auth/Auth_Redis.js +50 -50
  18. package/src/auth/BohoAuth.js +168 -168
  19. package/src/client/CongPacket.js +150 -150
  20. package/src/client/IOCongSocket.js +88 -88
  21. package/src/client/IOCore.js +851 -851
  22. package/src/client/IOWS.js +81 -81
  23. package/src/client/IOWebSocket.js +95 -95
  24. package/src/common/constants.js +159 -159
  25. package/src/common/payload.js +82 -82
  26. package/src/common/quotaTable.js +68 -68
  27. package/src/common/util.js +61 -61
  28. package/src/server/FileLogger.js +30 -30
  29. package/src/server/Manager.js +449 -449
  30. package/src/server/Metric.js +154 -154
  31. package/src/server/Server.js +166 -148
  32. package/src/server/ServerRemote.js +227 -227
  33. package/src/server/ServerRemoteCore.js +467 -467
  34. package/src/server/serverOption.js +56 -55
  35. package/test-browser/favicon.ico +0 -0
  36. package/test-browser/index.html +92 -92
  37. package/test-browser/server.js +11 -11
  38. package/test-client-nodejs/client.cjs +17 -17
  39. package/test-client-nodejs/client.mjs +17 -17
  40. package/test-client-nodejs/client_api_reply.mjs +15 -15
  41. package/test-client-nodejs/stateChange.mjs +19 -19
  42. package/test-server/server-Auth_Env.js +19 -19
  43. package/test-server/server-Auth_File.js +12 -12
  44. package/test-server/server-api_reply.js +6 -6
  45. package/test-server/server-api_sudo.js +7 -7
  46. package/test-server/server-commonjs.cjs +8 -8
  47. package/test-server/server-esm.mjs +19 -19
  48. package/test-server/simple-server.mjs +11 -11
  49. package/test-signal-payloadType/signalPack.js +34 -34
  50. package/test-signal-payloadType/signaling.js +60 -60
@@ -1,154 +1,154 @@
1
- import { memoryUsage } from 'process';
2
- import { ENC_MODE } from '../common/constants.js'
3
-
4
- const MAX = 10
5
- let period = 10000
6
-
7
- export class Metric{
8
- constructor(manager){
9
- this.manager = manager;
10
-
11
- this.metricsPack= {
12
- remotes:[0],
13
- channels:[0],
14
- txBytes:[0],
15
- rxBytes:[0],
16
- unixTime: [Math.floor( Date.now() /1000)],
17
- period: 0
18
- }
19
-
20
- this.tickId = setInterval( e=>{
21
-
22
- this.metricsPack.remotes.push( this.manager.remotes.size )
23
- if(this.metricsPack.remotes.length > MAX ) this.metricsPack.remotes.shift()
24
-
25
- this.metricsPack.channels.push( this.manager.channel_map.size )
26
- if(this.metricsPack.channels.length > MAX ) this.metricsPack.channels.shift()
27
-
28
-
29
- this.metricsPack.txBytes.push( this.manager.txBytes )
30
- if(this.metricsPack.txBytes.length > MAX ) this.metricsPack.txBytes.shift()
31
-
32
- this.metricsPack.rxBytes.push( this.manager.rxBytes )
33
- if(this.metricsPack.rxBytes.length > MAX ) this.metricsPack.rxBytes.shift()
34
-
35
- this.metricsPack.unixTime = Math.floor( Date.now() /1000)
36
- this.metricsPack.period = period;
37
- this.manager.txBytes = 0
38
- this.manager.rxBytes = 0
39
-
40
-
41
- },10000)
42
- }
43
-
44
-
45
-
46
- oneline(prn){
47
- let memoryUse = memoryUsage();
48
- let memoryInfo = [{
49
- ...memoryUse
50
- }]
51
-
52
- if ( prn ) console.table(memoryInfo, [ 'rss','heapTotal','heapUsed', 'external','arrayBuffers' ]);
53
-
54
- let metric = [{
55
- lastSSID: this.manager.lastSSID,
56
- remotes: this.manager.remotes.size,
57
- channels: this.manager.channel_map.size,
58
- txBytes: this.manager.txBytes,
59
- rxBytes: this.manager.rxBytes,
60
- }]
61
-
62
- if ( prn ) console.table(metric, [ 'lastSSID', 'remotes', 'channels','txBytes','rxBytes' ]);
63
-
64
- return metric[0]
65
- }
66
-
67
- getRemotes( prn ){
68
- let remoteList = Array.from(this.manager.remotes.values())
69
- let remoteStates = remoteList.map(v=>{
70
- return "#"+v.ssid+":"+ v.cid +"("+v.state+")"
71
- })
72
- if (prn ) console.table(remoteStates)
73
- return remoteStates
74
- }
75
- getCIdList( prn ){
76
- let CIdList = Array.from(this.manager.cid2remote.keys())
77
- if (prn ) console.table(CIdList)
78
- return CIdList
79
- }
80
-
81
- getChannelList(prn){
82
- let chList = Array.from(this.manager.channel_map.keys())
83
- if (prn ) console.table(chList)
84
- return chList
85
- }
86
-
87
- getSubscribers(ch){
88
- let list = [];
89
- if( this.manager.channel_map.has(ch)){
90
- let subscribers = this.manager.channel_map.get(ch) //set
91
- subscribers.forEach( c =>{
92
- list.push(c.cid)
93
- })
94
- }
95
- // console.log(list)
96
- return list
97
- }
98
-
99
- getRemoteByCId( cid , mode = 1){
100
-
101
- if( this.manager.cid2remote.has(cid)){
102
- let remote = this.manager.cid2remote.get(cid)
103
- if(mode == 1){
104
- return {
105
- ip: remote.ip,
106
- id: remote.cid,
107
- ssid: remote.ssid,
108
- cid: remote.cid,
109
- uptime: Math.trunc( ( Date.now() - remote.socket.openTime ) / 1000),
110
- tx: remote.socket.txCounter,
111
- rx: remote.socket.rxCounter,
112
- txBytes: remote.socket.bytesWritten || remote.socket._socket?.bytesWritten,
113
- rxBytes: remote.socket.bytesRead || remote.socket._socket?.bytesRead
114
- }
115
- }else if( mode == 2){
116
- return {
117
- ip: remote.ip,
118
- uptime: Math.trunc( ( Date.now() - remote.socket.openTime ) / 1000),
119
- nick: remote.nick,
120
- ssid: remote.ssid,
121
- echo: remote.lastEchoMessage
122
- }
123
- }else if( mode == 3){
124
- return {
125
- ip: remote.ip,
126
- uptime: Math.trunc( ( Date.now() - remote.socket.openTime ) / 1000),
127
- nick: remote.nick,
128
- ssid: remote.ssid,
129
- isSecure: remote.TLS,
130
- isAuth: remote.boho.isAuthorized,
131
- encMode: ENC_MODE[remote.encMode]
132
- }
133
- }else if( mode == 4){
134
- let channels = Array.from( remote.channels.keys() )
135
- let set_memory = Array.from( remote.memory.keys() )
136
- let retain_signal = Array.from( remote.retain_signal.keys() )
137
- return {
138
- ip: remote.ip,
139
- uptime: Math.trunc( ( Date.now() - remote.socket.openTime ) / 1000),
140
- channels: channels,
141
- set: set_memory,
142
- retain: retain_signal
143
- }
144
- }
145
-
146
- }else{
147
- return { result: "nop" }
148
- }
149
-
150
- }
151
-
152
-
153
- }
154
-
1
+ import { memoryUsage } from 'process';
2
+ import { ENC_MODE } from '../common/constants.js'
3
+
4
+ const MAX = 10
5
+ let period = 10000
6
+
7
+ export class Metric{
8
+ constructor(manager){
9
+ this.manager = manager;
10
+
11
+ this.metricsPack= {
12
+ remotes:[0],
13
+ channels:[0],
14
+ txBytes:[0],
15
+ rxBytes:[0],
16
+ unixTime: [Math.floor( Date.now() /1000)],
17
+ period: 0
18
+ }
19
+
20
+ this.tickId = setInterval( e=>{
21
+
22
+ this.metricsPack.remotes.push( this.manager.remotes.size )
23
+ if(this.metricsPack.remotes.length > MAX ) this.metricsPack.remotes.shift()
24
+
25
+ this.metricsPack.channels.push( this.manager.channel_map.size )
26
+ if(this.metricsPack.channels.length > MAX ) this.metricsPack.channels.shift()
27
+
28
+
29
+ this.metricsPack.txBytes.push( this.manager.txBytes )
30
+ if(this.metricsPack.txBytes.length > MAX ) this.metricsPack.txBytes.shift()
31
+
32
+ this.metricsPack.rxBytes.push( this.manager.rxBytes )
33
+ if(this.metricsPack.rxBytes.length > MAX ) this.metricsPack.rxBytes.shift()
34
+
35
+ this.metricsPack.unixTime = Math.floor( Date.now() /1000)
36
+ this.metricsPack.period = period;
37
+ this.manager.txBytes = 0
38
+ this.manager.rxBytes = 0
39
+
40
+
41
+ },10000)
42
+ }
43
+
44
+
45
+
46
+ oneline(prn){
47
+ let memoryUse = memoryUsage();
48
+ let memoryInfo = [{
49
+ ...memoryUse
50
+ }]
51
+
52
+ if ( prn ) console.table(memoryInfo, [ 'rss','heapTotal','heapUsed', 'external','arrayBuffers' ]);
53
+
54
+ let metric = [{
55
+ lastSSID: this.manager.lastSSID,
56
+ remotes: this.manager.remotes.size,
57
+ channels: this.manager.channel_map.size,
58
+ txBytes: this.manager.txBytes,
59
+ rxBytes: this.manager.rxBytes,
60
+ }]
61
+
62
+ if ( prn ) console.table(metric, [ 'lastSSID', 'remotes', 'channels','txBytes','rxBytes' ]);
63
+
64
+ return metric[0]
65
+ }
66
+
67
+ getRemotes( prn ){
68
+ let remoteList = Array.from(this.manager.remotes.values())
69
+ let remoteStates = remoteList.map(v=>{
70
+ return "#"+v.ssid+":"+ v.cid +"("+v.state+")"
71
+ })
72
+ if (prn ) console.table(remoteStates)
73
+ return remoteStates
74
+ }
75
+ getCIdList( prn ){
76
+ let CIdList = Array.from(this.manager.cid2remote.keys())
77
+ if (prn ) console.table(CIdList)
78
+ return CIdList
79
+ }
80
+
81
+ getChannelList(prn){
82
+ let chList = Array.from(this.manager.channel_map.keys())
83
+ if (prn ) console.table(chList)
84
+ return chList
85
+ }
86
+
87
+ getSubscribers(ch){
88
+ let list = [];
89
+ if( this.manager.channel_map.has(ch)){
90
+ let subscribers = this.manager.channel_map.get(ch) //set
91
+ subscribers.forEach( c =>{
92
+ list.push(c.cid)
93
+ })
94
+ }
95
+ // console.log(list)
96
+ return list
97
+ }
98
+
99
+ getRemoteByCId( cid , mode = 1){
100
+
101
+ if( this.manager.cid2remote.has(cid)){
102
+ let remote = this.manager.cid2remote.get(cid)
103
+ if(mode == 1){
104
+ return {
105
+ ip: remote.ip,
106
+ id: remote.cid,
107
+ ssid: remote.ssid,
108
+ cid: remote.cid,
109
+ uptime: Math.trunc( ( Date.now() - remote.socket.openTime ) / 1000),
110
+ tx: remote.socket.txCounter,
111
+ rx: remote.socket.rxCounter,
112
+ txBytes: remote.socket.bytesWritten || remote.socket._socket?.bytesWritten,
113
+ rxBytes: remote.socket.bytesRead || remote.socket._socket?.bytesRead
114
+ }
115
+ }else if( mode == 2){
116
+ return {
117
+ ip: remote.ip,
118
+ uptime: Math.trunc( ( Date.now() - remote.socket.openTime ) / 1000),
119
+ nick: remote.nick,
120
+ ssid: remote.ssid,
121
+ echo: remote.lastEchoMessage
122
+ }
123
+ }else if( mode == 3){
124
+ return {
125
+ ip: remote.ip,
126
+ uptime: Math.trunc( ( Date.now() - remote.socket.openTime ) / 1000),
127
+ nick: remote.nick,
128
+ ssid: remote.ssid,
129
+ isSecure: remote.TLS,
130
+ isAuth: remote.boho.isAuthorized,
131
+ encMode: ENC_MODE[remote.encMode]
132
+ }
133
+ }else if( mode == 4){
134
+ let channels = Array.from( remote.channels.keys() )
135
+ let set_memory = Array.from( remote.memory.keys() )
136
+ let retain_signal = Array.from( remote.retain_signal.keys() )
137
+ return {
138
+ ip: remote.ip,
139
+ uptime: Math.trunc( ( Date.now() - remote.socket.openTime ) / 1000),
140
+ channels: channels,
141
+ set: set_memory,
142
+ retain: retain_signal
143
+ }
144
+ }
145
+
146
+ }else{
147
+ return { result: "nop" }
148
+ }
149
+
150
+ }
151
+
152
+
153
+ }
154
+
@@ -1,148 +1,166 @@
1
- import net from 'net'
2
- import EventEmitter from 'events'
3
- import { WebSocketServer } from 'ws'
4
- import { Manager } from './Manager.js'
5
- import { serverOption } from './serverOption.js'
6
- import { STATUS } from '../api/api_constant.js'
7
-
8
- export class Server extends EventEmitter {
9
-
10
- constructor(options, authManager ) {
11
- super();
12
- this.apiNames = new Set()
13
-
14
- if (options.timeout) {
15
- let pingT = parseInt(options.timeout)
16
- if (pingT && pingT >= 1000) serverOption.timeout = pingT
17
- }
18
-
19
- if (options.monitorPeriod) {
20
- let monitorT = parseInt(options.monitorPeriod)
21
- if (monitorT && monitorT >= 1000) serverOption.monitorPeriod = monitorT
22
- }
23
-
24
-
25
- if (options.showMessage) {
26
- serverOption.showMessage = options.showMessage
27
- }
28
-
29
- if (options.showMetric) {
30
- serverOption.showMetric = options.showMetric
31
- }
32
-
33
- if (options.timeout) {
34
- serverOption.timeout = options.timeout
35
- }
36
-
37
- if (options.port) {
38
- serverOption.port = parseInt(options.port)
39
- }
40
-
41
- if (options.congPort) {
42
- serverOption.congPort = parseInt(options.congPort)
43
- }
44
-
45
- this.manager = new Manager(this, authManager)
46
- if (serverOption.port) this.startWSServer(serverOption.port)
47
- if( serverOption.congPort) this.startCongServer(serverOption.congPort)
48
-
49
- // console.log('serverOption:', serverOption)
50
- }
51
-
52
-
53
- startWSServer(port) {
54
-
55
- console.log('opening WebSocket Server:', port)
56
- this.wss = new WebSocketServer({ port })
57
- // this.wss.setMaxListeners(0)
58
-
59
- this.wss.on('error', (err) => {
60
- console.error('### ws server error:', err.message)
61
- if(err.code == 'EADDRINUSE'){
62
- process.exit()
63
- }
64
- })
65
-
66
- this.wss.on('close', (err) => {
67
- console.log('### WS server closed.', err)
68
- })
69
-
70
- this.wss.on('connection', (ws, req) => {
71
- ws.socketType = 'websocket'
72
- this.manager.addRemote(ws, req)
73
- })
74
-
75
-
76
- }
77
-
78
- startCongServer( congPort ) {
79
- console.log('opening CongSocket Server:', congPort)
80
-
81
- this.congServer = net.createServer((socket) => {
82
- this.manager.addRemote(socket)
83
- })
84
- .on('error', (err) => {
85
- console.log('### cong server error:', err.message)
86
- if(err.code == 'EADDRINUSE'){
87
- process.exit()
88
- }
89
- }).listen( congPort, () => {
90
- // console.log('congsocket server bound' );
91
- });
92
- }
93
-
94
-
95
-
96
- api(target, api) {
97
-
98
- this.apiNames.add(target)
99
-
100
- // common checkPermission
101
- if (!api.checkPermission || typeof api.checkPermission != 'function') {
102
- throw new Error('wrong api interface. no checkPermission function.')
103
- }
104
-
105
-
106
- if(typeof api.request == 'function' && Array.isArray( api.commands )){
107
- console.log(`API TYPE1. A Class with one request function. target: ${target} list: ${api.commands}` )
108
-
109
- this.on(target, (remote, req) => {
110
- if (api.checkPermission(remote, req)) {
111
- api.request(remote, req)
112
- } else {
113
- remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.")
114
- }
115
- })
116
-
117
- }else{
118
- let apiList = []
119
- Object.keys(api).forEach(v => {
120
- if (typeof api[v] === 'function') apiList.push(v)
121
- console.log('api list',typeof api[v] ,v )
122
- })
123
-
124
- console.log(`API TYPE2. Multiple function list. target: ${target} list:${apiList}`)
125
-
126
- this.on(target, (remote, req) => {
127
- let r;
128
- if (!api.checkPermission(remote, req)) {
129
- r = "NO_PERMISSION."
130
- } else {
131
- // if (apiList.includes(req.topic)) {
132
- if ( api[req.topic] ) {
133
- console.log(`API TYPE2. request target: ${target} has topic:${req.topic}`)
134
- api[req.topic](remote, req)
135
- return
136
- } else {
137
- r = `target: ${req.target} has not topic name: ${req.topic}`
138
- }
139
- }
140
-
141
- remote.response(req.mid, STATUS.ERROR, r)
142
- })
143
- }
144
-
145
- return this
146
- }
147
-
148
- }
1
+ import net from 'net'
2
+ import EventEmitter from 'events'
3
+ import { WebSocketServer } from 'ws'
4
+ import { Manager } from './Manager.js'
5
+ import { serverOption } from './serverOption.js'
6
+ import { STATUS } from '../api/api_constant.js'
7
+
8
+ export class Server extends EventEmitter {
9
+
10
+ constructor(options, authManager ) {
11
+ super();
12
+ this.apiNames = new Set()
13
+ this.wss = {};
14
+
15
+ if (options.timeout) {
16
+ let pingT = parseInt(options.timeout)
17
+ if (pingT && pingT >= 1000) serverOption.timeout = pingT
18
+ }
19
+
20
+ if (options.monitorPeriod) {
21
+ let monitorT = parseInt(options.monitorPeriod)
22
+ if (monitorT && monitorT >= 1000) serverOption.monitorPeriod = monitorT
23
+ }
24
+
25
+
26
+ if (options.showMessage) {
27
+ serverOption.showMessage = options.showMessage
28
+ }
29
+
30
+ if (options.showMetric) {
31
+ serverOption.showMetric = options.showMetric
32
+ }
33
+
34
+ if (options.timeout) {
35
+ serverOption.timeout = options.timeout
36
+ }
37
+
38
+ if (options.port) {
39
+ serverOption.port = parseInt(options.port)
40
+ }
41
+
42
+ if (options.httpServer) {
43
+ serverOption.httpServer = options.httpServer
44
+ }
45
+
46
+ if (options.congPort) {
47
+ serverOption.congPort = parseInt(options.congPort)
48
+ }
49
+
50
+ this.manager = new Manager(this, authManager)
51
+
52
+ if (serverOption.port || serverOption.httpServer ) this.startWSServer(serverOption)
53
+ if( serverOption.congPort) this.startCongServer(serverOption.congPort)
54
+
55
+ // console.log('serverOption:', serverOption)
56
+ }
57
+
58
+
59
+ startWSServer(serverOption) {
60
+
61
+ if(serverOption.port ){
62
+ console.log('opening WebSocket Server port:', serverOption.port)
63
+ this.wss = new WebSocketServer({ port: serverOption.port })
64
+ }else if( serverOption.httpServer ){
65
+ console.log('opening WebSocket Server external httpServer:' )
66
+ this.wss = new WebSocketServer({ server: serverOption.httpServer })
67
+ }else{
68
+ throw new TypeError(
69
+ 'One and only one of the "port", "httpServer"' +
70
+ 'must be specified'
71
+ );
72
+ }
73
+
74
+
75
+ // this.wss.setMaxListeners(0)
76
+
77
+ this.wss.on('error', (err) => {
78
+ console.error('### ws server error:', err.message)
79
+ if(err.code == 'EADDRINUSE'){
80
+ process.exit()
81
+ }
82
+ })
83
+
84
+ this.wss.on('close', (err) => {
85
+ console.log('### WS server closed.', err)
86
+ })
87
+
88
+ this.wss.on('connection', (ws, req) => {
89
+ ws.socketType = 'websocket'
90
+ this.manager.addRemote(ws, req)
91
+ })
92
+
93
+
94
+ }
95
+
96
+ startCongServer( congPort ) {
97
+ console.log('opening CongSocket Server:', congPort)
98
+
99
+ this.congServer = net.createServer((socket) => {
100
+ this.manager.addRemote(socket)
101
+ })
102
+ .on('error', (err) => {
103
+ console.log('### cong server error:', err.message)
104
+ if(err.code == 'EADDRINUSE'){
105
+ process.exit()
106
+ }
107
+ }).listen( congPort, () => {
108
+ // console.log('congsocket server bound' );
109
+ });
110
+ }
111
+
112
+
113
+
114
+ api(target, api) {
115
+
116
+ this.apiNames.add(target)
117
+
118
+ // common checkPermission
119
+ if (!api.checkPermission || typeof api.checkPermission != 'function') {
120
+ throw new Error('wrong api interface. no checkPermission function.')
121
+ }
122
+
123
+
124
+ if(typeof api.request == 'function' && Array.isArray( api.commands )){
125
+ console.log(`API TYPE1. A Class with one request function. target: ${target} list: ${api.commands}` )
126
+
127
+ this.on(target, (remote, req) => {
128
+ if (api.checkPermission(remote, req)) {
129
+ api.request(remote, req)
130
+ } else {
131
+ remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.")
132
+ }
133
+ })
134
+
135
+ }else{
136
+ let apiList = []
137
+ Object.keys(api).forEach(v => {
138
+ if (typeof api[v] === 'function') apiList.push(v)
139
+ console.log('api list',typeof api[v] ,v )
140
+ })
141
+
142
+ console.log(`API TYPE2. Multiple function list. target: ${target} list:${apiList}`)
143
+
144
+ this.on(target, (remote, req) => {
145
+ let r;
146
+ if (!api.checkPermission(remote, req)) {
147
+ r = "NO_PERMISSION."
148
+ } else {
149
+ // if (apiList.includes(req.topic)) {
150
+ if ( api[req.topic] ) {
151
+ console.log(`API TYPE2. request target: ${target} has topic:${req.topic}`)
152
+ api[req.topic](remote, req)
153
+ return
154
+ } else {
155
+ r = `target: ${req.target} has not topic name: ${req.topic}`
156
+ }
157
+ }
158
+
159
+ remote.response(req.mid, STATUS.ERROR, r)
160
+ })
161
+ }
162
+
163
+ return this
164
+ }
165
+
166
+ }