Skip to content
Open
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
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# OpenBikeNet Server

**Status: early draft, implements protocol v0.**
**Status: implements protocol v0.2. A public instance runs at
[openbikenet.cloud](https://openbikenet.cloud).**

This is the reference server for the [OpenBikeNet protocol](https://github.com/OpenBikeNet/protocol):
a shared, neutral server that lets riders of different indoor cycling apps see each other on
Expand All @@ -14,6 +15,29 @@ Ideas and feedback are welcome in its Discussions.
A public instance runs at [openbikenet.cloud](https://openbikenet.cloud). Apps connect to
`wss://openbikenet.cloud/v0`, and `https://openbikenet.cloud/v0/stats` shows which apps are on.

## Shared routes

The server serves every route file in `protocol/routes`. A position on a route is a distance in
metres from its start, so the same distance means the same spot in every app.

| Route ID | Length | Notes |
| --- | --- | --- |
| `velodrome-250` | 250 m | A flat velodrome, the first shared route |
| `herne-hill-450` | 450 m | Herne Hill Velodrome, anticlockwise as raced |
| `herne-hill-450-clockwise` | 450 m | The same track the other way round |

## Apps

- [OpenRadlr](https://openradlr.com): the first app on the network and the reference
implementation.
- [VeloPopuli](https://velopopuli.com): has the shared Herne Hill track; the OpenBikeNet link is
in review.

## Privacy

`GET /privacy` describes what the public server stores. In short: per-app counts and dates, never
rider names, positions or IP addresses. The landing page shows live usage and the last 30 days.

## Running it

With Docker (nothing else needed):
Expand Down
63 changes: 63 additions & 0 deletions crates/server/src/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ <h1><span class="dot">●</span> OpenBikeNet server</h1>
<p>A neutral relay that lets riders of different indoor cycling apps meet on the same route.</p>
<p class="dim">This is a backend for apps. There is nothing to use here in a browser.</p>

<h2>Live</h2>
<p id="live">Loading the live numbers…</p>
<p id="history" class="dim"></p>
<noscript><p class="dim">The live numbers need JavaScript. The raw numbers are at <a href="/v0/stats">/v0/stats</a>.</p></noscript>

<h2>Shared routes</h2>
<table>
{{ROUTES}}
</table>

<h2>Endpoints</h2>
<table>
<tr><td><span class="method">WS</span>/v0</td><td>Protocol v0: presence on shared routes</td></tr>
Expand All @@ -62,16 +72,69 @@ <h2>Apps using it</h2>
</tr>
</table>

<section id="usage" hidden>
<h2>Usage</h2>
<table>
<thead><tr><td>App</td><td>Versions</td><td>Riders / connections</td><td>Last 30 days</td><td>Last seen</td></tr></thead>
<tbody id="usage-rows"></tbody>
</table>
</section>

<h2>Links</h2>
<ul>
<li><a href="https://openbikenet.cloud">openbikenet.cloud</a> <span class="dim">· the public server</span></li>
<li><a href="https://github.com/OpenBikeNet">github.com/OpenBikeNet</a></li>
<li><a href="https://github.com/OpenBikeNet/protocol/blob/main/spec/v0.md">Protocol specification</a></li>
<li><a href="https://github.com/OpenBikeNet/server">Server source</a> <span class="dim">· run your own with <code>make up</code></span></li>
<li><a href="https://github.com/OpenBikeNet/protocol/discussions">Discussions</a> <span class="dim">· building an app? say hello</span></li>
<li><a href="/privacy">Privacy</a> <span class="dim">· what this server stores</span></li>
</ul>

<footer>obn-server {{VERSION}} · AGPL-3.0</footer>
</main>
<script>
(() => {
const set = (id, value) => {
document.getElementById(id).textContent = value;
};
fetch('/v0/stats', { cache: 'no-store' })
.then((r) => r.json())
.then(({ apps }) => {
const shown = apps.filter((a) => a.connections > 0 || a.riders > 0 || a.rider_minutes_30d > 0);
const riders = shown.reduce((n, a) => n + a.riders, 0);
const connected = shown.filter((a) => a.connections > 0).length;
set(
'live',
riders > 0
? `${riders} rider${riders === 1 ? '' : 's'} from ${connected} app${connected === 1 ? '' : 's'} on the shared routes right now.`
: connected > 0
? `${connected} app${connected === 1 ? '' : 's'} connected; no riders on the routes right now.`
: 'No riders online right now.'
);
const minutes = shown.reduce((n, a) => n + a.rider_minutes_30d, 0);
const riding = shown.filter((a) => a.rider_minutes_30d > 0).length;
set(
'history',
minutes > 0
? `${minutes} rider-minute${minutes === 1 ? '' : 's'} from ${riding} app${riding === 1 ? '' : 's'} in the last 30 days.`
: ''
);
if (shown.length > 0) {
const rows = document.getElementById('usage-rows');
for (const a of shown.sort((a, b) => b.riders - a.riders || a.id.localeCompare(b.id))) {
const tr = document.createElement('tr');
for (const value of [a.id, a.versions.join(', ') || '—', `${a.riders} / ${a.connections}`, a.rider_minutes_30d ? `${a.rider_minutes_30d} min` : '—', a.last_seen]) {
const td = document.createElement('td');
td.textContent = value;
tr.append(td);
}
rows.append(tr);
}
document.getElementById('usage').hidden = false;
}
})
.catch(() => set('live', 'The live numbers could not be loaded.'));
})();
</script>
</body>
</html>
5 changes: 5 additions & 0 deletions crates/server/src/presence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ impl Presence {
}
}

/// The routes this server offers, for the landing page.
pub fn route_list(&self) -> Vec<(String, f64)> {
self.routes.list().map(|r| (r.id.clone(), r.length)).collect()
}

pub fn connect(&mut self, conn: ConnId, app: AppInfo) {
self.conns.insert(
conn,
Expand Down
71 changes: 71 additions & 0 deletions crates/server/src/privacy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Privacy · OpenBikeNet server</title>
<style>
:root {
color-scheme: light dark;
--bg: #f6f6f3; --fg: #1d1d1b; --dim: #6b6b66; --line: #d9d9d3; --accent: #1f7a4d;
}
@media (prefers-color-scheme: dark) {
:root { --bg: #121312; --fg: #e4e4df; --dim: #8d8d86; --line: #2c2d2b; --accent: #5fd08f; }
}
* { box-sizing: border-box; }
body {
margin: 0; background: var(--bg); color: var(--fg);
font: 15px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
main { max-width: 44rem; margin: 0 auto; padding: 4rem 1.5rem 3rem; }
h1 { font-size: 1.1rem; margin: 0 0 1.5rem; font-weight: 600; }
h2 { font-size: 0.8rem; font-weight: 600; color: var(--dim); text-transform: uppercase;
letter-spacing: 0.08em; margin: 2.5rem 0 0.75rem; }
p { margin: 0 0 1rem; }
.dim { color: var(--dim); }
ul { list-style: none; padding: 0; margin: 0; }
li { padding: 0.2rem 0 0.2rem 1.2rem; text-indent: -1.2rem; }
li::before { content: "→ "; color: var(--dim); }
code { font: inherit; color: var(--fg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
footer { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--line);
color: var(--dim); font-size: 0.85rem; }
</style>
</head>
<body>
<main>
<h1><a href="/">OpenBikeNet server</a> · Privacy</h1>
<p>OpenBikeNet is a relay for shared presence. This page describes what the public server at
<a href="https://openbikenet.cloud">openbikenet.cloud</a> stores. If you run your own server,
you decide what it stores.</p>

<h2>What is stored</h2>
<ul>
<li>The app ID and versions that connect, and the dates each app was first and last seen.</li>
<li>How many riders each app had, per minute. The public statistics at
<a href="/v0/stats">/v0/stats</a> show the last 30 days.</li>
</ul>
<p>That is all. The counts are what makes the public usage statistics possible.</p>

<h2>What is not stored</h2>
<ul>
<li>Rider names, rider values, positions, speed, power, cadence or heart rate. They are
passed on to the other connections and kept only in memory while a rider is connected.</li>
<li>IP addresses. They are used only to limit connections per address and are never written
to disk.</li>
<li>Cookies or analytics. This page and the landing page have neither.</li>
</ul>

<h2>How long it is kept</h2>
<p>Per-app rider counts are stored per day. The public statistics only read the last 30 days.
There is no rider history to delete, because none is kept.</p>

<h2>Questions</h2>
<p>Ask in the <a href="https://github.com/OpenBikeNet/protocol/discussions">discussions</a>,
or open an issue in the <a href="https://github.com/OpenBikeNet/server">server repository</a>.</p>

<footer>obn-server {{VERSION}} · AGPL-3.0</footer>
</main>
</body>
</html>
5 changes: 5 additions & 0 deletions crates/server/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ impl Routes {
pub fn ids(&self) -> impl Iterator<Item = &str> {
self.by_id.keys().map(String::as_str)
}

/// Every route, sorted by ID.
pub fn list(&self) -> impl Iterator<Item = &Route> {
self.by_id.values()
}
}

/// Checks one route against the profile rules of spec 4.1.
Expand Down
18 changes: 16 additions & 2 deletions crates/server/src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pub fn spawn_tickers(state: Arc<AppState>) {
pub fn router(state: Arc<AppState>) -> Router {
Router::new()
.route("/", get(landing))
.route("/privacy", get(privacy))
.route("/v0", get(ws_handler))
.route("/v0/stats", get(stats_handler))
.route("/healthz", get(healthz))
Expand All @@ -180,8 +181,21 @@ pub fn router(state: Arc<AppState>) -> Router {
static LANDING: LazyLock<String> =
LazyLock::new(|| include_str!("landing.html").replace("{{VERSION}}", env!("CARGO_PKG_VERSION")));

async fn landing() -> Html<&'static str> {
Html(LANDING.as_str())
async fn landing(State(state): State<Arc<AppState>>) -> Html<String> {
let rows = lock(&state.presence)
.route_list()
.into_iter()
.map(|(id, length)| format!("<tr><td><code>{id}</code></td><td>{length:.0} m</td></tr>"))
.collect::<String>();
Html(LANDING.replace("{{ROUTES}}", &rows))
}

/// What the public server stores, and what it never stores.
static PRIVACY: LazyLock<String> =
LazyLock::new(|| include_str!("privacy.html").replace("{{VERSION}}", env!("CARGO_PKG_VERSION")));

async fn privacy() -> Html<&'static str> {
Html(PRIVACY.as_str())
}

async fn healthz() -> &'static str {
Expand Down
14 changes: 14 additions & 0 deletions crates/server/tests/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,18 @@ async fn landing_page() {
assert!(body.contains("/v0/stats"), "{body}");
assert!(body.contains("https://github.com/OpenBikeNet"), "{body}");
assert!(body.contains(env!("CARGO_PKG_VERSION")), "{body}");
assert!(body.contains("velodrome-250"), "{body}");
assert!(body.contains("herne-hill-450"), "{body}");
assert!(body.contains("/privacy"), "{body}");
}

#[tokio::test]
async fn privacy_page() {
let addr = start(test_config()).await;
let (head, body) = http_get(addr, "/privacy").await;
assert!(head.starts_with("HTTP/1.1 200"), "{head}");
assert!(head.to_lowercase().contains("content-type: text/html"), "{head}");
assert!(body.contains("IP addresses"), "{body}");
assert!(body.contains("Rider names"), "{body}");
assert!(body.contains(env!("CARGO_PKG_VERSION")), "{body}");
}
Loading