A local-first private AI assistant for everyday use. Runs on-device models with encrypted P2P sync, and supports sharing chats publicly on ATProto.
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'main' into feat/chat-sync

madclaws 7a3ec466 ed66c0a0

+852 -365
+8
.cursor/hooks/state/continual-learning.json
··· 1 + { 2 + "version": 1, 3 + "lastRunAtMs": 0, 4 + "turnsSinceLastRun": 1, 5 + "lastTranscriptMtimeMs": null, 6 + "lastProcessedGenerationId": "5552c716-dda2-45ab-b6e5-ebc72a547b48", 7 + "trialStartedAtMs": null 8 + }
+14
CHANGELOG.md
··· 5 5 6 6 ## [Unreleased] 7 7 8 + ## [0.4.5] - 2026-03-23 9 + 10 + ### Added 11 + - Added P2P device linking v1 in [#106](https://github.com/tilesprivacy/tiles/pull/106). 12 + - Works both online and in offline networks 13 + - Utility Commands for device linking 14 + - `tiles link enable` - creates the ticket and listens for an link requests 15 + - `tiles link enable <ticket>`- Device that need to join will run this command with the ticket from the sender. **NOTE**: The ticket sharing is out-of-band. 16 + - `tiles link list-peers` - Shows the info (DID, nickname etc) of the linked devices. 17 + - `tiles link disable <DID>` - Unlinks a linked device 18 + 19 + ### Fixed 20 + - Fixed the permission issues while trying to update Tiles using `tiles update` in [$104](https://github.com/tilesprivacy/tiles/pull/104). This was due to new binary location is in `/usr/` instead of `~/.local/`. Running the internal script with `sudo` fixed it. 21 + 8 22 ## [0.4.4] - 2026-03-16 9 23 10 24 ### Added
+40 -3
Cargo.lock
··· 3 3 version = 4 4 4 5 5 [[package]] 6 + name = "acto" 7 + version = "0.8.0" 8 + source = "registry+https://github.com/rust-lang/crates.io-index" 9 + checksum = "148541f13c28e3e840354ee4d6c99046c10be2c81068bbd23b9e3a38f95a917e" 10 + dependencies = [ 11 + "parking_lot", 12 + "pin-project-lite", 13 + "rustc_version", 14 + "smol_str", 15 + "sync_wrapper", 16 + "tokio", 17 + "tracing", 18 + ] 19 + 20 + [[package]] 6 21 name = "adler2" 7 22 version = "2.0.1" 8 23 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 3097 3112 "serde", 3098 3113 "smallvec", 3099 3114 "strum", 3115 + "swarm-discovery", 3100 3116 "sync_wrapper", 3101 3117 "time", 3102 3118 "tokio", ··· 5289 5305 5290 5306 [[package]] 5291 5307 name = "rustls-webpki" 5292 - version = "0.103.9" 5308 + version = "0.103.10" 5293 5309 source = "registry+https://github.com/rust-lang/crates.io-index" 5294 - checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" 5310 + checksum = "df33b2b81ac578cabaf06b89b0631153a3f416b0a886e8a7a1707fb51abbd1ef" 5295 5311 dependencies = [ 5296 5312 "ring", 5297 5313 "rustls-pki-types", ··· 5731 5747 checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" 5732 5748 5733 5749 [[package]] 5750 + name = "smol_str" 5751 + version = "0.1.24" 5752 + source = "registry+https://github.com/rust-lang/crates.io-index" 5753 + checksum = "fad6c857cbab2627dcf01ec85a623ca4e7dcb5691cbaa3d7fb7653671f0d09c9" 5754 + 5755 + [[package]] 5734 5756 name = "snap" 5735 5757 version = "1.1.1" 5736 5758 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 5875 5897 version = "2.6.1" 5876 5898 source = "registry+https://github.com/rust-lang/crates.io-index" 5877 5899 checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" 5900 + 5901 + [[package]] 5902 + name = "swarm-discovery" 5903 + version = "0.5.0" 5904 + source = "registry+https://github.com/rust-lang/crates.io-index" 5905 + checksum = "1a5ab62937edac8b23fa40e55a358ea1924245b17fc1eb20d14929c8f11be98d" 5906 + dependencies = [ 5907 + "acto", 5908 + "hickory-proto", 5909 + "rand 0.9.2", 5910 + "socket2 0.6.3", 5911 + "thiserror 2.0.18", 5912 + "tokio", 5913 + "tracing", 5914 + ] 5878 5915 5879 5916 [[package]] 5880 5917 name = "syn" ··· 6047 6084 6048 6085 [[package]] 6049 6086 name = "tiles" 6050 - version = "0.4.4" 6087 + version = "0.4.5" 6051 6088 dependencies = [ 6052 6089 "anyhow", 6053 6090 "async-std",
+201
LICENSE-APACHE
··· 1 + Apache License 2 + Version 2.0, January 2004 3 + http://www.apache.org/licenses/ 4 + 5 + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 + 7 + 1. Definitions. 8 + 9 + "License" shall mean the terms and conditions for use, reproduction, 10 + and distribution as defined by Sections 1 through 9 of this document. 11 + 12 + "Licensor" shall mean the copyright owner or entity authorized by 13 + the copyright owner that is granting the License. 14 + 15 + "Legal Entity" shall mean the union of the acting entity and all 16 + other entities that control, are controlled by, or are under common 17 + control with that entity. For the purposes of this definition, 18 + "control" means (i) the power, direct or indirect, to cause the 19 + direction or management of such entity, whether by contract or 20 + otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 + outstanding shares, or (iii) beneficial ownership of such entity. 22 + 23 + "You" (or "Your") shall mean an individual or Legal Entity 24 + exercising permissions granted by this License. 25 + 26 + "Source" form shall mean the preferred form for making modifications, 27 + including but not limited to software source code, documentation 28 + source, and configuration files. 29 + 30 + "Object" form shall mean any form resulting from mechanical 31 + transformation or translation of a Source form, including but 32 + not limited to compiled object code, generated documentation, 33 + and conversions to other media types. 34 + 35 + "Work" shall mean the work of authorship, whether in Source or 36 + Object form, made available under the License, as indicated by a 37 + copyright notice that is included in or attached to the work 38 + (an example is provided in the Appendix below). 39 + 40 + "Derivative Works" shall mean any work, whether in Source or Object 41 + form, that is based on (or derived from) the Work and for which the 42 + editorial revisions, annotations, elaborations, or other modifications 43 + represent, as a whole, an original work of authorship. For the purposes 44 + of this License, Derivative Works shall not include works that remain 45 + separable from, or merely link (or bind by name) to the interfaces of, 46 + the Work and Derivative Works thereof. 47 + 48 + "Contribution" shall mean any work of authorship, including 49 + the original version of the Work and any modifications or additions 50 + to that Work or Derivative Works thereof, that is intentionally 51 + submitted to Licensor for inclusion in the Work by the copyright owner 52 + or by an individual or Legal Entity authorized to submit on behalf of 53 + the copyright owner. For the purposes of this definition, "submitted" 54 + means any form of electronic, verbal, or written communication sent 55 + to the Licensor or its representatives, including but not limited to 56 + communication on electronic mailing lists, source code control systems, 57 + and issue tracking systems that are managed by, or on behalf of, the 58 + Licensor for the purpose of discussing and improving the Work, but 59 + excluding communication that is conspicuously marked or otherwise 60 + designated in writing by the copyright owner as "Not a Contribution." 61 + 62 + "Contributor" shall mean Licensor and any individual or Legal Entity 63 + on behalf of whom a Contribution has been received by Licensor and 64 + subsequently incorporated within the Work. 65 + 66 + 2. Grant of Copyright License. Subject to the terms and conditions of 67 + this License, each Contributor hereby grants to You a perpetual, 68 + worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 + copyright license to reproduce, prepare Derivative Works of, 70 + publicly display, publicly perform, sublicense, and distribute the 71 + Work and such Derivative Works in Source or Object form. 72 + 73 + 3. Grant of Patent License. Subject to the terms and conditions of 74 + this License, each Contributor hereby grants to You a perpetual, 75 + worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 + (except as stated in this section) patent license to make, have made, 77 + use, offer to sell, sell, import, and otherwise transfer the Work, 78 + where such license applies only to those patent claims licensable 79 + by such Contributor that are necessarily infringed by their 80 + Contribution(s) alone or by combination of their Contribution(s) 81 + with the Work to which such Contribution(s) was submitted. If You 82 + institute patent litigation against any entity (including a 83 + cross-claim or counterclaim in a lawsuit) alleging that the Work 84 + or a Contribution incorporated within the Work constitutes direct 85 + or contributory patent infringement, then any patent licenses 86 + granted to You under this License for that Work shall terminate 87 + as of the date such litigation is filed. 88 + 89 + 4. Redistribution. You may reproduce and distribute copies of the 90 + Work or Derivative Works thereof in any medium, with or without 91 + modifications, and in Source or Object form, provided that You 92 + meet the following conditions: 93 + 94 + (a) You must give any other recipients of the Work or 95 + Derivative Works a copy of this License; and 96 + 97 + (b) You must cause any modified files to carry prominent notices 98 + stating that You changed the files; and 99 + 100 + (c) You must retain, in the Source form of any Derivative Works 101 + that You distribute, all copyright, patent, trademark, and 102 + attribution notices from the Source form of the Work, 103 + excluding those notices that do not pertain to any part of 104 + the Derivative Works; and 105 + 106 + (d) If the Work includes a "NOTICE" text file as part of its 107 + distribution, then any Derivative Works that You distribute must 108 + include a readable copy of the attribution notices contained 109 + within such NOTICE file, excluding those notices that do not 110 + pertain to any part of the Derivative Works, in at least one 111 + of the following places: within a NOTICE text file distributed 112 + as part of the Derivative Works; within the Source form or 113 + documentation, if provided along with the Derivative Works; or, 114 + within a display generated by the Derivative Works, if and 115 + wherever such third-party notices normally appear. The contents 116 + of the NOTICE file are for informational purposes only and 117 + do not modify the License. You may add Your own attribution 118 + notices within Derivative Works that You distribute, alongside 119 + or as an addendum to the NOTICE text from the Work, provided 120 + that such additional attribution notices cannot be construed 121 + as modifying the License. 122 + 123 + You may add Your own copyright statement to Your modifications and 124 + may provide additional or different license terms and conditions 125 + for use, reproduction, or distribution of Your modifications, or 126 + for any such Derivative Works as a whole, provided Your use, 127 + reproduction, and distribution of the Work otherwise complies with 128 + the conditions stated in this License. 129 + 130 + 5. Submission of Contributions. Unless You explicitly state otherwise, 131 + any Contribution intentionally submitted for inclusion in the Work 132 + by You to the Licensor shall be under the terms and conditions of 133 + this License, without any additional terms or conditions. 134 + Notwithstanding the above, nothing herein shall supersede or modify 135 + the terms of any separate license agreement you may have executed 136 + with Licensor regarding such Contributions. 137 + 138 + 6. Trademarks. This License does not grant permission to use the trade 139 + names, trademarks, service marks, or product names of the Licensor, 140 + except as required for reasonable and customary use in describing the 141 + origin of the Work and reproducing the content of the NOTICE file. 142 + 143 + 7. Disclaimer of Warranty. Unless required by applicable law or 144 + agreed to in writing, Licensor provides the Work (and each 145 + Contributor provides its Contributions) on an "AS IS" BASIS, 146 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 + implied, including, without limitation, any warranties or conditions 148 + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 + PARTICULAR PURPOSE. You are solely responsible for determining the 150 + appropriateness of using or redistributing the Work and assume any 151 + risks associated with Your exercise of permissions under this License. 152 + 153 + 8. Limitation of Liability. In no event and under no legal theory, 154 + whether in tort (including negligence), contract, or otherwise, 155 + unless required by applicable law (such as deliberate and grossly 156 + negligent acts) or agreed to in writing, shall any Contributor be 157 + liable to You for damages, including any direct, indirect, special, 158 + incidental, or consequential damages of any character arising as a 159 + result of this License or out of the use or inability to use the 160 + Work (including but not limited to damages for loss of goodwill, 161 + work stoppage, computer failure or malfunction, or any and all 162 + other commercial damages or losses), even if such Contributor 163 + has been advised of the possibility of such damages. 164 + 165 + 9. Accepting Warranty or Additional Liability. While redistributing 166 + the Work or Derivative Works thereof, You may choose to offer, 167 + and charge a fee for, acceptance of support, warranty, indemnity, 168 + or other liability obligations and/or rights consistent with this 169 + License. However, in accepting such obligations, You may act only 170 + on Your own behalf and on Your sole responsibility, not on behalf 171 + of any other Contributor, and only if You agree to indemnify, 172 + defend, and hold each Contributor harmless for any liability 173 + incurred by, or claims asserted against, such Contributor by reason 174 + of your accepting any such warranty or additional liability. 175 + 176 + END OF TERMS AND CONDITIONS 177 + 178 + APPENDIX: How to apply the Apache License to your work. 179 + 180 + To apply the Apache License to your work, attach the following 181 + boilerplate notice, with the fields enclosed by brackets "[]" 182 + replaced with your own identifying information. (Don't include 183 + the brackets!) The text should be enclosed in the appropriate 184 + comment syntax for the file format. We also recommend that a 185 + file or class name and description of purpose be included on the 186 + same "printed page" as the copyright notice for easier 187 + identification within third-party archives. 188 + 189 + Copyright (c) 2026 Tiles Privacy & Contributors 190 + 191 + Licensed under the Apache License, Version 2.0 (the "License"); 192 + you may not use this file except in compliance with the License. 193 + You may obtain a copy of the License at 194 + 195 + http://www.apache.org/licenses/LICENSE-2.0 196 + 197 + Unless required by applicable law or agreed to in writing, software 198 + distributed under the License is distributed on an "AS IS" BASIS, 199 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 + See the License for the specific language governing permissions and 201 + limitations under the License.
-202
LICENSE-APACHE.txt
··· 1 - 2 - Apache License 3 - Version 2.0, January 2004 4 - http://www.apache.org/licenses/ 5 - 6 - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 - 8 - 1. Definitions. 9 - 10 - "License" shall mean the terms and conditions for use, reproduction, 11 - and distribution as defined by Sections 1 through 9 of this document. 12 - 13 - "Licensor" shall mean the copyright owner or entity authorized by 14 - the copyright owner that is granting the License. 15 - 16 - "Legal Entity" shall mean the union of the acting entity and all 17 - other entities that control, are controlled by, or are under common 18 - control with that entity. For the purposes of this definition, 19 - "control" means (i) the power, direct or indirect, to cause the 20 - direction or management of such entity, whether by contract or 21 - otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 - outstanding shares, or (iii) beneficial ownership of such entity. 23 - 24 - "You" (or "Your") shall mean an individual or Legal Entity 25 - exercising permissions granted by this License. 26 - 27 - "Source" form shall mean the preferred form for making modifications, 28 - including but not limited to software source code, documentation 29 - source, and configuration files. 30 - 31 - "Object" form shall mean any form resulting from mechanical 32 - transformation or translation of a Source form, including but 33 - not limited to compiled object code, generated documentation, 34 - and conversions to other media types. 35 - 36 - "Work" shall mean the work of authorship, whether in Source or 37 - Object form, made available under the License, as indicated by a 38 - copyright notice that is included in or attached to the work 39 - (an example is provided in the Appendix below). 40 - 41 - "Derivative Works" shall mean any work, whether in Source or Object 42 - form, that is based on (or derived from) the Work and for which the 43 - editorial revisions, annotations, elaborations, or other modifications 44 - represent, as a whole, an original work of authorship. For the purposes 45 - of this License, Derivative Works shall not include works that remain 46 - separable from, or merely link (or bind by name) to the interfaces of, 47 - the Work and Derivative Works thereof. 48 - 49 - "Contribution" shall mean any work of authorship, including 50 - the original version of the Work and any modifications or additions 51 - to that Work or Derivative Works thereof, that is intentionally 52 - submitted to Licensor for inclusion in the Work by the copyright owner 53 - or by an individual or Legal Entity authorized to submit on behalf of 54 - the copyright owner. For the purposes of this definition, "submitted" 55 - means any form of electronic, verbal, or written communication sent 56 - to the Licensor or its representatives, including but not limited to 57 - communication on electronic mailing lists, source code control systems, 58 - and issue tracking systems that are managed by, or on behalf of, the 59 - Licensor for the purpose of discussing and improving the Work, but 60 - excluding communication that is conspicuously marked or otherwise 61 - designated in writing by the copyright owner as "Not a Contribution." 62 - 63 - "Contributor" shall mean Licensor and any individual or Legal Entity 64 - on behalf of whom a Contribution has been received by Licensor and 65 - subsequently incorporated within the Work. 66 - 67 - 2. Grant of Copyright License. Subject to the terms and conditions of 68 - this License, each Contributor hereby grants to You a perpetual, 69 - worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 - copyright license to reproduce, prepare Derivative Works of, 71 - publicly display, publicly perform, sublicense, and distribute the 72 - Work and such Derivative Works in Source or Object form. 73 - 74 - 3. Grant of Patent License. Subject to the terms and conditions of 75 - this License, each Contributor hereby grants to You a perpetual, 76 - worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 - (except as stated in this section) patent license to make, have made, 78 - use, offer to sell, sell, import, and otherwise transfer the Work, 79 - where such license applies only to those patent claims licensable 80 - by such Contributor that are necessarily infringed by their 81 - Contribution(s) alone or by combination of their Contribution(s) 82 - with the Work to which such Contribution(s) was submitted. If You 83 - institute patent litigation against any entity (including a 84 - cross-claim or counterclaim in a lawsuit) alleging that the Work 85 - or a Contribution incorporated within the Work constitutes direct 86 - or contributory patent infringement, then any patent licenses 87 - granted to You under this License for that Work shall terminate 88 - as of the date such litigation is filed. 89 - 90 - 4. Redistribution. You may reproduce and distribute copies of the 91 - Work or Derivative Works thereof in any medium, with or without 92 - modifications, and in Source or Object form, provided that You 93 - meet the following conditions: 94 - 95 - (a) You must give any other recipients of the Work or 96 - Derivative Works a copy of this License; and 97 - 98 - (b) You must cause any modified files to carry prominent notices 99 - stating that You changed the files; and 100 - 101 - (c) You must retain, in the Source form of any Derivative Works 102 - that You distribute, all copyright, patent, trademark, and 103 - attribution notices from the Source form of the Work, 104 - excluding those notices that do not pertain to any part of 105 - the Derivative Works; and 106 - 107 - (d) If the Work includes a "NOTICE" text file as part of its 108 - distribution, then any Derivative Works that You distribute must 109 - include a readable copy of the attribution notices contained 110 - within such NOTICE file, excluding those notices that do not 111 - pertain to any part of the Derivative Works, in at least one 112 - of the following places: within a NOTICE text file distributed 113 - as part of the Derivative Works; within the Source form or 114 - documentation, if provided along with the Derivative Works; or, 115 - within a display generated by the Derivative Works, if and 116 - wherever such third-party notices normally appear. The contents 117 - of the NOTICE file are for informational purposes only and 118 - do not modify the License. You may add Your own attribution 119 - notices within Derivative Works that You distribute, alongside 120 - or as an addendum to the NOTICE text from the Work, provided 121 - that such additional attribution notices cannot be construed 122 - as modifying the License. 123 - 124 - You may add Your own copyright statement to Your modifications and 125 - may provide additional or different license terms and conditions 126 - for use, reproduction, or distribution of Your modifications, or 127 - for any such Derivative Works as a whole, provided Your use, 128 - reproduction, and distribution of the Work otherwise complies with 129 - the conditions stated in this License. 130 - 131 - 5. Submission of Contributions. Unless You explicitly state otherwise, 132 - any Contribution intentionally submitted for inclusion in the Work 133 - by You to the Licensor shall be under the terms and conditions of 134 - this License, without any additional terms or conditions. 135 - Notwithstanding the above, nothing herein shall supersede or modify 136 - the terms of any separate license agreement you may have executed 137 - with Licensor regarding such Contributions. 138 - 139 - 6. Trademarks. This License does not grant permission to use the trade 140 - names, trademarks, service marks, or product names of the Licensor, 141 - except as required for reasonable and customary use in describing the 142 - origin of the Work and reproducing the content of the NOTICE file. 143 - 144 - 7. Disclaimer of Warranty. Unless required by applicable law or 145 - agreed to in writing, Licensor provides the Work (and each 146 - Contributor provides its Contributions) on an "AS IS" BASIS, 147 - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 - implied, including, without limitation, any warranties or conditions 149 - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 - PARTICULAR PURPOSE. You are solely responsible for determining the 151 - appropriateness of using or redistributing the Work and assume any 152 - risks associated with Your exercise of permissions under this License. 153 - 154 - 8. Limitation of Liability. In no event and under no legal theory, 155 - whether in tort (including negligence), contract, or otherwise, 156 - unless required by applicable law (such as deliberate and grossly 157 - negligent acts) or agreed to in writing, shall any Contributor be 158 - liable to You for damages, including any direct, indirect, special, 159 - incidental, or consequential damages of any character arising as a 160 - result of this License or out of the use or inability to use the 161 - Work (including but not limited to damages for loss of goodwill, 162 - work stoppage, computer failure or malfunction, or any and all 163 - other commercial damages or losses), even if such Contributor 164 - has been advised of the possibility of such damages. 165 - 166 - 9. Accepting Warranty or Additional Liability. While redistributing 167 - the Work or Derivative Works thereof, You may choose to offer, 168 - and charge a fee for, acceptance of support, warranty, indemnity, 169 - or other liability obligations and/or rights consistent with this 170 - License. However, in accepting such obligations, You may act only 171 - on Your own behalf and on Your sole responsibility, not on behalf 172 - of any other Contributor, and only if You agree to indemnify, 173 - defend, and hold each Contributor harmless for any liability 174 - incurred by, or claims asserted against, such Contributor by reason 175 - of your accepting any such warranty or additional liability. 176 - 177 - END OF TERMS AND CONDITIONS 178 - 179 - APPENDIX: How to apply the Apache License to your work. 180 - 181 - To apply the Apache License to your work, attach the following 182 - boilerplate notice, with the fields enclosed by brackets "[]" 183 - replaced with your own identifying information. (Don't include 184 - the brackets!) The text should be enclosed in the appropriate 185 - comment syntax for the file format. We also recommend that a 186 - file or class name and description of purpose be included on the 187 - same "printed page" as the copyright notice for easier 188 - identification within third-party archives. 189 - 190 - Copyright [yyyy] [name of copyright owner] 191 - 192 - Licensed under the Apache License, Version 2.0 (the "License"); 193 - you may not use this file except in compliance with the License. 194 - You may obtain a copy of the License at 195 - 196 - http://www.apache.org/licenses/LICENSE-2.0 197 - 198 - Unless required by applicable law or agreed to in writing, software 199 - distributed under the License is distributed on an "AS IS" BASIS, 200 - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 - See the License for the specific language governing permissions and 202 - limitations under the License.
+25
LICENSE-MIT
··· 1 + Copyright (c) 2026 Tiles Privacy & Contributors 2 + 3 + Permission is hereby granted, free of charge, to any 4 + person obtaining a copy of this software and associated 5 + documentation files (the "Software"), to deal in the 6 + Software without restriction, including without 7 + limitation the rights to use, copy, modify, merge, 8 + publish, distribute, sublicense, and/or sell copies of 9 + the Software, and to permit persons to whom the Software 10 + is furnished to do so, subject to the following 11 + conditions: 12 + 13 + The above copyright notice and this permission notice 14 + shall be included in all copies or substantial portions 15 + of the Software. 16 + 17 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 + ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 + TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 + PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 + SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 + IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 + DEALINGS IN THE SOFTWARE.
-19
LICENSE-MIT.txt
··· 1 - MIT License 2 - 3 - Permission is hereby granted, free of charge, to any person obtaining a copy 4 - of this software and associated documentation files (the "Software"), to deal 5 - in the Software without restriction, including without limitation the rights 6 - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 - copies of the Software, and to permit persons to whom the Software is 8 - furnished to do so, subject to the following conditions: 9 - 10 - The above copyright notice and this permission notice shall be included in all 11 - copies or substantial portions of the Software. 12 - 13 - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 - SOFTWARE.
+7 -13
README.md
··· 28 28 29 29 ## Tiles CLI 30 30 31 - The CLI is the fastest way to get started and will feel familiar if you have used tools like Ollama or LM Studio. 31 + Tiles is the private and secure AI assistant for everyday use. It will feel familiar if you have used tools like Ollama or LM Studio. 32 32 33 33 Install the signed macOS package: 34 34 35 - https://download.tiles.run/tiles-0.4.3-signed.pkg 35 + https://tiles.run/download 36 36 37 - Then run: 37 + Then run the following command to start Tiles: 38 38 39 39 ```bash 40 40 tiles ··· 44 44 45 45 Tilekit is a Rust-based SDK for customizing local models and agent experiences within Tiles. 46 46 47 - It provides: 48 - - Modelfile specification and tooling for working with models 49 - - Fast, efficient local deployment of models across consumer platforms 50 - - Built on open source specifications such as Open Responses API 51 - - Model composition and chaining, with MIR support currently in development 52 - 53 47 ## Documentation 54 48 55 49 Full documentation is available in the Tiles Book: ··· 59 53 60 54 Our mission is to bring privacy technology to everyone. 61 55 62 - Tiles Privacy emerged from the [User & Agents](https://userandagents.com) community with a simple principle: software should understand you without taking anything from you. 56 + Tiles Privacy was born from the [User & Agents](https://userandagents.com) community with a simple idea: software should understand you without taking anything from you. 63 57 64 58 We strive to deliver the best privacy-focused engineering while also offering unmatched convenience in our consumer products. We believe identity and memory belong together, and Tiles gives you a way to own both through your personal user agent. 65 59 66 60 Tiles is built for privacy conscious users who want intelligence without renting their memory to centralized providers. 67 61 68 - We are seeking design partners for TEE based cloud workloads that align with our goal of a verifiable privacy perimeter. Contact us at hello@tiles.run. 62 + We are seeking design partners for TEE based cloud workloads that align with our goal of a verifiable privacy perimeter. Contact us at [mail@tiles.run](mailto:mail@tiles.run). 69 63 70 64 ## Contributing 71 65 ··· 79 73 80 74 This project is dual-licensed under MIT and Apache 2.0: 81 75 82 - - [MIT License](https://github.com/tilesprivacy/tiles/blob/main/LICENSE-MIT.txt) 83 - - [Apache License 2.0](https://github.com/tilesprivacy/tiles/blob/main/LICENSE-APACHE.txt) 76 + - [MIT License](https://github.com/tilesprivacy/tiles/blob/main/LICENSE-MIT) 77 + - [Apache License 2.0](https://github.com/tilesprivacy/tiles/blob/main/LICENSE-APACHE) 84 78 85 79 You may choose either license, or both. Apache 2.0 is included for its explicit patent protections.
+1 -1
scripts/install.sh
··· 5 5 REPO="tilesprivacy/tiles" 6 6 # VERSION=$(grep '^version' tiles/Cargo.toml | head -1 | awk -F'"' '{print $2}') 7 7 8 - VERSION="0.4.4" 8 + VERSION="0.4.5" 9 9 INSTALL_DIR="/usr/local/bin" # CLI install location 10 10 11 11 SERVER_DIR="/usr/local/share/tiles/server" # Python server folder
+1 -1
server/stack/requirements/app-server/packages-app-server.txt
··· 23 23 packaging==26.0 24 24 pathspec==1.0.4 25 25 platformdirs==4.9.4 26 - protobuf==7.34.0 26 + protobuf==7.34.1 27 27 pydantic==2.12.5 28 28 pydantic-core==2.41.5 29 29 pytokens==0.4.1
+2 -2
server/stack/requirements/app-server/pylock.app-server.meta.json
··· 1 1 { 2 2 "lock_input_hash": "sha256:c836d5cfb697330a57241b2b8f275a804178488ec906b19866809ef33c95ba81", 3 3 "lock_version": 1, 4 - "locked_at": "2026-03-15T22:15:15.536434+00:00", 4 + "locked_at": "2026-03-22T21:45:51.270370+00:00", 5 5 "other_inputs_hash": "sha256:63b3c2cfe2ec414938e81dace7aac779c7b902bae681618cd8827e9f16880985", 6 - "requirements_hash": "sha256:71fb833c54864760da900c69c2a0829e19fef2c6b6e8c174162fdb7f021a4eb3", 6 + "requirements_hash": "sha256:167a9044a762af6b1b0b26589b77a245bf351a3b74860bc9f1bc6a07053a48a7", 7 7 "version_inputs_hash": "sha256:58db986b7cd72eeded675f7c9afd8138fe024fb51451131b5562922bbde3cf43" 8 8 }
+13 -13
server/stack/requirements/app-server/pylock.app-server.toml
··· 508 508 509 509 [[packages]] 510 510 name = "protobuf" 511 - version = "7.34.0" 511 + version = "7.34.1" 512 512 index = "https://pypi.org/simple" 513 513 514 514 [[packages.wheels]] 515 - url = "https://files.pythonhosted.org/packages/13/c4/6322ab5c8f279c4c358bc14eb8aefc0550b97222a39f04eb3c1af7a830fa/protobuf-7.34.0-cp310-abi3-macosx_10_9_universal2.whl" 516 - upload-time = 2026-02-27T00:30:14Z 517 - size = 429248 515 + url = "https://files.pythonhosted.org/packages/ec/11/3325d41e6ee15bf1125654301211247b042563bcc898784351252549a8ad/protobuf-7.34.1-cp310-abi3-macosx_10_9_universal2.whl" 516 + upload-time = 2026-03-20T17:34:37Z 517 + size = 429247 518 518 519 519 [packages.wheels.hashes] 520 - sha256 = "8e329966799f2c271d5e05e236459fe1cbfdb8755aaa3b0914fa60947ddea408" 520 + sha256 = "d8b2cc79c4d8f62b293ad9b11ec3aebce9af481fa73e64556969f7345ebf9fc7" 521 521 522 522 [[packages.wheels]] 523 - url = "https://files.pythonhosted.org/packages/b5/57/89727baef7578897af5ed166735ceb315819f1c184da8c3441271dbcfde7/protobuf-7.34.0-cp310-abi3-manylinux2014_x86_64.whl" 524 - upload-time = 2026-02-27T00:30:20Z 525 - size = 324268 523 + url = "https://files.pythonhosted.org/packages/53/1b/3b431694a4dc6d37b9f653f0c64b0a0d9ec074ee810710c0c3da21d67ba7/protobuf-7.34.1-cp310-abi3-manylinux2014_x86_64.whl" 524 + upload-time = 2026-03-20T17:34:41Z 525 + size = 324267 526 526 527 527 [packages.wheels.hashes] 528 - sha256 = "964cf977e07f479c0697964e83deda72bcbc75c3badab506fb061b352d991b01" 528 + sha256 = "8ff40ce8cd688f7265326b38d5a1bed9bfdf5e6723d49961432f83e21d5713e4" 529 529 530 530 [[packages.wheels]] 531 - url = "https://files.pythonhosted.org/packages/a4/e7/14dc9366696dcb53a413449881743426ed289d687bcf3d5aee4726c32ebb/protobuf-7.34.0-py3-none-any.whl" 532 - upload-time = 2026-02-27T00:30:23Z 533 - size = 170716 531 + url = "https://files.pythonhosted.org/packages/88/95/608f665226bca68b736b79e457fded9a2a38c4f4379a4a7614303d9db3bc/protobuf-7.34.1-py3-none-any.whl" 532 + upload-time = 2026-03-20T17:34:45Z 533 + size = 170715 534 534 535 535 [packages.wheels.hashes] 536 - sha256 = "e3b914dd77fa33fa06ab2baa97937746ab25695f389869afdf03e81f34e45dc7" 536 + sha256 = "bb3812cd53aefea2b028ef42bd780f5b96407247f20c6ef7c679807e9d188f11" 537 537 538 538 [[packages]] 539 539 name = "pydantic"
+7 -1
tilekit/src/accounts.rs
··· 35 35 /// 36 36 /// - `app`- The service for which Identity is made (for ex: tiles) 37 37 /// - `did` - The `Identity` of the service 38 - pub fn get_secret_key(app: &str, did: &Identity) -> Result<SecretKey> { 38 + pub fn get_secret_key(app: &str, did: &str) -> Result<SecretKey> { 39 39 let entry = Entry::new(app, did)?; 40 40 let mut bytes: [u8; 64] = [0u8; 64]; 41 41 let secret_pair = entry.get_secret()?; ··· 60 60 61 61 pub fn get_random_bytes() -> [u8; 16] { 62 62 let mut value = [0u8; 16]; 63 + OsRng.fill_bytes(&mut value); 64 + value 65 + } 66 + 67 + pub fn get_random_bytes_32() -> [u8; 32] { 68 + let mut value = [0u8; 32]; 63 69 OsRng.fill_bytes(&mut value); 64 70 value 65 71 }
+2 -2
tiles/Cargo.toml
··· 1 1 [package] 2 2 name = "tiles" 3 - version = "0.4.4" 3 + version = "0.4.5" 4 4 edition = "2024" 5 5 6 6 [dependencies] ··· 21 21 rusqlite_migration = "2.4.1" 22 22 uuid = {version = "1.21.0", features = ["v7"]} 23 23 axum = "0.8.8" 24 - iroh = "0.97.0" 24 + iroh = {version = "0.97.0", features = ["address-lookup-mdns"]} 25 25 iroh-ping = "0.9.0" 26 26 iroh-tickets = "0.4.0" 27 27 axum-macros = "0.5.0"
+26 -2
tiles/src/commands/mod.rs
··· 6 6 use owo_colors::OwoColorize; 7 7 use tiles::core; 8 8 use tiles::core::accounts::{ 9 - RootUser, create_root_account, get_root_user_details, save_root_account, set_nickname, 9 + RootUser, create_root_account, get_peer_list, get_root_user_details, save_root_account, 10 + set_nickname, unlink, 10 11 }; 12 + use tiles::core::storage::db::get_db_conn; 11 13 use tiles::runtime::Runtime; 12 14 use tiles::utils::config::{ 13 15 ConfigProvider, DefaultProvider, get_or_create_config, set_user_data_path, ··· 253 255 } 254 256 255 257 pub async fn run(runtime: &Runtime, run_args: RunArgs) -> Result<()> { 256 - core::init().inspect_err(|e| eprintln!("Tiles core init failed due to {:?}", e))?; 257 258 runtime.run(run_args).await 258 259 } 259 260 ··· 335 336 "Local Identity not created yet, use {}", 336 337 "tiles account create".yellow() 337 338 ) 339 + } 340 + 341 + pub fn show_peers() -> Result<()> { 342 + let db_conn = get_db_conn(core::storage::db::DBTYPE::COMMON)?; 343 + 344 + let peers = get_peer_list(&db_conn)?; 345 + 346 + println!("DID\tNickname\n"); 347 + for peer in peers { 348 + println!("{}\t{}", peer.user_id, peer.username) 349 + } 350 + Ok(()) 351 + } 352 + 353 + pub fn unlink_peer(user_id: &str) -> Result<()> { 354 + let db_conn = get_db_conn(core::storage::db::DBTYPE::COMMON)?; 355 + 356 + if let Err(err) = unlink(&db_conn, user_id) { 357 + println!("{:?}", err) 358 + } else { 359 + println!("Succesfully disabled the peer") 360 + } 361 + Ok(()) 338 362 } 339 363 340 364 #[cfg(test)]
+162 -8
tiles/src/core/accounts.rs
··· 1 1 //! Accounts 2 2 // Stuff related to account and identity system 3 3 use anyhow::{Result, anyhow}; 4 + use iroh::SecretKey; 4 5 use rusqlite::{Connection, types::FromSqlError}; 5 6 use std::{ 6 7 fmt::Display, 7 8 time::{SystemTime, UNIX_EPOCH}, 8 9 }; 9 - use tilekit::accounts::create_identity; 10 + use tilekit::accounts::{create_identity, get_secret_key}; 10 11 use toml::Table; 11 12 use uuid::Uuid; 12 13 ··· 29 30 // root account, created in the system 30 31 LOCAL, 31 32 32 - // remote account but same previlege as your local account 33 - SELF, 33 + // remote account 34 + PEER, 34 35 } 35 36 36 37 #[derive(Debug)] ··· 50 51 let value_lower = value.to_lowercase(); 51 52 match value_lower.as_str() { 52 53 "local" => Ok(ACCOUNT::LOCAL), 54 + "peer" => Ok(ACCOUNT::PEER), 53 55 _ => Err(AccountError { 54 56 error: "Invalid account type".to_owned(), 55 57 }), ··· 60 62 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 61 63 match self { 62 64 Self::LOCAL => write!(f, "{}", String::from("local")), 63 - Self::SELF => write!(f, "{}", String::from("self")), 65 + Self::PEER => write!(f, "{}", String::from("peer")), 64 66 } 65 67 } 66 68 } ··· 225 227 .map_err(<rusqlite::Error as Into<anyhow::Error>>::into) 226 228 } 227 229 230 + pub fn get_user(conn: &Connection, did: &str) -> Result<User> { 231 + let mut fetch_current_user = conn.prepare("select id, user_id, username, account_type, active_profile, root, created_at, updated_at from users where user_id= ?1")?; 232 + 233 + fetch_current_user 234 + .query_one([did], |row| { 235 + let id: String = row.get(0)?; 236 + let account_type: String = row.get(3)?; 237 + let created_at: f64 = row.get(6)?; 238 + let updated_at: f64 = row.get(7)?; 239 + Ok(User { 240 + id: Uuid::try_parse(&id).map_err(FromSqlError::other)?, 241 + user_id: row.get(1)?, 242 + username: row.get(2)?, 243 + account_type: ACCOUNT::try_from(account_type).map_err(FromSqlError::other)?, 244 + active_profile: row.get(4)?, 245 + root: row.get(5)?, 246 + 247 + created_at: created_at as u64, 248 + updated_at: updated_at as u64, 249 + }) 250 + }) 251 + .map_err(<rusqlite::Error as Into<anyhow::Error>>::into) 252 + } 253 + 228 254 pub fn save_root_account_db() -> Result<()> { 229 255 let conn = get_db_conn(DBTYPE::COMMON)?; 230 256 let config = get_or_create_config()?; ··· 262 288 263 289 // TODO: We could add unique user_id constraints, but 264 290 // we will wait for it until we solve the sync part 265 - pub fn save_self_account_db(db_conn: &Connection, user_id: &str, nickname: &str) -> Result<()> { 291 + pub fn save_peer_account_db(db_conn: &Connection, user_id: &str, nickname: &str) -> Result<()> { 266 292 let user = User { 267 293 id: Uuid::now_v7(), 268 294 user_id: String::from(user_id), 269 295 username: String::from(nickname), 270 - account_type: ACCOUNT::SELF, 296 + account_type: ACCOUNT::PEER, 271 297 active_profile: false, 272 298 root: false, 273 299 created_at: SystemTime::now() ··· 294 320 Ok(()) 295 321 } 296 322 297 - pub fn get_user_by_user_id(conn: &Connection, user_id: &str) -> Result<()> { 323 + pub fn get_user_by_user_id(conn: &Connection, user_id: String) -> Result<()> { 298 324 let mut fetch_root_user = conn.prepare("select id from users where user_id = ?1")?; 299 325 300 326 match fetch_root_user.query_one([user_id], |_row| Ok(())) { ··· 306 332 307 333 fn create_root_user(root_user_config: &Table, nickname: Option<String>) -> Result<Table> { 308 334 let mut root_user_table = root_user_config.clone(); 309 - match create_identity("tiles") { 335 + let app_name = if cfg!(debug_assertions) { 336 + "tiles_dev" 337 + } else { 338 + "tiles" 339 + }; 340 + match create_identity(app_name) { 310 341 Ok(did) => { 311 342 root_user_table.insert("id".to_owned(), toml::Value::String(did)); 312 343 if let Some(nickname) = nickname { ··· 318 349 } 319 350 } 320 351 352 + pub fn get_peer_list(db_conn: &Connection) -> Result<Vec<User>> { 353 + let mut stmt= db_conn.prepare("select id, user_id, username, account_type, active_profile, root, created_at, updated_at from users where account_type != \'local\'")?; 354 + 355 + let user_rows = stmt 356 + .query_map([], |row| { 357 + let id: String = row.get(0)?; 358 + let account_type: String = row.get(3)?; 359 + let created_at: f64 = row.get(6)?; 360 + let updated_at: f64 = row.get(7)?; 361 + Ok(User { 362 + id: Uuid::try_parse(&id).map_err(FromSqlError::other)?, 363 + user_id: row.get(1)?, 364 + username: row.get(2)?, 365 + account_type: ACCOUNT::try_from(account_type).map_err(FromSqlError::other)?, 366 + active_profile: row.get(4)?, 367 + root: row.get(5)?, 368 + 369 + created_at: created_at as u64, 370 + updated_at: updated_at as u64, 371 + }) 372 + }) 373 + .map_err(<rusqlite::Error as Into<anyhow::Error>>::into)?; 374 + 375 + let mut peer_list: Vec<User> = vec![]; 376 + 377 + for peer in user_rows { 378 + peer_list.push(peer?); 379 + } 380 + 381 + Ok(peer_list) 382 + } 383 + 384 + pub fn unlink(db_conn: &Connection, user_id: &str) -> Result<()> { 385 + let user = get_current_user(db_conn)?; 386 + if user.user_id == user_id { 387 + return Err(anyhow!("Cannot unlink yourself")); 388 + } 389 + 390 + match db_conn.execute( 391 + "delete from users where user_id = ?1 and account_type != \'local\'", 392 + [user_id], 393 + ) { 394 + Ok(0) => Err(anyhow!("A peer with DID {} doesn't exist", user_id)), 395 + Ok(_) => Ok(()), 396 + Err(err) => Err(anyhow!("Unable to unlink the peer due to {:?}", err)), 397 + } 398 + } 399 + 400 + pub fn get_app_secret_key(did: &str) -> Result<SecretKey> { 401 + let app_name = if cfg!(debug_assertions) { 402 + "tiles_dev" 403 + } else { 404 + "tiles" 405 + }; 406 + let signing_key = get_secret_key(app_name, did)?; 407 + Ok(SecretKey::from_bytes(&signing_key)) 408 + } 409 + 321 410 #[cfg(test)] 322 411 mod tests { 323 412 use super::*; ··· 665 754 .unwrap(); 666 755 667 756 assert!(get_current_user(&conn).is_err()); 757 + } 758 + 759 + fn create_user(conn: &Connection, account_type: ACCOUNT) -> User { 760 + let user = User { 761 + id: Uuid::now_v7(), 762 + user_id: String::from("did"), 763 + username: String::from("nickname"), 764 + account_type, 765 + active_profile: true, 766 + root: true, 767 + created_at: SystemTime::now() 768 + .duration_since(UNIX_EPOCH) 769 + .expect("time went backwards") 770 + .as_secs(), 771 + updated_at: SystemTime::now() 772 + .duration_since(UNIX_EPOCH) 773 + .expect("time went backwards") 774 + .as_secs(), 775 + }; 776 + 777 + conn.execute("insert into users (id, user_id, username, active_profile, account_type, root) values (?1, ?2, ?3,?4, ?5, ?6)", (&user.id.to_string(), &user.user_id, &user.username, &user.active_profile, 778 + user.account_type.to_string(), &user.root)).unwrap(); 779 + user 780 + } 781 + 782 + #[test] 783 + fn test_list_peers_with_atleast_0_peer() { 784 + let conn = setup_db_schema(); 785 + let _local_user = create_user(&conn, ACCOUNT::LOCAL); 786 + 787 + let user_list = get_peer_list(&conn).unwrap(); 788 + 789 + assert!(user_list.is_empty()) 790 + } 791 + 792 + #[test] 793 + fn test_list_peers_with_more_than_0_peer() { 794 + let conn = setup_db_schema(); 795 + let _local_user = create_user(&conn, ACCOUNT::LOCAL); 796 + save_peer_account_db(&conn, "did:jey:varathan", "varathan").unwrap(); 797 + let user_list = get_peer_list(&conn).unwrap(); 798 + 799 + assert!(!user_list.is_empty()) 800 + } 801 + 802 + #[test] 803 + fn test_unlink_valid_peer() { 804 + let conn = setup_db_schema(); 805 + let _local_user = create_user(&conn, ACCOUNT::LOCAL); 806 + save_peer_account_db(&conn, "did:jey:varathan", "varathan").unwrap(); 807 + let user_list = get_peer_list(&conn).unwrap(); 808 + 809 + assert!(!user_list.is_empty()); 810 + 811 + unlink(&conn, "did:jey:varathan").unwrap(); 812 + let user_list = get_peer_list(&conn).unwrap(); 813 + assert!(user_list.is_empty()); 814 + } 815 + 816 + #[test] 817 + fn test_try_unlink_local() { 818 + let conn = setup_db_schema(); 819 + let local_user = create_user(&conn, ACCOUNT::LOCAL); 820 + 821 + assert!(unlink(&conn, &local_user.user_id).is_err()) 668 822 } 669 823 }
+258 -87
tiles/src/core/network/mod.rs
··· 5 5 io, 6 6 str::FromStr, 7 7 sync::{Arc, Mutex}, 8 + time::Duration, 8 9 }; 9 10 10 11 use anyhow::Result; 11 - use futures_util::TryStreamExt; 12 + use futures_util::{StreamExt, TryStreamExt}; 12 13 use iroh::{ 13 - Endpoint, EndpointId, SecretKey, 14 + Endpoint, EndpointId, NET_REPORT_TIMEOUT, PublicKey, 15 + address_lookup::{self, MdnsAddressLookup, mdns}, 14 16 endpoint::{BindError, presets}, 17 + endpoint_info::UserData, 15 18 protocol::Router, 16 19 }; 17 20 use iroh_gossip::{ ··· 21 24 use iroh_ping::Ping; 22 25 use iroh_tickets::endpoint::EndpointTicket; 23 26 use rusqlite::Connection; 24 - use tilekit::accounts::{get_did_from_public_key, get_random_bytes, get_secret_key}; 27 + use tilekit::accounts::{get_did_from_public_key, get_random_bytes, get_random_bytes_32}; 25 28 use tokio::task::spawn_blocking; 29 + use uuid::Uuid; 26 30 27 31 use crate::core::{ 28 - accounts::{self, get_current_user, get_user_by_user_id, save_self_account_db}, 29 - network::ticket::LinkTicket, 32 + accounts::{ 33 + self, get_app_secret_key, get_current_user, get_user_by_user_id, save_peer_account_db, 34 + }, 35 + network::ticket::{EndpointUserData, LinkTicket}, 30 36 storage::db::{DBTYPE, get_db_conn}, 31 37 }; 32 38 use sha2::{Digest, Sha256}; 33 39 40 + const DEVICE_LINK_LOCAL_TOPIC: &str = "com.tilesprivacy.tiles.link"; 34 41 #[derive(serde::Serialize, serde::Deserialize)] 35 42 struct NetworkMessage { 43 + from_did: String, 44 + from_nickname: String, 45 + is_online: bool, 36 46 body: MessageBody, 37 - 38 47 // to prevent iroh's deduplication on same msg 39 48 nonce: [u8; 16], 40 49 } 41 50 42 51 impl NetworkMessage { 43 - fn new(body: MessageBody) -> Self { 52 + fn new(user: &accounts::User, is_online: bool, body: MessageBody) -> Self { 44 53 Self { 54 + from_did: user.user_id.clone(), 55 + from_nickname: user.username.clone(), 56 + is_online, 45 57 body, 46 58 nonce: get_random_bytes(), 47 59 } ··· 57 69 #[derive(serde::Serialize, serde::Deserialize)] 58 70 #[allow(clippy::enum_variant_names)] 59 71 enum MessageBody { 60 - LinkRequest { did: String, nickname: String }, 61 - LinkAccepted { did: String, nickname: String }, 62 - LinkRejected { did: String, nickname: String }, 72 + LinkRequest { ticket: String }, 73 + LinkAccepted, 74 + LinkRejected { reason: String }, 63 75 } 64 76 65 77 // Entrypoint of network connection ··· 102 114 pub async fn link(ticket: Option<String>) -> Result<()> { 103 115 let user_db_conn = get_db_conn(DBTYPE::COMMON)?; 104 116 let user = get_current_user(&user_db_conn)?; 117 + let endpoint = create_endpoint(&user).await?; 118 + let is_online = is_online(&endpoint).await; 119 + let mut bootstrap_ids: Vec<EndpointId> = vec![]; 120 + // if ticket's there, then this is link enable sender's command, e;se receiver end 105 121 if let Some(ticket) = ticket { 106 - let link_ticket = LinkTicket::from_str(&ticket)?; 107 - if get_user_by_user_id(&user_db_conn, &link_ticket.did).is_ok() { 108 - println!( 109 - "Device {}({}) already linked", 110 - link_ticket.nickname, link_ticket.did 111 - ); 122 + let (endpoint_id, mut did, mut nickname, topic_value) = parse_link_ticket(&ticket)?; 123 + 124 + let topic_id = if is_online { 125 + topic_value.expect("Expected topicId") 126 + } else { 127 + create_topic_id(DEVICE_LINK_LOCAL_TOPIC) 128 + }; 129 + 130 + if is_online { 131 + bootstrap_ids.push(endpoint_id.expect("Expected an EndpointId as bootstrapId ")) 132 + } else { 133 + println!("Searching for peers in the local network.."); 134 + let mdns = address_lookup::mdns::MdnsAddressLookup::builder().build(endpoint.id())?; 135 + let (new_bootstrap_ids, user_data) = 136 + find_offline_bootstrap_peers(&endpoint, mdns).await?; 137 + bootstrap_ids = new_bootstrap_ids; 138 + let endpoint_user_data = EndpointUserData::try_from(user_data.to_string())?; 139 + did = endpoint_user_data.did; 140 + nickname = endpoint_user_data.nickname; 141 + }; 142 + if get_user_by_user_id(&user_db_conn, did.to_owned()).is_ok() { 143 + println!("Device {}({}) already linked", nickname, did); 112 144 return Ok(()); 113 145 } 114 - let endpoint = create_endpoint(&user).await?; 115 - endpoint.online().await; 116 - let gossip = Gossip::builder().spawn(endpoint.clone()); 146 + let (sender, mut receiver, recv_router) = 147 + create_gossip_network(&endpoint, topic_id, bootstrap_ids).await?; 117 148 118 - let recv_router = Router::builder(endpoint.clone()) 119 - .accept(iroh_gossip::ALPN, gossip.clone()) 120 - .spawn(); 149 + println!("\nConnecting to {}({}).....", nickname, did); 121 150 122 - let (sender, mut receiver) = gossip 123 - .subscribe(link_ticket.topic_id, vec![link_ticket.addr.id]) 124 - .await? 125 - .split(); 151 + receiver.joined().await?; 126 152 127 - println!( 128 - "Connecting to {}({}).....", 129 - link_ticket.nickname, link_ticket.did 130 - ); 131 - receiver.joined().await?; 132 153 tokio::spawn(subsribe_loop( 133 154 receiver, 134 155 sender.clone(), 135 156 user.clone(), 136 157 user_db_conn, 158 + None, 137 159 )); 138 160 139 - let link_req_msg = NetworkMessage::new(MessageBody::LinkRequest { 140 - did: user.user_id, 141 - nickname: user.username, 142 - }); 161 + let link_req_msg = 162 + NetworkMessage::new(&user, is_online, MessageBody::LinkRequest { ticket }); 143 163 sender.broadcast(link_req_msg.to_bytes().into()).await?; 144 164 145 - println!( 146 - "Sent link request to {}({})", 147 - link_ticket.nickname, link_ticket.did 148 - ); 165 + println!("\nSent link request to {}({})", nickname, did); 166 + 167 + println!("\nWaiting for response..."); 149 168 150 - println!("Waiting for response..."); 151 169 tokio::signal::ctrl_c().await?; 152 170 recv_router.shutdown().await?; 153 - endpoint.close().await; 154 171 } else { 155 - let endpoint = create_endpoint(&user).await?; 156 - endpoint.online().await; 172 + // RECEIVER BLOCK 173 + if !is_online { 174 + let mdns = address_lookup::mdns::MdnsAddressLookup::builder().build(endpoint.id())?; 175 + endpoint.address_lookup()?.add(mdns.clone()); 176 + } 157 177 158 - let gossip = Gossip::builder().spawn(endpoint.clone()); 178 + // Its better to have unique session'ed channels while 179 + // when the communication is over internet 180 + let topic_id = if is_online { 181 + TopicId::from_bytes(get_random_bytes_32()) 182 + } else { 183 + create_topic_id(DEVICE_LINK_LOCAL_TOPIC) 184 + }; 159 185 160 - let recv_router = Router::builder(endpoint.clone()) 161 - .accept(iroh_gossip::ALPN, gossip.clone()) 162 - .spawn(); 186 + let (sender, receiver, recv_router) = 187 + create_gossip_network(&endpoint, topic_id, bootstrap_ids).await?; 163 188 164 - let topic_id = create_topic_id("com.tilesprivacy.tiles.link"); 189 + let generated_ticket = if is_online { 190 + let ticket = LinkTicket::new( 191 + topic_id, 192 + endpoint.addr(), 193 + user.user_id.clone(), 194 + user.username.clone(), 195 + ); 196 + println!("Generated link ticket: \n{:?}\n", ticket.to_string()); 165 197 166 - let (sender, receiver) = gossip.subscribe(topic_id, vec![]).await?.split(); 198 + println!( 199 + "Use this ticket with `tiles link enable <ticket>` on the system you want to connect to\n" 200 + ); 201 + ticket.to_string() 202 + } else { 203 + // generate a code 204 + let uuid = Uuid::new_v4().to_string(); 167 205 168 - let ticket = LinkTicket::new( 169 - topic_id, 170 - endpoint.addr(), 171 - user.user_id.clone(), 172 - user.username.clone(), 173 - ); 206 + let ticket = uuid.split('-').collect::<Vec<&str>>()[0]; 174 207 175 - println!("Link Ticket: {:?}\n", ticket.to_string()); 176 - println!( 177 - "Use this link ticket with `tiles link <ticket>` on the system you want to connect to\n" 178 - ); 208 + println!("Generated link code: {}\n", ticket); 209 + 210 + println!( 211 + "Use this link code with `tiles link enable {}` on the system you want to connect to\n", 212 + ticket 213 + ); 214 + ticket.to_string() 215 + }; 179 216 180 217 println!("Don't close this session until the link process is done\n"); 181 218 ··· 184 221 sender.clone(), 185 222 user.clone(), 186 223 user_db_conn, 224 + Some(generated_ticket), 187 225 )); 188 226 189 227 // TODO: Maybe a better way is to use a oneshot channel to exit 190 228 // the terminal instead of SIGINT 191 229 tokio::signal::ctrl_c().await?; 192 230 recv_router.shutdown().await?; 193 - endpoint.close().await; 194 231 } 232 + endpoint.close().await; 195 233 Ok(()) 196 234 } 197 235 ··· 200 238 sender: GossipSender, 201 239 user: accounts::User, 202 240 db_conn: Connection, 241 + generated_ticket: Option<String>, 203 242 ) -> Result<()> { 204 243 while let Some(event) = receiver.try_next().await? { 205 - // println!("some event {:?}", event); 244 + if cfg!(debug_assertions) { 245 + println!("In {}:, some event {:?}", user.username, event); 246 + } 206 247 if let Event::Received(msg) = event { 207 - match NetworkMessage::from_bytes(&msg.content)?.body { 208 - MessageBody::LinkRequest { did, nickname } => { 248 + let pub_key = msg.delivered_from; 249 + let msg = NetworkMessage::from_bytes(&msg.content)?; 250 + if !is_did_valid(&msg.from_did, pub_key)? { 251 + eprintln!( 252 + "Incoming peer DID {} invalid, blocking request", 253 + msg.from_did 254 + ); 255 + continue; 256 + } 257 + match msg.body { 258 + MessageBody::LinkRequest { ticket } => { 209 259 println!( 210 260 "Received link request from {}({}), Do you want to link Y/N ?", 211 - nickname, did 261 + msg.from_nickname, msg.from_did 212 262 ); 213 263 let input: Arc<Mutex<String>> = Arc::new(Mutex::new(String::new())); 214 264 ··· 222 272 let input_resp = input.lock().unwrap().trim().to_owned(); 223 273 224 274 let link_res_resp = if input_resp.to_lowercase() == "y" { 225 - save_self_account_db(&db_conn, &did, &nickname)?; 275 + if let Some(gen_ticket) = &generated_ticket 276 + && !msg.is_online 277 + && *gen_ticket != ticket.to_lowercase() 278 + { 279 + println!("\nVerifying code does not match, please try again"); 280 + let response = NetworkMessage::new( 281 + &user, 282 + msg.is_online, 283 + MessageBody::LinkRejected { 284 + reason: String::from("Link code mismatch"), 285 + }, 286 + ); 287 + sender.broadcast(response.to_bytes().into()).await?; 288 + continue; 289 + } 290 + 291 + if let Err(err) = 292 + save_peer_account_db(&db_conn, &msg.from_did, &msg.from_nickname) 293 + { 294 + println!("Failed to add the peer locally due to {:?}", err); 295 + 296 + continue; 297 + } 298 + 226 299 println!( 227 300 "Device {}({}) is now linked\nYou can exit now by ctrl-c", 228 - nickname, did 301 + msg.from_nickname, msg.from_did 229 302 ); 230 - NetworkMessage::new(MessageBody::LinkAccepted { 231 - did: user.user_id.clone(), 232 - nickname: user.username.clone(), 233 - }) 303 + NetworkMessage::new(&user, msg.is_online, MessageBody::LinkAccepted) 234 304 } else { 235 305 println!("You can exit now by ctrl-c"); 236 - NetworkMessage::new(MessageBody::LinkRejected { 237 - did: user.user_id.clone(), 238 - nickname: user.username.clone(), 239 - }) 306 + NetworkMessage::new( 307 + &user, 308 + msg.is_online, 309 + MessageBody::LinkRejected { 310 + reason: String::from("Peer rejected the request"), 311 + }, 312 + ) 240 313 }; 241 314 input.lock().unwrap().clear(); 242 315 243 316 sender.broadcast(link_res_resp.to_bytes().into()).await?; 244 317 } 245 - MessageBody::LinkAccepted { did, nickname } => { 246 - save_self_account_db(&db_conn, &did, &nickname)?; 247 - println!("Link accepted by {}({})", nickname, did); 318 + MessageBody::LinkAccepted => { 319 + println!("\nLink accepted by {}({})", msg.from_nickname, msg.from_did); 248 320 249 - println!("You can exit now by ctrl-c"); 321 + if let Err(err) = 322 + save_peer_account_db(&db_conn, &msg.from_did, &msg.from_nickname) 323 + { 324 + println!("Failed to add the peer locally due to {:?}", err); 325 + return Ok(()); 326 + } 250 327 251 - return Ok(()); 328 + println!("\nYou can exit now by ctrl-c"); 329 + 330 + continue; 252 331 } 253 - MessageBody::LinkRejected { did, nickname } => { 332 + MessageBody::LinkRejected { reason } => { 254 333 println!( 255 - "Oops looks like your link request has been rejected by {}({}), exit (ctrl-c) and try again", 256 - nickname, did 334 + "Oops looks like your link request has been rejected by {}({}),\nreason: {},\nexit (ctrl-c) and try again", 335 + msg.from_nickname, msg.from_did, reason 257 336 ); 258 337 } 259 338 } ··· 265 344 async fn create_endpoint(user: &accounts::User) -> Result<Endpoint> { 266 345 // In release mode, we will build the endpoint using 267 346 // tiles keypair in keychain 347 + let usr_data = EndpointUserData::new(&user.user_id, &user.username); 268 348 if !cfg!(debug_assertions) { 269 - let signing_key = get_secret_key("tiles", &user.user_id)?; 270 - 271 - let secret_key = SecretKey::from_bytes(&signing_key); 272 - 349 + let secret_key = get_app_secret_key(&user.user_id)?; 273 350 Endpoint::builder(presets::N0) 351 + .user_data_for_address_lookup(UserData::try_from(usr_data.to_string())?) 274 352 .secret_key(secret_key) 275 353 .bind() 276 354 .await 277 355 .map_err(<BindError as Into<anyhow::Error>>::into) 278 356 } else { 279 - Endpoint::bind(presets::N0) 357 + Endpoint::builder(presets::N0) 358 + .user_data_for_address_lookup(UserData::try_from(usr_data.to_string())?) 359 + .bind() 280 360 .await 281 361 .map_err(<BindError as Into<anyhow::Error>>::into) 282 362 } ··· 293 373 get_did_from_public_key(endpoint_id.as_bytes()) 294 374 } 295 375 376 + async fn is_online(endpoint: &Endpoint) -> bool { 377 + tokio::select! { 378 + _ = endpoint.online() => { 379 + true 380 + } 381 + _ = tokio::time::sleep(Duration::from_secs(NET_REPORT_TIMEOUT)) => { 382 + false 383 + } 384 + } 385 + } 386 + 387 + // As of now we exit asap when we see a peer. This is subjected to change 388 + // as the scale 389 + async fn find_offline_bootstrap_peers( 390 + endpoint: &Endpoint, 391 + mdns: MdnsAddressLookup, 392 + ) -> Result<(Vec<EndpointId>, UserData)> { 393 + let mut bootstrap_ids: Vec<EndpointId> = vec![]; 394 + endpoint.address_lookup()?.add(mdns.clone()); 395 + let mut mdns_event = mdns.subscribe().await; 396 + let mut user_data = UserData::from_str("")?; 397 + while let Some(event) = mdns_event.next().await { 398 + match event { 399 + mdns::DiscoveryEvent::Discovered { 400 + endpoint_info, 401 + last_updated: _, 402 + } => { 403 + if cfg!(debug_assertions) { 404 + println!("peer discoverd {:?}", endpoint_info); 405 + } 406 + bootstrap_ids.push(endpoint_info.endpoint_id); 407 + user_data = endpoint_info.user_data().unwrap().clone(); 408 + break; 409 + } 410 + mdns::DiscoveryEvent::Expired { endpoint_id } => { 411 + if cfg!(debug_assertions) { 412 + println!("peer left {:?}", endpoint_id) 413 + } 414 + } 415 + } 416 + } 417 + 418 + Ok((bootstrap_ids, user_data)) 419 + } 420 + 421 + async fn create_gossip_network( 422 + endpoint: &Endpoint, 423 + topic_id: TopicId, 424 + bootstrap_ids: Vec<iroh::PublicKey>, 425 + ) -> Result<(GossipSender, GossipReceiver, Router)> { 426 + let gossip = Gossip::builder().spawn(endpoint.clone()); 427 + let recv_router = Router::builder(endpoint.clone()) 428 + .accept(iroh_gossip::ALPN, gossip.clone()) 429 + .spawn(); 430 + 431 + let (goss_sender, goss_receiver) = gossip.subscribe(topic_id, bootstrap_ids).await?.split(); 432 + 433 + Ok((goss_sender, goss_receiver, recv_router)) 434 + } 435 + 436 + // We handle the parsing in this way since ticket can be an encoded `LinkTicket` 437 + // or just a 4 byte hex if linking over mDNS 438 + fn parse_link_ticket( 439 + ticket: &str, 440 + ) -> Result<(Option<EndpointId>, String, String, Option<TopicId>)> { 441 + if let Ok(parsed_ticket) = LinkTicket::from_str(ticket) { 442 + Ok(( 443 + Some(parsed_ticket.addr.id), 444 + parsed_ticket.did, 445 + parsed_ticket.nickname, 446 + Some(parsed_ticket.topic_id), 447 + )) 448 + } else if ticket.len() == 8 { 449 + // NOTE: We only have len check as a "parser" for the offline code 450 + // but this will surely change once we fix the code format 451 + Ok((None, String::from(""), String::from(""), None)) 452 + } else { 453 + Err(anyhow::anyhow!("Invalid Ticket")) 454 + } 455 + } 456 + 457 + fn is_did_valid(did: &str, pub_key: PublicKey) -> Result<bool> { 458 + // on debug mode, we skip the auth check, since we will be testing 459 + // with random endpoitns but w DID from config atp 460 + if cfg!(debug_assertions) { 461 + Ok(true) 462 + } else { 463 + Ok(get_did_from_public_key(&pub_key)? == did) 464 + } 465 + } 466 + // fn subsribe_mdns_events(mdns_events) {} 296 467 //TODO: Add tests, can we get some from iroh reference?
+49 -1
tiles/src/core/network/ticket.rs
··· 53 53 } 54 54 } 55 55 56 - // TODO: Add tests 56 + #[derive(serde::Serialize, serde::Deserialize, Debug)] 57 + pub struct EndpointUserData { 58 + pub did: String, 59 + pub nickname: String, 60 + } 61 + 62 + impl EndpointUserData { 63 + pub fn new(did: &str, nickname: &str) -> Self { 64 + Self { 65 + did: did.to_owned(), 66 + nickname: nickname.to_owned(), 67 + } 68 + } 69 + 70 + fn to_bytes(&self) -> Vec<u8> { 71 + postcard::to_stdvec(&self).expect("EndpointUserData to bytes couldnt be done") 72 + } 73 + } 74 + 75 + impl TryFrom<String> for EndpointUserData { 76 + type Error = anyhow::Error; 77 + fn try_from(value: String) -> Result<Self, Self::Error> { 78 + let data_bytes = data_encoding::BASE32_NOPAD.decode(value.to_uppercase().as_bytes())?; 79 + postcard::from_bytes(&data_bytes).map_err(Into::into) 80 + } 81 + } 82 + 83 + impl Display for EndpointUserData { 84 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 85 + let mut text = data_encoding::BASE32_NOPAD.encode(&self.to_bytes()[..]); 86 + text.make_ascii_lowercase(); 87 + write!(f, "{}", text) 88 + } 89 + } 90 + 91 + #[cfg(test)] 92 + mod tests { 93 + use crate::core::network::ticket::EndpointUserData; 94 + 95 + #[test] 96 + fn test_basic_to_fro_userdata_conversion() { 97 + let user_data = EndpointUserData::new("did:key", "machine"); 98 + let usr_data_str = user_data.to_string(); 99 + let usr_data_struct = EndpointUserData::try_from(usr_data_str).unwrap(); 100 + 101 + assert_eq!(user_data.did, usr_data_struct.did); 102 + assert_eq!(user_data.nickname, usr_data_struct.nickname); 103 + } 104 + }
+36 -10
tiles/src/main.rs
··· 2 2 3 3 use clap::{Args, Parser, Subcommand}; 4 4 use tiles::{ 5 - core::network::link, 5 + core::{self, network::link}, 6 6 daemon::{start_cmd, start_server, stop_cmd}, 7 7 runtime::{RunArgs, build_runtime}, 8 8 utils::installer, 9 9 }; 10 + 11 + use crate::commands::{show_peers, unlink_peer}; 10 12 11 13 mod commands; 12 14 #[derive(Debug, Parser)] ··· 63 65 Daemon(DaemonArgs), 64 66 65 67 /// Link with other devices p2p 66 - Link { 67 - /// The ticket from a peer which can be used to link to it 68 - ticket: Option<String>, 69 - }, 68 + Link(LinkArgs), 70 69 } 71 70 72 71 #[derive(Debug, Args)] ··· 150 149 /// Stops the daemon 151 150 Stop, 152 151 } 152 + 153 + #[derive(Debug, Args)] 154 + #[command(args_conflicts_with_subcommands = true)] 155 + #[command(flatten_help = true)] 156 + struct LinkArgs { 157 + #[command(subcommand)] 158 + command: LinkCommands, 159 + } 160 + 161 + #[derive(Debug, Subcommand)] 162 + enum LinkCommands { 163 + /// Produce link ticket and wait or send link request with ticket 164 + Enable { 165 + ticket: Option<String>, 166 + }, 167 + 168 + // Unlink give device 169 + Disable { 170 + did: String, 171 + }, 172 + /// Start the daemon 173 + ListPeers, 174 + } 153 175 #[tokio::main] 154 176 pub async fn main() -> Result<(), Box<dyn Error>> { 155 177 let cli = Cli::parse(); ··· 173 195 let _ = start_cmd(None).await; 174 196 }); 175 197 } 176 - 198 + core::init().inspect_err(|e| eprintln!("Tiles core init failed due to {:?}", e))?; 177 199 if !cli.flags.no_repl { 178 200 commands::run(&runtime, run_args) 179 201 .await ··· 189 211 relay_count: flags.relay_count, 190 212 memory: flags.memory, 191 213 }; 214 + core::init().inspect_err(|e| eprintln!("Tiles core init failed due to {:?}", e))?; 192 215 commands::run(&runtime, run_args) 193 216 .await 194 217 .inspect_err(|e| eprintln!("Tiles failed to run due to {:?}", e))?; ··· 233 256 .inspect(|_| println!("Daemon stopped successfully"))?, 234 257 _ => start_server(None).await?, 235 258 }, 236 - Some(Commands::Link { ticket }) => { 237 - // TODO: Move these direct call to core 238 - link(ticket).await? 239 - } 259 + Some(Commands::Link(link_args)) => match link_args.command { 260 + LinkCommands::Enable { ticket } => link(ticket).await?, 261 + LinkCommands::Disable { did } => unlink_peer(&did)?, 262 + LinkCommands::ListPeers => { 263 + show_peers()?; 264 + } 265 + }, 240 266 } 241 267 Ok(()) 242 268 }