Squashed from work: - asset-ai: FastH3 4-step fast video backend; clip keyframes on the wire - asset-ui: loop video chains — text→image→video that ends where it began - h3: safetensors -> pruned-Q4_K GGUF quantizer for the 24GB DiT tiers - h3_quant_gguf verify: row-error gates calibrated to the measured Q4_K floor - asset-ai realtime: the feedback loop — the source anchors, the drifted frame inits - asset-ai realtime: a feedback loop survives a resize and travels by default - asset-ai realtime: the feedback loop frees itself from the feed handshake and pauses for its listener - asset-ai realtime: the outbound encode leaves the loop's critical path - asset-ai ocr: the ocr domain — Chandra 2 at page resolution, and the tower goes planner-owned - llm slots: a lane can hold an image span — embedding prefill and a rope cursor of its own - vision tower on CUDA: the encode leg gets its two missing kernels - llm/ocr: one M-RoPE grid encoder for both image paths, and a livelock made an error - vision tower on CUDA: the f16 GEMM keeps the precision it was throwing away - live: a feed that moves box takes its trip with it — one seed image - vision tower on CUDA: the tiled attention becomes bit-exact, and tensor cores go - llm prefill on CUDA: the MMA attention kernel gets the tile a 4-to-1 model needs - asset-ai ocr: the CUDA encode lane joins the integration — vision-parity sits beside run's three arms, and the kernels - Merge branch 'ocr-perf-integration' into work - asset-ai: the live anchor can follow the trip, and text leaves the 5090 - asset-ai: the camera moves the world, and the world starts still - asset-import: the EA strategy classics, in the one 2D contract - rtsmap: one seeded generator for tiled strategy maps - asset-ui: one card for the strategy classics, with a pack dropdown - asset-ai: music3 reference-audio path, ocr/h3 backends, registry - asset: mp4 sample index for range-streaming, chat tools, import profiles - cnc: tiberium is twelve growth frames, not twelve empty variants - platform: native file and save dialogs, in-house on all three desktops - chat: the scan holds out for a lane home - chat: a full home queues you — take the free lane - chat: the preload has a percentage, and the boundless cap stops showing - llm cuda: the 32x2 attention tile — even GQA ratios stay on MMA - sa3 gets a bake path: the sfx model's tables precomputed by a diffusion-side bin - sqlite_query: anti-join regression test - td import: HARV's second frame block is its harvesting cycle, not a turret - asset-ui: sprite enhancement runs on the 32B dev DiT — distillation, not the prompt, was the ceiling - ai-hub: makepad-asset-ai becomes makepad-ai-hub at libs/ai/hub, the chat pane becomes makepad-chat-ui, the service bin - asset-ui: test health fixtures grow the realtime field they were born without - ai-hub: one home at ~/.makepad — weights/ run/ cache/ logs/, the service cache migrates from ai_content by a single re - ai-hub: subprocess workers die with the node — process groups everywhere, PDEATHSIG on linux, one KILL_ON_JOB_CLOSE Jo - ai-hub: the hub object — AiHub::in_process, pipes vocabulary, and the local LLM engine generalized out of mpfiles (aic - strict-json: the dependency-free JSON module gets its own crate; asset-client re-exports it so nothing downstream move - ai-hub: the machine layer — node entries, the 0600 machine token, and the residency election that IS the lock (aicore - ai-hub: MPHUB1 — the fabric beacon only dedicated nodes can send (aicore §4) - ai-hub: job leases — work lives only while it is renewed (aicore §8) - asset-creator: the pipeline library is born — specs, the deps gate, and the derived-state law (aicore §9) - ai-hub: RAM residency facts — the CPU-side twin of residency.rs (aicore §3) - ai-hub: ETA placement primitives — relative GPU throughput, the four-term estimate, and an observable breakdown (aicor - ai-hub: leases go live on the wire — origin fields on submit, /job/<id>/keepalive, /bye, and the reaper that cancels w - ai-hub: the chat providers move in — fleet qwen, openai, grok, claude/codex/grok CLIs, the responses driver, and the w - asset-creator: the engine — one pipeline run against the hub, deps-gated, spliced, cancellable, resumable-by-construct - ai-hub: the machine node mode — --machine binds loopback, registers in ~/.makepad/run, and exits on its own once idle - asset-creator: makepad-creator-run — the detached client for runs that must outlive a window (aicore §9) - ai-hub: a native Claude Messages-API provider — API-key or Claude Code OAuth, bounded SSE streaming, injected tools (a - route + converse: off makepad_ai — the Agent seam moves to converse, route's cloud dispatcher rides the hub's Claude p - asset-creator: the preset tables move in — fifteen chain-policy constants shared by every creator app (aicore §9 / P6) - makepad_ai is deleted — every backend is a hub pipe, the agent seam lives with its consumers (aicore §14, decided 2026 - ai-hub: loads hold the machine residency election — set_model_state claims on Loaded and publishes the service port (a - ai-hub: chats run the machine election — route to a serving holder, wait on a loading one, claim and publish when open - ai-hub: pick_for_domain_eta — ETA-ranked placement over the shared hard-filter core (aicore §6 / P4) - asset-creator: the engine picks a provider per stage at dispatch time — a chain's later stages see fresh fleet state ( - ai-hub: the fabric secret gates the service HTTP surface — bearer on everything but /health and the ticketed peer path - vj: DREAM runs execute in the app — pipelines.rs becomes the run it used to watch (aicore §9 / F1) - asset-creator: the runner — generate one thing and put it in the catalog, one implementation for every surface (aicore - chat-ui: the session runs in the app — no broker anywhere on the chat path (aicore P8 / F5) - asset-store: assets.query is a first-class query endpoint — the bounded SQL surface outlives the broker (aicore P8 / F - asset-creator: CreatorTools — the chat tool pack for a store that only stores (aicore §9 / P8) - asset-store: the shrink — the store stores (aicore P7) - importer + asset-server host: the coordination era ends (aicore P7) - store config purge + asset-ui goes fleet-direct; the derive protocol gets its route proof (aicore P7) - client + chat dispatcher: the dead wire comes out (aicore P7/P8) - ai-hub: 0.3.0 — the health version says which era a node runs - ai-hub: the default fleet is 'gen' — apps hear the LAN without env plumbing - ai-hub: the preload note percents the prefill, not the job bar - ai-hub: conversations keep their KV — the wire mirror, the lane identity, the in-turn dynamic context (aicore §7) - ai-hub: an open-think model is thinking from its first token - libs: the zero-warning sweep — stitch casts say what they mean, xatlas keeps upstream's surface quietly - zero-warning sweep, round two — the first full-workspace pass - zero-warning sweep, round three — the model lanes and the deep examples - zero-warning sweep, round four — the last stragglers - zero-warning sweep, round five — vj and chat-ui - zero-warning sweep, round six — three cascades Co-authored-by: Claude <info@makepad.nl>
379 lines
15 KiB
Rust
379 lines
15 KiB
Rust
//! Security-focused tests: credential uniformity, capability scoping and
|
|
//! delegation limits, worker identity binding, the namespace claim gate,
|
|
//! hostile HTTP input, upload refusals, and discovery-plane hostility.
|
|
|
|
mod common;
|
|
|
|
use common::*;
|
|
use makepad_asset_store::discovery::{caps, Beacon, DiscoveryListener, PROTOCOL_VERSION};
|
|
use makepad_asset_store::json::Value;
|
|
use makepad_asset_data::BlobId;
|
|
use std::net::UdpSocket;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// credentials
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn refused_credentials_are_uniform() {
|
|
let ts = start_server("uniform401");
|
|
let token = ts.admin_token();
|
|
let mut admin = ts.control(Some(&token));
|
|
|
|
// A real token that will be expired, and one that will be revoked.
|
|
let victim = {
|
|
let r = admin.post_json("/v1/auth/principals", &jobj(vec![("name", jstr("victim"))]));
|
|
r.str_field("principal")
|
|
};
|
|
let short = admin
|
|
.post_json(
|
|
"/v1/auth/tokens",
|
|
&jobj(vec![("principal", jstr(victim.clone())), ("ttl_ms", Value::Int(50))]),
|
|
)
|
|
.str_field("token");
|
|
let revoked = admin
|
|
.post_json("/v1/auth/tokens", &jobj(vec![("principal", jstr(victim))]))
|
|
.str_field("token");
|
|
let r = admin.post_json("/v1/auth/tokens/revoke", &jobj(vec![("token", jstr(revoked.clone()))]));
|
|
assert_eq!(r.status, 204);
|
|
std::thread::sleep(std::time::Duration::from_millis(80)); // expire `short`
|
|
|
|
let unknown = format!("mpat_{}", "ab".repeat(32));
|
|
let cases: Vec<Option<String>> = vec![
|
|
None, // no header
|
|
Some("not-a-token".into()), // malformed shape
|
|
Some("mpat_zz".into()), // malformed hex
|
|
Some(unknown), // valid shape, unknown
|
|
Some(short), // expired
|
|
Some(revoked), // revoked
|
|
];
|
|
let mut bodies = Vec::new();
|
|
for case in cases {
|
|
let mut c = ts.control(case.as_deref());
|
|
let r = c.get("/v1/auth/whoami");
|
|
assert_eq!(r.status, 401);
|
|
assert_eq!(r.header("WWW-Authenticate"), Some("Bearer"));
|
|
bodies.push(r.body);
|
|
}
|
|
// Every refusal is byte-identical: no oracle distinguishes unknown,
|
|
// malformed, expired and revoked credentials.
|
|
for b in &bodies[1..] {
|
|
assert_eq!(b, &bodies[0]);
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// capability scoping
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn capability_scoping_and_revocation() {
|
|
let ts = start_server("scoping");
|
|
let token = ts.admin_token();
|
|
let mut admin = ts.control(Some(&token));
|
|
let scoped = principal_with(&mut admin, &[("asset_register", "demo")]);
|
|
let mut c = ts.control(Some(&scoped));
|
|
|
|
// In-scope namespace works; any other namespace is denied with the
|
|
// capability named.
|
|
let r = c.post_json("/v1/assets", &jobj(vec![("namespace", jstr("demo"))]));
|
|
assert_eq!(r.status, 201);
|
|
let asset_id = r.str_field("asset_id");
|
|
let r = c.post_json("/v1/assets", &jobj(vec![("namespace", jstr("other"))]));
|
|
assert_eq!(r.status, 403);
|
|
assert_eq!(r.json().get("capability").unwrap().as_str(), Some("asset_register"));
|
|
|
|
// A capability the principal never had is denied even in-scope.
|
|
let fake_rev = format!("arev_{}", "0".repeat(64));
|
|
let r = c.post_json(
|
|
&format!("/v1/assets/{asset_id}/revisions/{fake_rev}/publish"),
|
|
&jobj(vec![]),
|
|
);
|
|
assert_eq!(r.status, 403);
|
|
assert_eq!(r.json().get("capability").unwrap().as_str(), Some("asset_publish"));
|
|
|
|
// Revocation takes effect on the next request.
|
|
let whoami = c.get("/v1/auth/whoami").str_field("principal");
|
|
let r = admin.post_json(
|
|
"/v1/auth/grants/revoke",
|
|
&jobj(vec![
|
|
("principal", jstr(whoami)),
|
|
("capability", jstr("asset_register")),
|
|
("scope", jstr("demo")),
|
|
]),
|
|
);
|
|
assert_eq!(r.status, 204);
|
|
let r = c.post_json("/v1/assets", &jobj(vec![("namespace", jstr("demo"))]));
|
|
assert_eq!(r.status, 403);
|
|
}
|
|
|
|
#[test]
|
|
fn auth_admin_delegation_is_namespace_bounded() {
|
|
let ts = start_server("delegation");
|
|
let token = ts.admin_token();
|
|
let mut admin = ts.control(Some(&token));
|
|
let ns_admin = principal_with(&mut admin, &[("auth_admin", "demo")]);
|
|
let subject = principal_with(&mut admin, &[]);
|
|
let mut c = ts.control(Some(&ns_admin));
|
|
let subject_principal = {
|
|
let mut s = ts.control(Some(&subject));
|
|
s.get("/v1/auth/whoami").str_field("principal")
|
|
};
|
|
|
|
// A namespace-scoped auth admin may grant within its namespace...
|
|
let r = c.post_json(
|
|
"/v1/auth/grants",
|
|
&jobj(vec![
|
|
("principal", jstr(subject_principal.clone())),
|
|
("capability", jstr("blob_write")),
|
|
("scope", jstr("demo")),
|
|
]),
|
|
);
|
|
assert_eq!(r.status, 204);
|
|
// ...but not in another namespace, not with wildcard scope, and it may
|
|
// not mint principals or tokens (root-only).
|
|
let r = c.post_json(
|
|
"/v1/auth/grants",
|
|
&jobj(vec![
|
|
("principal", jstr(subject_principal.clone())),
|
|
("capability", jstr("blob_write")),
|
|
("scope", jstr("other")),
|
|
]),
|
|
);
|
|
assert_eq!(r.status, 403);
|
|
let r = c.post_json(
|
|
"/v1/auth/grants",
|
|
&jobj(vec![
|
|
("principal", jstr(subject_principal.clone())),
|
|
("capability", jstr("blob_write")),
|
|
("scope", jstr("*")),
|
|
]),
|
|
);
|
|
assert_eq!(r.status, 403);
|
|
assert_eq!(
|
|
c.post_json("/v1/auth/principals", &jobj(vec![("name", jstr("sneaky"))])).status,
|
|
403
|
|
);
|
|
let r = c.post_json(
|
|
"/v1/auth/tokens",
|
|
&jobj(vec![("principal", jstr(subject_principal))]),
|
|
);
|
|
assert_eq!(r.status, 403);
|
|
|
|
// The bootstrap admin principal cannot be disabled.
|
|
let root_principal = admin.get("/v1/auth/whoami").str_field("principal");
|
|
let r = admin.post_json(&format!("/v1/auth/principals/{root_principal}/disable"), &jobj(vec![]));
|
|
assert_eq!(r.status, 409);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// jobs: claim gate + identity binding + visibility
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn hostile_http_input_is_refused() {
|
|
let ts = start_server("hostile");
|
|
let addr = ts.server.control_addr();
|
|
|
|
// Request smuggling and framing hostility.
|
|
let cases: Vec<(&[u8], u16)> = vec![
|
|
(b"POST /v1/catalog HTTP/1.1\r\nHost: x\r\nContent-Length: 3\r\nTransfer-Encoding: chunked\r\n\r\n", 400),
|
|
(b"POST /v1/catalog HTTP/1.1\r\nHost: x\r\nTransfer-Encoding: gzip, chunked\r\n\r\n", 501),
|
|
(b"GET /v1/health HTTP/1.0\r\nHost: x\r\n\r\n", 505),
|
|
(b"BREW /v1/health HTTP/1.1\r\nHost: x\r\n\r\n", 501),
|
|
(b"GET /v1/health HTTP/1.1\r\n\r\n", 400),
|
|
(b"GET /v1/health HTTP/1.1\r\nHost: a\r\nHost: b\r\n\r\n", 400),
|
|
(b"GET /v1/%2e%2e/secrets HTTP/1.1\r\nHost: x\r\n\r\n", 400),
|
|
(b"GET /v1/../etc/passwd HTTP/1.1\r\nHost: x\r\n\r\n", 400),
|
|
(b"GET /v1//health HTTP/1.1\r\nHost: x\r\n\r\n", 400),
|
|
(b"GET /v1/health?a=1&a=2 HTTP/1.1\r\nHost: x\r\n\r\n", 400),
|
|
(b"GET /v1/health HTTP/1.1\r\nHost: x\r\nBad: a\x01b\r\n\r\n", 400),
|
|
(b"GET /v1/health HTTP/1.1\r\nHost: x\r\nContent-Length: 5\r\n\r\n", 400),
|
|
];
|
|
for (raw, want) in cases {
|
|
let resp = raw_roundtrip(addr, raw);
|
|
assert_eq!(status_of(&resp), want, "{}", String::from_utf8_lossy(raw));
|
|
let text = String::from_utf8_lossy(&resp);
|
|
assert!(text.contains("Connection: close"), "hostile input closes");
|
|
assert!(text.contains("X-Content-Type-Options: nosniff"));
|
|
}
|
|
|
|
// Oversized head: refused with 431.
|
|
let mut big = b"GET /v1/health HTTP/1.1\r\nHost: x\r\n".to_vec();
|
|
big.extend_from_slice(format!("X-Filler: {}\r\n", "a".repeat(40 * 1024)).as_bytes());
|
|
big.extend_from_slice(b"\r\n");
|
|
assert_eq!(status_of(&raw_roundtrip(addr, &big)), 431);
|
|
|
|
// Chunked body over the JSON budget: 413, connection closed.
|
|
let token = ts.admin_token();
|
|
let mut chunked = format!(
|
|
"POST /v1/catalog HTTP/1.1\r\nHost: x\r\nAuthorization: Bearer {token}\r\nTransfer-Encoding: chunked\r\n\r\n"
|
|
)
|
|
.into_bytes();
|
|
let chunk = vec![b'a'; 64 * 1024];
|
|
for _ in 0..6 {
|
|
chunked.extend_from_slice(format!("{:x}\r\n", chunk.len()).as_bytes());
|
|
chunked.extend_from_slice(&chunk);
|
|
chunked.extend_from_slice(b"\r\n");
|
|
}
|
|
chunked.extend_from_slice(b"0\r\n\r\n");
|
|
assert_eq!(status_of(&raw_roundtrip(addr, &chunked)), 413);
|
|
|
|
// Chunk-extension and non-hex size lines are malformed.
|
|
let bad_chunk = format!(
|
|
"POST /v1/catalog HTTP/1.1\r\nHost: x\r\nAuthorization: Bearer {token}\r\nTransfer-Encoding: chunked\r\n\r\n5;ext=1\r\nhello\r\n0\r\n\r\n"
|
|
);
|
|
assert_eq!(status_of(&raw_roundtrip(addr, bad_chunk.as_bytes())), 400);
|
|
|
|
// Pipelined requests on one connection are answered in order.
|
|
let two = b"GET /v1/health HTTP/1.1\r\nHost: x\r\n\r\nGET /v1/health HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n";
|
|
let resp = raw_roundtrip(addr, two);
|
|
let text = String::from_utf8_lossy(&resp);
|
|
assert_eq!(text.matches("HTTP/1.1 200").count(), 2);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// upload refusals
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn blob_upload_refusals_leave_no_state() {
|
|
// Shrunken blob budget makes over-budget cheap to hit.
|
|
let ts = start_server_with("uploadrefuse", |cfg| {
|
|
cfg.budgets.max_blob_bytes = 4096;
|
|
});
|
|
let token = ts.admin_token();
|
|
let mut admin = ts.control(Some(&token));
|
|
let writer = principal_with(&mut admin, &[("blob_write", "demo")]);
|
|
let mut data = ts.data(Some(&writer));
|
|
|
|
// Over budget: refused, and the digest stays unknown afterwards.
|
|
let big = vec![7u8; 8192];
|
|
let r = data.post_bytes("/v1/blobs?ns=demo", &big);
|
|
assert_eq!(r.status, 413);
|
|
let id = BlobId::hash_of(&big);
|
|
assert_eq!(data.get(&format!("/v1/blobs/{id}")).status, 404);
|
|
|
|
// Declared-digest mismatch: refused, nothing recorded.
|
|
let payload = b"honest bytes".to_vec();
|
|
let wrong = "1".repeat(64);
|
|
let r = data.request(
|
|
"POST",
|
|
&format!("/v1/blobs?ns=demo&sha256={wrong}"),
|
|
&[],
|
|
Some(&payload),
|
|
);
|
|
assert_eq!(r.status, 422);
|
|
let id = BlobId::hash_of(&payload);
|
|
assert_eq!(data.get(&format!("/v1/blobs/{id}")).status, 404);
|
|
|
|
// Missing namespace and missing capability refuse before any byte is
|
|
// admitted.
|
|
assert_eq!(data.post_bytes("/v1/blobs", &payload).status, 400);
|
|
let outsider = principal_with(&mut admin, &[]);
|
|
let mut noperm = ts.data(Some(&outsider));
|
|
let r = noperm.post_bytes("/v1/blobs?ns=demo", &payload);
|
|
assert_eq!(r.status, 403);
|
|
|
|
// Unauthenticated data plane: refused uniformly.
|
|
let mut anon = ts.data(None);
|
|
assert_eq!(anon.post_bytes("/v1/blobs?ns=demo", &payload).status, 401);
|
|
assert_eq!(anon.get(&format!("/v1/blobs/{id}")).status, 401);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// connection capacity
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn over_capacity_connections_get_an_explicit_503() {
|
|
let ts = start_server_with("capacity", |cfg| {
|
|
cfg.control_max_conns = 2;
|
|
});
|
|
// Two idle keep-alive connections occupy the whole plane.
|
|
let mut c1 = ts.control(None);
|
|
let mut c2 = ts.control(None);
|
|
assert_eq!(c1.get("/v1/health").status, 200);
|
|
assert_eq!(c2.get("/v1/health").status, 200);
|
|
// The third connection is refused immediately and explicitly — no silent
|
|
// backlog starvation behind idle keep-alives.
|
|
let resp = raw_roundtrip(
|
|
ts.server.control_addr(),
|
|
b"GET /v1/health HTTP/1.1\r\nHost: x\r\n\r\n",
|
|
);
|
|
assert_eq!(status_of(&resp), 503);
|
|
// The occupied connections still work, and freeing one readmits others.
|
|
assert_eq!(c1.get("/v1/health").status, 200);
|
|
drop(c2);
|
|
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
|
|
loop {
|
|
let resp = raw_roundtrip(
|
|
ts.server.control_addr(),
|
|
b"GET /v1/health HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n",
|
|
);
|
|
if status_of(&resp) == 200 {
|
|
break;
|
|
}
|
|
assert!(std::time::Instant::now() < deadline, "slot never freed");
|
|
std::thread::sleep(std::time::Duration::from_millis(20));
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// discovery hostility
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn discovery_listener_survives_hostile_floods() {
|
|
let mut listener = DiscoveryListener::start(0, 60_000).expect("listener");
|
|
let port = listener.port();
|
|
let sock = UdpSocket::bind("127.0.0.1:0").unwrap();
|
|
let dest = ("127.0.0.1", port);
|
|
|
|
// Garbage of every shape: ignored.
|
|
sock.send_to(b"", dest).unwrap();
|
|
sock.send_to(b"short", dest).unwrap();
|
|
sock.send_to(&[0u8; 36], dest).unwrap();
|
|
sock.send_to(&[0xffu8; 512], dest).unwrap();
|
|
let mut zero_port = Beacon {
|
|
protocol_version: PROTOCOL_VERSION,
|
|
server_id: [1; 16],
|
|
control_port: 0,
|
|
data_port: 1,
|
|
auth_required: true,
|
|
tls: false,
|
|
capability_bits: caps::ALL_V1,
|
|
};
|
|
sock.send_to(&zero_port.encode(), dest).unwrap();
|
|
zero_port.control_port = 1;
|
|
zero_port.protocol_version = 0;
|
|
sock.send_to(&zero_port.encode(), dest).unwrap();
|
|
|
|
// A flood of distinct identities cannot grow the cache past its bound.
|
|
for i in 0..300u32 {
|
|
let mut id = [0u8; 16];
|
|
id[..4].copy_from_slice(&i.to_be_bytes());
|
|
let b = Beacon {
|
|
protocol_version: PROTOCOL_VERSION,
|
|
server_id: id,
|
|
control_port: 9701,
|
|
data_port: 9702,
|
|
auth_required: true,
|
|
tls: false,
|
|
capability_bits: caps::ALL_V1,
|
|
};
|
|
sock.send_to(&b.encode(), dest).unwrap();
|
|
}
|
|
// Give the receive thread time to drain the socket.
|
|
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
|
|
loop {
|
|
let n = listener.snapshot(makepad_asset_store::util::now_ms()).len();
|
|
assert!(n <= DiscoveryListener::MAX_ENTRIES, "cache bounded");
|
|
if n == DiscoveryListener::MAX_ENTRIES || std::time::Instant::now() >= deadline {
|
|
assert!(n > 0, "well-formed beacons were received");
|
|
break;
|
|
}
|
|
std::thread::sleep(std::time::Duration::from_millis(20));
|
|
}
|
|
listener.stop();
|
|
}
|