Skip to content

Commit

Permalink
Emit csrs on replicated event
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkabuki committed Sep 12, 2023
1 parent 43513ed commit 5249807
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,12 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI
console.log('emitting deleted channel event back to state manager')
this.serverIoProvider.io.emit(SocketActionTypes.CHANNEL_DELETION_RESPONSE, payload)
})
this.storageService.on(StorageEvents.REPLICATED_CSR, async (payload: { csr: string }) => {
this.storageService.on(StorageEvents.REPLICATED_CSR, async (payload: string[]) => {
console.log(`On ${StorageEvents.REPLICATED_CSR}`)
this.serverIoProvider.io.emit(SocketActionTypes.RESPONSE_GET_CSRS, { csrs: [payload.csr] })
this.registrationService.emit(RegistrationEvents.REGISTER_USER_CERTIFICATE, payload.csr)
this.serverIoProvider.io.emit(SocketActionTypes.RESPONSE_GET_CSRS, { csrs: payload })
payload.forEach(csr =>
this.registrationService.emit(RegistrationEvents.REGISTER_USER_CERTIFICATE, csr)
)
})
this.storageService.on(StorageEvents.REPLICATED_COMMUNITY_METADATA, (payload: CommunityMetadata) => {
console.log(`On ${StorageEvents.REPLICATED_COMMUNITY_METADATA}: ${payload}`)
Expand Down
6 changes: 4 additions & 2 deletions packages/backend/src/nest/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,16 +415,18 @@ export class StorageService extends EventEmitter {
)
return
}
this.emit(StorageEvents.REPLICATED_CSR, { csr })
this.emit(StorageEvents.REPLICATED_CSR, [csr])
})
this.certificatesRequests.events.on('replicated', async () => {
this.logger('REPLICATED: CSRs')
const allCsrs = this.getAllEventLogEntries(this.certificatesRequests)
this.emit(StorageEvents.REPLICATED_CSR, allCsrs)
await this.updatePeersList()
})
this.certificatesRequests.events.on('write', async (_address, entry) => {
const csr: string = entry.payload.value
this.logger('Saved CSR locally', csr)
this.emit(StorageEvents.REPLICATED_CSR, { csr })
this.emit(StorageEvents.REPLICATED_CSR, [csr])
await this.updatePeersList()
})

Expand Down

0 comments on commit 5249807

Please sign in to comment.