MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / scanPacket

Method scanPacket

modules/io/dnssd/dnssd.js:225–347  ·  view source on GitHub ↗
(packet)

Source from the content-addressed store, hash-verified

223 this.timer = Timer.set(dnssd.monitorTask.bind(this), 30 * 60 * 1000); //@@ calculate based on TTL elapsed (section 5.2 Continuous Multicast DNS Querying)
224 }
225 scanPacket(packet) {
226 const answers = packet.answers, records = [];
227 for (let i = 0, length = answers + packet.additionals; i < length; i++)
228 records.push((i < answers) ? packet.answer(i) : packet.additional(i - answers));
229
230 let changed;
231 records.forEach(record => {
232 if ((DNS.RR.SRV !== record.qtype) && (DNS.RR.TXT !== record.qtype)) return;
233
234 const name = record.qname;
235 const service = name.slice(1).join(".");
236 const monitor = this.monitors.find(monitor => monitor.service === service);
237 if (!monitor)
238 return;
239 let instance = monitor.find(item => item.name.toLowerCase() === name[0].toLowerCase());
240 if (!instance) {
241 instance = {name: name[0]};
242 monitor.push(instance);
243 }
244 if (DNS.RR.TXT === record.qtype) {
245 const txt = record.rdata ? record.rdata : [];
246 if (!instance.txt || (instance.txt.length !== txt.length)) {
247 instance.txt = txt;
248 instance.changed = changed = true;
249 }
250 else {
251 for (let j = 0; j < txt.length; ++j) {
252 if (txt[j] === instance.txt[j])
253 continue;
254 instance.txt = txt;
255 instance.changed = changed = true;
256 break;
257 }
258 }
259 }
260 else {
261 const target = record.rdata.target.join(".");
262 if ((instance.port !== record.rdata.port) || (instance.target.toLowerCase() !== target.toLowerCase())) {
263 instance.port = record.rdata.port;
264 instance.target = target;
265 instance.changed = changed = true;
266 }
267 }
268 instance.ttl = record.ttl;
269 });
270
271 records.forEach(record => {
272 if (DNS.RR.PTR !== record.qtype) return;
273
274 const service = record.qname.join(".");
275 const monitor = this.monitors.find(monitor => monitor.service === service);
276 if (!monitor)
277 return;
278 let instance = monitor.find(item => item.name === record.rdata[0]);
279 if (!instance) {
280 instance = {name: record.rdata[0]};
281 monitor.push(instance);
282 instance.changed = changed = true;

Callers 1

#onPacketMethod · 0.95

Calls 9

addMethod · 0.95
writeMethod · 0.95
buildMethod · 0.95
answerMethod · 0.80
additionalMethod · 0.80
findMethod · 0.80
sliceMethod · 0.65
pushMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected