forked from Snider/Poindexter
Add comprehensive networking analytics to support peer selection based on performance and trust metrics for KD-Tree based NAT routing: - Add kdtree_analytics.go with TreeAnalytics, PeerAnalytics, DistributionStats, NATRoutingMetrics, TrustMetrics, and QualityWeights structures - Track query/insert/delete operations with timing statistics - Track per-peer selection frequency and average distances - Add PeerQualityScore() for composite peer ranking - Add ComputeTrustScore() for reputation-based selection - Add distribution statistics (min, max, mean, median, percentiles) - Add feature normalization helpers for multi-dimensional peer data WASM/TypeScript integration: - Expose all analytics via WASM bindings - Update TypeScript definitions with full type coverage - Update loader.js with new API methods - Update TypeScript demo to showcase analytics features Includes comprehensive test coverage for all analytics functionality. |
||
|---|---|---|
| .. | ||
| scripts | ||
| src | ||
| index.html | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.ts | ||
WASM Browser Example (TypeScript + Vite)
This is a minimal TypeScript example that runs Poindexter’s WebAssembly build in the browser.
It bundles a tiny page with Vite and demonstrates creating a KDTree and running Nearest,
KNearest, and Radius queries.
Prerequisites
- Go toolchain installed
- Node.js 18+ (tested with Node 20)
Quick start
- Build the WASM artifacts at the repo root:
make wasm-build
This creates dist/poindexter.wasm and dist/wasm_exec.js.
- From this example directory, install deps and start the dev server (the script copies the required files into
public/before starting Vite):
npm install
npm run dev
- Open the URL printed by Vite (usually http://127.0.0.1:5173/). Open the browser console to see outputs.
What the dev script does
- Copies
../../dist/poindexter.wasmand../../dist/wasm_exec.jsintopublic/ - Copies
../../npm/poindexter-wasm/loader.jsintopublic/ - Starts Vite with
public/as the static root for those assets
The TypeScript code imports the loader from /loader.js and initializes with:
const px = await init({
wasmURL: '/poindexter.wasm',
wasmExecURL: '/wasm_exec.js',
});
Notes
- This example is local-only and not built in CI to keep jobs light.
- You can adapt the same structure inside your own web projects; alternatively, install the published npm package when available and serve
dist/as static assets.