iosignal 4.8.0 → 4.10.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/dist/io.js +1 -1
- package/dist/io.js.map +1 -1
- package/dist/io.min.js +1 -1
- package/dist/io.min.js.map +1 -1
- package/dist/iosignal.js +38 -47
- package/package.json +1 -1
- package/src/auth/BohoAuth.js +26 -35
- package/src/client/IOCore.js +6 -5
- package/src/server/Server.js +4 -4
- package/src/server/serverOption.js +1 -2
package/dist/iosignal.js
CHANGED
|
@@ -13,7 +13,7 @@ import require$$2, { networkInterfaces } from 'os';
|
|
|
13
13
|
import require$$0$1 from 'buffer';
|
|
14
14
|
import { memoryUsage } from 'process';
|
|
15
15
|
|
|
16
|
-
var version$1 = "4.
|
|
16
|
+
var version$1 = "4.10.0";
|
|
17
17
|
var pkg = {
|
|
18
18
|
version: version$1};
|
|
19
19
|
|
|
@@ -1003,6 +1003,7 @@ class IOCore extends EventEmitter {
|
|
|
1003
1003
|
stop() {
|
|
1004
1004
|
this.autoReconnect = false;
|
|
1005
1005
|
this.close();
|
|
1006
|
+
this.cid = '';
|
|
1006
1007
|
this.stateChange('stop','stop');
|
|
1007
1008
|
}
|
|
1008
1009
|
|
|
@@ -1319,7 +1320,7 @@ class IOCore extends EventEmitter {
|
|
|
1319
1320
|
}
|
|
1320
1321
|
let oneString = decoder$4.decode(payloadStringWithoutNull);
|
|
1321
1322
|
if (tag.indexOf('@') === 0) this.emit('@', tag, oneString);
|
|
1322
|
-
|
|
1323
|
+
else {
|
|
1323
1324
|
this.emit(tag, tag, oneString);
|
|
1324
1325
|
this.emit('message', tag, oneString);
|
|
1325
1326
|
}
|
|
@@ -1327,7 +1328,7 @@ class IOCore extends EventEmitter {
|
|
|
1327
1328
|
|
|
1328
1329
|
case PAYLOAD_TYPE.BINARY:
|
|
1329
1330
|
if (tag.indexOf('@') === 0) this.emit('@', tag, payloadBuffer);
|
|
1330
|
-
|
|
1331
|
+
else {
|
|
1331
1332
|
this.emit(tag, tag, payloadBuffer);
|
|
1332
1333
|
this.emit('message', tag, payloadBuffer);
|
|
1333
1334
|
}
|
|
@@ -1337,7 +1338,7 @@ class IOCore extends EventEmitter {
|
|
|
1337
1338
|
let oneObjectBuffer = decoder$4.decode(payloadBuffer);
|
|
1338
1339
|
let oneJSONObject = JSON.parse(oneObjectBuffer);
|
|
1339
1340
|
if (tag.indexOf('@') === 0) this.emit('@', tag, oneJSONObject);
|
|
1340
|
-
|
|
1341
|
+
else {
|
|
1341
1342
|
this.emit(tag, tag, oneJSONObject);
|
|
1342
1343
|
this.emit('message', tag, oneJSONObject);
|
|
1343
1344
|
}
|
|
@@ -1347,7 +1348,7 @@ class IOCore extends EventEmitter {
|
|
|
1347
1348
|
let mjsonBuffer = decoder$4.decode(payloadBuffer);
|
|
1348
1349
|
let mjson = JSON.parse(mjsonBuffer);
|
|
1349
1350
|
if (tag.indexOf('@') === 0) this.emit('@', tag, ...mjson);
|
|
1350
|
-
|
|
1351
|
+
else {
|
|
1351
1352
|
this.emit(tag, tag, ...mjson);
|
|
1352
1353
|
this.emit('message', tag, ...mjson);
|
|
1353
1354
|
}
|
|
@@ -1356,7 +1357,7 @@ class IOCore extends EventEmitter {
|
|
|
1356
1357
|
case PAYLOAD_TYPE.MBA:
|
|
1357
1358
|
let mbaObject = M$1.unpack(payloadBuffer);
|
|
1358
1359
|
if (tag.indexOf('@') === 0) this.emit('@', tag, ...mbaObject.args);
|
|
1359
|
-
|
|
1360
|
+
else {
|
|
1360
1361
|
this.emit(tag, tag, ...mbaObject.args);
|
|
1361
1362
|
this.emit('message', tag, ...mbaObject.args);
|
|
1362
1363
|
}
|
|
@@ -7635,9 +7636,8 @@ let serverOption = {
|
|
|
7635
7636
|
},
|
|
7636
7637
|
|
|
7637
7638
|
auth: {
|
|
7638
|
-
delay_auth_fail: 600
|
|
7639
|
+
delay_auth_fail: 600
|
|
7639
7640
|
},
|
|
7640
|
-
|
|
7641
7641
|
membersOnly: false
|
|
7642
7642
|
|
|
7643
7643
|
};
|
|
@@ -9093,7 +9093,7 @@ class Server extends require$$0$3 {
|
|
|
9093
9093
|
|
|
9094
9094
|
// Service TYPE 1. single call() function.
|
|
9095
9095
|
if ( service_module.call && typeof service_module.call == 'function' ) {
|
|
9096
|
-
this.on(target,
|
|
9096
|
+
this.on(target, (remote, req) => {
|
|
9097
9097
|
try {
|
|
9098
9098
|
if (!service_module.checkPermission(remote, req)) {
|
|
9099
9099
|
remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.");
|
|
@@ -9101,7 +9101,7 @@ class Server extends require$$0$3 {
|
|
|
9101
9101
|
}
|
|
9102
9102
|
if( service_module.commands.includes( req.topic )){
|
|
9103
9103
|
// console.log('server service_module req', req )
|
|
9104
|
-
|
|
9104
|
+
service_module.call(remote, req);
|
|
9105
9105
|
}else {
|
|
9106
9106
|
remote.response(req.mid, STATUS.ERROR, "UNKNOWN_COMMAND");
|
|
9107
9107
|
}
|
|
@@ -9112,14 +9112,14 @@ class Server extends require$$0$3 {
|
|
|
9112
9112
|
});
|
|
9113
9113
|
} else {
|
|
9114
9114
|
// Service TYPE 2. multiple functions.
|
|
9115
|
-
this.on(target,
|
|
9115
|
+
this.on(target, (remote, req) => {
|
|
9116
9116
|
try {
|
|
9117
9117
|
if (!service_module.checkPermission(remote, req)) {
|
|
9118
9118
|
remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.");
|
|
9119
9119
|
return
|
|
9120
9120
|
}
|
|
9121
9121
|
if( service_module.commands.includes( req.topic )){
|
|
9122
|
-
|
|
9122
|
+
service_module[req.topic](remote, req);
|
|
9123
9123
|
}else {
|
|
9124
9124
|
remote.response(req.mid, STATUS.ERROR, "UNKNOWN_COMMAND");
|
|
9125
9125
|
}
|
|
@@ -9186,7 +9186,7 @@ class BohoAuth {
|
|
|
9186
9186
|
throw new Error('BohoAuth must be initialized with a keyProvider.');
|
|
9187
9187
|
}
|
|
9188
9188
|
this.keyProvider = keyProvider;
|
|
9189
|
-
|
|
9189
|
+
this.keepOldConnection = true;
|
|
9190
9190
|
this.authLogger;
|
|
9191
9191
|
if (serverOption.fileLogger.auth.use) {
|
|
9192
9192
|
this.authLogger = new FileLogger(serverOption.fileLogger.auth.path);
|
|
@@ -9201,42 +9201,40 @@ class BohoAuth {
|
|
|
9201
9201
|
}
|
|
9202
9202
|
// console.log('##### AUTH_FAIL reason: ', reason)
|
|
9203
9203
|
peer.setState(STATE.AUTH_FAIL);
|
|
9204
|
-
peer.send(Buffer.from([tt.BohoMsg.AUTH_FAIL]));
|
|
9205
9204
|
// add some delay time.
|
|
9206
|
-
|
|
9207
|
-
|
|
9205
|
+
setTimeout(e => {
|
|
9206
|
+
peer.send(Buffer.from([tt.BohoMsg.AUTH_FAIL]));
|
|
9207
|
+
}, serverOption.auth.delay_auth_fail);
|
|
9208
9208
|
}
|
|
9209
9209
|
|
|
9210
|
+
|
|
9210
9211
|
async verify_auth_hmac(auth_hmac, peer) {
|
|
9211
9212
|
try {
|
|
9212
9213
|
//1. unpack
|
|
9213
9214
|
let infoPack = M$1.unpack(auth_hmac, tt.Meta.AUTH_HMAC);
|
|
9214
|
-
|
|
9215
9215
|
if (!infoPack) {
|
|
9216
9216
|
this.send_auth_fail(peer, 'unpack auth_pack fail');
|
|
9217
9217
|
return
|
|
9218
9218
|
}
|
|
9219
|
-
|
|
9219
|
+
|
|
9220
9220
|
let id = "";
|
|
9221
9221
|
if (infoPack.id8.includes(0)) {
|
|
9222
9222
|
id = decoder.decode(infoPack.id8.subarray(0, infoPack.id8.indexOf(0)));
|
|
9223
9223
|
} else {
|
|
9224
9224
|
id = decoder.decode(infoPack.id8);
|
|
9225
9225
|
}
|
|
9226
|
-
|
|
9226
|
+
|
|
9227
9227
|
//2. get key of id from DB
|
|
9228
9228
|
let authInfo = await this.keyProvider.getAuth(id);
|
|
9229
|
-
|
|
9230
9229
|
if (!authInfo) {
|
|
9231
9230
|
this.send_auth_fail(peer, 'NO ID:' + id);
|
|
9232
9231
|
return
|
|
9233
9232
|
}
|
|
9234
9233
|
|
|
9235
9234
|
if (serverOption.debug.showAuthInfo) {
|
|
9236
|
-
console.log('[debug]showAuthInfo',authInfo
|
|
9235
|
+
console.log('[debug]showAuthInfo', authInfo);
|
|
9237
9236
|
}
|
|
9238
9237
|
|
|
9239
|
-
// console.log('db authInfo.key: ', authInfo.key)
|
|
9240
9238
|
peer.boho.copy_id8(infoPack.id8);
|
|
9241
9239
|
// type of key
|
|
9242
9240
|
let authKey;
|
|
@@ -9251,46 +9249,43 @@ class BohoAuth {
|
|
|
9251
9249
|
}
|
|
9252
9250
|
|
|
9253
9251
|
//3. check hmac
|
|
9254
|
-
// console.log('-- found: authKey of id: ', id, authKey.toString('hex'))
|
|
9255
9252
|
let auth_ack = peer.boho.check_auth_hmac(infoPack);
|
|
9256
|
-
|
|
9257
|
-
// console.log('auth_ack', auth_ack )
|
|
9258
9253
|
if (!auth_ack) {
|
|
9259
9254
|
this.send_auth_fail(peer, 'hmac dismatched');
|
|
9260
9255
|
return
|
|
9261
9256
|
}
|
|
9262
9257
|
|
|
9263
9258
|
//4. get info
|
|
9264
|
-
// console.log('#### auth success' )
|
|
9265
9259
|
|
|
9266
9260
|
//5. check duplicate login.
|
|
9267
|
-
// current policy. Deny duplicate login
|
|
9268
|
-
|
|
9269
|
-
// duplicate login policy.
|
|
9270
|
-
// 1. send clear_auth signal to the old connection.
|
|
9271
|
-
// 2. close old connection.
|
|
9272
|
-
// 3. close new connection. retry from begining.
|
|
9273
9261
|
if (peer.manager.cid2remote.has(authInfo.cid)) {
|
|
9274
9262
|
let old = peer.manager.cid2remote.get(authInfo.cid);
|
|
9263
|
+
console.log('[WARN]DUPLICATE_LOGIN detected.', old.cid);
|
|
9264
|
+
old.ping(); // check the connection.
|
|
9275
9265
|
if (old == peer) {
|
|
9276
|
-
console.log('## trying RELOGIN
|
|
9266
|
+
console.log('## trying to RELOGIN after login.');
|
|
9277
9267
|
return
|
|
9278
9268
|
}
|
|
9279
|
-
|
|
9280
|
-
let
|
|
9269
|
+
|
|
9270
|
+
let authClearSignal = M$1.pack(
|
|
9281
9271
|
M$1.MB('#MsgType', '8', IOMsg.AUTH_CLEAR),
|
|
9282
9272
|
M$1.MB('#reason', 'duplicate login.')
|
|
9283
9273
|
);
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
|
|
9274
|
+
if (this.keepOldConnection) { // default true
|
|
9275
|
+
// keep old connection. reject new connection by sending auth_fail signal.
|
|
9276
|
+
this.send_auth_fail(peer, 'duplicate login');
|
|
9277
|
+
// peer.send(authClearSignal)
|
|
9278
|
+
} else {
|
|
9279
|
+
// accept new connection. stop the old connection by sending auth_clear signal.
|
|
9280
|
+
old.send(authClearSignal);
|
|
9281
|
+
peer.close();
|
|
9282
|
+
}
|
|
9287
9283
|
return
|
|
9288
9284
|
}
|
|
9289
9285
|
|
|
9290
|
-
|
|
9291
|
-
//6. delete current (temp rand)cid if exist.
|
|
9286
|
+
//6. delete current (or anonymouse)cid if exist.
|
|
9292
9287
|
if (peer.cid) {
|
|
9293
|
-
console.log('
|
|
9288
|
+
// console.log('if peer has cid', peer.cid)
|
|
9294
9289
|
peer.manager.cid2remote.delete(peer.cid);
|
|
9295
9290
|
}
|
|
9296
9291
|
|
|
@@ -9298,7 +9293,7 @@ class BohoAuth {
|
|
|
9298
9293
|
peer.did = id;
|
|
9299
9294
|
peer.cid = authInfo.cid;
|
|
9300
9295
|
peer.nick = authInfo.cid; // temporary: nick as cid
|
|
9301
|
-
if(
|
|
9296
|
+
if (authInfo.uid) peer.uid = authInfo.uid;
|
|
9302
9297
|
|
|
9303
9298
|
//8. setting quota level.
|
|
9304
9299
|
let quotaLevel = serverOption.defaultQuotaIndex;
|
|
@@ -9307,7 +9302,6 @@ class BohoAuth {
|
|
|
9307
9302
|
let newQuota = quotaTable[quotaLevel];
|
|
9308
9303
|
if (!newQuota) {
|
|
9309
9304
|
let err = 'no index quotaTable for auth.level: ' + quotaLevel;
|
|
9310
|
-
console.log('##AUTH:DATA ERROR##', err);
|
|
9311
9305
|
this.send_auth_fail(peer, err);
|
|
9312
9306
|
return
|
|
9313
9307
|
} else {
|
|
@@ -9319,14 +9313,11 @@ class BohoAuth {
|
|
|
9319
9313
|
console.log('## LOGIN ADMIN CID:', peer.cid);
|
|
9320
9314
|
peer.isAdmin = true;
|
|
9321
9315
|
}
|
|
9322
|
-
// console.log('auth: peer.quota', peer.quota )
|
|
9323
9316
|
// send quota.level
|
|
9324
9317
|
peer.send(Buffer.from([IOMsg.QUOTA_LEVEL, quotaLevel]));
|
|
9325
9318
|
|
|
9326
9319
|
//9. set cid2remote
|
|
9327
9320
|
peer.manager.cid2remote.set(peer.cid, peer);
|
|
9328
|
-
// console.log( 'done: cid2remote:', peer.manager.cid2remote.keys() )
|
|
9329
|
-
// console.log("LOGIN: ", `id: ${ peer.did}(${peer.cid})` )
|
|
9330
9321
|
//10. send ack.
|
|
9331
9322
|
peer.send(auth_ack);
|
|
9332
9323
|
peer.setState(STATE.AUTH_ACK);
|
|
@@ -9337,9 +9328,9 @@ class BohoAuth {
|
|
|
9337
9328
|
}
|
|
9338
9329
|
return authInfo
|
|
9339
9330
|
} catch (error) {
|
|
9331
|
+
console.log('verify_auth_hmac error', error);
|
|
9340
9332
|
this.send_auth_fail(peer, '[BohoAuth]caught: unknown error:' + error);
|
|
9341
9333
|
}
|
|
9342
|
-
|
|
9343
9334
|
}
|
|
9344
9335
|
|
|
9345
9336
|
async getAuth(id) {
|
package/package.json
CHANGED
package/src/auth/BohoAuth.js
CHANGED
|
@@ -12,7 +12,7 @@ export class BohoAuth {
|
|
|
12
12
|
throw new Error('BohoAuth must be initialized with a keyProvider.');
|
|
13
13
|
}
|
|
14
14
|
this.keyProvider = keyProvider;
|
|
15
|
-
|
|
15
|
+
this.keepOldConnection = true;
|
|
16
16
|
this.authLogger;
|
|
17
17
|
if (serverOption.fileLogger.auth.use) {
|
|
18
18
|
this.authLogger = new FileLogger(serverOption.fileLogger.auth.path)
|
|
@@ -27,42 +27,40 @@ export class BohoAuth {
|
|
|
27
27
|
}
|
|
28
28
|
// console.log('##### AUTH_FAIL reason: ', reason)
|
|
29
29
|
peer.setState(STATE.AUTH_FAIL)
|
|
30
|
-
peer.send(Buffer.from([Boho.BohoMsg.AUTH_FAIL]))
|
|
31
30
|
// add some delay time.
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
setTimeout(e => {
|
|
32
|
+
peer.send(Buffer.from([Boho.BohoMsg.AUTH_FAIL]))
|
|
33
|
+
}, serverOption.auth.delay_auth_fail)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
|
|
36
37
|
async verify_auth_hmac(auth_hmac, peer) {
|
|
37
38
|
try {
|
|
38
39
|
//1. unpack
|
|
39
40
|
let infoPack = MBP.unpack(auth_hmac, Boho.Meta.AUTH_HMAC)
|
|
40
|
-
|
|
41
41
|
if (!infoPack) {
|
|
42
42
|
this.send_auth_fail(peer, 'unpack auth_pack fail');
|
|
43
43
|
return
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
let id = ""
|
|
47
47
|
if (infoPack.id8.includes(0)) {
|
|
48
48
|
id = decoder.decode(infoPack.id8.subarray(0, infoPack.id8.indexOf(0)));
|
|
49
49
|
} else {
|
|
50
50
|
id = decoder.decode(infoPack.id8);
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
//2. get key of id from DB
|
|
54
54
|
let authInfo = await this.keyProvider.getAuth(id)
|
|
55
|
-
|
|
56
55
|
if (!authInfo) {
|
|
57
56
|
this.send_auth_fail(peer, 'NO ID:' + id);
|
|
58
57
|
return
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
if (serverOption.debug.showAuthInfo) {
|
|
62
|
-
console.log('[debug]showAuthInfo',authInfo
|
|
61
|
+
console.log('[debug]showAuthInfo', authInfo)
|
|
63
62
|
}
|
|
64
63
|
|
|
65
|
-
// console.log('db authInfo.key: ', authInfo.key)
|
|
66
64
|
peer.boho.copy_id8(infoPack.id8)
|
|
67
65
|
// type of key
|
|
68
66
|
let authKey;
|
|
@@ -77,46 +75,43 @@ export class BohoAuth {
|
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
//3. check hmac
|
|
80
|
-
// console.log('-- found: authKey of id: ', id, authKey.toString('hex'))
|
|
81
78
|
let auth_ack = peer.boho.check_auth_hmac(infoPack)
|
|
82
|
-
|
|
83
|
-
// console.log('auth_ack', auth_ack )
|
|
84
79
|
if (!auth_ack) {
|
|
85
80
|
this.send_auth_fail(peer, 'hmac dismatched');
|
|
86
81
|
return
|
|
87
82
|
}
|
|
88
83
|
|
|
89
84
|
//4. get info
|
|
90
|
-
// console.log('#### auth success' )
|
|
91
85
|
|
|
92
86
|
//5. check duplicate login.
|
|
93
|
-
// current policy. Deny duplicate login
|
|
94
|
-
|
|
95
|
-
// duplicate login policy.
|
|
96
|
-
// 1. send clear_auth signal to the old connection.
|
|
97
|
-
// 2. close old connection.
|
|
98
|
-
// 3. close new connection. retry from begining.
|
|
99
87
|
if (peer.manager.cid2remote.has(authInfo.cid)) {
|
|
100
88
|
let old = peer.manager.cid2remote.get(authInfo.cid)
|
|
89
|
+
console.log('[WARN]DUPLICATE_LOGIN detected.', old.cid)
|
|
90
|
+
old.ping(); // check the connection.
|
|
101
91
|
if (old == peer) {
|
|
102
|
-
console.log('## trying RELOGIN
|
|
92
|
+
console.log('## trying to RELOGIN after login.')
|
|
103
93
|
return
|
|
104
94
|
}
|
|
105
|
-
|
|
106
|
-
let
|
|
95
|
+
|
|
96
|
+
let authClearSignal = MBP.pack(
|
|
107
97
|
MBP.MB('#MsgType', '8', IOMsg.AUTH_CLEAR),
|
|
108
98
|
MBP.MB('#reason', 'duplicate login.')
|
|
109
99
|
)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
if (this.keepOldConnection) { // default true
|
|
101
|
+
// keep old connection. reject new connection by sending auth_fail signal.
|
|
102
|
+
this.send_auth_fail(peer, 'duplicate login')
|
|
103
|
+
// peer.send(authClearSignal)
|
|
104
|
+
} else {
|
|
105
|
+
// accept new connection. stop the old connection by sending auth_clear signal.
|
|
106
|
+
old.send(authClearSignal)
|
|
107
|
+
peer.close()
|
|
108
|
+
}
|
|
113
109
|
return
|
|
114
110
|
}
|
|
115
111
|
|
|
116
|
-
|
|
117
|
-
//6. delete current (temp rand)cid if exist.
|
|
112
|
+
//6. delete current (or anonymouse)cid if exist.
|
|
118
113
|
if (peer.cid) {
|
|
119
|
-
console.log('
|
|
114
|
+
// console.log('if peer has cid', peer.cid)
|
|
120
115
|
peer.manager.cid2remote.delete(peer.cid)
|
|
121
116
|
}
|
|
122
117
|
|
|
@@ -124,7 +119,7 @@ export class BohoAuth {
|
|
|
124
119
|
peer.did = id
|
|
125
120
|
peer.cid = authInfo.cid
|
|
126
121
|
peer.nick = authInfo.cid // temporary: nick as cid
|
|
127
|
-
if(
|
|
122
|
+
if (authInfo.uid) peer.uid = authInfo.uid
|
|
128
123
|
|
|
129
124
|
//8. setting quota level.
|
|
130
125
|
let quotaLevel = serverOption.defaultQuotaIndex;
|
|
@@ -133,7 +128,6 @@ export class BohoAuth {
|
|
|
133
128
|
let newQuota = quotaTable[quotaLevel];
|
|
134
129
|
if (!newQuota) {
|
|
135
130
|
let err = 'no index quotaTable for auth.level: ' + quotaLevel
|
|
136
|
-
console.log('##AUTH:DATA ERROR##', err)
|
|
137
131
|
this.send_auth_fail(peer, err);
|
|
138
132
|
return
|
|
139
133
|
} else {
|
|
@@ -145,14 +139,11 @@ export class BohoAuth {
|
|
|
145
139
|
console.log('## LOGIN ADMIN CID:', peer.cid)
|
|
146
140
|
peer.isAdmin = true;
|
|
147
141
|
}
|
|
148
|
-
// console.log('auth: peer.quota', peer.quota )
|
|
149
142
|
// send quota.level
|
|
150
143
|
peer.send(Buffer.from([IOMsg.QUOTA_LEVEL, quotaLevel]))
|
|
151
144
|
|
|
152
145
|
//9. set cid2remote
|
|
153
146
|
peer.manager.cid2remote.set(peer.cid, peer)
|
|
154
|
-
// console.log( 'done: cid2remote:', peer.manager.cid2remote.keys() )
|
|
155
|
-
// console.log("LOGIN: ", `id: ${ peer.did}(${peer.cid})` )
|
|
156
147
|
//10. send ack.
|
|
157
148
|
peer.send(auth_ack)
|
|
158
149
|
peer.setState(STATE.AUTH_ACK)
|
|
@@ -163,9 +154,9 @@ export class BohoAuth {
|
|
|
163
154
|
}
|
|
164
155
|
return authInfo
|
|
165
156
|
} catch (error) {
|
|
157
|
+
console.log('verify_auth_hmac error', error)
|
|
166
158
|
this.send_auth_fail(peer, '[BohoAuth]caught: unknown error:' + error);
|
|
167
159
|
}
|
|
168
|
-
|
|
169
160
|
}
|
|
170
161
|
|
|
171
162
|
async getAuth(id) {
|
package/src/client/IOCore.js
CHANGED
|
@@ -246,6 +246,7 @@ export class IOCore extends EventEmitter {
|
|
|
246
246
|
stop() {
|
|
247
247
|
this.autoReconnect = false;
|
|
248
248
|
this.close();
|
|
249
|
+
this.cid = ''
|
|
249
250
|
this.stateChange('stop','stop');
|
|
250
251
|
}
|
|
251
252
|
|
|
@@ -567,7 +568,7 @@ export class IOCore extends EventEmitter {
|
|
|
567
568
|
}
|
|
568
569
|
let oneString = decoder.decode(payloadStringWithoutNull)
|
|
569
570
|
if (tag.indexOf('@') === 0) this.emit('@', tag, oneString)
|
|
570
|
-
|
|
571
|
+
else {
|
|
571
572
|
this.emit(tag, tag, oneString)
|
|
572
573
|
this.emit('message', tag, oneString)
|
|
573
574
|
}
|
|
@@ -575,7 +576,7 @@ export class IOCore extends EventEmitter {
|
|
|
575
576
|
|
|
576
577
|
case PAYLOAD_TYPE.BINARY:
|
|
577
578
|
if (tag.indexOf('@') === 0) this.emit('@', tag, payloadBuffer)
|
|
578
|
-
|
|
579
|
+
else {
|
|
579
580
|
this.emit(tag, tag, payloadBuffer)
|
|
580
581
|
this.emit('message', tag, payloadBuffer)
|
|
581
582
|
}
|
|
@@ -585,7 +586,7 @@ export class IOCore extends EventEmitter {
|
|
|
585
586
|
let oneObjectBuffer = decoder.decode(payloadBuffer)
|
|
586
587
|
let oneJSONObject = JSON.parse(oneObjectBuffer)
|
|
587
588
|
if (tag.indexOf('@') === 0) this.emit('@', tag, oneJSONObject)
|
|
588
|
-
|
|
589
|
+
else {
|
|
589
590
|
this.emit(tag, tag, oneJSONObject)
|
|
590
591
|
this.emit('message', tag, oneJSONObject)
|
|
591
592
|
}
|
|
@@ -595,7 +596,7 @@ export class IOCore extends EventEmitter {
|
|
|
595
596
|
let mjsonBuffer = decoder.decode(payloadBuffer)
|
|
596
597
|
let mjson = JSON.parse(mjsonBuffer)
|
|
597
598
|
if (tag.indexOf('@') === 0) this.emit('@', tag, ...mjson)
|
|
598
|
-
|
|
599
|
+
else {
|
|
599
600
|
this.emit(tag, tag, ...mjson)
|
|
600
601
|
this.emit('message', tag, ...mjson)
|
|
601
602
|
}
|
|
@@ -604,7 +605,7 @@ export class IOCore extends EventEmitter {
|
|
|
604
605
|
case PAYLOAD_TYPE.MBA:
|
|
605
606
|
let mbaObject = MBP.unpack(payloadBuffer)
|
|
606
607
|
if (tag.indexOf('@') === 0) this.emit('@', tag, ...mbaObject.args)
|
|
607
|
-
|
|
608
|
+
else {
|
|
608
609
|
this.emit(tag, tag, ...mbaObject.args)
|
|
609
610
|
this.emit('message', tag, ...mbaObject.args)
|
|
610
611
|
}
|
package/src/server/Server.js
CHANGED
|
@@ -149,7 +149,7 @@ export class Server extends EventEmitter {
|
|
|
149
149
|
|
|
150
150
|
// Service TYPE 1. single call() function.
|
|
151
151
|
if ( service_module.call && typeof service_module.call == 'function' ) {
|
|
152
|
-
this.on(target,
|
|
152
|
+
this.on(target, (remote, req) => {
|
|
153
153
|
try {
|
|
154
154
|
if (!service_module.checkPermission(remote, req)) {
|
|
155
155
|
remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.")
|
|
@@ -157,7 +157,7 @@ export class Server extends EventEmitter {
|
|
|
157
157
|
}
|
|
158
158
|
if( service_module.commands.includes( req.topic )){
|
|
159
159
|
// console.log('server service_module req', req )
|
|
160
|
-
|
|
160
|
+
service_module.call(remote, req)
|
|
161
161
|
}else{
|
|
162
162
|
remote.response(req.mid, STATUS.ERROR, "UNKNOWN_COMMAND");
|
|
163
163
|
}
|
|
@@ -168,14 +168,14 @@ export class Server extends EventEmitter {
|
|
|
168
168
|
})
|
|
169
169
|
} else {
|
|
170
170
|
// Service TYPE 2. multiple functions.
|
|
171
|
-
this.on(target,
|
|
171
|
+
this.on(target, (remote, req) => {
|
|
172
172
|
try {
|
|
173
173
|
if (!service_module.checkPermission(remote, req)) {
|
|
174
174
|
remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.")
|
|
175
175
|
return
|
|
176
176
|
}
|
|
177
177
|
if( service_module.commands.includes( req.topic )){
|
|
178
|
-
|
|
178
|
+
service_module[req.topic](remote, req)
|
|
179
179
|
}else{
|
|
180
180
|
remote.response(req.mid, STATUS.ERROR, "UNKNOWN_COMMAND");
|
|
181
181
|
}
|