Skip to content

Commit

Permalink
adds separation of query & rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-burns committed Aug 6, 2024
1 parent cc8185f commit baa85e4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 33 deletions.
84 changes: 52 additions & 32 deletions golang/wasm/pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,35 +517,66 @@ const DNS_CLASS = [
// "QCLASS * (ANY)", // 255
]

// renderQuery
async function renderQuery() {

var domain = document.getElementById("query-name").value
if (domain == "") {
domain = "zenr.io"
}

var rrType = document.getElementById("query-type").value
if (rrType == "") {
rrType = 'A'
}

const pre = document.getElementById("query-result")
if (pre.children.length > 0) {
pre.removeChild(pre.children[0])
}

const ul = document.createElement("ul")

responseJson = await query(domain, rrType)

const getDohServer = window.goFuncs.getDefaultDOHResolver
dohServer = document.createElement("li")
dohServer.innerHTML = "Query DOH responder: " + getDohServer()
ul.appendChild(dohServer)

const dohQName = document.createElement("li")
dohQName.innerHTML = "Query Name: " + domain
ul.appendChild(dohQName)

const dohQType = document.createElement("li")
dohQType.innerHTML = "Query RRType: " + rrType
ul.appendChild(dohQType)


const raw = document.createElement("li")
raw.innerHTML = JSON.stringify(responseJson, null, 4)
ul.appendChild(raw)

pre.appendChild(ul)

}

// query()
// for a given name and RR type, return dns response
async function query() {
async function query(dohQName, dohQType) {
// set query question name
var dohQName = document.getElementById("query-name").value

// DEBUG
if (dohQName == "") {
dohQName = "zenr.io"
}
// var dohQName = document.getElementById("query-name").value

// append .
if (! dohQName.endsWith('.')) {
dohQName = dohQName + '.'
}

// set query question RR type
var dohQType = document.getElementById("query-type").value
// set default query question RR type
if (dohQType == "") {
dohQType = 'A'
}

const pre = document.getElementById("query-result")
if (pre.children.length > 0) {
pre.removeChild(pre.children[0])
}

const ul = document.createElement("ul")

const dohQuery = window.goFuncs.query
result = await dohQuery(dohQName, dohQType)

Expand Down Expand Up @@ -582,7 +613,7 @@ async function query() {
})

if (resultJson.Answer != null) {
console.log("This response has Answer array length of ", resultJson.Answer.length)
console.log("DOH response has Answer array length of ", resultJson.Answer.length)

resultJson.Answer.forEach(answer => {

Expand Down Expand Up @@ -628,11 +659,11 @@ async function query() {

})
} else {
console.log("This response has null as Answer property")
console.log("DOH response has null as Answer property")
}

if (resultJson.Ns != null) {
console.log("This response has Ns array length of ", resultJson.Ns.length)
console.log("DOH response has Ns array length of ", resultJson.Ns.length)

resultJson.Ns.forEach(answer => {

Expand Down Expand Up @@ -679,19 +710,8 @@ async function query() {

})
} else {
console.log("This response has null as Ns property")
console.log("DOH response has null as Ns property")
}

const getDohServer = window.goFuncs.getDefaultDOHResolver
dohServer = document.createElement("li")
dohServer.innerHTML = "Querying DOH host: " + getDohServer()
ul.appendChild(dohServer)

const raw = document.createElement("li")
raw.innerHTML = JSON.stringify(resultJson, null, 4)
ul.appendChild(raw)

pre.appendChild(ul)

return
return resultJson
}
2 changes: 1 addition & 1 deletion golang/wasm/wasm_exec.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h3>DOH Resolver</h3>
<p>
<input type="text" id="query-name" placeholder="mythingymajig.zenr.io">
<input type="text" id="query-type" placeholder="A">
<button onclick="query()">Resolve</button>
<button onclick="renderQuery()">Resolve</button>
<pre id="query-result"></pre>
</p>

Expand Down

0 comments on commit baa85e4

Please sign in to comment.