From 10243a1ddd803456a70b1e9d99e82cceeccd0926 Mon Sep 17 00:00:00 2001 From: Jono Wenger <jono@elixxir.io> Date: Mon, 12 Sep 2022 12:11:49 -0700 Subject: [PATCH] Add button to stop network follower --- examples/sendE2E/README.md | 5 ++++- examples/sendE2E/receiver.html | 6 +++++- examples/sendE2E/sender.html | 22 ++++++++++++---------- examples/sendE2E/xxdk.js | 13 ++++++++++--- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/examples/sendE2E/README.md b/examples/sendE2E/README.md index ade0f0e9..48c53c59 100644 --- a/examples/sendE2E/README.md +++ b/examples/sendE2E/README.md @@ -1,4 +1,7 @@ # SendE2E Test This test sets up two clients in the browser and has one client send an E2E -message to the other. \ No newline at end of file +message to the other. + +## Running the Test + diff --git a/examples/sendE2E/receiver.html b/examples/sendE2E/receiver.html index cfe2d112..3ef4f64b 100644 --- a/examples/sendE2E/receiver.html +++ b/examples/sendE2E/receiver.html @@ -32,6 +32,9 @@ // Get element to print log messages to const logOutput = document.getElementById("logOutput") + // Get button that will stop the network follower + const stopNetworkFollowerBtn = document.getElementById("stopNetworkFollowerBtn") + // Client specific parameters const recipientContactFile = ''; const myContactFileName = 'receiverContact.xxc'; @@ -41,7 +44,7 @@ document.getElementById('ndfInput').addEventListener('change', e => { let reader = new FileReader(); reader.onload = function (e) { - SendE2e(logOutput, e.target.result, + SendE2e(logOutput, stopNetworkFollowerBtn, e.target.result, recipientContactFile, myContactFileName, statePath, statePass); }; @@ -53,6 +56,7 @@ <body> <h1 style="margin-top: 0">SendE2E: Receiver</h1> <input type="button" style="float:right;" value="Download Log File" id="logFileDownload"> +<input type="button" style="float:right;display:none;" value="Stop Network Follower" id="stopNetworkFollowerBtn"> <p>Selecting an NDF will start the client.</p> <form id="startCmix"> <div> diff --git a/examples/sendE2E/sender.html b/examples/sendE2E/sender.html index da6a347c..f051b24c 100644 --- a/examples/sendE2E/sender.html +++ b/examples/sendE2E/sender.html @@ -17,8 +17,6 @@ <script type="text/javascript" src="xxdk.js"></script> <script type="text/javascript" src="../wasm_exec.js"></script> <script> - // Use the encoder to convert a string to Uint8Array using enc.encode() - const go = new Go(); WebAssembly.instantiateStreaming(fetch("../xxdk.wasm"), go.importObject).then((result) => { go.run(result.instance); @@ -34,6 +32,9 @@ // Get element to print log messages to const logOutput = document.getElementById("logOutput") + // Get button that will stop the network follower + const stopNetworkFollowerBtn = document.getElementById("stopNetworkFollowerBtn") + // Client specific parameters const recipientContactFile = '<xxc(2)3Rk5yAbf4xfrKbxuHXudBmy6Y8ftb9fxpqPzBOZL2nIDrgZ7Ugdw/BAr6UOUDFtAKbqUp7U6rfxNbwkYOuTySVFQqKpGAVNVaSWgNEUmG2fkK0bTCGamLELsIn+1dWmO3vA+TXx8HPq1Y79pFvs87wN5bD+F97sOto085y5oMuEwoSuQu4nwS9vCoXPgOpXJjeRBqKYOM/ObbtF4OAhwmR5C86F2pDSBAkenKVt2/4/SeHdlZqmriqd5QDMhEQlXdyjUl/GfuqOFHiTyqcfQq7krE3pNhI0YYZ2VPK+gnM7klGbTJeNZ23jQLxC8UjSTd/tZbz764dv3ncqQDhdGpqEjk/0larKIscMcKFT/JqHyduiVW6PjZ382vO+TZYre0pF4fG4bnY7rbiy2iegeH/GtemJJLtYsww1PFFRKEz7tM1P/B3+eT/CkrFwT2O7l6lobi7kamO4mmxX26IF7WOHc68c99SrIUKBzFViY67TCRvO3/yt11TOpudAsnoix7sEW8ZwozVnLvVvSBMr6FTEyDdn2JncL3l5xtWH7L5cimQsl+PLJTwtBKMX6aek9W4IuIBhdSu1yYQAAAgA7UO/H/diSxQainCF4/o6URQ==xxc>'; const myContactFileName = 'theirE2eContact.xxc'; @@ -41,20 +42,21 @@ const statePass = 'password'; document.getElementById('ndfInput').addEventListener('change', e => { - let reader = new FileReader(); - reader.onload = function (e) { - SendE2e(logOutput, e.target.result, - recipientContactFile, myContactFileName, statePath, - statePass); - }; - reader.readAsText(e.target.files[0]); - }, false); + let reader = new FileReader(); + reader.onload = function (e) { + SendE2e(logOutput, stopNetworkFollowerBtn, e.target.result, + recipientContactFile, myContactFileName, statePath, + statePass); + }; + reader.readAsText(e.target.files[0]); + }, false); }); </script> </head> <body> <h1 style="margin-top: 0">SendE2E: Sender</h1> <input type="button" style="float:right;" value="Download Log File" id="logFileDownload"> +<input type="button" style="float:right;display:none;" value="Stop Network Follower" id="stopNetworkFollowerBtn"> <p>Selecting an NDF will start the client.</p> <form id="startCmix"> <div> diff --git a/examples/sendE2E/xxdk.js b/examples/sendE2E/xxdk.js index 0a723386..b8ba56d3 100644 --- a/examples/sendE2E/xxdk.js +++ b/examples/sendE2E/xxdk.js @@ -5,8 +5,9 @@ // LICENSE file. // //////////////////////////////////////////////////////////////////////////////// -async function SendE2e(logOutput, ndf, recipientContactFile, myContactFileName, - statePath, statePassString) { +async function SendE2e(logOutput, stopNetworkFollowerBtn, ndf, + recipientContactFile, myContactFileName, statePath, + statePassString) { const htmlConsole = newHtmlConsole(logOutput) @@ -101,6 +102,12 @@ async function SendE2e(logOutput, ndf, recipientContactFile, myContactFileName, htmlConsole.log("Started network follower") + stopNetworkFollowerBtn.style.display = 'block'; + stopNetworkFollowerBtn.addEventListener('click', () => { + htmlConsole.log("Stopping network follower") + net.StopNetworkFollower() + }) + // Provide a callback that will be signalled when network health status changes let health = false net.AddHealthCallback({ @@ -112,11 +119,11 @@ async function SendE2e(logOutput, ndf, recipientContactFile, myContactFileName, htmlConsole.log("Waiting for network to be healthy") try { await sleepUntil(() => health === true, 25000); - htmlConsole.log("Network is healthy: " + health) } catch { htmlConsole.error("Timed out. Network is not healthy: " + health) throw new Error("Timed out. Network is not healthy: " + health) } + htmlConsole.log("Network is healthy: " + health) //////////////////////////////////////////////////////////////////////////// -- GitLab