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

Method resolve

modules/network/net/netmdns.js:30–66  ·  view source on GitHub ↗
(host, client)

Source from the content-addressed store, hash-verified

28 static get() @ "xs_net_get";
29
30 static resolve(host, client) {
31 if (!host.endsWith(".local"))
32 return this._resolve(host, client);
33
34 const socket = new Socket({kind: "UDP"});
35 socket.host = host;
36 socket.client = client;
37 socket.callback = callback;
38
39 host = host.split(".");
40 if (2 !== host.length)
41 throw new Error("unrecognized");
42
43 host[0] = ArrayBuffer.fromString(host[0]);
44 host[1] = ArrayBuffer.fromString(host[1]);
45
46 const packet = new Uint8Array(12 + host[0].byteLength + host[1].byteLength + 3 + 4);
47 packet[5] = 1; // 1 question
48 let position = 12;
49 packet[position++] = host[0].byteLength;
50 packet.set(new Uint8Array(host[0]), position); position += host[0].byteLength;
51 packet[position++] = host[1].byteLength;
52 packet.set(new Uint8Array(host[1]), position); position += host[1].byteLength;
53 packet[position + 2] = packet[position + 4] = 1;
54 packet[position + 3] = 0x80;
55
56 let count = 3;
57 socket.timer = Timer.repeat(function (id) {
58 if (0 === count--) {
59 socket.client(socket.host)
60 Timer.clear(id);
61 return socket.close();
62 }
63 trace(`query ${socket.host}\n`);
64 socket.write("224.0.0.251", 5353, packet.buffer);
65 }, 1000, 1);
66 }
67 static _resolve(host, callback) @ "xs_net_resolve";
68}
69

Callers 15

resolveFunction · 0.45
index.jsFile · 0.45
resolveFilePathMethod · 0.45
DebugBehavior.jsFile · 0.45
startMethod · 0.45
constructorMethod · 0.45
httpget-ip.jsFile · 0.45
lookup-address.jsFile · 0.45
lookup-fail.jsFile · 0.45
lookup.jsFile · 0.45

Calls 6

fromStringMethod · 0.80
repeatMethod · 0.80
setMethod · 0.65
closeMethod · 0.65
writeMethod · 0.65
clearMethod · 0.45

Tested by

no test coverage detected