Skip to content

Commit

Permalink
plugins/dns-op: m jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Jun 7, 2023
1 parent fc967c4 commit 0d007fd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/plugins/dns-op/cache-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@ export class CacheApi {
}
}

/**
* @param {string} href
* @returns {Promise<Response?>}
*/
async get(href) {
if (this.noop) return false;
if (!href) return false;

return await caches.default.match(href);
}

/**
* @param {string} href
* @param {Response} response
* @returns
*/
put(href, response) {
if (this.noop) return false;
if (!href || !response) return false;

// todo: what does this return?
return caches.default.put(href, response);
}
}
17 changes: 16 additions & 1 deletion src/plugins/dns-op/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as dnsutil from "../../commons/dnsutil.js";
import * as bufutil from "../../commons/bufutil.js";
import * as util from "../../commons/util.js";
import * as envutil from "../../commons/envutil.js";
import { BlocklistFilter } from "../rethinkdns/filter.js";

export default class DNSResolver {
/**
Expand Down Expand Up @@ -163,6 +164,7 @@ export default class DNSResolver {
* @param {Object} ctx.userBlocklistInfo
* @param {String} ctx.userDnsResolverUrl
* @param {string} ctx.userBlockstamp
* @param {any} ctx.domainBlockstamp
* @param {function(function):void} ctx.dispatcher
* @returns {Promise<pres.RResp>}
*/
Expand Down Expand Up @@ -295,6 +297,13 @@ export default class DNSResolver {
return r;
}

/**
* @param {string} rxid
* @param {ArrayBuffer} raw
* @param {BlocklistFilter} blf
* @param {any} stamps
* @returns
*/
async makeRdnsResponse(rxid, raw, blf, stamps = null) {
if (!raw) throw new Error(rxid + " mk-res no upstream result");

Expand All @@ -310,7 +319,13 @@ export default class DNSResolver {
return pres.dnsResponse(dnsPacket, raw, stamps);
}

primeCache(rxid, r, dispatcher) {
/**
* @param {string} rxid
* @param {pres.RespData} r
* @param {function(function):void} dispatcher
* @returns {Promise<void>}
*/
async primeCache(rxid, r, dispatcher) {
const blocked = r.isBlocked;

const k = cacheutil.makeHttpCacheKey(r.dnsPacket);
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/plugin-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ export function errResponse(id, err) {
return new RResp(data, hasex, id, st);
}

/**
* @param {Object} packet
* @param {ArrayBuffer} raw
* @param {Object?} stamps
* @returns {RespData}
*/
export function dnsResponse(packet = null, raw = null, stamps = null) {
if (util.emptyObj(packet) || bufutil.emptyBuf(raw)) {
throw new Error("empty packet for dns-res");
Expand Down

0 comments on commit 0d007fd

Please sign in to comment.