bip150: use map objects.
This commit is contained in:
parent
963c2173dd
commit
9743e8e314
@ -470,7 +470,7 @@ function AuthDB(options) {
|
|||||||
this.prefix = null;
|
this.prefix = null;
|
||||||
this.dnsKnown = [];
|
this.dnsKnown = [];
|
||||||
|
|
||||||
this.known = {};
|
this.known = new Map();
|
||||||
this.authorized = [];
|
this.authorized = [];
|
||||||
|
|
||||||
this._init(options);
|
this._init(options);
|
||||||
@ -556,7 +556,7 @@ AuthDB.prototype.addKnown = function addKnown(host, key) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.known[host] = key;
|
this.known.set(host, key);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -578,7 +578,7 @@ AuthDB.prototype.addAuthorized = function addAuthorized(key) {
|
|||||||
AuthDB.prototype.setKnown = function setKnown(map) {
|
AuthDB.prototype.setKnown = function setKnown(map) {
|
||||||
let keys = Object.keys(map);
|
let keys = Object.keys(map);
|
||||||
|
|
||||||
this.known = {};
|
this.known.clear();
|
||||||
|
|
||||||
for (let host of keys) {
|
for (let host of keys) {
|
||||||
let key = map[host];
|
let key = map[host];
|
||||||
@ -605,7 +605,7 @@ AuthDB.prototype.setAuthorized = function setAuthorized(keys) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
AuthDB.prototype.getKnown = function getKnown(hostname) {
|
AuthDB.prototype.getKnown = function getKnown(hostname) {
|
||||||
let known = this.known[hostname];
|
let known = this.known.get(hostname);
|
||||||
let addr;
|
let addr;
|
||||||
|
|
||||||
if (known)
|
if (known)
|
||||||
@ -613,7 +613,7 @@ AuthDB.prototype.getKnown = function getKnown(hostname) {
|
|||||||
|
|
||||||
addr = IP.fromHostname(hostname);
|
addr = IP.fromHostname(hostname);
|
||||||
|
|
||||||
return this.known[addr.host];
|
return this.known.get(addr.host);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -625,8 +625,8 @@ AuthDB.prototype.getKnown = function getKnown(hostname) {
|
|||||||
AuthDB.prototype.lookup = async function lookup() {
|
AuthDB.prototype.lookup = async function lookup() {
|
||||||
let jobs = [];
|
let jobs = [];
|
||||||
|
|
||||||
for (let addr of this.dnsKnown)
|
for (let [addr, key] of this.dnsKnown)
|
||||||
jobs.push(this.populate(addr[0], addr[1]));
|
jobs.push(this.populate(addr, key));
|
||||||
|
|
||||||
await Promise.all(jobs);
|
await Promise.all(jobs);
|
||||||
};
|
};
|
||||||
@ -658,7 +658,7 @@ AuthDB.prototype.populate = async function populate(addr, key) {
|
|||||||
if (addr.port !== 0)
|
if (addr.port !== 0)
|
||||||
host = IP.toHostname(host, addr.port);
|
host = IP.toHostname(host, addr.port);
|
||||||
|
|
||||||
this.known[host] = key;
|
this.known.set(host, key);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user