farhadi / farhadi/node-smpp

crashes when trying to forward UDH

Open
#161 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
435
Forks
194
PR merge metrics
No merged PRs in 30d

Description

For testing purposes, I created a transparent smpp proxy. socket A <-> (PDU) <-> socket B.
Here is part of simplest code:
```javascript
a.on("pdu", pdu => {
console.log("->", pdu);

// Inverse message_id to prevent message_id dublicates
if (pdu.message_id) pdu.message_id = inverse(pdu.message_id);

// Forward PDU
console.log("<-", pdu);
b.send(pdu);
});
```
Everything works fine, but sometimes these death messages happen:
console.log output:
```log
-> PDU {
command_length: 83,
command_id: 4,
command_status: 0,
sequence_number: 16704908,
command: 'submit_sm',
service_type: '',
source_addr_ton: 5,
source_addr_npi: 0,
source_addr: 'aaaa',
dest_addr_ton: 1,
dest_addr_npi: 1,
destination_addr: '0000',
esm_class: 64,
protocol_id: 0,
priority_flag: 0,
schedule_delivery_time: '',
validity_period: 2021-01-16T15:32:33.000Z,
registered_delivery: 1,
replace_if_present_flag: 0,
data_coding: 8,
sm_default_msg_id: 0,
short_message: { udh: [ ], message: 'nutes.' }
}
<- PDU {
command_length: 83,
command_id: 4,
command_status: 0,
sequence_number: 16704908,
command: 'submit_sm',
service_type: '',
source_addr_ton: 5,
source_addr_npi: 0,
source_addr: 'aaaa',
dest_addr_ton: 1,
dest_addr_npi: 1,
destination_addr: '0000',
esm_class: 64,
protocol_id: 0,
priority_flag: 0,
schedule_delivery_time: '',
validity_period: 2021-01-16T15:32:33.000Z,
registered_delivery: 1,
replace_if_present_flag: 0,
data_coding: 8,
sm_default_msg_id: 0,
short_message: { udh: [ ], message: 'nutes.' }
}
TypeError [ERR_INVALID_ARG_TYPE]: The "list[0]" argument must be an instance of Buffer or Uint8Array. Received an instance of Array
at Object.concat (buffer.js:574:13)
at PDU.encode (/devel/smpp-tools/node_modules/smpp/lib/defs.js:545:17)
at PDU._filter (/devel/smpp-tools/node_modules/smpp/lib/pdu.js:144:41)
at PDU.toBuffer (/devel/smpp-tools/node_modules/smpp/lib/pdu.js:177:7)
at Session.send (/devel/smpp-tools/node_modules/smpp/lib/smpp.js:119:24)
at Session. (/devel/smpp-tools/proxy.js:90:11)
at Session.emit (events.js:315:20)
at Session._extractPDUs (/devel/smpp-tools/node_modules/smpp/lib/smpp.js:88:8)
at Socket.emit (events.js:315:20)
at emitReadable_ (_stream_readable.js:569:12) {
code: 'ERR_INVALID_ARG_TYPE'
}
```
It looks like not correctly decoded-encoded message body.
Here is my ugly workaround preventing proxy from crash but we lost a part of message:
```javascript
a.on("pdu", pdu => {
console.log("->", pdu);

// Inverse message_id to prevent message_id dublicates
if (pdu.message_id) pdu.message_id = inverse(pdu.message_id);

// Ugly workaround
for (let key in pdu.short_message) {
if (key !== "message") delete pdu.short_message[key];
}

// Forward PDU
console.log("<-", pdu);
b.send(pdu);
});
```
I would like to understand the problem, but manipulations with message encoding-decoding are confusing.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.