aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.js3
-rw-r--r--beacons.js112
-rw-r--r--gossip.js10
-rw-r--r--index.html1
-rw-r--r--package-lock.json2
-rw-r--r--package.json2
-rw-r--r--render.js153
-rw-r--r--server.js80
8 files changed, 4 insertions, 359 deletions
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 @@
<script src="bog.js"></script>
<script src="composer.js"></script>
<script src="settings.js"></script>
- <script src="beacons.js"></script>
<script src="identify.js"></script>
<script src="render.js"></script>
<script src="gossip.js"></script>
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)