From b6ff03513160fcdf662d07571c37ffdb037368a0 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 6 Dec 2020 02:35:08 +0000 Subject: [PATCH] lots of fixes, added upload count --- index.html | 1 + js/hush-hush.js | 5 ++++- js/message-creator.js | 8 ++++++++ js/onionr-blocks.js | 7 +++++++ js/tordetect.js | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 593f195..05d9e77 100644 --- a/index.html +++ b/index.html @@ -90,6 +90,7 @@
Create Post +
diff --git a/js/hush-hush.js b/js/hush-hush.js index 5d6f2e3..5ccac61 100644 --- a/js/hush-hush.js +++ b/js/hush-hush.js @@ -141,7 +141,7 @@ async function findMessages(){ setTimeout(function(){findMessages()}, findMessageIntervalTime) return } - lastLookup = Math.floor((Date.now() / 1000)) - (findMessageIntervalTime / 1000) - 600 + lastLookup = Math.floor((Date.now() / 1000)) - (findMessageIntervalTime / 1000) - 1200 messages.forEach(block => { if (!block) { return} block = reconstructHash(block) @@ -155,6 +155,9 @@ async function findMessages(){ document.getElementById('memUsage').innerText = getReadableFileSizeString(current + ((basicTextEncoder.encode(data)).length + block.length)) } try{ + if (typeof d === "undefined"){ + return + } var metadata = JSON.parse(d.split("\n")[0]) // Make sure the block is an actual post so nodes can't send us stuff unrelated to dapp if (JSON.parse(metadata['meta'])['type'] !== postTopic){ diff --git a/js/message-creator.js b/js/message-creator.js index 26f1369..f44c5a2 100644 --- a/js/message-creator.js +++ b/js/message-creator.js @@ -42,6 +42,7 @@ document.getElementById("createMessageBtn").onclick = async function(){ } async function doUpload(data){ + document.getElementById("uploadingCount").parentNode.classList.remove('is-hidden') if (! publicNodes.length){ setTimeout(function(){ doUpload(data) @@ -70,6 +71,12 @@ async function doUpload(data){ }) clearTimeout(uploadTimeout) if (upload.ok){ + let cur = parseInt(document.getElementById("uploadingCount").innerText) + document.getElementById("uploadingCount").innerText = parseInt(document.getElementById("uploadingCount").innerText) - 1 + if (cur - 1 <= 0){ + document.getElementById("uploadingCount").parentNode.classList.add('is-hidden') + } + return } doUpload(data) @@ -81,5 +88,6 @@ powWorker.addEventListener('message', function(e) { document.getElementById("creatingMessage").classList.add("is-hidden") } console.debug("Generated block: " + doHashHex(e.data)) + document.getElementById("uploadingCount").innerText = parseInt(document.getElementById("uploadingCount").innerText) + 1 doUpload(e.data) }, false) diff --git a/js/onionr-blocks.js b/js/onionr-blocks.js index b7fbbee..e8100f2 100644 --- a/js/onionr-blocks.js +++ b/js/onionr-blocks.js @@ -23,9 +23,16 @@ function reconstructHash(hash){ function verifyBlock(raw, hash){ var encoder = new TextEncoder("utf-8") hash = reconstructHash(hash) + const blockSize = encoder.encode(raw).length; if (doHashHex(encoder.encode(raw)) != hash){ throw new Error("Hash does not match") } + if (blockSize > 10000){ + throw new Error("Block is too large") + } + else if(blockSize < 10){ + throw new Error("Block size is too small") + } } function verifyTime(time){ diff --git a/js/tordetect.js b/js/tordetect.js index 97ddca9..aef6ba7 100644 --- a/js/tordetect.js +++ b/js/tordetect.js @@ -1,4 +1,7 @@ let torDetect = function(){ + if (document.location.origin.endsWith('.onion')){ + return + } let el = document.createElement('img') el.onerror = function(){ document.getElementsByClassName('noTor')[0].classList.remove('is-hidden')