Swarm assets for native games
ComingHow a native game's files reach players, from manifest assets in a content-addressed cache to site files delivered by the player swarm with hash verification and origin fallback.
A native game gets its files in two ways. Both are verified by hash before the game sees a byte.
#1. Manifest assets
Files listed in the manifest's assets (and the entry module) are downloaded before sg_init
and read with:
let level = sg_guest::asset("level1.bin").expect("listed in the manifest");Each file is named by its SHA-256 and stored on disk as <cache>/sha256/<hex>. A cached file is
used only after its hash is checked again, identical files are shared across games and versions,
and an update downloads only the files whose hash changed.
#2. Site files through the player swarm
A game that loads files at run time from its web site (with a fetch permission for the site's
URL prefix) can have those files delivered by other players instead of the site. This is the
same swarm that serves the site to browser players:
- The site publishes
swarm/manifest.jsonat the root of the fetch prefix, in the meshtorrent asset-manifest format:{"version": 1, "entries": {"/path": {"tileId": "<sha256>", "infoHash": "<40 hex>", "size": N}}}. The 0x hosting pipeline writes it for you from the site's swarm-assets policy. - When the game does a
GET(without aRangeheader) for a listed path, the runtime asks the swarm first: this machine's store, then the WebTorrent swarm the site's browser players share, then the native swarm with the site's content store as the web seed. - The bytes must match the entry's size and SHA-256. Then the game gets them, and the runtime seeds them to both swarms.
- Anything else is the game's ordinary request to the site: a path that is not listed, a site without a manifest, the swarm not ready within 3 seconds, a timeout, or a hash mismatch. The game behaves exactly as without the swarm.
Your code does not change: it is an ordinary sg_guest::Fetch::get.
let req = sg_guest::Fetch::get("https://mygame-play.0x.limo/sites/mygame/3/textures/rock.ktx2", &[]);
// poll req.state() each frame; then req.body()Who takes part. The 0x app turns this on for a signed-in player who shares content, and only
for sites served over https://. A signed-out player fetches from the site.
What you control. Which files are in the swarm manifest (the site's swarm-assets policy), and the fetch prefixes your manifest declares. You do not run a tracker or a seeder; 0x's web seed always has every file, so a file is never unavailable because no player has it.
