Skip to content

Commit

Permalink
Tolerate port numbers up to double the range shown in a 'G' response.
Browse files Browse the repository at this point in the history
This works around wb2osz/direwolf#515
  • Loading branch information
jmkristian committed Jun 11, 2024
1 parent 8d6ab3e commit 7a49dc4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
13 changes: 6 additions & 7 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const Stream = require('stream');

const newError = guts.newError;
const validateCallSign = guts.validateCallSign;
const validatePort = guts.validatePort;

class RouterShim {
constructor(port, throttle, connection, connectListener) {
Expand All @@ -21,10 +20,10 @@ class RouterShim {
case 'G': // ports
try {
const numberOfPorts = parseInt(frame.data.toString('ascii').split(/;/)[0]);
if (this.port >= numberOfPorts) {
this.connection.emit('error', newError(
`The TNC has no port ${this.port}`,
'ERR_INVALID_ARG_VALUE'));
if (this.port >= numberOfPorts * 2) {
// Multiplying * 2 works around https://github.com/wb2osz/direwolf/issues/515
this.connection.emit('error', guts.newRangeError(
`The TNC has no port ${this.port}.`, 'ENOENT'));
}
} catch(err) {
this.connection.emit('error', err);
Expand Down Expand Up @@ -57,12 +56,12 @@ function createConnection(options, connectListener) {
ID: options.ID,
logger: options.logger,
};
const localPort = validatePort(options.localPort);
const localPort = guts.validatePort(options.localPort || 0);
const localAddress = validateCallSign('local', options.localAddress);
const remoteAddress = validateCallSign('remote', options.remoteAddress);
const via = guts.validatePath(options.via);
const connectFrame = {
port: localPort || 0,
port: localPort,
callTo: localAddress,
callFrom: remoteAddress,
};
Expand Down
5 changes: 3 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,9 @@ class Server extends EventEmitter {
mergeOptions(options, {logger: null}),
typeof callback);
const localPort = guts.validatePort(options.localPort || 0);
if (localPort >= this.ports.length) {
throw guts.newRangeError(`There is no port ${localPort}.`, 'ENOENT');
if (localPort >= this.ports.length * 2) {
// Multiplying * 2 works around https://github.com/wb2osz/direwolf/issues/515
throw guts.newRangeError(`The TNC has no port ${localPort}.`, 'ENOENT');
}
const localAddress = guts.validateCallSign('local', options.localAddress);
const remoteAddress = guts.validateCallSign('remote', options.remoteAddress);
Expand Down

0 comments on commit 7a49dc4

Please sign in to comment.