From e23ac25357fbcc90542248f15b8b195328ccfe49 Mon Sep 17 00:00:00 2001 From: ProgrammerIn-wonderland <3838shah@gmail.com> Date: Sun, 27 Oct 2024 16:44:10 -0400 Subject: [PATCH 1/2] only save on postcommit --- src/emulator/image/rootfs/bin/puter-save | 2 +- .../image/rootfs/etc/apk/commit_hooks.d/puter.sh | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/emulator/image/rootfs/bin/puter-save b/src/emulator/image/rootfs/bin/puter-save index cc541e7c2f..19d7adc720 100644 --- a/src/emulator/image/rootfs/bin/puter-save +++ b/src/emulator/image/rootfs/bin/puter-save @@ -11,4 +11,4 @@ fi echo -n $$ > /var/puter-save PUTERUSERNAME=$( cat /proc/cmdline | sed -n 's/.*puterusername=\(.*\)/\1/p' ) lbu package - > /puter/$PUTERUSERNAME/emulatorstate.apkovl.tar.gz -rm /var/puter-save \ No newline at end of file +rm /var/puter-save diff --git a/src/emulator/image/rootfs/etc/apk/commit_hooks.d/puter.sh b/src/emulator/image/rootfs/etc/apk/commit_hooks.d/puter.sh index f3f5d46d48..37ac5662e6 100644 --- a/src/emulator/image/rootfs/etc/apk/commit_hooks.d/puter.sh +++ b/src/emulator/image/rootfs/etc/apk/commit_hooks.d/puter.sh @@ -1,4 +1,9 @@ -#!/bin/bash +#!/bin/sh -echo saving state to puter... -puter-save +if [ "$1" = "pre-commit" ]; then + echo Running with puter integration +elif [ "$1" = "post-commit" ]; then + echo Queuing puter save... + puter-save +fi +exit 0 \ No newline at end of file From d07c6f2635855e784a5e4f1da607963efe679258 Mon Sep 17 00:00:00 2001 From: ProgrammerIn-wonderland <3838shah@gmail.com> Date: Mon, 18 Nov 2024 17:06:38 -0500 Subject: [PATCH 2/2] (WIP) wisp bus starting --- experiments/puter-net/child/child.js | 3 ++ experiments/puter-net/child/index.html | 0 experiments/puter-net/index.html | 0 experiments/puter-net/index.js | 22 +++++++++ experiments/puter-net/parent/index.html | 13 ++++++ experiments/puter-net/parent/parent.js | 62 +++++++++++++++++++++++++ experiments/puter-net/parent/wisplib.js | 51 ++++++++++++++++++++ 7 files changed, 151 insertions(+) create mode 100644 experiments/puter-net/child/child.js create mode 100644 experiments/puter-net/child/index.html create mode 100644 experiments/puter-net/index.html create mode 100644 experiments/puter-net/index.js create mode 100644 experiments/puter-net/parent/index.html create mode 100644 experiments/puter-net/parent/parent.js create mode 100644 experiments/puter-net/parent/wisplib.js diff --git a/experiments/puter-net/child/child.js b/experiments/puter-net/child/child.js new file mode 100644 index 0000000000..db6e11d8a5 --- /dev/null +++ b/experiments/puter-net/child/child.js @@ -0,0 +1,3 @@ +window.parent.postMessage({$: "wisp-reg"}) + +window.parent.postMessage({$: "wisp-tx", new Uint8Array()}) \ No newline at end of file diff --git a/experiments/puter-net/child/index.html b/experiments/puter-net/child/index.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/experiments/puter-net/index.html b/experiments/puter-net/index.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/experiments/puter-net/index.js b/experiments/puter-net/index.js new file mode 100644 index 0000000000..e99e1c6f69 --- /dev/null +++ b/experiments/puter-net/index.js @@ -0,0 +1,22 @@ +class WispBus extends EventEmitter { + constructor(parameters) { + + } +} + + + +class puterSocket { + + constructor(host, port) { + + } + async write(arg[0]) { + + if (args[3]) { + + } + + + } +} \ No newline at end of file diff --git a/experiments/puter-net/parent/index.html b/experiments/puter-net/parent/index.html new file mode 100644 index 0000000000..dfa6e99e32 --- /dev/null +++ b/experiments/puter-net/parent/index.html @@ -0,0 +1,13 @@ + + + + + + Document + + + + + + + \ No newline at end of file diff --git a/experiments/puter-net/parent/parent.js b/experiments/puter-net/parent/parent.js new file mode 100644 index 0000000000..988e255a71 --- /dev/null +++ b/experiments/puter-net/parent/parent.js @@ -0,0 +1,62 @@ + +const streamID = 1; +const streamMapping = new Map(); + +const ws = new WebSocket("wss://anura.pro/"); +ws.binaryType = "arraybuffer"; +ws.onmessage = ((ev) => { + const data = wispPacketParser(new Uint8Array(ev.data)); + if ( data.streamID !== 0 ) + streamMapping.get(data.streamID).rxCallBack(new Uint8Array(ev.data)); +}); + + + + +// Message registerer +window.addEventListener("message", (message) => { + if (message.data.$ !== "wisp-reg") + return; + + const app = message.source; + message.source.addEventListener("message", (message) => { + if (message.data.$ === "wisp-tx") { + const unmapping = {}; + const messageData = wispPacketParser(message.data.packet); + + if (messageData.type === "CONNECT") { + const view = new DataView(message.data.packet.buffer); + streamMapping.set(streamID, { + originalID: messageData.streamID, + rxCallBack: (data) => { + const view = new DataView(data.buffer); + view.setUint32(0, messageData.streamID, true); // replace with old stream ID + + app.postMessage({ + $: "wisp-rx", + packet: data + }); + } + }) + unmapping[messageData.streamID] = streamID; + + view.setUint32(0, streamID, true); // override the given stream ID with one we made instead to avoid conflicts + ws.send(message.data); + } + if (messageData.type === "DATA") { + const streamID = unmapping[messageData.streamID]; + const view = new DataView(message.data.packet.buffer); + view.setUint32(0, streamID, true); // replace with old stream ID + ws.send(message.data); + + } + if (messageData.type === "CLOSE") { + const streamID = unmapping[messageData.streamID]; + const view = new DataView(message.data.packet.buffer); + view.setUint32(0, streamID, true); // replace with old stream ID + ws.send(message.data); + delete unmapping[messageData.streamID]; + } + } + }); +}) \ No newline at end of file diff --git a/experiments/puter-net/parent/wisplib.js b/experiments/puter-net/parent/wisplib.js new file mode 100644 index 0000000000..f51f56b2b0 --- /dev/null +++ b/experiments/puter-net/parent/wisplib.js @@ -0,0 +1,51 @@ +/** + * + * @param {Uint8Array} arr + * @returns {Object} + */ +function wispPacketParser(arr) { + const returnObj = {}; + const view = new DataView(arr.buffer); + + returnObj.streamID = view.getUint32(0, true); + returnObj.payload = arr.slice(5); + + switch (arr[0]) { + case 1: // CONNECT + returnObj.type = "CONNECT"; + returnObj.socketType = view.getUint8(5) === 1 ? "TCP": "UDP"; + returnObj.port = view.getUint16(6, true) === 1 ? "TCP": "UDP"; + returnObj.hostname = returnObj.payload.slice(7); + break; + case 2: // DATA + returnObj.type = "DATA"; + break; + case 3: // CONTINUE + returnObj.type = "CONTINUE"; + returnObj.bufferRemaining = view.getUint32(5, true) + break; + case 4: // CLOSE + returnObj.type = "CLOSE"; + returnObj.reason = view.getUint8(5) + break; + case 5: // PROTOEXT + returnObj.type = "PROTOEXT" + returnObj.wispVer = `${view.getUint8(5)}.${view.getUint8(6)}` + returnObj.extensions = []; + let pointer = 7; + while (true) { + if (pointer >= view.byteLength) + break; + returnObj.extensions.push( + { + ID: view.getUint8(pointer), + metadata: view.slice(pointer + 2, pointer + view.getUint8(pointer + 1)) + } + ) + pointer += 2 + view.getUint8(pointer + 1); + } + break; + + } + return returnObj; +} \ No newline at end of file