Skip to content

Commit df2f3f2

Browse files
committed
make fingerprint resolver optional and add get all api
1 parent 92413a9 commit df2f3f2

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

src/FingerprintResolver.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ export default class FingerprintResolver extends HttpServer {
4545
res.writeHead(200, { "content-type": "application/json" });
4646
res.end(JSON.stringify({ ok: true }));
4747
});
48+
this.addListener("/all", ({ res }) => {
49+
const all = Array.from(this.fingerprintByTuple.entries()).map(([key, record]) => ({
50+
key,
51+
protocol: record.protocol,
52+
gatePort: record.gatePort,
53+
channelPort: record.channelPort,
54+
fingerprint: record.fingerprint,
55+
createdAt: record.createdAt,
56+
expiresAt: record.expiresAt,
57+
}));
58+
res.writeHead(200, { "content-type": "application/json" });
59+
res.end(JSON.stringify(all));
60+
});
4861
this.addListener("/resolve", ({ req, res, url }) => {
4962
try {
5063
if (!this.authorize(req)) {
@@ -97,8 +110,7 @@ export default class FingerprintResolver extends HttpServer {
97110
}
98111

99112
public start() {
100-
// HttpServer starts listening in the parent constructor.
101-
// Keep this method for backward compatibility with existing call sites.
113+
102114
}
103115

104116
public async stop() {

src/ServiceProvider.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,22 @@ import { Protocol, protocolToString } from "./Protocol.js";
1212

1313
export default class ServiceProvider extends Peer {
1414
private services: Array<Service> = [];
15-
private readonly fingerprintResolver: FingerprintResolver;
15+
private readonly fingerprintResolver?: FingerprintResolver;
1616
private readonly ingressPolicy?: IngressPolicy;
1717

1818
constructor(secret: string, opts?: object, fingerprintResolverOpts?: FingerprintResolverOptions, ingressPolicy?: IngressPolicy) {
1919
super(secret, false, opts);
20-
this.fingerprintResolver = new FingerprintResolver(fingerprintResolverOpts);
20+
if (fingerprintResolverOpts) {
21+
this.fingerprintResolver = new FingerprintResolver(fingerprintResolverOpts);
22+
this.fingerprintResolver.start();
23+
}
2124
this.ingressPolicy = ingressPolicy;
22-
this.fingerprintResolver.start();
2325
this.start().catch(console.error);
26+
2427
}
2528

2629
public override async stop() {
27-
await this.fingerprintResolver.stop();
30+
await this.fingerprintResolver?.stop();
2831
await super.stop();
2932
}
3033

@@ -68,11 +71,11 @@ export default class ServiceProvider extends Peer {
6871
}
6972

7073
private registerFingerprintTuple(channel: any) {
71-
this.fingerprintResolver.registerChannel(channel);
74+
this.fingerprintResolver?.registerChannel(channel);
7275
}
7376

7477
private unregisterFingerprintTuple(channel: any) {
75-
this.fingerprintResolver.unregisterChannel(channel);
78+
this.fingerprintResolver?.unregisterChannel(channel);
7679
}
7780

7881
private createRoutingTableFragment(): RoutingTable {

src/cli.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,12 @@ async function cli(processArgv: string[]) {
204204
ctx.serviceProvider = new ServiceProvider(
205205
secret,
206206
undefined,
207+
fingerprintResolverPort ?
207208
{
208-
host: argv.fingerprintResolverHost,
209+
host: argv.fingerprintResolverHost ?? "127.0.0.1",
209210
port: fingerprintResolverPort,
210211
basicAuth: argv.fingerprintResolverBasicAuth ?? null,
211-
},
212+
} : undefined,
212213
providerIngressPolicy,
213214
);
214215

0 commit comments

Comments
 (0)