fix: fix outdated reads. port of s5 08c4bda5c1109673fba907ba119c9855fc3fcf68 0d2bf39845b37dd0b2ebe06be34c5d51e7060280

This commit is contained in:
Derrick Hammer 2023-09-04 07:19:19 -04:00
parent 614a699cc3
commit 9c471e6949
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 2 deletions

View File

@ -26,6 +26,7 @@ export class RegistryService {
private node: S5Node; private node: S5Node;
private logger: Logger; private logger: Logger;
private streams: Map<string, EventEmitter> = new Map<string, EventEmitter>(); private streams: Map<string, EventEmitter> = new Map<string, EventEmitter>();
private subs: Map<string, Multihash> = new Map<string, Multihash>();
constructor(node: S5Node) { constructor(node: S5Node) {
this.node = node; this.node = node;
@ -125,7 +126,8 @@ export class RegistryService {
async get(pk: Uint8Array): Promise<SignedRegistryEntry | null> { async get(pk: Uint8Array): Promise<SignedRegistryEntry | null> {
const key = new Multihash(pk); const key = new Multihash(pk);
if (this.streams.has(key.toString())) { const keyString = key.toString();
if (this.subs.has(keyString)) {
this.logger.verbose(`[registry] get (subbed) ${key}`); this.logger.verbose(`[registry] get (subbed) ${key}`);
let res = await this.getFromDB(pk); let res = await this.getFromDB(pk);
if (res !== null) { if (res !== null) {
@ -136,7 +138,10 @@ export class RegistryService {
return this.getFromDB(pk); return this.getFromDB(pk);
} else { } else {
this.sendRegistryRequest(pk); this.sendRegistryRequest(pk);
this.streams.set(key.toString(), new EventEmitter()); this.subs.set(keyString, key);
if (!this.streams.has(keyString)) {
this.streams.set(keyString, new EventEmitter());
}
let res = await this.getFromDB(pk); let res = await this.getFromDB(pk);
if (res === null) { if (res === null) {
this.logger.verbose(`[registry] get (clean) ${key}`); this.logger.verbose(`[registry] get (clean) ${key}`);