├── .github └── FUNDING.yml ├── ARCHITECTURE.md ├── LICENSE ├── Makefile ├── README.md ├── cmd └── webfs │ └── main.go ├── doc ├── 10_CLI.md └── 11_Volume_Specs.md ├── etc └── start_ipfs.sh ├── go.mod ├── go.sum └── pkg ├── cells ├── filecell │ └── filecell.go └── gotcells │ └── gbcell.go ├── stores ├── httpstore │ ├── client.go.dont │ ├── httpstore_test.go.dont │ └── server.go.dont └── ipfsstore │ └── ipfsstore.go ├── webfs ├── errors.go ├── file.go ├── option.go ├── specs.go ├── webfs.go └── webfs_test.go └── webfscmd ├── add.go ├── cat.go ├── edit.go ├── http.go ├── ls.go ├── mkdir.go ├── mount.go ├── mv.go ├── rm.go ├── root.go └── touch.go /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: #e.g., [user1, user2] 4 | patreon: brendoncarroll 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /ARCHITECTURE.md: -------------------------------------------------------------------------------- 1 | # WebFS Architecture 2 | 3 | WebFS depends on two interfaces: `Stores` and `Cells`. 4 | 5 | ### Stores 6 | Stores are content-addressed stores. 7 | They support two fundamental operations 8 | 9 | ``` 10 | Post(data) -> hash 11 | Get(hash) -> data 12 | ``` 13 | The standard interface is defined by the [`cadata`](http://github.com/brendoncarroll/go-state/tree/master/cadata) package from the go-state library. 14 | 15 | Store implementations can be found in `pkg/stores/` 16 | 17 | ### Cells 18 | Cells in WebFS are like cells in a spreadsheet, a holder of a data which can change over time. 19 | The compare-and-swap operation (`CAS(current, next)`) allows writes which will be synchronized with other WebFS instances writing to the same cell. 20 | 21 | Cells provide two fundamental operations: 22 | ``` 23 | Get() -> current 24 | CAS(prev, next []byte) -> current 25 | ``` 26 | 27 | The standard interface is defined by the [`cells`](https://github.com/brendoncarroll/go-state/tree/master/cells) package from the go-state library. 28 | 29 | Cell implementations can be found in `pkg/cells/` 30 | 31 | ### Formats 32 | WebFS uses [GotFS](https://github.com/gotvc/got/tree/master/pkg/gotfs) from the [Got](https://github.com/gotvc/got) version control system for storing file data. 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | .PHONY: test testv install 3 | 4 | test: 5 | go test ./... 6 | 7 | testv: 8 | go test -v ./... 9 | 10 | install: 11 | go install ./cmd/webfs 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebFS 2 | 3 | WebFS is a filesystem built on top of the web. 4 | 5 | WebFS started after looking for a way to use IPFS as a Dropbox replacement, 6 | and not finding any really solid solutions. I also wanted to be able to fluidly move 7 | my data between traditional storage providers like Dropbox, MEGA, or Google Drive while testing the waters of new p2p storage systems, like Swarm or Filecoin. 8 | 9 | If you have ever thought "x can probably be used as a file system", but didn't want to actually write the file system part, WebFS might be of benefit to you. 10 | You can probably turn x into a file system with WebFS by writing a new `Store` or `Cell` implementation. 11 | 12 | ## Quick Links 13 | [CLI Docs](./doc/10_CLI.md) 14 | 15 | [Volume Specs Docs](./doc/11_Volume_Specs.md) 16 | 17 | [ARCHITECTURE.md](./ARCHITECTURE.md) 18 | 19 | ## Installation 20 | Installs to `$GOPATH/bin` with `make install` 21 | 22 | ## Getting Started 23 | A simple volume spec using the filesystem for storage 24 | 25 | ```json 26 | { 27 | "cell": { 28 | "file": "CELL_DATA", 29 | }, 30 | "store": { 31 | "fs": "BLOBS", 32 | } 33 | } 34 | ``` 35 | This configuration will create and write to a file `./CELL_DATA` and a directory `./BLOBS`, so plan accordingly. 36 | 37 | To serve the files over http 38 | ```shell 39 | $ webfs http --root myvolume.webfs 40 | serving at http://127.0.0.1:7007 41 | ``` 42 | 43 | ## Examples 44 | There are examples in the `/examples` directory. 45 | The examples assume you have the `webfs` executable on your `$PATH`. 46 | 47 | You can also use 48 | ```go run ../../cmd/webfs``` instead of ```webfs``` if you don't want to set that up. 49 | 50 | ## Community 51 | Questions and Discussion happening on Matrix. 52 | 53 | ![Matrix](https://img.shields.io/matrix/webfs:matrix.org?label=%23webfs%3Amatrix.org&logo=matrix) 54 | -------------------------------------------------------------------------------- /cmd/webfs/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/brendoncarroll/webfs/pkg/webfscmd" 7 | ) 8 | 9 | func main() { 10 | if err := webfscmd.Execute(); err != nil { 11 | fmt.Println(err) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /doc/10_CLI.md: -------------------------------------------------------------------------------- 1 | # WebFS Command Line Interface 2 | 3 | When performing an operation on a WebFS filesystem, the root config must always be provided. 4 | On the command line, this is done using the `--root` or `-r` flag. 5 | 6 | In practice this usually lookes something like this: 7 | ```shell 8 | $ webfs -r ./path/to/webfs_root.json ls 9 | ``` 10 | 11 | # Primitive Operations 12 | 13 | ## `webfs add ` 14 | Adds files to WebFS. 15 | - `dst` is a path within WebFS. 16 | - `src` is assumed to be a file in the local filesystem. 17 | URLs may also eventually be supported. 18 | 19 | ## `webfs ls ` 20 | Like UNIX's `ls`, but within the WebFS filesystem. 21 | Lists the paths which are children of `path` 22 | 23 | ## `webfs rm ` 24 | Removes a file or directory. 25 | This is like `rm -rf`. 26 | 27 | ## `webfs edit ` 28 | Edit a file in WebFS using `$EDITOR`. 29 | Defaults to `vim` if `$EDITOR` is not set. 30 | This is useful for configuring a subvolume in a `*.webfs` file within the filesystem. 31 | 32 | ## `webfs mkdir ` 33 | Creates all directories along path. 34 | Similar to `mkdir -p `. 35 | 36 | # Servers 37 | ## `webfs http [--addr]` 38 | Serves files over HTTP. 39 | 40 | ## `webfs nfs [--addr]` 41 | Serves files ovver NFS. 42 | 43 | ## `webfs mount [--path]` 44 | Mounts a fuse filesystem at path. 45 | -------------------------------------------------------------------------------- /doc/11_Volume_Specs.md: -------------------------------------------------------------------------------- 1 | # Volume Specs 2 | WebFS volumes are specified by JSON configuration files in the filesystem with names ending in `.webfs` 3 | 4 | WebFS volumes consist of a cell, a store, and a salt. 5 | The salt is only used when adding files. 6 | 7 | Every volume spec should look something like this 8 | 9 | ```json 10 | { 11 | "cell": { 12 | ... 13 | }, 14 | "store" : { 15 | ... 16 | }, 17 | "salt": "hJYTuuOky0Q4w25olAF+UY894bnNgRkXO2OIyeRd+yE=" 18 | } 19 | ``` 20 | 21 | # Cells 22 | 23 | ## `file` 24 | e.g. 25 | ```json 26 | { 27 | "cell": { 28 | "file": "path/to/cell" 29 | } 30 | ... 31 | } 32 | ``` 33 | 34 | ## `http` 35 | e.g. 36 | ```json 37 | { 38 | "cell": { 39 | "http": { 40 | "url": "http://example.com/cells/1234", 41 | "headers": { 42 | "X-My-Header": "header-value", 43 | } 44 | } 45 | } 46 | ... 47 | } 48 | ``` 49 | 50 | ## `aead` 51 | e.g. 52 | ```json 53 | { 54 | "cell": { 55 | "aead": { 56 | "inner": { 57 | ... 58 | }, 59 | "algo": "chacha20poly1305", 60 | "secret": "hJYTuuOky0Q4w25olAF+UY894bnNgRkXO2OIyeRd+yE=" 61 | } 62 | } 63 | ... 64 | } 65 | ``` 66 | 67 | ## `got_branch` 68 | e.g. 69 | ```json 70 | { 71 | "cell": { 72 | "got_branch": { 73 | "inner": { 74 | ... 75 | }, 76 | } 77 | } 78 | ... 79 | } 80 | ``` 81 | 82 | # Stores 83 | 84 | ## `fs` 85 | e.g. 86 | ```json 87 | { 88 | "store": { 89 | "fs": "path/to/dir", 90 | } 91 | ... 92 | } 93 | ``` 94 | 95 | ## `http` 96 | e.g. 97 | ```json 98 | { 99 | "store": { 100 | "http": "path/to/dir", 101 | } 102 | ... 103 | } 104 | ``` 105 | 106 | ## `blobcache` 107 | e.g. 108 | ```json 109 | { 110 | "store": { 111 | "blobcache": {} 112 | } 113 | ... 114 | } 115 | ``` 116 | 117 | ## `ipfs` 118 | e.g. 119 | ```json 120 | { 121 | "store": { 122 | "ipfs": {}, 123 | } 124 | ... 125 | } 126 | ``` 127 | -------------------------------------------------------------------------------- /etc/start_ipfs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | docker run -it --rm --name ipfs-node \ 4 | -p 8080:8080 -p 4001:4001 -p 127.0.0.1:5001:5001 \ 5 | jbenet/go-ipfs:latest 6 | 7 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/brendoncarroll/webfs 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/blobcache/blobcache v0.0.0-20220615224329-ce25fe33118b 7 | github.com/brendoncarroll/go-state v0.0.0-20220617134034-2613fe050888 8 | github.com/gotvc/got v0.0.3-0.20220618220735-aa388cfe7f66 9 | github.com/ipfs/go-ipfs-api v0.0.1 10 | github.com/multiformats/go-multihash v0.0.1 11 | github.com/sirupsen/logrus v1.7.0 12 | github.com/spf13/cobra v0.0.5 13 | github.com/stretchr/testify v1.7.0 14 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 15 | ) 16 | 17 | require ( 18 | github.com/DataDog/zstd v1.4.1 // indirect 19 | github.com/brendoncarroll/go-p2p v0.0.0-20220617145626-749dd26b09b0 // indirect 20 | github.com/brendoncarroll/go-tai64 v0.0.0-20220527232055-eab29bd93d59 // indirect 21 | github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 // indirect 22 | github.com/cespare/xxhash v1.1.0 // indirect 23 | github.com/chmduquesne/rollinghash v0.0.0-20180912150627-a60f8e7142b5 // indirect 24 | github.com/davecgh/go-spew v1.1.1 // indirect 25 | github.com/dgraph-io/badger/v2 v2.0.3 // indirect 26 | github.com/dgraph-io/ristretto v0.0.2-0.20200115201040-8f368f2f2ab3 // indirect 27 | github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 // indirect 28 | github.com/dustin/go-humanize v1.0.0 // indirect 29 | github.com/gogo/protobuf v1.2.1 // indirect 30 | github.com/golang/protobuf v1.5.2 // indirect 31 | github.com/golang/snappy v0.0.1 // indirect 32 | github.com/gxed/hashland/keccakpg v0.0.1 // indirect 33 | github.com/gxed/hashland/murmur3 v0.0.1 // indirect 34 | github.com/hashicorp/golang-lru v0.5.1 // indirect 35 | github.com/inconshreveable/mousetrap v1.0.0 // indirect 36 | github.com/inet256/inet256 v0.0.5 // indirect 37 | github.com/ipfs/go-ipfs-files v0.0.1 // indirect 38 | github.com/klauspost/cpuid v1.3.1 // indirect 39 | github.com/libp2p/go-flow-metrics v0.0.1 // indirect 40 | github.com/libp2p/go-libp2p-crypto v0.0.1 // indirect 41 | github.com/libp2p/go-libp2p-metrics v0.0.1 // indirect 42 | github.com/libp2p/go-libp2p-peer v0.0.1 // indirect 43 | github.com/libp2p/go-libp2p-protocol v0.0.1 // indirect 44 | github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect 45 | github.com/minio/highwayhash v1.0.2 // indirect 46 | github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 // indirect 47 | github.com/mitchellh/go-homedir v1.1.0 // indirect 48 | github.com/mr-tron/base58 v1.1.0 // indirect 49 | github.com/multiformats/go-multiaddr v0.0.1 // indirect 50 | github.com/multiformats/go-multiaddr-dns v0.0.1 // indirect 51 | github.com/multiformats/go-multiaddr-net v0.0.1 // indirect 52 | github.com/pkg/errors v0.9.1 // indirect 53 | github.com/pmezard/go-difflib v1.0.0 // indirect 54 | github.com/spf13/pflag v1.0.5 // indirect 55 | github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c // indirect 56 | golang.org/x/exp v0.0.0-20220518171630-0b5c67f07fdf // indirect 57 | golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect 58 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect 59 | golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect 60 | golang.org/x/text v0.3.7 // indirect 61 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect 62 | google.golang.org/grpc v1.33.2 // indirect 63 | google.golang.org/protobuf v1.27.1 // indirect 64 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect 65 | lukechampine.com/blake3 v1.1.5 // indirect 66 | ) 67 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 3 | github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM= 4 | github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= 5 | github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= 6 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= 7 | github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= 8 | github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= 9 | github.com/blobcache/blobcache v0.0.0-20220615224329-ce25fe33118b h1:qGIL3abcOn+lYiWbF4L2YqvjWvO0BlsAv7023vGv2ak= 10 | github.com/blobcache/blobcache v0.0.0-20220615224329-ce25fe33118b/go.mod h1:H+Ueli0WttKzmehHBNdhR6ZnNjnPd2ewDajIfRzsoiE= 11 | github.com/brendoncarroll/go-p2p v0.0.0-20220617145626-749dd26b09b0 h1:Idc/XRY+rDtdfaKsFXVUURASYhUQc2IhHBZR4v5gY+A= 12 | github.com/brendoncarroll/go-p2p v0.0.0-20220617145626-749dd26b09b0/go.mod h1:SYrjMHMGtFrl7YEgojiE4ilnE4Shvc9KQD+1JLlug+g= 13 | github.com/brendoncarroll/go-state v0.0.0-20220617134034-2613fe050888 h1:K3nefzNog9/2Uv8amsYayEQIYb+Qe1SoV7vjPPWU+RM= 14 | github.com/brendoncarroll/go-state v0.0.0-20220617134034-2613fe050888/go.mod h1:iGr/QRPP1S157c7eb5NjWI0SOr2wRk7CzZHnt/Ff+H8= 15 | github.com/brendoncarroll/go-tai64 v0.0.0-20220527232055-eab29bd93d59 h1:lQUpAM005I5qy3OsNSTPGZ7QfoHHnQzQvNjhf5nBoMA= 16 | github.com/brendoncarroll/go-tai64 v0.0.0-20220527232055-eab29bd93d59/go.mod h1:E9+Qr3YRBlU8HsajHzdoyHAm8XRqITZrtsh1gZSzu+4= 17 | github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32 h1:qkOC5Gd33k54tobS36cXdAzJbeHaduLtnLQQwNoIi78= 18 | github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= 19 | github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= 20 | github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= 21 | github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= 22 | github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= 23 | github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= 24 | github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= 25 | github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= 26 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 27 | github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= 28 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 29 | github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927 h1:SKI1/fuSdodxmNNyVBR8d7X/HuLnRpvvFO0AgyQk764= 30 | github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U= 31 | github.com/chmduquesne/rollinghash v0.0.0-20180912150627-a60f8e7142b5 h1:Wg96Dh0MLTanEaPO0OkGtUIaa2jOnShAIOVUIzRHUxo= 32 | github.com/chmduquesne/rollinghash v0.0.0-20180912150627-a60f8e7142b5/go.mod h1:Uc2I36RRfTAf7Dge82bi3RU0OQUmXT9iweIcPqvr8A0= 33 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 34 | github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= 35 | github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= 36 | github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= 37 | github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= 38 | github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= 39 | github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 40 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 41 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 42 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 43 | github.com/dgraph-io/badger/v2 v2.0.3 h1:inzdf6VF/NZ+tJ8RwwYMjJMvsOALTHYdozn0qSl6XJI= 44 | github.com/dgraph-io/badger/v2 v2.0.3/go.mod h1:3KY8+bsP8wI0OEnQJAKpd4wIJW/Mm32yw2j/9FUVnIM= 45 | github.com/dgraph-io/ristretto v0.0.2-0.20200115201040-8f368f2f2ab3 h1:MQLRM35Pp0yAyBYksjbj1nZI/w6eyRY/mWoM1sFf4kU= 46 | github.com/dgraph-io/ristretto v0.0.2-0.20200115201040-8f368f2f2ab3/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= 47 | github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= 48 | github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= 49 | github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= 50 | github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= 51 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 52 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 53 | github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= 54 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= 55 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 56 | github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= 57 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 58 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 59 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 60 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 61 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 62 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 63 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 64 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 65 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 66 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 67 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 68 | github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= 69 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 70 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= 71 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 72 | github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= 73 | github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 74 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 75 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 76 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 77 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 78 | github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 79 | github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= 80 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 81 | github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 82 | github.com/gotvc/got v0.0.3-0.20220618220735-aa388cfe7f66 h1:tlNoiODJDwa+YmBzncLPa6zIwiTQsj3kSdQ9rro/22M= 83 | github.com/gotvc/got v0.0.3-0.20220618220735-aa388cfe7f66/go.mod h1:Gk3KOO4291moIWW3ufqaPCSoKpAd/aeRQzj7lyBwF8c= 84 | github.com/gxed/hashland/keccakpg v0.0.1 h1:wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU= 85 | github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= 86 | github.com/gxed/hashland/murmur3 v0.0.1 h1:SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJu4ZbSc= 87 | github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= 88 | github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= 89 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 90 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 91 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 92 | github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= 93 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 94 | github.com/inet256/inet256 v0.0.5 h1:IdkUhSbG4kVgxXY2DePUepCraIyIiN38sZRX5x3HGLg= 95 | github.com/inet256/inet256 v0.0.5/go.mod h1:T2E5ui0P/4gS9YYAj/tFIEc/Tuq+BW3eF8IejPOZ1ho= 96 | github.com/ipfs/go-ipfs-api v0.0.1 h1:4wx4mSgeq5FwMN8LDF7WLwPDKEd+YKjgySrpOJQ2r8o= 97 | github.com/ipfs/go-ipfs-api v0.0.1/go.mod h1:0FhXgCzrLu7qNmdxZvgYqD9jFzJxzz1NAVt3OQ0WOIc= 98 | github.com/ipfs/go-ipfs-files v0.0.1 h1:OroTsI58plHGX70HPLKy6LQhPR3HZJ5ip61fYlo6POM= 99 | github.com/ipfs/go-ipfs-files v0.0.1/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4= 100 | github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc= 101 | github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= 102 | github.com/jonboulle/clockwork v0.1.1-0.20190114141812-62fb9bc030d1 h1:qBCV/RLV02TSfQa7tFmxTihnG+u+7JXByOkhlkR5rmQ= 103 | github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= 104 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 105 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 106 | github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= 107 | github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s= 108 | github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4= 109 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 110 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 111 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 112 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 113 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 114 | github.com/libp2p/go-flow-metrics v0.0.1 h1:0gxuFd2GuK7IIP5pKljLwps6TvcuYgvG7Atqi3INF5s= 115 | github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= 116 | github.com/libp2p/go-libp2p-crypto v0.0.1 h1:JNQd8CmoGTohO/akqrH16ewsqZpci2CbgYH/LmYl8gw= 117 | github.com/libp2p/go-libp2p-crypto v0.0.1/go.mod h1:yJkNyDmO341d5wwXxDUGO0LykUVT72ImHNUqh5D/dBE= 118 | github.com/libp2p/go-libp2p-metrics v0.0.1 h1:yumdPC/P2VzINdmcKZd0pciSUCpou+s0lwYCjBbzQZU= 119 | github.com/libp2p/go-libp2p-metrics v0.0.1/go.mod h1:jQJ95SXXA/K1VZi13h52WZMa9ja78zjyy5rspMsC/08= 120 | github.com/libp2p/go-libp2p-peer v0.0.1 h1:0qwAOljzYewINrU+Kndoc+1jAL7vzY/oY2Go4DCGfyY= 121 | github.com/libp2p/go-libp2p-peer v0.0.1/go.mod h1:nXQvOBbwVqoP+T5Y5nCjeH4sP9IX/J0AMzcDUVruVoo= 122 | github.com/libp2p/go-libp2p-protocol v0.0.1 h1:+zkEmZ2yFDi5adpVE3t9dqh/N9TbpFWywowzeEzBbLM= 123 | github.com/libp2p/go-libp2p-protocol v0.0.1/go.mod h1:Af9n4PiruirSDjHycM1QuiMi/1VZNHYcK8cLgFJLZ4s= 124 | github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 125 | github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= 126 | github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= 127 | github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g= 128 | github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= 129 | github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ= 130 | github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= 131 | github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= 132 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 133 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 134 | github.com/mr-tron/base58 v1.1.0 h1:Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ= 135 | github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= 136 | github.com/multiformats/go-multiaddr v0.0.1 h1:/QUV3VBMDI6pi6xfiw7lr6xhDWWvQKn9udPn68kLSdY= 137 | github.com/multiformats/go-multiaddr v0.0.1/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= 138 | github.com/multiformats/go-multiaddr-dns v0.0.1 h1:jQt9c6tDSdQLIlBo4tXYx7QUHCPjxsB1zXcag/2S7zc= 139 | github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= 140 | github.com/multiformats/go-multiaddr-net v0.0.1 h1:76O59E3FavvHqNg7jvzWzsPSW5JSi/ek0E4eiDVbg9g= 141 | github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d1tnvM7ihcFwHMSstNAVUU= 142 | github.com/multiformats/go-multihash v0.0.1 h1:HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ= 143 | github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= 144 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 145 | github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 146 | github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= 147 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 148 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 149 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 150 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 151 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 152 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 153 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 154 | github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= 155 | github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= 156 | github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= 157 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 158 | github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= 159 | github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 160 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 161 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 162 | github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= 163 | github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= 164 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 165 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 166 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 167 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 168 | github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= 169 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 170 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 171 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 172 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 173 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 174 | github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= 175 | github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c h1:GGsyl0dZ2jJgVT+VvWBf/cNijrHRhkrTjkmp5wg7li0= 176 | github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c/go.mod h1:xxcJeBb7SIUl/Wzkz1eVKJE/CB34YNrqX2TQI6jY9zs= 177 | github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= 178 | golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 179 | golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 180 | golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 181 | golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 182 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 183 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= 184 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 185 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 186 | golang.org/x/exp v0.0.0-20220518171630-0b5c67f07fdf h1:oXVg4h2qJDd9htKxb5SCpFBHLipW6hXmL3qpUixS2jw= 187 | golang.org/x/exp v0.0.0-20220518171630-0b5c67f07fdf/go.mod h1:yh0Ynu2b5ZUe3MQfp2nM0ecK7wsgouWTDN0FNeJuIys= 188 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 189 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 190 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 191 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 192 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 193 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 194 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 195 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 196 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 197 | golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY= 198 | golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 199 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 200 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 201 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 202 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 203 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= 204 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 205 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 206 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 207 | golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 208 | golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 209 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 210 | golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 211 | golang.org/x/sys v0.0.0-20190302025703-b6889370fb10/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 212 | golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 213 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 214 | golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0= 215 | golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 216 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 217 | golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= 218 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 219 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 220 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 221 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 222 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 223 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 224 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 225 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= 226 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 227 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 228 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 229 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 230 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= 231 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= 232 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 233 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= 234 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= 235 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 236 | google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= 237 | google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= 238 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 239 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 240 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 241 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 242 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 243 | google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 244 | google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 245 | google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= 246 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 247 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 248 | google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= 249 | google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 250 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 251 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 252 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 253 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 254 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 255 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 256 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 257 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 258 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 259 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 260 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 261 | lukechampine.com/blake3 v1.1.5 h1:hsACfxWvLdGmjYbWGrumQIphOvO+ZruZehWtgd2fxoM= 262 | lukechampine.com/blake3 v1.1.5/go.mod h1:hE8RpzdO8ttZ7446CXEwDP1eu2V4z7stv0Urj1El20g= 263 | -------------------------------------------------------------------------------- /pkg/cells/filecell/filecell.go: -------------------------------------------------------------------------------- 1 | package filecell 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "io/ioutil" 7 | "sync" 8 | 9 | "github.com/brendoncarroll/go-state/posixfs" 10 | ) 11 | 12 | type Cell struct { 13 | mu sync.Mutex 14 | fs posixfs.FS 15 | p string 16 | } 17 | 18 | func New(pfs posixfs.FS, p string) *Cell { 19 | c := &Cell{fs: pfs, p: p} 20 | return c 21 | } 22 | 23 | func (c *Cell) Read(ctx context.Context, buf []byte) (int, error) { 24 | c.mu.Lock() 25 | defer c.mu.Unlock() 26 | data, err := posixfs.ReadFile(ctx, c.fs, c.p) 27 | if err != nil && !posixfs.IsErrNotExist(err) { 28 | return 0, err 29 | } 30 | return copy(buf, data), nil 31 | } 32 | 33 | func (c *Cell) CAS(ctx context.Context, actual, prev, next []byte) (bool, int, error) { 34 | c.mu.Lock() 35 | defer c.mu.Unlock() 36 | data, err := posixfs.ReadFile(ctx, c.fs, c.p) 37 | if err != nil && !posixfs.IsErrNotExist(err) { 38 | return false, 0, err 39 | } 40 | var swapped bool 41 | if bytes.Equal(prev, data) { 42 | if err := ioutil.WriteFile(c.p, next, 0644); err != nil { 43 | return false, 0, err 44 | } 45 | swapped = true 46 | data = next 47 | } else { 48 | swapped = false 49 | } 50 | return swapped, copy(actual, data), nil 51 | } 52 | 53 | func (c *Cell) MaxSize() int { 54 | return 1 << 16 55 | } 56 | -------------------------------------------------------------------------------- /pkg/cells/gotcells/gbcell.go: -------------------------------------------------------------------------------- 1 | package gotcells 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "errors" 7 | 8 | "github.com/brendoncarroll/go-state/cadata" 9 | "github.com/brendoncarroll/go-state/cells" 10 | "github.com/gotvc/got/pkg/gotvc" 11 | ) 12 | 13 | type BranchCell struct { 14 | inner cells.Cell 15 | gotvc *gotvc.Operator 16 | vcStore cadata.Store 17 | } 18 | 19 | func NewBranch(inner cells.Cell, vcop *gotvc.Operator, vcStore cadata.Store) *BranchCell { 20 | return &BranchCell{ 21 | inner: inner, 22 | gotvc: vcop, 23 | vcStore: vcStore, 24 | } 25 | } 26 | 27 | func (c *BranchCell) Read(ctx context.Context, buf []byte) (int, error) { 28 | n, err := c.inner.Read(ctx, buf) 29 | if err != nil { 30 | return 0, err 31 | } 32 | if n == 0 { 33 | return n, nil 34 | } 35 | var snap gotvc.Snap 36 | if err := json.Unmarshal(buf[:n], &snap); err != nil { 37 | return 0, err 38 | } 39 | data, err := json.Marshal(snap.Root) 40 | if err != nil { 41 | return 0, err 42 | } 43 | return copy(buf, data), nil 44 | } 45 | 46 | func (c *BranchCell) CAS(ctx context.Context, actual, prev, next []byte) (bool, int, error) { 47 | return false, 0, errors.New("writing to got branches not yet supported") 48 | } 49 | 50 | func (c *BranchCell) MaxSize() int { 51 | return 1 << 10 52 | } 53 | -------------------------------------------------------------------------------- /pkg/stores/httpstore/client.go.dont: -------------------------------------------------------------------------------- 1 | package httpstore 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "encoding/base64" 7 | "errors" 8 | "fmt" 9 | "io" 10 | "io/ioutil" 11 | "log" 12 | "net/http" 13 | 14 | "github.com/brendoncarroll/go-state/cadata" 15 | "github.com/brendoncarroll/webfs/pkg/stores" 16 | "github.com/multiformats/go-multihash" 17 | ) 18 | 19 | type HttpStore struct { 20 | endpoint string 21 | maxBlobSize int 22 | headers map[string]string 23 | hc *http.Client 24 | } 25 | 26 | func New(endpoint string, hf cadata.HashFunc, maxSize int, headers map[string]string) *HttpStore { 27 | s := &HttpStore{ 28 | endpoint: endpoint, 29 | hc: http.DefaultClient, 30 | headers: headers, 31 | maxBlobSize: -1, 32 | } 33 | return s 34 | } 35 | 36 | func (hs *HttpStore) Get(ctx context.Context, id cadata.ID, buf []byte) (int, error) { 37 | req := hs.newRequest(ctx, http.MethodGet, hs.getURL(id), nil) 38 | 39 | resp, err := hs.hc.Do(req) 40 | if err != nil { 41 | return 0, err 42 | } 43 | defer func() { 44 | if err := resp.Body.Close(); err != nil { 45 | log.Println(err) 46 | } 47 | }() 48 | if resp.StatusCode == http.StatusNotFound { 49 | return 0, stores.ErrNotFound 50 | } 51 | if resp.StatusCode != http.StatusOK { 52 | return 0, errorFromRes(resp) 53 | } 54 | 55 | data, err := ioutil.ReadAll(resp.Body) 56 | if err != nil { 57 | return 0, err 58 | } 59 | 60 | if hs.validateMH { 61 | mhBytes, err := base64.URLEncoding.DecodeString(key) 62 | if err != nil { 63 | return nil, err 64 | } 65 | want, err := multihash.Decode(mhBytes) 66 | if err != nil { 67 | return nil, err 68 | } 69 | 70 | actual, err := multihash.Sum(data, want.Code, want.Length) 71 | if err != nil { 72 | return nil, err 73 | } 74 | if bytes.Compare(mhBytes, actual) != 0 { 75 | return nil, errors.New("got bad data from store") 76 | } 77 | } 78 | 79 | return data, nil 80 | } 81 | 82 | func (hs *HttpStore) Check(ctx context.Context, key string) (err error) { 83 | u := hs.getURL(key) 84 | req := hs.newRequest(ctx, http.MethodHead, u, nil) 85 | resp, err := hs.hc.Do(req) 86 | if err != nil { 87 | return err 88 | } 89 | ok := resp.StatusCode == http.StatusOK 90 | if !ok { 91 | return errors.New("status: " + resp.Status) 92 | } 93 | return nil 94 | } 95 | 96 | func (hs *HttpStore) Post(ctx context.Context, prefix string, data []byte) (string, error) { 97 | if len(prefix) > 0 { 98 | return "", errors.New("prefix must be empty") 99 | } 100 | if len(data) > hs.maxBlobSize { 101 | return "", stores.ErrMaxSizeExceeded 102 | } 103 | 104 | buf := bytes.NewBuffer(data) 105 | req := hs.newRequest(ctx, http.MethodPost, hs.endpoint, buf) 106 | resp, err := hs.hc.Do(req) 107 | if err != nil { 108 | return "", err 109 | } 110 | defer func() { 111 | if err := resp.Body.Close(); err != nil { 112 | log.Println(err) 113 | } 114 | }() 115 | 116 | body, err := ioutil.ReadAll(resp.Body) 117 | if err != nil { 118 | return "", err 119 | } 120 | if resp.StatusCode != http.StatusOK { 121 | return "", errorFromRes(resp) 122 | } 123 | 124 | if hs.validateMH { 125 | mhBytes := make([]byte, enc.DecodedLen(len(body))) 126 | n, err := enc.Decode(mhBytes, body) 127 | if err != nil { 128 | return "", err 129 | } 130 | mhBytes = mhBytes[:n] 131 | 132 | mh, err := multihash.Decode(mhBytes) 133 | if err != nil { 134 | return "", err 135 | } 136 | mh2, err := multihash.Sum(data, mh.Code, mh.Length) 137 | if err != nil { 138 | return "", err 139 | } 140 | if bytes.Compare(mhBytes, mh2) != 0 { 141 | return "", errors.New("server gave bad multihash for data") 142 | } 143 | } 144 | 145 | return string(body), nil 146 | } 147 | 148 | func (hs *HttpStore) MaxBlobSize() int { 149 | return hs.maxBlobSize 150 | } 151 | 152 | func (hs *HttpStore) Delete(ctx context.Context, key string) (err error) { 153 | u := hs.getURL(key) 154 | 155 | req := hs.newRequest(ctx, http.MethodDelete, u, nil) 156 | 157 | resp, err := http.DefaultClient.Do(req) 158 | if err != nil { 159 | return err 160 | } 161 | if resp.StatusCode != http.StatusOK { 162 | return errorFromRes(resp) 163 | } 164 | return nil 165 | } 166 | 167 | func (hs *HttpStore) getURL(x string) string { 168 | y := hs.endpoint 169 | if y[len(y)-1] != '/' { 170 | y += "/" 171 | } 172 | y += x 173 | return y 174 | } 175 | 176 | func (hs *HttpStore) newRequest(ctx context.Context, method, u string, body io.Reader) *http.Request { 177 | r, err := http.NewRequest(method, u, body) 178 | if err != nil { 179 | panic(err) 180 | } 181 | r = r.WithContext(ctx) 182 | for k, v := range hs.headers { 183 | r.Header.Set(k, v) 184 | } 185 | return r 186 | } 187 | 188 | func errorFromRes(r *http.Response) error { 189 | body, err := ioutil.ReadAll(r.Body) 190 | if err != nil { 191 | log.Println(err) 192 | } 193 | msg := string(body) 194 | return fmt.Errorf("%s: %s", r.Status, msg) 195 | } 196 | -------------------------------------------------------------------------------- /pkg/stores/httpstore/httpstore_test.go.dont: -------------------------------------------------------------------------------- 1 | package httpstore 2 | 3 | import ( 4 | "context" 5 | mrand "math/rand" 6 | "testing" 7 | 8 | "github.com/stretchr/testify/assert" 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestStore(t *testing.T) { 13 | storetest.TestStore(t, func(t testing.TB) cadata.Store { 14 | ctx := context.Background() 15 | s, err := NewServer("127.0.0.1:", 4096) 16 | require.NoError(t, err) 17 | 18 | c := New(s.GetURL(), nil) 19 | err = c.Init(ctx) 20 | require.NoError(t, err) 21 | return s 22 | }) 23 | } 24 | -------------------------------------------------------------------------------- /pkg/stores/httpstore/server.go.dont: -------------------------------------------------------------------------------- 1 | package httpstore 2 | 3 | import ( 4 | "encoding/base64" 5 | "errors" 6 | "fmt" 7 | "io" 8 | "log" 9 | "net" 10 | "net/http" 11 | "sync" 12 | 13 | "github.com/multiformats/go-multihash" 14 | "golang.org/x/crypto/sha3" 15 | ) 16 | 17 | var enc = base64.URLEncoding 18 | 19 | type Server struct { 20 | maxBlobSize int 21 | l net.Listener 22 | m sync.Map 23 | } 24 | 25 | func NewServer(laddr string, maxBlobSize int) (*Server, error) { 26 | l, err := net.Listen("tcp", laddr) 27 | if err != nil { 28 | return nil, err 29 | } 30 | s := &Server{ 31 | l: l, 32 | maxBlobSize: maxBlobSize, 33 | } 34 | go func() { 35 | if err := http.Serve(l, s); err != nil { 36 | log.Println(err) 37 | } 38 | }() 39 | return s, nil 40 | } 41 | 42 | func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { 43 | switch r.Method { 44 | case http.MethodPost: 45 | s.post(w, r) 46 | case http.MethodGet: 47 | if r.URL.Path == "/.maxBlobSize" { 48 | fmt.Fprint(w, s.maxBlobSize) 49 | return 50 | } 51 | s.get(w, r) 52 | case http.MethodHead: 53 | s.head(w, r) 54 | case http.MethodDelete: 55 | s.delete(w, r) 56 | default: 57 | w.WriteHeader(http.StatusBadRequest) 58 | } 59 | } 60 | 61 | func (s *Server) LocalAddr() string { 62 | return s.l.Addr().String() 63 | } 64 | 65 | func (s *Server) Close() error { 66 | return s.l.Close() 67 | } 68 | 69 | func (s *Server) GetURL() string { 70 | return "http://" + s.LocalAddr() 71 | } 72 | 73 | func (s *Server) get(w http.ResponseWriter, r *http.Request) { 74 | mh, err := getID(r) 75 | if err != nil { 76 | w.WriteHeader(http.StatusBadRequest) 77 | return 78 | } 79 | 80 | v, ok := s.m.Load(string(mh)) 81 | if !ok { 82 | w.WriteHeader(http.StatusNotFound) 83 | return 84 | } 85 | 86 | w.WriteHeader(http.StatusOK) 87 | w.Write(v.([]byte)) 88 | } 89 | 90 | func (s *Server) post(w http.ResponseWriter, r *http.Request) { 91 | buf := make([]byte, s.maxBlobSize) 92 | 93 | total := 0 94 | for total < len(buf) { 95 | n, err := r.Body.Read(buf[total:]) 96 | total += n 97 | if err == io.EOF { 98 | break 99 | } else if err != nil { 100 | w.WriteHeader(http.StatusBadRequest) 101 | return 102 | } 103 | } 104 | data := buf[:total] 105 | 106 | h := sha3.Sum256(data) 107 | mh, err := multihash.Encode(h[:], multihash.SHA3_256) 108 | if err != nil { 109 | panic(err) 110 | } 111 | 112 | s.m.Store(string(mh), data) 113 | 114 | resp := make([]byte, enc.EncodedLen(len(mh))) 115 | enc.Encode(resp, mh) 116 | 117 | w.WriteHeader(http.StatusOK) 118 | w.Write(resp) 119 | } 120 | 121 | func (s *Server) head(w http.ResponseWriter, r *http.Request) { 122 | mh, err := getID(r) 123 | if err != nil { 124 | w.WriteHeader(http.StatusBadRequest) 125 | return 126 | } 127 | _, exists := s.m.Load(string(mh)) 128 | if !exists { 129 | w.WriteHeader(http.StatusNotFound) 130 | } 131 | w.WriteHeader(http.StatusOK) 132 | } 133 | 134 | func (s *Server) delete(w http.ResponseWriter, r *http.Request) { 135 | mh, err := getID(r) 136 | if err != nil { 137 | w.WriteHeader(http.StatusBadRequest) 138 | return 139 | } 140 | _, exists := s.m.Load(string(mh)) 141 | if !exists { 142 | w.WriteHeader(http.StatusNotFound) 143 | } 144 | s.m.Delete(string(mh)) 145 | w.WriteHeader(http.StatusOK) 146 | } 147 | 148 | func getID(r *http.Request) ([]byte, error) { 149 | p := r.URL.Path 150 | if len(p) < 2 { 151 | return nil, errors.New("bad path") 152 | } 153 | p = p[1:] 154 | return enc.DecodeString(p) 155 | } 156 | -------------------------------------------------------------------------------- /pkg/stores/ipfsstore/ipfsstore.go: -------------------------------------------------------------------------------- 1 | package ipfsstore 2 | 3 | import ( 4 | "context" 5 | "io" 6 | 7 | "github.com/brendoncarroll/go-state/cadata" 8 | ipfsapi "github.com/ipfs/go-ipfs-api" 9 | "github.com/multiformats/go-multihash" 10 | "golang.org/x/crypto/blake2b" 11 | ) 12 | 13 | const ( 14 | MaxBlobSize = 1 << 20 // 1MiB 15 | 16 | DefaultMHType = "blake2b-256" 17 | DefaultMHLen = 32 18 | 19 | DefaultLocalURL = "http://127.0.0.1:5001" 20 | OfficialGatewayURL = "https://ipfs.io" 21 | CloudflareURL = "https://cloudflare-ipfs.com" 22 | ) 23 | 24 | type ipfsClient struct { 25 | client *ipfsapi.Shell 26 | } 27 | 28 | func New(client *ipfsapi.Shell) cadata.Store { 29 | return &ipfsClient{client: client} 30 | } 31 | 32 | func (s *ipfsClient) Get(ctx context.Context, id cadata.ID, buf []byte) (int, error) { 33 | data, err := s.client.BlockGet("") 34 | if err != nil { 35 | return 0, err 36 | } 37 | if len(buf) < len(data) { 38 | return 0, io.ErrShortBuffer 39 | } 40 | return copy(buf, data), nil 41 | } 42 | 43 | func (s *ipfsClient) Post(ctx context.Context, data []byte) (cadata.ID, error) { 44 | var ( 45 | format = "" 46 | mhtype = DefaultMHType 47 | mhlen = DefaultMHLen 48 | ) 49 | k, err := s.client.BlockPut(data, format, mhtype, mhlen) 50 | if err != nil { 51 | return cadata.ID{}, err 52 | } 53 | mh, err := multihash.Decode([]byte(k)) 54 | if err != nil { 55 | return cadata.ID{}, err 56 | } 57 | return cadata.IDFromBytes(mh.Digest), nil 58 | } 59 | 60 | func (s *ipfsClient) List(ctx context.Context, span cadata.Span, ids []cadata.ID) (int, error) { 61 | panic("not implemented") 62 | } 63 | 64 | func (s *ipfsClient) Delete(ctx context.Context, id cadata.ID) error { 65 | panic("not implemented") 66 | } 67 | 68 | func (s *ipfsClient) Hash(x []byte) cadata.ID { 69 | return blake2b.Sum256(x) 70 | } 71 | 72 | func (s *ipfsClient) MaxSize() int { 73 | return MaxBlobSize 74 | } 75 | -------------------------------------------------------------------------------- /pkg/webfs/errors.go: -------------------------------------------------------------------------------- 1 | package webfs 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // ErrBadConfig is returned when WebFS encounters an invalid config which it cannot mount. 8 | type ErrBadConfig struct { 9 | Path string 10 | Data []byte 11 | Inner error 12 | } 13 | 14 | func (e ErrBadConfig) Cause() error { 15 | return e.Inner 16 | } 17 | 18 | func (e ErrBadConfig) Error() string { 19 | return fmt.Sprintf("bad webfs config at path %q. data=%q error=%v", e.Path, e.Data, e.Inner) 20 | } 21 | -------------------------------------------------------------------------------- /pkg/webfs/file.go: -------------------------------------------------------------------------------- 1 | package webfs 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "fmt" 7 | "io" 8 | iofs "io/fs" 9 | "time" 10 | 11 | "github.com/brendoncarroll/go-state/posixfs" 12 | ) 13 | 14 | var ( 15 | _ io.Reader = &File{} 16 | _ io.ReaderAt = &File{} 17 | ) 18 | 19 | type File struct { 20 | vol *volumeMount 21 | path string 22 | 23 | ctx context.Context 24 | offset int64 25 | } 26 | 27 | func newFile(vol *volumeMount, path string) *File { 28 | return &File{ 29 | vol: vol, 30 | path: path, 31 | ctx: context.Background(), 32 | } 33 | } 34 | 35 | func (f *File) Read(p []byte) (int, error) { 36 | n, err := f.ReadAt(p, f.offset) 37 | if err != nil && !errors.Is(err, io.EOF) { 38 | return 0, err 39 | } 40 | f.offset += int64(n) 41 | return n, err 42 | } 43 | 44 | func (f *File) ReadAt(buf []byte, offset int64) (int, error) { 45 | root, err := readRoot(f.ctx, f.vol.vol.Cell) 46 | if err != nil { 47 | return 0, err 48 | } 49 | if root == nil { 50 | return 0, iofs.ErrNotExist 51 | } 52 | if offset < 0 { 53 | return 0, fmt.Errorf("invalid offset %d", offset) 54 | } 55 | s := f.vol.vol.Store 56 | return f.vol.gotfs.ReadFileAt(f.ctx, s, s, *root, f.path, uint64(offset), buf) 57 | } 58 | 59 | func (f *File) Stat() (iofs.FileInfo, error) { 60 | return f.vol.Stat(f.ctx, f.path) 61 | } 62 | 63 | func (f *File) Sync() error { 64 | return nil 65 | } 66 | 67 | func (f *File) ReadDir(n int) (ret []iofs.DirEntry, _ error) { 68 | return f.vol.readDir(f.ctx, f.path, n) 69 | } 70 | 71 | func (f *File) Close() error { 72 | return nil 73 | } 74 | 75 | type fileInfo struct { 76 | name string 77 | mode iofs.FileMode 78 | size int64 79 | modTime time.Time 80 | } 81 | 82 | func (fi fileInfo) Name() string { 83 | return fi.name 84 | } 85 | 86 | func (fi fileInfo) Size() int64 { 87 | return fi.size 88 | } 89 | 90 | func (fi fileInfo) Mode() iofs.FileMode { 91 | return fi.mode 92 | } 93 | 94 | func (fi fileInfo) IsDir() bool { 95 | return fi.mode.IsDir() 96 | } 97 | 98 | func (fi fileInfo) ModTime() time.Time { 99 | return fi.modTime 100 | } 101 | 102 | func (fi fileInfo) Sys() any { 103 | return nil 104 | } 105 | 106 | var _ iofs.DirEntry = &dirEntry{} 107 | 108 | type dirEntry struct { 109 | name string 110 | mode iofs.FileMode 111 | getInfo func() (*fileInfo, error) 112 | } 113 | 114 | func (de *dirEntry) Name() string { 115 | return de.name 116 | } 117 | 118 | func (de *dirEntry) IsDir() bool { 119 | return de.mode.IsDir() 120 | } 121 | 122 | func (de *dirEntry) Type() iofs.FileMode { 123 | return de.mode.Type() 124 | } 125 | 126 | func (de *dirEntry) Info() (iofs.FileInfo, error) { 127 | return de.getInfo() 128 | } 129 | 130 | func convertError(err error) error { 131 | switch { 132 | case err == nil: 133 | return nil 134 | case errors.Is(err, posixfs.ErrNotExist): 135 | return iofs.ErrNotExist 136 | default: 137 | return err 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /pkg/webfs/option.go: -------------------------------------------------------------------------------- 1 | package webfs 2 | 3 | import ( 4 | "context" 5 | "net" 6 | "os" 7 | "path/filepath" 8 | 9 | bcclient "github.com/blobcache/blobcache/client/go_client" 10 | "github.com/brendoncarroll/go-state/posixfs" 11 | ipfsapi "github.com/ipfs/go-ipfs-api" 12 | "github.com/sirupsen/logrus" 13 | ) 14 | 15 | type fsConfig struct { 16 | log logrus.FieldLogger 17 | pfs posixfs.FS 18 | dialer TCPDialer 19 | blobcacheEndpoint string 20 | ipfs *ipfsapi.Shell 21 | } 22 | 23 | func defaultConfig() fsConfig { 24 | return fsConfig{ 25 | log: logrus.StandardLogger(), 26 | pfs: posixfs.NewDirFS(filepath.Join(os.TempDir(), "webfs")), 27 | blobcacheEndpoint: bcclient.DefaultEndpoint, 28 | } 29 | } 30 | 31 | // Option is used to configure a WebFS instance. 32 | type Option func(c *fsConfig) 33 | 34 | // WithPosixFS sets x as the filesystem to use for file backed cells. 35 | func WithPosixFS(x posixfs.FS) Option { 36 | return func(c *fsConfig) { 37 | c.pfs = x 38 | } 39 | } 40 | 41 | type TCPDialer = func(context.Context, string) (net.Conn, error) 42 | 43 | // WithTCPDialer sets the dialer used for outbound TCP connections. 44 | func WithTCPDialer(d func(context.Context, string) (net.Conn, error)) Option { 45 | return func(c *fsConfig) { 46 | c.dialer = d 47 | } 48 | } 49 | 50 | // WithBlobcache sets the endpoint to connect to the blobcache daemon 51 | func WithBlobcache(endpoint string) Option { 52 | return func(c *fsConfig) { 53 | c.blobcacheEndpoint = endpoint 54 | } 55 | } 56 | 57 | // WithLogger sets the logger for the WebFS instance 58 | func WithLogger(l logrus.FieldLogger) Option { 59 | return func(c *fsConfig) { 60 | c.log = l 61 | } 62 | } 63 | 64 | func WithIPFS(shell *ipfsapi.Shell) Option { 65 | return func(c *fsConfig) { 66 | c.ipfs = shell 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /pkg/webfs/specs.go: -------------------------------------------------------------------------------- 1 | package webfs 2 | 3 | import ( 4 | "crypto/cipher" 5 | "encoding/json" 6 | "errors" 7 | "fmt" 8 | "os" 9 | "strings" 10 | 11 | bcclient "github.com/blobcache/blobcache/client/go_client" 12 | "github.com/blobcache/blobcache/pkg/blobcache" 13 | "github.com/brendoncarroll/go-state/cadata" 14 | "github.com/brendoncarroll/go-state/cadata/fsstore" 15 | "github.com/brendoncarroll/go-state/cells" 16 | "github.com/brendoncarroll/go-state/cells/cryptocell" 17 | "github.com/brendoncarroll/go-state/cells/httpcell" 18 | "github.com/brendoncarroll/go-state/posixfs" 19 | "golang.org/x/crypto/chacha20poly1305" 20 | 21 | "github.com/brendoncarroll/webfs/pkg/cells/filecell" 22 | "github.com/brendoncarroll/webfs/pkg/cells/gotcells" 23 | "github.com/brendoncarroll/webfs/pkg/stores/ipfsstore" 24 | ) 25 | 26 | // VolumeSpec is a specification for a Volume. 27 | type VolumeSpec struct { 28 | Cell CellSpec `json:"cell"` 29 | Store StoreSpec `json:"store"` 30 | Salt []byte `json:"salt"` 31 | } 32 | 33 | func (vs VolumeSpec) Fingerprint() [32]byte { 34 | data, _ := json.Marshal(vs) 35 | return Hash(data) 36 | } 37 | 38 | // ParseVolumeSpec parses a JSON formatted VolumeSpec from x. 39 | func ParseVolumeSpec(x []byte) (*VolumeSpec, error) { 40 | var spec VolumeSpec 41 | if err := json.Unmarshal(x, &spec); err != nil { 42 | return nil, err 43 | } 44 | return &spec, nil 45 | } 46 | 47 | func MarshalVolumeSpec(x VolumeSpec) ([]byte, error) { 48 | return json.MarshalIndent(x, "", " ") 49 | } 50 | 51 | // CellSpec is a specification for a Cell 52 | type CellSpec struct { 53 | Memory *struct{} `json:"memory,omitempty"` 54 | File *string `json:"file,omitempty"` 55 | HTTP *HTTPCellSpec `json:"http,omitempty"` 56 | Literal json.RawMessage `json:"literal,omitempty"` 57 | 58 | AEAD *AEADCellSpec `json:"aead,omitempty"` 59 | GotBranch *GotBranchCellSpec `json:"got_branch,omitempty"` 60 | } 61 | 62 | type HTTPCellSpec struct { 63 | URL string `json:"url"` 64 | Headers map[string]string `json:"headers,omitempty"` 65 | } 66 | 67 | type AEADCellSpec struct { 68 | Inner CellSpec `json:"inner"` 69 | Algo string `json:"algo"` 70 | Secret []byte `json:"secret"` 71 | } 72 | 73 | type GotBranchCellSpec struct { 74 | Inner CellSpec `json:"inner"` 75 | VCStore StoreSpec `json:"vc_store"` 76 | } 77 | 78 | type StoreSpec struct { 79 | Memory *struct{} `json:"memory,omitempty"` 80 | FS *string `json:"fs,omitempty"` 81 | HTTP HTTPStoreSpec `json:"http,omitempty"` 82 | Blobcache *BlobcacheStoreSpec `json:"blobcache,omitempty"` 83 | IPFS *IPFSStoreSpec `json:"ipfs,omitempty"` 84 | } 85 | 86 | type HTTPStoreSpec struct { 87 | URL string `json:"url"` 88 | Headers map[string]string `json:"headers"` 89 | } 90 | 91 | type BlobcacheStoreSpec struct{} 92 | 93 | type IPFSStoreSpec struct{} 94 | 95 | func (fs *FS) makeVolume(spec VolumeSpec) (*Volume, error) { 96 | cell, err := fs.makeCell(spec.Cell) 97 | if err != nil { 98 | return nil, err 99 | } 100 | store, err := fs.makeStore(spec.Store) 101 | if err != nil { 102 | return nil, err 103 | } 104 | return &Volume{ 105 | Cell: cell, 106 | Store: store, 107 | }, nil 108 | } 109 | 110 | func (fs *FS) makeCell(spec CellSpec) (cells.Cell, error) { 111 | switch { 112 | case spec.Memory != nil: 113 | return cells.NewMem(1 << 16), nil 114 | case spec.File != nil: 115 | return filecell.New(fs.fs, *spec.File), nil 116 | case spec.HTTP != nil: 117 | return httpcell.New(httpcell.Spec{ 118 | URL: spec.HTTP.URL, 119 | Headers: spec.HTTP.Headers, 120 | }), nil 121 | case spec.Literal != nil: 122 | panic("not implemented") 123 | 124 | case spec.AEAD != nil: 125 | inner, err := fs.makeCell(spec.AEAD.Inner) 126 | if err != nil { 127 | return nil, err 128 | } 129 | var aead cipher.AEAD 130 | algo := strings.ToLower(spec.AEAD.Algo) 131 | switch algo { 132 | case "chacha20poly1305": 133 | aead, err = chacha20poly1305.NewX(spec.AEAD.Secret) 134 | if err != nil { 135 | return nil, err 136 | } 137 | default: 138 | return nil, fmt.Errorf("unsupported AEAD: %q", algo) 139 | } 140 | return cryptocell.NewAEAD(inner, aead), nil 141 | case spec.GotBranch != nil: 142 | inner, err := fs.makeCell(spec.GotBranch.Inner) 143 | if err != nil { 144 | return nil, err 145 | } 146 | // vcstore, err := fs.makeStore(spec.GotBranch.VCStore) 147 | // if err != nil { 148 | // return nil, err 149 | // } 150 | return gotcells.NewBranch(inner, nil, nil), nil 151 | default: 152 | return nil, errors.New("empty cell spec") 153 | } 154 | } 155 | 156 | func (fs *FS) makeStore(spec StoreSpec) (cadata.Store, error) { 157 | switch { 158 | case spec.Memory != nil: 159 | return cadata.NewMem(Hash, MaxBlobSize), nil 160 | case spec.FS != nil: 161 | if err := os.MkdirAll(*spec.FS, 0o755); err != nil { 162 | return nil, err 163 | } 164 | pfs := posixfs.NewDirFS(*spec.FS) 165 | return fsstore.New(pfs, Hash, MaxBlobSize), nil 166 | case spec.Blobcache != nil: 167 | c, err := bcclient.NewClient(fs.config.blobcacheEndpoint) 168 | if err != nil { 169 | return nil, err 170 | } 171 | // TODO: need to set handle 172 | return blobcache.NewStore(c, blobcache.Handle{}), nil 173 | case spec.IPFS != nil: 174 | return ipfsstore.New(fs.config.ipfs), nil 175 | default: 176 | return nil, errors.New("empty store spec") 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /pkg/webfs/webfs.go: -------------------------------------------------------------------------------- 1 | package webfs 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "errors" 7 | "io" 8 | iofs "io/fs" 9 | "path" 10 | "strings" 11 | "time" 12 | 13 | "github.com/brendoncarroll/go-state/cadata" 14 | "github.com/brendoncarroll/go-state/cells" 15 | "github.com/brendoncarroll/go-state/posixfs" 16 | "github.com/gotvc/got/pkg/gdat" 17 | "github.com/gotvc/got/pkg/gotfs" 18 | "github.com/sirupsen/logrus" 19 | ) 20 | 21 | const ( 22 | MaxBlobSize = gotfs.DefaultMaxBlobSize 23 | ) 24 | 25 | func Hash(x []byte) cadata.ID { 26 | return gdat.Hash(x) 27 | } 28 | 29 | type Volume struct { 30 | Cell cells.Cell 31 | Store cadata.Store 32 | Salt []byte 33 | } 34 | 35 | // FS is an instance of a WebFS filesystem 36 | type FS struct { 37 | config *fsConfig 38 | fs posixfs.FS 39 | log logrus.FieldLogger 40 | 41 | root *volumeMount 42 | } 43 | 44 | func New(vspec VolumeSpec, opts ...Option) (*FS, error) { 45 | config := defaultConfig() 46 | for _, opt := range opts { 47 | opt(&config) 48 | } 49 | fs := &FS{ 50 | config: &config, 51 | fs: config.pfs, 52 | log: config.log, 53 | } 54 | root, err := fs.getVolumeMount(context.Background(), nil, "", &vspec) 55 | if err != nil { 56 | return nil, err 57 | } 58 | fs.root = root 59 | return fs, nil 60 | } 61 | 62 | func (fs *FS) Open(ctx context.Context, p string) (*File, error) { 63 | res, err := fs.resolve(ctx, fs.root, p) 64 | if err != nil { 65 | return nil, err 66 | } 67 | fs.log.Infof("open %q", p) 68 | return res.VM.Open(res.Path) 69 | } 70 | 71 | func (fs *FS) PutFile(ctx context.Context, p string, r io.Reader) error { 72 | res, err := fs.resolve(ctx, fs.root, p) 73 | if err != nil { 74 | return err 75 | } 76 | return res.VM.PutFile(ctx, res.Path, r) 77 | } 78 | 79 | func (fs *FS) Mkdir(ctx context.Context, p string) error { 80 | res, err := fs.resolve(ctx, fs.root, p) 81 | if err != nil { 82 | return err 83 | } 84 | return res.VM.Mkdir(ctx, res.Path) 85 | } 86 | 87 | func (fs *FS) Remove(ctx context.Context, p string) error { 88 | res, err := fs.resolve(ctx, fs.root, p) 89 | if err != nil { 90 | return err 91 | } 92 | return res.VM.Rm(ctx, p) 93 | } 94 | 95 | func (fs *FS) Cat(ctx context.Context, p string, w io.Writer) error { 96 | f, err := fs.Open(ctx, p) 97 | if err != nil { 98 | return err 99 | } 100 | defer f.Close() 101 | _, err = io.Copy(w, f) 102 | return err 103 | } 104 | 105 | func (fs *FS) Ls(ctx context.Context, p string, fn func(iofs.DirEntry) error) error { 106 | f, err := fs.Open(ctx, p) 107 | if err != nil { 108 | return err 109 | } 110 | defer f.Close() 111 | dirEnts, err := f.ReadDir(0) 112 | if err != nil { 113 | return err 114 | } 115 | for _, dirEnt := range dirEnts { 116 | if err := fn(dirEnt); err != nil { 117 | return err 118 | } 119 | } 120 | return nil 121 | } 122 | 123 | func (fs *FS) getVolumeMount(ctx context.Context, parent *volumeMount, p string, spec *VolumeSpec) (*volumeMount, error) { 124 | vol, err := fs.makeVolume(*spec) 125 | if err != nil { 126 | return nil, err 127 | } 128 | var seed [32]byte 129 | copy(seed[:], spec.Salt) 130 | return &volumeMount{ 131 | parent: parent, 132 | path: p, 133 | vol: *vol, 134 | gotfs: gotfs.NewOperator(gotfs.WithSeed(&seed), gotfs.WithContentCacheSize(10), gotfs.WithMetaCacheSize(128)), 135 | }, nil 136 | } 137 | 138 | type resolveRes struct { 139 | VM *volumeMount 140 | Path string 141 | } 142 | 143 | func (fs *FS) resolve(ctx context.Context, vm *volumeMount, p string) (*resolveRes, error) { 144 | p = cleanPath(p) 145 | root, err := readRoot(ctx, vm.vol.Cell) 146 | if err != nil { 147 | return nil, err 148 | } 149 | if root != nil { 150 | for _, configPath := range potConfigPaths(p) { 151 | vs, err := loadWebFSConfig(ctx, &vm.gotfs, vm.vol.Store, *root, configPath) 152 | if err != nil { 153 | return nil, err 154 | } 155 | if vs == nil { 156 | continue 157 | } 158 | mountPath := path.Dir(configPath) 159 | vm2, err := fs.getVolumeMount(ctx, vm, mountPath, vs) 160 | if err != nil { 161 | return nil, err 162 | } 163 | p2 := cleanPath(p[len(mountPath):]) 164 | return fs.resolve(ctx, vm2, p2) 165 | } 166 | } 167 | return &resolveRes{ 168 | VM: vm, 169 | Path: p, 170 | }, nil 171 | } 172 | 173 | type volumeMount struct { 174 | parent *volumeMount 175 | path string 176 | 177 | vol Volume 178 | gotfs gotfs.Operator 179 | } 180 | 181 | func (v *volumeMount) Open(p string) (*File, error) { 182 | return newFile(v, p), nil 183 | } 184 | 185 | func (v *volumeMount) PutFile(ctx context.Context, p string, r io.Reader) error { 186 | p = cleanPath(p) 187 | ms, ds := v.vol.Store, v.vol.Store 188 | return modifyRoot(ctx, v.vol.Cell, func(root *gotfs.Root) (*gotfs.Root, error) { 189 | var err error 190 | if root == nil { 191 | root, err = v.gotfs.NewEmpty(ctx, ms) 192 | if err != nil { 193 | return nil, err 194 | } 195 | } 196 | root, err = v.gotfs.RemoveAll(ctx, ms, *root, p) 197 | if err != nil { 198 | return nil, err 199 | } 200 | if p != "" { 201 | root, err = v.gotfs.MkdirAll(ctx, ms, *root, parentOf(p)) 202 | if err != nil { 203 | return nil, err 204 | } 205 | } 206 | root, err = v.gotfs.CreateFile(ctx, ms, ds, *root, p, r) 207 | if err != nil { 208 | return nil, err 209 | } 210 | return root, nil 211 | }) 212 | } 213 | 214 | func (v *volumeMount) Rm(ctx context.Context, p string) error { 215 | ms := v.vol.Store 216 | return modifyRoot(ctx, v.vol.Cell, func(root *gotfs.Root) (*gotfs.Root, error) { 217 | var err error 218 | if root == nil { 219 | return nil, nil 220 | } 221 | root, err = v.gotfs.RemoveAll(ctx, ms, *root, p) 222 | if err != nil { 223 | return nil, err 224 | } 225 | return root, nil 226 | }) 227 | } 228 | 229 | func (v *volumeMount) Stat(ctx context.Context, p string) (iofs.FileInfo, error) { 230 | p = cleanPath(p) 231 | root, err := readRoot(ctx, v.vol.Cell) 232 | if err != nil { 233 | return nil, err 234 | } 235 | if root == nil { 236 | return nil, iofs.ErrNotExist 237 | } 238 | return v.stat(ctx, *root, p) 239 | } 240 | 241 | func (v *volumeMount) Mkdir(ctx context.Context, p string) error { 242 | p = cleanPath(p) 243 | ms := v.vol.Store 244 | return modifyRoot(ctx, v.vol.Cell, func(root *gotfs.Root) (*gotfs.Root, error) { 245 | var err error 246 | if root == nil { 247 | root, err = v.gotfs.NewEmpty(ctx, ms) 248 | if err != nil { 249 | return nil, err 250 | } 251 | } 252 | return v.gotfs.MkdirAll(ctx, ms, *root, p) 253 | }) 254 | } 255 | 256 | func (v *volumeMount) readDir(ctx context.Context, p string, n int) (ret []iofs.DirEntry, _ error) { 257 | root, err := readRoot(ctx, v.vol.Cell) 258 | if err != nil { 259 | return nil, err 260 | } 261 | if root == nil { 262 | if p != "" { 263 | return nil, iofs.ErrNotExist 264 | } 265 | return nil, nil 266 | } 267 | stopIter := errors.New("stop iteration") 268 | if err := v.gotfs.ReadDir(ctx, v.vol.Store, *root, p, func(e gotfs.DirEnt) error { 269 | if n > 0 && len(ret) >= n { 270 | return stopIter 271 | } 272 | ret = append(ret, &dirEntry{ 273 | name: e.Name, 274 | mode: e.Mode, 275 | getInfo: func() (*fileInfo, error) { 276 | return v.stat(ctx, *root, path.Join(v.path, e.Name)) 277 | }, 278 | }) 279 | return nil 280 | }); err != nil && !errors.Is(err, stopIter) { 281 | return nil, err 282 | } 283 | return ret, nil 284 | } 285 | 286 | func (v *volumeMount) stat(ctx context.Context, root gotfs.Root, p string) (*fileInfo, error) { 287 | ms := v.vol.Store 288 | info, err := v.gotfs.GetInfo(ctx, ms, root, p) 289 | if err != nil { 290 | return nil, convertError(err) 291 | } 292 | mode := iofs.FileMode(info.Mode) 293 | var size int64 294 | if mode.IsRegular() { 295 | s, err := v.gotfs.SizeOfFile(ctx, ms, root, p) 296 | if err != nil { 297 | return nil, convertError(err) 298 | } 299 | size = int64(s) 300 | } 301 | return &fileInfo{ 302 | name: path.Base(p), 303 | mode: mode, 304 | size: size, 305 | modTime: time.Now(), 306 | }, nil 307 | } 308 | 309 | func readRoot(ctx context.Context, c cells.Cell) (*gotfs.Root, error) { 310 | data, err := cells.GetBytes(ctx, c) 311 | if err != nil { 312 | return nil, err 313 | } 314 | if len(data) == 0 { 315 | return nil, nil 316 | } 317 | var root gotfs.Root 318 | if err := json.Unmarshal(data, &root); err != nil { 319 | return nil, err 320 | } 321 | return &root, nil 322 | } 323 | 324 | func modifyRoot(ctx context.Context, c cells.Cell, fn func(*gotfs.Root) (*gotfs.Root, error)) error { 325 | return cells.Apply(ctx, c, func(x []byte) ([]byte, error) { 326 | var xRoot *gotfs.Root 327 | if len(x) > 0 { 328 | xRoot = &gotfs.Root{} 329 | if err := json.Unmarshal(x, xRoot); err != nil { 330 | return nil, err 331 | } 332 | } 333 | yRoot, err := fn(xRoot) 334 | if err != nil { 335 | return nil, err 336 | } 337 | if yRoot == nil { 338 | return nil, nil 339 | } 340 | return json.Marshal(yRoot) 341 | }) 342 | } 343 | 344 | func cleanPath(x string) string { 345 | x = strings.Trim(x, "/") 346 | return x 347 | } 348 | 349 | func parentOf(x string) string { 350 | parts := strings.Split(x, "/") 351 | if len(parts) == 1 { 352 | return "" 353 | } 354 | return cleanPath(strings.Join(parts[:len(parts)-1], "/")) 355 | } 356 | 357 | // potConfigPath returns a list of the potential config paths 358 | func potConfigPaths(p string) (ret []string) { 359 | p = cleanPath(p) 360 | parts := strings.Split(p, "/") 361 | for i, x := range parts { 362 | if x == "" { 363 | continue 364 | } 365 | configPath := strings.Join(parts[:i+1], "/") + ".webfs" 366 | ret = append(ret, configPath) 367 | } 368 | return ret 369 | } 370 | 371 | func loadWebFSConfig(ctx context.Context, fsop *gotfs.Operator, s cadata.Store, root gotfs.Root, p string) (*VolumeSpec, error) { 372 | const maxConfigSize = 1 << 16 373 | info, err := fsop.GetInfo(ctx, s, root, p) 374 | if posixfs.IsErrNotExist(err) { 375 | return nil, nil 376 | } 377 | if !posixfs.FileMode(info.Mode).IsRegular() { 378 | return nil, nil 379 | } 380 | r := fsop.NewReader(ctx, s, s, root, p) 381 | buf := make([]byte, maxConfigSize) 382 | n, err := io.ReadFull(r, buf) 383 | if err != nil && !errors.Is(err, io.ErrUnexpectedEOF) { 384 | return nil, err 385 | } 386 | vs, err := ParseVolumeSpec(buf[:n]) 387 | if err != nil { 388 | return nil, ErrBadConfig{ 389 | Path: p, 390 | Data: buf[:n], 391 | Inner: err, 392 | } 393 | } 394 | return vs, nil 395 | } 396 | -------------------------------------------------------------------------------- /pkg/webfs/webfs_test.go: -------------------------------------------------------------------------------- 1 | package webfs 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "strings" 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestPotConfigPaths(t *testing.T) { 13 | pcps := potConfigPaths("a/b/c/d") 14 | require.Equal(t, []string{ 15 | "a.webfs", 16 | "a/b.webfs", 17 | "a/b/c.webfs", 18 | "a/b/c/d.webfs", 19 | }, pcps) 20 | 21 | pcps = potConfigPaths("a") 22 | require.Equal(t, []string{"a.webfs"}, pcps) 23 | 24 | pcps = potConfigPaths("") 25 | require.ElementsMatch(t, []string{}, pcps) 26 | } 27 | 28 | func TestPut(t *testing.T) { 29 | ctx := context.Background() 30 | wfs := newTestWebFS(t) 31 | require.NoError(t, wfs.PutFile(ctx, "test", strings.NewReader("my test data"))) 32 | } 33 | 34 | func TestPutCat(t *testing.T) { 35 | ctx := context.Background() 36 | wfs := newTestWebFS(t) 37 | testData := "my test data" 38 | require.NoError(t, wfs.PutFile(ctx, "test", strings.NewReader(testData))) 39 | buf := &bytes.Buffer{} 40 | require.NoError(t, wfs.Cat(ctx, "test", buf)) 41 | require.Equal(t, testData, buf.String()) 42 | } 43 | 44 | func newTestWebFS(t testing.TB) *FS { 45 | fs, err := New(VolumeSpec{ 46 | Cell: CellSpec{Memory: &struct{}{}}, 47 | Store: StoreSpec{Memory: &struct{}{}}, 48 | }) 49 | require.NoError(t, err) 50 | return fs 51 | } 52 | -------------------------------------------------------------------------------- /pkg/webfscmd/add.go: -------------------------------------------------------------------------------- 1 | package webfscmd 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "os" 8 | "path" 9 | "path/filepath" 10 | 11 | "github.com/brendoncarroll/webfs/pkg/webfs" 12 | "github.com/spf13/cobra" 13 | ) 14 | 15 | func newAddCmd() *cobra.Command { 16 | return &cobra.Command{ 17 | Use: "add ", 18 | Short: "adds a file or directory to a WebFS instance", 19 | Args: cobra.ExactArgs(2), 20 | RunE: func(cmd *cobra.Command, args []string) error { 21 | dst, src := args[0], args[1] 22 | return importPath(ctx, wfs, dst, src) 23 | }, 24 | } 25 | } 26 | 27 | func importPath(ctx context.Context, wfs *webfs.FS, dst, src string) error { 28 | fmt.Println("importing", src, "->", dst) 29 | finfo, err := os.Stat(src) 30 | if err != nil { 31 | return err 32 | } 33 | if finfo.IsDir() { 34 | if err := wfs.Mkdir(ctx, dst); err != nil { 35 | return err 36 | } 37 | return importDir(ctx, wfs, dst, src) 38 | } 39 | return importFile(ctx, wfs, dst, src) 40 | } 41 | 42 | func importDir(ctx context.Context, wfs *webfs.FS, dst, src string) error { 43 | f, err := os.Open(src) 44 | if err != nil { 45 | return err 46 | } 47 | defer func() { 48 | if err := f.Close(); err != nil { 49 | log.Println(err) 50 | } 51 | }() 52 | 53 | names, err := f.Readdirnames(-1) 54 | if err != nil { 55 | return err 56 | } 57 | for _, name := range names { 58 | subsrc := filepath.Join(src, name) 59 | subdst := path.Join(dst, name) 60 | if err := importPath(ctx, wfs, subdst, subsrc); err != nil { 61 | return err 62 | } 63 | } 64 | return nil 65 | } 66 | 67 | func importFile(ctx context.Context, wfs *webfs.FS, dst, src string) error { 68 | f, err := os.Open(src) 69 | if err != nil { 70 | return err 71 | } 72 | defer func() { 73 | if err := f.Close(); err != nil { 74 | log.Println(err) 75 | } 76 | }() 77 | return wfs.PutFile(ctx, dst, f) 78 | } 79 | -------------------------------------------------------------------------------- /pkg/webfscmd/cat.go: -------------------------------------------------------------------------------- 1 | package webfscmd 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func newCatCmd() *cobra.Command { 10 | return &cobra.Command{ 11 | Use: "cat ", 12 | Short: "Write the contents of a file to stdout", 13 | Args: cobra.ExactArgs(1), 14 | RunE: func(cmd *cobra.Command, args []string) error { 15 | p := args[0] 16 | return wfs.Cat(ctx, p, os.Stdout) 17 | }, 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /pkg/webfscmd/edit.go: -------------------------------------------------------------------------------- 1 | package webfscmd 2 | 3 | import ( 4 | "context" 5 | "io" 6 | "log" 7 | "os" 8 | "os/exec" 9 | "path/filepath" 10 | 11 | "github.com/spf13/cobra" 12 | ) 13 | 14 | func newEditCmd() *cobra.Command { 15 | return &cobra.Command{ 16 | Use: "edit ", 17 | Short: "edit a file using $EDITOR", 18 | Args: cobra.ExactArgs(1), 19 | RunE: func(cmd *cobra.Command, args []string) error { 20 | p := args[0] 21 | f, err := os.CreateTemp("", "webfs-edit-") 22 | if err != nil { 23 | return err 24 | } 25 | defer f.Close() 26 | defer os.Remove(f.Name()) 27 | // read out 28 | if err := wfs.Cat(ctx, p, f); err != nil { 29 | return err 30 | } 31 | if err := f.Close(); err != nil { 32 | return err 33 | } 34 | // edit 35 | tmpPath := filepath.Join(f.Name()) 36 | if err := userEditor(ctx, tmpPath); err != nil { 37 | return err 38 | } 39 | f, err = os.Open(tmpPath) 40 | if err != nil { 41 | return err 42 | } 43 | defer f.Close() 44 | // write in 45 | if _, err := f.Seek(0, io.SeekStart); err != nil { 46 | return err 47 | } 48 | return wfs.PutFile(ctx, p, f) 49 | }, 50 | } 51 | } 52 | 53 | func userEditor(ctx context.Context, p string) error { 54 | editor := os.Getenv("EDITOR") 55 | if editor == "" { 56 | editor = "vim" 57 | } 58 | log.Println(editor, p) 59 | cmd := exec.CommandContext(ctx, editor, p) 60 | cmd.Stdout = os.Stdout 61 | cmd.Stdin = os.Stdin 62 | return cmd.Run() 63 | } 64 | -------------------------------------------------------------------------------- /pkg/webfscmd/http.go: -------------------------------------------------------------------------------- 1 | package webfscmd 2 | 3 | import ( 4 | "context" 5 | iofs "io/fs" 6 | "net" 7 | "net/http" 8 | 9 | "github.com/brendoncarroll/webfs/pkg/webfs" 10 | "github.com/sirupsen/logrus" 11 | "github.com/spf13/cobra" 12 | ) 13 | 14 | func newHTTPCmd() *cobra.Command { 15 | c := &cobra.Command{ 16 | Use: "http", 17 | Short: "serve files over http", 18 | } 19 | laddr := c.Flags().String("addr", "127.0.0.1:7007", "--addr 127.0.0.1:12345") 20 | c.RunE = func(cmd *cobra.Command, args []string) error { 21 | h := http.FileServer(http.FS(iofsAdapt{wfs})) 22 | l, err := net.Listen("tcp", *laddr) 23 | if err != nil { 24 | return err 25 | } 26 | defer l.Close() 27 | logrus.Infof("serving on http://%v", l.Addr()) 28 | return http.Serve(l, h) 29 | } 30 | return c 31 | } 32 | 33 | type iofsAdapt struct { 34 | wfs *webfs.FS 35 | } 36 | 37 | func (fs iofsAdapt) Open(p string) (iofs.File, error) { 38 | return fs.wfs.Open(context.Background(), p) 39 | } 40 | -------------------------------------------------------------------------------- /pkg/webfscmd/ls.go: -------------------------------------------------------------------------------- 1 | package webfscmd 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "io/fs" 7 | 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func newLsCmd() *cobra.Command { 12 | return &cobra.Command{ 13 | Use: "ls", 14 | Short: "List files and directories", 15 | RunE: func(cmd *cobra.Command, args []string) error { 16 | var p string 17 | if len(args) > 0 { 18 | p = args[0] 19 | } 20 | w := bufio.NewWriter(cmd.OutOrStdout()) 21 | if err := wfs.Ls(ctx, p, func(de fs.DirEntry) error { 22 | perm := de.Type().Perm() 23 | _, err := fmt.Fprintf(w, "%v %-20s\n", perm, de.Name()) 24 | return err 25 | }); err != nil { 26 | return err 27 | } 28 | return w.Flush() 29 | }, 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pkg/webfscmd/mkdir.go: -------------------------------------------------------------------------------- 1 | package webfscmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | func newMkDirCmd() *cobra.Command { 8 | return &cobra.Command{ 9 | Use: "mkdir", 10 | Short: "Makes a new directory", 11 | Args: cobra.ExactArgs(2), 12 | RunE: func(cmd *cobra.Command, args []string) error { 13 | p := args[0] 14 | return wfs.Mkdir(ctx, p) 15 | }, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pkg/webfscmd/mount.go: -------------------------------------------------------------------------------- 1 | package webfscmd 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func newMountCmd() *cobra.Command { 10 | return &cobra.Command{ 11 | Use: "mount", 12 | Short: "Mounts a fuse filesystem", 13 | RunE: func(cmd *cobra.Command, args []string) error { 14 | return errors.New("fuse not yet supported") 15 | // if err := setupWfs(); err != nil { 16 | // return err 17 | // } 18 | // if len(args) < 1 { 19 | // return errors.New("must provide path") 20 | // } 21 | // path := args[0] 22 | // return fuseadapt.MountAndRun(wfs, path) 23 | }, 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /pkg/webfscmd/mv.go: -------------------------------------------------------------------------------- 1 | package webfscmd 2 | 3 | import ( 4 | "errors" 5 | "log" 6 | 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func newMvCmd() *cobra.Command { 11 | return &cobra.Command{ 12 | Use: "mv ", 13 | Short: "Copys the object at args[0] to args[1]", 14 | Args: cobra.ExactArgs(2), 15 | RunE: func(cmd *cobra.Command, args []string) error { 16 | src, dst := args[0], args[1] 17 | log.Println("moving", src, "->", dst) 18 | return errors.New("mv not yet supported") 19 | }, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /pkg/webfscmd/rm.go: -------------------------------------------------------------------------------- 1 | package webfscmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | func newRmCmd() *cobra.Command { 8 | return &cobra.Command{ 9 | Short: "Remove an item from a directory", 10 | Use: "rm", 11 | Args: cobra.ExactArgs(1), 12 | RunE: func(cmd *cobra.Command, args []string) error { 13 | p := args[0] 14 | return wfs.Remove(ctx, p) 15 | }, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pkg/webfscmd/root.go: -------------------------------------------------------------------------------- 1 | package webfscmd 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "io/ioutil" 7 | "path/filepath" 8 | 9 | "github.com/brendoncarroll/go-state/posixfs" 10 | "github.com/brendoncarroll/webfs/pkg/stores/ipfsstore" 11 | "github.com/brendoncarroll/webfs/pkg/webfs" 12 | ipfsapi "github.com/ipfs/go-ipfs-api" 13 | "github.com/spf13/cobra" 14 | ) 15 | 16 | func Execute() error { 17 | rc := NewRootCmd() 18 | return rc.Execute() 19 | } 20 | 21 | func NewRootCmd() *cobra.Command { 22 | rootCmd := &cobra.Command{ 23 | Short: "WebFS", 24 | Use: "webfs", 25 | } 26 | rootPath := rootCmd.PersistentFlags().StringP("root", "r", "", "-r root.webfs") 27 | rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error { 28 | if *rootPath == "" { 29 | return errors.New("must provide a root") 30 | } 31 | data, err := ioutil.ReadFile(*rootPath) 32 | if err != nil { 33 | return err 34 | } 35 | vs, err := webfs.ParseVolumeSpec(data) 36 | if err != nil { 37 | return err 38 | } 39 | fsRoot, err := filepath.Abs(".") 40 | if err != nil { 41 | return err 42 | } 43 | opts := []webfs.Option{ 44 | webfs.WithPosixFS(posixfs.NewDirFS(fsRoot)), 45 | webfs.WithIPFS(ipfsapi.NewShell(ipfsstore.CloudflareURL)), 46 | } 47 | wfs, err = webfs.New(*vs, opts...) 48 | return err 49 | } 50 | 51 | for _, c := range []*cobra.Command{ 52 | newCatCmd(), 53 | newHTTPCmd(), 54 | newEditCmd(), 55 | newAddCmd(), 56 | newLsCmd(), 57 | newMkDirCmd(), 58 | newRmCmd(), 59 | newTouchCmd(), 60 | newMountCmd(), 61 | newMvCmd(), 62 | } { 63 | rootCmd.AddCommand(c) 64 | } 65 | return rootCmd 66 | } 67 | 68 | var ( 69 | ctx = context.Background() 70 | wfs *webfs.FS 71 | ) 72 | -------------------------------------------------------------------------------- /pkg/webfscmd/touch.go: -------------------------------------------------------------------------------- 1 | package webfscmd 2 | 3 | import ( 4 | "bytes" 5 | 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | func newTouchCmd() *cobra.Command { 10 | c := &cobra.Command{ 11 | Use: "touch", 12 | RunE: func(cmd *cobra.Command, args []string) error { 13 | p := args[0] 14 | err := wfs.PutFile(ctx, p, bytes.NewReader(nil)) 15 | return err 16 | }, 17 | } 18 | return c 19 | } 20 | --------------------------------------------------------------------------------