tlsd 2.11.2 → 2.12.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/package.json +1 -1
- package/tlsd.js +21 -17
- /package/scaffold/rpc/{index.js → index.cjs} +0 -0
package/package.json
CHANGED
package/tlsd.js
CHANGED
|
@@ -44,7 +44,11 @@ function next_seq() {
|
|
|
44
44
|
|
|
45
45
|
// Handles incoming RPC msgs.
|
|
46
46
|
// Tries to load the rpc handler module from root and if successful, passes the msg to it
|
|
47
|
-
|
|
47
|
+
// transport =
|
|
48
|
+
// { type: "WS", connection: { ... } }
|
|
49
|
+
// { type: "GET", connection: { req, res } }
|
|
50
|
+
// { type: "POST", connection: { req, res } }
|
|
51
|
+
function rpc_handler( root, msg, transport, _okay, _fail ) {
|
|
48
52
|
|
|
49
53
|
let ll = toInt( msg.log_level );
|
|
50
54
|
if( ll > 0 ) {
|
|
@@ -60,15 +64,15 @@ function rpc_handler( root, msg, xport, _okay, _fail ) {
|
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
V( "RPC " + o2j( msg ).abbr( 70 ) );
|
|
63
|
-
D( "----------->>> "+
|
|
67
|
+
D( "----------->>> "+transport.type+" "+o2j( msg, null, 2 ) );
|
|
64
68
|
|
|
65
69
|
const okay = data => {
|
|
66
|
-
D( "<<<=========== "+
|
|
70
|
+
D( "<<<=========== "+transport.type+" OKAY "+o2j( data, null, 2 ) );
|
|
67
71
|
_okay( data );
|
|
68
72
|
};
|
|
69
73
|
|
|
70
74
|
const fail = error => {
|
|
71
|
-
D( "<<<*********** "+
|
|
75
|
+
D( "<<<*********** "+transport.type+" ERROR "+o2j( error, null, 2 ) );
|
|
72
76
|
_fail( error );
|
|
73
77
|
};
|
|
74
78
|
|
|
@@ -78,9 +82,9 @@ function rpc_handler( root, msg, xport, _okay, _fail ) {
|
|
|
78
82
|
};
|
|
79
83
|
|
|
80
84
|
try {
|
|
81
|
-
const mod = require( root + "/rpc" );
|
|
85
|
+
const mod = require( root + "/rpc/index.cjs" );
|
|
82
86
|
try {
|
|
83
|
-
mod( msg, okay, ouch );
|
|
87
|
+
mod( msg, okay, ouch, transport );
|
|
84
88
|
} catch( err ) {
|
|
85
89
|
E( (err instanceof Error ) ? err.stack : err );
|
|
86
90
|
ouch( "RPC handler exception" );
|
|
@@ -94,8 +98,8 @@ function rpc_handler( root, msg, xport, _okay, _fail ) {
|
|
|
94
98
|
|
|
95
99
|
// Glue function to call rpc handler module and then return response
|
|
96
100
|
// via the websockets msg object
|
|
97
|
-
function ws_msg_handler( root, msg ) {
|
|
98
|
-
rpc_handler( root, msg.msg, "WS", data => {
|
|
101
|
+
function ws_msg_handler( root, msg, connection ) {
|
|
102
|
+
rpc_handler( root, msg.msg, { type: "WS", connection }, data => {
|
|
99
103
|
msg.reply( data );
|
|
100
104
|
}, error => {
|
|
101
105
|
msg.error( { error } );
|
|
@@ -161,7 +165,7 @@ function rpc_post( root ) {
|
|
|
161
165
|
const fail = ( error, body ) => { done( error, body ); };
|
|
162
166
|
|
|
163
167
|
// Summon the rpc handler for the domain root.
|
|
164
|
-
rpc_handler( root, input,
|
|
168
|
+
rpc_handler( root, input, { type: method, connection: { req, res, } } , okay, fail );
|
|
165
169
|
};
|
|
166
170
|
}
|
|
167
171
|
|
|
@@ -252,7 +256,7 @@ function rest_handler( root, req, rsp ) {
|
|
|
252
256
|
|
|
253
257
|
|
|
254
258
|
// tracked websocket connections
|
|
255
|
-
const ws_connections = {};
|
|
259
|
+
//const ws_connections = {};
|
|
256
260
|
|
|
257
261
|
|
|
258
262
|
// Associate a websocket message handler (msg_handler) to a webserver instance (server)
|
|
@@ -270,7 +274,7 @@ function ws_attach( server, msg_handler ) {
|
|
|
270
274
|
const name = "ws-conn-"+next_seq(); // XXX just use the websocket id
|
|
271
275
|
|
|
272
276
|
// send msg to connected client
|
|
273
|
-
const send = function( msg
|
|
277
|
+
const send = function( msg, cb ) {
|
|
274
278
|
if( msg.msg_id === undefined ) {
|
|
275
279
|
msg.msg_id = "msg-id-" + next_seq(); // every message must have an id
|
|
276
280
|
}
|
|
@@ -286,7 +290,7 @@ function ws_attach( server, msg_handler ) {
|
|
|
286
290
|
|
|
287
291
|
socket.on("close", function() {
|
|
288
292
|
D( "WS: disconnect" );
|
|
289
|
-
delete ws_connections[ name ]; // remove from tracked connections
|
|
293
|
+
//delete ws_connections[ name ]; // remove from tracked connections
|
|
290
294
|
});
|
|
291
295
|
|
|
292
296
|
// incoming msgs from client come through here
|
|
@@ -318,7 +322,7 @@ function ws_attach( server, msg_handler ) {
|
|
|
318
322
|
|
|
319
323
|
D( "WS: connected: "+name );
|
|
320
324
|
|
|
321
|
-
ws_connections[ name ] = conn; // add to tracked connections
|
|
325
|
+
//ws_connections[ name ] = conn; // add to tracked connections
|
|
322
326
|
|
|
323
327
|
} );
|
|
324
328
|
|
|
@@ -354,9 +358,9 @@ if( argv.length == 2 ) {
|
|
|
354
358
|
|
|
355
359
|
var server = glx.httpsServer();
|
|
356
360
|
|
|
357
|
-
ws_attach( server, ( msg,
|
|
361
|
+
ws_attach( server, ( msg, connection, domain ) => {
|
|
358
362
|
const root = path.resolve( DOMAINS_ROOT + "/" + domain );
|
|
359
|
-
ws_msg_handler( root, msg );
|
|
363
|
+
ws_msg_handler( root, msg, connection );
|
|
360
364
|
} );
|
|
361
365
|
|
|
362
366
|
glx.serveApp( ( req, res ) => {
|
|
@@ -392,8 +396,8 @@ if( argv.length == 5 ) {
|
|
|
392
396
|
rest_handler( SITE_ROOT, req, res );
|
|
393
397
|
} );
|
|
394
398
|
|
|
395
|
-
ws_attach( server, ( msg,
|
|
396
|
-
ws_msg_handler( SITE_ROOT, msg );
|
|
399
|
+
ws_attach( server, ( msg, connection, domain ) => {
|
|
400
|
+
ws_msg_handler( SITE_ROOT, msg, connection );
|
|
397
401
|
} );
|
|
398
402
|
|
|
399
403
|
server.listen( toInt( PORT ), () => {
|
|
File without changes
|