From 8f06071ee16dbf815f14dc67acd9925ef1559da6 Mon Sep 17 00:00:00 2001 From: Emile Nijssen Date: Mon, 20 Apr 2020 16:20:43 +0200 Subject: [PATCH 1/2] Add underscore to allowed service type names --- lib/service_type.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/service_type.js b/lib/service_type.js index bc726217..46b567d2 100644 --- a/lib/service_type.js +++ b/lib/service_type.js @@ -151,7 +151,7 @@ function isProtocol(str) { function _u(str) { return "_" + str; } function _uu(str) { return str[0] === '_' ? str.substr(1) : str; } -var charset_regex = /[^-a-zA-Z0-9]/; +var charset_regex = /[^-_a-zA-Z0-9]/; function checkLengthAndCharset(str) { if (str.length === 0) { throw new Error('type ' + str + ' must not be empty'); From 44601738f8eb1b398fb264d39b4735b695b15a99 Mon Sep 17 00:00:00 2001 From: Robin Bolscher Date: Wed, 21 Feb 2024 17:00:12 +0100 Subject: [PATCH 2/2] fix: increase `service_name` limit from 15 to 20 chars --- lib/service_type.js | 9 +++++---- test.js | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 test.js diff --git a/lib/service_type.js b/lib/service_type.js index 46b567d2..c485e76a 100644 --- a/lib/service_type.js +++ b/lib/service_type.js @@ -156,8 +156,8 @@ function checkLengthAndCharset(str) { if (str.length === 0) { throw new Error('type ' + str + ' must not be empty'); } - if (str.length > 15) { - throw new Error('type ' + str + ' has more than 15 characters'); + if (str.length > 20) { // Note: this is not according to spec (https://github.com/agnat/node_mdns/issues/264) + throw new Error('type ' + str + ' has more than 20 characters'); } if (str.match(charset_regex)) { throw new Error('type ' + str + ' may only contain alphanumeric ' + @@ -170,8 +170,9 @@ function checkFormat(str) { if (str.length === 0) { throw new Error('type string must not be empty'); } - if (str.length > 16) { // 16 is correct because we have a leading underscore - throw new Error('type ' + _uu(str) + ' has more than 15 characters'); + // 21 is correct because we have a leading underscore + if (str.length > 21) { // Note: this is not according to spec (https://github.com/agnat/node_mdns/issues/264) + throw new Error('type ' + _uu(str) + ' has more than 20 characters'); } if ( ! str.match(format_regex)) { throw new Error('type ' + str + ' must start with an underscore ' + diff --git a/test.js b/test.js new file mode 100644 index 00000000..7946a257 --- /dev/null +++ b/test.js @@ -0,0 +1,24 @@ +// import the module +const mdns = require('./'); + +// advertise a http server on port 4321 +// const ad = mdns.createAdvertisement(mdns.tcp('http'), 4321); +// ad.start(); + +// watch all http servers +const browser = mdns.createBrowser( + new mdns.ServiceType({ + name: 'androidtvremote2', + protocol: 'tcp', + }), +); +browser.on('serviceUp', service => { + console.log("service up: ", service); +}); +browser.on('serviceDown', service => { + console.log("service down: ", service); +}); +browser.start(); + +// discover all available service types +const all_the_types = mdns.browseThemAll(); // all_the_types is just another browser...