|
| 1 | + |
| 2 | +# Zzzync Spec Document |
| 3 | + |
| 4 | +This document is meant to provide clarity on zzzync as a protocol. |
| 5 | + |
| 6 | +Protocol Version: `1.0.0-beta` |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +<br/> |
| 11 | + |
| 12 | +## DCID |
| 13 | + |
| 14 | +DCID are a definition made by Zzzync and are not recognized as a separate format by IPFS. |
| 15 | +They are of the same format as CIDs but are created differently. |
| 16 | +DCID are created by taking the CID of a manifest/setup document for some dynamic content, then prefixing `'/dcoi/'` decoded utf-8 bytes to the CID multihash, and then hashing into a different CID. |
| 17 | + |
| 18 | +> 'dcoi' is an acronym meaning *dynamic content over ipfs* |
| 19 | +
|
| 20 | +DCID format: |
| 21 | + |
| 22 | +``` |
| 23 | +<0x01 (CIDv1)><0x55 (multicode raw)><sha256(<'/dcoi/' decoded utf-8><manifest CID multihash>)> |
| 24 | +``` |
| 25 | + |
| 26 | +--- |
| 27 | +> **Q:** Why not just use `<'/dcoi/' decoded utf-8><manifest CID multihash>` as the routing key. Why convert it back to a CID? |
| 28 | +
|
| 29 | +> **A:** The kad-dht api in javascript makes working with CIDs easier. As the protocol matures this may be changed. |
| 30 | +--- |
| 31 | + |
| 32 | +<br/> |
| 33 | + |
| 34 | +## PeerId |
| 35 | + |
| 36 | +A [PeerId](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md) is a Libp2p definition. |
| 37 | +They are used to identify nodes on the network and are made of a cryptographic keypair. |
| 38 | +They are unique to a device and must not be shared. |
| 39 | + |
| 40 | +<br/> |
| 41 | + |
| 42 | +## Advertisers |
| 43 | + |
| 44 | +Advertisers are used to point from a DCID to PeerIds. |
| 45 | +Advertisers can use any system to do so. |
| 46 | +There may be multiple advertisers to use and defined under this protocol and they can be used together. |
| 47 | + |
| 48 | +Advertisers need only re-advertise when the system requires it, to keep the advertisements available. |
| 49 | + |
| 50 | +### DHT Advertiser |
| 51 | + |
| 52 | +The DHT advertiser uses the IPFS DHT's Provider Records to point from DCIDs to PeerIds. |
| 53 | +Each record points to a different PeerId and records stay on the network for a maximum of 48hours. |
| 54 | + |
| 55 | +The `ADD_PROVIDER` query is used to advertise that a PeerId is the provider of a DCID. |
| 56 | +The `GET_PROVIDERS` query is used to discover PeerIds that are providing a DCID. |
| 57 | + |
| 58 | +The [IPFS DHT spec](https://github.com/libp2p/specs/tree/master/kad-dht) provides further information. |
| 59 | + |
| 60 | +<br/> |
| 61 | + |
| 62 | +## Namers |
| 63 | + |
| 64 | +Namers are used to point from a PeerId to a CID. |
| 65 | +The CID is the latest version of some dynamic content. |
| 66 | +Namers can use any system that provides verifiable guarantees of a mutable PeerId -> CID mapping. |
| 67 | +There may be multiple namers to use and defined under this protocol |
| 68 | + |
| 69 | +Namers need only republish after a change has been made to a local replica, changing its CID. |
| 70 | + |
| 71 | +### IPNS Namer |
| 72 | + |
| 73 | +The IPNS namer uses the Interplanetary Name System to resolve PeerIds to CIDs. |
| 74 | + |
| 75 | +[IPNS spec](https://specs.ipfs.tech/ipns/ipns-record/) |
| 76 | + |
| 77 | +IPNS Records have a value field which is encoded as bytes and can contain something other than a CID. |
| 78 | +For Zzzync's purpose there should only ever be IPFS path here, encoded utf-8. |
| 79 | +An immutable IPFS path is utf-8 encoded string that includes a multibase encoded CID with an `/ipfs/` prefix: |
| 80 | + |
| 81 | +``` |
| 82 | +/ipfs/<multibase encoded CID> |
| 83 | +``` |
| 84 | + |
| 85 | +### W3Name Namer |
| 86 | + |
| 87 | +The W3Name namer uses the W3Name system to resolve PeerIds to CIDs. |
| 88 | +W3Name system was built to be a substitute for IPNS. |
| 89 | + |
| 90 | +The design and records used are very similar so the IPNS Namer section on value field format also applies here. |
| 91 | + |
| 92 | +PeerIds are made of cryptographic keys. |
| 93 | +The private key of the PeerId being used must be used to sign the W3Name records. |
| 94 | + |
| 95 | +<br/> |
| 96 | + |
| 97 | +## Replication Protocol |
| 98 | + |
| 99 | +### Advertisement |
| 100 | + |
| 101 | +After a change has been made to a local replica and the replica data has been uploaded to another machine: |
| 102 | + |
| 103 | +1. Use Namer to publish device unique PeerId -> CID of replica. |
| 104 | +2. Use Advertiser to advertise DCID -> PeerId |
| 105 | + |
| 106 | +### Discovery |
| 107 | + |
| 108 | +1. Use Advertiser to query PeerIds for DCID. |
| 109 | +2. Use Namer for each PeerId to resolve replica CIDs. |
| 110 | + |
| 111 | +If the replica data for the CID has been uploaded to another machine offline replication can be completed. |
| 112 | + |
| 113 | +<br/> |
| 114 | + |
| 115 | +## Replica Hosts |
| 116 | + |
| 117 | +For offline discovery to be possible the records created by the Advertisers/Namers must be available. |
| 118 | +For offline replication the referenced replica data remain available. |
| 119 | +Without both offline collaboration cannot occur in this context. |
| 120 | + |
| 121 | +This document does not specify how data should be hosted for this purpose. |
| 122 | +It only specifies how to advertise and discover the latest versions for some dynamic content. |
0 commit comments