# TollGate Protocol Integration Analysis for Archipelago ## 1. What is TollGate? TollGate is a protocol for selling network access via micropayments. Key concepts: - **Metered access**: Pay per byte, per millisecond, or per request. - **Bearer asset payments**: Cashu ecash tokens are sent to a TollGate in exchange for an allotment of service. - **Multi-layered protocol**: - **TIP-01 (Base Events)**: Nostr event kinds 10021 (advertisement), 1022 (session), 21023 (notice). - **TIP-02 (Cashu)**: Payment via Cashu tokens, `price_per_step` tags. - **HTTP-01**: POST cashu token to `http://gate:2121/` → get session back. - **HTTP-03**: `GET /usage` → `used/allotment`. - **WIFI-01**: Beacon frame discovery. - **No accounts, no KYC**: Device MAC/pubkey as identifier. --- ## 2. Current State: Half-Implemented in Archipelago! The good news: **archipelago already has a `streaming/` module** at `core/archipelago/src/streaming/` that implements a TollGate-inspired protocol. This was clearly built while studying the TollGate protocol. ### Existing Modules | Module | What it does | Completeness | |---|---|---| | `streaming/advertisement.rs` | Nostr kind 10021 ads, parsing `price_per_step` tags | ✅ Full TIP-01/TIP-02 compatible | | `streaming/session.rs` | Session creation, top-ups, expiry, usage tracking | ✅ Full | | `streaming/meter.rs` | Usage recording, allotment enforcement, formatting | ✅ Full | | `streaming/pricing.rs` | Metric types, price calculation | ✅ Full | | `streaming/gate.rs` | The payment gate (cashu validation + session creation) | ✅ Full | | `streaming/mod.rs` | Module exports, dead_code (no callers yet) | 🟡 Suppressed | ### The Missing Piece There is **no frontend (Vue/neode-ui) UI** for TollGate/streaming — no way to discover, pay for, monitor, and top-up streaming sessions from the archipelago interface. --- ## 3. Integration Plan ### 3.1 Wire Up the Backend - Enable `streaming/` as a living module (remove `#![allow(dead_code)]`). - Wire it into the main archipelago server config (pricing config per service). - Enable publishing kind 10021 advertisements on Nostr relays. - Add HTTP endpoints (`POST /`, `GET /usage`) in `gate.rs`. - Integrate with the existing Cashu wallet (`wallet/cashu.rs` & `wallet/mint_client.rs`). - Add a configuration mechanism in `settings/transport.rs`. ### 3.2 New neode-ui Page: "Streaming" (or "TollGate") A new view/page in the neode-ui (Vue + TypeScript): - **Discovery panel**: List of available TollGate services (from Nostr kind 10021) with pricing. - **Session management**: Active sessions with usage bars (`5.2 MB / 10 MB`), remaining, time left. - **Payment flow**: Cashu payment integration — pay more, top-up sessions. - **Revenue dashboard**: For node operators — total sats earned per service. ### 3.3 New UI Components Needed | Component | Purpose | |---|---| | `StreamingServiceCard.vue` | Displays a priced service (name, price per step, metric, mint) | | `StreamingSessionBar.vue` | Progress bar for session usage | | `StreamingPaymentModal.vue` | Cashu payment / top-up modal | | `StreamingDashboard.vue` | Operator view — revenue, active sessions, service config | | `StreamingSettings.vue` | Enable/disable services, set prices, configure accepted mints | ### 3.4 RPC/API Additions Needed on the Rust Side New RPC methods in the archipelago API: - `streaming/advertisements` — list all kind 10021 events - `streaming/services` — get configured services/pricing - `streaming/session/list` — active sessions - `streaming/session/pay` — send cashu token, get session update - `streaming/session/topup` — top-up existing session - `streaming/usage` — usage summary for peer+service - `streaming/config/update` — operator config changes ### 3.5 Integration with Existing Archipelago Features - **Federation sync**: The existing federation module could use streaming for metered access between nodes. - **Content sync**: Content downloads (photos, music, documents) could be metered. - **Mesh map**: Show streaming-capable nodes on the Mesh map (use `MeshMap.vue`). - **Monitoring**: Integrate streaming revenue into the monitoring/telemetry module. --- ## 4. Visual Architecture ```text ┌──────────────────── Archipelago Interface ───────────────────────┐ │ neode-ui (Vue/TypeScript frontend) │ │ ┌───────────────┐ ┌──────────────┐ ┌────────────────────┐ │ │ │ Streaming │ │ Streaming │ │ Streaming │ │ │ │ (Discovery) │ │ Dashboard │ │ Settings │ │ │ └───────┬────────┘ └──────┬───────┘ └────────┬───────────┘ │ │ └───────┬──────────┴────────┬───────────┘ │ │ └───── RPC Client ───┘ │ └─────────────────────────────┬──────────────────────────────────┘ │ JSON-RPC / WebSocket ┌────────────── Archipelago Core (Rust) ────────────┐ │ ┌─ core/archipelago/ streaming/ module ──────────┐│ │ │ ├── advertisement.rs (TIP-01 Nostr ads) ││ │ │ ├── pricing.rs (pricing config) ││ │ │ ├── session.rs (session lifecycle) ││ │ │ ├── meter.rs (usage tracking) ││ │ │ └── gate.rs (cashu validation) ││ │ └─────────────────────────────────────────────────┘│ │ ┌─ cashu.rs [wallet] ──┐ ┌─ nostr_relays [mesh] ┐│ │ └───────────────────────┘ └──────────────────────┘│ └────────────────────────────────┬─────────────────────┘ │ ┌────────────▼────────────┐ │ Cashu Mint (external) │ └─────────────────────────┘ ``` --- ## 5. Recommended Execution Order 1. **Wire up the backend**: Enable `streaming/` as a living module, add RPC endpoints, publish advertisements on Nostr. 2. **Create the streaming page**: Discovery + session list + payment modal in neode-ui. 3. **Add the dashboard**: Revenue tracking for node operators. 4. **Add settings**: Pricing configuration UI. 5. **Integrate with federation**: Make federation sync metered by default.