Compare commits

...

2 Commits

Author SHA1 Message Date
Derrick Hammer e2ed9ed184
*Update dist 2023-01-15 02:58:50 -05:00
Derrick Hammer f278892f76
*Add optional options object to peer discovery 2023-01-15 02:58:08 -05:00
3 changed files with 13 additions and 7 deletions

4
dist/index.d.ts vendored
View File

@ -3,10 +3,10 @@ export interface Peer {
host: string;
port: number;
}
export type PeerSource = (pubkey: Buffer) => Promise<boolean | Peer>;
export type PeerSource = (pubkey: Buffer, options?: any) => 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>;
discover(pubkey: string | Buffer, options?: {}): Promise<Peer | boolean>;
}

4
dist/index.js vendored
View File

@ -21,12 +21,12 @@ class PeerDiscovery {
this._sources.delete(name);
return true;
}
async discover(pubkey) {
async discover(pubkey, options = {}) {
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);
const result = await source(pubkey, options);
if (result) {
return result;
}

View File

@ -5,7 +5,10 @@ export interface Peer {
port: number;
}
export type PeerSource = (pubkey: Buffer) => Promise<boolean | Peer>;
export type PeerSource = (
pubkey: Buffer,
options?: any
) => Promise<boolean | Peer>;
export class PeerDiscovery {
private _sources: Map<string, PeerSource> = new Map<string, PeerSource>();
@ -29,13 +32,16 @@ export class PeerDiscovery {
return true;
}
public async discover(pubkey: string | Buffer): Promise<Peer | boolean> {
public async discover(
pubkey: string | Buffer,
options = {}
): Promise<Peer | boolean> {
if (!b4a.isBuffer(pubkey)) {
pubkey = b4a.from(pubkey, "hex") as Buffer;
}
for (const source of this._sources.values()) {
const result = await source(pubkey);
const result = await source(pubkey, options);
if (result) {
return result;