@based/server 4.0.0 → 4.0.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.
- package/dist/BasedServerClient.d.ts +71 -0
- package/dist/BasedServerClient.js +390 -0
- package/dist/BasedServerClient.js.map +1 -0
- package/dist/Client.d.ts +75 -0
- package/dist/Client.js +277 -0
- package/dist/Client.js.map +1 -0
- package/dist/Params.d.ts +20 -0
- package/dist/Params.js +48 -0
- package/dist/Params.js.map +1 -0
- package/dist/auth/authorize.d.ts +2 -0
- package/dist/auth/authorize.js +8 -0
- package/dist/auth/authorize.js.map +1 -0
- package/dist/clientContext.d.ts +0 -0
- package/dist/clientContext.js +83 -0
- package/dist/clientContext.js.map +1 -0
- package/dist/closeListener.d.ts +4 -0
- package/dist/closeListener.js +13 -0
- package/dist/closeListener.js.map +1 -0
- package/dist/createSimpleServer.d.ts +22 -0
- package/dist/createSimpleServer.js +120 -0
- package/dist/createSimpleServer.js.map +1 -0
- package/dist/error.d.ts +66 -0
- package/dist/error.js +149 -0
- package/dist/error.js.map +1 -0
- package/dist/findPrefix.d.ts +3 -0
- package/dist/findPrefix.js +20 -0
- package/dist/findPrefix.js.map +1 -0
- package/dist/functions/types.d.ts +0 -2
- package/dist/functions/types.js.map +1 -1
- package/dist/functions/workerPool.d.ts +0 -0
- package/dist/functions/workerPool.js +5 -0
- package/dist/functions/workerPool.js.map +1 -0
- package/dist/getFromConfig.d.ts +3 -0
- package/dist/getFromConfig.js +50 -0
- package/dist/getFromConfig.js.map +1 -0
- package/dist/handlers/authorize.d.ts +5 -0
- package/dist/handlers/authorize.js +196 -0
- package/dist/handlers/authorize.js.map +1 -0
- package/dist/handlers/bulkUpdate/index.d.ts +5 -0
- package/dist/handlers/bulkUpdate/index.js +26 -0
- package/dist/handlers/bulkUpdate/index.js.map +1 -0
- package/dist/handlers/configuration/index.d.ts +10 -0
- package/dist/handlers/configuration/index.js +74 -0
- package/dist/handlers/configuration/index.js.map +1 -0
- package/dist/handlers/configuration/observable/index.d.ts +46 -0
- package/dist/handlers/configuration/observable/index.js +277 -0
- package/dist/handlers/configuration/observable/index.js.map +1 -0
- package/dist/handlers/configure/index.d.ts +5 -0
- package/dist/handlers/configure/index.js +44 -0
- package/dist/handlers/configure/index.js.map +1 -0
- package/dist/handlers/copy/index.d.ts +8 -0
- package/dist/handlers/copy/index.js +135 -0
- package/dist/handlers/copy/index.js.map +1 -0
- package/dist/handlers/delete/index.d.ts +5 -0
- package/dist/handlers/delete/index.js +34 -0
- package/dist/handlers/delete/index.js.map +1 -0
- package/dist/handlers/digest/index.d.ts +5 -0
- package/dist/handlers/digest/index.js +23 -0
- package/dist/handlers/digest/index.js.map +1 -0
- package/dist/handlers/functions/call.d.ts +6 -0
- package/dist/handlers/functions/call.js +54 -0
- package/dist/handlers/functions/call.js.map +1 -0
- package/dist/handlers/functions/observable/Observable.d.ts +49 -0
- package/dist/handlers/functions/observable/Observable.js +290 -0
- package/dist/handlers/functions/observable/Observable.js.map +1 -0
- package/dist/handlers/functions/observable/SharedObservable.d.ts +45 -0
- package/dist/handlers/functions/observable/SharedObservable.js +291 -0
- package/dist/handlers/functions/observable/SharedObservable.js.map +1 -0
- package/dist/handlers/functions/observable/index.d.ts +14 -0
- package/dist/handlers/functions/observable/index.js +130 -0
- package/dist/handlers/functions/observable/index.js.map +1 -0
- package/dist/handlers/get/index.d.ts +5 -0
- package/dist/handlers/get/index.js +23 -0
- package/dist/handlers/get/index.js.map +1 -0
- package/dist/handlers/getConfig/index.d.ts +5 -0
- package/dist/handlers/getConfig/index.js +38 -0
- package/dist/handlers/getConfig/index.js.map +1 -0
- package/dist/handlers/handleRequests.d.ts +5 -0
- package/dist/handlers/handleRequests.js +78 -0
- package/dist/handlers/handleRequests.js.map +1 -0
- package/dist/handlers/index.d.ts +4 -0
- package/dist/handlers/index.js +49 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/messageParser.d.ts +5 -0
- package/dist/handlers/messageParser.js +122 -0
- package/dist/handlers/messageParser.js.map +1 -0
- package/dist/handlers/removeField/index.d.ts +5 -0
- package/dist/handlers/removeField/index.js +42 -0
- package/dist/handlers/removeField/index.js.map +1 -0
- package/dist/handlers/removeType/index.d.ts +5 -0
- package/dist/handlers/removeType/index.js +30 -0
- package/dist/handlers/removeType/index.js.map +1 -0
- package/dist/handlers/rest/file/DataStream.d.ts +7 -0
- package/dist/handlers/rest/file/DataStream.js +17 -0
- package/dist/handlers/rest/file/DataStream.js.map +1 -0
- package/dist/handlers/rest/file/formStream.d.ts +4 -0
- package/dist/handlers/rest/file/formStream.js +188 -0
- package/dist/handlers/rest/file/formStream.js.map +1 -0
- package/dist/handlers/rest/file/getExtenstion.d.ts +2 -0
- package/dist/handlers/rest/file/getExtenstion.js +22 -0
- package/dist/handlers/rest/file/getExtenstion.js.map +1 -0
- package/dist/handlers/rest/file/index.d.ts +4 -0
- package/dist/handlers/rest/file/index.js +53 -0
- package/dist/handlers/rest/file/index.js.map +1 -0
- package/dist/handlers/rest/file/storeFile.d.ts +6 -0
- package/dist/handlers/rest/file/storeFile.js +44 -0
- package/dist/handlers/rest/file/storeFile.js.map +1 -0
- package/dist/handlers/rest/file/stream.d.ts +5 -0
- package/dist/handlers/rest/file/stream.js +104 -0
- package/dist/handlers/rest/file/stream.js.map +1 -0
- package/dist/handlers/rest/file/types.d.ts +9 -0
- package/dist/handlers/rest/file/types.js +3 -0
- package/dist/handlers/rest/file/types.js.map +1 -0
- package/dist/handlers/rest/getReqMessage.d.ts +3 -0
- package/dist/handlers/rest/getReqMessage.js +92 -0
- package/dist/handlers/rest/getReqMessage.js.map +1 -0
- package/dist/handlers/rest/index.d.ts +4 -0
- package/dist/handlers/rest/index.js +121 -0
- package/dist/handlers/rest/index.js.map +1 -0
- package/dist/handlers/rest/invalidReq.d.ts +4 -0
- package/dist/handlers/rest/invalidReq.js +20 -0
- package/dist/handlers/rest/invalidReq.js.map +1 -0
- package/dist/handlers/rest/parseResponse.d.ts +6 -0
- package/dist/handlers/rest/parseResponse.js +230 -0
- package/dist/handlers/rest/parseResponse.js.map +1 -0
- package/dist/handlers/rest/playground/index.d.ts +5 -0
- package/dist/handlers/rest/playground/index.js +308 -0
- package/dist/handlers/rest/playground/index.js.map +1 -0
- package/dist/handlers/rest/readBody.d.ts +3 -0
- package/dist/handlers/rest/readBody.js +45 -0
- package/dist/handlers/rest/readBody.js.map +1 -0
- package/dist/handlers/set/index.d.ts +5 -0
- package/dist/handlers/set/index.js +20 -0
- package/dist/handlers/set/index.js.map +1 -0
- package/dist/handlers/subscription/index.d.ts +32 -0
- package/dist/handlers/subscription/index.js +223 -0
- package/dist/handlers/subscription/index.js.map +1 -0
- package/dist/handlers/token.d.ts +5 -0
- package/dist/handlers/token.js +122 -0
- package/dist/handlers/token.js.map +1 -0
- package/dist/handlers/track/index.d.ts +7 -0
- package/dist/handlers/track/index.js +102 -0
- package/dist/handlers/track/index.js.map +1 -0
- package/dist/handlers/userAuth/index.d.ts +5 -0
- package/dist/handlers/userAuth/index.js +78 -0
- package/dist/handlers/userAuth/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/network/http/authorize.d.ts +3 -0
- package/dist/network/http/authorize.js +28 -0
- package/dist/network/http/authorize.js.map +1 -0
- package/dist/network/http/compress.d.ts +6 -0
- package/dist/network/http/compress.js +56 -0
- package/dist/network/http/compress.js.map +1 -0
- package/dist/network/http/end.d.ts +4 -0
- package/dist/network/http/end.js +19 -0
- package/dist/network/http/end.js.map +1 -0
- package/dist/network/http/function.d.ts +3 -0
- package/dist/network/http/function.js +47 -0
- package/dist/network/http/function.js.map +1 -0
- package/dist/network/http/get.d.ts +3 -0
- package/dist/network/http/get.js +129 -0
- package/dist/network/http/get.js.map +1 -0
- package/dist/network/http/index.d.ts +3 -0
- package/dist/network/http/index.js +122 -0
- package/dist/network/http/index.js.map +1 -0
- package/dist/network/http/readBody.d.ts +3 -0
- package/dist/network/http/readBody.js +112 -0
- package/dist/network/http/readBody.js.map +1 -0
- package/dist/network/http/send.d.ts +5 -0
- package/dist/network/http/send.js +60 -0
- package/dist/network/http/send.js.map +1 -0
- package/dist/network/http/streamFunction/DataStream.d.ts +7 -0
- package/dist/network/http/streamFunction/DataStream.js +19 -0
- package/dist/network/http/streamFunction/DataStream.js.map +1 -0
- package/dist/network/http/streamFunction/getExtension.d.ts +2 -0
- package/dist/network/http/streamFunction/getExtension.js +29 -0
- package/dist/network/http/streamFunction/getExtension.js.map +1 -0
- package/dist/network/http/streamFunction/index.d.ts +3 -0
- package/dist/network/http/streamFunction/index.js +81 -0
- package/dist/network/http/streamFunction/index.js.map +1 -0
- package/dist/network/http/streamFunction/multipartStream.d.ts +12 -0
- package/dist/network/http/streamFunction/multipartStream.js +208 -0
- package/dist/network/http/streamFunction/multipartStream.js.map +1 -0
- package/dist/network/http/streamFunction/stream.d.ts +5 -0
- package/dist/network/http/streamFunction/stream.js +103 -0
- package/dist/network/http/streamFunction/stream.js.map +1 -0
- package/dist/network/index.d.ts +4 -0
- package/dist/network/index.js +84 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/message/auth.d.ts +4 -0
- package/dist/network/message/auth.js +32 -0
- package/dist/network/message/auth.js.map +1 -0
- package/dist/network/message/function.d.ts +3 -0
- package/dist/network/message/function.js +67 -0
- package/dist/network/message/function.js.map +1 -0
- package/dist/network/message/get.d.ts +3 -0
- package/dist/network/message/get.js +109 -0
- package/dist/network/message/get.js.map +1 -0
- package/dist/network/message/index.d.ts +3 -0
- package/dist/network/message/index.js +62 -0
- package/dist/network/message/index.js.map +1 -0
- package/dist/network/message/observable.d.ts +5 -0
- package/dist/network/message/observable.js +103 -0
- package/dist/network/message/observable.js.map +1 -0
- package/dist/network/message/send.d.ts +4 -0
- package/dist/network/message/send.js +11 -0
- package/dist/network/message/send.js.map +1 -0
- package/dist/network/upgrade.d.ts +4 -0
- package/dist/network/upgrade.js +49 -0
- package/dist/network/upgrade.js.map +1 -0
- package/dist/network/worker/get.d.ts +0 -0
- package/dist/network/worker/get.js +122 -0
- package/dist/network/worker/get.js.map +1 -0
- package/dist/network/worker/observable.d.ts +0 -0
- package/dist/network/worker/observable.js +120 -0
- package/dist/network/worker/observable.js.map +1 -0
- package/dist/openListener.d.ts +4 -0
- package/dist/openListener.js +13 -0
- package/dist/openListener.js.map +1 -0
- package/dist/secrets.d.ts +9 -0
- package/dist/secrets.js +150 -0
- package/dist/secrets.js.map +1 -0
- package/dist/security/index.d.ts +3 -0
- package/dist/security/index.js +66 -0
- package/dist/security/index.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/dist/upgradeListener.d.ts +4 -0
- package/dist/upgradeListener.js +47 -0
- package/dist/upgradeListener.js.map +1 -0
- package/dist/worker/authorize.d.ts +5 -0
- package/dist/worker/authorize.js +15 -0
- package/dist/worker/authorize.js.map +1 -0
- package/dist/worker/fnMap.d.ts +2 -0
- package/dist/worker/fnMap.js +5 -0
- package/dist/worker/fnMap.js.map +1 -0
- package/dist/worker/functions.d.ts +3 -0
- package/dist/worker/functions.js +8 -0
- package/dist/worker/functions.js.map +1 -0
- package/dist/worker/http/function.d.ts +4 -0
- package/dist/worker/http/function.js +75 -0
- package/dist/worker/http/function.js.map +1 -0
- package/dist/worker/index.d.ts +1 -0
- package/dist/worker/index.js +101 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/observable.d.ts +15 -0
- package/dist/worker/observable.js +110 -0
- package/dist/worker/observable.js.map +1 -0
- package/dist/worker/ws/function.d.ts +3 -0
- package/dist/worker/ws/function.js +42 -0
- package/dist/worker/ws/function.js.map +1 -0
- package/dist/workers/index.d.ts +0 -0
- package/dist/workers/index.js +20 -0
- package/dist/workers/index.js.map +1 -0
- package/dist/workers/workerCode.d.ts +12 -0
- package/dist/workers/workerCode.js +46 -0
- package/dist/workers/workerCode.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const uws_1 = __importDefault(require("@based/uws"));
|
|
7
|
+
const upgrade_1 = require("./upgrade");
|
|
8
|
+
const message_1 = require("./message");
|
|
9
|
+
const observable_1 = require("../observable");
|
|
10
|
+
const http_1 = require("./http");
|
|
11
|
+
// ----------------- mem test code -------------------
|
|
12
|
+
// let cl = 0
|
|
13
|
+
// const genLargeMemBlock = (): string => {
|
|
14
|
+
// ++cl
|
|
15
|
+
// let str = ''
|
|
16
|
+
// for (let i = 0; i < 100000; i++) {
|
|
17
|
+
// str += Math.random() * 99999 + ' xxxx'
|
|
18
|
+
// }
|
|
19
|
+
// return str
|
|
20
|
+
// }
|
|
21
|
+
// let cnt = 0
|
|
22
|
+
// setInterval(() => {
|
|
23
|
+
// ++cnt
|
|
24
|
+
// console.info('Amount of clients', cl, 'after', cnt, 'seconds')
|
|
25
|
+
// }, 1e3)
|
|
26
|
+
// -----------------------------------------------------
|
|
27
|
+
exports.default = (server, { key, cert, port }) => {
|
|
28
|
+
const app = key && cert
|
|
29
|
+
? uws_1.default.SSLApp({
|
|
30
|
+
key_file_name: key,
|
|
31
|
+
cert_file_name: cert,
|
|
32
|
+
ssl_prefer_low_memory_usage: true,
|
|
33
|
+
})
|
|
34
|
+
: uws_1.default.App();
|
|
35
|
+
if (port) {
|
|
36
|
+
server.port = port;
|
|
37
|
+
}
|
|
38
|
+
app
|
|
39
|
+
.ws('/*', {
|
|
40
|
+
maxPayloadLength: 1024 * 1024 * 10,
|
|
41
|
+
idleTimeout: 100,
|
|
42
|
+
maxBackpressure: 1024,
|
|
43
|
+
// compression: uws.SHARED_COMPRESSOR,
|
|
44
|
+
upgrade: server.auth?.config?.authorizeConnection
|
|
45
|
+
? (res, req, ctx) => {
|
|
46
|
+
(0, upgrade_1.upgradeAuthorize)(server.auth.config.authorizeConnection, res, req, ctx);
|
|
47
|
+
}
|
|
48
|
+
: upgrade_1.upgrade,
|
|
49
|
+
message: (ws, data, isBinary) => {
|
|
50
|
+
(0, message_1.message)(server, ws.c, data, isBinary);
|
|
51
|
+
},
|
|
52
|
+
open: (ws) => {
|
|
53
|
+
if (ws) {
|
|
54
|
+
// ws.bla = genLargeMemBlock()
|
|
55
|
+
const client = { ws };
|
|
56
|
+
ws.c = client;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
close: (ws) => {
|
|
60
|
+
// cl--
|
|
61
|
+
ws.obs.forEach((id) => {
|
|
62
|
+
(0, observable_1.unsubscribeIgnoreClient)(server, id, ws.c);
|
|
63
|
+
});
|
|
64
|
+
// Looks really ugly but same impact on memory and GC as using the ws directly
|
|
65
|
+
// and better for dc's when functions etc are in progress
|
|
66
|
+
ws.c.ws = null;
|
|
67
|
+
ws.c = null;
|
|
68
|
+
},
|
|
69
|
+
drain: () => {
|
|
70
|
+
// console.info('drain')
|
|
71
|
+
// lets handle drain efficiently (or more efficiently at least)
|
|
72
|
+
// call client.drain can be much more efficient
|
|
73
|
+
// if (ws.client && ws.client.backpressureQueue) {
|
|
74
|
+
// ws.client.drain()
|
|
75
|
+
// }
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
// REST
|
|
79
|
+
.get('/*', (res, req) => (0, http_1.httpHandler)(server, req, res))
|
|
80
|
+
.post('/*', (res, req) => (0, http_1.httpHandler)(server, req, res))
|
|
81
|
+
.options('/*', (res, req) => (0, http_1.httpHandler)(server, req, res));
|
|
82
|
+
server.uwsApp = app;
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/network/index.ts"],"names":[],"mappings":";;;;;AAEA,qDAA4B;AAC5B,uCAAqD;AACrD,uCA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from '../../types';
|
|
3
|
+
export declare type AuthState = any;
|
|
4
|
+
export declare const authMessage: (arr: Uint8Array, start: number, len: number, isDeflate: boolean, client: WebsocketClient, server: BasedServer) => boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authMessage = void 0;
|
|
4
|
+
const protocol_1 = require("../../protocol");
|
|
5
|
+
const observable_1 = require("./observable");
|
|
6
|
+
const authMessage = (arr, start, len, isDeflate, client, server) => {
|
|
7
|
+
// | 4 header | * payload |
|
|
8
|
+
const authPayload = (0, protocol_1.decodePayload)(new Uint8Array(arr.slice(start + 4, start + len)), isDeflate);
|
|
9
|
+
let authState;
|
|
10
|
+
try {
|
|
11
|
+
authState = JSON.parse(authPayload);
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
console.error("can't decode auth payload", err);
|
|
15
|
+
}
|
|
16
|
+
if (client.ws) {
|
|
17
|
+
client.ws.authState = authState;
|
|
18
|
+
if (client.ws.unauthorizedObs.size) {
|
|
19
|
+
client.ws.unauthorizedObs.forEach((obs) => {
|
|
20
|
+
const { id, name, checksum, payload } = obs;
|
|
21
|
+
(0, observable_1.enableSubscribe)(server, client, id, checksum, name, payload, {
|
|
22
|
+
name: 'internal-websocket-auth',
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
client.ws.unauthorizedObs.clear();
|
|
26
|
+
}
|
|
27
|
+
client.ws.send((0, protocol_1.encodeAuthResponse)((0, protocol_1.valueToBuffer)(true)), true, false);
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
};
|
|
31
|
+
exports.authMessage = authMessage;
|
|
32
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/network/message/auth.ts"],"names":[],"mappings":";;;AAAA,6CAIuB;AAGvB,6CAA8C;AAIvC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"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functionMessage = void 0;
|
|
4
|
+
const functions_1 = require("../../functions");
|
|
5
|
+
const protocol_1 = require("../../protocol");
|
|
6
|
+
const error_1 = require("../../error");
|
|
7
|
+
const send_1 = require("./send");
|
|
8
|
+
const functionMessage = (arr, start, len, isDeflate, client, server) => {
|
|
9
|
+
// | 4 header | 3 id | 1 name length | * name | * payload |
|
|
10
|
+
const reqId = (0, protocol_1.readUint8)(arr, start + 4, 3);
|
|
11
|
+
const nameLen = arr[start + 7];
|
|
12
|
+
const name = (0, protocol_1.decodeName)(arr, start + 8, start + 8 + nameLen);
|
|
13
|
+
if (!name || !reqId) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const route = server.functions.route(name);
|
|
17
|
+
if (!route) {
|
|
18
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.FunctionNotFound, { name });
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (route.observable === true) {
|
|
22
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.FunctionIsObservable, route);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (len > route.maxPayloadSize) {
|
|
26
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.PayloadTooLarge, route);
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (route.stream === true) {
|
|
30
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.FunctionIsStream, route);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
const p = arr.slice(start + 8 + nameLen, start + len);
|
|
34
|
+
server.functions
|
|
35
|
+
.install(name)
|
|
36
|
+
.then((spec) => {
|
|
37
|
+
if (!client.ws) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (spec && !(0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
41
|
+
server.functions
|
|
42
|
+
.runFunction(0, spec, {
|
|
43
|
+
isDeflate,
|
|
44
|
+
reqId,
|
|
45
|
+
// TODO: way too much copy but this is tmp solution
|
|
46
|
+
authState: client.ws.authState,
|
|
47
|
+
query: client.ws.query,
|
|
48
|
+
ua: client.ws.ua,
|
|
49
|
+
ip: client.ws.ip,
|
|
50
|
+
}, p)
|
|
51
|
+
.then(async (v) => {
|
|
52
|
+
client.ws?.send(v, true, false);
|
|
53
|
+
})
|
|
54
|
+
.catch((err) => {
|
|
55
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.FunctionError, {
|
|
56
|
+
route,
|
|
57
|
+
requestId: reqId,
|
|
58
|
+
err,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
.catch(() => (0, send_1.sendError)(server, client, error_1.BasedErrorCode.FunctionNotFound, route));
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
66
|
+
exports.functionMessage = functionMessage;
|
|
67
|
+
//# sourceMappingURL=function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function.js","sourceRoot":"","sources":["../../../src/network/message/function.ts"],"names":[],"mappings":";;;AAAA,+CAA0D;AAC1D,6CAAsD;AAEtD,uCAA4C;AAC5C,iCAAkC;AAG3B,MAAM,eAAe,GAAG,CAC7B,GAAe,EACf,KAAa,EACb,GAAW,EACX,SAAkB,EAClB,MAAuB,EACvB,MAAmB,EACV,EAAE;IACX,2DAA2D;IAE3D,MAAM,KAAK,GAAG,IAAA,oBAAS,EAAC,GAAG,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IAC1C,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;IAC9B,MAAM,IAAI,GAAG,IAAA,qBAAU,EAAC,GAAG,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,GAAG,OAAO,CA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I,EACJ;gBACE,SAAS;gBACT,KAAK;gBACL,mDAAmD;gBACnD,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,SAAS;gBAC9B,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,KAAK;gBACtB,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE;gBAChB,EAAE,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE;aACjB,EACD,CAAC,CACF;iBACA,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;gBAChB,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;YACjC,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACb,IAAA,gBAAS,EAAC,MAAM,EAAE,MAAM,EAAE,sBAAc,CAAC,aAAa,EAAE;oBACtD,KAAK;oBACL,SAAS,EAAE,KAAK;oBAChB,GAAG;iBACJ,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;SACL;IACH,CAAC,CAAC;SACD,KAAK,CAAC,GAAG,EAAE,CACV,IAAA,gBAAS,EAAC,MAAM,EAAE,MAAM,EAAE,sBAAc,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAClE,CAAA;IAEH,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAjFY,QAAA,eAAe,mBAiF3B"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMessage = void 0;
|
|
4
|
+
const functions_1 = require("../../functions");
|
|
5
|
+
const protocol_1 = require("../../protocol");
|
|
6
|
+
const observable_1 = require("../../observable");
|
|
7
|
+
const error_1 = require("../../error");
|
|
8
|
+
const send_1 = require("./send");
|
|
9
|
+
const sendGetData = (server, id, obs, checksum, client) => {
|
|
10
|
+
if (!client.ws) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (checksum === 0) {
|
|
14
|
+
client.ws.send(obs.cache, true, false);
|
|
15
|
+
}
|
|
16
|
+
else if (checksum === obs.checksum) {
|
|
17
|
+
client.ws.send((0, protocol_1.encodeGetResponse)(id), true, false);
|
|
18
|
+
}
|
|
19
|
+
else if (obs.diffCache && obs.previousChecksum === checksum) {
|
|
20
|
+
client.ws.send(obs.diffCache, true, false);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
client.ws.send(obs.cache, true, false);
|
|
24
|
+
}
|
|
25
|
+
if (obs.clients.size === 0) {
|
|
26
|
+
(0, observable_1.destroy)(server, id);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const getMessage = (arr, start, len, isDeflate, client, server) => {
|
|
30
|
+
// | 4 header | 8 id | 8 checksum | 1 name length | * name | * payload |
|
|
31
|
+
const nameLen = arr[start + 20];
|
|
32
|
+
const id = (0, protocol_1.readUint8)(arr, start + 4, 8);
|
|
33
|
+
const checksum = (0, protocol_1.readUint8)(arr, start + 12, 8);
|
|
34
|
+
const name = (0, protocol_1.decodeName)(arr, start + 21, start + 21 + nameLen);
|
|
35
|
+
if (!name || !id) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const route = server.functions.route(name);
|
|
39
|
+
if (!route || !route.observable) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (route.maxPayloadSize !== -1 && len > route.maxPayloadSize) {
|
|
43
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.PayloadTooLarge, route);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const payload = (0, protocol_1.decodePayload)(new Uint8Array(arr.slice(start + 21 + nameLen, start + len)), isDeflate);
|
|
47
|
+
server.auth
|
|
48
|
+
.authorize(client.ws, name, payload)
|
|
49
|
+
.then((ok) => {
|
|
50
|
+
if (!client.ws) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (!ok) {
|
|
54
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.AuthorizeRejectedError, route);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (server.activeObservablesById.has(id)) {
|
|
58
|
+
const obs = server.activeObservablesById.get(id);
|
|
59
|
+
if (obs.beingDestroyed) {
|
|
60
|
+
clearTimeout(obs.beingDestroyed);
|
|
61
|
+
obs.beingDestroyed = null;
|
|
62
|
+
}
|
|
63
|
+
if (obs.cache) {
|
|
64
|
+
sendGetData(server, id, obs, checksum, client);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
if (!obs.onNextData) {
|
|
68
|
+
obs.onNextData = new Set();
|
|
69
|
+
}
|
|
70
|
+
obs.onNextData.add(() => {
|
|
71
|
+
sendGetData(server, id, obs, checksum, client);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
server.functions
|
|
77
|
+
.install(name)
|
|
78
|
+
.then((spec) => {
|
|
79
|
+
if (spec && (0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
80
|
+
const obs = (0, observable_1.create)(server, name, id, payload);
|
|
81
|
+
if (!client.ws?.obs.has(id)) {
|
|
82
|
+
if (!obs.onNextData) {
|
|
83
|
+
obs.onNextData = new Set();
|
|
84
|
+
}
|
|
85
|
+
obs.onNextData.add(() => {
|
|
86
|
+
sendGetData(server, id, obs, checksum, client);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.FunctionNotFound, route);
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
.catch(() => {
|
|
95
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.FunctionNotFound, route);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
.catch((err) => {
|
|
100
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.AuthorizeFunctionError, {
|
|
101
|
+
route,
|
|
102
|
+
observableId: id,
|
|
103
|
+
err,
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
return true;
|
|
107
|
+
};
|
|
108
|
+
exports.getMessage = getMessage;
|
|
109
|
+
//# sourceMappingURL=get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../src/network/message/get.ts"],"names":[],"mappings":";;;AAAA,+CAA0D;AAC1D,6CAKuB;AAEvB,iDAAkD;AAElD,uCAA4C;AAC5C,iCAAkC;AAElC,MAAM,WAAW,GAAG,CAClB,MAAmB,EACnB,EAAU,EACV,GAAqB,EACrB,QAAgB,EAChB,MAAuB,EACvB,EAAE;IACF,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;QACd,OAAM;KACP;IAED,IAAI,QAAQ,KAAK,CAAC,EAAE;QAClB,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;KACvC;SAAM,IAAI,QAAQ,KAAK,GAAG,CAAC,QAAQ,EAAE;QACpC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,IAAA,4BAAiB,EAAC,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;KACnD;SAAM,IAAI,GAAG,CAAC,SAAS,IAAI,GAAG,CAAC,gBAAgB,KAAK,QAAQ,EAAE;QAC7D,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;KAC3C;SAAM;QACL,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;KACvC;IAED,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,EAAE;QAC1B,IAAA,oBAAO,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;KACpB;AACH,CAAC,CAAA;AAEM,MAAM,UAAU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,CAAC,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;wBAC3B,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE;4BACnB,GAAG,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAA;yBAC3B;wBACD,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE;4BACtB,WAAW,CAAC,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;wBAChD,CAAC,CAAC,CAAA;qBACH;iBACF;qBAAM;oBACL,IAAA,gBAAS,EAAC,MAAM,EAAE,MAAM,EAAE,sBAAc,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAA;iBAClE;YACH,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE;gBACV,IAAA,gBAAS,EAAC,MAAM,EAAE,MAAM,EAAE,sBAAc,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAA;YACnE,CAAC,CAAC,CAAA;SACL;IACH,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,IAAA,gBAAS,EAAC,MAAM,EAAE,MAAM,EAAE,sBAAc,CAAC,sBAAsB,EAAE;YAC/D,KAAK;YACL,YAAY,EAAE,EAAE;YAChB,GAAG;SACJ,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEJ,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAhGY,QAAA,UAAU,cAgGtB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.message = void 0;
|
|
4
|
+
const protocol_1 = require("../../protocol");
|
|
5
|
+
const function_1 = require("./function");
|
|
6
|
+
const observable_1 = require("./observable");
|
|
7
|
+
const auth_1 = require("./auth");
|
|
8
|
+
const get_1 = require("./get");
|
|
9
|
+
const error_1 = require("../../error");
|
|
10
|
+
const reader = (server, client, arr, start) => {
|
|
11
|
+
const { len, isDeflate, type } = (0, protocol_1.decodeHeader)((0, protocol_1.readUint8)(arr, start, 4));
|
|
12
|
+
const next = len + start;
|
|
13
|
+
// type 0 = function
|
|
14
|
+
if (type === 0 &&
|
|
15
|
+
(0, function_1.functionMessage)(arr, start, len, isDeflate, client, server)) {
|
|
16
|
+
return next;
|
|
17
|
+
}
|
|
18
|
+
// type 1 = subscribe
|
|
19
|
+
if (type === 1 &&
|
|
20
|
+
(0, observable_1.subscribeMessage)(arr, start, len, isDeflate, client, server)) {
|
|
21
|
+
return next;
|
|
22
|
+
}
|
|
23
|
+
// type 2 = unsubscribe
|
|
24
|
+
if (type === 2 && (0, observable_1.unsubscribeMessage)(arr, start, client, server)) {
|
|
25
|
+
return next;
|
|
26
|
+
}
|
|
27
|
+
// type 3 = get
|
|
28
|
+
if (type === 3 && (0, get_1.getMessage)(arr, start, len, isDeflate, client, server)) {
|
|
29
|
+
return next;
|
|
30
|
+
}
|
|
31
|
+
// type 4 = auth
|
|
32
|
+
if (type === 4 && (0, auth_1.authMessage)(arr, start, len, isDeflate, client, server)) {
|
|
33
|
+
return next;
|
|
34
|
+
}
|
|
35
|
+
// emit whats wrong
|
|
36
|
+
// console.warn('Unsupported incoming message with type', type)
|
|
37
|
+
};
|
|
38
|
+
const message = (server, client, msg, isBinary) => {
|
|
39
|
+
if (!client.ws) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (!isBinary) {
|
|
43
|
+
(0, error_1.createError)(server, client, error_1.BasedErrorCode.NoBinaryProtocol, msg);
|
|
44
|
+
client.ws.close();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// check if msg if empty (0) then it idle timeout
|
|
48
|
+
const uint8View = new Uint8Array(msg);
|
|
49
|
+
const len = uint8View.length;
|
|
50
|
+
let next = 0;
|
|
51
|
+
while (next < len) {
|
|
52
|
+
const n = reader(server, client, uint8View, next);
|
|
53
|
+
if (n === undefined) {
|
|
54
|
+
// Malformed message close client
|
|
55
|
+
client.ws.close();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
next = n;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.message = message;
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/network/message/index.ts"],"names":[],"mappings":";;;AACA,6CAAwD;AACxD,yCAA4C;AAC5C,6CAAmE;AACnE,iCAAoC;AACpC,+BAAkC;AAElC,uCAAyD;AAEzD,MAAM,MAAM,GAAG,CACb,MAAmB,EACnB,MAAuB,EACvB,GAAe,EACf,KAAa,EACL,EAAE;IACV,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,IAAA,uBAAY,EAAC,IAAA,oBAAS,EAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IACvE,MAAM,IAAI,GAAG,GAAG,GAAG,KAAK,CAAA;IAExB,oBAAoB;IACpB,IACE,IAAI,KAAK,CAAC;QACV,IAAA,0BAAe,EAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAC3D;QACA,OAAO,IAAI,CAAA;KACZ;IAED,qBAAqB;IACrB,IACE,IAAI,KAAK,CAAC;QACV,IAAA,6BAAgB,EAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAC5D;QACA,OAAO,IAAI,CAAA;KACZ;IAED,uBAAuB;IACvB,IAAI,IAAI,KAAK,CAAC,IAAI,IAAA,+BAAkB,EAAC,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QAChE,OAAO,IAAI,CAAA;KACZ;IAED,eAAe;IACf,IAAI,IAAI,KAAK,CAAC,IAAI,IAAA,gBAAU,EAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QACxE,OAAO,IAAI,CAAA;KACZ;IAED,gBAAgB;IAChB,IAAI,IAAI,KAAK,CAAC,IAAI,IAAA,kBAAW,EAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QACzE,OAAO,IAAI,CAAA;KACZ;IAED,mBAAmB;IACnB,+DAA+D;AACjE,CAAC,CAAA;AAEM,MAAM,OAAO,GAAG,CACrB,MAAmB,EACnB,MAAuB,EACvB,GAAgB,EAChB,QAAiB,EACjB,EAAE;IACF,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;QACd,OAAM;KACP;IAED,IAAI,CAAC,QAAQ,EAAE;QACb,IAAA,mBAAW,EAAC,MAAM,EAAE,MAAM,EAAE,sBAAc,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAA;QACjE,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;QACjB,OAAM;KACP;IAED,iDAAiD;IACjD,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;IACrC,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAA;IAC5B,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,OAAO,IAAI,GAAG,GAAG,EAAE;QACjB,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,CAAA;QACjD,IAAI,CAAC,KAAK,SAAS,EAAE;YACnB,iCAAiC;YACjC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAA;YACjB,OAAM;SACP;QACD,IAAI,GAAG,CAAC,CAAA;KACT;AACH,CAAC,CAAA;AA7BY,QAAA,OAAO,WA6BnB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BasedServer } from '../../server';
|
|
2
|
+
import { WebsocketClient, BasedFunctionRoute } from '../../types';
|
|
3
|
+
export declare const enableSubscribe: (server: BasedServer, client: WebsocketClient, id: number, checksum: number, name: string, payload: any, route: BasedFunctionRoute) => void;
|
|
4
|
+
export declare const subscribeMessage: (arr: Uint8Array, start: number, len: number, isDeflate: boolean, client: WebsocketClient, server: BasedServer) => boolean;
|
|
5
|
+
export declare const unsubscribeMessage: (arr: Uint8Array, start: number, client: WebsocketClient, server: BasedServer) => boolean;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unsubscribeMessage = exports.subscribeMessage = exports.enableSubscribe = void 0;
|
|
4
|
+
const functions_1 = require("../../functions");
|
|
5
|
+
const protocol_1 = require("../../protocol");
|
|
6
|
+
const observable_1 = require("../../observable");
|
|
7
|
+
const error_1 = require("../../error");
|
|
8
|
+
const send_1 = require("./send");
|
|
9
|
+
const enableSubscribe = (server, client, id, checksum, name, payload, route) => {
|
|
10
|
+
client.ws.subscribe(String(id));
|
|
11
|
+
client.ws.obs.add(id);
|
|
12
|
+
if (server.activeObservablesById.has(id)) {
|
|
13
|
+
(0, observable_1.subscribe)(server, id, checksum, client);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
server.functions
|
|
17
|
+
.install(name)
|
|
18
|
+
.then((spec) => {
|
|
19
|
+
if (spec && (0, functions_1.isObservableFunctionSpec)(spec)) {
|
|
20
|
+
const obs = (0, observable_1.create)(server, name, id, payload);
|
|
21
|
+
if (!client.ws?.obs.has(id)) {
|
|
22
|
+
if (obs.clients.size === 0) {
|
|
23
|
+
(0, observable_1.destroy)(server, id);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
(0, observable_1.subscribe)(server, id, checksum, client);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.FunctionNotFound, route);
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
.catch(() => {
|
|
35
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.FunctionNotFound, route);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.enableSubscribe = enableSubscribe;
|
|
40
|
+
const subscribeMessage = (arr, start, len, isDeflate, client, server) => {
|
|
41
|
+
// | 4 header | 8 id | 8 checksum | 1 name length | * name | * payload |
|
|
42
|
+
const nameLen = arr[start + 20];
|
|
43
|
+
const id = (0, protocol_1.readUint8)(arr, start + 4, 8);
|
|
44
|
+
const checksum = (0, protocol_1.readUint8)(arr, start + 12, 8);
|
|
45
|
+
const name = (0, protocol_1.decodeName)(arr, start + 21, start + 21 + nameLen);
|
|
46
|
+
if (!name || !id) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const route = server.functions.route(name);
|
|
50
|
+
if (!route || !route.observable) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (route.maxPayloadSize !== -1 && len > route.maxPayloadSize) {
|
|
54
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.PayloadTooLarge, route);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (client.ws?.obs.has(id)) {
|
|
58
|
+
// allready subscribed to this id
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
const payload = (0, protocol_1.decodePayload)(new Uint8Array(arr.slice(start + 21 + nameLen, start + len)), isDeflate);
|
|
62
|
+
server.auth
|
|
63
|
+
.authorize(client.ws, name, payload)
|
|
64
|
+
.then((ok) => {
|
|
65
|
+
if (!client.ws) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (!ok) {
|
|
69
|
+
client.ws.unauthorizedObs.add({ id, checksum, name, payload });
|
|
70
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.AuthorizeRejectedError, route);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
(0, exports.enableSubscribe)(server, client, id, checksum, name, payload, route);
|
|
74
|
+
})
|
|
75
|
+
.catch((err) => {
|
|
76
|
+
(0, send_1.sendError)(server, client, error_1.BasedErrorCode.AuthorizeFunctionError, {
|
|
77
|
+
route,
|
|
78
|
+
observableId: id,
|
|
79
|
+
err,
|
|
80
|
+
});
|
|
81
|
+
(0, observable_1.destroy)(server, id);
|
|
82
|
+
});
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
85
|
+
exports.subscribeMessage = subscribeMessage;
|
|
86
|
+
const unsubscribeMessage = (arr, start, client, server) => {
|
|
87
|
+
// | 4 header | 8 id |
|
|
88
|
+
const id = (0, protocol_1.readUint8)(arr, start + 4, 8);
|
|
89
|
+
if (!id) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (!client.ws) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!client.ws.obs.has(id)) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
client.ws.unsubscribe(String(id));
|
|
99
|
+
(0, observable_1.unsubscribe)(server, id, client);
|
|
100
|
+
return true;
|
|
101
|
+
};
|
|
102
|
+
exports.unsubscribeMessage = unsubscribeMessage;
|
|
103
|
+
//# sourceMappingURL=observable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observable.js","sourceRoot":"","sources":["../../../src/network/message/observable.ts"],"names":[],"mappings":";;;AAAA,+CAA0D;AAC1D,6CAAqE;AAErE,iDAA0E;AAC1E,uCAA4C;AAC5C,iCAAkC;AAG3B,MAAM,eAAe,GAAG,CAC7B,MAAmB,EACnB,MAAuB,EACvB,EAAU,EACV,QAAgB,EAChB,IAAY,EACZ,OAAY,EACZ,KAAyB,EACzB,EAAE;IACF,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;IAC/B,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAErB,IAAI,MAAM,CA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,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;IAEjC,IAAA,wBAAW,EAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;IAE/B,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AA3BY,QAAA,kBAAkB,sBA2B9B"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BasedErrorCode, ErrorPayload } from '../../error';
|
|
2
|
+
import { WebsocketClient } from '../../types';
|
|
3
|
+
import { BasedServer } from '../../server';
|
|
4
|
+
export declare const sendError: (server: BasedServer, client: WebsocketClient, basedCode: BasedErrorCode, err?: ErrorPayload[BasedErrorCode]) => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendError = void 0;
|
|
4
|
+
const protocol_1 = require("../../protocol");
|
|
5
|
+
const error_1 = require("../../error");
|
|
6
|
+
const sendError = (server, client, basedCode, err) => {
|
|
7
|
+
const errorData = (0, error_1.createError)(server, client, basedCode, err);
|
|
8
|
+
client.ws?.send((0, protocol_1.encodeErrorResponse)((0, protocol_1.valueToBuffer)(errorData)), true, false);
|
|
9
|
+
};
|
|
10
|
+
exports.sendError = sendError;
|
|
11
|
+
//# sourceMappingURL=send.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send.js","sourceRoot":"","sources":["../../../src/network/message/send.ts"],"names":[],"mappings":";;;AAAA,6CAAmE;AACnE,uCAAuE;AAIhE,MAAM,SAAS,GAAG,CACvB,MAAmB,EACnB,MAAuB,EACvB,SAAyB,EACzB,GAAkC,EAC5B,EAAE;IACR,MAAM,SAAS,GAAG,IAAA,mBAAW,EAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,CAAA;IAC7D,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,IAAA,8BAAmB,EAAC,IAAA,wBAAa,EAAC,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;AAC7E,CAAC,CAAA;AARY,QAAA,SAAS,aAQrB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import uws from '@based/uws';
|
|
2
|
+
import { AuthorizeConnection } from '../types';
|
|
3
|
+
export declare const upgrade: (res: uws.HttpResponse, req: uws.HttpRequest, ctx: uws.us_socket_context_t) => void;
|
|
4
|
+
export declare const upgradeAuthorize: (authorizeConnection: AuthorizeConnection, res: uws.HttpResponse, req: uws.HttpRequest, ctx: uws.us_socket_context_t) => void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.upgradeAuthorize = exports.upgrade = void 0;
|
|
4
|
+
let clientId = 0;
|
|
5
|
+
// const encoder = new TextEncoder()
|
|
6
|
+
const upgrade = (res, req,
|
|
7
|
+
// eslint-disable-next-line
|
|
8
|
+
ctx) => {
|
|
9
|
+
const query = req.getQuery(); // encode
|
|
10
|
+
const ua = req.getHeader('user-agent');
|
|
11
|
+
const ip = req.getHeader('x-forwarded-for') ||
|
|
12
|
+
Buffer.from(res.getRemoteAddressAsText()).toString();
|
|
13
|
+
const secWebSocketKey = req.getHeader('sec-websocket-key');
|
|
14
|
+
const secWebSocketProtocol = req.getHeader('sec-websocket-protocol');
|
|
15
|
+
const secWebSocketExtensions = req.getHeader('sec-websocket-extensions');
|
|
16
|
+
res.writeStatus('101 Switching Protocols');
|
|
17
|
+
res.upgrade({
|
|
18
|
+
query,
|
|
19
|
+
ua,
|
|
20
|
+
ip,
|
|
21
|
+
id: ++clientId,
|
|
22
|
+
obs: new Set(),
|
|
23
|
+
unauthorizedObs: new Set(),
|
|
24
|
+
headers: {}, // TODO: can add some extra headers here
|
|
25
|
+
}, secWebSocketKey, secWebSocketProtocol, secWebSocketExtensions, ctx);
|
|
26
|
+
};
|
|
27
|
+
exports.upgrade = upgrade;
|
|
28
|
+
const upgradeAuthorize = (authorizeConnection, res, req,
|
|
29
|
+
// eslint-disable-next-line
|
|
30
|
+
ctx) => {
|
|
31
|
+
let aborted = false;
|
|
32
|
+
res.onAborted(() => {
|
|
33
|
+
aborted = true;
|
|
34
|
+
});
|
|
35
|
+
authorizeConnection(req).then((authorized) => {
|
|
36
|
+
if (aborted) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (authorized) {
|
|
40
|
+
(0, exports.upgrade)(res, req, ctx);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
res.writeStatus('401 Unauthorized');
|
|
44
|
+
res.end();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
exports.upgradeAuthorize = upgradeAuthorize;
|
|
49
|
+
//# sourceMappingURL=upgrade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrade.js","sourceRoot":"","sources":["../../src/network/upgrade.ts"],"names":[],"mappings":";;;AAGA,IAAI,QAAQ,GAAG,CAAC,CAAA;AAEhB,oCAAoC;AAE7B,MAAM,OAAO,GAAG,CACrB,GAAqB,EACrB,GAAoB;AACpB,2BAA2B;AAC3B,GAA4B,EAC5B,EAAE;IACF,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAA,CAAC,SAAS;IACtC,MAAM,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;IAEtC,MAAM,EAAE,GACN,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAA;IACtD,MAAM,eAAe,GAAG,GAAG,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAA;IAC1D,MAAM,oBAAoB,GAAG,GAAG,CAAC,SAAS,CAAC,wBAAwB,CAAC,CAAA;IACpE,MAAM,sBAAsB,GAAG,GAAG,CAAC,SAAS,CAAC,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