Skip to content

Commit

Permalink
v86 internal socket foxes
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgrammerIn-wonderland committed Sep 2, 2024
1 parent 92ef130 commit 4d1bc67
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/v86.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -513,29 +513,33 @@ class V86Backend {
binaryType = "arraybuffer";
constructor(hostname: string, port: string) {
super();
this.pty = anura.x86!.ptyNum++;
console.log("creating socket: " + hostname);

(async () => {
this.pty = await anura.x86!.sendWispFrame({
this.pty = anura.x86!.ptyNum++;
await anura.x86!.sendWispFrame({
type: "CONNECT",
streamType: 0x01,
streamID: this.pty,
port: port,
command: hostname,
dataCallback: (data: Uint8Array) => {
this.onmessage(data);
this.onmessage({ data: data.buffer });

this.dispatchEvent(
//@ts-expect-error idk why?
new CustomEvent("message", { data: data.buffer }),
);
},
closeCallback: (data: number) => {
this.onclose();
if (this.onclose) {
this.onclose();
}
this.dispatchEvent(new CustomEvent("close"));
},
});
this.dispatchEvent(new CustomEvent("open"));
if (this.onopen) {
console.log("calling onopen");
this.onopen();
}
})();
Expand Down Expand Up @@ -682,7 +686,6 @@ class V86Backend {
//console.log(frame);
const view = new DataView(frame.buffer);
const streamID = view.getUint32(1, true);
console.log("Got packet type " + frame[0]);
switch (frame[0]) {
case 1: // CONNECT
// The server should never send this actually
Expand All @@ -700,7 +703,6 @@ class V86Backend {

break;
case 3: // CONTINUE
console.log("Got continue!");
if (connections[streamID]) {
console.log(
`setting congestion for ${streamID} to ${view.getUint32(5, true)}`,
Expand All @@ -712,7 +714,6 @@ class V86Backend {
}

if (connections[streamID].congested) {
console.log("Continuing transmission");
for (const packet of congestedBuffer) {
sendPacket(packet.data, packet.type, streamID);
}
Expand Down Expand Up @@ -777,16 +778,15 @@ class V86Backend {
frameObj.command,
);
fullPacket = new Uint8Array(
4 + 5 + 1 + 1 + commandBuffer.length,
4 + 5 + 1 + 2 + commandBuffer.length,
);
view = new DataView(fullPacket.buffer);
view.setUint32(0, fullPacket.length - 4, true); // Packet size
view.setUint8(4, 0x01); // FRAME TYPE (CONNECT)
view.setUint32(5, frameObj.streamID, true); // Stream ID
view.setUint8(9, frameObj.streamType || 0x03); // TCP
view.setUint16(10, frameObj.port || 10); // PORT (unused, hardcoded to 10)
fullPacket.set(commandBuffer, 11); // command

view.setUint16(10, frameObj.port || 10, true); // PORT (unused, hardcoded to 10)
fullPacket.set(commandBuffer, 12); // command
// Setting callbacks
connections[frameObj.streamID] = {
dataCallback: frameObj.dataCallback,
Expand Down

0 comments on commit 4d1bc67

Please sign in to comment.