Skip to content

Commit

Permalink
Remove puzzle run functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuens committed Jun 27, 2024
1 parent 1355378 commit 2aef33c
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 94 deletions.
49 changes: 0 additions & 49 deletions cmd/wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ const Bits = 1024
func main() {
fmt.Printf("Hello %s\n", "World")

js.Global().Set("runTLP", tlpWrapped())
js.Global().Set("generateTLP", generateTLP())
js.Global().Set("solveTLP", solveTLP())

js.Global().Set("runLHTLP", lhtlpWrapped())
js.Global().Set("generateLHTLP", generateLHTLP())
js.Global().Set("solveLHTLP", solveLHTLP())

Expand Down Expand Up @@ -75,26 +73,6 @@ func solveTLP() js.Func {
})
}

func tlpWrapped() js.Func {
return js.FuncOf(func(this js.Value, args []js.Value) any {
if len(args) != 2 {
return "Invalid number of arguments passed."
}

message := args[0].Int()
difficulty := args[1].Int()

fmt.Printf("Bits: %d\n", Bits)
fmt.Printf("Message: %d\n", message)
fmt.Printf("Difficulty: %d\n", difficulty)

puzzle := tlp.Generate(Bits, message, difficulty)
solution := tlp.Solve(puzzle)

return solution.String()
})
}

func generateLHTLP() js.Func {
return js.FuncOf(func(this js.Value, args []js.Value) any {
if len(args) != 3 {
Expand Down Expand Up @@ -152,30 +130,3 @@ func solveLHTLP() js.Func {
return solution.String()
})
}

func lhtlpWrapped() js.Func {
return js.FuncOf(func(this js.Value, args []js.Value) any {
if len(args) != 3 {
return "Invalid number of arguments passed."
}

message1 := args[0].Int()
message2 := args[1].Int()
difficulty := args[2].Int()

fmt.Printf("Bits: %d\n", Bits)
fmt.Printf("Message #1: %d\n", message1)
fmt.Printf("Message #2: %d\n", message2)
fmt.Printf("Difficulty: %d\n", difficulty)

params := lhtlp.NewParams(Bits, difficulty)
puzzle1 := lhtlp.NewPuzzle(*params, message1)
puzzle2 := lhtlp.NewPuzzle(*params, message2)

puzzle3 := puzzle1.Add(*puzzle2)

solution := lhtlp.Solve(*puzzle3)

return solution.String()
})
}
Binary file modified frontend/src/assets/main.wasm
Binary file not shown.
2 changes: 0 additions & 2 deletions frontend/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ export const TLP_PATH = "/tlp";
export const LHTLP_PATH = "/lhtlp";
export const RESULT = "RESULT";
export const INITIALIZED = "INITIALIZED";
export const CALL_RUN_TLP = "CALL_RUN_TLP";
export const CALL_RUN_LHTLP = "CALL_RUN_LHTLP";
export const GENERATE_TLP = "GENERATE_TLP";
export const GENERATE_LHTLP = "GENERATE_LHTLP";
export const SOLVE_TLP = "SOLVE_TLP";
Expand Down
24 changes: 0 additions & 24 deletions frontend/src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { useEffect, useState } from "preact/hooks";
import WasmWorker from "./worker.js?worker";
import {
RESULT,
CALL_RUN_TLP,
CALL_RUN_LHTLP,
GENERATE_TLP,
SOLVE_TLP,
GENERATE_LHTLP,
Expand Down Expand Up @@ -37,26 +35,6 @@ export function useWorker() {
}
}

function runTLP(message, difficulty) {
worker.postMessage({
id: getId(),
type: CALL_RUN_TLP,
data: [message, difficulty],
});

return id;
}

function runLHTLP(message1, message2, difficulty) {
worker.postMessage({
id: getId(),
type: CALL_RUN_LHTLP,
data: [message1, message2, difficulty],
});

return id;
}

function generateTLP(message, difficulty) {
worker.postMessage({
id: getId(),
Expand Down Expand Up @@ -107,8 +85,6 @@ export function useWorker() {

return {
results,
runTLP,
runLHTLP,
generateTLP,
solveTLP,
generateLHTLP,
Expand Down
20 changes: 1 addition & 19 deletions frontend/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import wasmURL from "./assets/main.wasm";
import * as _ from "./assets/wasm_exec.js?inline";
import {
RESULT,
CALL_RUN_TLP,
CALL_RUN_LHTLP,
GENERATE_TLP,
SOLVE_TLP,
GENERATE_LHTLP,
Expand Down Expand Up @@ -40,23 +38,7 @@ self.addEventListener(

console.log("worker.js - event.data", event.data);

if (type === CALL_RUN_TLP) {
const result = self.runTLP(...data);

self.postMessage({
id,
type: RESULT,
data: result,
});
} else if (type === CALL_RUN_LHTLP) {
const result = self.runLHTLP(...data);

self.postMessage({
id,
type: RESULT,
data: result,
});
} else if (type === GENERATE_TLP) {
if (type === GENERATE_TLP) {
const result = self.generateTLP(...data);

self.postMessage({
Expand Down

0 comments on commit 2aef33c

Please sign in to comment.