iosignal 4.0.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.
@@ -1,7 +1,7 @@
1
1
  import MBP from 'meta-buffer-pack'
2
2
  import Boho from 'boho'
3
3
  import { serverOption } from './serverOption.js';
4
- import { IOMsg, ENC_MODE, CLIENT_STATE } from '../common/constants.js'
4
+ import { IOMsg, ENC_MODE, STATE } from '../common/constants.js'
5
5
  import { quotaTable } from '../common/quotaTable.js'
6
6
 
7
7
  const decoder = new TextDecoder()
@@ -40,7 +40,7 @@ export class RemoteCore {
40
40
 
41
41
  this.state;
42
42
  this.stateLog = [];
43
- this.setState(CLIENT_STATE.INIT)
43
+ this.setState(STATE.OPEN)
44
44
 
45
45
  }
46
46
 
@@ -49,7 +49,7 @@ export class RemoteCore {
49
49
  setState(state) {
50
50
  this.state = state
51
51
  if (serverOption.debug.showAuthInfo) {
52
- // let s = state + ":" + CLIENT_STATE[ state]
52
+ state = state + ":" + STATE[ state]
53
53
  this.stateLog.push( state )
54
54
  console.log(this.stateLog.join('>'))
55
55
  }
@@ -60,24 +60,30 @@ export class RemoteCore {
60
60
  }
61
61
 
62
62
  getStateName() { // <String>
63
- return (CLIENT_STATE[this.state]).toLowerCase()
63
+ return (STATE[this.state]).toLowerCase()
64
64
  }
65
65
 
66
66
 
67
67
  showMessageLog(message, isBinary) {
68
- let from = this.boho.isAuthorized ? `[FROM]did: ${this.did} cid:${this.cid}` : `[FROM]cid:${this.cid}`
68
+ let h = '->S '
69
+ let from = this.boho.isAuthorized ? ` did: ${this.did} cid: ${this.cid}` : ` cid: ${this.cid}`
70
+ let prnLimit = 20
69
71
  if (isBinary) {
70
72
  let msgTypeName = IOMsg[message[0]]
71
73
  if (!msgTypeName) msgTypeName = Boho.BohoMsg[message[0]]
72
- msgTypeName = ' [' + msgTypeName + ']';
73
- if (message.byteLength > 40) {
74
- console.log(from + msgTypeName + ' LEN:', message.length);
74
+
75
+ msgTypeName = '[' + msgTypeName + ']';
76
+ let size = message.byteLength;
77
+ if (size < prnLimit) {
78
+ console.log( h + msgTypeName + from +` [${size}]`, message);
75
79
  } else {
76
- console.log(from + msgTypeName, message);
80
+ let elseLen = size - prnLimit
81
+ let some = message.subarray(0,prnLimit)
82
+ console.log( h + msgTypeName + from +` [${size}]` , some , ' ... else: ', elseLen);
77
83
  }
78
84
 
79
85
  } else {
80
- console.log(from + ' [TEXT] %s', message);
86
+ console.log( h + ' [TEXT] %s' + from, message);
81
87
  }
82
88
  }
83
89
 
@@ -162,7 +168,7 @@ export class RemoteCore {
162
168
  break;
163
169
 
164
170
  case IOMsg.CID_REQ:
165
- if (this.state < CLIENT_STATE.SENT_SERVER_READY) {
171
+ if (this.state < STATE.SERVER_READY) {
166
172
  // Protocol violation: CID_REQ was sent before receiving the SERVER_READY signal.
167
173
  console.log('CID_REQ before SERVER_READY')
168
174
  this.close()
@@ -179,7 +185,7 @@ export class RemoteCore {
179
185
  MB('#cid', this.cid)
180
186
  ))
181
187
 
182
- this.setState(CLIENT_STATE.CID_READY)
188
+ this.setState(STATE.CID_RES)
183
189
  break;
184
190
 
185
191
  case IOMsg.ECHO:
@@ -285,24 +291,24 @@ export class RemoteCore {
285
291
  // Auth
286
292
  case Boho.BohoMsg.AUTH_REQ:
287
293
  if (!this.manager.authManager) return
288
- if (this.state < CLIENT_STATE.SENT_SERVER_READY) {
294
+ if (this.state < STATE.SERVER_READY) {
289
295
  console.log('protocol error. auth_req before server_ready')
290
296
  this.close();
291
297
  }
292
- this.setState(CLIENT_STATE.RECV_AUTH_REQ)
298
+ this.setState(STATE.AUTH_REQ)
293
299
  let auth_nonce_pack = this.boho.auth_nonce()
294
300
  // console.log('## auth_nonce_pack', auth_nonce_pack )
295
301
  this.send(auth_nonce_pack)
296
- this.setState(CLIENT_STATE.SENT_SERVER_NONCE)
302
+ this.setState(STATE.AUTH_NONCE)
297
303
  break;
298
304
 
299
305
  case Boho.BohoMsg.AUTH_HMAC:
300
306
  if (!this.manager.authManager) return
301
- if (this.state < CLIENT_STATE.SENT_SERVER_NONCE) {
307
+ if (this.state < STATE.AUTH_NONCE) {
302
308
  console.log('protocol error. auth_hmac before server_nonce')
303
309
  this.close();
304
310
  }
305
- this.setState(CLIENT_STATE.RECV_AUTH_HMAC)
311
+ this.setState(STATE.AUTH_HMAC)
306
312
  //async
307
313
  this.manager.authManager.verify_auth_hmac(message, this)
308
314
  .then(authInfo => {
@@ -81,7 +81,7 @@ export class Server extends EventEmitter {
81
81
 
82
82
  this.wss.once('listening', () => {
83
83
  this.port = this.wss.address().port;
84
- console.log('wss server bound port:', this.port );
84
+ // console.log('wss server bound port:', this.port );
85
85
  this.listeningServerCount++;
86
86
  if (this.listeningServerCount === this.serverCountToListen) {
87
87
  this.emit('ready');
@@ -97,7 +97,7 @@ export class Server extends EventEmitter {
97
97
  })
98
98
 
99
99
  this.wss.on('close', () => {
100
- console.log('### WS server is closed.')
100
+ // console.log('### WS server is closed.')
101
101
  })
102
102
 
103
103
  this.wss.on('connection', (ws, req) => {
@@ -118,10 +118,10 @@ export class Server extends EventEmitter {
118
118
  process.exit()
119
119
  }
120
120
  }).on('close', () => {
121
- console.log('### congsocket server is closed.')
121
+ // console.log('### congsocket server is closed.')
122
122
  }).listen(this.congPort, () => {
123
123
  this.congPort = this.congServer.address().port;
124
- console.log('congsocket server bound port:', this.congPort );
124
+ // console.log('congsocket server bound port:', this.congPort );
125
125
  this.listeningServerCount++;
126
126
  if (this.listeningServerCount === this.serverCountToListen) {
127
127
  this.emit('ready');
@@ -156,7 +156,7 @@ export class Server extends EventEmitter {
156
156
  return
157
157
  }
158
158
  if( api.commands.includes( req.topic )){
159
- console.log('server api req', req )
159
+ // console.log('server api req', req )
160
160
  await api.request(remote, req)
161
161
  }else{
162
162
  remote.response(req.mid, STATUS.ERROR, "UNKNOWN_COMMAND");
@@ -186,7 +186,7 @@ export class Server extends EventEmitter {
186
186
  })
187
187
  }
188
188
  this.apiNames.add(target)
189
- console.log(`[API registed: ${target} ] accept commands: ${api.commands}`)
189
+ // console.log(`[API registed: ${target} ] accept commands: ${api.commands}`)
190
190
  return this
191
191
  }
192
192
 
@@ -226,7 +226,7 @@ export class Server extends EventEmitter {
226
226
 
227
227
  if (this.congServer) {
228
228
  this.congServer.close((err) => {
229
- if (err) console.error('congServer close error', err)
229
+ // if (err) console.error('congServer close error', err)
230
230
  // console.log('cong server closed.')
231
231
  onClosed()
232
232
  })
package/README.en.md DELETED
@@ -1,56 +0,0 @@
1
- [ English | [한국어](./README.md) ]
2
-
3
- # IOSignal
4
-
5
- IOSignal enables real-time communication across web browsers, Node.js, and Arduino. It features built-in secure authentication, encrypted communication, and a pre-configured signaling protocol, allowing server deployment without complex programming.
6
-
7
-
8
- ## Features
9
-
10
- ### Built-in Message Trasport Protocol
11
- - pub/sub multicast by channel name.
12
- - uni-cast: one to one messaging by CID.
13
- - `CID` is a Communication Id
14
- - CID subscribing: subscribe one peer using CID.
15
- - HomeChannel: group by IP address.
16
-
17
- ### Built-in Security
18
- - Authentication
19
- - Encryption
20
- - E2EE
21
- - thanks to the `Boho` [ [github](https://github.com/remocons/boho) ]
22
-
23
- ## Connection
24
- - Web browser use WebSocket.
25
- - Node.js use WebSocket or CongSocket.
26
- - Arduino use CongSocket.
27
-
28
- ## IOSignal Server Architecture
29
- ![IOSignal](./docs/iosignal_architecture.png)
30
-
31
- ## IOSignal repositories.
32
-
33
- - Javascript: `iosignal` [ [github](https://github.com/remocons/iosignal) | [npm](https://www.npmjs.com/package/iosignal) ]
34
- - Node.js server ( WebSocket, CongSocket)
35
- - Node.js client ( WebSocket, CongSocket)
36
- - Web Browser client( WebSocket)
37
-
38
- - CLI program
39
- - `iosignal-cli` [ [github](https://github.com/remocons/iosignal-cli) | [npm](https://www.npmjs.com/package/iosignal-cli) ]
40
- - install: `npm i -g iosignal-cli` or `sudo npm i -g iosignal-cli`
41
- - support mac, linux and windows.
42
- - server and client
43
-
44
- - Arduino iosignal library and examples:
45
- - use Arduino Library Manager: `iosignal`
46
- - or `iosignal-arduino` [ [github](https://github.com/remocons/iosignal-arduino) ]
47
- - web app : http://test.iosignal.net
48
-
49
- - Arduino remocon library and examples:
50
- - use Arduino Library Manager: `remocon`
51
- - or `remocon-arduino` [ [github](https://github.com/remocons/remocon-arduino) ]
52
- - web app : https://remocon.kr
53
-
54
- ## License
55
-
56
- This code is released under the MIT License.
@@ -1,23 +0,0 @@
1
-
2
- /*
3
- Authentication data sample.
4
-
5
- device props: ["did", "key", "cid", level ]
6
-
7
- did: ( device id ) authentication id. maximum 8 chars.
8
- key: ( device key ) authentication key. no size limit.
9
- cid: ( communication id ) signal target id. maximum 12 chars.
10
- level:( quota level) <Number> ref. /server/quotaTable.js
11
-
12
- */
13
- export const authInfo = [
14
- ["did","passowrd","cid",0],
15
- ["device1","device1_key","device1_cid",0],
16
- ["device2","device2_key","device2_cid",0],
17
- ["uno","uno-key","uno",1],
18
- ["go","go-key","go",2],
19
- ["bro","bro-key","bro",3],
20
- ["admin","admin-key","admin",255],
21
- ]
22
-
23
-
@@ -1,13 +0,0 @@
1
- [
2
- ["sampleid","samplekey","sample_cid",0],
3
- ["id_max8","no_key_size_limit","communication_id",0],
4
- ["device1","device1_key","device1_cid",0],
5
- ["device2","device2_key","device2_cid",0],
6
- ["uno","uno","uno",1],
7
- ["go","go","go",2],
8
- ["bro","bro","bro",3],
9
- ["admin","admin","admin",255],
10
- ["adminb","adminb","adminb",255]
11
- ]
12
-
13
-
@@ -1,76 +0,0 @@
1
- /**
2
- * Auth_Env.js
3
- *
4
- * You can use environment variable BOHO_AUTH.
5
- *
6
- * BOHO_AUTH=id1.key1.level,id2:key2.level
7
- *
8
- * or constructor parameter.
9
- *
10
- *
11
- * [ authInfo ]
12
- * id: <String> max 8chars
13
- * key: <String>
14
- * level: <Numbrer> range: 0~255
15
- * separator: ','
16
- *
17
- * example => process.env.BOHO_AUTH=id1.key1.255,id2.key2.200
18
- */
19
-
20
- import { BohoAuth } from './BohoAuth.js';
21
- import Boho from 'boho'
22
-
23
- export class Auth_Env extends BohoAuth {
24
- constructor(authInfo) {
25
- super()
26
- let id_keys;
27
- if (authInfo) {
28
- id_keys = authInfo.split(',')
29
- } else if (process.env.BOHO_AUTH) {
30
- authInfo = process.env.BOHO_AUTH
31
- id_keys = process.env.BOHO_AUTH.split(',')
32
- } else {
33
- console.log("Auth_Env: None of process.env.BOHO_AUTH or authInfo")
34
- process.exit()
35
- }
36
-
37
- this.AUTH = new Map();
38
-
39
- if (id_keys.length >= 1) {
40
- id_keys.forEach(v => {
41
-
42
- let did = v.split('.')[0]
43
- let key = v.split('.')[1]
44
- let level = v.split('.')[2]
45
- level = parseInt(level)
46
-
47
- if (did && key && typeof level == 'number') {
48
- let cid = did;
49
- this.addAuth(did, key, cid, level)
50
- } else {
51
- console.log("Wrong process.env.BOHO_AUTH authentication value.", id, key, level)
52
- process.exit();
53
- }
54
- })
55
-
56
- } else {
57
- console.log("Wrong process.env.BOHO_AUTH authentication value.")
58
- process.exit();
59
- }
60
-
61
- }
62
-
63
- async getAuth(id) {
64
- return this.AUTH.get(id)
65
- }
66
- async getAuthIdList() {
67
- return Array.from(this.AUTH.keys())
68
- }
69
-
70
- addAuth(id, keyStr, cid, level = 0) {
71
- let Base64hashKey = Buffer.from(Boho.sha256.hash(keyStr)).toString('base64')
72
- this.AUTH.set(id, { key: Base64hashKey, cid: cid, level: level })
73
- }
74
-
75
- }
76
-