From f9aca21037c9b17813a89acf803996dd11637a14 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sat, 14 Dec 2024 18:31:00 +1300 Subject: [PATCH] try several times to send packets --- src/js/Connection.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/js/Connection.js b/src/js/Connection.js index a42efeb..b80e496 100644 --- a/src/js/Connection.js +++ b/src/js/Connection.js @@ -694,7 +694,15 @@ class Connection { try { // tell remote node we completed the file transfer - await FileTransferAPI.completeFileTransfer(fileTransfer.from, fileTransfer.id); + for(var attempt = 0; attempt < 3; attempt++){ + try { + await FileTransferAPI.completeFileTransfer(fileTransfer.from, fileTransfer.id); + console.log(`completeFileTransfer attempt ${attempt + 1} success`); + break; + } catch(e) { + console.log(`completeFileTransfer attempt ${attempt + 1} failed`); + } + } } catch(e) { console.log(e); @@ -705,7 +713,15 @@ class Connection { try { // ask remote node for parts - await FileTransferAPI.requestFileParts(fileTransfer.from, fileTransfer.id, partIndexes); + for(var attempt = 0; attempt < 3; attempt++){ + try { + await FileTransferAPI.requestFileParts(fileTransfer.from, fileTransfer.id, partIndexes); + console.log(`requestFileParts attempt ${attempt + 1} success`); + break; + } catch(e) { + console.log(`requestFileParts attempt ${attempt + 1} failed`); + } + } } catch(e) { console.log(e); @@ -722,7 +738,16 @@ class Connection { const partData = fileTransfer.data.slice(start, end); // send part to remote node - await FileTransferAPI.sendFilePart(fileTransfer.to, fileTransfer.id, partIndex, fileTransfer.total_parts, partData); + for(var attempt = 0; attempt < 3; attempt++){ + try { + await FileTransferAPI.sendFilePart(fileTransfer.to, fileTransfer.id, partIndex, fileTransfer.total_parts, partData); + console.log(`sendFilePart attempt ${attempt + 1} success`); + break; + } catch(e) { + console.log(`sendFilePart attempt ${attempt + 1} failed`); + } + } + } catch(e) { console.log(e);