basic message creation done

This commit is contained in:
Kevin Froman 2020-10-06 02:07:48 +00:00
parent 1889989e20
commit c362ff33c0
6 changed files with 40 additions and 7 deletions

View File

@ -17,8 +17,8 @@
*/
var findMessageIntervalTime = 5000
var publicNodes = [
"yre3tmbu25lcogl42xlh73wfchgbx3unz2zz3ttyiylj6gaq5mzhevid",
"ltqmmfww3tue6tibtyfc4kk7edh3owewxwcgrkvwqw4cwgd3w3zcj6id"
"67xpi7z753tbmylc7etrifjxqeyizoiqg6n7p5we6e4nblit5bqenqad",
"mpidhsfpmdgxxc5ygqluwtxptgne5swp5nkjzdre6tmnent7zqwp3cyd"
]
var messageHashes = []
var blocks = []
@ -116,8 +116,7 @@ async function findMessages(){
document.getElementById('memUsage').innerText = getReadableFileSizeString(current + ((basicTextEncoder.encode(data)).length + block.length))
}
let metadata = JSON.parse(d.split("\n")[0])
console.debug(metadata)
//let data = d.split('\n')[1]
let data = d.substring(d.indexOf('\n') + 1);
try{
verifyBlock(d, block)

View File

@ -20,6 +20,7 @@
<script src="onionr-blocks.js" defer></script>
<script src="hush-hush.js" defer></script>
<script src="worker-handler.js" defer></script>
<script src="message-creator.js" defer></script>
</head>
<body>
<section class="section">
@ -48,7 +49,7 @@
<div class="postForm">
<div class="control">
<p>Markdown is supported, except for images, styles and scripts.</p>
<textarea class="textarea" placeholder="Draft a post..."></textarea>
<textarea class="textarea" placeholder="Draft a post..." id="postMessageField"></textarea>
</div>
</div>
</div>
@ -56,7 +57,7 @@
</div>
</div>
<div class="control">
<a class="button is-primary">Create Post</a>
<a class="button is-primary" id="createMessageBtn">Create Post</a>
</div>
</div>
<div class="container messageFeed">

29
message-creator.js Normal file
View File

@ -0,0 +1,29 @@
document.getElementById("createMessageBtn").onclick = async function(){
let field = document.getElementById("postMessageField")
let payload = {
"metadata": {
'time': Math.floor((Date.now() / 1000)),
'meta': JSON.stringify({'type': 'brd', 'ch': 'global'})
},
"data": field.value,
"difficulty": difficulty.length / 2
}
powWorker.postMessage(JSON.stringify(payload))
}
powWorker.addEventListener('message', function(e) {
let decoder = new TextDecoder("utf-8")
let message = decoder.decode(e.data)
fetch('http://' + getCurrentNode() + '.onion/upload', {
method: 'POST',
headers: {
"content-type": "application/octet-stream"
},
body: decoder.decode(e.data)
})
console.debug("Generated block: " + doHashHex(e.data))
}, false)

View File

@ -31,6 +31,9 @@ self.addEventListener('message', async function(e) {
let peerList = await lookupPeer(peer)
peerList.forEach(node => {
if (node){
//if (await (await fetch('http://' + node + '.onion/ping')).text() !== 'pong'){
// return
//}
postMessage(node)
}
})

View File

@ -3,6 +3,7 @@ importScripts("sha3.js")
self.addEventListener('message', function(e) {
var data = JSON.parse(e.data)
console.debug(data.metadata)
self.postMessage(
doPow(
data.metadata,

View File

@ -1,5 +1,5 @@
var lookupWorker = new Worker('peer-lookup.js');
var powWorker = new Worker("powworker.js")
lookupWorker.addEventListener('message', function(e) {
publicNodes.push(e.data)