From 9c352e19173cc330f3d2e8a4356fdfd04d7654cc Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 9 Oct 2020 02:02:35 +0000 Subject: [PATCH] added topic support, apiGET timeout --- hush-hush.js | 20 ++++++++++++++------ index.html | 5 +++++ message-creator.js | 8 ++++++-- style.css | 4 ++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/hush-hush.js b/hush-hush.js index d796cc6..2edd03a 100644 --- a/hush-hush.js +++ b/hush-hush.js @@ -17,14 +17,15 @@ */ var findMessageIntervalTime = 5000 var publicNodes = [ - "4wbarqtxh6zasoxxftakrellcjzztcib7bqth4u3igof5fskrrvrk4yd", - "zl67stwxpjkntaxcfdhj3dvayculoojju6eek2jhsrdz6uwf224o6oqd" + "ty3rq3kub6gvzpngnrvfsk5emhoh2ltkti62u4ophca6ijciajotqqid" ] var messageHashes = [] var blocks = [] var basicTextEncoder = new TextEncoder() var difficulty = "0000" var maxBlockAge = 2678400 +var postTopic = 'kic' // we use block types as the topic with 'kic' as the prefix +var lastLookup = Math.floor((Date.now() / 1000)) - maxBlockAge function shuffleArray(array) { @@ -84,7 +85,7 @@ function addMessage(message, timestamp){ } - message = DOMPurify.sanitize(marked(message), + message = DOMPurify.sanitize(message, {FORBID_ATTR: ['style'], ALLOWED_TAGS: ['b', 'p', 'em', 'i', 'a', 'strong', 'sub', 'small', 'ul', 'li', 'ol', 'strike', 'tr', 'td', 'th', 'table', 'thead', 'tfoot', 'colgroup', 'col', 'caption', 'marquee', @@ -107,13 +108,19 @@ function addMessage(message, timestamp){ } async function apiGET(path, queryString, raw=false){ - let response = await fetch("http://" + getCurrentNode() + ".onion/" + encodeURIComponent(path) + queryString) + let nodeToUse = getCurrentNode() + let requestTimeout = setTimeout(function(){ + console.debug(nodeToUse + " timed out") + publicNodes = publicNodes.filter(item => item !== nodeToUse) + }, 10000) + let response = await fetch("http://" + nodeToUse + ".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() } + clearTimeout(requestTimeout) return await response.text() } else { console.debug("HTTP-Error: " + response.status) @@ -125,7 +132,8 @@ async function findMessages(){ setTimeout(function(){findMessages()}, 1000) return } - let messages = (await apiGET("getblocklist", "?type=kic")).split('\n') + let messages = (await apiGET("getblocklist", "?type=" + postTopic + "&date=" + lastLookup)).split('\n') + lastLookup = Math.floor((Date.now() / 1000)) messages.forEach(block => { if (!block) { return} block = reconstructHash(block) @@ -141,7 +149,7 @@ async function findMessages(){ try{ 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'] !== 'kic'){ + if (JSON.parse(metadata['meta'])['type'] !== postTopic){ throw new Error("Not correct block type: " + block) } } diff --git a/index.html b/index.html index d685686..1dddf63 100644 --- a/index.html +++ b/index.html @@ -40,6 +40,11 @@

kiccan 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.

+
+

feed size: 0kb | page size: 289kb

diff --git a/message-creator.js b/message-creator.js index 7cf5b68..df276d1 100644 --- a/message-creator.js +++ b/message-creator.js @@ -19,13 +19,17 @@ document.getElementById("createMessageBtn").onclick = async function(){ document.getElementById("createMessageBtn").setAttribute("disabled", true) let field = document.getElementById("postMessageField") + var postMessage = field.value + if (document.getElementById('use-markdown').checked){ + postMessage = marked(postMessage) + } let payload = { "metadata": { 'time': Math.floor((Date.now() / 1000)), - 'meta': JSON.stringify({'type': 'kic', 'ch': 'global'}) + 'meta': JSON.stringify({'type': postTopic}) }, - "data": field.value, + "data": postMessage, "difficulty": difficulty.length / 2 } powWorker.postMessage(JSON.stringify(payload)) diff --git a/style.css b/style.css index bff520e..14b8b16 100644 --- a/style.css +++ b/style.css @@ -5,3 +5,7 @@ .messageCreator{ margin-bottom: 1em; } + +.messageFeed{ + font-family: Georgia, 'Times New Roman', Times, serif; +} \ No newline at end of file