From 58169f4f06879f4e708fcd3ccb0ebfc8eaab9eae Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 20 Oct 2019 10:31:34 -0500 Subject: comment out newer additions that are not quite ready for primetime --- gossip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gossip.js') diff --git a/gossip.js b/gossip.js index 37a8d90..1c85f88 100644 --- a/gossip.js +++ b/gossip.js @@ -260,7 +260,7 @@ function sync (subs, keys) { } } }) - }, index * 100000) + }, index * 1000) }) }) }) -- cgit v1.2.3-70-g09d2 From a83eb1a62d8c928414edaff6a4ef3a383b677bd3 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 17 Nov 2019 12:23:05 -0600 Subject: remove unused code --- gossip.js | 83 --------------------------------------------------------------- server.js | 65 +------------------------------------------------ 2 files changed, 1 insertion(+), 147 deletions(-) (limited to 'gossip.js') diff --git a/gossip.js b/gossip.js index 1c85f88..00e6f40 100644 --- a/gossip.js +++ b/gossip.js @@ -1,86 +1,3 @@ -function blobSync (blob, author, keys, needs) { - console.log(needs) - - var wsServers - - // duplicate code, we should abstract this - localforage.getItem('securepubs').then(function (servers) { - if (servers) { - wsServers = servers - } else { - servers = ['ws://bogbook.com', 'ws://localhost:8080'] - var pubs = [] - servers.forEach(server => { - var ws = new WebSocket(server) - ws.onopen = function () { - ws.send(JSON.stringify({requester: keys.publicKey, sendpub: true})) - } - ws.onmessage = function (message) { - pubs.push(server + '/~' + message.data) - localforage.setItem('securepubs', pubs) - } - }) - wsServers = pubs - } - }).then(function () { - wsServers.forEach(function (server, index) { - setTimeout(function () { - var split = server.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - console.log('requesting ' + blob + ' from ' + server) - ws.onopen = function () { - var req = { - blob: blob, - needs: needs - } - - box(JSON.stringify(req), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - ws.onmessage = function (message) { - var serverreq = JSON.parse(message.data) - unbox(serverreq.box, serverreq.requester, keys).then(unboxed => { - - var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - //console.log(unboxedreq) - if (unboxedreq.blobFile) { - var openedimg = nacl.sign.open(nacl.util.decodeBase64(unboxedreq.blobFile), nacl.util.decodeBase64(author.substring(1))) - if (openedimg) { - localforage.setItem(unboxedreq.blob, unboxedreq.blobFile) - } - } else { - localforage.getItem(unboxedreq.blob).then(blob => { - if (blob) { - var nextreq = { - author: author, - blob: unboxedreq.blob, - blobFile: blob - } - box(JSON.stringify(nextreq), serverreq.requester, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - }) - } - }) - } - }, index * 10000) - }) - }) -} - function sync (subs, keys) { var wsServers diff --git a/server.js b/server.js index e0b4218..c278a3a 100644 --- a/server.js +++ b/server.js @@ -36,72 +36,9 @@ bog.keys().then(key => { var req = JSON.parse(message) if (req.sendpub) { ws.send(key.publicKey) - } - else { + } else { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - //console.log(unboxedreq) - /*if (unboxedreq.blobFile) { - var openedimg = nacl.sign.open(nacl.util.decodeBase64(unboxedreq.blobFile), nacl.util.decodeBase64(unboxedreq.author.substring(1))) - if (openedimg) { - //console.log(openedimg) - fs.writeFileSync(blobdir + '/' + sanitize(unboxedreq.blob), unboxedreq.blobFile, 'UTF-8') - console.log('received blob ' + unboxedreq.blob + ' from ' + req.requester + ' and saved to blobs folder') - } - } - if (unboxedreq.blob) { - console.log(req.requester + ' has requested the blob ' + unboxedreq.blob) - var blobExists = fs.existsSync(blobdir + '/' + sanitize(unboxedreq.blob)) - if (unboxedreq.needs) { - console.log(req.requester + ' needs ' + unboxedreq.blob + ' do we have it?') - if (blobExists) { - console.log('We have it, so send it to the client') - var blobToSend = fs.readFileSync(blobdir + '/' + sanitize(unboxedreq.blob), 'UTF-8') - var sendblob = { - blob: unboxedreq.blob, - blobFile: blobToSend - } - console.log(sendblob) - bog.box(JSON.stringify(sendblob), req.requester, key).then(boxed => { - var obj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - } else { - console.log(req.requester + ' has ' + unboxedreq.blob + ' do we need it?') - if (!blobExists) { - console.log('We need it, so request it from the client') - var blobreq = { blob: unboxedreq.blob, needs: true } - bog.box(JSON.stringify(blobreq), req.requester, key).then(boxed => { - var obj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - } - }*/ - if (unboxedreq.seq === 0) { - console.log(req.requester + ' asked the full log of ' + unboxedreq.author) - fs.readFile(bogdir + unboxedreq.author, 'UTF-8', function (err, data) { - if (data) { - //var feed = JSON.stringify(data) - var feed = data - bog.box(feed, req.requester, key).then(boxed => { - var obj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - console.log('Sent full log of ' + unboxedreq.author + ' to ' + req.requester) - }) - } - }) - } if (unboxedreq.seq) { console.log(req.requester + ' asked for feed ' + unboxedreq.author + ' after sequence ' + unboxedreq.seq) // check to see if we have the feed on disk -- cgit v1.2.3-70-g09d2 From 6f73dcee4fbf3935a411c7a5434779ff1935d342 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 22 Nov 2019 10:49:39 -0600 Subject: remove console logs --- gossip.js | 3 --- 1 file changed, 3 deletions(-) (limited to 'gossip.js') diff --git a/gossip.js b/gossip.js index 00e6f40..f7ed484 100644 --- a/gossip.js +++ b/gossip.js @@ -46,10 +46,8 @@ function sync (subs, keys) { } ws.onmessage = function (message) { var req = JSON.parse(message.data) - console.log(req) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - console.log(unboxedreq) if (unboxedreq.seq === 0) { var stringedfeed = JSON.stringify(srclog) box(stringedfeed, serverpub, keys).then(boxed => { @@ -58,7 +56,6 @@ function sync (subs, keys) { box: boxed } console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) - console.log(obj) ws.send(JSON.stringify(obj)) }) } -- cgit v1.2.3-70-g09d2 From cdcbf89b31a823390ab94c9e66e80a71669b273e Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 23 Nov 2019 18:55:18 -0600 Subject: clean up and move all config and keys to a settings page --- app.js | 10 +++----- css/style.css | 7 +++-- gossip.js | 4 +-- package-lock.json | 21 --------------- package.json | 1 - server.js | 8 ++---- views.js | 76 +++++++++++++++++++++++++++++++------------------------ 7 files changed, 55 insertions(+), 72 deletions(-) (limited to 'gossip.js') diff --git a/app.js b/app.js index 09b2e5d..7fe1ae2 100644 --- a/app.js +++ b/app.js @@ -8,10 +8,8 @@ function route (keys) { var screen = document.getElementById('screen') screen.appendChild(scroller) - if (src === 'key') { - keyPage(keys) - } else if (src === 'pubs') { - pubs() + if (src === 'settings') { + settingsPage(keys) } else if (src[0] === '@') { profilePage(src, keys) } else if (src[0] === '?') { @@ -30,9 +28,7 @@ keys().then(key => { h('div', {classList: 'internal'}, [ h('li', [h('a', {href: '#'}, ['Home'])]), h('li', [h('a', {href: '#' + key.publicKey}, [getName(key.publicKey, keys)])]), - h('li', [h('a', {href: '#key'}, ['Key'])]), - h('li', [h('a', {href: '#pubs'}, ['Pubs'])]), - h('li', {classList: 'right'}, [h('a', {href: 'http://git.sr.ht/~ev/bogbook'}, ['Git'])]), + h('li', {classList: 'right'}, [h('a', {href: '#settings'}, ['Settings'])]), h('form', { classList: 'search', onsubmit: function (e) { window.location.hash = '?' + search.value diff --git a/css/style.css b/css/style.css index fad1090..2aedb05 100644 --- a/css/style.css +++ b/css/style.css @@ -61,6 +61,8 @@ hr { border-radius: 5px; } +#scroller:last-child { margin-bottom: 10em; } + .message, .message > *, .navbar, .navbar > * { animation: fadein .5s; } @@ -167,17 +169,18 @@ textarea { } form.search, input.search { - width: 100px; + width: 175px; float: right; margin: 0; padding: 0; + padding-left: .1em; color: #f5f5f5; background: #444; border-radius: 3px; } form.search { - margin-top: .3em; + margin-top: .20em; } .navbar li.right { diff --git a/gossip.js b/gossip.js index f7ed484..d0fc31c 100644 --- a/gossip.js +++ b/gossip.js @@ -102,7 +102,7 @@ function sync (subs, keys) { open(unboxedreq[i]).then(opened => { log.unshift(opened) var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) if (unboxedreq.length + lastmsg.seq === opened.seq) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() @@ -155,7 +155,7 @@ function sync (subs, keys) { open(unboxedreq[i]).then(opened => { log.unshift(opened) var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) if (opened.seq === unboxedreq.length) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() diff --git a/package-lock.json b/package-lock.json index 1571dd4..c684ff2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -83,22 +83,6 @@ "is-wsl": "^1.1.0" } }, - "sanitize-filename": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.3.tgz", - "integrity": "sha512-y/52Mcy7aw3gRm7IrcGDFx/bCk4AhRh2eI9luHOQM86nZsqwiRkkq2GekHXBBD+SmPidc8i2PqtYZl+pWJ8Oeg==", - "requires": { - "truncate-utf8-bytes": "^1.0.0" - } - }, - "truncate-utf8-bytes": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", - "integrity": "sha1-QFkjkJWS1W94pYGENLC3hInKXys=", - "requires": { - "utf8-byte-length": "^1.0.1" - } - }, "tweetnacl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.1.tgz", @@ -114,11 +98,6 @@ "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" }, - "utf8-byte-length": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", - "integrity": "sha1-9F8VDExm7uloGGUFq5P8u4rWv2E=" - }, "ws": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", diff --git a/package.json b/package.json index 3386ed5..658ffd8 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,6 @@ "ecstatic": "^4.1.2", "ed2curve": "^0.2.1", "open": "^6.2.0", - "sanitize-filename": "^1.6.3", "tweetnacl": "^1.0.1", "tweetnacl-util": "^0.15.0", "ws": "^6.2.1" diff --git a/server.js b/server.js index e2b2f06..475551a 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,6 @@ // static server (8089) +var fs = require('fs') var http = require('http') var serve = require('ecstatic') var open = require('open') @@ -14,19 +15,14 @@ open('http://localhost:8089') var bog = require('./bog') var WS = require('ws') -var fs = require('fs') var nacl = require('tweetnacl') nacl.util = require('tweetnacl-util') -var homedir = require('os').homedir() -var sanitize = require('sanitize-filename') - +var homedir = require('os').homedir() var bogdir = homedir + '/.bogbook/bogs/' -var blobdir = homedir + '/.bogbook/blobs/' if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} -if (!fs.existsSync(blobdir)){fs.mkdirSync(blobdir)} var wserve = new WS.Server({ port: 8080 }) diff --git a/views.js b/views.js index 519e3ea..1cac555 100644 --- a/views.js +++ b/views.js @@ -11,7 +11,7 @@ function profilePage (src, keys) { var profile = h('div', {classList: 'profile'}) scroller.appendChild(profile) - scroller.appendChild(h('div')) + //scroller.appendChild(h('div')) var subs = [src] @@ -144,22 +144,6 @@ function publicPage (keys) { } }) - var div = h('div') - - div.appendChild(h('button', { - onclick: function () { - localforage.clear().then(function () {location.reload()}) - } - }, ['Delete Everything'])) - - div.appendChild(h('button', { - onclick: function () { - regenerate() - } - }, ['Regenerate'])) - - scroller.appendChild(div) - scroller.appendChild(composer(keys)) async function addPosts (posts, keys) { @@ -189,14 +173,18 @@ function publicPage (keys) { }) } -function keyPage (keys) { - var message = h('div', {classList: 'message'}) +function settingsPage (keys) { + var welcome = h('div', {classList: 'message'}) - message.appendChild(h('p', {innerHTML: marked('This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). Your public key is your identity when using [Bogbook](http://bogbook.com/), save your key in a safe place so that you can continue to use the same identity.')})) + welcome.appendChild(h('p', {innerHTML: marked('This is [Bogbook](http://bogbook.com), a distributed social network built using secure-gossiped blockchain logging (blogging), but we call them "bogs".\n\n You can view the code at [git.sr.ht/~ev/bogbook](https://git.sr.ht/~ev/bogbook) or clone it directly from our server:\n```\ngit clone http://git.bogbook.com/bogbook.git\n```\n Please communicate errors, bugs, and pull-requests to [@ev](http://bogbook.com/#@Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0=) using Bogbook or via email: [ev@evbogue.com](mailto:ev@evbogue.com)')})) - message.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])])) + var keyDiv = h('div', {classList: 'message'}) - message.appendChild(h('button', { + keyDiv.appendChild(h('p', {innerHTML: marked('This is your ed25519 public/private keypair. It was generated using [TweetNaCl.js](https://tweetnacl.js.org/#/). Your public key is your identity when using Bogbook, save your key in a safe place so that you can continue to use the same identity.')})) + + keyDiv.appendChild(h('pre', {style: 'width: 80%'}, [h('code', [JSON.stringify(keys)])])) + + keyDiv.appendChild(h('button', { onclick: function () { localforage.removeItem('id', function () { location.hash = '' @@ -206,8 +194,8 @@ function keyPage (keys) { }, ['Delete Key'])) var textarea = h('textarea', {placeholder: 'Import your existing ed25519 keypair'}) - message.appendChild(textarea) - message.appendChild(h('button', { + keyDiv.appendChild(textarea) + keyDiv.appendChild(h('button', { onclick: function () { if (textarea.value) { localforage.setItem('id', JSON.parse(textarea.value)).then(function () { location.reload() }) @@ -215,19 +203,37 @@ function keyPage (keys) { } }, ['Import Key'])) - scroller.appendChild(message) -} + var everything = h('div', {classList: 'message'}) + + everything.appendChild(h('p', {innerHTML: marked('Sometimes you may want to delete all of your bogbook data in the browser. When you click this button, Bogbook will erase everything that you\'ve stored in the browser. NOTE: This will not delete Bogbook posts that you have already gossiped with others. WARNING: This will delete your Bogbook keypair as well as all data stored in the browser. If you want to continue to use the same key, make sure you\'ve backed up your keypair!')})) + + everything.appendChild(h('button', { + onclick: function () { + localforage.clear().then(function () {location.reload()}) + } + }, ['Delete Everything'])) + + /* we probably don't need this anymore + var regenerate = h('div', {classList: 'message'}) + + regenerate.appendChild(h('p', {innerHTML: marked('The regenerate button will create a new bogbook log in your browser from all of the feeds that you\'ve collected in your browser. While it is rare, you may use this button to troubleshoot if Bogbook is throwing strange database errors in your console.')})) + + regenerate.appendChild(h('button', { + onclick: function () { + regenerate() + } + }, ['Regenerate']))*/ + -function pubs () { - var message = h('div', {classList: 'message'}) + var pubs = h('div', {classList: 'message'}) - message.appendChild(h('p', {innerHTML: marked('These are the Bogbook pubs that your browser will connect to as it looks for new messages from your subscriptions, when you post new bog posts, and when you click on feeds.\n\nAdd or remove these pubs to control where your Bogbook gossips. Localhost is a default, but will only work if you install Bogbook on your local computer by [cloning down the repo](https://git.sr.ht/~ev/bogbook).')})) + pubs.appendChild(h('p', {innerHTML: marked('These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com/~@h4e3bHDJeDWiCAkzp83HINPR4y7BLR7tI3fOVqwLQqw=\n```\n to your pubs list.')})) var add = h('input', {placeholder: 'Add a pub'}) localforage.getItem('securepubs').then(function (servers) { - message.appendChild(h('div', [ + pubs.appendChild(h('div', [ add, h('button', { onclick: function () { @@ -240,7 +246,7 @@ function pubs () { ])) servers.forEach(function (pub) { - message.appendChild(h('p', [ + pubs.appendChild(h('p', [ pub, h('button', { onclick: function () { @@ -252,7 +258,7 @@ function pubs () { }) }) - message.appendChild(h('button', { + pubs.appendChild(h('button', { onclick: function () { localforage.removeItem('securepubs').then(function () { location.hash = '' @@ -261,6 +267,10 @@ function pubs () { } }, ['Reset pubs'])) - scroller.appendChild(message) + scroller.appendChild(welcome) + scroller.appendChild(keyDiv) + scroller.appendChild(pubs) + scroller.appendChild(everything) + //scroller.appendChild(regenerate) } -- cgit v1.2.3-70-g09d2 From 30cdde804f90ca533bc3388de46251f1400087a5 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 24 Nov 2019 09:03:30 -0600 Subject: serve ads if client feeds are up to date --- ads.json | 15 +++++++++++++++ css/style.css | 23 ++++++++++++++++++++++- gossip.js | 4 ++++ index.html | 2 +- package.json | 2 +- render.js | 26 ++++++++++++++++++++++++++ server.js | 25 ++++++++++++++++++------- 7 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 ads.json (limited to 'gossip.js') diff --git a/ads.json b/ads.json new file mode 100644 index 0000000..ada8e83 --- /dev/null +++ b/ads.json @@ -0,0 +1,15 @@ +[ +"Eat your veggies.", +"Drink more coffee.", +"Read my post.", +"Avoid Black Friday.", +"Your ad here.", +"Run your own pub to serve your ads.", +"Run your own pub to turn off ads.", +"Make money online.", +"Hello world.", +"Become a professional bogger.", +"Invite your friends.", +"Bogbook 2020.", +"Tip your bartender." +] diff --git a/css/style.css b/css/style.css index 4200941..2f28584 100644 --- a/css/style.css +++ b/css/style.css @@ -66,10 +66,31 @@ hr { #scroller:last-child { margin-bottom: 10em; } -.message, .message > *, .navbar, .navbar > * { +.message, .message > *, .navbar, .navbar > *, #ad, #ad > * { animation: fadein .5s; } +#ad { + background: white; + font-size: .8em; + border: 1px solid #ddd; + border-radius: 5px; + position: fixed; + padding: .3em .5em; + bottom: 5px; + left: 5px; + width: 250px; +} + +#ad button { + font-size: .8em; + margin: 0; + padding: 0; + padding-left: 5px; padding-right: 5px; + position: absolute; + bottom: 2px; right: 2px; +} + @keyframes fadein { from { opacity: 0; } to { opacity: 1; } diff --git a/gossip.js b/gossip.js index d0fc31c..09f4207 100644 --- a/gossip.js +++ b/gossip.js @@ -48,6 +48,10 @@ function sync (subs, keys) { var req = JSON.parse(message.data) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) + if (unboxedreq.content) { + console.log(unboxedreq) + renderAd(unboxedreq) + } if (unboxedreq.seq === 0) { var stringedfeed = JSON.stringify(srclog) box(stringedfeed, serverpub, keys).then(boxed => { diff --git a/index.html b/index.html index a663afc..04d275f 100644 --- a/index.html +++ b/index.html @@ -17,8 +17,8 @@ - + diff --git a/package.json b/package.json index 658ffd8..c8799e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.6.0", + "version": "1.7.0", "description": "secure blockchain logging (blogging, without the l) -- bogging", "main": "server.js", "scripts": { diff --git a/render.js b/render.js index 3bd02df..ee91c24 100644 --- a/render.js +++ b/render.js @@ -1,3 +1,29 @@ +function renderAd (ad) { + var screen = document.getElementById('screen') + var adspot = document.getElementById('ad') + + if (adspot) { + adspot.parentNode.removeChild(adspot) + } + + newAd = h('div', {id: 'ad'}, [ + h('span', {classList: 'right'}, [h('pre', ['Ad'])]), + h('p', {innerHTML: marked(ad.content)}), + h('button', {classList: 'right', + onclick: function () { + adspot = document.getElementById('ad') + adspot.parentNode.removeChild(adspot) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + + screen.appendChild(newAd) +} + function getHeader (post, keys, mini) { var getRaw = h('button', { onclick: function () { diff --git a/server.js b/server.js index 475551a..112f899 100644 --- a/server.js +++ b/server.js @@ -26,6 +26,8 @@ if (!fs.existsSync(bogdir)){fs.mkdirSync(bogdir)} var wserve = new WS.Server({ port: 8080 }) +var adContents = JSON.parse(fs.readFileSync(__dirname + '/ads.json')) + bog.keys().then(key => { wserve.on('connection', function (ws) { ws.on('message', function (message) { @@ -42,9 +44,23 @@ bog.keys().then(key => { var feed = JSON.parse(data) bog.open(feed[0]).then(msg => { if (unboxedreq.seq === msg.seq) { - console.log(unboxedreq.author + '\'s feed is identical, sending nothing to client') + //console.log(unboxedreq.author + '\'s feed is identical, sending nothing to client') + //commment this section out to disable ads + console.log(unboxedreq.author + '\'s feed is identical, sending an ad to ' + req.requester) + var ad = JSON.stringify({ + author: key.publicKey, + name: 'http://bogbook.com/', + content: adContents[Math.floor(Math.random() * adContents.length)], + timestamp: Date.now() + }) + bog.box(ad, req.requester, key).then(boxed => { + obj = { + requester: key.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) } - if (unboxedreq.seq > msg.seq) { // right now the client is still sending the entire log, which works just fine but isn't optimal console.log('client feed is longer, requesting diff from client') @@ -57,21 +73,18 @@ bog.keys().then(key => { ws.send(JSON.stringify(obj)) }) } - if (unboxedreq.seq < msg.seq) { var endrange = feed.length - unboxedreq.seq - 25 if (endrange < 0) { endrange = feed.length - unboxedreq.seq - 1 } var baserange = feed.length - unboxedreq.seq - console.log('client feed is shorter, sending from ' + baserange + ' to ' + endrange + ' to client') var diff = JSON.stringify( feed.slice( endrange, baserange) ) - //var diff = JSON.stringify(feed.slice(0, msg.seq - unboxedreq.seq)) bog.box(diff, req.requester, key).then(boxed => { var obj = { requester: key.publicKey, @@ -82,7 +95,6 @@ bog.keys().then(key => { } }) } else { - // if we don't have the feed, request the feed from the client and save console.log('We don\'t have the log on the server, requesting log from ' + req.requester ) var reqwhole = JSON.stringify({author: unboxedreq.author, seq: 0}) @@ -96,7 +108,6 @@ bog.keys().then(key => { } }) } else if (Array.isArray(unboxedreq)) { - // first check to make sure that we have an entire log bog.open(unboxedreq[0]).then(msg => { if (msg.seq === unboxedreq.length) { fs.writeFile(bogdir + msg.author, JSON.stringify(unboxedreq), 'UTF-8', function (err, success) { -- cgit v1.2.3-70-g09d2 From 79b1c0e953dad37e4f8f97e2fb297a78e876715b Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 24 Nov 2019 09:54:52 -0600 Subject: slow down gossip a little --- gossip.js | 278 +++++++++++++++++++++++++++++++------------------------------- views.js | 8 +- 2 files changed, 143 insertions(+), 143 deletions(-) (limited to 'gossip.js') diff --git a/gossip.js b/gossip.js index 09f4207..81c3f1c 100644 --- a/gossip.js +++ b/gossip.js @@ -21,22 +21,118 @@ function sync (subs, keys) { wsServers = pubs } }).then(function () { - subs.forEach(function (sub) { - wsServers.forEach(function (server, index) { - setTimeout(function () { - console.log('SYNCING WITH: ' + server + ' to fetch ' + sub) - var split = server.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) + subs.forEach(function (sub, index) { + setTimeout(function () { + wsServers.forEach(function (server, index) { + setTimeout(function () { + console.log('SYNCING WITH: ' + server + ' to fetch ' + sub) + var split = server.split('~') + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) - bog(sub).then(srclog => { - if (srclog) { - open(srclog[0]).then(msg => { + bog(sub).then(srclog => { + if (srclog) { + open(srclog[0]).then(msg => { + ws.onopen = function () { + var message = JSON.stringify(msg) + // if we have a log then send the latest log and see if we get anything back + box(message, serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + } + ws.onmessage = function (message) { + var req = JSON.parse(message.data) + unbox(req.box, req.requester, keys).then(unboxed => { + var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) + if (unboxedreq.content) { + console.log(unboxedreq) + renderAd(unboxedreq) + } + if (unboxedreq.seq === 0) { + var stringedfeed = JSON.stringify(srclog) + box(stringedfeed, serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) + ws.send(JSON.stringify(obj)) + }) + } + + if (unboxedreq.seq > msg.seq) { + console.log('server feed is longer, requesting diff from server') + var reqdiff = JSON.stringify({author: unboxedreq.author, seq: msg.seq}) + box(reqdiff, serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + } + + if (unboxedreq.seq < msg.seq) { + console.log('server feed is shorter, sending diff to server') + var diff = JSON.stringify(srclog.slice(0, msg.seq - unboxedreq.seq)) + box(diff, serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + } + + if (Array.isArray(unboxedreq)) { + console.log('received diff from server') + open(unboxedreq[0]).then(msg => { + localforage.getItem(msg.author).then(feed => { + open(feed[0]).then(lastmsg => { + if (unboxedreq.length + lastmsg.seq === msg.seq) { + var newlog = unboxedreq.concat(feed) + localforage.setItem(msg.author, newlog).then(success => { + console.log('combined existing feed of ' + msg.author + ' with diff and saved to client') + }) + localforage.getItem('log').then(log => { + if (!log) { + var log = [] + } + for (var i = unboxedreq.length -1; i >= 0; --i) { + open(unboxedreq[i]).then(opened => { + log.unshift(opened) + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + if (unboxedreq.length + lastmsg.seq === opened.seq) { + log.sort((a, b) => a.timestamp - b.timestamp) + var reversed = log.reverse() + localforage.setItem('log', reversed).then(success => { + console.log('saved log with ' + opened.author + ' prepended to localForage') + }) + } + }) + } + }) + } + }) + }) + }) + + } + + }) + } + }) + } else { + console.log('NO LOG IN CLIENT') ws.onopen = function () { - var message = JSON.stringify(msg) - // if we have a log then send the latest log and see if we get anything back - box(message, serverpub, keys).then(boxed => { + var reqwhole = JSON.stringify({author: sub, seq: 0}) + box(reqwhole, serverpub, keys).then(boxed => { var obj = { requester: keys.publicKey, box: boxed @@ -46,140 +142,46 @@ function sync (subs, keys) { } ws.onmessage = function (message) { var req = JSON.parse(message.data) + console.log('received message from ' + req.requester) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (unboxedreq.content) { - console.log(unboxedreq) - renderAd(unboxedreq) - } - if (unboxedreq.seq === 0) { - var stringedfeed = JSON.stringify(srclog) - box(stringedfeed, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) - ws.send(JSON.stringify(obj)) - }) - } - - if (unboxedreq.seq > msg.seq) { - console.log('server feed is longer, requesting diff from server') - var reqdiff = JSON.stringify({author: unboxedreq.author, seq: msg.seq}) - box(reqdiff, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - - if (unboxedreq.seq < msg.seq) { - console.log('server feed is shorter, sending diff to server') - var diff = JSON.stringify(srclog.slice(0, msg.seq - unboxedreq.seq)) - box(diff, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - if (Array.isArray(unboxedreq)) { - console.log('received diff from server') open(unboxedreq[0]).then(msg => { localforage.getItem(msg.author).then(feed => { - open(feed[0]).then(lastmsg => { - if (unboxedreq.length + lastmsg.seq === msg.seq) { - var newlog = unboxedreq.concat(feed) - localforage.setItem(msg.author, newlog).then(success => { - console.log('combined existing feed of ' + msg.author + ' with diff and saved to client') - }) - localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } - for (var i = unboxedreq.length -1; i >= 0; --i) { - open(unboxedreq[i]).then(opened => { - log.unshift(opened) - var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) - if (unboxedreq.length + lastmsg.seq === opened.seq) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed).then(success => { - console.log('saved log with ' + opened.author + ' prepended to localForage') - }) - } - }) - } - }) - } - }) + if (!feed) { + localforage.setItem(msg.author, unboxedreq).then(success => { + console.log('saved log of ' + msg.author + ' to localforage') + }) + localforage.getItem('log').then(log => { + if (!log) { + var log = [] + } + for (var i = unboxedreq.length -1; i >= 0; --i) { + open(unboxedreq[i]).then(opened => { + log.unshift(opened) + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + if (opened.seq === unboxedreq.length) { + log.sort((a, b) => a.timestamp - b.timestamp) + var reversed = log.reverse() + localforage.setItem('log', reversed).then(success => { + console.log('saved log with ' + opened.author + ' prepended to localForage') + }) + } + }) + } + }) + } }) }) - } - - }) + }) } - }) - } else { - console.log('NO LOG IN CLIENT') - ws.onopen = function () { - var reqwhole = JSON.stringify({author: sub, seq: 0}) - box(reqwhole, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) } - ws.onmessage = function (message) { - var req = JSON.parse(message.data) - console.log('received message from ' + req.requester) - unbox(req.box, req.requester, keys).then(unboxed => { - var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (Array.isArray(unboxedreq)) { - open(unboxedreq[0]).then(msg => { - localforage.getItem(msg.author).then(feed => { - if (!feed) { - localforage.setItem(msg.author, unboxedreq).then(success => { - console.log('saved log of ' + msg.author + ' to localforage') - }) - localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } - for (var i = unboxedreq.length -1; i >= 0; --i) { - open(unboxedreq[i]).then(opened => { - log.unshift(opened) - var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) - if (opened.seq === unboxedreq.length) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed).then(success => { - console.log('saved log with ' + opened.author + ' prepended to localForage') - }) - } - }) - } - }) - } - }) - }) - } - }) - } - } - }) - }, index * 1000) - }) + }) + }, index * 50000) + }) + }, index * 20000) }) }) } diff --git a/views.js b/views.js index 1cac555..99db90c 100644 --- a/views.js +++ b/views.js @@ -18,7 +18,7 @@ function profilePage (src, keys) { var interval = 1000 timer = function() { if (src === window.location.hash.substring(1)) { - if (interval < 10000) { interval = interval + 200 } + if (interval < 10000) { interval = interval + 100 } sync(subs, keys) setTimeout(timer, interval) } @@ -124,17 +124,15 @@ function searchPage (src, keys) { function publicPage (keys) { localforage.getItem('subscriptions').then(function (subs) { - var interval = 1000 + var interval = 10000 timer = function() { if ('' === window.location.hash.substring(1)) { - if (interval < 10000) { interval = interval + 1000 } + if (interval < 100000) { interval = interval + 1000 } sync(subs, keys) setTimeout(timer, interval) } } - if (subs) { - subs.push(keys.publicKey) timer() } else { var subs = [] -- cgit v1.2.3-70-g09d2 From dca488003d1f57db840fb9473e61a22a15b96ed7 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 7 Dec 2019 07:27:33 -0600 Subject: clean up --- bog.js | 7 +++---- css/style.css | 6 +++--- gossip.js | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 19 deletions(-) (limited to 'gossip.js') diff --git a/bog.js b/bog.js index 49d0b52..c5cb679 100644 --- a/bog.js +++ b/bog.js @@ -12,7 +12,6 @@ if ((typeof process !== 'undefined') && (process.release.name === 'node')) { // EX: open(msg).then(content => { console.log(content) }) async function open (msg) { - var pubkey = nacl.util.decodeBase64(msg.author.substring(1)) var sig = nacl.util.decodeBase64(msg.signature) var opened = await JSON.parse(nacl.util.encodeUTF8(nacl.sign.open(sig, pubkey))) @@ -139,7 +138,7 @@ function getName (id, keys) { localforage.getItem('name:' + id).then(cache => { if (cache) { - console.log(cache) + //console.log(cache) return name.textContent = '@' + cache } else { bog().then(log => { @@ -182,7 +181,7 @@ function regenerate (home) { if (key[0] == '@') { newlog = newlog.concat(value) } - console.log(newlog) + //console.log(newlog) }).then(function () { newlog.forEach(function (msg) { var pubkey = nacl.util.decodeBase64(msg.author.substring(1)) @@ -192,7 +191,7 @@ function regenerate (home) { openedlog.push(opened) }) - console.log(openedlog) + //console.log(openedlog) openedlog.sort((a, b) => a.timestamp - b.timestamp) diff --git a/css/style.css b/css/style.css index 96a50e7..bdd1c6b 100644 --- a/css/style.css +++ b/css/style.css @@ -45,7 +45,7 @@ hr { } #scroller { - max-width: 50em; + max-width: 680px; margin-right: auto; margin-left: auto; } @@ -172,8 +172,8 @@ textarea { position: fixed; z-index: 1000; margin: 0; - padding-top: .3em; - padding-bottom: .3em; + padding-top: .33em; + padding-bottom: .27em; left: 0; right: 0; top: 0; } diff --git a/gossip.js b/gossip.js index 81c3f1c..d0b91f1 100644 --- a/gossip.js +++ b/gossip.js @@ -25,7 +25,7 @@ function sync (subs, keys) { setTimeout(function () { wsServers.forEach(function (server, index) { setTimeout(function () { - console.log('SYNCING WITH: ' + server + ' to fetch ' + sub) + //console.log('SYNCING WITH: ' + server + ' to fetch ' + sub) var split = server.split('~') var serverurl = split[0] var serverpub = split[1] @@ -50,7 +50,7 @@ function sync (subs, keys) { unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) if (unboxedreq.content) { - console.log(unboxedreq) + unboxedreq.signature = unboxedreq.content renderAd(unboxedreq) } if (unboxedreq.seq === 0) { @@ -60,13 +60,13 @@ function sync (subs, keys) { requester: keys.publicKey, box: boxed } - console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) + //console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) ws.send(JSON.stringify(obj)) }) } if (unboxedreq.seq > msg.seq) { - console.log('server feed is longer, requesting diff from server') + //console.log('server feed is longer, requesting diff from server') var reqdiff = JSON.stringify({author: unboxedreq.author, seq: msg.seq}) box(reqdiff, serverpub, keys).then(boxed => { var obj = { @@ -78,7 +78,7 @@ function sync (subs, keys) { } if (unboxedreq.seq < msg.seq) { - console.log('server feed is shorter, sending diff to server') + //console.log('server feed is shorter, sending diff to server') var diff = JSON.stringify(srclog.slice(0, msg.seq - unboxedreq.seq)) box(diff, serverpub, keys).then(boxed => { var obj = { @@ -90,14 +90,14 @@ function sync (subs, keys) { } if (Array.isArray(unboxedreq)) { - console.log('received diff from server') + //console.log('received diff from server') open(unboxedreq[0]).then(msg => { localforage.getItem(msg.author).then(feed => { open(feed[0]).then(lastmsg => { if (unboxedreq.length + lastmsg.seq === msg.seq) { var newlog = unboxedreq.concat(feed) localforage.setItem(msg.author, newlog).then(success => { - console.log('combined existing feed of ' + msg.author + ' with diff and saved to client') + //console.log('combined existing feed of ' + msg.author + ' with diff and saved to client') }) localforage.getItem('log').then(log => { if (!log) { @@ -112,7 +112,7 @@ function sync (subs, keys) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() localforage.setItem('log', reversed).then(success => { - console.log('saved log with ' + opened.author + ' prepended to localForage') + //console.log('saved log with ' + opened.author + ' prepended to localForage') }) } }) @@ -129,7 +129,7 @@ function sync (subs, keys) { } }) } else { - console.log('NO LOG IN CLIENT') + //console.log('NO LOG IN CLIENT') ws.onopen = function () { var reqwhole = JSON.stringify({author: sub, seq: 0}) box(reqwhole, serverpub, keys).then(boxed => { @@ -142,7 +142,7 @@ function sync (subs, keys) { } ws.onmessage = function (message) { var req = JSON.parse(message.data) - console.log('received message from ' + req.requester) + //console.log('received message from ' + req.requester) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) if (Array.isArray(unboxedreq)) { @@ -150,7 +150,7 @@ function sync (subs, keys) { localforage.getItem(msg.author).then(feed => { if (!feed) { localforage.setItem(msg.author, unboxedreq).then(success => { - console.log('saved log of ' + msg.author + ' to localforage') + //console.log('saved log of ' + msg.author + ' to localforage') }) localforage.getItem('log').then(log => { if (!log) { @@ -165,7 +165,7 @@ function sync (subs, keys) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() localforage.setItem('log', reversed).then(success => { - console.log('saved log with ' + opened.author + ' prepended to localForage') + //console.log('saved log with ' + opened.author + ' prepended to localForage') }) } }) -- cgit v1.2.3-70-g09d2 From 3fe02c91174d7316ae2c66a7679ab807ca43c6c3 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 21 Dec 2019 14:26:30 -0600 Subject: initial stab at private beacons --- app.js | 3 ++ beacons.js | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ css/style.css | 4 +-- gossip.js | 3 ++ index.html | 1 + render.js | 73 +++++++++++++++++++++++++++++++++--------------- server.js | 59 +++++++++++++++++++++++++++------------ settings.js | 49 -------------------------------- 8 files changed, 190 insertions(+), 91 deletions(-) create mode 100644 beacons.js (limited to 'gossip.js') diff --git a/app.js b/app.js index 7fe1ae2..5dd49a5 100644 --- a/app.js +++ b/app.js @@ -10,6 +10,8 @@ function route (keys) { if (src === 'settings') { settingsPage(keys) + } else if (src === 'beacons') { + beaconsPage(keys) } else if (src[0] === '@') { profilePage(src, keys) } else if (src[0] === '?') { @@ -28,6 +30,7 @@ keys().then(key => { h('div', {classList: 'internal'}, [ h('li', [h('a', {href: '#'}, ['Home'])]), h('li', [h('a', {href: '#' + key.publicKey}, [getName(key.publicKey, keys)])]), + h('li', [h('a', {href: '#beacons'}, ['Beacons'])]), h('li', {classList: 'right'}, [h('a', {href: '#settings'}, ['Settings'])]), h('form', { classList: 'search', onsubmit: function (e) { diff --git a/beacons.js b/beacons.js new file mode 100644 index 0000000..1656879 --- /dev/null +++ b/beacons.js @@ -0,0 +1,89 @@ + +function beaconsPage (keys) { + + var pubslist = h('select') + + localforage.getItem('securepubs').then(function (servers) { + servers.forEach(function (pub) { + pubslist.appendChild( + h('option', {value: pub}, [pub]) + ) + }) + }) + + var ads = h('div', {classList: 'message'}) + + ads.appendChild(h('span', {innerHTML: marked('Sometimes when you\'re lost on the Internet you might want to send out a beacon so that people can see you. \n\n Beacons from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')})) + + ads.appendChild(pubslist) + + var recp = h('input', {placeholder: 'Ex: @Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0='}) + + var adstext = h('textarea', {placeholder: 'Hello World!'}) + + ads.appendChild(h('span', [ + h('br'), + h('p', [" Send a beacon (leave the 'To:' field blank for a public beacon): "]), + h('p', ['To: ', + recp + ]), + adstext, + h('br'), + h('button', { + onclick: function () { + var split = pubslist.value.split('~') + console.log(split) + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) + + if ((recp.value) && (adstext.value)) { + var tobox = { + author: keys.publicKey, + timestamp: Date.now(), + content: adstext.value + } + box(JSON.stringify(tobox), recp.value, keys).then(boxedmsg => { + var msg = { + type: 'beacon', + author: keys.publicKey, + box: boxedmsg + } + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + adstext.value = '' + recp.value = '' + } + }) + } + + if ((!recp.value) && (adstext.value)) { + var msg = { + type: 'beacon', + author: keys.publicKey + } + msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey))) + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + }) + adstext.value = '' + } + } + } + }, ['Publish']) + ])) + + scroller.appendChild(ads) +} + diff --git a/css/style.css b/css/style.css index 2a7745b..1eef78f 100644 --- a/css/style.css +++ b/css/style.css @@ -70,7 +70,7 @@ hr { animation: fadein .5s; } -#ad { +#ad, #pm { background: white; font-size: .8em; border: 1px solid #ddd; @@ -82,7 +82,7 @@ hr { width: 250px; } -#ad button { +#ad button, #pm button { font-size: .8em; margin: 0; padding: 0; diff --git a/gossip.js b/gossip.js index d0b91f1..3f88b54 100644 --- a/gossip.js +++ b/gossip.js @@ -53,6 +53,9 @@ function sync (subs, keys) { unboxedreq.signature = unboxedreq.content renderAd(unboxedreq) } + if (unboxedreq.box) { + renderAd(unboxedreq, keys) + } if (unboxedreq.seq === 0) { var stringedfeed = JSON.stringify(srclog) box(stringedfeed, serverpub, keys).then(boxed => { diff --git a/index.html b/index.html index 0396bcc..5d18890 100644 --- a/index.html +++ b/index.html @@ -17,6 +17,7 @@ + diff --git a/render.js b/render.js index d85d04b..02e4b88 100644 --- a/render.js +++ b/render.js @@ -1,4 +1,6 @@ -function renderAd (ad) { +function renderAd (ad, keys) { + console.log(ad) + var screen = document.getElementById('screen') var adspot = document.getElementById('ad') @@ -11,30 +13,57 @@ function renderAd (ad) { if (ad.views) { adspace.appendChild(h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])])) } else { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['ad'])])) + adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['beacon'])])) } - open(ad).then(opened => { - quickName(ad.author).then(gotName => { - newAd = h('div', {id: 'ad'}, [ - adspace, - h('p', {innerHTML: marked(opened)}), - h('button', {classList: 'right', - onclick: function () { - adspot = document.getElementById('ad') - adspot.parentNode.removeChild(adspot) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) + if (ad.box) { + unbox(ad.box, ad.author, keys).then(unboxed => { + var msg = JSON.parse(nacl.util.encodeUTF8(unboxed)) + quickName(ad.author).then(gotName => { + beacon = h('div', {id: 'pm'}, [ + h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), + h('p', {innerHTML: marked(msg.content)}), + h('button', {classList: 'right', + onclick: function () { + pmspot = document.getElementById('pm') + pmspot.parentNode.removeChild(pmspot) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) ]) - ]) - screen.appendChild(newAd) - }) - }) + screen.append(beacon) + }) + }) + } + + if (ad.signature) { + open(ad).then(opened => { + quickName(ad.author).then(gotName => { + newAd = h('div', {id: 'ad'}, [ + adspace, + h('p', {innerHTML: marked(opened)}), + h('button', {classList: 'right', + onclick: function () { + adspot = document.getElementById('ad') + adspot.parentNode.removeChild(adspot) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + screen.appendChild(newAd) + }) + }) + } } function getHeader (post, keys, mini) { diff --git a/server.js b/server.js index d324f43..5ad7064 100644 --- a/server.js +++ b/server.js @@ -119,15 +119,27 @@ bog.keys().then(key => { } else { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (unboxedreq.type == 'ad') { - - var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.signature))).toString('hex') - - var obj = { - hash: hex, - author: unboxedreq.author, - signature: unboxedreq.signature, - views: 0 + //console.log(unboxedreq) + if (unboxedreq.type == 'beacon') { + if (unboxedreq.box) { + var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.box))).toString('hex') + + var obj = { + hash: hex, + author: unboxedreq.author, + box: unboxedreq.box, + views: 0 + } + } + + if (unboxedreq.signature) { + var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.signature))).toString('hex') + var obj = { + hash: hex, + author: unboxedreq.author, + signature: unboxedreq.signature, + views: 0 + } } fs.writeFile(addir + hex, JSON.stringify(obj), 'UTF-8', function () { @@ -150,13 +162,25 @@ bog.keys().then(key => { var num = Math.floor(Math.random() * (adfiles.length)) fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { var obj = JSON.parse(adFile) - var ad = { - author: obj.author, - name: config.fullurl, - content: obj.signature, - timestamp: Date.now(), - views: obj.views + + if (obj.signature) { + var ad = { + author: obj.author, + name: config.fullurl, + content: obj.signature, + views: obj.views + } } + + if (obj.box) { + var ad = { + author: obj.author, + name: config.fullurl, + box: obj.box, + views: obj.views + } + } + if ((obj.views > 100) && (obj.author != config.author)) { fs.unlinkSync(addir + obj.hash) //console.log('REMOVING AD') @@ -165,6 +189,7 @@ bog.keys().then(key => { fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') } printSendAd(ad, req) + console.log(ad) //console.log('SENDING AD') bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { sendobj = { @@ -175,9 +200,7 @@ bog.keys().then(key => { ws.close() }) }) - } else { - ads.make('Hello World.') - } + } }) } } diff --git a/settings.js b/settings.js index 51dc1f2..c88ea07 100644 --- a/settings.js +++ b/settings.js @@ -56,11 +56,7 @@ function settingsPage (keys) { var add = h('input', {placeholder: 'Add a pub'}) - var pubslist = h('select') - localforage.getItem('securepubs').then(function (servers) { - - pubs.appendChild(h('div', [ add, h('button', { @@ -74,9 +70,6 @@ function settingsPage (keys) { ])) servers.forEach(function (pub) { - pubslist.appendChild( - h('option', {value: pub}, [pub]) - ) pubs.appendChild(h('p', [ pub, h('button', { @@ -98,52 +91,10 @@ function settingsPage (keys) { } }, ['Reset pubs'])) - var ads = h('div', {classList: 'message'}) - - - ads.appendChild(h('span', {innerHTML: marked('Submit an advertisement. Right now advertisements are free for anyone to post to this pub. Ads from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')})) - - ads.appendChild(pubslist) - - var adstext = h('input', {placeholder: 'Hello World!'}) - - ads.appendChild(h('span', [ - h('br'), - ' Write an ad: ', - h('br'), - adstext, - h('button', { - onclick: function () { - var split = pubslist.value.split('~') - console.log(split) - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - var msg = { - type: 'ad', - author: keys.publicKey - } - msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey))) - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - adstext.value = '' - } - }, ['Publish']) - ])) - scroller.appendChild(welcome) scroller.appendChild(keyDiv) scroller.appendChild(pubs) scroller.appendChild(everything) //scroller.appendChild(regenerate) - scroller.appendChild(ads) } -- cgit v1.2.3-70-g09d2 From 07ad37b0fd4711da999a5caddc7e04c4e569110f Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 22 Dec 2019 08:51:10 -0600 Subject: this should prevent arriving posts from rendering on incorrect views --- gossip.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'gossip.js') diff --git a/gossip.js b/gossip.js index 3f88b54..eb0812e 100644 --- a/gossip.js +++ b/gossip.js @@ -110,7 +110,13 @@ function sync (subs, keys) { open(unboxedreq[i]).then(opened => { log.unshift(opened) var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + + var src = window.location.hash.substring(1) + console.log(src) + if ((src === sub) || (src === '')) { + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + } if (unboxedreq.length + lastmsg.seq === opened.seq) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() @@ -162,8 +168,12 @@ function sync (subs, keys) { for (var i = unboxedreq.length -1; i >= 0; --i) { open(unboxedreq[i]).then(opened => { log.unshift(opened) - var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + var src = window.location.hash.substring(1) + console.log(src) + if ((src === sub) || (src === '')) { + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + } if (opened.seq === unboxedreq.length) { log.sort((a, b) => a.timestamp - b.timestamp) var reversed = log.reverse() -- cgit v1.2.3-70-g09d2 From 8a030de9eb5ca256be397311efbf58872120ec17 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 22 Dec 2019 09:17:24 -0600 Subject: remove console logs --- gossip.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'gossip.js') diff --git a/gossip.js b/gossip.js index eb0812e..2636ac6 100644 --- a/gossip.js +++ b/gossip.js @@ -112,7 +112,6 @@ function sync (subs, keys) { var scroller = document.getElementById('scroller') var src = window.location.hash.substring(1) - console.log(src) if ((src === sub) || (src === '')) { var scroller = document.getElementById('scroller') scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) @@ -169,7 +168,6 @@ function sync (subs, keys) { open(unboxedreq[i]).then(opened => { log.unshift(opened) var src = window.location.hash.substring(1) - console.log(src) if ((src === sub) || (src === '')) { var scroller = document.getElementById('scroller') scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) -- cgit v1.2.3-70-g09d2 From b9a1917fdbc5d79d58b4c7b9e268d555e97624ca Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 22 Dec 2019 12:38:19 -0600 Subject: make beacons go away with the heard button, also broadcast a heard to the pub --- beacons.js | 1 - gossip.js | 2 +- render.js | 192 ++++++++++++++++++++++++++++++++++++++++++------------------- server.js | 4 ++ 4 files changed, 138 insertions(+), 61 deletions(-) (limited to 'gossip.js') diff --git a/beacons.js b/beacons.js index 1656879..79f88a5 100644 --- a/beacons.js +++ b/beacons.js @@ -1,4 +1,3 @@ - function beaconsPage (keys) { var pubslist = h('select') diff --git a/gossip.js b/gossip.js index 2636ac6..0c12a40 100644 --- a/gossip.js +++ b/gossip.js @@ -51,7 +51,7 @@ function sync (subs, keys) { var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) if (unboxedreq.content) { unboxedreq.signature = unboxedreq.content - renderAd(unboxedreq) + renderAd(unboxedreq, keys) } if (unboxedreq.box) { renderAd(unboxedreq, keys) diff --git a/render.js b/render.js index 3979bb3..8e90a84 100644 --- a/render.js +++ b/render.js @@ -1,69 +1,143 @@ function renderAd (ad, keys) { - console.log(ad) + localforage.getItem(ad.hash).then(heard => { + if (!heard) { + var screen = document.getElementById('screen') + var adspot = document.getElementById('ad') + var pmspot = document.getElementById('pm') - var screen = document.getElementById('screen') - var adspot = document.getElementById('ad') + if (adspot) { + adspot.parentNode.removeChild(adspot) + } - if (adspot) { - adspot.parentNode.removeChild(adspot) - } + if (pmspot) { + pmspot.parentNode.removeChild(pmspot) + } - var adspace = h('span') + var adspace = h('span') - if (ad.views) { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])])) - } else { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['beacon'])])) - } + if (ad.views) { + adspace.appendChild(h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])])) + } else { + adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['beacon'])])) + } - if (ad.box) { - unbox(ad.box, ad.author, keys).then(unboxed => { - var msg = JSON.parse(nacl.util.encodeUTF8(unboxed)) - quickName(ad.author).then(gotName => { - beacon = h('div', {id: 'pm'}, [ - h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), - h('p', {innerHTML: marked(msg.content)}), - h('button', {classList: 'right', - onclick: function () { - pmspot = document.getElementById('pm') - pmspot.parentNode.removeChild(pmspot) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - screen.append(beacon) - }) - }) - } + if (ad.box) { + unbox(ad.box, ad.author, keys).then(unboxed => { + var msg = JSON.parse(nacl.util.encodeUTF8(unboxed)) + quickName(ad.author).then(gotName => { + beacon = h('div', {id: 'pm'}, [ + h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), + h('p', {innerHTML: marked(msg.content)}), + h('button', {classList: 'right', + onclick: function () { + pmspot = document.getElementById('pm') + pmspot.parentNode.removeChild(pmspot) + if (msg.content.substring((msg.content.length - 6), msg.content.length) === 'Heard.') { + localforage.setItem(ad.hash, true).then(success => { + //console.log('heard: ' + ad.hash) + }) - if (ad.signature) { - open(ad).then(opened => { - quickName(ad.author).then(gotName => { - newAd = h('div', {id: 'ad'}, [ - adspace, - h('p', {innerHTML: marked(opened)}), - h('button', {classList: 'right', - onclick: function () { - adspot = document.getElementById('ad') - adspot.parentNode.removeChild(adspot) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - screen.appendChild(newAd) - }) - }) - } + } else { + var split = ad.pub.split('~') + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) + + var tobox = { + author: keys.publicKey, + timestamp: Date.now(), + content: '>' + msg.content + '\n\nHeard.' + } + + box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { + var msg = { + type: 'beacon', + author: keys.publicKey, + box: boxedmsg + } + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + localforage.setItem(ad.hash, true).then(success => { + //console.log('heard: ' + ad.hash) + }) + }) + } + }) + } + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + screen.append(beacon) + }) + }) + } + + if (ad.signature) { + open(ad).then(opened => { + quickName(ad.author).then(gotName => { + newAd = h('div', {id: 'ad'}, [ + adspace, + h('p', {innerHTML: marked(opened)}), + h('button', {classList: 'right', + onclick: function () { + adspot = document.getElementById('ad') + adspot.parentNode.removeChild(adspot) + var split = ad.pub.split('~') + var serverurl = split[0] + var serverpub = split[1] + var ws = new WebSocket(serverurl) + + + + var tobox = { + author: keys.publicKey, + timestamp: Date.now(), + content: '>' + opened + '\n\nHeard.' + } + + box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { + var msg = { + type: 'beacon', + author: keys.publicKey, + box: boxedmsg + } + ws.onopen = function () { + box(JSON.stringify(msg), serverpub, keys).then(boxed => { + var obj = { + requester: keys.publicKey, + box: boxed + } + ws.send(JSON.stringify(obj)) + localforage.setItem(ad.hash, true).then(success => {console.log('heard: ' + ad.hash)}) + }) + } + }) + } + }, ['Heard']), + h('span', [ + '—', + h('a', {href: '#' + ad.author}, [gotName]), + ' from ', + h('a', {href: ad.name}, [ad.name]) + ]) + ]) + screen.appendChild(newAd) + }) + }) + } + } + }) } function getHeader (post, keys, mini) { diff --git a/server.js b/server.js index 3ec7f5d..e47f165 100644 --- a/server.js +++ b/server.js @@ -166,7 +166,9 @@ bog.keys().then(key => { if (obj.signature) { var ad = { author: obj.author, + hash: obj.hash, name: config.fullurl, + pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, content: obj.signature, views: obj.views } @@ -175,7 +177,9 @@ bog.keys().then(key => { if (obj.box) { var ad = { author: obj.author, + hash: obj.hash, name: config.fullurl, + pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, box: obj.box, views: obj.views } -- cgit v1.2.3-70-g09d2 From 9983e7b768f2fc04376e3dfad7335a8a7941dbaa Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Tue, 31 Dec 2019 15:58:18 -0600 Subject: refactor gossip v 1.8.0 --- beacons.js | 24 ++++ bog.js | 2 +- gossip.js | 352 ++++++++++++++++++++++++++---------------------------- package-lock.json | 2 +- package.json | 2 +- render.js | 15 ++- server.js | 5 +- settings.js | 6 +- views.js | 8 +- 9 files changed, 216 insertions(+), 200 deletions(-) (limited to 'gossip.js') diff --git a/beacons.js b/beacons.js index 79f88a5..3c65f3e 100644 --- a/beacons.js +++ b/beacons.js @@ -84,5 +84,29 @@ function beaconsPage (keys) { ])) scroller.appendChild(ads) + + localforage.getItem('beacons').then(beacons => { + beacons.forEach(beacon => { + var message = h('div', {classList: 'message'}) + + if (beacon.signature) { + open(beacon).then(opened => { + quickName(beacon.author).then(gotName => { + message.appendChild(h('p', {innerHTML: marked(opened)})) + message.appendChild(h('span', [ + '—', + h('a', {href: '#' + beacon.author}, [gotName]), + ' from ', + h('a', {href: beacon.name}, [beacon.name]) + ]) + ) + }) + }) + } + + scroller.appendChild(message) + console.log(beacon) + }) + }) } diff --git a/bog.js b/bog.js index e9477ed..55188e5 100644 --- a/bog.js +++ b/bog.js @@ -76,7 +76,7 @@ async function unbox (boxed, sender, keys) { var nonceMsg = nacl.util.decodeBase64(boxed) var nonce = nonceMsg.slice(0, nacl.box.nonceLength) var msg = nonceMsg.slice(nacl.box.nonceLength, nonceMsg.length) - var message = nacl.box.open(msg, nonce, ed2curve.convertPublicKey(nacl.util.decodeBase64(sender.substring(1))), ed2curve.convertSecretKey(nacl.util.decodeBase64(keys.privateKey))) + var message = nacl.util.encodeUTF8(nacl.box.open(msg, nonce, ed2curve.convertPublicKey(nacl.util.decodeBase64(sender.substring(1))), ed2curve.convertSecretKey(nacl.util.decodeBase64(keys.privateKey)))) return message } diff --git a/gossip.js b/gossip.js index 0c12a40..47d40c1 100644 --- a/gossip.js +++ b/gossip.js @@ -1,198 +1,180 @@ -function sync (subs, keys) { +function processreq (req, pubkey, connection, keys) { + console.log(req) + if (req.box || req.signature) { + renderAd(req, keys) + } - var wsServers - - localforage.getItem('securepubs').then(function (servers) { - if (servers) { - wsServers = servers - } else { - servers = ['ws://bogbook.com', 'ws://localhost:8080'] - var pubs = [] - servers.forEach(server => { - var ws = new WebSocket(server) - ws.onopen = function () { - ws.send(JSON.stringify({requester: keys.publicKey, sendpub: true})) - } - ws.onmessage = function (message) { - pubs.push(server + '/~' + message.data) - localforage.setItem('securepubs', pubs) - } - }) - wsServers = pubs - } - }).then(function () { - subs.forEach(function (sub, index) { - setTimeout(function () { - wsServers.forEach(function (server, index) { - setTimeout(function () { - //console.log('SYNCING WITH: ' + server + ' to fetch ' + sub) - var split = server.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) + if (req.seq === 0 || req.seq) { + console.log('feed sync') + bog(req.author).then(feed => { + if (feed) { + open(feed[0]).then(msg => { + if (req.seq > msg.seq) { + var reqdiff = JSON.stringify({author: req.author, seq: msg.seq}) + box(reqdiff, pubkey, keys).then(boxed => { + connection.send(JSON.stringify({ + requester: keys.publicKey, + box: boxed + })) + }) + } - bog(sub).then(srclog => { - if (srclog) { - open(srclog[0]).then(msg => { - ws.onopen = function () { - var message = JSON.stringify(msg) - // if we have a log then send the latest log and see if we get anything back - box(message, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } - ws.onmessage = function (message) { - var req = JSON.parse(message.data) - unbox(req.box, req.requester, keys).then(unboxed => { - var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (unboxedreq.content) { - unboxedreq.signature = unboxedreq.content - renderAd(unboxedreq, keys) - } - if (unboxedreq.box) { - renderAd(unboxedreq, keys) - } - if (unboxedreq.seq === 0) { - var stringedfeed = JSON.stringify(srclog) - box(stringedfeed, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - //console.log('Sending entire log of ' + msg.author + ' to ' + serverpub) - ws.send(JSON.stringify(obj)) - }) - } - - if (unboxedreq.seq > msg.seq) { - //console.log('server feed is longer, requesting diff from server') - var reqdiff = JSON.stringify({author: unboxedreq.author, seq: msg.seq}) - box(reqdiff, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } + if (req.seq < msg.seq) { + var endrange = feed.length - req.seq - 25 + if (endrange < 0) { + endrange = feed.length - req.seq - 1 + } + var baserange = feed.length - req.seq + var diff = JSON.stringify( + feed.slice( + endrange, + baserange) + ) + box(diff, pubkey, keys).then(boxed => { + connection.send(JSON.stringify({ + requester: keys.publicKey, + box: boxed + })) + }) + } + }) + } else { console.log('we dont have it')} + }) + } - if (unboxedreq.seq < msg.seq) { - //console.log('server feed is shorter, sending diff to server') - var diff = JSON.stringify(srclog.slice(0, msg.seq - unboxedreq.seq)) - box(diff, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - } + if (Array.isArray(req)) { + open(req[0]).then(msg => { + localforage.getItem(msg.author).then(feed => { + if (!feed) { + localforage.setItem(msg.author, req) + localforage.getItem('log').then(log => { + if (!log) { + var log = [] + } + for (var i = req.length -1; i >= 0; --i) { + open(req[i]).then(opened => { + log.unshift(opened) + var src = window.location.hash.substring(1) + if ((src === msg.author) || (src === '')) { + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + } + if (opened.seq === req.length) { + log.sort((a, b) => a.timestamp - b.timestamp) + var reversed = log.reverse() + localforage.setItem('log', reversed) + } + }) + } + }) + } if (feed) { + open(feed[0]).then(lastmsg => { + if (req.length + lastmsg.seq === msg.seq) { + var newlog = req.concat(feed) + localforage.setItem(msg.author, newlog) + localforage.getItem('log').then(log => { + if (!log) { + var log = [] + } + for (var i = req.length -1; i >= 0; --i) { + open(req[i]).then(opened => { + log.unshift(opened) + var scroller = document.getElementById('scroller') - if (Array.isArray(unboxedreq)) { - //console.log('received diff from server') - open(unboxedreq[0]).then(msg => { - localforage.getItem(msg.author).then(feed => { - open(feed[0]).then(lastmsg => { - if (unboxedreq.length + lastmsg.seq === msg.seq) { - var newlog = unboxedreq.concat(feed) - localforage.setItem(msg.author, newlog).then(success => { - //console.log('combined existing feed of ' + msg.author + ' with diff and saved to client') - }) - localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } - for (var i = unboxedreq.length -1; i >= 0; --i) { - open(unboxedreq[i]).then(opened => { - log.unshift(opened) - var scroller = document.getElementById('scroller') - - var src = window.location.hash.substring(1) - if ((src === sub) || (src === '')) { - var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) - } - if (unboxedreq.length + lastmsg.seq === opened.seq) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed).then(success => { - //console.log('saved log with ' + opened.author + ' prepended to localForage') - }) - } - }) - } - }) - } - }) - }) - }) - - } - - }) - } - }) - } else { - //console.log('NO LOG IN CLIENT') - ws.onopen = function () { - var reqwhole = JSON.stringify({author: sub, seq: 0}) - box(reqwhole, serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed + var src = window.location.hash.substring(1) + if ((src === msg.author) || (src === '')) { + var scroller = document.getElementById('scroller') + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) } - ws.send(JSON.stringify(obj)) - }) - } - ws.onmessage = function (message) { - var req = JSON.parse(message.data) - //console.log('received message from ' + req.requester) - unbox(req.box, req.requester, keys).then(unboxed => { - var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) - if (Array.isArray(unboxedreq)) { - open(unboxedreq[0]).then(msg => { - localforage.getItem(msg.author).then(feed => { - if (!feed) { - localforage.setItem(msg.author, unboxedreq).then(success => { - //console.log('saved log of ' + msg.author + ' to localforage') - }) - localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } - for (var i = unboxedreq.length -1; i >= 0; --i) { - open(unboxedreq[i]).then(opened => { - log.unshift(opened) - var src = window.location.hash.substring(1) - if ((src === sub) || (src === '')) { - var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) - } - if (opened.seq === unboxedreq.length) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed).then(success => { - //console.log('saved log with ' + opened.author + ' prepended to localForage') - }) - } - }) - } - }) - } - }) - }) + if (req.length + lastmsg.seq === opened.seq) { + log.sort((a, b) => a.timestamp - b.timestamp) + var reversed = log.reverse() + localforage.setItem('log', reversed) } }) } - } + }) + } + }) + } + }) + }) + } +} + +function getpubkey (connection, keys) { + console.log('asking for pubkey') + connection.onopen = () => { + connection.send(JSON.stringify({ + requester: keys.publicKey, sendpub: true + })) + } + + connection.onmessage = (m) => { + console.log(m) + localforage.setItem(m.origin, m.data) + } +} + +function getfeed (feed, pubkey, connection, keys) { + bog(feed).then(log => { + var logseq = 0 + connection.onopen = () => { + if (log) { + open(log[0]).then(msg => { + box(JSON.stringify(msg), pubkey, keys).then(boxed => { + connection.send(JSON.stringify({ + requester: keys.publicKey, + box: boxed + })) + }) + logseq = msg.seq + }) + } else { + var msg = { + author: feed, + seq: logseq + } + box(JSON.stringify(msg), pubkey, keys).then(boxed => { + connection.send(JSON.stringify({ + requester: keys.publicKey, + box: boxed + })) + }) + } + } + connection.onmessage = (m) => { + var req = JSON.parse(m.data) + unbox(req.box, req.requester, keys).then(unboxed => { + var unboxedreq = JSON.parse(unboxed) + processreq(unboxedreq, pubkey, connection, keys) + }) + } + }) +} + +function sync (feeds, keys) { + var pubs + localforage.getItem('pubs').then(pubs => { + if (!pubs) { + pubs = ['ws://' + location.hostname + ':8080'] + localforage.setItem('pubs', pubs) + } + pubs.forEach(function (pub, index) { + setTimeout(function () { + console.log(pub) + var connection = new WebSocket(pub) + localforage.getItem(pub).then(pubkey => { + if (!pubkey) { + getpubkey(connection, keys) + } + if (pubkey) { + feeds.forEach(feed => { + getfeed(feed, pubkey, connection, keys) }) - }, index * 50000) + } }) - }, index * 20000) + }, index * 5000) }) }) } diff --git a/package-lock.json b/package-lock.json index 655685a..ad97945 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.7.0", + "version": "1.8.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ac7e569..a174152 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.7.0", + "version": "1.8.0", "description": "secure blockchain logging (blogging, without the l) -- bogging", "main": "server.js", "scripts": { diff --git a/render.js b/render.js index 97798e6..f1e5511 100644 --- a/render.js +++ b/render.js @@ -21,7 +21,7 @@ function renderAd (ad, keys) { if (ad.box) { unbox(ad.box, ad.author, keys).then(unboxed => { if (unboxed) { - var msg = JSON.parse(nacl.util.encodeUTF8(unboxed)) + var msg = JSON.parse(unboxed) if (pmspot) { pmspot.parentNode.removeChild(pmspot) } @@ -65,6 +65,12 @@ function renderAd (ad, keys) { ws.send(JSON.stringify(obj)) localforage.setItem(ad.hash, true).then(success => { //console.log('heard: ' + ad.hash) + localforage.getItem('beacons').then(beacons => { + if (!beacons) { beacons = [] } + beacons.unshift(ad) + localforage.setItem('beacons', beacons) + }) + }) }) } @@ -100,8 +106,6 @@ function renderAd (ad, keys) { var serverpub = split[1] var ws = new WebSocket(serverurl) - - var tobox = { author: keys.publicKey, timestamp: Date.now(), @@ -122,6 +126,11 @@ function renderAd (ad, keys) { } ws.send(JSON.stringify(obj)) localforage.setItem(ad.hash, true).then(success => {console.log('heard: ' + ad.hash)}) + localforage.getItem('beacons').then(beacons => { + if (!beacons) { beacons = [] } + beacons.unshift(ad) + localforage.setItem('beacons', beacons) + }) }) } }) diff --git a/server.js b/server.js index e47f165..3904593 100644 --- a/server.js +++ b/server.js @@ -114,11 +114,12 @@ bog.keys().then(key => { wserve.on('connection', function (ws) { ws.on('message', function (message) { var req = JSON.parse(message) + console.log(req) if (req.sendpub) { ws.send(key.publicKey) } else { bog.unbox(req.box, req.requester, key).then(unboxed => { - var unboxedreq = JSON.parse(nacl.util.encodeUTF8(unboxed)) + var unboxedreq = JSON.parse(unboxed) //console.log(unboxedreq) if (unboxedreq.type == 'beacon') { if (unboxedreq.box) { @@ -169,7 +170,7 @@ bog.keys().then(key => { hash: obj.hash, name: config.fullurl, pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, - content: obj.signature, + signature: obj.signature, views: obj.views } } diff --git a/settings.js b/settings.js index c88ea07..f5b341c 100644 --- a/settings.js +++ b/settings.js @@ -52,18 +52,18 @@ function settingsPage (keys) { var pubs = h('div', {classList: 'message'}) - pubs.appendChild(h('p', {innerHTML: marked('These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com/~@h4e3bHDJeDWiCAkzp83HINPR4y7BLR7tI3fOVqwLQqw=\n```\n to your pubs list.')})) + pubs.appendChild(h('p', {innerHTML: marked('These are your bogbook pubs. Bogbook will gossip with these pubs to publish your messages and check for new messages from your subscriptions. You should have at least one Bogbook pub in order to gossip your messages. If you don\'t see a bogbook pub below, try clicking "Reset Pubs" or add \n```\nws://bogbook.com\n```\n to your pubs list.')})) var add = h('input', {placeholder: 'Add a pub'}) - localforage.getItem('securepubs').then(function (servers) { + localforage.getItem('pubs').then(function (servers) { pubs.appendChild(h('div', [ add, h('button', { onclick: function () { if (add.value) { servers.push(add.value) - localforage.setItem('securepubs', servers).then(function () { location.reload() }) + localforage.setItem('pubs', servers).then(function () { location.reload() }) } } }, ['Add a pub']) diff --git a/views.js b/views.js index b13d797..20cbd4b 100644 --- a/views.js +++ b/views.js @@ -15,10 +15,10 @@ function profilePage (src, keys) { var subs = [src] - var interval = 500 + var interval = 50 timer = function() { if (src === window.location.hash.substring(1)) { - if (interval < 10000) { interval = interval + 100 } + if (interval < 10000) { interval = interval + 50 } sync(subs, keys) setTimeout(timer, interval) } @@ -121,6 +121,7 @@ function searchPage (src, keys) { } function publicPage (keys) { + localforage.getItem('subscriptions').then(function (subs) { var interval = 1000 timer = function() { @@ -133,9 +134,8 @@ function publicPage (keys) { if (subs) { timer() } else { - var subs = [] + var subs = [keys.publickey] localforage.setItem('subscriptions', subs) - subs.push(keys.publicKey) timer() } }) -- cgit v1.2.3-70-g09d2 From 508e4c53a93cfa443dd590dd52f8fc22471d9e7c Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 3 Jan 2020 15:57:10 -0600 Subject: rip out beacons --- app.js | 3 -- beacons.js | 112 --------------------------------------- gossip.js | 10 +--- index.html | 1 - package-lock.json | 2 +- package.json | 2 +- render.js | 153 ------------------------------------------------------ server.js | 80 ---------------------------- 8 files changed, 4 insertions(+), 359 deletions(-) delete mode 100644 beacons.js (limited to 'gossip.js') diff --git a/app.js b/app.js index 5dd49a5..7fe1ae2 100644 --- a/app.js +++ b/app.js @@ -10,8 +10,6 @@ function route (keys) { if (src === 'settings') { settingsPage(keys) - } else if (src === 'beacons') { - beaconsPage(keys) } else if (src[0] === '@') { profilePage(src, keys) } else if (src[0] === '?') { @@ -30,7 +28,6 @@ keys().then(key => { h('div', {classList: 'internal'}, [ h('li', [h('a', {href: '#'}, ['Home'])]), h('li', [h('a', {href: '#' + key.publicKey}, [getName(key.publicKey, keys)])]), - h('li', [h('a', {href: '#beacons'}, ['Beacons'])]), h('li', {classList: 'right'}, [h('a', {href: '#settings'}, ['Settings'])]), h('form', { classList: 'search', onsubmit: function (e) { diff --git a/beacons.js b/beacons.js deleted file mode 100644 index 3c65f3e..0000000 --- a/beacons.js +++ /dev/null @@ -1,112 +0,0 @@ -function beaconsPage (keys) { - - var pubslist = h('select') - - localforage.getItem('securepubs').then(function (servers) { - servers.forEach(function (pub) { - pubslist.appendChild( - h('option', {value: pub}, [pub]) - ) - }) - }) - - var ads = h('div', {classList: 'message'}) - - ads.appendChild(h('span', {innerHTML: marked('Sometimes when you\'re lost on the Internet you might want to send out a beacon so that people can see you. \n\n Beacons from guests will run for 100 views before they are deleted by the pub. \n\nSelect a pub:')})) - - ads.appendChild(pubslist) - - var recp = h('input', {placeholder: 'Ex: @Q++V5BbvWIg8B+TqtC9ZKFhetruuw+nOgxEqfjlOZI0='}) - - var adstext = h('textarea', {placeholder: 'Hello World!'}) - - ads.appendChild(h('span', [ - h('br'), - h('p', [" Send a beacon (leave the 'To:' field blank for a public beacon): "]), - h('p', ['To: ', - recp - ]), - adstext, - h('br'), - h('button', { - onclick: function () { - var split = pubslist.value.split('~') - console.log(split) - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - if ((recp.value) && (adstext.value)) { - var tobox = { - author: keys.publicKey, - timestamp: Date.now(), - content: adstext.value - } - box(JSON.stringify(tobox), recp.value, keys).then(boxedmsg => { - var msg = { - type: 'beacon', - author: keys.publicKey, - box: boxedmsg - } - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - adstext.value = '' - recp.value = '' - } - }) - } - - if ((!recp.value) && (adstext.value)) { - var msg = { - type: 'beacon', - author: keys.publicKey - } - msg.signature = nacl.util.encodeBase64(nacl.sign(nacl.util.decodeUTF8(JSON.stringify(adstext.value)), nacl.util.decodeBase64(keys.privateKey))) - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) - adstext.value = '' - } - } - } - }, ['Publish']) - ])) - - scroller.appendChild(ads) - - localforage.getItem('beacons').then(beacons => { - beacons.forEach(beacon => { - var message = h('div', {classList: 'message'}) - - if (beacon.signature) { - open(beacon).then(opened => { - quickName(beacon.author).then(gotName => { - message.appendChild(h('p', {innerHTML: marked(opened)})) - message.appendChild(h('span', [ - '—', - h('a', {href: '#' + beacon.author}, [gotName]), - ' from ', - h('a', {href: beacon.name}, [beacon.name]) - ]) - ) - }) - }) - } - - scroller.appendChild(message) - console.log(beacon) - }) - }) -} - diff --git a/gossip.js b/gossip.js index 47d40c1..809266e 100644 --- a/gossip.js +++ b/gossip.js @@ -1,11 +1,5 @@ function processreq (req, pubkey, connection, keys) { - console.log(req) - if (req.box || req.signature) { - renderAd(req, keys) - } - if (req.seq === 0 || req.seq) { - console.log('feed sync') bog(req.author).then(feed => { if (feed) { open(feed[0]).then(msg => { @@ -38,7 +32,7 @@ function processreq (req, pubkey, connection, keys) { }) } }) - } else { console.log('we dont have it')} + } }) } @@ -157,7 +151,7 @@ function sync (feeds, keys) { var pubs localforage.getItem('pubs').then(pubs => { if (!pubs) { - pubs = ['ws://' + location.hostname + ':8080'] + pubs = ['ws://' + location.hostname + ':8080', 'ws://bogbook.com'] localforage.setItem('pubs', pubs) } pubs.forEach(function (pub, index) { diff --git a/index.html b/index.html index 5d18890..0396bcc 100644 --- a/index.html +++ b/index.html @@ -17,7 +17,6 @@ - diff --git a/package-lock.json b/package-lock.json index ad97945..e17dee8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.8.0", + "version": "1.8.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a174152..437d4c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bogbook", - "version": "1.8.0", + "version": "1.8.1", "description": "secure blockchain logging (blogging, without the l) -- bogging", "main": "server.js", "scripts": { diff --git a/render.js b/render.js index f1e5511..e807c1e 100644 --- a/render.js +++ b/render.js @@ -1,156 +1,3 @@ -function renderAd (ad, keys) { - localforage.getItem(ad.hash).then(heard => { - if (!heard) { - var screen = document.getElementById('screen') - var adspot = document.getElementById('ad') - var pmspot = document.getElementById('pm') - - if (adspot) { - adspot.parentNode.removeChild(adspot) - } - - - var adspace = h('span') - - if (ad.views) { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', [ad.views + ' views'])])) - } else { - adspace.appendChild(h('span', {classList: 'right'}, [h('pre', ['beacon'])])) - } - - if (ad.box) { - unbox(ad.box, ad.author, keys).then(unboxed => { - if (unboxed) { - var msg = JSON.parse(unboxed) - if (pmspot) { - pmspot.parentNode.removeChild(pmspot) - } - quickName(ad.author).then(gotName => { - beacon = h('div', {id: 'pm'}, [ - h('span', {classList: 'right'}, [h('pre', [human(new Date(msg.timestamp))])]), - h('p', {innerHTML: marked(msg.content)}), - h('button', {classList: 'right', - onclick: function () { - pmspot = document.getElementById('pm') - pmspot.parentNode.removeChild(pmspot) - if (msg.content.substring((msg.content.length - 6), msg.content.length) === 'Heard.') { - localforage.setItem(ad.hash, true).then(success => { - //console.log('heard: ' + ad.hash) - }) - - } else { - var split = ad.pub.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - var tobox = { - author: keys.publicKey, - timestamp: Date.now(), - content: '>' + msg.content + '\n\nHeard.' - } - - box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { - var msg = { - type: 'beacon', - author: keys.publicKey, - box: boxedmsg - } - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - localforage.setItem(ad.hash, true).then(success => { - //console.log('heard: ' + ad.hash) - localforage.getItem('beacons').then(beacons => { - if (!beacons) { beacons = [] } - beacons.unshift(ad) - localforage.setItem('beacons', beacons) - }) - - }) - }) - } - }) - } - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - screen.append(beacon) - }) - } - }) - } - - if (ad.signature) { - open(ad).then(opened => { - quickName(ad.author).then(gotName => { - newAd = h('div', {id: 'ad'}, [ - adspace, - h('p', {innerHTML: marked(opened)}), - h('button', {classList: 'right', - onclick: function () { - adspot = document.getElementById('ad') - adspot.parentNode.removeChild(adspot) - var split = ad.pub.split('~') - var serverurl = split[0] - var serverpub = split[1] - var ws = new WebSocket(serverurl) - - var tobox = { - author: keys.publicKey, - timestamp: Date.now(), - content: '>' + opened + '\n\nHeard.' - } - - box(JSON.stringify(tobox), ad.author, keys).then(boxedmsg => { - var msg = { - type: 'beacon', - author: keys.publicKey, - box: boxedmsg - } - ws.onopen = function () { - box(JSON.stringify(msg), serverpub, keys).then(boxed => { - var obj = { - requester: keys.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - localforage.setItem(ad.hash, true).then(success => {console.log('heard: ' + ad.hash)}) - localforage.getItem('beacons').then(beacons => { - if (!beacons) { beacons = [] } - beacons.unshift(ad) - localforage.setItem('beacons', beacons) - }) - }) - } - }) - } - }, ['Heard']), - h('span', [ - '—', - h('a', {href: '#' + ad.author}, [gotName]), - ' from ', - h('a', {href: ad.name}, [ad.name]) - ]) - ]) - screen.appendChild(newAd) - }) - }) - } - } - }) -} - function getHeader (post, keys, mini) { var getRaw = h('button', { onclick: function () { diff --git a/server.js b/server.js index ad802d1..fbe92e0 100644 --- a/server.js +++ b/server.js @@ -3,7 +3,6 @@ var homedir = require('os').homedir() var path = homedir + '/.bogbook/' var bogdir = path + 'bogs/' -var addir = path + 'ads/' var confpath = path + 'config.json' if (!fs.existsSync(homedir + '/.bogbook/')) {fs.mkdirSync(homedir + '/.bogbook/')} @@ -120,33 +119,6 @@ bog.keys().then(key => { bog.unbox(req.box, req.requester, key).then(unboxed => { var unboxedreq = JSON.parse(unboxed) //console.log(unboxedreq) - if (unboxedreq.type == 'beacon') { - if (unboxedreq.box) { - var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.box))).toString('hex') - - var obj = { - hash: hex, - author: unboxedreq.author, - box: unboxedreq.box, - views: 0 - } - } - - if (unboxedreq.signature) { - var hex = Buffer.from(nacl.hash(nacl.util.decodeUTF8(unboxedreq.signature))).toString('hex') - var obj = { - hash: hex, - author: unboxedreq.author, - signature: unboxedreq.signature, - views: 0 - } - } - - fs.writeFile(addir + hex, JSON.stringify(obj), 'UTF-8', function () { - console.log('Saved as ' + hex) - }) - ws.close() - } if (unboxedreq.seq >= 0) { printAsk(req, unboxedreq) fs.readFile(bogdir + unboxedreq.author, 'UTF-8', function (err, data) { @@ -155,58 +127,6 @@ bog.keys().then(key => { bog.open(feed[0]).then(msg => { if (unboxedreq.seq === msg.seq) { printFeedIdentical(msg, req) - if (config.ads) { - if (Math.floor(Math.random() * 6) == 2) { - fs.readdir(addir, function (err, adfiles) { - if (adfiles) { - var num = Math.floor(Math.random() * (adfiles.length)) - fs.readFile(addir + adfiles[num], 'UTF-8', function (err, adFile) { - var obj = JSON.parse(adFile) - - if (obj.signature) { - var ad = { - author: obj.author, - hash: obj.hash, - name: config.fullurl, - pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, - signature: obj.signature, - views: obj.views - } - } - - if (obj.box) { - var ad = { - author: obj.author, - hash: obj.hash, - name: config.fullurl, - pub: 'ws://' + config.url + ':' + config.wsport + '/~' + key.publicKey, - box: obj.box, - views: obj.views - } - } - - if ((obj.views > 100) && (obj.author != config.author)) { - fs.unlinkSync(addir + obj.hash) - //console.log('REMOVING AD') - } else { - obj.views++ - fs.writeFileSync(addir + obj.hash, JSON.stringify(obj), 'UTF-8') - } - printSendAd(ad, req) - //console.log('SENDING AD') - bog.box(JSON.stringify(ad), req.requester, key).then(boxed => { - sendobj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(sendobj)) - ws.close() - }) - }) - } - }) - } - } } if (unboxedreq.seq > msg.seq) { printClientLonger(msg, req) -- cgit v1.2.3-70-g09d2 From df5dd87b165d3496e808b5ab443ed5f919f3e88c Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 10 Jan 2020 09:24:18 -0600 Subject: attempt to fix bug where subs end up as null --- gossip.js | 40 ++++++++++++++++++++++++---------------- render.js | 2 -- views.js | 18 ++++++++++++++++-- 3 files changed, 40 insertions(+), 20 deletions(-) (limited to 'gossip.js') diff --git a/gossip.js b/gossip.js index 809266e..828b471 100644 --- a/gossip.js +++ b/gossip.js @@ -1,11 +1,15 @@ function processreq (req, pubkey, connection, keys) { + console.log('processreq') if (req.seq === 0 || req.seq) { bog(req.author).then(feed => { if (feed) { + console.log('opening first message') open(feed[0]).then(msg => { + console.log(msg) if (req.seq > msg.seq) { var reqdiff = JSON.stringify({author: req.author, seq: msg.seq}) box(reqdiff, pubkey, keys).then(boxed => { + console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -25,6 +29,7 @@ function processreq (req, pubkey, connection, keys) { baserange) ) box(diff, pubkey, keys).then(boxed => { + console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -42,9 +47,7 @@ function processreq (req, pubkey, connection, keys) { if (!feed) { localforage.setItem(msg.author, req) localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } + if (!log) { var log = [] } for (var i = req.length -1; i >= 0; --i) { open(req[i]).then(opened => { log.unshift(opened) @@ -54,36 +57,30 @@ function processreq (req, pubkey, connection, keys) { scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) } if (opened.seq === req.length) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed) + localforage.setItem('log', log) } }) } }) - } if (feed) { + } + if (feed) { open(feed[0]).then(lastmsg => { + console.log(lastmsg) if (req.length + lastmsg.seq === msg.seq) { var newlog = req.concat(feed) localforage.setItem(msg.author, newlog) localforage.getItem('log').then(log => { - if (!log) { - var log = [] - } + if (!log) { var log = [] } for (var i = req.length -1; i >= 0; --i) { open(req[i]).then(opened => { log.unshift(opened) - var scroller = document.getElementById('scroller') - var src = window.location.hash.substring(1) if ((src === msg.author) || (src === '')) { var scroller = document.getElementById('scroller') scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) } if (req.length + lastmsg.seq === opened.seq) { - log.sort((a, b) => a.timestamp - b.timestamp) - var reversed = log.reverse() - localforage.setItem('log', reversed) + localforage.setItem('log', log) } }) } @@ -111,12 +108,18 @@ function getpubkey (connection, keys) { } function getfeed (feed, pubkey, connection, keys) { + console.log('getfeed') bog(feed).then(log => { var logseq = 0 connection.onopen = () => { if (log) { + console.log('onopen') + console.log(log[0]) + // for some reason this does not open below open(log[0]).then(msg => { - box(JSON.stringify(msg), pubkey, keys).then(boxed => { + var string = JSON.stringify(msg) + box(string, pubkey, keys).then(boxed => { + console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -125,6 +128,7 @@ function getfeed (feed, pubkey, connection, keys) { logseq = msg.seq }) } else { + console.log('else') var msg = { author: feed, seq: logseq @@ -138,6 +142,7 @@ function getfeed (feed, pubkey, connection, keys) { } } connection.onmessage = (m) => { + console.log('onmessage') var req = JSON.parse(m.data) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(unboxed) @@ -163,7 +168,10 @@ function sync (feeds, keys) { getpubkey(connection, keys) } if (pubkey) { + console.log(pubkey) + console.log(feeds) feeds.forEach(feed => { + console.log('getting ' + feed) getfeed(feed, pubkey, connection, keys) }) } diff --git a/render.js b/render.js index aaea0c2..e440abd 100644 --- a/render.js +++ b/render.js @@ -142,8 +142,6 @@ function render (msg, keys, preview) { message.appendChild(getHeader(msg, keys, mini)) - console.log(getTitle(msg.reply)) - if (msg.reply) { getTitle(msg.reply).then(title => { if (!title) { diff --git a/views.js b/views.js index d8c537f..b964915 100644 --- a/views.js +++ b/views.js @@ -138,7 +138,13 @@ function searchPage (src, keys) { function publicPage (keys) { - localforage.getItem('subscriptions').then(function (subs) { + localforage.getItem('log').then(log => { + log.sort((a, b) => a.timestamp - b.timestamp) + var reversed = log.reverse() + localforage.setItem('log', reversed) + }) + + localforage.getItem('subscriptions').then(subs => { var interval = 1000 timer = function() { if ('' === window.location.hash.substring(1)) { @@ -148,9 +154,17 @@ function publicPage (keys) { } } if (subs) { + // the next two lines just fix a bug where the first sub was being set to null. Delete this code after March 2020. + subs.forEach(sub => { + if (sub == null) { + var subs = [keys.publicKey] + localforage.setItem('subscriptions', subs) + } + }) timer() } else { - var subs = [keys.publickey] + var subs = [keys.publicKey] + console.log(subs) localforage.setItem('subscriptions', subs) timer() } -- cgit v1.2.3-70-g09d2 From 5f47d7c1ca5e5baed3180c125844803804a8a7a1 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 10 Jan 2020 13:52:42 -0600 Subject: remove console.logs --- gossip.js | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'gossip.js') diff --git a/gossip.js b/gossip.js index 828b471..26915b1 100644 --- a/gossip.js +++ b/gossip.js @@ -1,15 +1,11 @@ function processreq (req, pubkey, connection, keys) { - console.log('processreq') if (req.seq === 0 || req.seq) { bog(req.author).then(feed => { if (feed) { - console.log('opening first message') open(feed[0]).then(msg => { - console.log(msg) if (req.seq > msg.seq) { var reqdiff = JSON.stringify({author: req.author, seq: msg.seq}) box(reqdiff, pubkey, keys).then(boxed => { - console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -29,7 +25,6 @@ function processreq (req, pubkey, connection, keys) { baserange) ) box(diff, pubkey, keys).then(boxed => { - console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -65,7 +60,6 @@ function processreq (req, pubkey, connection, keys) { } if (feed) { open(feed[0]).then(lastmsg => { - console.log(lastmsg) if (req.length + lastmsg.seq === msg.seq) { var newlog = req.concat(feed) localforage.setItem(msg.author, newlog) @@ -94,7 +88,6 @@ function processreq (req, pubkey, connection, keys) { } function getpubkey (connection, keys) { - console.log('asking for pubkey') connection.onopen = () => { connection.send(JSON.stringify({ requester: keys.publicKey, sendpub: true @@ -102,24 +95,18 @@ function getpubkey (connection, keys) { } connection.onmessage = (m) => { - console.log(m) localforage.setItem(m.origin, m.data) } } function getfeed (feed, pubkey, connection, keys) { - console.log('getfeed') bog(feed).then(log => { var logseq = 0 connection.onopen = () => { if (log) { - console.log('onopen') - console.log(log[0]) - // for some reason this does not open below open(log[0]).then(msg => { var string = JSON.stringify(msg) box(string, pubkey, keys).then(boxed => { - console.log(boxed) connection.send(JSON.stringify({ requester: keys.publicKey, box: boxed @@ -128,7 +115,6 @@ function getfeed (feed, pubkey, connection, keys) { logseq = msg.seq }) } else { - console.log('else') var msg = { author: feed, seq: logseq @@ -142,7 +128,6 @@ function getfeed (feed, pubkey, connection, keys) { } } connection.onmessage = (m) => { - console.log('onmessage') var req = JSON.parse(m.data) unbox(req.box, req.requester, keys).then(unboxed => { var unboxedreq = JSON.parse(unboxed) @@ -161,17 +146,13 @@ function sync (feeds, keys) { } pubs.forEach(function (pub, index) { setTimeout(function () { - console.log(pub) var connection = new WebSocket(pub) localforage.getItem(pub).then(pubkey => { if (!pubkey) { getpubkey(connection, keys) } if (pubkey) { - console.log(pubkey) - console.log(feeds) feeds.forEach(feed => { - console.log('getting ' + feed) getfeed(feed, pubkey, connection, keys) }) } -- cgit v1.2.3-70-g09d2 From cb59e302155933359a8500b3094b1fb495c89afb Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Fri, 10 Jan 2020 17:47:28 -0600 Subject: add background photos -- not quite done yet --- css/style.css | 7 +++++- gossip.js | 4 +-- identify.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- render.js | 16 ++++++++++-- views.js | 24 ++++++++++++++++-- 5 files changed, 119 insertions(+), 10 deletions(-) (limited to 'gossip.js') diff --git a/css/style.css b/css/style.css index 7ec1ee4..df53ffe 100644 --- a/css/style.css +++ b/css/style.css @@ -59,11 +59,16 @@ hr { .message, .profile { border: 1px solid #ddd; background: white; - margin-top: .5em; + margin-bottom: .5em; padding: .3em .5em; +} + +.message { border-radius: 5px; } +.banner { height: 275px; } + #scroller:last-child { margin-bottom: 10em; } .message, .message > *, .navbar, .navbar > *, #ad, #ad > *, #viewer > * { diff --git a/gossip.js b/gossip.js index 26915b1..5cf19e9 100644 --- a/gossip.js +++ b/gossip.js @@ -49,7 +49,7 @@ function processreq (req, pubkey, connection, keys) { var src = window.location.hash.substring(1) if ((src === msg.author) || (src === '')) { var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) } if (opened.seq === req.length) { localforage.setItem('log', log) @@ -71,7 +71,7 @@ function processreq (req, pubkey, connection, keys) { var src = window.location.hash.substring(1) if ((src === msg.author) || (src === '')) { var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) } if (req.length + lastmsg.seq === opened.seq) { localforage.setItem('log', log) diff --git a/identify.js b/identify.js index 1381c6f..eb8827c 100644 --- a/identify.js +++ b/identify.js @@ -8,6 +8,72 @@ function identify (src, profile, keys) { var photoURL = {} + // this could be a hell of a lot dry-er + + // also we need to get rid of UI glitches when you hit the cancel button (it should return to the same state it started in) + + var newBackground = h('span', [ + h('input', {id: 'input', type: 'file', + onclick: function () { + var canvas = document.getElementById("canvas") + var ctx = canvas.getContext("2d") + + var maxW + var maxH + + var input = document.getElementById('input') + input.addEventListener('change', handleFiles) + + function handleFiles(e) { + var img = new Image + img.onload = function() { + var iw = img.width + var ih = img.height + + maxW = 800 + maxH = 800 + + var scale = Math.min((maxW/iw), (maxH/ih)) + var iwScaled = iw*scale + var ihScaled = ih*scale + canvas.width = iwScaled + canvas.height = ihScaled + ctx.drawImage(img, 0, 0, iwScaled, ihScaled) + photoURL.value = canvas.toDataURL('image/jpeg', 0.7) + } + img.src = URL.createObjectURL(e.target.files[0]) + } + } + }), + h('canvas', {id: 'canvas', width: '0', height: '0'}), + h('button', { + onclick: function () { + identifyDiv.appendChild(identifyButtons) + newBackground.parentNode.removeChild(newBackground) + } + }, ['Cancel']), + h('button', { + onclick: function () { + if (photoURL.value) { + content = { + type: 'background', + backgrounded: src, + background: photoURL.value + } + localforage.removeItem('image:' + src) + publish(content, keys).then(post => { + open(post).then(msg => { + nameInput.value = '' + scroller.insertBefore(render(msg, keys), scroller.childNodes[1]) + }) + }) + newBackground.parentNode.removeChild(newBackground) + identifyDiv.appendChild(identifyButton) + } + } + }, ['Publish']) + ]) + var newPhoto = h('span', [ h('input', {id: 'input', type: 'file', onclick: function () { @@ -47,7 +113,6 @@ function identify (src, profile, keys) { canvas.width = iwScaled canvas.height = ihScaled ctx.drawImage(img, 0, 0, iwScaled, ihScaled) - console.log(canvas.toDataURL('image/jpeg', 0.9)) photoURL.value = canvas.toDataURL('image/jpeg', 0.9) } img.src = URL.createObjectURL(e.target.files[0]) @@ -69,7 +134,6 @@ function identify (src, profile, keys) { imaged: src, image: photoURL.value } - console.log(content) localforage.removeItem('image:' + src) publish(content, keys).then(post => { open(post).then(msg => { @@ -84,6 +148,9 @@ function identify (src, profile, keys) { }, ['Publish']) ]) + + + var nameInput = h('input', {placeholder: 'New name'}) var newName = h('div', [ @@ -125,7 +192,12 @@ function identify (src, profile, keys) { identifyButtons.parentNode.removeChild(identifyButtons) } }, ['New name'])) - + identifyButtons.appendChild(h('button', { + onclick: function () { + identifyDiv.appendChild(newBackground) + identifyButtons.parentNode.removeChild(identifyButtons) + } + }, ['New background'])) } //}, ['Identify ' + src.substring(0, 10) + '... with a new name']), identifyButtons.appendChild(h('button', { diff --git a/render.js b/render.js index e440abd..faf3c17 100644 --- a/render.js +++ b/render.js @@ -183,10 +183,11 @@ function render (msg, keys, preview) { message.appendChild(buttons) } - } else if (msg.type == 'name') { + } if (msg.type == 'name') { var mini = h('span', [' identified ', h('a', {href: '#' + msg.named }, [msg.named.substring(0, 10) + '...']), ' as ' + msg.name]) message.appendChild(getHeader(msg, keys, mini)) - } else if (msg.type == 'image') { + + } if (msg.type == 'image') { var mini = h('span', [ ' added an image to ', h('a', { href: '#' + msg.imaged }, [msg.imaged.substring(0, 10) + '...']), @@ -194,8 +195,19 @@ function render (msg, keys, preview) { h('img', {src: msg.image, classList: 'avatar'}) ]) message.appendChild(getHeader(msg, keys, mini)) + + } if (msg.type == 'background') { + var mini = h('span', [ + ' added a background to ', + h('a', { href: '#' + msg.backgrounded }, [msg.backgrounded.substring(0, 10) + '...']), + ' ', + h('img', {src: msg.background, classList: 'avatar'}) + ]) + message.appendChild(getHeader(msg, keys, mini)) } + + messageDiv.appendChild(message) return messageDiv } diff --git a/views.js b/views.js index b964915..da1eeb9 100644 --- a/views.js +++ b/views.js @@ -9,7 +9,24 @@ function profilePage (src, keys) { msg.author = src var profile = h('div', {classList: 'profile'}) + var banner = h('div', {classList: 'banner'}) + + function getBg (src, profile) { + bog().then(log => { + if (log) { + for (var i = 0; i < log.length; i++) { + if ((log[i].backgrounded === src) && (log[i].author === src)) { + // if you've identified someone as something else show that something else + return banner.style.background = 'fixed top/680px no-repeat url(' + log[i].background + ')' + } + } + } + }) + } + + getBg(src, profile) + scroller.appendChild(banner) scroller.appendChild(profile) //scroller.appendChild(h('div')) @@ -27,12 +44,15 @@ function profilePage (src, keys) { profile.appendChild(h('a', {href: '#' + src}, [ getImage(src, keys, 'profileAvatar'), - getName(src, keys) + getName(src, keys), + h('br'), + h('br') ])) profile.appendChild(h('br')) quickName(src).then(name => { + profile.appendChild(identify(src, profile, keys, name)) var mentionsButton = h('button', { onclick: function () { location.href = '#?' + src @@ -76,7 +96,6 @@ function profilePage (src, keys) { }, ['Delete ' + name + '\'s feed'])) }) - profile.appendChild(identify(src, profile, keys)) async function addPosts (posts, keys) { posts.forEach(function (msg) { @@ -197,3 +216,4 @@ function publicPage (keys) { }) } + -- cgit v1.2.3-70-g09d2 From dac0064cf55e6a3f9321ea78875bfe8ca9952fc3 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 11 Jan 2020 06:13:44 -0600 Subject: finish adding backgrounds to profiles --- css/style.css | 4 ++-- gossip.js | 4 ++-- identify.js | 6 +++--- views.js | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) (limited to 'gossip.js') diff --git a/css/style.css b/css/style.css index df53ffe..26784e7 100644 --- a/css/style.css +++ b/css/style.css @@ -56,6 +56,8 @@ hr { .right { float: right;} +.banner {height: 10px; } + .message, .profile { border: 1px solid #ddd; background: white; @@ -67,8 +69,6 @@ hr { border-radius: 5px; } -.banner { height: 275px; } - #scroller:last-child { margin-bottom: 10em; } .message, .message > *, .navbar, .navbar > *, #ad, #ad > *, #viewer > * { diff --git a/gossip.js b/gossip.js index 5cf19e9..26915b1 100644 --- a/gossip.js +++ b/gossip.js @@ -49,7 +49,7 @@ function processreq (req, pubkey, connection, keys) { var src = window.location.hash.substring(1) if ((src === msg.author) || (src === '')) { var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) } if (opened.seq === req.length) { localforage.setItem('log', log) @@ -71,7 +71,7 @@ function processreq (req, pubkey, connection, keys) { var src = window.location.hash.substring(1) if ((src === msg.author) || (src === '')) { var scroller = document.getElementById('scroller') - scroller.insertBefore(render(opened, keys), scroller.childNodes[2]) + scroller.insertBefore(render(opened, keys), scroller.childNodes[1]) } if (req.length + lastmsg.seq === opened.seq) { localforage.setItem('log', log) diff --git a/identify.js b/identify.js index eb8827c..f56a0f9 100644 --- a/identify.js +++ b/identify.js @@ -1,4 +1,4 @@ -function identify (src, profile, keys) { +function identify (src, profile, keys, name) { var identifyDiv = h('div') @@ -213,7 +213,6 @@ function identify (src, profile, keys) { identifyButtons.parentNode.removeChild(identifyButtons) } }, ['Cancel'])) - if (src[0] == '@') { var identifyButton = h('button', { onclick: function () { @@ -221,7 +220,7 @@ function identify (src, profile, keys) { profile.appendChild(identifyButtons) identifyButton.parentNode.removeChild(identifyButton) } - }, ['Identify ' + src.substring(0, 10) + '...']) + }, ['Identify ' + name]) } else { var identifyButton = h('button', { onclick: function () { @@ -231,6 +230,7 @@ function identify (src, profile, keys) { } }, ['Add to ' + src.substring(0, 10) + '...']) } + return identifyButton } diff --git a/views.js b/views.js index da1eeb9..d6fb5f2 100644 --- a/views.js +++ b/views.js @@ -8,6 +8,7 @@ function profilePage (src, keys) { var msg = {} msg.author = src + var profileDiv = h('div') var profile = h('div', {classList: 'profile'}) var banner = h('div', {classList: 'banner'}) @@ -16,7 +17,8 @@ function profilePage (src, keys) { if (log) { for (var i = 0; i < log.length; i++) { if ((log[i].backgrounded === src) && (log[i].author === src)) { - // if you've identified someone as something else show that something else + // if you've identified someone as something else show that something else + banner.style.height = '300px' return banner.style.background = 'fixed top/680px no-repeat url(' + log[i].background + ')' } } @@ -26,9 +28,9 @@ function profilePage (src, keys) { getBg(src, profile) - scroller.appendChild(banner) - scroller.appendChild(profile) - //scroller.appendChild(h('div')) + profileDiv.appendChild(banner) + profileDiv.appendChild(profile) + scroller.appendChild(profileDiv) var subs = [src] @@ -45,8 +47,6 @@ function profilePage (src, keys) { profile.appendChild(h('a', {href: '#' + src}, [ getImage(src, keys, 'profileAvatar'), getName(src, keys), - h('br'), - h('br') ])) profile.appendChild(h('br')) -- cgit v1.2.3-70-g09d2 From 970777008147f611bef649ac1d682c8f9e3a44fa Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 19 Jan 2020 09:20:23 -0600 Subject: send latest five posts if the feed has many unsynced messages, render latest in the client if we are not caught up --- gossip.js | 37 +++++++++++++++++++++++++++++++++++++ server.js | 26 +++++++++++++++----------- views.js | 2 +- 3 files changed, 53 insertions(+), 12 deletions(-) (limited to 'gossip.js') diff --git a/gossip.js b/gossip.js index 26915b1..a67ea3c 100644 --- a/gossip.js +++ b/gossip.js @@ -36,6 +36,43 @@ function processreq (req, pubkey, connection, keys) { }) } + if (req.latest) { + var latest + latest = document.getElementById('latest') + var src = window.location.hash.substring(1) + if ((!latest) && (src == req.latest)) { + latest = h('div', {id: 'latest'}) + latest.appendChild(h('div', {classList: 'message', innerHTML: marked('**Still syncing feed**. In the meantime, here are the latest five messages...') + })) + req.feed.forEach(post => { + open(post).then(msg => { + latest.appendChild(render(msg, keys)) + }) + }) + scroller.firstChild.appendChild(latest) + + var timer = setInterval(function () { + localforage.getItem(req.latest).then(feed => { + open(feed[0]).then(msg => { + open(req.feed[0]).then(latestmsg => { + src = window.location.hash.substring(1) + if (msg.seq >= latestmsg.seq) { + latest.parentNode.removeChild(latest) + clearInterval(timer) + console.log('we are caught up, deleting latest div') + } + if (src != req.latest) { + clearInterval(timer) + console.log('we navigated away') + } + }) + }) + }) + console.log('checking to see if we have caught up') + }, 5000) + } + } + if (Array.isArray(req)) { open(req[0]).then(msg => { localforage.getItem(msg.author).then(feed => { diff --git a/server.js b/server.js index a73f5ad..dd75528 100644 --- a/server.js +++ b/server.js @@ -140,17 +140,21 @@ bog.keys().then(key => { } var baserange = feed.length - unboxedreq.seq printClientShorter(msg, req, baserange, endrange) - var latest = JSON.stringify({ - latest: true, - feed: feed.slice(0, 15) - }) - bog.box(latest, req.requester, key).then(boxed => { - var obj = { - requester: key.publicKey, - box: boxed - } - ws.send(JSON.stringify(obj)) - }) + if (baserange > 50) { + var latest = JSON.stringify({ + latest: unboxedreq.author, + feed: feed.slice(0, 5) + }) + bog.box(latest, req.requester, key).then(boxed => { + var obj = { + requester: key.publicKey, + box: boxed + } + console.log('sending latest ' + unboxedreq.author) + ws.send(JSON.stringify(obj)) + }) + } + var diff = JSON.stringify( feed.slice( endrange, diff --git a/views.js b/views.js index 1cfe338..1878b3c 100644 --- a/views.js +++ b/views.js @@ -28,7 +28,7 @@ function profilePage (src, keys) { } sync([src], keys) console.log('syncing ' + src) - }, 2500) + }, 5000) /*timer = function() { if (src === window.location.hash.substring(1)) { -- cgit v1.2.3-70-g09d2 From 7a5291fd24326b799db92fc4f15c49111ab7c172 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sun, 19 Jan 2020 09:22:14 -0600 Subject: comment out console logs --- gossip.js | 6 +++--- server.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'gossip.js') diff --git a/gossip.js b/gossip.js index a67ea3c..be16a9c 100644 --- a/gossip.js +++ b/gossip.js @@ -59,16 +59,16 @@ function processreq (req, pubkey, connection, keys) { if (msg.seq >= latestmsg.seq) { latest.parentNode.removeChild(latest) clearInterval(timer) - console.log('we are caught up, deleting latest div') + //console.log('we are caught up, deleting latest div') } if (src != req.latest) { clearInterval(timer) - console.log('we navigated away') + //console.log('we navigated away') } }) }) }) - console.log('checking to see if we have caught up') + //console.log('checking to see if we have caught up') }, 5000) } } diff --git a/server.js b/server.js index dd75528..9a53943 100644 --- a/server.js +++ b/server.js @@ -150,7 +150,7 @@ bog.keys().then(key => { requester: key.publicKey, box: boxed } - console.log('sending latest ' + unboxedreq.author) + //console.log('sending latest ' + unboxedreq.author) ws.send(JSON.stringify(obj)) }) } -- cgit v1.2.3-70-g09d2