Compare commits
No commits in common. "e2ed9ed1847b456d90f901f6e5bc8db11f8cb94a" and "0a780414e2bc5dbb4e991408c8df599dfebcf018" have entirely different histories.
e2ed9ed184
...
0a780414e2
|
@ -3,10 +3,10 @@ export interface Peer {
|
||||||
host: string;
|
host: string;
|
||||||
port: number;
|
port: number;
|
||||||
}
|
}
|
||||||
export type PeerSource = (pubkey: Buffer, options?: any) => Promise<boolean | Peer>;
|
export type PeerSource = (pubkey: Buffer) => Promise<boolean | Peer>;
|
||||||
export declare class PeerDiscovery {
|
export declare class PeerDiscovery {
|
||||||
private _sources;
|
private _sources;
|
||||||
registerSource(name: string, source: PeerSource): boolean;
|
registerSource(name: string, source: PeerSource): boolean;
|
||||||
removeSource(name: string): boolean;
|
removeSource(name: string): boolean;
|
||||||
discover(pubkey: string | Buffer, options?: {}): Promise<Peer | boolean>;
|
discover(pubkey: string | Buffer): Promise<Peer | boolean>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,12 @@ class PeerDiscovery {
|
||||||
this._sources.delete(name);
|
this._sources.delete(name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
async discover(pubkey, options = {}) {
|
async discover(pubkey) {
|
||||||
if (!b4a_1.default.isBuffer(pubkey)) {
|
if (!b4a_1.default.isBuffer(pubkey)) {
|
||||||
pubkey = b4a_1.default.from(pubkey, "hex");
|
pubkey = b4a_1.default.from(pubkey, "hex");
|
||||||
}
|
}
|
||||||
for (const source of this._sources.values()) {
|
for (const source of this._sources.values()) {
|
||||||
const result = await source(pubkey, options);
|
const result = await source(pubkey);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
12
src/index.ts
12
src/index.ts
|
@ -5,10 +5,7 @@ export interface Peer {
|
||||||
port: number;
|
port: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PeerSource = (
|
export type PeerSource = (pubkey: Buffer) => Promise<boolean | Peer>;
|
||||||
pubkey: Buffer,
|
|
||||||
options?: any
|
|
||||||
) => Promise<boolean | Peer>;
|
|
||||||
|
|
||||||
export class PeerDiscovery {
|
export class PeerDiscovery {
|
||||||
private _sources: Map<string, PeerSource> = new Map<string, PeerSource>();
|
private _sources: Map<string, PeerSource> = new Map<string, PeerSource>();
|
||||||
|
@ -32,16 +29,13 @@ export class PeerDiscovery {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async discover(
|
public async discover(pubkey: string | Buffer): Promise<Peer | boolean> {
|
||||||
pubkey: string | Buffer,
|
|
||||||
options = {}
|
|
||||||
): Promise<Peer | boolean> {
|
|
||||||
if (!b4a.isBuffer(pubkey)) {
|
if (!b4a.isBuffer(pubkey)) {
|
||||||
pubkey = b4a.from(pubkey, "hex") as Buffer;
|
pubkey = b4a.from(pubkey, "hex") as Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const source of this._sources.values()) {
|
for (const source of this._sources.values()) {
|
||||||
const result = await source(pubkey, options);
|
const result = await source(pubkey);
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in New Issue