refactor: v0.8 Iteration B — cruft purge + ALPN bump to itsgoin/4
Zero-users ruling removes all wire-compat obligations. Net -1,443 LOC of Rust. Protocol break: - ALPN_V2 b"itsgoin/3" -> ALPN b"itsgoin/4" (renamed: the versioned name was what rotted). Old nodes are now refused at the QUIC handshake instead of half-interoperating with the v0.8 manifest/digest formats. Deploy gate from Iteration A is discharged. Dead wire surface removed (MessageType 46 -> 40): - DeleteRecord 0x51 (deletes ride ControlOp::DeletePost + InitialExchange) - VisibilityUpdate 0x52 + its two dead senders (ControlOp::UpdateVisibility) - SocialDisconnectNotice 0x71 (zero senders; checkin timeouts carry the signal) - MeshPrefer 0xB3 + request_prefer + handler (preferred peers are gone) - Legacy dual pull-matching half (have_post_ids) — behavior-identical - PullSyncResponse.visibility_updates + counters (control posts cover it) - serde(default) stripped from wire-only payloads (kept where skip_serializing_if makes it load-bearing; persisted-row defaults untouched) Preferred-peer subsystem eliminated (design ruling: CDN file_holders replaced the N+10 direct push/pull it served): slot tier, preferred_peers table (dropped), preferred_tree semantics, rebalance Priority 0, find_relays_for preferred tiers, 7-day prune + 30-day watcher, dead FromStr impl. Slots are now Local/Wide only (91 desktop / 12 mobile) pending Iteration C's single ~20-slot pool. Other dead code: hostlist encoder + base64url helper, always-empty downstream_addrs parameter chain, start_upnp_renewal_cycle no-op + 4 callers, RELAY_TARGET_RATE_LIMIT, GetSecretSeed, stale comments swept. Preserved deliberately: EDM scanner corpse (awaiting raw-UDP refactor), PortScanHeartbeat, Iteration A startup migrations, session-relay opt-in gating. Docs: design.html + tech.html synced (message counts, ALPN, purge status, Rework asides flipped past-tense). 190 core tests pass; CLI + desktop build; A3 integration 9/9 (independently re-run post-purge). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LGiPD2cF75mnvneSCjdDC5
This commit is contained in:
parent
17dbf076cb
commit
36e3871c4b
15 changed files with 152 additions and 1476 deletions
|
|
@ -8,7 +8,6 @@ use std::sync::Arc;
|
|||
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::sync::Mutex;
|
||||
use tracing::{debug, info};
|
||||
|
||||
use crate::blob::BlobStore;
|
||||
|
|
@ -106,7 +105,6 @@ pub async fn run_http_server(
|
|||
port: u16,
|
||||
storage: Arc<StoragePool>,
|
||||
blob_store: Arc<BlobStore>,
|
||||
downstream_addrs: Arc<Mutex<HashMap<[u8; 32], Vec<SocketAddr>>>>,
|
||||
) -> anyhow::Result<()> {
|
||||
let addr: SocketAddr = ([0, 0, 0, 0], port).into();
|
||||
// Use SO_REUSEADDR + SO_REUSEPORT so TCP punch sockets can share the port
|
||||
|
|
@ -156,10 +154,9 @@ pub async fn run_http_server(
|
|||
let storage = Arc::clone(&storage);
|
||||
let blob_store = Arc::clone(&blob_store);
|
||||
let budget = Arc::clone(&budget);
|
||||
let downstream_addrs = Arc::clone(&downstream_addrs);
|
||||
|
||||
tokio::spawn(async move {
|
||||
handle_connection(stream, ip, slot, &storage, &blob_store, &downstream_addrs).await;
|
||||
handle_connection(stream, ip, slot, &storage, &blob_store).await;
|
||||
let mut b = budget.lock().unwrap();
|
||||
match slot {
|
||||
SlotKind::Content => b.release_content(ip),
|
||||
|
|
@ -182,7 +179,6 @@ async fn handle_connection(
|
|||
slot: SlotKind,
|
||||
storage: &Arc<StoragePool>,
|
||||
blob_store: &Arc<BlobStore>,
|
||||
downstream_addrs: &Arc<Mutex<HashMap<[u8; 32], Vec<SocketAddr>>>>,
|
||||
) {
|
||||
// Keep-alive loop: handle sequential requests on the same connection
|
||||
loop {
|
||||
|
|
@ -222,7 +218,7 @@ async fn handle_connection(
|
|||
}
|
||||
}
|
||||
SlotKind::Redirect => {
|
||||
if !try_redirect(&mut stream, &post_id, storage, downstream_addrs).await {
|
||||
if !try_redirect(&mut stream, &post_id, storage).await {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -368,7 +364,6 @@ async fn try_redirect(
|
|||
stream: &mut TcpStream,
|
||||
post_id: &[u8; 32],
|
||||
storage: &Arc<StoragePool>,
|
||||
_downstream_addrs: &Arc<Mutex<HashMap<[u8; 32], Vec<SocketAddr>>>>,
|
||||
) -> bool {
|
||||
// Get downstream peers for this post
|
||||
let downstream_peers = {
|
||||
|
|
@ -583,114 +578,6 @@ pub fn html_escape(s: &str) -> String {
|
|||
out
|
||||
}
|
||||
|
||||
// --- Share link generation ---
|
||||
|
||||
/// Encode a list of socket addresses as compact binary, then base64url.
|
||||
/// Per IPv4: [0x04][4 bytes IP][2 bytes port] = 7 bytes
|
||||
/// Per IPv6: [0x06][16 bytes IP][2 bytes port] = 19 bytes
|
||||
pub fn encode_hostlist(hosts: &[SocketAddr]) -> String {
|
||||
let mut buf = Vec::with_capacity(hosts.len() * 19);
|
||||
for host in hosts.iter().take(5) {
|
||||
match host {
|
||||
SocketAddr::V4(v4) => {
|
||||
buf.push(0x04);
|
||||
buf.extend_from_slice(&v4.ip().octets());
|
||||
buf.extend_from_slice(&v4.port().to_be_bytes());
|
||||
}
|
||||
SocketAddr::V6(v6) => {
|
||||
buf.push(0x06);
|
||||
buf.extend_from_slice(&v6.ip().octets());
|
||||
buf.extend_from_slice(&v6.port().to_be_bytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
base64url_encode(&buf)
|
||||
}
|
||||
|
||||
/// Decode a base64url-encoded hostlist back to socket addresses.
|
||||
pub fn decode_hostlist(encoded: &str) -> Vec<SocketAddr> {
|
||||
let buf = match base64url_decode(encoded) {
|
||||
Some(b) => b,
|
||||
None => return Vec::new(),
|
||||
};
|
||||
let mut addrs = Vec::new();
|
||||
let mut i = 0;
|
||||
while i < buf.len() {
|
||||
match buf[i] {
|
||||
0x04 if i + 7 <= buf.len() => {
|
||||
let ip = std::net::Ipv4Addr::new(buf[i + 1], buf[i + 2], buf[i + 3], buf[i + 4]);
|
||||
let port = u16::from_be_bytes([buf[i + 5], buf[i + 6]]);
|
||||
addrs.push(SocketAddr::new(ip.into(), port));
|
||||
i += 7;
|
||||
}
|
||||
0x06 if i + 19 <= buf.len() => {
|
||||
let mut octets = [0u8; 16];
|
||||
octets.copy_from_slice(&buf[i + 1..i + 17]);
|
||||
let ip = std::net::Ipv6Addr::from(octets);
|
||||
let port = u16::from_be_bytes([buf[i + 17], buf[i + 18]]);
|
||||
addrs.push(SocketAddr::new(ip.into(), port));
|
||||
i += 19;
|
||||
}
|
||||
_ => break, // malformed
|
||||
}
|
||||
}
|
||||
addrs
|
||||
}
|
||||
|
||||
// --- Minimal base64url implementation (no external dependency) ---
|
||||
|
||||
const B64_CHARS: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
||||
|
||||
fn base64url_encode(data: &[u8]) -> String {
|
||||
let mut out = String::with_capacity((data.len() * 4 + 2) / 3);
|
||||
let mut i = 0;
|
||||
while i + 2 < data.len() {
|
||||
let n = ((data[i] as u32) << 16) | ((data[i + 1] as u32) << 8) | data[i + 2] as u32;
|
||||
out.push(B64_CHARS[((n >> 18) & 0x3F) as usize] as char);
|
||||
out.push(B64_CHARS[((n >> 12) & 0x3F) as usize] as char);
|
||||
out.push(B64_CHARS[((n >> 6) & 0x3F) as usize] as char);
|
||||
out.push(B64_CHARS[(n & 0x3F) as usize] as char);
|
||||
i += 3;
|
||||
}
|
||||
let remaining = data.len() - i;
|
||||
if remaining == 2 {
|
||||
let n = ((data[i] as u32) << 16) | ((data[i + 1] as u32) << 8);
|
||||
out.push(B64_CHARS[((n >> 18) & 0x3F) as usize] as char);
|
||||
out.push(B64_CHARS[((n >> 12) & 0x3F) as usize] as char);
|
||||
out.push(B64_CHARS[((n >> 6) & 0x3F) as usize] as char);
|
||||
} else if remaining == 1 {
|
||||
let n = (data[i] as u32) << 16;
|
||||
out.push(B64_CHARS[((n >> 18) & 0x3F) as usize] as char);
|
||||
out.push(B64_CHARS[((n >> 12) & 0x3F) as usize] as char);
|
||||
}
|
||||
out // no padding
|
||||
}
|
||||
|
||||
fn base64url_decode(s: &str) -> Option<Vec<u8>> {
|
||||
let mut buf = Vec::with_capacity(s.len() * 3 / 4);
|
||||
let mut accum: u32 = 0;
|
||||
let mut bits: u32 = 0;
|
||||
for c in s.bytes() {
|
||||
let val = match c {
|
||||
b'A'..=b'Z' => c - b'A',
|
||||
b'a'..=b'z' => c - b'a' + 26,
|
||||
b'0'..=b'9' => c - b'0' + 52,
|
||||
b'-' => 62,
|
||||
b'_' => 63,
|
||||
b'=' => continue, // skip padding
|
||||
_ => return None,
|
||||
};
|
||||
accum = (accum << 6) | val as u32;
|
||||
bits += 6;
|
||||
if bits >= 8 {
|
||||
bits -= 8;
|
||||
buf.push((accum >> bits) as u8);
|
||||
accum &= (1 << bits) - 1;
|
||||
}
|
||||
}
|
||||
Some(buf)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -713,26 +600,6 @@ mod tests {
|
|||
assert_eq!(html_escape("a&b"), "a&b");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_base64url_roundtrip() {
|
||||
let data = b"hello world";
|
||||
let encoded = base64url_encode(data);
|
||||
let decoded = base64url_decode(&encoded).unwrap();
|
||||
assert_eq!(decoded, data);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hostlist_roundtrip() {
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
let hosts = vec![
|
||||
SocketAddr::new(Ipv4Addr::new(192, 168, 1, 1).into(), 4433),
|
||||
SocketAddr::new(Ipv6Addr::LOCALHOST.into(), 8080),
|
||||
];
|
||||
let encoded = encode_hostlist(&hosts);
|
||||
let decoded = decode_hostlist(&encoded);
|
||||
assert_eq!(decoded, hosts);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_request_line() {
|
||||
let req = b"GET /p/abc123 HTTP/1.1\r\nHost: example.com\r\n\r\n";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue