Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ npm run test:coverage # With coverage report
### Priority 4: AI Systems

- [ ] **AIWorkerManager.ts** - Worker task assignment
- [ ] **AbilityAI.ts** - AI ability usage decisions
- [ ] **FormationControl.ts** - Formation positioning
- [ ] **InfluenceMap.ts** - Influence calculations
- [ ] **PositionalAnalysis.ts** - Map analysis
Expand Down Expand Up @@ -176,8 +175,6 @@ npm run test:coverage # With coverage report
### Priority 7: Network & Multiplayer

- [ ] **ConnectionCode.ts** - Full connection code generation/parsing
- [ ] **NostrMatchmaking.ts** - Matchmaking via Nostr
- [ ] **PeerRelay.ts** - P2P relay communication
- [ ] **ChecksumSystem.ts** - State checksumming for desync detection
- [ ] **DesyncDetectionManager** - Full desync handling (partial coverage)

Expand Down
19 changes: 5 additions & 14 deletions docs/architecture/OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ voidstrike/
│ │ └── consoleCommands.ts
│ ├── data/ # Game data definitions
│ │ ├── abilities/
│ │ │ ├── abilities.ts
│ │ │ └── abilityMapper.ts
│ │ │ └── abilities.ts
│ │ ├── ai/ # AI subsystems
│ │ │ ├── factions/
│ │ │ │ └── dominion.ts
Expand All @@ -137,8 +136,7 @@ voidstrike/
│ │ │ │ ├── ConnectivityValidator.ts
│ │ │ │ ├── ElevationMap.ts
│ │ │ │ ├── ElevationMapGenerator.ts
│ │ │ │ ├── index.ts
│ │ │ │ └── MapScaffolder.ts
│ │ │ │ └── index.ts
│ │ │ ├── json/
│ │ │ │ ├── battle_arena.json
│ │ │ │ ├── contested_frontier.json
Expand Down Expand Up @@ -197,8 +195,6 @@ voidstrike/
│ │ │ ├── EditorCanvas.tsx
│ │ │ ├── EditorContextMenu.tsx
│ │ │ ├── EditorCore.tsx
│ │ │ ├── EditorExportModal.tsx
│ │ │ ├── EditorFloatingToolbar.tsx
│ │ │ ├── EditorHeader.tsx
│ │ │ ├── EditorMiniMap.tsx
│ │ │ ├── EditorStatusBar.tsx
Expand Down Expand Up @@ -227,7 +223,6 @@ voidstrike/
│ │ ├── terrain/
│ │ │ └── EdgeDetector.ts
│ │ ├── tools/ # Development tools
│ │ │ ├── AngleConstraint.ts
│ │ │ ├── index.ts
│ │ │ ├── ObjectPlacer.ts
│ │ │ └── TerrainBrush.ts
Expand All @@ -237,7 +232,6 @@ voidstrike/
│ │ └── index.ts
│ ├── engine/ # Game engine core
│ │ ├── ai/ # AI subsystems
│ │ │ ├── AbilityAI.ts
│ │ │ ├── AIWorkerManager.ts
│ │ │ ├── BehaviorTree.ts
│ │ │ ├── FormationControl.ts
Expand Down Expand Up @@ -327,9 +321,7 @@ voidstrike/
│ │ ├── network/
│ │ │ ├── p2p/
│ │ │ │ ├── index.ts
│ │ │ │ ├── NostrMatchmaking.ts
│ │ │ │ ├── NostrRelays.ts
│ │ │ │ └── PeerRelay.ts
│ │ │ │ └── NostrRelays.ts
│ │ │ ├── CommandSigning.ts
│ │ │ ├── DesyncDetection.ts
│ │ │ ├── index.ts
Expand Down Expand Up @@ -983,7 +975,7 @@ VOIDSTRIKE uses a **fully serverless peer-to-peer architecture** with Nostr-base
| Layer | Technology | Location |
| ---------------- | ------------------- | -------------------------------------------- |
| Transport | WebRTC DataChannels | `src/hooks/useMultiplayer.ts` |
| Signaling | Nostr Protocol | `src/engine/network/p2p/NostrMatchmaking.ts` |
| Signaling | Nostr Protocol | `src/hooks/useMultiplayer.ts` (lobby codes) |
| NAT Traversal | STUN (Google) | ICE servers in useMultiplayer |
| Synchronization | Lockstep | `src/engine/network/types.ts` |
| Desync Detection | Checksums | `src/engine/network/DesyncDetection.ts` |
Expand Down Expand Up @@ -1071,7 +1063,7 @@ const ICE_SERVERS: RTCIceServer[] = [
];
```

For symmetric NATs, the peer relay system (`PeerRelay.ts`) routes through other players with E2E encryption (ECDH + AES-GCM).
For symmetric NATs, STUN servers handle most traversal cases. A peer relay system for routing through other players was planned but not implemented.

#### Alternative: Connection Codes (`src/engine/network/p2p/ConnectionCode.ts`)

Expand Down Expand Up @@ -1889,7 +1881,6 @@ src/data/maps/
├── ConnectivityAnalyzer.ts # Analyzes maps for connectivity
├── ConnectivityValidator.ts # Reports connectivity issues
├── ConnectivityFixer.ts # Auto-fixes ramps and connections
├── MapScaffolder.ts # Auto-generate maps from base positions
└── index.ts # Public API exports
```

Expand Down
66 changes: 29 additions & 37 deletions docs/architecture/networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ A groundbreaking multiplayer architecture that requires **zero servers** to oper
| Phase | Component | Reliability | Why |
|-------|-----------|-------------|-----|
| **1** | Connection Codes | ✅ **100%** | Pure WebRTC encoding. Zero external dependencies. Cannot fail. |
| **2** | LAN Discovery (mDNS) | ✅ **100%** | Standard protocol, works offline |
| **3** | Nostr Discovery | ✅ **99%** | Hundreds of relays, instant WebSocket, battle-tested by millions |
| **4** | Peer Relay | ✅ **95%** | Standard WebRTC relay pattern, adds ~50-100ms latency |
| **2** | LAN Discovery (mDNS) | ⏳ Not implemented | Requires Electron/Tauri for desktop build |
| **3** | Nostr Discovery | ❌ Removed | Infrastructure removed - lobby codes used instead |
| **4** | Peer Relay | ❌ Removed | Infrastructure removed - STUN servers handle most NAT cases |

> **Note**: Phase 3 (NostrMatchmaking.ts) and Phase 4 (PeerRelay.ts) infrastructure files were removed.
> The architecture diagrams below show the original design vision; current implementation uses lobby codes via Nostr relays in useMultiplayer.ts.

---

Expand All @@ -30,14 +33,19 @@ A groundbreaking multiplayer architecture that requires **zero servers** to oper
| Component | File | Status |
|-----------|------|--------|
| **Connection Codes** | `ConnectionCode.ts` | ✅ SDP encoding/decoding |
| **Nostr Matchmaking** | `NostrMatchmaking.ts` | ✅ Relay-based discovery |
| **Nostr Relays** | `NostrRelays.ts` | ✅ Health-checked relay list |
| **Peer Relay** | `PeerRelay.ts` | ✅ NAT traversal via peers |
| **Game Message Protocol** | `types.ts` | ✅ 16 message types |
| **Checksum System** | `ChecksumSystem.ts` | ✅ State verification + Merkle tree |
| **Merkle Tree** | `MerkleTree.ts` | ✅ O(log n) divergence detection |
| **Desync Detection** | `DesyncDetection.ts` | ✅ Debugging tools |

### ❌ What's REMOVED (Phase 3/4 Infrastructure)

| Component | Former File | Notes |
|-----------|-------------|-------|
| **Nostr Matchmaking** | `NostrMatchmaking.ts` | Removed - lobby codes via useMultiplayer.ts used instead |
| **Peer Relay** | `PeerRelay.ts` | Removed - STUN servers handle NAT traversal |

### ✅ What's COMPLETE (Game Integration)

| Component | File | Status |
Expand Down Expand Up @@ -532,8 +540,10 @@ export async function checkRelayHealth(

### Technical Implementation

> **Note**: The `NostrMatchmaking.ts` file was removed. The code below is preserved as design reference documentation. Current matchmaking uses lobby codes in `useMultiplayer.ts`.

```typescript
// src/engine/network/p2p/NostrMatchmaking.ts
// REMOVED: src/engine/network/p2p/NostrMatchmaking.ts (design reference only)

import {
SimplePool,
Expand Down Expand Up @@ -986,8 +996,10 @@ When both players are behind **symmetric NAT** (strict corporate firewalls, some

### Technical Implementation

> **Note**: The `PeerRelay.ts` file was removed. The code below is preserved as design reference documentation for the peer relay concept that was planned but not implemented.

```typescript
// src/engine/network/p2p/PeerRelay.ts
// REMOVED: src/engine/network/p2p/PeerRelay.ts (design reference only)

/**
* Message types for relay protocol
Expand Down Expand Up @@ -1462,38 +1474,16 @@ Tasks:
```

### Phase 3: Nostr Discovery
**Status**: ✅ Complete
**Reliability**: 99%
**Dependencies**: `nostr-tools` (~30KB)
**Implementation**: `src/engine/network/p2p/NostrMatchmaking.ts`, `src/hooks/useMultiplayer.ts`
**Status**: ❌ Removed
**Former Implementation**: `src/engine/network/p2p/NostrMatchmaking.ts` (deleted)

```
Tasks:
- [x] NostrMatchmaking class implementation
- [x] Ephemeral keypair generation
- [x] Game seek event publishing
- [x] Game seek subscription and filtering
- [x] WebRTC offer/answer exchange via Nostr
- [x] Skill-based matchmaking (300 point bracket)
- [x] Lobby system with 4-char codes
- [x] Relay health monitoring
- [x] Public lobby listing
```
The standalone NostrMatchmaking class was removed. Lobby-based matchmaking is now handled directly in `src/hooks/useMultiplayer.ts` using 4-character codes published to Nostr relays.

### Phase 4: Peer Relay
**Status**: Ready to implement
**Reliability**: 95%
**Dependencies**: None (uses Web Crypto API)
**Status**: ❌ Removed
**Former Implementation**: `src/engine/network/p2p/PeerRelay.ts` (deleted)

```
Tasks:
- [ ] PeerRelayNetwork class implementation
- [ ] ECDH key exchange between peers
- [ ] AES-GCM encryption for relay data
- [ ] Relay route discovery (BFS)
- [ ] Message forwarding protocol
- [ ] Automatic fallback when direct fails
```
The peer relay system for routing through other players was planned but removed. STUN servers handle most NAT traversal cases. For symmetric NATs where direct connection fails, players must use connection codes or find a different network configuration.

---

Expand Down Expand Up @@ -1635,11 +1625,13 @@ const groups = checksumSystem.getDivergentGroups(remoteMerkleTree, 'units');
src/engine/network/
├── p2p/
│ ├── ConnectionCode.ts # Phase 1: Code generation/parsing
│ ├── NostrMatchmaking.ts # Phase 3: Nostr-based discovery
│ ├── PeerRelay.ts # Phase 4: Relay network
│ ├── NostrRelays.ts # Health-checked relay list
│ └── index.ts # Public exports
├── MerkleTree.ts # Merkle tree for O(log n) desync detection
├── DesyncDetection.ts # Desync debugging tools
├── index.ts # Module exports
└── types.ts # Network types
```

> **Note**: `NostrMatchmaking.ts` (Phase 3) and `PeerRelay.ts` (Phase 4) were removed.
> Matchmaking functionality is now in `src/hooks/useMultiplayer.ts`.
14 changes: 7 additions & 7 deletions docs/security/CODE_AUDIT_REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,21 @@ this.queueCommand(command); // NO validation of playerId!

1. **Input Spoofing (playerId)** - `Game.ts:229-247`
2. **Stale Command Handling** - `Game.ts:890-910`
3. **No Command Authentication** - `ConnectionCode.ts`, `NostrMatchmaking.ts`
3. **No Command Authentication** - `ConnectionCode.ts`

### High

4. **Desync Detection Silent Failures** - `ChecksumSystem.ts:239-257`
5. **No Determinism Enforcement** - Various (Math.random usage)
6. **Peer Relay Encryption Fallback** - `PeerRelay.ts:379-416`
7. **Command Queue Memory Leak** - `Game.ts:836-848`
6. **Command Queue Memory Leak** - `Game.ts:836-848`

### Medium

8. **Network Delays & Clock Skew** - `Game.ts:393-407`
9. **Incomplete Lockstep Barrier** - `Game.ts:163-167`
10. **Merkle Tree Limited Resolution** - `ChecksumSystem.ts:286-292`
11. **Cleartext Nostr Transmission** - `NostrMatchmaking.ts`
7. **Network Delays & Clock Skew** - `Game.ts:393-407`
8. **Incomplete Lockstep Barrier** - `Game.ts:163-167`
9. **Merkle Tree Limited Resolution** - `ChecksumSystem.ts:286-292`

> **Note**: Issues related to `NostrMatchmaking.ts` and `PeerRelay.ts` removed - those files have been deleted.

---

Expand Down
115 changes: 0 additions & 115 deletions src/data/abilities/abilityMapper.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,6 @@ export {
type AbilityTargetFilter,
} from './abilities/abilities';

// Ability mapper for converting between data and engine layer types
export {
mapActivationModeToTargetType,
toEngineAbilityDefinition,
toEngineAbilityDefinitions,
requiresTargetSelection,
isToggleAbility,
isPassiveAbility,
canAutocast,
} from './abilities/abilityMapper';

// ==================== FORMATIONS ====================
export {
Expand Down
Loading
Loading