Skip to content

hotfix-for-234c: Improve NetMessage create-from-object handling #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# git config --global core.excludesfile ~/.gitignore

# NetCreate ignored directories
/app-data/*
/runtime
netcreate-config.js

Expand Down
1 change: 1 addition & 0 deletions app/unisys/common-netmessage-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class NetMessage {
if (typeof msg === 'object' && data === undefined) {
// make sure it has a msg and data obj
if (typeof msg.msg !== 'string' || typeof msg.data !== 'object') {
console.log('bad message object', JSON.stringify(msg));
throw ERR_NOT_NETMESG;
}
// merge properties into this new class instance and return it
Expand Down
36 changes: 20 additions & 16 deletions app/unisys/server-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,24 @@ function m_SocketMessage(socket, json) {
m_ResetPongTimer(socket.UADDR);
return;
}

let pkt = new NetMessage(json);
// figure out what to do
switch (pkt.Type()) {
case 'state':
m_HandleState(socket, pkt);
break;
case 'msig':
case 'msend':
case 'mcall':
m_HandleMessage(socket, pkt);
break;
default:
throw new Error(`${PR} unknown packet type '${pkt.Type()}'`);
} // end switch
try {
let pkt = new NetMessage(json);
// figure out what to do
switch (pkt.Type()) {
case 'state':
m_HandleState(socket, pkt);
break;
case 'msig':
case 'msend':
case 'mcall':
m_HandleMessage(socket, pkt);
break;
default:
throw new Error(`${PR} unknown packet type '${pkt.Type()}'`);
} // end switch
} catch (err) {
console.error(PR, 'm_SocketMessage try:', err);
}
} // end m_SocketMessage()
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/** handle global state and rebroadcast
Expand Down Expand Up @@ -454,7 +457,8 @@ function m_PromiseRemoteHandlers(pkt) {
if (verbose) {
console.log(
'make_resolver_func:',
`PKT: ${srcPkt.Type()} '${srcPkt.Message()}' from ${srcPkt.Info()} to d_uaddr:${d_uaddr} dispatch to d_sock.UADDR:${d_sock.UADDR
`PKT: ${srcPkt.Type()} '${srcPkt.Message()}' from ${srcPkt.Info()} to d_uaddr:${d_uaddr} dispatch to d_sock.UADDR:${
d_sock.UADDR
}`
);
}
Expand Down