atproto relay implementation in zig zlay.waow.tech

allow disabling bootstrap from upstream relay #1

closed opened by zzstoatzz.io targeting main from disable-bootstrap

this PR allows you to set RELAY_UPSTREAM="" or RELAY_UPSTREAM="none" to disable pullHosts seeding at startup

cc @mia.omg.lol for review

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:xbtmt2zjwlrfegqvch7fboei/sh.tangled.repo.pull/3mh7cmssaa522
+26 -6
Diff #1
+1 -1
README.md
··· 43 43 |---|---|---| 44 44 | `RELAY_PORT` | `3000` | firehose + API port | 45 45 | `RELAY_METRICS_PORT` | `3001` | prometheus metrics port | 46 - | `RELAY_UPSTREAM` | `bsky.network` | bootstrap relay for initial host list | 46 + | `RELAY_UPSTREAM` | `bsky.network` | bootstrap relay for initial host list (set to `""` or `"none"` to disable) | 47 47 | `RELAY_DATA_DIR` | `data/events` | event log storage | 48 48 | `RELAY_RETENTION_HOURS` | `72` | event retention window | 49 49 | `COLLECTION_INDEX_DIR` | `data/collection-index` | RocksDB collection index path |
+17 -1
src/main.zig
··· 148 148 // parse config from env 149 149 const port = parseEnvInt(u16, "RELAY_PORT", 3000); 150 150 const metrics_port = parseEnvInt(u16, "RELAY_METRICS_PORT", 3001); 151 - const upstream = std.posix.getenv("RELAY_UPSTREAM") orelse "bsky.network"; 151 + const upstream = normalizeSeedHost(std.posix.getenv("RELAY_UPSTREAM") orelse "bsky.network"); 152 152 const data_dir = std.posix.getenv("RELAY_DATA_DIR") orelse "data/events"; 153 153 const retention_hours = parseEnvInt(u64, "RELAY_RETENTION_HOURS", 72); 154 154 const frame_workers = parseEnvInt(u16, "FRAME_WORKERS", 16); ··· 333 333 std.posix.sigaction(std.posix.SIG.PIPE, &ignore_act, null); 334 334 } 335 335 336 + /// normalize seed host: empty string or "none" means disabled (no bootstrap). 337 + fn normalizeSeedHost(raw: []const u8) []const u8 { 338 + if (raw.len == 0 or std.mem.eql(u8, raw, "none")) return ""; 339 + return raw; 340 + } 341 + 336 342 fn parseEnvInt(comptime T: type, key: []const u8, default: T) T { 337 343 const val = std.posix.getenv(key) orelse return default; 338 344 return std.fmt.parseInt(T, val, 10) catch default; 339 345 } 346 + 347 + test "normalizeSeedHost" { 348 + // normal hostnames pass through 349 + try std.testing.expectEqualStrings("bsky.network", normalizeSeedHost("bsky.network")); 350 + try std.testing.expectEqualStrings("relay.example.com", normalizeSeedHost("relay.example.com")); 351 + 352 + // empty string and "none" disable bootstrap 353 + try std.testing.expectEqualStrings("", normalizeSeedHost("")); 354 + try std.testing.expectEqualStrings("", normalizeSeedHost("none")); 355 + }
+8 -4
src/slurper.zig
··· 485 485 /// is shorter than a throttled ramp (many hosts fail-fast, freeing memory quickly). 486 486 fn spawnWorkers(self: *Slurper) void { 487 487 // pull hosts from seed relay first โ€” idempotent (getOrCreateHost skips existing) 488 - log.info("pulling hosts from {s}...", .{self.options.seed_host}); 489 - self.pullHosts() catch |err| { 490 - log.warn("pullHosts from {s} failed: {s}", .{ self.options.seed_host, @errorName(err) }); 491 - }; 488 + if (self.options.seed_host.len > 0) { 489 + log.info("pulling hosts from {s}...", .{self.options.seed_host}); 490 + self.pullHosts() catch |err| { 491 + log.warn("pullHosts from {s} failed: {s}", .{ self.options.seed_host, @errorName(err) }); 492 + }; 493 + } else { 494 + log.info("no seed host configured, skipping bootstrap", .{}); 495 + } 492 496 493 497 const hosts = self.persist.listActiveHosts(self.allocator) catch |err| { 494 498 log.err("failed to load hosts: {s}", .{@errorName(err)});

History

2 rounds 2 comments
sign up or login to add to the discussion
2 commits
expand
allow disabling bootstrap by setting RELAY_UPSTREAM="" or "none"
readme: note RELAY_UPSTREAM can be disabled
expand 2 comments

I'm no zig expert, but the logic seems sound

cool ty! will get this on main

closed without merging
1 commit
expand
allow disabling bootstrap by setting RELAY_UPSTREAM="" or "none"
expand 0 comments