Skip to content

Commit

Permalink
feat: add IP address to client context
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyTseng committed Sep 22, 2024
1 parent fe0e752 commit 5bdcdff
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/nostr-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ export class NostrRelay {
* client connects to the Nostr Relay server.
*
* @param client Client instance, usually a WebSocket
* @param ip IP address of the client
*/
handleConnection(client: Client): void {
const ctx = this.getClientContext(client);
handleConnection(client: Client, ip?: string): void {
const ctx = this.getClientContext(client, ip);
if (this.hostname) {
ctx.sendMessage(createOutgoingAuthMessage(ctx.id));
}
Expand Down Expand Up @@ -346,13 +347,14 @@ export class NostrRelay {
});
}

private getClientContext(client: Client): ClientContext {
private getClientContext(client: Client, ip?: string): ClientContext {
const ctx = this.clientContexts.get(client);
if (ctx) return ctx;

const newCtx = new ClientContext(client, {
maxSubscriptionsPerClient: this.options.maxSubscriptionsPerClient,
});
newCtx.ip = ip;
this.clientContexts.set(client, newCtx);
return newCtx;
}
Expand Down

0 comments on commit 5bdcdff

Please sign in to comment.