| 68 | | The P2P sync component '''must''' authenticate peers, or allow the user to authenticate them, before granting them access to data. If a destination server has been configured, the P2P sync component '''must''' authenticate the destination server before granting it access to data. If a delivery confirmation from a destination server is received, either directly from the server itself or from a peer, the P2P sync component '''must''' authenticate the delivery confirmation before acting on it or synchronizing it with peers. |
| | 68 | The P2P sync component '''must''' authenticate peers, or allow the user to authenticate them, before granting them access to data. If a destination server has been configured, the P2P sync component '''must''' authenticate the destination server before granting it access to data. |
| | 69 | |
| | 70 | If a delivery confirmation from a destination server is received, either directly from the server itself or from a peer, the P2P sync component '''must''' authenticate the delivery confirmation before acting on it or synchronizing it with peers. |
| | 71 | |
| | 72 | To protect the privacy of data subjects, the P2P sync component '''may''' encrypt data before synchronizing it with peers, such that it can only be decrypted by the destination server. |
| 87 | | <Where relevant include alternative design options> |
| | 92 | There are two design options: |
| | 93 | |
| | 94 | ==== 1. Synchronize immutable documents ==== |
| | 95 | |
| | 96 | In this option, the data to be synced consists of immutable documents, each of which originates on one mobile device and is synced to other devices without being modified. Examples of immutable documents might include a completed form or a photo. |
| | 97 | |
| | 98 | Detecting and resolving conflicts is simple in this option: each data item is identified by its cryptographic hash, which ensures that if two items have the same identifier then they also contain the same data. |
| | 99 | |
| | 100 | This option also makes it simple for data to be encrypted on the originating device and decrypted on the destination server. |
| | 101 | |
| | 102 | The destination server confirms delivery of an immutable document by creating a delivery confirmation containing the document's identifier, signed with the server's OpenPGP key. The confirmation can be synced between mobile devices, which can delete the confirmed document if they no longer need a local copy. |
| | 103 | |
| | 104 | ==== 2. Synchronize changes to database records ==== |
| | 105 | |
| | 106 | In this option, the data to be synced consists of database records that may be modified independently on any device. This provides maximum flexibility for the application, as anything stored in the database can potentially be synced, but it also requires the application to handle conflicts that may arise from concurrent modification of a given record on multiple devices. |
| | 107 | |
| | 108 | Detecting and resolving conflicts in this option follows a similar approach to [http://docs.couchdb.org/en/2.0.0/intro/consistency.html CouchDB]. Non-conflicting updates are applied automatically. If a conflict occurs, the P2P sync component stores all conflicting versions of the record and asks the application to resolve the conflict, which may require user intervention, either on the mobile device or on the destination server. |
| | 109 | |
| | 110 | This option allows individual database fields to be encrypted on the originating device and decrypted on the destination server, but if a conflict occurs in an encrypted field it may not be possible to resolve it intelligently on the mobile device. |
| | 111 | |
| | 112 | The destination server confirms delivery of a record by creating a delivery confirmation containing the record's identifier and [https://wiki.apache.org/couchdb/Replication_and_conflicts revision], signed with the server's OpenPGP key. The confirmation can be synced between mobile devices, which can delete the confirmed record if they are storing the same revision and no longer need a local copy. Multiple revisions of a given record may be confirmed by the destination server. |