diff --git a/config.yaml b/config.yaml index ac70e1b..485bdd4 100644 --- a/config.yaml +++ b/config.yaml @@ -3,3 +3,4 @@ admin_token: "super_secret_rebuild" enable_thumbnail_cache: true rebuild_error_threshold: 50 verify_interval_hours: 12 +sync_api_key: "can-sync-default-key" diff --git a/examples/can-sync/config.yaml b/examples/can-sync/config.yaml index 4638ff0..5cce4e5 100644 --- a/examples/can-sync/config.yaml +++ b/examples/can-sync/config.yaml @@ -1,13 +1,20 @@ # CAN Sync v2 configuration +# +# This config is used by the go_example_1.ps1 script. +# All machines that clone this repo and run the script will +# auto-discover each other via iroh's relay network as long +# as they share the same sync_passphrase. # URL of the local CAN Service (sync API is at /sync/*) can_service_url: "http://127.0.0.1:3210" # API key for CAN service's sync endpoints (must match sync_api_key in CAN config) -sync_api_key: "changeme" +sync_api_key: "can-sync-default-key" -# Shared passphrase for peer discovery (all peers must use the same one) -sync_passphrase: "my-shared-secret" +# Shared passphrase for peer discovery — all peers with the same passphrase +# find each other automatically over the internet via iroh relay servers. +# Change this to something unique to your team/project. +sync_passphrase: "duke-canman-sync" -# Seconds between polls for new local assets -poll_interval_secs: 3 +# Seconds between fallback polls (SSE handles instant sync, this is a safety net) +poll_interval_secs: 30 diff --git a/go_example_1.ps1 b/go_example_1.ps1 index 172ad11..6e1e123 100644 --- a/go_example_1.ps1 +++ b/go_example_1.ps1 @@ -1,4 +1,7 @@ -# go_example_1.ps1 — Start CanService + Paste example, open browser +# go_example_1.ps1 — Start CanService + Paste + Sync agent, open browser +# +# Run on multiple machines (after git clone) and they will auto-sync +# all ingested assets via iroh's relay network. No port forwarding needed. $ErrorActionPreference = "Stop" $root = $PSScriptRoot @@ -11,13 +14,19 @@ Get-NetTCPConnection -LocalPort 3211 -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue } Start-Sleep -Milliseconds 500 +# --- Build everything --- + Write-Host "Building CanService..." -ForegroundColor Cyan cargo build --manifest-path "$root\Cargo.toml" Write-Host "Building Paste example..." -ForegroundColor Cyan cargo build --manifest-path "$root\examples\paste\Cargo.toml" -# Start CanService in background +Write-Host "Building CAN Sync agent..." -ForegroundColor Cyan +cargo build --manifest-path "$root\examples\can-sync\Cargo.toml" --bin can-sync + +# --- Start CanService --- + Write-Host "Starting CanService on port 3210..." -ForegroundColor Green $canService = Start-Process -FilePath "cargo" ` -ArgumentList "run --manifest-path `"$root\Cargo.toml`"" ` @@ -43,7 +52,20 @@ if (-not $ready) { } Write-Host "CanService ready." -ForegroundColor Green -# Start Paste example (it opens the browser itself) +# --- Start Sync agent --- + +$syncConfig = "$root\examples\can-sync\config.yaml" +Write-Host "Starting CAN Sync agent (P2P replication)..." -ForegroundColor Green +$syncAgent = Start-Process -FilePath "cargo" ` + -ArgumentList "run --manifest-path `"$root\examples\can-sync\Cargo.toml`" --bin can-sync -- `"$syncConfig`"" ` + -WorkingDirectory $root ` + -PassThru -NoNewWindow + +# Give sync agent a moment to connect to CAN service +Start-Sleep -Seconds 2 + +# --- Start Paste example --- + Write-Host "Starting Paste on port 3211..." -ForegroundColor Green $paste = Start-Process -FilePath "cargo" ` -ArgumentList "run --manifest-path `"$root\examples\paste\Cargo.toml`"" ` @@ -54,16 +76,22 @@ Write-Host "" Write-Host "Running:" -ForegroundColor Cyan Write-Host " CanService -> http://127.0.0.1:3210" Write-Host " Paste UI -> http://127.0.0.1:3211" +Write-Host " CAN Sync -> P2P replication active (iroh relay)" -ForegroundColor Magenta Write-Host "" -Write-Host "Press Ctrl+C to stop both." -ForegroundColor Yellow +Write-Host "Sync passphrase: 'duke-canman-sync'" -ForegroundColor Magenta +Write-Host "Any other machine running this script with the same passphrase" -ForegroundColor Magenta +Write-Host "will automatically discover this instance and sync all assets." -ForegroundColor Magenta +Write-Host "" +Write-Host "Press Ctrl+C to stop all services." -ForegroundColor Yellow -# Wait for either process to exit, then clean up both +# Wait for any process to exit, then clean up all try { - while (-not $canService.HasExited -and -not $paste.HasExited) { + while (-not $canService.HasExited -and -not $paste.HasExited -and -not $syncAgent.HasExited) { Start-Sleep -Seconds 1 } } finally { Write-Host "Shutting down..." -ForegroundColor Yellow Stop-Process -Id $canService.Id -Force -ErrorAction SilentlyContinue Stop-Process -Id $paste.Id -Force -ErrorAction SilentlyContinue + Stop-Process -Id $syncAgent.Id -Force -ErrorAction SilentlyContinue }