mirror of
https://github.com/Cameri/nostream.git
synced 2025-03-17 21:31:48 +01:00
chore: update logging
Signed-off-by: Ricardo Arturo Cabral Mejía <me@ricardocabral.io>
This commit is contained in:
parent
9d1a027c0d
commit
af217fb798
@ -9,6 +9,7 @@ import { Mirror, Settings } from '../@types/settings'
|
||||
import { createLogger } from '../factories/logger-factory'
|
||||
import { IRunnable } from '../@types/base'
|
||||
import { OutgoingEventMessage } from '../@types/messages'
|
||||
import { RelayedEvent } from '../@types/event'
|
||||
import { WebSocketServerAdapterEvent } from '../constants/adapter'
|
||||
|
||||
const debug = createLogger('static-mirror-worker')
|
||||
@ -59,13 +60,13 @@ export class StaticMirroringWorker implements IRunnable {
|
||||
.on('message', async function (raw: RawData) {
|
||||
try {
|
||||
const message = JSON.parse(raw.toString('utf8')) as OutgoingEventMessage
|
||||
debug('received from %s: %o', config.address, message)
|
||||
|
||||
if (!Array.isArray(message)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (message[0] !== 'EVENT' || message[1] !== subscriptionId) {
|
||||
debug('%s >> local: %o', config.address, message)
|
||||
return
|
||||
}
|
||||
|
||||
@ -82,6 +83,7 @@ export class StaticMirroringWorker implements IRunnable {
|
||||
since = Math.floor(Date.now()) - 30
|
||||
|
||||
if (cluster.isWorker && typeof process.send === 'function') {
|
||||
debug('%s >> local: %s', config.address, event.id)
|
||||
process.send({
|
||||
eventName: WebSocketServerAdapterEvent.Broadcast,
|
||||
event,
|
||||
@ -118,9 +120,12 @@ export class StaticMirroringWorker implements IRunnable {
|
||||
return
|
||||
}
|
||||
|
||||
const eventToRelay = createRelayedEventMessage(message.event as any, this.config.secret)
|
||||
debug('relaying from %s to %s: %o', message.source, this.config.address, eventToRelay)
|
||||
this.client.send(JSON.stringify(eventToRelay))
|
||||
const event = message.event as RelayedEvent
|
||||
|
||||
const eventToRelay = createRelayedEventMessage(event, this.config.secret)
|
||||
const outboundMessage = JSON.stringify(eventToRelay)
|
||||
debug('%s >> %s: %s', message.source ?? 'local', this.config.address, outboundMessage)
|
||||
this.client.send(outboundMessage)
|
||||
}
|
||||
|
||||
private onError(error: Error) {
|
||||
|
@ -10,10 +10,11 @@ import { createLogger } from '../factories/logger-factory'
|
||||
|
||||
if (released) {
|
||||
const now = new Date().getTime()
|
||||
lastUpdate[this.config.tag] = lastUpdate[this.config.tag] ?? now
|
||||
if (now - lastUpdate[this.config.tag] >= 60000) {
|
||||
lastUpdate[this.config.tag] = now
|
||||
console.log(`${this.config.tag} connection pool: ${this.pool.numUsed()} used / ${this.pool.numFree()} free / ${this.pool.numPendingAcquires()} pending`)
|
||||
const { tag } = this.config
|
||||
lastUpdate[tag] = lastUpdate[tag] ?? now
|
||||
if (now - lastUpdate[tag] >= 60000) {
|
||||
lastUpdate[tag] = now
|
||||
console.log(`${tag} connection pool: ${this.pool.numUsed()} used / ${this.pool.numFree()} free / ${this.pool.numPendingAcquires()} pending`)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,9 +162,7 @@ export const isDelegatedEventValid = async (event: Event): Promise<boolean> => {
|
||||
export const getEventHash = async (event: Event | UnidentifiedEvent | UnsignedEvent): Promise<string> => {
|
||||
const id = await secp256k1.utils.sha256(Buffer.from(JSON.stringify(serializeEvent(event))))
|
||||
|
||||
return Buffer.from(
|
||||
id
|
||||
).toString('hex')
|
||||
return Buffer.from(id).toString('hex')
|
||||
}
|
||||
|
||||
export const isEventIdValid = async (event: Event): Promise<boolean> => {
|
||||
@ -225,7 +223,7 @@ export const encryptKind4Event = (
|
||||
export const broadcastEvent = async (event: Event): Promise<Event> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!cluster.isWorker || typeof process.send === 'undefined') {
|
||||
return Promise.resolve(event)
|
||||
return resolve(event)
|
||||
}
|
||||
|
||||
process.send(
|
||||
|
Loading…
x
Reference in New Issue
Block a user