diff --git a/app/modules/crawler/lib/sandbox.ts b/app/modules/crawler/lib/sandbox.ts index 047a3d5e1ee09075ae881dc561e681ac98221c6a..438ac2713a3caff30eef229577da9586a680f25c 100644 --- a/app/modules/crawler/lib/sandbox.ts +++ b/app/modules/crawler/lib/sandbox.ts @@ -30,7 +30,7 @@ export const pullSandbox = async (currency:string, fromHost:string, fromPort:num } } -export const pullSandboxToLocalServer = async (currency:string, fromHost:any, toServer:Server, logger:any, watcher:any = null, nbCertsMin = 1) => { +export const pullSandboxToLocalServer = async (currency:string, fromHost:any, toServer:Server, logger:any, watcher:any = null, nbCertsMin = 1, notify = true) => { let res try { res = await fromHost.getRequirementsPending(nbCertsMin || 1) @@ -44,19 +44,19 @@ export const pullSandboxToLocalServer = async (currency:string, fromHost:any, to for (let i = 0; i < docs.identities.length; i++) { const idty = docs.identities[i]; watcher && watcher.writeStatus('Identity ' + (i+1) + '/' + docs.identities.length) - await submitIdentityToServer(idty, toServer, logger) + await submitIdentityToServer(idty, toServer, notify, logger) } for (let i = 0; i < docs.certifications.length; i++) { const cert = docs.certifications[i]; watcher && watcher.writeStatus('Certification ' + (i+1) + '/' + docs.certifications.length) - await submitCertificationToServer(cert, toServer, logger) + await submitCertificationToServer(cert, toServer, notify, logger) } for (let i = 0; i < docs.memberships.length; i++) { const ms = docs.memberships[i]; watcher && watcher.writeStatus('Membership ' + (i+1) + '/' + docs.memberships.length) - await submitMembershipToServer(ms, toServer, logger) + await submitMembershipToServer(ms, toServer, notify, logger) } } } @@ -132,30 +132,30 @@ async function submitMembership(ms:any, to:any, logger:any = null) { } } -async function submitIdentityToServer(idty:any, toServer:any, logger:any = null) { +async function submitIdentityToServer(idty:any, toServer:any, notify:boolean, logger:any) { try { const obj = parsers.parseIdentity.syncWrite(idty) - await toServer.writeIdentity(obj) + await toServer.writeIdentity(obj, notify) logger && logger.trace('Sandbox pulling: success with identity \'%s\'', idty.uid) } catch (e) { // Silent error } } -async function submitCertificationToServer(cert:any, toServer:any, logger:any = null) { +async function submitCertificationToServer(cert:any, toServer:any, notify:boolean, logger:any) { try { const obj = parsers.parseCertification.syncWrite(cert) - await toServer.writeCertification(obj) + await toServer.writeCertification(obj, notify) logger && logger.trace('Sandbox pulling: success with cert key %s => %s', cert.from.substr(0, 6), cert.idty_uid) } catch (e) { // Silent error } } -async function submitMembershipToServer(ms:any, toServer:any, logger:any = null) { +async function submitMembershipToServer(ms:any, toServer:any, notify:boolean, logger:any) { try { const obj = parsers.parseMembership.syncWrite(ms) - await toServer.writeMembership(obj) + await toServer.writeMembership(obj, notify) logger && logger.trace('Sandbox pulling: success with membership \'%s\'', ms.uid) } catch (e) { // Silent error diff --git a/app/modules/crawler/lib/sync.ts b/app/modules/crawler/lib/sync.ts index d942daab1213aeeb1fe550005f407f5b9dfcc34a..046006982cc4e45b0727424f668255c2b230394b 100644 --- a/app/modules/crawler/lib/sync.ts +++ b/app/modules/crawler/lib/sync.ts @@ -300,7 +300,7 @@ export class Synchroniser extends stream.Duplex { // Sandboxes //======= this.watcher.writeStatus('Synchronizing the sandboxes...'); - await pullSandboxToLocalServer(this.conf.currency, node, this.server, this.server.logger, this.watcher) + await pullSandboxToLocalServer(this.conf.currency, node, this.server, this.server.logger, this.watcher, 1, false) //======= // Peers diff --git a/server.ts b/server.ts index eb766f3e1ff55403e71f55302db64ee798999e8a..e6e35e10c13c16ad752bc7de9fc02c873ea4128e 100644 --- a/server.ts +++ b/server.ts @@ -195,9 +195,11 @@ export class Server extends stream.Duplex implements HookableServer { return await this.writeIdentity(obj) } - async writeIdentity(obj:any) { + async writeIdentity(obj:any, notify = true) { const res = await this.IdentityService.submitIdentity(obj) - this.emitDocument(res, DuniterDocument.ENTITY_IDENTITY) + if (notify) { + this.emitDocument(res, DuniterDocument.ENTITY_IDENTITY) + } return res } @@ -206,9 +208,11 @@ export class Server extends stream.Duplex implements HookableServer { return await this.writeCertification(obj) } - async writeCertification(obj:any) { + async writeCertification(obj:any, notify = true) { const res = await this.IdentityService.submitCertification(obj) - this.emitDocument(res, DuniterDocument.ENTITY_CERTIFICATION) + if (notify) { + this.emitDocument(res, DuniterDocument.ENTITY_CERTIFICATION) + } return res } @@ -217,9 +221,11 @@ export class Server extends stream.Duplex implements HookableServer { return await this.writeMembership(obj) } - async writeMembership(obj:any) { + async writeMembership(obj:any, notify = true) { const res = await this.MembershipService.submitMembership(obj) - this.emitDocument(res, DuniterDocument.ENTITY_MEMBERSHIP) + if (notify) { + this.emitDocument(res, DuniterDocument.ENTITY_MEMBERSHIP) + } return res }