*Add dist
This commit is contained in:
parent
e340a79d5c
commit
0a780414e2
|
@ -0,0 +1,12 @@
|
|||
/// <reference types="node" />
|
||||
export interface Peer {
|
||||
host: string;
|
||||
port: number;
|
||||
}
|
||||
export type PeerSource = (pubkey: Buffer) => Promise<boolean | Peer>;
|
||||
export declare class PeerDiscovery {
|
||||
private _sources;
|
||||
registerSource(name: string, source: PeerSource): boolean;
|
||||
removeSource(name: string): boolean;
|
||||
discover(pubkey: string | Buffer): Promise<Peer | boolean>;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PeerDiscovery = void 0;
|
||||
const b4a_1 = __importDefault(require("b4a"));
|
||||
class PeerDiscovery {
|
||||
_sources = new Map();
|
||||
registerSource(name, source) {
|
||||
if (this._sources.has(name)) {
|
||||
return false;
|
||||
}
|
||||
this._sources.set(name, source);
|
||||
return true;
|
||||
}
|
||||
removeSource(name) {
|
||||
if (!this._sources.has(name)) {
|
||||
return false;
|
||||
}
|
||||
this._sources.delete(name);
|
||||
return true;
|
||||
}
|
||||
async discover(pubkey) {
|
||||
if (!b4a_1.default.isBuffer(pubkey)) {
|
||||
pubkey = b4a_1.default.from(pubkey, "hex");
|
||||
}
|
||||
for (const source of this._sources.values()) {
|
||||
const result = await source(pubkey);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
exports.PeerDiscovery = PeerDiscovery;
|
||||
//# sourceMappingURL=index.js.map
|
Loading…
Reference in New Issue