From f1f91b12542ce2e24f732f050f59932b134006c8 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 12 Aug 2016 03:38:24 -0400 Subject: [PATCH] solution for #2, send updates to all workers, all workers update caches --- master.js | 6 +++++- worker.js | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/master.js b/master.js index cde2d98..9e31650 100644 --- a/master.js +++ b/master.js @@ -4,6 +4,7 @@ // opts.approveDomains(options, certs, cb) module.exports.create = function (opts) { opts = opts || { }; + opts._workers = []; opts.webrootPath = opts.webrootPath || require('os').tmpdir() + require('path').sep + 'acme-challenge'; if (!opts.letsencrypt) { opts.letsencrypt = require('letsencrypt').create(opts); } if ('function' !== typeof opts.approveDomains) { @@ -23,6 +24,7 @@ module.exports.create = function (opts) { opts._le = opts.letsencrypt; opts.addWorker = function (worker) { + opts._workers.push(worker); worker.on('online', function () { log(opts.debug, 'worker is up'); @@ -75,7 +77,9 @@ module.exports.create = function (opts) { promise.then(function (certs) { log(opts.debug, 'Approval got certs', certs); // certs = { subject, domains, issuedAt, expiresAt, privkey, cert, chain }; - worker.send({ type: 'LE_RESPONSE', domain: msg.domain, certs: certs }); + opts._workers.forEach(function (w) { + w.send({ type: 'LE_RESPONSE', domain: msg.domain, certs: certs }); + }); }, function (err) { log(opts.debug, 'Approval got ERROR', err.stack || err); worker.send({ type: 'LE_RESPONSE', domain: msg.domain, error: err }); diff --git a/worker.js b/worker.js index 47ec3bc..4e3d501 100644 --- a/worker.js +++ b/worker.js @@ -15,7 +15,14 @@ function log(debug) { module.exports.create = function (opts) { - + // if another worker updates the certs, + // receive a copy from master here as well + // and update the sni cache manually + process.on('message', function (msg) { + if ('LE_RESPONSE' === msg.type && msg.certs) { + opts.sni.cacheCerts(msg.certs); + } + }); opts.sni = require('le-sni-auto').create({ notBefore: opts.notBefore || (10 * 24 * 60 * 60 * 1000)