Skip to content

Commit babb3a3

Browse files
authored
Merge pull request #246 from netcreateorg/hotfix-for-234c
hotfix-for-234c: Improve NetMessage create-from-object handling
2 parents ec7dff0 + 05cb45d commit babb3a3

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# git config --global core.excludesfile ~/.gitignore
77

88
# NetCreate ignored directories
9+
/app-data/*
910
/runtime
1011
netcreate-config.js
1112

app/unisys/common-netmessage-class.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class NetMessage {
6262
if (typeof msg === 'object' && data === undefined) {
6363
// make sure it has a msg and data obj
6464
if (typeof msg.msg !== 'string' || typeof msg.data !== 'object') {
65+
console.log('bad message object', JSON.stringify(msg));
6566
throw ERR_NOT_NETMESG;
6667
}
6768
// merge properties into this new class instance and return it

app/unisys/server-network.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -290,21 +290,24 @@ function m_SocketMessage(socket, json) {
290290
m_ResetPongTimer(socket.UADDR);
291291
return;
292292
}
293-
294-
let pkt = new NetMessage(json);
295-
// figure out what to do
296-
switch (pkt.Type()) {
297-
case 'state':
298-
m_HandleState(socket, pkt);
299-
break;
300-
case 'msig':
301-
case 'msend':
302-
case 'mcall':
303-
m_HandleMessage(socket, pkt);
304-
break;
305-
default:
306-
throw new Error(`${PR} unknown packet type '${pkt.Type()}'`);
307-
} // end switch
293+
try {
294+
let pkt = new NetMessage(json);
295+
// figure out what to do
296+
switch (pkt.Type()) {
297+
case 'state':
298+
m_HandleState(socket, pkt);
299+
break;
300+
case 'msig':
301+
case 'msend':
302+
case 'mcall':
303+
m_HandleMessage(socket, pkt);
304+
break;
305+
default:
306+
throw new Error(`${PR} unknown packet type '${pkt.Type()}'`);
307+
} // end switch
308+
} catch (err) {
309+
console.error(PR, 'm_SocketMessage try:', err);
310+
}
308311
} // end m_SocketMessage()
309312
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
310313
/** handle global state and rebroadcast
@@ -454,7 +457,8 @@ function m_PromiseRemoteHandlers(pkt) {
454457
if (verbose) {
455458
console.log(
456459
'make_resolver_func:',
457-
`PKT: ${srcPkt.Type()} '${srcPkt.Message()}' from ${srcPkt.Info()} to d_uaddr:${d_uaddr} dispatch to d_sock.UADDR:${d_sock.UADDR
460+
`PKT: ${srcPkt.Type()} '${srcPkt.Message()}' from ${srcPkt.Info()} to d_uaddr:${d_uaddr} dispatch to d_sock.UADDR:${
461+
d_sock.UADDR
458462
}`
459463
);
460464
}

0 commit comments

Comments
 (0)