diff --git a/hush-hush.js b/hush-hush.js index d9c9b24..6f90857 100644 --- a/hush-hush.js +++ b/hush-hush.js @@ -17,8 +17,8 @@ */ var findMessageIntervalTime = 5000 var publicNodes = [ - "yre3tmbu25lcogl42xlh73wfchgbx3unz2zz3ttyiylj6gaq5mzhevid", - "ltqmmfww3tue6tibtyfc4kk7edh3owewxwcgrkvwqw4cwgd3w3zcj6id" + "67xpi7z753tbmylc7etrifjxqeyizoiqg6n7p5we6e4nblit5bqenqad", + "mpidhsfpmdgxxc5ygqluwtxptgne5swp5nkjzdre6tmnent7zqwp3cyd" ] var messageHashes = [] var blocks = [] @@ -116,8 +116,7 @@ async function findMessages(){ document.getElementById('memUsage').innerText = getReadableFileSizeString(current + ((basicTextEncoder.encode(data)).length + block.length)) } let metadata = JSON.parse(d.split("\n")[0]) - console.debug(metadata) - //let data = d.split('\n')[1] + let data = d.substring(d.indexOf('\n') + 1); try{ verifyBlock(d, block) diff --git a/index.html b/index.html index b84f9d2..48016b1 100644 --- a/index.html +++ b/index.html @@ -20,6 +20,7 @@ +
@@ -48,7 +49,7 @@

Markdown is supported, except for images, styles and scripts.

- +
@@ -56,7 +57,7 @@
- Create Post + Create Post
diff --git a/message-creator.js b/message-creator.js new file mode 100644 index 0000000..6d44e67 --- /dev/null +++ b/message-creator.js @@ -0,0 +1,29 @@ +document.getElementById("createMessageBtn").onclick = async function(){ + + let field = document.getElementById("postMessageField") + + let payload = { + "metadata": { + 'time': Math.floor((Date.now() / 1000)), + 'meta': JSON.stringify({'type': 'brd', 'ch': 'global'}) + }, + "data": field.value, + "difficulty": difficulty.length / 2 + } + powWorker.postMessage(JSON.stringify(payload)) +} + +powWorker.addEventListener('message', function(e) { + let decoder = new TextDecoder("utf-8") + let message = decoder.decode(e.data) + + fetch('http://' + getCurrentNode() + '.onion/upload', { + method: 'POST', + headers: { + "content-type": "application/octet-stream" + }, + body: decoder.decode(e.data) + }) + + console.debug("Generated block: " + doHashHex(e.data)) + }, false) diff --git a/peer-lookup.js b/peer-lookup.js index 56355c6..17c739e 100644 --- a/peer-lookup.js +++ b/peer-lookup.js @@ -31,6 +31,9 @@ self.addEventListener('message', async function(e) { let peerList = await lookupPeer(peer) peerList.forEach(node => { if (node){ + //if (await (await fetch('http://' + node + '.onion/ping')).text() !== 'pong'){ + // return + //} postMessage(node) } }) diff --git a/powworker.js b/powworker.js index 0ebef46..3f792e7 100644 --- a/powworker.js +++ b/powworker.js @@ -3,6 +3,7 @@ importScripts("sha3.js") self.addEventListener('message', function(e) { var data = JSON.parse(e.data) + console.debug(data.metadata) self.postMessage( doPow( data.metadata, diff --git a/worker-handler.js b/worker-handler.js index b24a44e..5de3bba 100644 --- a/worker-handler.js +++ b/worker-handler.js @@ -1,5 +1,5 @@ var lookupWorker = new Worker('peer-lookup.js'); - +var powWorker = new Worker("powworker.js") lookupWorker.addEventListener('message', function(e) { publicNodes.push(e.data)