@camstack/server 1.2.731 → 1.2.733
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/api/core/cap-providers.js +1 -0
- package/dist/api/core/logging-settings.js +88 -1
- package/dist/api/trpc/generated-cap-routers.js +49 -0
- package/dist/core/addon/addon-registry.service.js +61 -59
- package/package.json +11 -19
- package/system/dist/addon-runner.js +1 -0
- package/system/dist/addon-runner.mjs +2 -1
- package/system/dist/addon-utils.mjs +1 -1
- package/system/dist/{agent-https-AJPmB73W.mjs → agent-https-D3dptveB.mjs} +1 -1
- package/system/dist/{agent-https-CLJhq0GZ.js → agent-https-v5uyVgpk.js} +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +4 -4
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +5 -5
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +5 -5
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +1 -1
- package/system/dist/builtins/camera-grid/index.mjs +1 -1
- package/system/dist/builtins/composer/composer.addon.js +3 -3
- package/system/dist/builtins/composer/composer.addon.mjs +3 -3
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +2 -2
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +2 -2
- package/system/dist/builtins/device-history/device-history.addon.js +2 -2
- package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
- package/system/dist/builtins/device-manager/device-manager.addon.js +220 -16
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +220 -16
- package/system/dist/builtins/device-manager/discovery-proposal-service.d.ts +38 -0
- package/system/dist/builtins/device-manager/discovery-proposal-store.d.ts +28 -0
- package/system/dist/builtins/device-manager/record-kinds.d.ts +2 -1
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +3 -3
- package/system/dist/builtins/keychain/index.mjs +3 -3
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +5 -5
- package/system/dist/builtins/local-network/local-network.addon.d.ts +10 -0
- package/system/dist/builtins/local-network/local-network.addon.js +297 -190
- package/system/dist/builtins/local-network/local-network.addon.mjs +294 -187
- package/system/dist/builtins/local-network/passive/discovery-watcher.d.ts +60 -0
- package/system/dist/builtins/local-network/passive/passive-io-node.d.ts +2 -0
- package/system/dist/builtins/local-network/passive/passive-packets.d.ts +10 -0
- package/system/dist/builtins/local-network/scan/dns-wire.d.ts +6 -2
- package/system/dist/builtins/local-network/scan/scan-engine.d.ts +1 -1
- package/system/dist/builtins/local-network/scan/scan-io.d.ts +6 -0
- package/system/dist/builtins/loki-logging/index.js +1 -1
- package/system/dist/builtins/loki-logging/index.mjs +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +10 -10
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +10 -10
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +20 -20
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +2 -2
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +2 -2
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +115 -115
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{composition-sources-D-S2hhdw.mjs → composition-sources-Dnyu7-1p.mjs} +1 -1
- package/system/dist/{composition-sources-BNBlJAgu.js → composition-sources-j_bFq7Tx.js} +1 -1
- package/system/dist/{constants-CKwdQTnw.js → constants-C6zJ_38f.js} +1 -1
- package/system/dist/{constants-DmithOex.mjs → constants-GDBin8zB.mjs} +1 -1
- package/system/dist/{coral-accelerators-BW3OcrLD.mjs → coral-accelerators-DBlgWB8k.mjs} +6 -6
- package/system/dist/{custom-action-registry-BIJZBObd.mjs → custom-action-registry-oHl1xltx.mjs} +37 -37
- package/system/dist/{device-ca-D-Cvxobt.mjs → device-ca-Bpqrad00.mjs} +1 -1
- package/system/dist/{device-ca-TbdQfW4d.js → device-ca-CV9QZvoy.js} +1 -1
- package/system/dist/{dist-dQKZfa3-.js → dist-CwYYyGAB.js} +227 -3
- package/system/dist/{dist-yrk6fm65.mjs → dist-DcHvuBfD.mjs} +210 -4
- package/system/dist/dns-wire-CqgMi_uB.js +202 -0
- package/system/dist/dns-wire-DO56tOHL.mjs +173 -0
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-mdns-ciao-Cae5VWUc.mjs → hub-mdns-ciao-D2sU6sKd.mjs} +2 -2
- package/system/dist/{hub-mdns-ciao-DP3_GNZw.js → hub-mdns-ciao-DNLnbJNG.js} +2 -2
- package/system/dist/index.js +24 -7
- package/system/dist/index.mjs +236 -219
- package/system/dist/{restore-archive-BJ5gxMvf.mjs → restore-archive-BGK6EnYj.mjs} +94 -94
- package/system/dist/{restore-archive-X9c_wEBY.js → restore-archive-xTqhDFkW.js} +1 -1
- package/system/dist/{retention-DBrdAv12.mjs → retention-CXu8PB2L.mjs} +1 -1
- package/system/dist/{retention-DRT2wUyB.js → retention-gQ3GIUA3.js} +1 -1
- package/system/dist/{wal-maintenance-Bi4yImEY.mjs → wal-maintenance-D7XmFaUD.mjs} +0 -0
- package/system/dist/{wal-maintenance-hsgNGrjh.js → wal-maintenance-Hwzm3DCe.js} +0 -0
- package/system/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Ar as isAppLinkBase, Dn as checkRoleAddress, Et as NetworkTunnelStartedDataSchema, Gi as resolveNotificationTapAddress, Kr as localNetworkCapability, Ks as errMsg, Li as resolveAppConnections, Pr as isDefaultAppConnectionEndpoint, Vi as resolveHubAddressRoles, _ as CAMSTACK_APP_LINK_ORIGIN, do as BaseAddon, dt as HUB_MDNS_TXT_KEYS, ia as shortHostname, qs as EventCategory, ut as HUB_MDNS_SERVICE_TYPE, wa as validateCustomAddress, xi as pickAppLinkHub } from "../../dist-DcHvuBfD.mjs";
|
|
2
|
+
import { a as parseMdnsMessage, i as normalizeServiceType, n as MDNS_PORT, r as buildPtrQuery, t as MDNS_GROUP } from "../../dns-wire-DO56tOHL.mjs";
|
|
3
|
+
import { E as ensureTlsCert, I as readLanHttpState, N as applyLanHttp, _ as readTlsMode, a as storeUploadedCertificate, b as writeTlsEnabled, d as servedHttpsLeafFingerprint, h as readTlsAccessStatus, i as revertToGeneratedCertificate, j as DEFAULT_LAN_HTTP_PORT, m as readExtraSans, n as applyCertificateToListener, o as useStoredUploadedCertificate, r as regenerateCertificate, t as createCiaoPublisher, y as writeExtraSans } from "../../hub-mdns-ciao-D2sU6sKd.mjs";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
import { isIP } from "node:net";
|
|
5
6
|
import * as os$1 from "node:os";
|
|
@@ -567,175 +568,6 @@ function parseLocalHostname(raw) {
|
|
|
567
568
|
};
|
|
568
569
|
}
|
|
569
570
|
//#endregion
|
|
570
|
-
//#region src/builtins/local-network/scan/dns-wire.ts
|
|
571
|
-
/**
|
|
572
|
-
* DNS-SD wire format for the scan engine: one PTR question per service type,
|
|
573
|
-
* and a parser that turns an answer into services (instance, host, port, TXT).
|
|
574
|
-
*/
|
|
575
|
-
/** Top bit of the question class: ask for a unicast reply (RFC 6762). */
|
|
576
|
-
var MDNS_QU_CLASS = 32769;
|
|
577
|
-
var A = 1;
|
|
578
|
-
var PTR = 12;
|
|
579
|
-
var TXT = 16;
|
|
580
|
-
var SRV = 33;
|
|
581
|
-
var SRV_FIXED = 6;
|
|
582
|
-
var MAX_NAME_HOPS = 16;
|
|
583
|
-
var MDNS_PORT = 5353;
|
|
584
|
-
var MDNS_GROUP = "224.0.0.251";
|
|
585
|
-
/** `_esphomelib._tcp` and `_esphomelib._tcp.local.` name the same service. */
|
|
586
|
-
function normalizeServiceType(serviceType) {
|
|
587
|
-
const lower = serviceType.trim().toLowerCase().replace(/\.$/, "");
|
|
588
|
-
return lower.endsWith(".local") ? lower.slice(0, -6) : lower;
|
|
589
|
-
}
|
|
590
|
-
function readName(buf, start) {
|
|
591
|
-
const labels = [];
|
|
592
|
-
let pos = start;
|
|
593
|
-
let end = start;
|
|
594
|
-
let jumped = false;
|
|
595
|
-
for (let hops = 0; hops < MAX_NAME_HOPS; hops++) {
|
|
596
|
-
if (pos < 0 || pos >= buf.length) return null;
|
|
597
|
-
const len = buf[pos] ?? 0;
|
|
598
|
-
if (len === 0) {
|
|
599
|
-
if (!jumped) end = pos + 1;
|
|
600
|
-
return {
|
|
601
|
-
name: labels.join("."),
|
|
602
|
-
end
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
if ((len & 192) === 192) {
|
|
606
|
-
if (pos + 1 >= buf.length) return null;
|
|
607
|
-
if (!jumped) end = pos + 2;
|
|
608
|
-
jumped = true;
|
|
609
|
-
pos = (len & 63) << 8 | (buf[pos + 1] ?? 0);
|
|
610
|
-
continue;
|
|
611
|
-
}
|
|
612
|
-
if ((len & 192) !== 0 || pos + 1 + len > buf.length) return null;
|
|
613
|
-
labels.push(buf.subarray(pos + 1, pos + 1 + len).toString("utf8"));
|
|
614
|
-
pos += 1 + len;
|
|
615
|
-
if (!jumped) end = pos;
|
|
616
|
-
}
|
|
617
|
-
return null;
|
|
618
|
-
}
|
|
619
|
-
function readRecords(buf, offset, count) {
|
|
620
|
-
const records = [];
|
|
621
|
-
let pos = offset;
|
|
622
|
-
for (let i = 0; i < count; i++) {
|
|
623
|
-
const name = readName(buf, pos);
|
|
624
|
-
if (name === null || name.end + 10 > buf.length) return null;
|
|
625
|
-
const type = buf.readUInt16BE(name.end);
|
|
626
|
-
const dataLength = buf.readUInt16BE(name.end + 8);
|
|
627
|
-
const dataOffset = name.end + 10;
|
|
628
|
-
if (dataOffset + dataLength > buf.length) return null;
|
|
629
|
-
records.push({
|
|
630
|
-
name: name.name,
|
|
631
|
-
type,
|
|
632
|
-
dataOffset,
|
|
633
|
-
dataLength
|
|
634
|
-
});
|
|
635
|
-
pos = dataOffset + dataLength;
|
|
636
|
-
}
|
|
637
|
-
return {
|
|
638
|
-
records,
|
|
639
|
-
next: pos
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
function parseTxt(buf, offset, length) {
|
|
643
|
-
const out = {};
|
|
644
|
-
let pos = offset;
|
|
645
|
-
const end = offset + length;
|
|
646
|
-
while (pos < end) {
|
|
647
|
-
const len = buf[pos] ?? 0;
|
|
648
|
-
pos += 1;
|
|
649
|
-
if (len === 0 || pos + len > end) break;
|
|
650
|
-
const entry = buf.subarray(pos, pos + len).toString("utf8");
|
|
651
|
-
pos += len;
|
|
652
|
-
const eq = entry.indexOf("=");
|
|
653
|
-
if (eq < 0) out[entry] = "";
|
|
654
|
-
else out[entry.slice(0, eq)] = entry.slice(eq + 1);
|
|
655
|
-
}
|
|
656
|
-
return out;
|
|
657
|
-
}
|
|
658
|
-
/** One PTR question per service type, all with the unicast-reply bit. */
|
|
659
|
-
function buildPtrQuery(serviceTypes) {
|
|
660
|
-
const header = Buffer.alloc(12);
|
|
661
|
-
header.writeUInt16BE(serviceTypes.length, 4);
|
|
662
|
-
const questions = serviceTypes.map((type) => {
|
|
663
|
-
const encoded = `${normalizeServiceType(type)}.local`.split(".").filter((part) => part.length > 0).map((l) => Buffer.concat([Buffer.from([l.length]), Buffer.from(l)]));
|
|
664
|
-
const tail = Buffer.alloc(4);
|
|
665
|
-
tail.writeUInt16BE(PTR, 0);
|
|
666
|
-
tail.writeUInt16BE(MDNS_QU_CLASS, 2);
|
|
667
|
-
return Buffer.concat([
|
|
668
|
-
...encoded,
|
|
669
|
-
Buffer.from([0]),
|
|
670
|
-
tail
|
|
671
|
-
]);
|
|
672
|
-
});
|
|
673
|
-
return Buffer.concat([header, ...questions]);
|
|
674
|
-
}
|
|
675
|
-
/** The services advertised on one mDNS message; a malformed packet yields none. */
|
|
676
|
-
function parseMdnsMessage(buf) {
|
|
677
|
-
if (buf.length < 12) return [];
|
|
678
|
-
const [questions = 0, answers = 0, authorities = 0, extra = 0] = [
|
|
679
|
-
4,
|
|
680
|
-
6,
|
|
681
|
-
8,
|
|
682
|
-
10
|
|
683
|
-
].map((o) => buf.readUInt16BE(o));
|
|
684
|
-
let pos = 12;
|
|
685
|
-
for (let i = 0; i < questions; i++) {
|
|
686
|
-
const name = readName(buf, pos);
|
|
687
|
-
if (name === null) return [];
|
|
688
|
-
pos = name.end + 4;
|
|
689
|
-
if (pos > buf.length) return [];
|
|
690
|
-
}
|
|
691
|
-
const records = [];
|
|
692
|
-
for (const count of [
|
|
693
|
-
answers,
|
|
694
|
-
authorities,
|
|
695
|
-
extra
|
|
696
|
-
]) {
|
|
697
|
-
const read = readRecords(buf, pos, count);
|
|
698
|
-
if (read === null) return [];
|
|
699
|
-
records.push(...read.records);
|
|
700
|
-
pos = read.next;
|
|
701
|
-
}
|
|
702
|
-
const ptrs = [];
|
|
703
|
-
const srv = /* @__PURE__ */ new Map();
|
|
704
|
-
const txt = /* @__PURE__ */ new Map();
|
|
705
|
-
const addresses = /* @__PURE__ */ new Map();
|
|
706
|
-
for (const rec of records) {
|
|
707
|
-
const key = rec.name.toLowerCase();
|
|
708
|
-
if (rec.type === PTR) {
|
|
709
|
-
const target = readName(buf, rec.dataOffset);
|
|
710
|
-
if (target !== null) ptrs.push({
|
|
711
|
-
serviceType: rec.name,
|
|
712
|
-
instance: target.name
|
|
713
|
-
});
|
|
714
|
-
} else if (rec.type === SRV && rec.dataLength >= SRV_FIXED) {
|
|
715
|
-
const target = readName(buf, rec.dataOffset + SRV_FIXED);
|
|
716
|
-
if (target !== null) srv.set(key, {
|
|
717
|
-
target: target.name,
|
|
718
|
-
port: buf.readUInt16BE(rec.dataOffset + 4)
|
|
719
|
-
});
|
|
720
|
-
} else if (rec.type === TXT) txt.set(key, parseTxt(buf, rec.dataOffset, rec.dataLength));
|
|
721
|
-
else if (rec.type === A && rec.dataLength === 4) addresses.set(key, `${buf[rec.dataOffset]}.${buf[rec.dataOffset + 1]}.${buf[rec.dataOffset + 2]}.${buf[rec.dataOffset + 3]}`);
|
|
722
|
-
}
|
|
723
|
-
const out = [];
|
|
724
|
-
for (const { serviceType, instance } of ptrs) {
|
|
725
|
-
const service = srv.get(instance.toLowerCase());
|
|
726
|
-
const target = service?.target ?? instance;
|
|
727
|
-
out.push({
|
|
728
|
-
serviceType: normalizeServiceType(serviceType),
|
|
729
|
-
instance,
|
|
730
|
-
address: addresses.get(target.toLowerCase()) ?? addresses.get(instance.toLowerCase()) ?? null,
|
|
731
|
-
host: target,
|
|
732
|
-
port: service?.port ?? 0,
|
|
733
|
-
txt: txt.get(instance.toLowerCase()) ?? {}
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
return out;
|
|
737
|
-
}
|
|
738
|
-
//#endregion
|
|
739
571
|
//#region src/builtins/local-network/scan/scan-io.ts
|
|
740
572
|
/** A hit carries at most this much of a response body. */
|
|
741
573
|
var MAX_HIT_BODY_BYTES = 16 * 1024;
|
|
@@ -884,7 +716,7 @@ var UNICAST_RESEND_AT_MS = [900];
|
|
|
884
716
|
var UNICAST_LISTEN_MS = 2e3;
|
|
885
717
|
var WSD_GROUP = "239.255.255.250";
|
|
886
718
|
var WSD_PORT = 3702;
|
|
887
|
-
var SSDP_PORT = 1900;
|
|
719
|
+
var SSDP_PORT$2 = 1900;
|
|
888
720
|
var MAX_HEADERS_PER_HIT = 32;
|
|
889
721
|
function bucket(c, kind) {
|
|
890
722
|
const existing = c.stats.get(kind);
|
|
@@ -962,23 +794,52 @@ function hubLinks(interfaces) {
|
|
|
962
794
|
function instanceLabel(instance) {
|
|
963
795
|
return instance.split("._")[0] ?? instance;
|
|
964
796
|
}
|
|
797
|
+
/**
|
|
798
|
+
* One link: join 5353 on the group and ask QM, so the answer a router reflects from
|
|
799
|
+
* another VLAN (it arrives as multicast) is heard. A device on another VLAN ignores
|
|
800
|
+
* an off-link unicast-response query (RFC 6762 §11), so the old ephemeral-port QU
|
|
801
|
+
* query alone never found it. A bind or membership failure is a named skip and the
|
|
802
|
+
* link falls back to the QU query, which still finds same-link devices.
|
|
803
|
+
*/
|
|
804
|
+
async function exchangeOnLink(deps, link, groupQuery, fallbackQuery) {
|
|
805
|
+
const request = {
|
|
806
|
+
targets: [{
|
|
807
|
+
host: MDNS_GROUP,
|
|
808
|
+
port: MDNS_PORT
|
|
809
|
+
}],
|
|
810
|
+
localAddress: link.address,
|
|
811
|
+
resendAtMs: MULTICAST_RESEND_AT_MS,
|
|
812
|
+
listenMs: MULTICAST_LISTEN_MS
|
|
813
|
+
};
|
|
814
|
+
try {
|
|
815
|
+
return await deps.io.udpExchange({
|
|
816
|
+
...request,
|
|
817
|
+
payload: groupQuery,
|
|
818
|
+
bindPort: MDNS_PORT,
|
|
819
|
+
joinGroup: MDNS_GROUP
|
|
820
|
+
});
|
|
821
|
+
} catch (err) {
|
|
822
|
+
deps.logger.warn("local-network: mdns group listen skipped on link, using unicast-response query", { meta: {
|
|
823
|
+
link: link.address,
|
|
824
|
+
interface: link.name,
|
|
825
|
+
error: errMsg(err)
|
|
826
|
+
} });
|
|
827
|
+
return deps.io.udpExchange({
|
|
828
|
+
...request,
|
|
829
|
+
payload: fallbackQuery
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
}
|
|
965
833
|
async function runMdns(deps, entries, subnets, c) {
|
|
966
834
|
if (entries.length === 0) return;
|
|
967
|
-
const
|
|
835
|
+
const types = [...new Set(entries.map((e) => normalizeServiceType(e.mode.serviceType)))];
|
|
836
|
+
const query = buildPtrQuery(types);
|
|
837
|
+
const groupQuery = buildPtrQuery(types, { unicastResponse: false });
|
|
968
838
|
const replies = [];
|
|
969
839
|
const links = hubLinks(deps.interfaces());
|
|
970
840
|
for (const link of links) {
|
|
971
841
|
bucket(c, "mdns").probed += 1;
|
|
972
|
-
replies.push(...await deps
|
|
973
|
-
payload: query,
|
|
974
|
-
targets: [{
|
|
975
|
-
host: MDNS_GROUP,
|
|
976
|
-
port: MDNS_PORT
|
|
977
|
-
}],
|
|
978
|
-
localAddress: link.address,
|
|
979
|
-
resendAtMs: MULTICAST_RESEND_AT_MS,
|
|
980
|
-
listenMs: MULTICAST_LISTEN_MS
|
|
981
|
-
}));
|
|
842
|
+
replies.push(...await exchangeOnLink(deps, link, groupQuery, query));
|
|
982
843
|
}
|
|
983
844
|
const extraHosts = extraHostsOf(subnets);
|
|
984
845
|
if (extraHosts.length > 0) {
|
|
@@ -1109,10 +970,10 @@ function parseSsdp(data) {
|
|
|
1109
970
|
}
|
|
1110
971
|
async function runSsdp(deps, entries, subnets, c) {
|
|
1111
972
|
for (const target of new Set(entries.map((e) => e.mode.searchTarget))) {
|
|
1112
|
-
const replies = await exchangeEverywhere(deps, "ssdp", Buffer.from(`M-SEARCH * HTTP/1.1\r\nHOST: ${WSD_GROUP}:${SSDP_PORT}\r\nMAN: "ssdp:discover"\r\nMX: 1\r\nST: ${target}\r\n\r\n`), {
|
|
973
|
+
const replies = await exchangeEverywhere(deps, "ssdp", Buffer.from(`M-SEARCH * HTTP/1.1\r\nHOST: ${WSD_GROUP}:${SSDP_PORT$2}\r\nMAN: "ssdp:discover"\r\nMX: 1\r\nST: ${target}\r\n\r\n`), {
|
|
1113
974
|
host: WSD_GROUP,
|
|
1114
|
-
port: SSDP_PORT
|
|
1115
|
-
}, SSDP_PORT, subnets, c);
|
|
975
|
+
port: SSDP_PORT$2
|
|
976
|
+
}, SSDP_PORT$2, subnets, c);
|
|
1116
977
|
for (const reply of replies) {
|
|
1117
978
|
const parsed = parseSsdp(reply.data);
|
|
1118
979
|
if (parsed === null) continue;
|
|
@@ -1285,6 +1146,198 @@ async function runScan(deps, input) {
|
|
|
1285
1146
|
};
|
|
1286
1147
|
}
|
|
1287
1148
|
//#endregion
|
|
1149
|
+
//#region src/builtins/local-network/passive/passive-packets.ts
|
|
1150
|
+
var MAX_HEADERS = 32;
|
|
1151
|
+
var SSDP_PORT$1 = 1900;
|
|
1152
|
+
function parseMdnsPacket(data) {
|
|
1153
|
+
return parseMdnsMessage(data).filter((service) => service.port > 0).map((service) => ({
|
|
1154
|
+
kind: "mdns",
|
|
1155
|
+
serviceType: service.serviceType,
|
|
1156
|
+
instance: service.instance,
|
|
1157
|
+
host: service.host,
|
|
1158
|
+
address: service.address,
|
|
1159
|
+
port: service.port,
|
|
1160
|
+
txt: service.txt
|
|
1161
|
+
}));
|
|
1162
|
+
}
|
|
1163
|
+
/** A NOTIFY (`NT`) or a search response (`ST`); an M-SEARCH request is somebody asking. */
|
|
1164
|
+
function parseSsdpPacket(data, from) {
|
|
1165
|
+
const lines = data.toString("utf8").split(/\r?\n/);
|
|
1166
|
+
const first = lines[0] ?? "";
|
|
1167
|
+
const isNotify = /^NOTIFY\s/i.test(first);
|
|
1168
|
+
if (!isNotify && !/^HTTP\/1\.[01]\s+200/.test(first)) return null;
|
|
1169
|
+
const headers = {};
|
|
1170
|
+
for (const line of lines.slice(1)) {
|
|
1171
|
+
const colon = line.indexOf(":");
|
|
1172
|
+
if (colon <= 0) continue;
|
|
1173
|
+
if (Object.keys(headers).length >= MAX_HEADERS) break;
|
|
1174
|
+
headers[line.slice(0, colon).trim().toLowerCase()] = line.slice(colon + 1).trim();
|
|
1175
|
+
}
|
|
1176
|
+
if (isNotify && headers["nts"] !== "ssdp:alive") return null;
|
|
1177
|
+
const target = isNotify ? headers["nt"] : headers["st"];
|
|
1178
|
+
if (target === void 0 || target.length === 0) return null;
|
|
1179
|
+
return {
|
|
1180
|
+
kind: "ssdp",
|
|
1181
|
+
host: from,
|
|
1182
|
+
port: SSDP_PORT$1,
|
|
1183
|
+
target,
|
|
1184
|
+
headers
|
|
1185
|
+
};
|
|
1186
|
+
}
|
|
1187
|
+
/** What identifies a sighting for de-duplication: who said it and about what. */
|
|
1188
|
+
function observationKey(o) {
|
|
1189
|
+
return o.kind === "mdns" ? `mdns|${o.address ?? o.host}|${o.serviceType}|${o.instance}` : `ssdp|${o.host}|${o.target}`;
|
|
1190
|
+
}
|
|
1191
|
+
//#endregion
|
|
1192
|
+
//#region src/builtins/local-network/passive/discovery-watcher.ts
|
|
1193
|
+
/**
|
|
1194
|
+
* Passive discovery for the hub (D994): a listener on the mDNS and SSDP
|
|
1195
|
+
* multicast groups plus a low-cost sweep on a fixed schedule. Both end in the
|
|
1196
|
+
* same place, `device-manager`'s proposal stream, which persists them.
|
|
1197
|
+
*
|
|
1198
|
+
* The listener never asks anything on the wire. It de-duplicates what it hears
|
|
1199
|
+
* (a chatty device announces every few seconds), batches it, and hands the batch
|
|
1200
|
+
* over; the sweep runs the discovery the integrations already offer, at most one
|
|
1201
|
+
* at a time, once per {@link SWEEP_INTERVAL_MS}.
|
|
1202
|
+
*/
|
|
1203
|
+
var SWEEP_INTERVAL_MS = 1800 * 1e3;
|
|
1204
|
+
var FLUSH_INTERVAL_MS = 5e3;
|
|
1205
|
+
/** Bound on the de-duplication memory. */
|
|
1206
|
+
var MAX_SEEN = 4096;
|
|
1207
|
+
var DiscoveryWatcher = class {
|
|
1208
|
+
deps;
|
|
1209
|
+
now;
|
|
1210
|
+
seen = /* @__PURE__ */ new Map();
|
|
1211
|
+
pending = [];
|
|
1212
|
+
dropped = 0;
|
|
1213
|
+
listener = null;
|
|
1214
|
+
flushTimer = null;
|
|
1215
|
+
sweepTimer = null;
|
|
1216
|
+
sweeping = false;
|
|
1217
|
+
running = false;
|
|
1218
|
+
constructor(deps) {
|
|
1219
|
+
this.deps = deps;
|
|
1220
|
+
this.now = deps.now ?? (() => Date.now());
|
|
1221
|
+
}
|
|
1222
|
+
async start(options) {
|
|
1223
|
+
if (this.running) return;
|
|
1224
|
+
this.running = true;
|
|
1225
|
+
this.sweepTimer = setInterval(() => void this.runSweep(), SWEEP_INTERVAL_MS);
|
|
1226
|
+
this.sweepTimer.unref?.();
|
|
1227
|
+
if (!options.passive) return;
|
|
1228
|
+
this.flushTimer = setInterval(() => void this.flush(), FLUSH_INTERVAL_MS);
|
|
1229
|
+
this.flushTimer.unref?.();
|
|
1230
|
+
this.listener = await this.deps.io.open((packet) => this.onPacket(packet), (protocol, error) => this.deps.logger.warn("passive discovery: listener unavailable", { meta: {
|
|
1231
|
+
protocol,
|
|
1232
|
+
error: errMsg(error)
|
|
1233
|
+
} }));
|
|
1234
|
+
}
|
|
1235
|
+
async stop() {
|
|
1236
|
+
this.running = false;
|
|
1237
|
+
if (this.sweepTimer !== null) clearInterval(this.sweepTimer);
|
|
1238
|
+
if (this.flushTimer !== null) clearInterval(this.flushTimer);
|
|
1239
|
+
this.sweepTimer = null;
|
|
1240
|
+
this.flushTimer = null;
|
|
1241
|
+
this.listener?.close();
|
|
1242
|
+
this.listener = null;
|
|
1243
|
+
this.pending = [];
|
|
1244
|
+
}
|
|
1245
|
+
onPacket(packet) {
|
|
1246
|
+
const sightings = packet.protocol === "mdns" ? parseMdnsPacket(packet.data) : [parseSsdpPacket(packet.data, packet.from)].filter((o) => o !== null);
|
|
1247
|
+
const at = this.now();
|
|
1248
|
+
for (const sighting of sightings) {
|
|
1249
|
+
const key = observationKey(sighting);
|
|
1250
|
+
const last = this.seen.get(key);
|
|
1251
|
+
if (last !== void 0 && at - last < 6e5) continue;
|
|
1252
|
+
if (this.pending.length >= 512) {
|
|
1253
|
+
this.dropped += 1;
|
|
1254
|
+
continue;
|
|
1255
|
+
}
|
|
1256
|
+
this.remember(key, at);
|
|
1257
|
+
this.pending.push(sighting);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
remember(key, at) {
|
|
1261
|
+
if (this.seen.size >= MAX_SEEN) {
|
|
1262
|
+
for (const [k, t] of this.seen) if (at - t >= 6e5) this.seen.delete(k);
|
|
1263
|
+
if (this.seen.size >= MAX_SEEN) this.seen.clear();
|
|
1264
|
+
}
|
|
1265
|
+
this.seen.set(key, at);
|
|
1266
|
+
}
|
|
1267
|
+
/** Hand the batch over. A failed hand-over puts nothing back: a later sighting repeats it. */
|
|
1268
|
+
async flush() {
|
|
1269
|
+
if (this.dropped > 0) {
|
|
1270
|
+
this.deps.logger.warn("passive discovery: sightings dropped, queue full", { meta: { dropped: this.dropped } });
|
|
1271
|
+
this.dropped = 0;
|
|
1272
|
+
}
|
|
1273
|
+
if (this.pending.length === 0) return;
|
|
1274
|
+
const batch = this.pending;
|
|
1275
|
+
this.pending = [];
|
|
1276
|
+
try {
|
|
1277
|
+
await this.deps.sink.report(batch);
|
|
1278
|
+
} catch (err) {
|
|
1279
|
+
this.deps.logger.warn("passive discovery: could not report sightings", { meta: {
|
|
1280
|
+
count: batch.length,
|
|
1281
|
+
error: errMsg(err)
|
|
1282
|
+
} });
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
async runSweep() {
|
|
1286
|
+
if (this.sweeping) return;
|
|
1287
|
+
this.sweeping = true;
|
|
1288
|
+
try {
|
|
1289
|
+
await this.deps.sink.sweep();
|
|
1290
|
+
} catch (err) {
|
|
1291
|
+
this.deps.logger.warn("discovery sweep failed", { meta: { error: errMsg(err) } });
|
|
1292
|
+
} finally {
|
|
1293
|
+
this.sweeping = false;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
//#endregion
|
|
1298
|
+
//#region src/builtins/local-network/passive/passive-io-node.ts
|
|
1299
|
+
/** The real {@link PassiveListenIo}: two multicast UDP sockets. Not unit-tested; the watcher is. */
|
|
1300
|
+
var SSDP_GROUP = "239.255.255.250";
|
|
1301
|
+
var SSDP_PORT = 1900;
|
|
1302
|
+
function listenOn(protocol, port, group, onPacket, onError) {
|
|
1303
|
+
return new Promise((resolve) => {
|
|
1304
|
+
const socket = createSocket({
|
|
1305
|
+
type: "udp4",
|
|
1306
|
+
reuseAddr: true
|
|
1307
|
+
});
|
|
1308
|
+
socket.on("error", (err) => {
|
|
1309
|
+
onError(protocol, err);
|
|
1310
|
+
try {
|
|
1311
|
+
socket.close();
|
|
1312
|
+
} catch {}
|
|
1313
|
+
resolve(null);
|
|
1314
|
+
});
|
|
1315
|
+
socket.on("message", (data, rinfo) => onPacket({
|
|
1316
|
+
protocol,
|
|
1317
|
+
data,
|
|
1318
|
+
from: rinfo.address
|
|
1319
|
+
}));
|
|
1320
|
+
socket.bind(port, () => {
|
|
1321
|
+
try {
|
|
1322
|
+
socket.addMembership(group);
|
|
1323
|
+
resolve(socket);
|
|
1324
|
+
} catch (err) {
|
|
1325
|
+
onError(protocol, err instanceof Error ? err : new Error(String(err)));
|
|
1326
|
+
socket.close();
|
|
1327
|
+
resolve(null);
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
var nodePassiveListenIo = { async open(onPacket, onError) {
|
|
1333
|
+
const sockets = (await Promise.all([listenOn("mdns", MDNS_PORT, MDNS_GROUP, onPacket, onError), listenOn("ssdp", SSDP_PORT, SSDP_GROUP, onPacket, onError)])).filter((s) => s !== null);
|
|
1334
|
+
return { close: () => {
|
|
1335
|
+
for (const s of sockets) try {
|
|
1336
|
+
s.close();
|
|
1337
|
+
} catch {}
|
|
1338
|
+
} };
|
|
1339
|
+
} };
|
|
1340
|
+
//#endregion
|
|
1288
1341
|
//#region src/builtins/local-network/scan/scan-io-node.ts
|
|
1289
1342
|
/** The real {@link ScanIo}: node `dgram`, `http` and `https`. Not unit-tested; the engine is. */
|
|
1290
1343
|
function udpExchange(request) {
|
|
@@ -1295,9 +1348,13 @@ function udpExchange(request) {
|
|
|
1295
1348
|
});
|
|
1296
1349
|
const replies = [];
|
|
1297
1350
|
let settled = false;
|
|
1351
|
+
let joined = false;
|
|
1298
1352
|
const finish = (error) => {
|
|
1299
1353
|
if (settled) return;
|
|
1300
1354
|
settled = true;
|
|
1355
|
+
if (joined && request.joinGroup !== void 0) try {
|
|
1356
|
+
socket.dropMembership(request.joinGroup, request.localAddress);
|
|
1357
|
+
} catch {}
|
|
1301
1358
|
try {
|
|
1302
1359
|
socket.close();
|
|
1303
1360
|
} catch {}
|
|
@@ -1312,8 +1369,13 @@ function udpExchange(request) {
|
|
|
1312
1369
|
data
|
|
1313
1370
|
});
|
|
1314
1371
|
});
|
|
1315
|
-
|
|
1372
|
+
const bindAddress = request.joinGroup === void 0 ? request.localAddress : void 0;
|
|
1373
|
+
socket.bind(request.bindPort ?? 0, bindAddress, () => {
|
|
1316
1374
|
try {
|
|
1375
|
+
if (request.joinGroup !== void 0) {
|
|
1376
|
+
socket.addMembership(request.joinGroup, request.localAddress);
|
|
1377
|
+
joined = true;
|
|
1378
|
+
}
|
|
1317
1379
|
if (request.broadcast === true) socket.setBroadcast(true);
|
|
1318
1380
|
if (request.localAddress !== void 0) socket.setMulticastInterface(request.localAddress);
|
|
1319
1381
|
} catch (err) {
|
|
@@ -1441,6 +1503,8 @@ var LocalNetworkAddon = class extends BaseAddon {
|
|
|
1441
1503
|
*/
|
|
1442
1504
|
meshEndpoint = null;
|
|
1443
1505
|
mdns = null;
|
|
1506
|
+
discoveryWatcher = null;
|
|
1507
|
+
watcherPassive = true;
|
|
1444
1508
|
constructor() {
|
|
1445
1509
|
super({
|
|
1446
1510
|
allowedAddresses: [],
|
|
@@ -1455,6 +1519,7 @@ var LocalNetworkAddon = class extends BaseAddon {
|
|
|
1455
1519
|
internalUrl: "",
|
|
1456
1520
|
publicEndpointUrl: "",
|
|
1457
1521
|
mdnsAdvertise: true,
|
|
1522
|
+
passiveDiscovery: true,
|
|
1458
1523
|
scanSubnets: []
|
|
1459
1524
|
});
|
|
1460
1525
|
}
|
|
@@ -1796,6 +1861,9 @@ var LocalNetworkAddon = class extends BaseAddon {
|
|
|
1796
1861
|
this.ctx.logger.warn("local-network: LAN HTTP not applied at boot", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
1797
1862
|
}
|
|
1798
1863
|
await this.applyMdnsAdvertisement();
|
|
1864
|
+
this.applyDiscoveryWatcher().catch((err) => {
|
|
1865
|
+
this.ctx.logger.warn("local-network: discovery watcher not started", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
1866
|
+
});
|
|
1799
1867
|
return [{
|
|
1800
1868
|
capability: localNetworkCapability,
|
|
1801
1869
|
provider
|
|
@@ -1854,6 +1922,16 @@ var LocalNetworkAddon = class extends BaseAddon {
|
|
|
1854
1922
|
style: "switch",
|
|
1855
1923
|
default: true
|
|
1856
1924
|
}),
|
|
1925
|
+
this.field({
|
|
1926
|
+
type: "boolean",
|
|
1927
|
+
key: "passiveDiscovery",
|
|
1928
|
+
label: "Find new devices on the LAN by listening",
|
|
1929
|
+
labelKey: "server:globalSettings.s_local-access.passiveDiscovery.label",
|
|
1930
|
+
description: "On by default. Listens for mDNS and SSDP announcements and proposes the devices an integration can adopt; a low-cost scan also runs every 30 minutes. It never sends a probe of its own. Needs UDP multicast to reach the LAN (host networking or a dedicated container IP).",
|
|
1931
|
+
descriptionKey: "server:globalSettings.s_local-access.passiveDiscovery.description",
|
|
1932
|
+
style: "switch",
|
|
1933
|
+
default: true
|
|
1934
|
+
}),
|
|
1857
1935
|
this.field({
|
|
1858
1936
|
type: "text",
|
|
1859
1937
|
key: "localHostname",
|
|
@@ -1870,6 +1948,33 @@ var LocalNetworkAddon = class extends BaseAddon {
|
|
|
1870
1948
|
async onConfigChanged() {
|
|
1871
1949
|
await this.applyLanAccessFromSettings();
|
|
1872
1950
|
await this.applyMdnsAdvertisement();
|
|
1951
|
+
await this.applyDiscoveryWatcher();
|
|
1952
|
+
}
|
|
1953
|
+
/**
|
|
1954
|
+
* (Re)start the passive listener and the 30-minute sweep, both feeding the
|
|
1955
|
+
* proposal stream of device-manager. Never throws: a socket that cannot open
|
|
1956
|
+
* is logged by the watcher and the sweep still runs.
|
|
1957
|
+
*/
|
|
1958
|
+
async applyDiscoveryWatcher() {
|
|
1959
|
+
const passive = this.config.passiveDiscovery !== false;
|
|
1960
|
+
if (this.discoveryWatcher !== null && passive === this.watcherPassive) return;
|
|
1961
|
+
await this.discoveryWatcher?.stop();
|
|
1962
|
+
const api = this.ctx.api;
|
|
1963
|
+
if (api === void 0) return;
|
|
1964
|
+
this.watcherPassive = passive;
|
|
1965
|
+
this.discoveryWatcher = new DiscoveryWatcher({
|
|
1966
|
+
io: nodePassiveListenIo,
|
|
1967
|
+
logger: this.ctx.logger.child("discovery"),
|
|
1968
|
+
sink: {
|
|
1969
|
+
report: async (observations) => {
|
|
1970
|
+
await api.deviceManager.reportDiscoveryObservations.mutate({ observations: [...observations] });
|
|
1971
|
+
},
|
|
1972
|
+
sweep: async () => {
|
|
1973
|
+
await api.deviceManager.runDiscoverySweep.mutate({});
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
});
|
|
1977
|
+
await this.discoveryWatcher.start({ passive });
|
|
1873
1978
|
}
|
|
1874
1979
|
/**
|
|
1875
1980
|
* Start, re-announce or stop the hub's mDNS service (D838). Never throws:
|
|
@@ -1890,6 +1995,8 @@ var LocalNetworkAddon = class extends BaseAddon {
|
|
|
1890
1995
|
await this.mdns.start();
|
|
1891
1996
|
}
|
|
1892
1997
|
async onShutdown() {
|
|
1998
|
+
await this.discoveryWatcher?.stop();
|
|
1999
|
+
this.discoveryWatcher = null;
|
|
1893
2000
|
await this.mdns?.stop();
|
|
1894
2001
|
this.mdns = null;
|
|
1895
2002
|
if (this.pollTimer) {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passive discovery for the hub (D994): a listener on the mDNS and SSDP
|
|
3
|
+
* multicast groups plus a low-cost sweep on a fixed schedule. Both end in the
|
|
4
|
+
* same place, `device-manager`'s proposal stream, which persists them.
|
|
5
|
+
*
|
|
6
|
+
* The listener never asks anything on the wire. It de-duplicates what it hears
|
|
7
|
+
* (a chatty device announces every few seconds), batches it, and hands the batch
|
|
8
|
+
* over; the sweep runs the discovery the integrations already offer, at most one
|
|
9
|
+
* at a time, once per {@link SWEEP_INTERVAL_MS}.
|
|
10
|
+
*/
|
|
11
|
+
import { type DiscoveryObservation, type IScopedLogger } from "@camstack/types";
|
|
12
|
+
export declare const SWEEP_INTERVAL_MS: number;
|
|
13
|
+
/** A sighting already reported within this window is not reported again. */
|
|
14
|
+
export declare const SEEN_WINDOW_MS: number;
|
|
15
|
+
export declare const FLUSH_INTERVAL_MS = 5e3;
|
|
16
|
+
/** More distinct sightings than this between two flushes are dropped, and said so. */
|
|
17
|
+
export declare const MAX_PENDING = 512;
|
|
18
|
+
export interface PassivePacket {
|
|
19
|
+
readonly protocol: "mdns" | "ssdp";
|
|
20
|
+
readonly data: Buffer;
|
|
21
|
+
readonly from: string;
|
|
22
|
+
}
|
|
23
|
+
export interface PassiveListenIo {
|
|
24
|
+
open(onPacket: (packet: PassivePacket) => void, onError: (protocol: PassivePacket["protocol"], error: Error) => void): Promise<{
|
|
25
|
+
close(): void;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
/** Where sightings and sweeps go: device-manager through `ctx.api`. */
|
|
29
|
+
export interface DiscoverySink {
|
|
30
|
+
report(observations: readonly DiscoveryObservation[]): Promise<void>;
|
|
31
|
+
sweep(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export interface DiscoveryWatcherDeps {
|
|
34
|
+
readonly io: PassiveListenIo;
|
|
35
|
+
readonly sink: DiscoverySink;
|
|
36
|
+
readonly logger: IScopedLogger;
|
|
37
|
+
readonly now?: () => number;
|
|
38
|
+
}
|
|
39
|
+
export declare class DiscoveryWatcher {
|
|
40
|
+
private readonly deps;
|
|
41
|
+
private readonly now;
|
|
42
|
+
private readonly seen;
|
|
43
|
+
private pending;
|
|
44
|
+
private dropped;
|
|
45
|
+
private listener;
|
|
46
|
+
private flushTimer;
|
|
47
|
+
private sweepTimer;
|
|
48
|
+
private sweeping;
|
|
49
|
+
private running;
|
|
50
|
+
constructor(deps: DiscoveryWatcherDeps);
|
|
51
|
+
start(options: {
|
|
52
|
+
readonly passive: boolean;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
stop(): Promise<void>;
|
|
55
|
+
private onPacket;
|
|
56
|
+
private remember;
|
|
57
|
+
/** Hand the batch over. A failed hand-over puts nothing back: a later sighting repeats it. */
|
|
58
|
+
flush(): Promise<void>;
|
|
59
|
+
runSweep(): Promise<void>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn one multicast datagram into what the proposal stream understands.
|
|
3
|
+
* Pure: a malformed or irrelevant packet yields nothing.
|
|
4
|
+
*/
|
|
5
|
+
import type { DiscoveryObservation } from "@camstack/types";
|
|
6
|
+
export declare function parseMdnsPacket(data: Buffer): readonly DiscoveryObservation[];
|
|
7
|
+
/** A NOTIFY (`NT`) or a search response (`ST`); an M-SEARCH request is somebody asking. */
|
|
8
|
+
export declare function parseSsdpPacket(data: Buffer, from: string): DiscoveryObservation | null;
|
|
9
|
+
/** What identifies a sighting for de-duplication: who said it and about what. */
|
|
10
|
+
export declare function observationKey(o: DiscoveryObservation): string;
|
|
@@ -11,7 +11,11 @@ export interface MdnsService {
|
|
|
11
11
|
readonly port: number;
|
|
12
12
|
readonly txt: Readonly<Record<string, string>>;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
export interface PtrQueryOptions {
|
|
15
|
+
/** Unicast-reply bit (QU). Default true; a group member asks QM so a reflected answer reaches it. */
|
|
16
|
+
readonly unicastResponse?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** One PTR question per service type, with the unicast-reply bit unless `unicastResponse` is false. */
|
|
19
|
+
export declare function buildPtrQuery(serviceTypes: readonly string[], options?: PtrQueryOptions): Buffer;
|
|
16
20
|
/** The services advertised on one mDNS message; a malformed packet yields none. */
|
|
17
21
|
export declare function parseMdnsMessage(buf: Buffer): readonly MdnsService[];
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* Bounded: 64 requests in flight, 1.2 s per request, 4096 hosts per scan.
|
|
15
15
|
* The sockets are injected ({@link ScanIo}), so this is unit-testable.
|
|
16
16
|
*/
|
|
17
|
-
import type
|
|
17
|
+
import { type IScopedLogger, type LocalInterface, type ScanNetworkResult, type ScanRequest } from "@camstack/types";
|
|
18
18
|
import { type ScanIo } from "./scan-io.js";
|
|
19
19
|
export declare const SCAN_CONCURRENCY = 64;
|
|
20
20
|
export declare const SCAN_REQUEST_TIMEOUT_MS = 1200;
|