mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-09-14 23:26:38 +00:00
Ports examples/simple_repeater to variants/sim/ (new sim_simple_repeater native env + build_wasm_repeater.sh) and adds a JS "ether" (variants/sim/web/mesh.html) that bridges two real companion_radio WASM instances through a real simple_repeater instance in a strict A<->R<->B topology (no direct A-B link), proving genuine relay routing rather than a shortcut. Also fixes multi-instance issues Phase 2's single-instance design never surfaced: SimDisplayDriver's canvas context/id caching was keyed on a single global instead of per-instance, and both wasm builds were missing _malloc/_free/HEAPU8 runtime exports needed for the ether to poke bytes into an instance's memory. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
25 lines
804 B
C++
25 lines
804 B
C++
#pragma once
|
|
|
|
#include <Utils.h>
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
#include "SimInstance.h"
|
|
|
|
// mesh::RNG implementation for the native sim build. Not cryptographically
|
|
// strong (rand() under the hood) -- fine for a terminal demo. Phase 3 mixes
|
|
// in sim_instance_salt() so that two module instances of the SAME compiled
|
|
// binary (the browser's two companion_radio instances) can't end up with
|
|
// the same seed -- see SimInstance.h for why that's a real risk here, not
|
|
// a hypothetical one.
|
|
class SimRNG : public mesh::RNG {
|
|
public:
|
|
SimRNG() { }
|
|
void begin() {
|
|
unsigned seed = (unsigned)time(NULL) ^ (unsigned)(uintptr_t)this ^ sim_instance_salt();
|
|
srand(seed);
|
|
}
|
|
void random(uint8_t* dest, size_t sz) override {
|
|
for (size_t i = 0; i < sz; i++) dest[i] = (uint8_t)rand();
|
|
}
|
|
};
|