From 47e8b52c2e24772bf4a9edeed79662d65de20a52 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sat, 23 Apr 2022 18:38:53 +0200 Subject: [PATCH 1/4] test(server): add IPv6 to multicast test --- test/server.ts | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/test/server.ts b/test/server.ts index 0a422a85..9772ab71 100644 --- a/test/server.ts +++ b/test/server.ts @@ -9,7 +9,7 @@ import { parse, generate } from 'coap-packet' import { nextPort } from './common' import { expect } from 'chai' -import { CoapPacket, Option } from '../models/models' +import { CoapPacket, CoapServerOptions, Option } from '../models/models' import { request, createServer } from '../index' import { createSocket } from 'dgram' import BufferListStream = require('bl') @@ -1000,22 +1000,37 @@ describe('server', function () { describe('multicast', function () { const port = nextPort() - it('receive CoAP message', function (done) { - const server = createServer({ - multicastAddress: '224.0.1.2' - }) + const testVector: Array = [ + { + addressType: 'IPv4', + multicastAddress: '224.0.1.2', + type: 'udp4' + }, + { + addressType: 'IPv6', + multicastAddress: 'ff02::fd', + type: 'udp6' + }] - server.listen(port) + testVector.forEach(({ addressType, multicastAddress, type }) => { + it(`receive ${addressType} CoAP message`, function (done) { + const server = createServer({ + multicastAddress, + type + }) - server.once('request', (req, res) => { - done() - }) + server.listen(port) - request({ - host: '224.0.1.2', - port: port, - multicast: true - }).end() + server.once('request', (req, res) => { + done() + }) + + request({ + host: multicastAddress, + port: port, + multicast: true + }).end() + }) }) }) }) From de6d0615a963a5dc048f0312aacb03183b5cdd29 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sat, 23 Apr 2022 19:35:04 +0200 Subject: [PATCH 2/4] fix: add workaround for IPv6 multicast addresses --- lib/server.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/server.ts b/lib/server.ts index 51678054..65743e68 100644 --- a/lib/server.ts +++ b/lib/server.ts @@ -259,7 +259,7 @@ class CoAPServer extends EventEmitter { multicastAddress, this._multicastInterface ) - } else { + } else if (this._options.type === 'udp4') { allAddresses(this._options.type).forEach(( _interface ) => { @@ -268,6 +268,10 @@ class CoAPServer extends EventEmitter { _interface ) }) + } else { + // FIXME: Iterating over all network interfaces does not + // work for IPv6 at the moment + sock.addMembership(multicastAddress) } } } catch (err) { From d62aa8b6e72c5084859dc44e570500ab680265b3 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sat, 23 Apr 2022 19:59:18 +0200 Subject: [PATCH 3/4] test: skip IPv6 multicast test on macos --- test/server.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/server.ts b/test/server.ts index 9772ab71..1a9f1f89 100644 --- a/test/server.ts +++ b/test/server.ts @@ -1014,6 +1014,12 @@ describe('server', function () { testVector.forEach(({ addressType, multicastAddress, type }) => { it(`receive ${addressType} CoAP message`, function (done) { + if (addressType === 'IPv6' && process.platform === 'darwin') { + // FIXME: IPv6 multicast seems to have problems on macos + // at the moment + this.skip() + } + const server = createServer({ multicastAddress, type From 0b7bde13480d6415df78a9a816966d19671d98f7 Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Sat, 23 Apr 2022 22:43:54 +0200 Subject: [PATCH 4/4] chore: bump version to 1.0.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 676f9b1e..4da02453 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coap", - "version": "1.0.6", + "version": "1.0.7", "description": "A CoAP library for node modelled after 'http'", "main": "dist/index.js", "types": "dist/index.d.ts",