diff --git a/api/grpc/index.ts b/api/grpc/index.ts index aab0127..dbe4a04 100644 --- a/api/grpc/index.ts +++ b/api/grpc/index.ts @@ -10,6 +10,7 @@ import * as path from 'path' const constants = require(path.join(__dirname,'../../config/constants.json')) const ERR_CODE_UNAVAILABLE = 14 +const ERR_CODE_STREAM_REMOVED = 2 // VERIFY PUBKEY OF SENDER async function parseAndVerifyPayload(data){ @@ -173,16 +174,18 @@ function subscribeInvoices(actions) { call.on('status', function(status) { console.log("Status", status); // The server is unavailable, trying to reconnect. - if (status.code == ERR_CODE_UNAVAILABLE) { - reconnectToLND(); + if (status.code == ERR_CODE_UNAVAILABLE || status.code == ERR_CODE_STREAM_REMOVED) { + i = 0 + reconnectToLND(Math.random()); } else { resolve(status); } }) call.on('error', function(err){ console.error(err) - if (err.code == ERR_CODE_UNAVAILABLE) { - reconnectToLND(); + if (err.code == ERR_CODE_UNAVAILABLE || err.code == ERR_CODE_STREAM_REMOVED) { + i = 0 + reconnectToLND(Math.random()); } else { reject(err) } @@ -191,7 +194,8 @@ function subscribeInvoices(actions) { const now = moment().format('YYYY-MM-DD HH:mm:ss').trim(); console.log(`Closed stream ${now}`); // The server has closed the stream. - reconnectToLND() + i = 0 + reconnectToLND(Math.random()) }) setTimeout(()=>{ resolve(null) @@ -200,7 +204,9 @@ function subscribeInvoices(actions) { } var i = 0 -async function reconnectToLND(){ +var ctx = 0 +async function reconnectToLND(innerCtx:number){ + ctx = innerCtx i++ console.log(`=> [lnd] reconnecting... attempt #${i}`) try { @@ -209,7 +215,9 @@ async function reconnectToLND(){ console.log(`=> [lnd] reconnected! ${now}`) } catch(e) { setTimeout(async()=>{ // retry each 2 secs - await reconnectToLND() + if(ctx===innerCtx) { // if another retry fires, then this will not run + await reconnectToLND(innerCtx) + } },2000) } } diff --git a/dist/api/grpc/index.js b/dist/api/grpc/index.js index 26d5ec9..b0d4800 100644 --- a/dist/api/grpc/index.js +++ b/dist/api/grpc/index.js @@ -20,6 +20,7 @@ const moment = require("moment"); const path = require("path"); const constants = require(path.join(__dirname, '../../config/constants.json')); const ERR_CODE_UNAVAILABLE = 14; +const ERR_CODE_STREAM_REMOVED = 2; // VERIFY PUBKEY OF SENDER function parseAndVerifyPayload(data) { return __awaiter(this, void 0, void 0, function* () { @@ -184,8 +185,9 @@ function subscribeInvoices(actions) { call.on('status', function (status) { console.log("Status", status); // The server is unavailable, trying to reconnect. - if (status.code == ERR_CODE_UNAVAILABLE) { - reconnectToLND(); + if (status.code == ERR_CODE_UNAVAILABLE || status.code == ERR_CODE_STREAM_REMOVED) { + i = 0; + reconnectToLND(Math.random()); } else { resolve(status); @@ -193,8 +195,9 @@ function subscribeInvoices(actions) { }); call.on('error', function (err) { console.error(err); - if (err.code == ERR_CODE_UNAVAILABLE) { - reconnectToLND(); + if (err.code == ERR_CODE_UNAVAILABLE || err.code == ERR_CODE_STREAM_REMOVED) { + i = 0; + reconnectToLND(Math.random()); } else { reject(err); @@ -204,7 +207,8 @@ function subscribeInvoices(actions) { const now = moment().format('YYYY-MM-DD HH:mm:ss').trim(); console.log(`Closed stream ${now}`); // The server has closed the stream. - reconnectToLND(); + i = 0; + reconnectToLND(Math.random()); }); setTimeout(() => { resolve(null); @@ -213,8 +217,10 @@ function subscribeInvoices(actions) { } exports.subscribeInvoices = subscribeInvoices; var i = 0; -function reconnectToLND() { +var ctx = 0; +function reconnectToLND(innerCtx) { return __awaiter(this, void 0, void 0, function* () { + ctx = innerCtx; i++; console.log(`=> [lnd] reconnecting... attempt #${i}`); try { @@ -224,7 +230,9 @@ function reconnectToLND() { } catch (e) { setTimeout(() => __awaiter(this, void 0, void 0, function* () { - yield reconnectToLND(); + if (ctx === innerCtx) { + yield reconnectToLND(innerCtx); + } }), 2000); } }); diff --git a/dist/api/grpc/index.js.map b/dist/api/grpc/index.js.map index 3827747..f021b17 100644 --- a/dist/api/grpc/index.js.map +++ b/dist/api/grpc/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api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A;AACH,CAAC;AAsBA,8CAAiB;AApBlB,IAAI,CAAC,GAAG,CAAC,CAAA;AACT,IAAI,GAAG,GAAG,CAAC,CAAA;AACX,SAAe,cAAc,CAAC,QAAe;;QAC5C,GAAG,GAAG,QAAQ,CAAA;QACd,CAAC,EAAE,CAAA;QACH,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,EAAE,CAAC,CAAA;QACrD,IAAI;YACH,MAAM,WAAW,CAAC,oBAAoB,EAAE,CAAA;YACxC,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,IAAI,EAAE,CAAC;YAC1D,OAAO,CAAC,GAAG,CAAC,yBAAyB,GAAG,EAAE,CAAC,CAAA;SAC3C;QAAC,OAAM,CAAC,EAAE;YACV,UAAU,CAAC,GAAO,EAAE;gBACnB,IAAG,GAAG,KAAG,QAAQ,EAAE;oBAClB,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAA;iBAC9B;YACF,CAAC,CAAA,EAAC,IAAI,CAAC,CAAA;SACP;IACF,CAAC;CAAA"} \ No newline at end of file diff --git a/dist/public/js/app.js b/dist/public/js/app.js index 6ebc7cb..2e4ba48 100644 --- a/dist/public/js/app.js +++ b/dist/public/js/app.js @@ -31891,8 +31891,7 @@ function Media(props) { file = files[0] || {}; start = new Date(); _context2.next = 5; - return api_media.UPLOAD('upload/attachment', file, { - chat_uuid: '1234567890', + return api_media.UPLOAD('file', file, { name: file.name || 'filename', description: description || 'description', ttl: ttl @@ -31902,14 +31901,15 @@ function Media(props) { r = _context2.sent; end = new Date(); time = end.getTime() - start.getTime(); - console.log('Upload Timer: finished in', time, 'ms'); // await api.relay.POST('attachment', { + console.log('Upload Timer: finished in', time, 'ms'); + console.log(r); // await api.relay.POST('attachment', { // muid: r.muid, // file_name: r.filename, // chat_id: 13, // ttl: ttl, // }) - case 9: + case 10: case "end": return _context2.stop(); } diff --git a/frontend/components/Media/index.jsx b/frontend/components/Media/index.jsx index 364d953..cb199f9 100644 --- a/frontend/components/Media/index.jsx +++ b/frontend/components/Media/index.jsx @@ -43,8 +43,7 @@ export default function Media(props) { const ttl = 60*60*24*7 // one week const file = files[0] || {} var start = new Date(); - const r = await api.media.UPLOAD('upload/attachment',file,{ - chat_uuid: '1234567890', + const r = await api.media.UPLOAD('public',file,{ name: file.name||'filename', description: description||'description', ttl: ttl, @@ -52,6 +51,7 @@ export default function Media(props) { var end = new Date(); var time = end.getTime() - start.getTime(); console.log('Upload Timer: finished in', time, 'ms'); + console.log(r) // await api.relay.POST('attachment', { // muid: r.muid, // file_name: r.filename, diff --git a/public/js/app.js b/public/js/app.js index 6ebc7cb..2e4ba48 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -31891,8 +31891,7 @@ function Media(props) { file = files[0] || {}; start = new Date(); _context2.next = 5; - return api_media.UPLOAD('upload/attachment', file, { - chat_uuid: '1234567890', + return api_media.UPLOAD('file', file, { name: file.name || 'filename', description: description || 'description', ttl: ttl @@ -31902,14 +31901,15 @@ function Media(props) { r = _context2.sent; end = new Date(); time = end.getTime() - start.getTime(); - console.log('Upload Timer: finished in', time, 'ms'); // await api.relay.POST('attachment', { + console.log('Upload Timer: finished in', time, 'ms'); + console.log(r); // await api.relay.POST('attachment', { // muid: r.muid, // file_name: r.filename, // chat_id: 13, // ttl: ttl, // }) - case 9: + case 10: case "end": return _context2.stop(); }