Skip to content

Commit

Permalink
feat:filter csrs on replicated event
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-RF committed Oct 24, 2023
1 parent 100add9 commit 8463b91
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/backend/src/nest/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
verifyUserCert,
parseCertificationRequest,
getReqFieldValue,
loadCSR,
} from '@quiet/identity'
import type { IPFS } from 'ipfs-core'
import OrbitDB from 'orbit-db'
Expand Down Expand Up @@ -400,8 +401,26 @@ export class StorageService extends EventEmitter {
this.certificatesRequests.events.on('replicated', async () => {
this.logger('REPLICATED: CSRs')
const allCsrs = this.getAllEventLogEntries(this.certificatesRequests)

const filteredCsrsMap: Map<string, string> = new Map()

await Promise.all(
allCsrs.map(async csr => {
const parsedCsr = await loadCSR(csr)
const pubKey = keyFromCertificate(parsedCsr)

if (filteredCsrsMap.has(pubKey)) {
filteredCsrsMap.delete(pubKey)
}

filteredCsrsMap.set(pubKey, csr)
})
)

const filteredCsrsArr = [...filteredCsrsMap.values()]

const allCertificates = this.getAllEventLogEntries(this.certificates)
this.emit(StorageEvents.REPLICATED_CSR, { csrs: allCsrs, certificates: allCertificates })
this.emit(StorageEvents.REPLICATED_CSR, { csrs: filteredCsrsArr, certificates: allCertificates })
await this.updatePeersList()
})
this.certificatesRequests.events.on('write', async (_address, entry) => {
Expand Down

0 comments on commit 8463b91

Please sign in to comment.