From 329d296df3572347d921a8cbac33fab6576a39c4 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 3 Oct 2020 23:32:10 +0000 Subject: [PATCH] baisc block downloading finished --- hush-hush.js | 18 +++++++++++++----- index.html | 6 +++--- peer-lookup.js | 5 ++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/hush-hush.js b/hush-hush.js index 1a45099..3cc6ab4 100644 --- a/hush-hush.js +++ b/hush-hush.js @@ -15,10 +15,12 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ +var findMessageIntervalTime = 5000 var publicNodes = [ - "y7odk7elskeyfpgngqfy4xn3vawyrdmn7a4aqock44ksmlnwi4pxcbad" + "4gh2dwbmlrombeoyco55un7kbej7trsuebxfzvo53h6uj5adseceduyd" ] var messageHashes = [] +var blocks = {} // Make Tor connect to each node to reduce future connection time publicNodes.forEach(element => { @@ -42,11 +44,14 @@ function addMessage(message, timestamp){ document.getElementsByClassName("messageFeed")[0].append(newEl) } -async function apiGET(path, queryString){ +async function apiGET(path, queryString, raw=false){ let response = await fetch("http://" + getCurrentNode() + ".onion/" + encodeURIComponent(path) + queryString) if (response.ok) { // if HTTP-status is 200-299 // get the response body (the method explained below) + if (raw){ + return await response.blob() + } return await response.text() } else { console.debug("HTTP-Error: " + response.status) @@ -57,10 +62,13 @@ async function findMessages(){ let messages = (await apiGET("getblocklist", "?type=brd")).split('\n') messages.forEach(block => { if (! block){return} - apiGET("getdata", "/" + block).then(function(d){ - console.debug(d) + if (block in blocks){return} + apiGET("getdata", "/" + block, raw=false).then(function(d){ + let metadata = d.split("\n")[0] + let data = d.split('\n')[1] + blocks[block] = data }) }) } -findMessages() \ No newline at end of file +setInterval(function(){findMessages()}, findMessageIntervalTime) \ No newline at end of file diff --git a/index.html b/index.html index a44a0de..b2e792d 100644 --- a/index.html +++ b/index.html @@ -32,9 +32,9 @@

ℹ️ hush-hush is a message board program that utilizes the Onionr network.

⚠️ Posts are rate-limited using a partial hash collision proof of work function.

⏲️ The host of this web page has no control over posts. Browse and post at your own risk.

- - - + + +
diff --git a/peer-lookup.js b/peer-lookup.js index 0f582f3..b952091 100644 --- a/peer-lookup.js +++ b/peer-lookup.js @@ -19,12 +19,11 @@ self.addEventListener('message', function(e) { let lookupPeer = async function(peer){ - console.log("looking up on " + peer) - //return await fetch("") + let newList = await fetch('http://') } var data = JSON.parse(e.data) - let peers = data['nodeList'][0] + let peers = data['nodeList'] lookupPeer(peers) }