├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTOR ├── COPYING ├── Cargo.toml ├── LICENSE ├── README.md ├── appveyor.yml ├── examples └── simulate_browser.rs └── src ├── dns_operations ├── dns_configuration.rs └── mod.rs ├── errors.rs └── lib.rs /.gitignore: -------------------------------------------------------------------------------- 1 | # Executables 2 | *.exe 3 | *.out 4 | 5 | # Libraires and Objects 6 | *.o 7 | *.a 8 | *.so 9 | *.lo 10 | *.lib 11 | *.dll 12 | *.rlib 13 | *.dylib 14 | 15 | # Generated by Cargo 16 | bin/ 17 | tags* 18 | *.lock 19 | build/ 20 | target/ 21 | build-tests/ 22 | 23 | # Generated by Editors 24 | ~* 25 | *.swp 26 | *.sublime-* 27 | 28 | # Manual 29 | .cargo/ 30 | 31 | # Misc 32 | packages/ 33 | .DS_Store 34 | *.bootstrap.cache 35 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | env: 2 | global: 3 | - secure: EiEvVANqdw2R10LioyfqI3oLBfE9M7fzETOx3fQqwrCRunA2Ke97Ay7uJxumxPIu5o8TI2GG5V0S1nvaSkznuZ3BYXfuuHk8OBky18OF/iib596raI6dfmMH2T2el2zN8XI233PmhAp+zmmDDqGxukcUsT35Hg+gBv+D2pb/i1P/vvcOkFlo9CHROogGRIv0GXPweMMnz+TF7yAZZuzExfpigLAX22qkMIX/HIppq5/YA9WiHXJhWD+XjMfGF46qr+5tUrk6B62I0bjXx1gw3z2+ul0QylXttj3Vt6UuFTWD2Ifw2BC0F19jbyXNzyNbYpAymKsG2WB6wbaecAUNBDmCnsicubm3sBAb9FEnaMEMDyifW4r6EcizO5PS486uYKePKAdC7skc5bGnXP6YFuZoCkMsrNWhdhGJTM1px6qLe3TzoZBfWatvSXe8kjYDFkOZWeYZYU2fZMU2OburvDAW6SZIE3YVp5N/XJaIpLKN3uPXQbvdT9rvCOJIt4BK+ILQTuuwNvgWxA9gMwDZYclboiYi1GHZ6jSyDNRLH5NtwSV8qH/2pHy303q8JpOpjIfi5h5EJdVa3x7fwtn6UhKuvfeGUZde3fcxGjn0JimSn8gvtN4bd6GLsnfzpaott/H9D/y2W+LfqE6Fw7D7Aa2v20Den7DITegbCdlO1zw= 4 | - Features=use-mock-routing 5 | os: 6 | - linux 7 | - osx 8 | language: rust 9 | rust: 10 | - stable 11 | - nightly 12 | sudo: false 13 | branches: 14 | only: 15 | - master 16 | cache: 17 | directories: 18 | - $HOME/libsodium 19 | - $HOME/elfutils 20 | install: 21 | - curl -sSLO https://github.com/maidsafe/QA/raw/master/Bash%20Scripts/Travis/install_libsodium.sh 22 | - . install_libsodium.sh 23 | script: 24 | - curl -sSL https://github.com/maidsafe/QA/raw/master/Bash%20Scripts/Travis/build_and_run_tests.sh | bash 25 | before_cache: 26 | - curl -sSLO https://github.com/maidsafe/QA/raw/master/Bash%20Scripts/Travis/install_elfutils.sh 27 | - . install_elfutils.sh 28 | after_success: 29 | - curl -sSL https://github.com/maidsafe/QA/raw/master/Bash%20Scripts/Travis/after_success.sh | bash 30 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # safe_dns - Change Log 2 | 3 | ## [0.6.0] 4 | - Migrate to Routing 0.7.0 5 | 6 | ## [0.5.0] 7 | - Dependencies updated to allow building with Rust stable 8 | 9 | ## [0.4.0] 10 | - Refactored to work with refactored routing, safe_core and safe_nfs api's 11 | 12 | ## [0.3.1] 13 | - Remove wildcard dependencies. 14 | 15 | ## [0.3.0] 16 | - [MAID-1423](https://maidsafe.atlassian.net/browse/MAID-1423) Rename safe_client to safe_core 17 | 18 | ## [0.2.1] 19 | - Routing crate updated to version 0.4.* 20 | 21 | ## [0.2.0] 22 | - [MAID-1314](https://maidsafe.atlassian.net/browse/MAID-1314) Remove all unwraps 23 | - [MAID-1315](https://maidsafe.atlassian.net/browse/MAID-1315) Remove unwanted errors and Unexpected should take an &str instead of String 24 | - [MAID-1316](https://maidsafe.atlassian.net/browse/MAID-1316) Put debug statements 25 | - [MAID-1317](https://maidsafe.atlassian.net/browse/MAID-1317) check for all muts (eg., response_getter etc) and validate if really required 26 | - [MAID-1318](https://maidsafe.atlassian.net/browse/MAID-1318) Follow changes in NFS and Client 27 | - [MAID-1319](https://maidsafe.atlassian.net/browse/MAID-1319) Address the TODO’s and make temporary fixes as permanent 28 | - [MAID-1320](https://maidsafe.atlassian.net/browse/MAID-1320) Test cases for TODO's and temporary fixes as permanent 29 | 30 | ## [0.1.0] 31 | - [MAID-1240](https://maidsafe.atlassian.net/browse/MAID-1240) Create DNS mapping 32 | - [MAID-1241](https://maidsafe.atlassian.net/browse/MAID-1241) Update DNS Mapping 33 | - [MAID-1242](https://maidsafe.atlassian.net/browse/MAID-1242) Delete DNS Mapping 34 | - [MAID-1243](https://maidsafe.atlassian.net/browse/MAID-1243) DNS Lookup 35 | - [MAID-1244](https://maidsafe.atlassian.net/browse/MAID-1244) Unit tests 36 | - [MAID-1245](https://maidsafe.atlassian.net/browse/MAID-1245) Create Example to demonstrate the API usage 37 | -------------------------------------------------------------------------------- /CONTRIBUTOR: -------------------------------------------------------------------------------- 1 | MaidSafe Contributor Agreement version 1.0 1. Scope of this Agreement This MaidSafe Contributor Agreement ("MCA") applies to any contribution (as defined below) that you make to any software or other product or project managed by us (the "project"), and sets out the intellectual property rights you assign and grant to us in the contributed materials. The term "us" shall mean MaidSafe.net Limited. The term "you" shall mean the person or entity identified below. 2. Acceptance You should read this agreement carefully before posting any contributions (as defined below) to the project. Your posting of any contribution to this project will be deemed to constitute acceptance of the terms of this MCA. This MCA is a binding legal agreement between you and us. 3. Intellectual property rights The term "contributions" or "contributed materials" means any source code, object code, patch, tool, sample, graphic, specification, manual, documentation, or any other material posted or submitted by you to the project. The term "intellectual property rights" means any patents, rights to inventions, copyrights and similar rights, rights in know-how and all other intellectual property rights anywhere in the world for the full term of those rights including all registrations and applications and the right to apply for registrations. In relation to intellectual property rights in your contributions: * you hereby assign to us with full title guarantee all the intellectual property rights (existing and future) in your contributions (the "rights"), and we hereby grant to you a perpetual, irrevocable, non-exclusive, worldwide, no-charge, royalty-free, unrestricted license to use the rights for any purpose. To the extent that such assignment is or becomes invalid, ineffective or unenforceable, you hereby grant to us a perpetual, irrevocable, non-exclusive, worldwide, no-charge, royalty-free, unrestricted license to use the rights for any purpose (including, at our option, the right to sublicense these same rights to third parties through multiple levels of sublicensees or other licensing arrangements. * you hereby irrevocably and unconditionally waive all moral rights which you may have in your contributions in whatever part of the world such rights may be enforceable; * you agree to, without charge, execute and do all such acts, documents, matters and things as may be necessary or reasonably required to obtain patent, copyright or other protection for any of your contributions (or software in which they are included) or improvements or developments to them and to vest title to the intellectual property rights in them in us and you irrevocably appoint us to be your attorney and in your name and on your behalf to execute and do any such acts described above for the same purpose if needed; and * you agree that neither of us has any duty to consult with, obtain the consent of, pay or render an accounting to the other for any use or distribution of your contribution. This MCA is effective on the date you first submitted a contribution to us. Any contribution we make available under any license will also be made available under a suitable FSF (Free Software Foundation) or OSI (Open Source Initiative) approved license. You covenant, represent, warrant and agree that: * each contribution that you submit (1) is and shall be an original work of authorship and you can legally assign and grant the rights set out in this MCA, and (2) does not include any third party code or other materials; * no contribution will violate any third party's intellectual property rights; and * each contribution shall be in compliance with (and will not need a licence or permission under) applicable export or import laws. You agree to notify us if you become aware of any circumstance which would make any of the foregoing representations inaccurate in any respect. MaidSafe may publicly disclose your participation in the project, including the fact that you have signed the MCA. Any notice or other written communication to be given under or in connection with this agreement shall be in writing, no term shall be varied by statement, conduct or act of any party except that the parties may amend this agreement only by letter or written instrument signed by both parties. This agreement sets out the entire agreement and understanding between the parties relating to your contributions. This MCA is governed by Scottish law and subject to the jurisdiction of the Scottish courts save that we or you may bring action in other courts to the extent necessary to protect or enforce our intellectual property rights. -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["MaidSafe Developers "] 3 | description = "SAFE DNS API library" 4 | documentation = "http://maidsafe.net/safe_dns/latest" 5 | homepage = "http://maidsafe.net" 6 | license = "GPL-3.0" 7 | name = "safe_dns" 8 | readme = "README.md" 9 | repository = "https://github.com/maidsafe/safe_dns" 10 | version = "0.6.0" 11 | 12 | [dependencies] 13 | clippy = {version = "~0.0.44", optional = true} 14 | log = "~0.3.5" 15 | maidsafe_utilities = "~0.2.0" 16 | routing = "~0.7.0" 17 | rustc-serialize = "~0.3.16" 18 | safe_core = "~0.6.0" 19 | safe_nfs = "~0.6.0" 20 | sodiumoxide = "~0.0.9" 21 | xor_name = "~0.0.4" 22 | 23 | [dev-dependencies] 24 | regex = "~0.1.44" 25 | 26 | [features] 27 | use-mock-routing = ["safe_core/use-mock-routing", "safe_nfs/use-mock-routing"] 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MaidSafe.net Commercial Licence 1.0 2 | 3 | DATE [insert date] 4 | 5 | 6 | PARTIES 7 | 8 | (1) MaidSafe.next Ltd registered company number SC297540 of 72 Templehill, Troon, Scotland, 9 | KA10 6BE; and 10 | 11 | (2) [INSERT FULL COMPANY NAME OF CUSTOMER] (registered company number [number]) of [address] 12 | (the "Customer"). 13 | 14 | 15 | INTRODUCTION 16 | 17 | MaidSafe has agreed to supply and license, and the Customer has agreed to use and pay for, 18 | MaidSafe's proprietary software on the terms set out in this agreement. 19 | 20 | 21 | 1. Definitions 22 | 23 | In this agreement: 24 | 25 | "Affiliate" means in relation to any company, any body corporate which is from time to time a 26 | holding company of that company, a subsidiary of that company or a subsidiary of a holding 27 | company of that company ("holding company" and "subsidiary" having the meanings attributed to 28 | them by s.1159 Companies Act 2006); 29 | 30 | "Intellectual Property Rights" means any patents, rights to inventions, copyrights and similar 31 | rights, rights in know-how and all other intellectual property rights anywhere in the world 32 | for the full term of those rights including all registrations and applications and the right 33 | to apply for registrations; 34 | 35 | "Licence" shall mean the licence in clause 3 of this agreement; 36 | 37 | "Object" form shall mean any form resulting from mechanical transformation or translation of a 38 | Source form, including but not limited to compiled object code, generated documentation, and 39 | conversions to other media types; 40 | 41 | "Software" means the source or binary form of any MaidSafe.net limited developed code; and 42 | 43 | "Source" form shall mean software source code. 44 | 45 | 46 | 2. Supply of the Software 47 | 48 | MaidSafe will make available to the Customer the Software for download. 49 | 50 | 51 | 3. Licence 52 | 53 | 3.1 In consideration of, and subject to payment of, the charges payable under this agreement, 54 | MaidSafe grants the Customer a perpetual non-exclusive licence to use reproduce, sublicense, 55 | and distribute the Software in Source or Object form, in each case in accordance with this 56 | clause 3, for the duration of this agreement. This right includes the right to use the 57 | Intellectual Property Rights in the Software, including patent rights, and the Customer 58 | acknowledges that its use of the Software or any similar software (or any modified version of 59 | the Software or any software that is based on or includes any part of the Software) other than 60 | in accordance with the terms of this agreement (including the payment of the charges when due) 61 | would infringe MaidSafe's Intellectual Property Rights, including patents rights, and in such 62 | cases MaidSafe may terminate this Agreement without prejudice to its rights to claim damages, 63 | account of profits and/or injunctive relief. 64 | 65 | 3.2 Customer may reproduce and distribute copies of the Software in any medium, with or without 66 | modifications, and in Source or Object form, provided that Customer meets the following 67 | conditions: 68 | 69 | (a) Customer must ensure that any permitted user is required to enter into a written 70 | software licence and is not allowed to use the Software (including any modified version 71 | of the Software or any software that is based on or includes any part of the Software) 72 | in any manner that would not be permitted by this Licence; 73 | 74 | (b) Customer must cause any modified files to carry prominent notices stating that Customer 75 | changed the files; 76 | 77 | (c) Customer must retain, in the Source form of any copies of the Software (including any 78 | modified version of the Software or any software that is based on or includes any part 79 | of the Software) or any part thereof that Customer distributes, all copyright, patent, 80 | trademark, and attribution notices from the Source form of the Software; and 81 | 82 | (d) if the Software includes a "NOTICE" text file as part of its distribution, then any 83 | copies of the Software (including any modified version of the Software or any software 84 | that is based on or includes any part of the Software) or any part that Customer 85 | distributes must include a readable copy of the attribution notices contained within 86 | such NOTICE file in at least one of the following places: 87 | 88 | (i) within a NOTICE text file distributed as part of the Software; 89 | 90 | (ii) within the Source form or documentation, if provided along with the Software; or 91 | 92 | (iii) within a display generated by the Software, if and wherever such third-party 93 | notices normally appear. The contents of the NOTICE file are for informational 94 | purposes only and do not modify the Licence. 95 | 96 | 3.3 Except as expressly permitted otherwise by any term of this agreement, only the Customer is 97 | permitted to use the Software. Use by the Customer includes use by the Customer's employees 98 | and contractors provided that such use is solely on behalf of the Customer and for the 99 | purposes of the Customer's business. 100 | 101 | 3.4 The Customer may make such backup copies of the Software as are reasonably necessary to 102 | support the Customer's use of the Software in accordance with this agreement. MaidSafe will 103 | own the Intellectual Property Rights in any such backup copies. 104 | 105 | 3.5 The Customer may reverse engineer or decompile the Software but only to the extent allowed 106 | under applicable law and on the basis that Customer will request interoperability information 107 | from MaidSafe. 108 | 109 | 3.6 The Customer will comply with any reasonable instructions which MaidSafe gives the Customer 110 | relating to the use of the Software (or any modified version of the Software or any software 111 | that is based on or includes any part of the Software). The Customer will allow MaidSafe 112 | access to any premises controlled by the Customer in order to allow MaidSafe to check that the 113 | Software (or any modified version of the Software or any software that is based on or includes 114 | any part of the Software) is being used only as permitted. 115 | 116 | 3.7 This agreement does not grant permission to use the trade names, trademarks, service marks, or 117 | product names of the Licensor, except as required for reasonable and customary use in 118 | describing the origin of the Software and complying with this agreement. 119 | 120 | 121 | 4. Limited warranty 122 | 123 | 4.1 MaidSafe warrants that it will perform its obligations under this agreement with reasonable 124 | care and skill. 125 | 126 | 4.2 If the warranty in clause 4.1 is breached, the Customer must tell MaidSafe as soon as 127 | possible. The Customer must give MaidSafe a reasonable time to fix the problem or to 128 | re-perform any relevant services. This will be done without any additional charge to the 129 | Customer. If MaidSafe is able to do this within a reasonable time, MaidSafe will have no 130 | other obligations or liability in relation to that breach. If MaidSafe is unable to do this 131 | within a reasonable time or MaidSafe does not think that it is a sensible way to deal with the 132 | problem, then MaidSafe may if it wishes elect to take back the Software and to refund to the 133 | Customer all of the money which the Customer has paid to MaidSafe under this agreement. Where 134 | the problem relates to a portion of the Software and other elements supplied which are capable 135 | of use separately without material detriment to the Customer, MaidSafe may take back (and 136 | refund in respect of) affected portions only. 137 | 138 | 4.3 Apart from the terms set out in this agreement, no conditions, warranties or other terms apply 139 | to the Software or its supply or Licence under this agreement. In particular, no implied 140 | conditions, warranties or other terms relating to satisfactory quality or fitness for any 141 | purpose will apply to anything supplied under this agreement. MaidSafe does not warrant or 142 | enter into any terms to the effect that the Software: 143 | 144 | (a) will perform any particular function or purpose; or 145 | 146 | (b) be entirely free from defects or that its operation will be entirely error free. 147 | 148 | 4.4 MaidSafe will not be liable for breach of any of the warranties or any other terms in this 149 | agreement to the extent that the breach arises from: 150 | 151 | (a) use of the Software other than in accordance with normal operating procedures or as 152 | otherwise notified to the Customer by MaidSafe; 153 | 154 | (b) any alterations to the Software made by anyone other than MaidSafe or someone authorised 155 | by MaidSafe; 156 | 157 | (c) any problem with the computer on which the Software is installed, any equipment 158 | connected to that computer or any other software which is installed on that computer; 159 | 160 | (d) any abnormal or incorrect operating conditions; or 161 | 162 | (e) use of the Software in combination with any other hardware or software, unless this use 163 | has been approved by MaidSafe in writing. 164 | 165 | 166 | 5. Limitation of Liability 167 | 168 | 5.1 Neither party's liability: 169 | 170 | (a) for death or personal injury caused by its negligence or the negligence of its employees 171 | or agents; 172 | 173 | (b) for breach of clause 7 (Confidentiality); or 174 | 175 | (c) for fraudulent misrepresentation, is excluded or limited by this agreement, even if any 176 | other term of this agreement would otherwise suggest that this might be the case. 177 | 178 | 5.2 Other than as set out in clause 5.1, neither party shall be liable to the other (whether for 179 | breach of contract, negligence or for any other reason) for any: 180 | 181 | (a) loss of profits; 182 | 183 | (b) loss of sales; 184 | 185 | (c) loss of revenue; 186 | 187 | (d) loss of any software or data; 188 | 189 | (e) loss of use of hardware, software or data; 190 | 191 | (f) indirect, consequential or special loss. 192 | 193 | 5.3 Subject to clauses 5.1 and 5.2, MaidSafe's total aggregate liability under this agreement and 194 | in relation to anything which MaidSafe has done or not done in connection with this agreement 195 | (and whether the liability arises because of breach of contract, negligence or for any other 196 | reason) shall be limited to: 197 | 198 | (a) an amount equal to 125% of the total amount payable by the Customer under this agreement 199 | in the preceding 12 months; or 200 | 201 | (b) if the amount referred to in (a) cannot be calculated accurately at the time the 202 | relevant liability is to be assessed, or if it is less than £5,000, to £5,000 203 | 204 | 205 | 6. Charges 206 | 207 | 6.1 Schedule 1 sets out the licence fees and other charges payable by the Customer under this 208 | agreement. The charges are due on the dates (or on the happening of the events) specified in 209 | schedule 1. 210 | 211 | 6.2 MaidSafe may invoice the Customer for the charges as soon as they become due. The Customer 212 | must pay the invoices within 30 days of receiving them (and if MaidSafe posts them to the 213 | Customer, the Customer will be treated as having received them two working days later unless 214 | the Customer can show that this was not the case). 215 | 216 | 6.3 Where any charges are based on the Customer's revenues the Customer shall keep all accounts 217 | and documents necessary to evidence such revenues and to support any calculation of the 218 | relevant revenue share, and shall provide copies to MaidSafe on request. Customer shall allow 219 | MaidSafe and its agents to enter into Customer's premises and to have access to all such 220 | accounts and documents upon reasonable request. Where Customer's accounts and documents 221 | illustrate that Customer has underpaid any charges (or MaidSafe can otherwise demonstrate 222 | this) Customer shall immediately pay the balance due to MaidSafe plus MaidSafe's reasonable 223 | costs of audit. This clause 6.3 shall survive termination or expiry of this agreement for 6 224 | years. 225 | 226 | 6.4 MaidSafe may charge interest on all sums outstanding beyond the date on which they are due for 227 | payment under this agreement. Interest may be charged on that basis from the date payment was 228 | due until the date of payment (including after any judgement has been obtained) at the rate of 229 | 3% per calendar month or part thereof. 230 | 231 | 6.5 The amounts specified in schedule 1 do not include VAT or any other taxes on supplies and the 232 | Customer will pay these to MaidSafe as well as the amounts concerned. 233 | 234 | 235 | 7. Confidentiality 236 | 237 | 7.1 Each party will keep confidential any information which the other supplies to it in connection 238 | with this agreement. Confidential information will include the Software and any related 239 | documentation; all information marked as being confidential; and any other information which 240 | might reasonably be assumed to be confidential. The obligations as to confidentiality in this 241 | agreement will not apply to any information which: 242 | 243 | (a) is available to the public other than because of any breach of this agreement; 244 | 245 | (b) is, when it is supplied, already known to whomever it is disclosed to in circumstances 246 | in which they are not prevented from disclosing it to others; 247 | 248 | (c) is independently obtained by whomever it is disclosed to in circumstances in which they 249 | are not prevented from disclosing it to others; or 250 | 251 | (d) is required to be disclosed by law or by any court or tribunal with proper authority to 252 | order its disclosure (but only to the extent of such requirements). 253 | 254 | 255 | 8. Term and termination 256 | 257 | 8.1 This agreement will commence on the date set out on page 1 and will continue indefinitely 258 | until terminated in accordance with this clause 8. 259 | 260 | 8.2 Either party may terminate this agreement if: 261 | 262 | (a) the other materially breaches any term of this agreement and it is not possible to 263 | remedy that breach or it is possible to remedy that breach, but the other fails to do so 264 | within 30 days of being asked to do so; or 265 | 266 | (b) the other suffers any of the following event: 267 | 268 | (i) a meeting of creditors of that party being held or an arrangement or composition 269 | with or for the benefit of its creditors (including a voluntary arrangement as 270 | defined in the Insolvency Act 1986) being proposed by or in relation to that 271 | party; 272 | 273 | (ii) a chargeholder, receiver, administrative receiver or other similar party taking 274 | possession of or being appointed over or any distress, execution or other process 275 | being levied or enforced (and not being discharged within seven days) on the whole 276 | or a material part of the assets of that party; 277 | 278 | (iii) that party ceasing to carry on business or being deemed to be unable to pay its 279 | debts within the meaning of section 123 Insolvency Act 1986; 280 | 281 | (iv) that party or its directors or the holder of a qualifying floating charge or any 282 | of its creditors giving notice of their intention to appoint, appointing or making 283 | an application to the court for the appointment of, an administrator; 284 | 285 | (v) a petition being advertised or a resolution being passed or an order being made 286 | for the administration or the winding-up, bankruptcy or dissolution of that party; 287 | and/or 288 | 289 | (vi) the happening in relation to that party of an event analogous to any of the above 290 | in any jurisdiction in which it is incorporated or resident or in which it carries 291 | on business or has assets. 292 | 293 | 8.3 MaidSafe may terminate this agreement if: 294 | 295 | (a) Customer fails to pay any charges within 60 days of their due date; or 296 | 297 | (b) should the Software become, or in MaidSafe's reasonable opinion is likely to become, the 298 | subject of a claim of intellectual property infringement claim. 299 | 300 | 8.4 Apart from any other rights which MaidSafe might have, if the Customer breaches this agreement 301 | MaidSafe may suspend performance of any of its obligations or any of the Customer's rights 302 | under this agreement until the Customer remedies the breach to the reasonable satisfaction of 303 | MaidSafe. 304 | 305 | 306 | 9. Consequences of termination 307 | 308 | 9.1 If this agreement is terminated (regardless of who terminates it and regardless of the reason) 309 | the Customer will immediately on termination: 310 | 311 | (a) cease using the Software (including any modified version of the Software or any software 312 | that is based on or includes any part of the Software); 313 | 314 | (b) return all copies of the Software to MaidSafe or (if the copies are on media which is 315 | non-removable and forms part of equipment belonging to the Customer) delete all copies 316 | in such a way that they cannot be recovered; and 317 | 318 | (c) confirm to MaidSafe in writing that both of the above things have been done. 319 | 320 | 9.2 Termination of this agreement will not affect any accrued rights or liabilities which either 321 | MaidSafe or the Customer may have by the time termination takes effect. Clauses 5, 6 (for 322 | unpaid charges), 7 and 9 shall survive termination or expiry of this agreement and any other 323 | clause shall survive termination or expiry if expressly stated. 324 | 325 | 326 | 10. Other terms 327 | 328 | 10.1 The Customer may not assign any of the Customer's rights or obligations under this agreement. 329 | MaidSafe may assign this agreement or any of MaidSafe's rights or obligations under this 330 | agreement to someone else, provided MaidSafe tells the Customer in writing if it does so. 331 | 332 | 10.2 Neither party has any authority to enter into a contract for or on behalf of the other party, 333 | to assume a liability on behalf of the other party or to pledge the credit of the other party, 334 | unless such authority is expressly granted in writing by the other party. Neither party may 335 | act as if it has such authority and must not represent (expressly or by implying it) that it 336 | has such authority. 337 | 338 | 10.3 MaidSafe will not be liable to the Customer for any breach of this agreement which arises 339 | because of any circumstances which MaidSafe cannot reasonably be expected to control. 340 | 341 | 10.4 All notices and consents relating to this agreement must be in writing. All variations to 342 | this agreement must be agreed, set out in writing and signed on behalf of both MaidSafe and 343 | the Customer before they take effect. 344 | 345 | 10.5 In this agreement, unless it says otherwise: 346 | 347 | (a) reference to a person includes a legal person (such as a limited company) as well as a 348 | natural person; 349 | 350 | (b) reference to this agreement includes reference to the schedules and appendices and other 351 | documents attached to it or incorporated by reference into it (all as amended or added 352 | to from time to time); 353 | 354 | (c) reference to "including" in this agreement shall be treated as being by way of example 355 | and shall not limit the general applicability of any preceding words; 356 | 357 | (d) reference to any legislation shall be to that legislation as amended, extended or 358 | re-enacted from time to time and to any subordinate provision made under that 359 | legislation; 360 | 361 | (e) references to clauses or schedules shall be to those in this agreement; 362 | 363 | (f) reference to this agreement shall include reference to it after it has been amended, 364 | added to or replaced by a new agreement. 365 | 366 | 10.6 Except to the extent that this agreement expressly says otherwise, nothing in this agreement 367 | shall create a partnership between the parties or give the rights of a partner to either 368 | party. 369 | 370 | 10.7 Any software supplied or Licenced under this agreement will not be treated as goods within the 371 | meaning of the Sale of Goods Act 1979. Firmware will be treated as part of the goods in which 372 | it is installed. 373 | 374 | 10.8 This agreement sets out all of the terms that have been agreed between MaidSafe and the 375 | Customer in relation to the subjects covered by it. Subject to clause 5.1, no other 376 | representations or terms shall apply or form part of this agreement. The Customer 377 | acknowledges that it has not been influenced to enter this agreement by anything MaidSafe has 378 | said or done or committed to do, except as expressly recorded herein. 379 | 380 | 10.9 No term of this agreement is enforceable under the Contracts (Rights of Third Parties) Act 381 | 1999 by a person who is not a party to this agreement. 382 | 383 | 10.10 This agreement is governed by Scottish law. Both MaidSafe and the Customer submit to the 384 | exclusive jurisdiction of the Scottish courts in relation to any dispute concerning this 385 | agreement but MaidSafe is also entitled to apply to any court worldwide for injunctive and 386 | other remedies in order to protect or enforce its Intellectual Property Rights. 387 | 388 | 389 | SCHEDULE 1 390 | 391 | CHARGES 392 | 393 | 394 | 1. Customer shall pay to MaidSafe 1% of Qualifying Revenue. 395 | 396 | 2 "Qualifying Revenue" shall mean any revenue generated directly or indirectly by Customer or 397 | any Affiliate of Customer through: 398 | 399 | (a) use of the Software (including any modified version of the Software or any software that 400 | is based on or includes any part of the Software); or 401 | 402 | (b) the provision of services directly or indirectly to any person using the Software 403 | (including any modified version of the Software or any software that is based on or 404 | includes any part of the Software), 405 | 406 | ("Qualifying Activities") less any VAT charged on such Qualifying Activities. 407 | 408 | 3. Where any Qualifying Activity is discounted or provided for free (whether through bundling or 409 | otherwise) it will be deemed to be provided at market rate and the relevant Qualifying Revenue 410 | shall be calculated accordingly. 411 | 412 | 4. The charges will be payable quarterly in arrears. 413 | 414 | 5. Within 5 days of the end of each month Customer will provide to MaidSafe a statement setting 415 | out the Qualifying Revenue for the month. MaidSafe shall invoice Customer within 5 days of 416 | the end of each third month. Where no statement is provided or MaidSafe has cause to believe 417 | it to be inaccurate it may invoke its audit rights under this agreement. 418 | 419 | 420 | SIGNED on behalf of both parties on the date set out on page 1 of this agreement: 421 | 422 | 423 | 424 | SIGNED: ..................................................................... 425 | for and on behalf of MaidSafe 426 | 427 | 428 | 429 | ..................................................................... 430 | Name/status 431 | 432 | 433 | 434 | 435 | SIGNED: ..................................................................... 436 | for and on behalf of the Customer 437 | 438 | 439 | 440 | ..................................................................... 441 | Name/status 442 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ***This repository is no longer maintained*** 2 | # It has been moved to the maidsafe-archive organisation for reference only 3 | # 4 | # 5 | # 6 | # 7 | # safe_dns 8 | 9 | [![](https://img.shields.io/badge/Project%20SAFE-Approved-green.svg)](http://maidsafe.net/applications) [![](https://img.shields.io/badge/License-GPL3-green.svg)](https://github.com/maidsafe/safe_dns/blob/master/COPYING) 10 | 11 | **Primary Maintainer:** Krishna Kumar (krishna.kumar@maidsafe.net) 12 | 13 | **Secondary Maintainer:** Spandan Sharma (spandan.sharma@maidsafe.net) 14 | 15 | |Crate|Linux/OS X|Windows|Coverage|Issues| 16 | |:---:|:--------:|:-----:|:------:|:----:| 17 | |[![](http://meritbadge.herokuapp.com/safe_dns)](https://crates.io/crates/safe_dns)|[![Build Status](https://travis-ci.org/maidsafe/safe_dns.svg?branch=master)](https://travis-ci.org/maidsafe/safe_dns)|[![Build status](https://ci.appveyor.com/api/projects/status/eig27xveg95e6ct6/branch/master?svg=true)](https://ci.appveyor.com/project/MaidSafe-QA/safe-dns/branch/master)|[![Coverage Status](https://coveralls.io/repos/maidsafe/safe_dns/badge.svg)](https://coveralls.io/r/maidsafe/safe_dns)|[![Stories in Ready](https://badge.waffle.io/maidsafe/safe_dns.png?label=ready&title=Ready)](https://waffle.io/maidsafe/safe_dns)| 18 | 19 | | [API Documentation - master branch](http://maidsafe.net/safe_dns/master) | [SAFE Network System Documentation](http://systemdocs.maidsafe.net) | [MaidSafe website](http://maidsafe.net) | [SAFE Network Forum](https://forum.safenetwork.io) | 20 | |:------:|:-------:|:-------:|:-------:| 21 | 22 | ## Prerequisite 23 | 24 | [libsodium](https://github.com/jedisct1/libsodium) is a native dependency, and can be installed by following the instructions [for Windows](https://github.com/maidsafe/QA/blob/master/Documentation/Install%20libsodium%20for%20Windows.md) or [for OS X and Linux](https://github.com/maidsafe/QA/blob/master/Documentation/Install%20libsodium%20for%20OS%20X%20or%20Linux.md). 25 | 26 | ## Build Instructions 27 | `safe_dns` depends on `safe_client` which can interface conditionally against either the routing crate or a mock used for local testing. 28 | 29 | To use it with the Mock: 30 | ``` 31 | cargo build --features "use-mock-routing" 32 | cargo test --features "use-mock-routing" 33 | ``` 34 | 35 | To interface it with actual routing (default): 36 | ``` 37 | cargo build 38 | cargo test 39 | ``` 40 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | global: 3 | RUST_BACKTRACE: 1 4 | Features: "use-mock-routing" 5 | matrix: 6 | - RUST_VERSION: stable 7 | branches: 8 | only: 9 | - master 10 | 11 | clone_depth: 50 12 | 13 | install: 14 | - ps: | 15 | $url = "https://github.com/maidsafe/QA/raw/master/Powershell%20Scripts/AppVeyor" 16 | Start-FileDownload "$url/Install%20Rust.ps1" -FileName "Install Rust.ps1" 17 | Start-FileDownload "$url/Install%20MinGW.ps1" -FileName "Install MinGW.ps1" 18 | Start-FileDownload "$url/Install%20libsodium.ps1" -FileName "Install libsodium.ps1" 19 | Start-FileDownload "$url/Build.ps1" -FileName "Build.ps1" 20 | Start-FileDownload "$url/Run%20Tests.ps1" -FileName "Run Tests.ps1" 21 | . ".\Install Rust.ps1" 22 | . ".\Install MinGW.ps1" 23 | . ".\Install libsodium.ps1" 24 | 25 | platform: 26 | - x86 27 | - x64 28 | 29 | configuration: 30 | # - Debug 31 | - Release 32 | 33 | # Allowing failures for x86 to accommodate for current libsodium test failure in x86 34 | matrix: 35 | allow_failures: 36 | - platform: x86 37 | 38 | build_script: 39 | - ps: . ".\Build.ps1" 40 | 41 | test_script: 42 | - ps: . ".\Run Tests.ps1" 43 | -------------------------------------------------------------------------------- /examples/simulate_browser.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 7 | // By contributing code to the SAFE Network Software, or to this project generally, you agree to be 8 | // bound by the terms of the MaidSafe Contributor Agreement, version 1.0. This, along with the 9 | // Licenses can be found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | //! Simulate browser example. 19 | 20 | // For explanation of lint checks, run `rustc -W help` or see 21 | // https://github.com/maidsafe/QA/blob/master/Documentation/Rust%20Lint%20Checks.md 22 | #![forbid(bad_style, exceeding_bitshifts, mutable_transmutes, no_mangle_const_items, 23 | unknown_crate_types, warnings)] 24 | #![deny(deprecated, drop_with_repr_extern, improper_ctypes, missing_docs, 25 | non_shorthand_field_patterns, overflowing_literals, plugin_as_library, 26 | private_no_mangle_fns, private_no_mangle_statics, stable_features, unconditional_recursion, 27 | unknown_lints, unsafe_code, unused, unused_allocation, unused_attributes, 28 | unused_comparisons, unused_features, unused_parens, while_true)] 29 | #![warn(trivial_casts, trivial_numeric_casts, unused_extern_crates, unused_import_braces, 30 | unused_qualifications, unused_results)] 31 | #![allow(box_pointers, fat_ptr_transmutes, missing_copy_implementations, 32 | missing_debug_implementations, variant_size_differences)] 33 | 34 | #![cfg_attr(feature="clippy", feature(plugin))] 35 | #![cfg_attr(feature="clippy", plugin(clippy))] 36 | #![cfg_attr(feature="clippy", deny(clippy, clippy_pedantic))] 37 | 38 | #![allow(unused_extern_crates)] #[macro_use] 39 | extern crate maidsafe_utilities; 40 | extern crate regex; 41 | extern crate routing; 42 | extern crate safe_dns; 43 | extern crate safe_core; 44 | extern crate safe_nfs; 45 | extern crate sodiumoxide; 46 | 47 | use routing::Data; 48 | 49 | const DEFAULT_SERVICE: &'static str = "www"; 50 | const HOME_PAGE_FILE_NAME: &'static str = "index.html"; 51 | 52 | fn handle_login() -> std::sync::Arc> { 53 | let mut pin = String::new(); 54 | let mut keyword = String::new(); 55 | let mut password = String::new(); 56 | 57 | println!("\n\tAccount Creation"); 58 | println!("\t================"); 59 | 60 | println!("\n------------ Enter Keyword ---------------"); 61 | let _ = std::io::stdin().read_line(&mut keyword); 62 | 63 | println!("\n\n------------ Enter Password --------------"); 64 | let _ = std::io::stdin().read_line(&mut password); 65 | loop { 66 | println!("\n\n--------- Enter PIN (4 Digits) -----------"); 67 | let _ = std::io::stdin().read_line(&mut pin); 68 | pin = pin.trim().to_string(); 69 | if pin.parse::().is_ok() && pin.len() == 4 { 70 | break; 71 | } 72 | println!("ERROR: PIN is not 4 Digits !!"); 73 | pin.clear(); 74 | } 75 | 76 | // Account Creation 77 | { 78 | println!("\nTrying to create an account ..."); 79 | let _ = unwrap_result!(safe_core::client::Client::create_account(keyword.clone(), pin.clone(), password.clone())); 80 | println!("Account Creation Successful !!"); 81 | } 82 | 83 | println!("\n\n\tAuto Account Login"); 84 | println!("\t=================="); 85 | 86 | // Log into the created account 87 | println!("\nTrying to log into the created account using supplied credentials ..."); 88 | std::sync::Arc::new(std::sync::Mutex::new(unwrap_result!(safe_core::client::Client::log_in(keyword, pin, password)))) 89 | } 90 | 91 | fn create_dns_record(client : std::sync::Arc>, 92 | dns_operations: &safe_dns::dns_operations::DnsOperations) -> Result<(), safe_dns::errors::DnsError> { 93 | println!("\n\n Create Dns Record"); 94 | println!( " ================="); 95 | println!("\nEnter Dns Name (eg., pepsico.com [Note: more than one \".\"s are not allowed in this simple example]):"); 96 | let mut long_name = String::new(); 97 | let _ = std::io::stdin().read_line(&mut long_name); 98 | long_name = long_name.trim().to_string(); 99 | 100 | println!("\nGenerating messaging ecryption keys for you..."); 101 | let (public_messaging_encryption_key, secret_messaging_encryption_key) = sodiumoxide::crypto::box_::gen_keypair(); 102 | 103 | println!("Registering Dns..."); 104 | 105 | let owners = vec![try!(client.lock().unwrap().get_public_signing_key()).clone()]; 106 | let secret_signing_key = try!(client.lock().unwrap().get_secret_signing_key()).clone(); 107 | let dns_struct_data = try!(dns_operations.register_dns(long_name, 108 | &public_messaging_encryption_key, 109 | &secret_messaging_encryption_key, 110 | &vec![], 111 | owners, 112 | &secret_signing_key, 113 | None)); 114 | Ok(try!(unwrap_result!(client.lock()).put(Data::Structured(dns_struct_data), None))) 115 | } 116 | 117 | fn delete_dns_record(client : std::sync::Arc>, 118 | dns_operations: &safe_dns::dns_operations::DnsOperations) -> Result<(), safe_dns::errors::DnsError> { 119 | println!("\n\n Delete Dns Record"); 120 | println!( " ================="); 121 | println!("\nEnter Dns Name (eg., pepsico.com):"); 122 | let mut long_name = String::new(); 123 | let _ = std::io::stdin().read_line(&mut long_name); 124 | long_name = long_name.trim().to_string(); 125 | 126 | let secret_signing_key = try!(client.lock().unwrap().get_secret_signing_key()).clone(); 127 | 128 | println!("Deleting Dns..."); 129 | 130 | let dns_struct_data = try!(dns_operations.delete_dns(&long_name, &secret_signing_key)); 131 | Ok(try!(unwrap_result!(client.lock()).delete(Data::Structured(dns_struct_data), None))) 132 | } 133 | 134 | fn display_dns_records(dns_operations: &safe_dns::dns_operations::DnsOperations) -> Result<(), safe_dns::errors::DnsError> { 135 | println!("\n\n Display Dns Records"); 136 | println!( " ==================="); 137 | println!("\nRegistered Dns Names (fetching...):"); 138 | let record_names = try!(dns_operations.get_all_registered_names()); 139 | for it in record_names.iter().enumerate() { 140 | println!("<{:?}> {}", it.0 + 1, it.1); 141 | } 142 | Ok(()) 143 | } 144 | 145 | fn add_service(client : std::sync::Arc>, 146 | dns_operations: &safe_dns::dns_operations::DnsOperations) -> Result<(), safe_dns::errors::DnsError> { 147 | println!("\n\n Add Service"); 148 | println!( " ==========="); 149 | println!("\nEnter Dns Name (eg., pepsico.com):"); 150 | let mut long_name = String::new(); 151 | let _ = std::io::stdin().read_line(&mut long_name); 152 | long_name = long_name.trim().to_string(); 153 | 154 | println!("\nEnter Service Name (eg., www):"); 155 | let mut service_name = String::new(); 156 | let _ = std::io::stdin().read_line(&mut service_name); 157 | service_name = service_name.trim().to_string(); 158 | 159 | println!("Creating Home Directory for the Service..."); 160 | 161 | let service_home_dir_name = service_name.clone() + "_home_dir"; 162 | 163 | let dir_helper = safe_nfs::helper::directory_helper::DirectoryHelper::new(client.clone()); 164 | let (dir_listing, _) = try!(dir_helper.create(service_home_dir_name, 165 | safe_nfs::UNVERSIONED_DIRECTORY_LISTING_TAG, 166 | vec![], 167 | false, 168 | safe_nfs::AccessLevel::Public, 169 | None)); 170 | 171 | let file_helper = safe_nfs::helper::file_helper::FileHelper::new(client.clone()); 172 | let mut writer = try!(file_helper.create(HOME_PAGE_FILE_NAME.to_string(), vec![], dir_listing)); 173 | 174 | println!("\nEnter text that you want to display on the Home-Page:"); 175 | let mut text = String::new(); 176 | let _ = std::io::stdin().read_line(&mut text); 177 | text = text.trim().to_string(); 178 | 179 | println!("Creating Home Page for the Service..."); 180 | 181 | writer.write(text.as_bytes(), 0); 182 | let (updated_parent_dir_listing, _) = try!(writer.close()); 183 | let dir_key = updated_parent_dir_listing.get_key(); 184 | 185 | let secret_signing_key = try!(client.lock().unwrap().get_secret_signing_key()).clone(); 186 | 187 | let struct_data = try!(dns_operations.add_service(&long_name, 188 | (service_name, dir_key.clone()), 189 | &secret_signing_key, 190 | None)); 191 | 192 | Ok(try!(client.lock().unwrap().post(Data::Structured(struct_data), None))) 193 | } 194 | 195 | fn remove_service(client : std::sync::Arc>, 196 | dns_operations: &safe_dns::dns_operations::DnsOperations) -> Result<(), safe_dns::errors::DnsError> { 197 | println!("\n\n Remove Service"); 198 | println!( " =============="); 199 | println!("\nEnter Dns Name (eg., pepsico.com):"); 200 | let mut long_name = String::new(); 201 | let _ = std::io::stdin().read_line(&mut long_name); 202 | long_name = long_name.trim().to_string(); 203 | 204 | println!("\nEnter Service Name (eg., www):"); 205 | let mut service_name = String::new(); 206 | let _ = std::io::stdin().read_line(&mut service_name); 207 | service_name = service_name.trim().to_string(); 208 | 209 | println!("Removing Service..."); 210 | 211 | let secret_signing_key = try!(client.lock().unwrap().get_secret_signing_key()).clone(); 212 | let struct_data = try!(dns_operations.remove_service(&long_name, service_name, &secret_signing_key, None)); 213 | Ok(try!(client.lock().unwrap().post(Data::Structured(struct_data), None))) 214 | } 215 | 216 | fn display_services(dns_operations: &safe_dns::dns_operations::DnsOperations) -> Result<(), safe_dns::errors::DnsError> { 217 | println!("\n\n Display Services"); 218 | println!( " ================"); 219 | println!("\nEnter Dns Name (eg., pepsico.com):"); 220 | let mut long_name = String::new(); 221 | let _ = std::io::stdin().read_line(&mut long_name); 222 | long_name = long_name.trim().to_string(); 223 | 224 | println!("\nServices For Dns {:?} (fetching...):", long_name); 225 | let service_names = try!(dns_operations.get_all_services(&long_name, None)); 226 | for it in service_names.iter().enumerate() { 227 | println!("<{:?}> {}", it.0 + 1, it.1); 228 | } 229 | Ok(()) 230 | } 231 | 232 | fn parse_url_and_get_home_page(client : std::sync::Arc>, 233 | dns_operations: &safe_dns::dns_operations::DnsOperations) -> Result<(), safe_dns::errors::DnsError> { 234 | println!("\n\n Parse URL"); 235 | println!( " ========="); 236 | println!("\nEnter SAFE-Url (eg., safe:lays.pepsico.com ie., \"safe:[.]\"):"); 237 | let mut url = String::new(); 238 | let _ = std::io::stdin().read_line(&mut url); 239 | url = url.trim().to_string(); 240 | 241 | let re_with_service = try!(regex::Regex::new(r"safe:([^.]+?)\.([^.]+?\.[^.]+)$").map_err(|_| safe_dns::errors::DnsError::Unexpected("Failed to form Regular-Expression !!".to_string()))); 242 | let re_without_service = try!(regex::Regex::new(r"safe:([^.]+?\.[^.]+)$").map_err(|_| safe_dns::errors::DnsError::Unexpected("Failed to form Regular-Expression !!".to_string()))); 243 | 244 | let long_name; 245 | let service_name; 246 | 247 | if re_with_service.is_match(&url) { 248 | let captures = try!(re_with_service.captures(&url).ok_or(safe_dns::errors::DnsError::Unexpected("Could not capture items in Url !!".to_string()))); 249 | let caps_0 = try!(captures.at(1).ok_or(safe_dns::errors::DnsError::Unexpected("Could not access a capture !!".to_string()))); 250 | let caps_1 = try!(captures.at(2).ok_or(safe_dns::errors::DnsError::Unexpected("Could not access a capture !!".to_string()))); 251 | 252 | long_name = caps_1.to_string(); 253 | service_name = caps_0.to_string(); 254 | } else if re_without_service.is_match(&url) { 255 | let captures = try!(re_without_service.captures(&url).ok_or(safe_dns::errors::DnsError::Unexpected("Could not capture items in Url !!".to_string()))); 256 | let caps_0 = try!(captures.at(1).ok_or(safe_dns::errors::DnsError::Unexpected("Could not access a capture !!".to_string()))); 257 | 258 | long_name = caps_0.to_string(); 259 | service_name = DEFAULT_SERVICE.to_string(); 260 | } else { 261 | return Err(safe_dns::errors::DnsError::Unexpected("Malformed Url !!".to_string())) 262 | } 263 | 264 | println!("Fetching data..."); 265 | 266 | let dir_key = try!(dns_operations.get_service_home_directory_key(&long_name, &service_name, None)); 267 | let directory_helper = safe_nfs::helper::directory_helper::DirectoryHelper::new(client.clone()); 268 | let dir_listing = try!(directory_helper.get(&dir_key)); 269 | 270 | let file = try!(dir_listing.get_files().iter().find(|a| *a.get_name() == HOME_PAGE_FILE_NAME.to_string()) 271 | .ok_or(safe_dns::errors::DnsError::Unexpected("Could not find homepage !!".to_string()))); 272 | let file_helper = safe_nfs::helper::file_helper::FileHelper::new(client.clone()); 273 | let mut reader = file_helper.read(file); 274 | let size = reader.size(); 275 | let content = try!(reader.read(0, size)); 276 | 277 | println!("\n-----------------------------------------------------"); 278 | println!( " Home Page Contents"); 279 | println!( "-----------------------------------------------------\n"); 280 | println!("{}", try!(String::from_utf8(content).map_err(|_| safe_dns::errors::DnsError::Unexpected("Cannot convert contents to displayable string !!".to_string())))); 281 | 282 | Ok(()) 283 | } 284 | 285 | fn main() { 286 | let client = handle_login(); 287 | let unregistered_client = ::std::sync::Arc::new(::std::sync::Mutex::new(unwrap_result!(::safe_core 288 | ::client 289 | ::Client 290 | ::create_unregistered_client()))); 291 | println!("Account Login Successful !!"); 292 | 293 | println!("Initialising Dns..."); 294 | let dns_operations = unwrap_result!(safe_dns::dns_operations::DnsOperations::new(client.clone())); 295 | let dns_operations_unregistered = safe_dns::dns_operations::DnsOperations::new_unregistered(unregistered_client.clone()); 296 | 297 | let mut user_option = String::new(); 298 | 299 | loop { 300 | println!("\n\n ------\n | MENU |\n ------"); 301 | println!("\n<1> Register Your Dns"); 302 | println!("\n<2> Delete Dns Record"); 303 | println!("\n<3> List Dns Records"); 304 | println!("\n<4> Add Service"); 305 | println!("\n<5> Remove Service"); 306 | println!("\n<6> List Services"); 307 | println!("\n<7> Parse URL (Simulate Browser)"); 308 | println!("\n<8> Exit"); 309 | 310 | println!("\nEnter Option [1-8]:"); 311 | let _ = std::io::stdin().read_line(&mut user_option); 312 | 313 | if let Ok(option) = user_option.trim().parse::() { 314 | let mut error = None; 315 | 316 | match option { 317 | 1 => if let Err(err) = create_dns_record(client.clone(), &dns_operations) { 318 | error = Some(err); 319 | }, 320 | 2 => if let Err(err) = delete_dns_record(client.clone(), &dns_operations) { 321 | error = Some(err); 322 | }, 323 | 3 => if let Err(err) = display_dns_records(&dns_operations) { 324 | error = Some(err); 325 | }, 326 | 4 => if let Err(err) = add_service(client.clone(), &dns_operations) { 327 | error = Some(err); 328 | }, 329 | 5 => if let Err(err) = remove_service(client.clone(), &dns_operations) { 330 | error = Some(err); 331 | }, 332 | 6 => if let Err(err) = display_services(&dns_operations_unregistered) { 333 | error = Some(err); 334 | }, 335 | 7 => if let Err(err) = parse_url_and_get_home_page(unregistered_client.clone(), 336 | &dns_operations_unregistered) { 337 | error = Some(err); 338 | }, 339 | 8 => break, 340 | _ => println!("\nUnrecognised option !!"), 341 | } 342 | 343 | println!("\n ----------------------------------------------"); 344 | if let Some(err) = error { 345 | println!("| ERROR !! {:?}", err); 346 | } else { 347 | println!("| Operation Completed Successfully !"); 348 | } 349 | println!(" ----------------------------------------------"); 350 | } else { 351 | println!("\nUnrecognised option !!"); 352 | } 353 | 354 | println!("Hit Enter to continue..."); 355 | let _ = std::io::stdin().read_line(&mut user_option); 356 | user_option.clear(); 357 | } 358 | } 359 | -------------------------------------------------------------------------------- /src/dns_operations/dns_configuration.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 7 | // By contributing code to the SAFE Network Software, or to this project generally, you agree to be 8 | // bound by the terms of the MaidSafe Contributor Agreement, version 1.0. This, along with the 9 | // Licenses can be found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | use maidsafe_utilities::serialisation::{serialise, deserialise}; 19 | 20 | const DNS_CONFIG_DIR_NAME: &'static str = "DnsReservedDirectory"; 21 | const DNS_CONFIG_FILE_NAME: &'static str = "DnsConfigurationFile"; 22 | 23 | #[derive(Clone, Debug, Eq, PartialEq, RustcEncodable, RustcDecodable)] 24 | pub struct DnsConfiguation { 25 | pub long_name : String, 26 | pub encryption_keypair: (::sodiumoxide::crypto::box_::PublicKey, 27 | ::sodiumoxide::crypto::box_::SecretKey), 28 | 29 | } 30 | 31 | pub fn initialise_dns_configuaration(client: ::std::sync::Arc<::std::sync::Mutex<::safe_core::client::Client>>) -> Result<(), ::errors::DnsError> { 32 | let dir_helper = ::safe_nfs::helper::directory_helper::DirectoryHelper::new(client.clone()); 33 | let dir_listing = try!(dir_helper.get_configuration_directory_listing(DNS_CONFIG_DIR_NAME.to_string())); 34 | let file_helper = ::safe_nfs::helper::file_helper::FileHelper::new(client.clone()); 35 | match file_helper.create(DNS_CONFIG_FILE_NAME.to_string(), vec![], dir_listing) { 36 | Ok(writer) => { 37 | let _ = try!(writer.close()); 38 | Ok(()) 39 | }, 40 | Err(::safe_nfs::errors::NfsError::FileAlreadyExistsWithSameName) => Ok(()), 41 | Err(error) => Err(::errors::DnsError::from(error)), 42 | } 43 | } 44 | 45 | pub fn get_dns_configuaration_data(client: ::std::sync::Arc<::std::sync::Mutex<::safe_core::client::Client>>) -> Result, ::errors::DnsError> { 46 | let dir_helper = ::safe_nfs::helper::directory_helper::DirectoryHelper::new(client.clone()); 47 | let dir_listing = try!(dir_helper.get_configuration_directory_listing(DNS_CONFIG_DIR_NAME.to_string())); 48 | let file = try!(dir_listing.get_files().iter().find(|file| file.get_name() == DNS_CONFIG_FILE_NAME).ok_or(::errors::DnsError::DnsConfigFileNotFoundOrCorrupted)); 49 | let file_helper = ::safe_nfs::helper::file_helper::FileHelper::new(client.clone()); 50 | debug!("Reading dns configuration data from file ..."); 51 | let mut reader = file_helper.read(file); 52 | let size = reader.size(); 53 | if size != 0 { 54 | Ok(try!(deserialise(&try!(reader.read(0, size))))) 55 | } else { 56 | Ok(vec![]) 57 | } 58 | } 59 | 60 | pub fn write_dns_configuaration_data(client: ::std::sync::Arc<::std::sync::Mutex<::safe_core::client::Client>>, 61 | config: &Vec) -> Result<(), ::errors::DnsError> { 62 | let dir_helper = ::safe_nfs::helper::directory_helper::DirectoryHelper::new(client.clone()); 63 | let dir_listing = try!(dir_helper.get_configuration_directory_listing(DNS_CONFIG_DIR_NAME.to_string())); 64 | let file = try!(dir_listing.get_files().iter().find(|file| file.get_name() == DNS_CONFIG_FILE_NAME).ok_or(::errors::DnsError::DnsConfigFileNotFoundOrCorrupted)).clone(); 65 | let file_helper = ::safe_nfs::helper::file_helper::FileHelper::new(client.clone()); 66 | let mut writer = try!(file_helper.update_content(file, ::safe_nfs::helper::writer::Mode::Overwrite, dir_listing)); 67 | debug!("Writing dns configuration data ..."); 68 | writer.write(&try!(serialise(&config)), 0); 69 | let _ = try!(writer.close()); 70 | Ok(()) 71 | } 72 | 73 | #[cfg(test)] 74 | mod test { 75 | use super::*; 76 | 77 | #[test] 78 | fn read_write_dns_configuration_file() { 79 | let client = ::std::sync::Arc::new(::std::sync::Mutex::new(unwrap_result!(::safe_core::utility::test_utils::get_client()))); 80 | 81 | // Initialise Dns Configuration File 82 | unwrap_result!(initialise_dns_configuaration(client.clone())); 83 | 84 | // Get the Stored Configurations 85 | let mut config_vec = unwrap_result!(get_dns_configuaration_data(client.clone())); 86 | assert_eq!(config_vec.len(), 0); 87 | 88 | let long_name = unwrap_result!(::safe_core::utility::generate_random_string(10)); 89 | 90 | // Put in the 1st record 91 | let mut keypair = ::sodiumoxide::crypto::box_::gen_keypair(); 92 | let config_0 = DnsConfiguation { 93 | long_name : long_name.clone(), 94 | encryption_keypair: (keypair.0, keypair.1), 95 | }; 96 | 97 | config_vec.push(config_0.clone()); 98 | unwrap_result!(write_dns_configuaration_data(client.clone(), &config_vec)); 99 | 100 | // Get the Stored Configurations 101 | config_vec = unwrap_result!(get_dns_configuaration_data(client.clone())); 102 | assert_eq!(config_vec.len(), 1); 103 | 104 | assert_eq!(config_vec[0], config_0); 105 | 106 | // Modify the content 107 | keypair = ::sodiumoxide::crypto::box_::gen_keypair(); 108 | let config_1 = DnsConfiguation { 109 | long_name : long_name, 110 | encryption_keypair: (keypair.0, keypair.1), 111 | }; 112 | 113 | config_vec[0] = config_1.clone(); 114 | unwrap_result!(write_dns_configuaration_data(client.clone(), &config_vec)); 115 | 116 | // Get the Stored Configurations 117 | config_vec = unwrap_result!(get_dns_configuaration_data(client.clone())); 118 | assert_eq!(config_vec.len(), 1); 119 | 120 | assert!(config_vec[0] != config_0); 121 | assert_eq!(config_vec[0], config_1); 122 | 123 | // Delete Record 124 | config_vec.clear(); 125 | unwrap_result!(write_dns_configuaration_data(client.clone(), &config_vec)); 126 | 127 | // Get the Stored Configurations 128 | config_vec = unwrap_result!(get_dns_configuaration_data(client.clone())); 129 | assert_eq!(config_vec.len(), 0); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/dns_operations/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 7 | // By contributing code to the SAFE Network Software, or to this project generally, you agree to be 8 | // bound by the terms of the MaidSafe Contributor Agreement, version 1.0. This, along with the 9 | // Licenses can be found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | use xor_name::XorName; 19 | use routing::{Data, DataRequest, StructuredData}; 20 | use maidsafe_utilities::serialisation::{serialise, deserialise}; 21 | 22 | mod dns_configuration; 23 | 24 | const DNS_TAG: u64 = 5; 25 | 26 | /// This is a representational structure for all safe-dns operations 27 | pub struct DnsOperations { 28 | client: ::std::sync::Arc<::std::sync::Mutex<::safe_core::client::Client>>, 29 | } 30 | 31 | impl DnsOperations { 32 | /// Create a new instance of DnsOperations. It is intended that only one of this be created as 33 | /// it operates on global data such as files. 34 | pub fn new(client: ::std::sync::Arc<::std::sync::Mutex<::safe_core::client::Client>>) -> Result { 35 | try!(dns_configuration::initialise_dns_configuaration(client.clone())); 36 | 37 | Ok(DnsOperations { 38 | client: client, 39 | }) 40 | } 41 | 42 | /// Create a new instance of DnsOperations. This is used for an unregistered client and will 43 | /// have very limited set of functionalities - mostly reads. This is ideal for browsers etc., 44 | /// which only want to fetch from the Network, not mutate it. 45 | /// It is intended that only one of this be created as it operates on global data such as 46 | /// files. 47 | pub fn new_unregistered(unregistered_client: ::std::sync::Arc<::std::sync::Mutex<::safe_core::client::Client>>) -> DnsOperations { 48 | DnsOperations { 49 | client: unregistered_client, 50 | } 51 | } 52 | 53 | /// Register one's own Dns - eg., pepsico.com, spandansharma.com, krishnakumar.in etc 54 | pub fn register_dns(&self, 55 | long_name : String, 56 | public_messaging_encryption_key: &::sodiumoxide::crypto::box_::PublicKey, 57 | secret_messaging_encryption_key: &::sodiumoxide::crypto::box_::SecretKey, 58 | services : &Vec<(String, ::safe_nfs::metadata::directory_key::DirectoryKey)>, 59 | owners : Vec<::sodiumoxide::crypto::sign::PublicKey>, 60 | private_signing_key : &::sodiumoxide::crypto::sign::SecretKey, 61 | data_encryption_keys : Option<(&::sodiumoxide::crypto::box_::PublicKey, 62 | &::sodiumoxide::crypto::box_::SecretKey, 63 | &::sodiumoxide::crypto::box_::Nonce)>) -> Result { 64 | debug!("Registering {:?} dns ...", long_name); 65 | let mut saved_configs = try!(dns_configuration::get_dns_configuaration_data(self.client.clone())); 66 | if saved_configs.iter().any(|config| config.long_name == long_name) { 67 | Err(::errors::DnsError::DnsNameAlreadyRegistered) 68 | } else { 69 | let identifier = XorName::new(::sodiumoxide::crypto::hash::sha512::hash(long_name.as_bytes()).0); 70 | 71 | let dns_record = Dns { 72 | long_name : long_name.clone(), 73 | services : services.iter().map(|a| a.clone()).collect(), 74 | encryption_key: public_messaging_encryption_key.clone(), 75 | }; 76 | 77 | debug!("Adding encryption key pair to saved dns configuration ..."); 78 | saved_configs.push(dns_configuration::DnsConfiguation { 79 | long_name : long_name, 80 | encryption_keypair: (public_messaging_encryption_key.clone(), 81 | secret_messaging_encryption_key.clone()) 82 | 83 | }); 84 | try!(dns_configuration::write_dns_configuaration_data(self.client.clone(), &saved_configs)); 85 | 86 | Ok(try!(::safe_core::structured_data_operations::unversioned::create(self.client.clone(), 87 | DNS_TAG, 88 | identifier, 89 | 0, 90 | try!(serialise(&dns_record)), 91 | owners, 92 | vec![], 93 | private_signing_key, 94 | data_encryption_keys))) 95 | } 96 | } 97 | 98 | /// Delete the Dns-Record 99 | pub fn delete_dns(&self, 100 | long_name : &String, 101 | private_signing_key: &::sodiumoxide::crypto::sign::SecretKey) -> Result { 102 | let mut saved_configs = try!(dns_configuration::get_dns_configuaration_data(self.client.clone())); 103 | let pos = try!(saved_configs.iter().position(|config| config.long_name == *long_name).ok_or(::errors::DnsError::DnsRecordNotFound)); 104 | 105 | let prev_struct_data = try!(self.get_housing_structured_data(long_name)); 106 | 107 | debug!("Removing dns saved configs at {:?} position ...", pos); 108 | let _ = saved_configs.remove(pos); 109 | try!(dns_configuration::write_dns_configuaration_data(self.client.clone(), &saved_configs)); 110 | 111 | Ok(try!(::safe_core::structured_data_operations::unversioned::create(self.client.clone(), 112 | DNS_TAG, 113 | prev_struct_data.get_identifier().clone(), 114 | prev_struct_data.get_version() + 1, 115 | vec![], 116 | prev_struct_data.get_owner_keys().clone(), 117 | prev_struct_data.get_previous_owner_keys().clone(), 118 | private_signing_key, 119 | None))) 120 | } 121 | 122 | /// Get all the Dns-names registered by the user so far in the network. 123 | pub fn get_all_registered_names(&self) -> Result, ::errors::DnsError> { 124 | dns_configuration::get_dns_configuaration_data(self.client.clone()).map(|v| v.iter().map(|a| a.long_name.clone()).collect()) 125 | } 126 | 127 | /// Get the messaging encryption keys that the user has associated with one's particular Dns-name. 128 | pub fn get_messaging_encryption_keys(&self, long_name: &String) -> Result<(::sodiumoxide::crypto::box_::PublicKey, 129 | ::sodiumoxide::crypto::box_::SecretKey), ::errors::DnsError> { 130 | let dns_config_record = try!(self.find_dns_record(long_name)); 131 | Ok(dns_config_record.encryption_keypair.clone()) 132 | } 133 | 134 | /// Get all the services (www, blog, micro-blog etc) that user has associated with this 135 | /// Dns-name 136 | pub fn get_all_services(&self, 137 | long_name : &String, 138 | data_decryption_keys: Option<(&::sodiumoxide::crypto::box_::PublicKey, 139 | &::sodiumoxide::crypto::box_::SecretKey, 140 | &::sodiumoxide::crypto::box_::Nonce)>) -> Result, ::errors::DnsError> { 141 | // Allow unregistered clients to access this function 142 | match self.find_dns_record(long_name) { 143 | Ok(_) => (), 144 | Err(::errors::DnsError::CoreError(::safe_core::errors::CoreError::OperationForbiddenForClient)) => (), 145 | Err(::errors::DnsError::NfsError(::safe_nfs::errors::NfsError::CoreError(::safe_core::errors::CoreError::OperationForbiddenForClient))) => (), 146 | Err(error) => return Err(error), 147 | }; 148 | 149 | let (_, dns_record) = try!(self.get_housing_structured_data_and_dns_record(long_name, data_decryption_keys)); 150 | Ok(dns_record.services.keys().map(|a| a.clone()).collect()) 151 | } 152 | 153 | /// Get the home directory (eg., homepage containing HOME.html, INDEX.html) for the given service. 154 | pub fn get_service_home_directory_key(&self, 155 | long_name : &String, 156 | service_name : &String, 157 | data_decryption_keys: Option<(&::sodiumoxide::crypto::box_::PublicKey, 158 | &::sodiumoxide::crypto::box_::SecretKey, 159 | &::sodiumoxide::crypto::box_::Nonce)>) -> Result<::safe_nfs::metadata::directory_key::DirectoryKey, ::errors::DnsError> { 160 | // Allow unregistered clients to access this function 161 | match self.find_dns_record(long_name) { 162 | Ok(_) => (), 163 | Err(::errors::DnsError::CoreError(::safe_core::errors::CoreError::OperationForbiddenForClient)) => (), 164 | Err(::errors::DnsError::NfsError(::safe_nfs::errors::NfsError::CoreError(::safe_core::errors::CoreError::OperationForbiddenForClient))) => (), 165 | Err(error) => return Err(error), 166 | }; 167 | 168 | let (_, dns_record) = try!(self.get_housing_structured_data_and_dns_record(long_name, data_decryption_keys)); 169 | dns_record.services.get(service_name).map(|v| v.clone()).ok_or(::errors::DnsError::ServiceNotFound) 170 | } 171 | 172 | /// Add a new service for the given Dns-name. 173 | pub fn add_service(&self, 174 | long_name : &String, 175 | new_service : (String, ::safe_nfs::metadata::directory_key::DirectoryKey), 176 | private_signing_key : &::sodiumoxide::crypto::sign::SecretKey, 177 | data_encryption_decryption_keys: Option<(&::sodiumoxide::crypto::box_::PublicKey, 178 | &::sodiumoxide::crypto::box_::SecretKey, 179 | &::sodiumoxide::crypto::box_::Nonce)>) -> Result { 180 | self.add_remove_service_impl(long_name, (new_service.0, Some(new_service.1)), private_signing_key, data_encryption_decryption_keys) 181 | } 182 | 183 | /// Remove a service from the given Dns-name. 184 | pub fn remove_service(&self, 185 | long_name : &String, 186 | service_to_remove : String, 187 | private_signing_key : &::sodiumoxide::crypto::sign::SecretKey, 188 | data_encryption_decryption_keys: Option<(&::sodiumoxide::crypto::box_::PublicKey, 189 | &::sodiumoxide::crypto::box_::SecretKey, 190 | &::sodiumoxide::crypto::box_::Nonce)>) -> Result { 191 | self.add_remove_service_impl(long_name, (service_to_remove, None), private_signing_key, data_encryption_decryption_keys) 192 | } 193 | 194 | fn find_dns_record(&self, long_name: &String) -> Result { 195 | let config_vec = try!(dns_configuration::get_dns_configuaration_data(self.client.clone())); 196 | config_vec.iter().find(|config| config.long_name == *long_name).map(|v| v.clone()).ok_or(::errors::DnsError::DnsRecordNotFound) 197 | } 198 | 199 | fn add_remove_service_impl(&self, 200 | long_name : &String, 201 | service : (String, Option<::safe_nfs::metadata::directory_key::DirectoryKey>), 202 | private_signing_key : &::sodiumoxide::crypto::sign::SecretKey, 203 | data_encryption_decryption_keys: Option<(&::sodiumoxide::crypto::box_::PublicKey, 204 | &::sodiumoxide::crypto::box_::SecretKey, 205 | &::sodiumoxide::crypto::box_::Nonce)>) -> Result { 206 | let _ = try!(self.find_dns_record(long_name)); 207 | 208 | let is_add_service = service.1.is_some(); 209 | let (prev_struct_data, mut dns_record) = try!(self.get_housing_structured_data_and_dns_record(long_name, 210 | data_encryption_decryption_keys)); 211 | 212 | if !is_add_service && !dns_record.services.contains_key(&service.0) { 213 | Err(::errors::DnsError::ServiceNotFound) 214 | } else if is_add_service && dns_record.services.contains_key(&service.0) { 215 | Err(::errors::DnsError::ServiceAlreadyExists) 216 | } else { 217 | if is_add_service { 218 | debug!("Inserting service ..."); 219 | let _ = dns_record.services.insert(service.0, try!(service.1.ok_or(::errors::DnsError::from("Programming Error - Investigate !!")))); 220 | } else { 221 | debug!("Removing service ..."); 222 | let _ = dns_record.services.remove(&service.0); 223 | } 224 | 225 | Ok(try!(::safe_core::structured_data_operations::unversioned::create(self.client.clone(), 226 | DNS_TAG, 227 | prev_struct_data.get_identifier().clone(), 228 | prev_struct_data.get_version() + 1, 229 | try!(serialise(&dns_record)), 230 | prev_struct_data.get_owner_keys().clone(), 231 | prev_struct_data.get_previous_owner_keys().clone(), 232 | private_signing_key, 233 | data_encryption_decryption_keys))) 234 | } 235 | } 236 | 237 | fn get_housing_structured_data_and_dns_record(&self, 238 | long_name : &String, 239 | data_decryption_keys: Option<(&::sodiumoxide::crypto::box_::PublicKey, 240 | &::sodiumoxide::crypto::box_::SecretKey, 241 | &::sodiumoxide::crypto::box_::Nonce)>) -> Result<(StructuredData, 242 | Dns), ::errors::DnsError> { 243 | let struct_data = try!(self.get_housing_structured_data(long_name)); 244 | let dns_record = try!(deserialise(&try!(::safe_core::structured_data_operations::unversioned::get_data(self.client.clone(), 245 | &struct_data, 246 | data_decryption_keys)))); 247 | Ok((struct_data, dns_record)) 248 | } 249 | 250 | fn get_housing_structured_data(&self, long_name: &String) -> Result { 251 | let identifier = XorName::new(::sodiumoxide::crypto::hash::sha512::hash(long_name.as_bytes()).0); 252 | let request = DataRequest::Structured(identifier, DNS_TAG); 253 | debug!("Retrieving structured data from network for {:?} dns ...", long_name); 254 | let response_getter = try!(unwrap_result!(self.client.lock()).get(request, None)); 255 | if let Data::Structured(struct_data) = try!(response_getter.get()) { 256 | Ok(struct_data) 257 | } else { 258 | Err(::errors::DnsError::from(::safe_core::errors::CoreError::ReceivedUnexpectedData)) 259 | } 260 | } 261 | } 262 | 263 | #[derive(Clone, Debug, Eq, PartialEq, RustcEncodable, RustcDecodable)] 264 | struct Dns { 265 | long_name : String, 266 | services : ::std::collections::HashMap, 267 | encryption_key: ::sodiumoxide::crypto::box_::PublicKey, 268 | } 269 | 270 | #[cfg(test)] 271 | mod test { 272 | use super::*; 273 | use xor_name::XorName; 274 | use routing::Data; 275 | 276 | #[test] 277 | fn register_and_delete_dns() { 278 | let client = ::std::sync::Arc::new(::std::sync::Mutex::new(unwrap_result!(::safe_core::utility::test_utils::get_client()))); 279 | let dns_operations = unwrap_result!(DnsOperations::new(client.clone())); 280 | 281 | let dns_name = unwrap_result!(::safe_core::utility::generate_random_string(10)); 282 | let messaging_keypair = ::sodiumoxide::crypto::box_::gen_keypair(); 283 | let owners = vec![unwrap_result!(unwrap_result!(client.lock()).get_public_signing_key()).clone()]; 284 | 285 | let secret_signing_key = unwrap_result!(unwrap_result!(client.lock()).get_secret_signing_key()).clone(); 286 | 287 | // Register 288 | let mut struct_data = unwrap_result!(dns_operations.register_dns(dns_name.clone(), 289 | &messaging_keypair.0, 290 | &messaging_keypair.1, 291 | &vec![], 292 | owners.clone(), 293 | &secret_signing_key, 294 | None)); 295 | 296 | unwrap_result!(unwrap_result!(client.lock()).put(Data::Structured(struct_data), None)); 297 | 298 | // Get Services 299 | let services = unwrap_result!(dns_operations.get_all_services(&dns_name, None)); 300 | assert_eq!(services.len(), 0); 301 | 302 | // Re-registering is not allowed 303 | match dns_operations.register_dns(dns_name.clone(), 304 | &messaging_keypair.0, 305 | &messaging_keypair.1, 306 | &vec![], 307 | owners.clone(), 308 | &secret_signing_key, 309 | None) { 310 | Ok(_) => panic!("Should have been an error"), 311 | Err(::errors::DnsError::DnsNameAlreadyRegistered) => (), 312 | Err(error) => panic!("{:?}", error), 313 | } 314 | 315 | // Delete 316 | struct_data = unwrap_result!(dns_operations.delete_dns(&dns_name, &secret_signing_key)); 317 | unwrap_result!(unwrap_result!(client.lock()).delete(Data::Structured(struct_data), None)); 318 | 319 | // Registering again should be allowed 320 | let _ = unwrap_result!(dns_operations.register_dns(dns_name, 321 | &messaging_keypair.0, 322 | &messaging_keypair.1, 323 | &vec![], 324 | owners, 325 | &secret_signing_key, 326 | None)); 327 | } 328 | 329 | #[test] 330 | fn manipulate_services() { 331 | let client = ::std::sync::Arc::new(::std::sync::Mutex::new(unwrap_result!(::safe_core::utility::test_utils::get_client()))); 332 | let dns_operations = unwrap_result!(DnsOperations::new(client.clone())); 333 | 334 | let dns_name = unwrap_result!(::safe_core::utility::generate_random_string(10)); 335 | let messaging_keypair = ::sodiumoxide::crypto::box_::gen_keypair(); 336 | 337 | let mut services = vec![("www".to_string(), 338 | ::safe_nfs::metadata::directory_key::DirectoryKey::new(XorName::new([123; 64]), 339 | 15000, 340 | false, 341 | ::safe_nfs::AccessLevel::Public)), 342 | ("blog".to_string(), 343 | ::safe_nfs::metadata::directory_key::DirectoryKey::new(XorName::new([123; 64]), 344 | 15000, 345 | false, 346 | ::safe_nfs::AccessLevel::Public)), 347 | ("bad-ass".to_string(), 348 | ::safe_nfs::metadata::directory_key::DirectoryKey::new(XorName::new([123; 64]), 349 | 15000, 350 | false, 351 | ::safe_nfs::AccessLevel::Public))]; 352 | 353 | let owners = vec![unwrap_result!(unwrap_result!(client.lock()).get_public_signing_key()).clone()]; 354 | 355 | let secret_signing_key = unwrap_result!(unwrap_result!(client.lock()).get_secret_signing_key()).clone(); 356 | 357 | // Register 358 | let mut struct_data = unwrap_result!(dns_operations.register_dns(dns_name.clone(), 359 | &messaging_keypair.0, 360 | &messaging_keypair.1, 361 | &services, 362 | owners.clone(), 363 | &secret_signing_key, 364 | None)); 365 | 366 | unwrap_result!(unwrap_result!(client.lock()).put(Data::Structured(struct_data), None)); 367 | 368 | // Get all dns-names 369 | let dns_records_vec = unwrap_result!(dns_operations.get_all_registered_names()); 370 | assert_eq!(dns_records_vec.len(), 1); 371 | 372 | // Gets should be possible with unregistered clients 373 | let unregistered_client = ::std::sync::Arc::new(::std::sync::Mutex::new(unwrap_result!(::safe_core::client::Client::create_unregistered_client()))); 374 | let dns_operations_unregistered = DnsOperations::new_unregistered(unregistered_client); 375 | 376 | // Get all services for a dns-name 377 | let services_vec = unwrap_result!(dns_operations_unregistered.get_all_services(&dns_name, None)); 378 | assert_eq!(services.len(), services_vec.len()); 379 | assert!(services.iter().all(|&(ref a, _)| services_vec.iter().find(|b| *a == **b).is_some())); 380 | 381 | // TODO(Spandan) update all test cases for negative GET's once it is figured out how 382 | // match dns_operations.get_service_home_directory_key(&"bogus".to_string(), &services[0].0, None) { 383 | // Ok(_) => panic!("Should have been an error"), 384 | // Err(::errors::DnsError::DnsRecordNotFound) => (), 385 | // Err(error) => panic!("{:?}", error), 386 | // } 387 | 388 | // Get information about a service - the home-directory and its type 389 | let home_dir_key = unwrap_result!(dns_operations_unregistered.get_service_home_directory_key(&dns_name, &services[1].0, None)); 390 | assert_eq!(home_dir_key, services[1].1); 391 | 392 | // Remove a service 393 | let removed_service = services.remove(1); 394 | struct_data = unwrap_result!(dns_operations.remove_service(&dns_name, removed_service.0.clone(), &secret_signing_key, None)); 395 | unwrap_result!(unwrap_result!(client.lock()).post(Data::Structured(struct_data), None)); 396 | 397 | // Get all services 398 | let services_vec = unwrap_result!(dns_operations_unregistered.get_all_services(&dns_name, None)); 399 | assert_eq!(services.len(), services_vec.len()); 400 | assert!(services.iter().all(|&(ref a, _)| services_vec.iter().find(|b| *a == **b).is_some())); 401 | 402 | // TODO(Spandan) update all test cases for negative GET's once it is figured out how 403 | // Try to enquire about a deleted service 404 | // match dns_operations.get_service_home_directory_key(&dns_name, &removed_service.0, None) { 405 | // Ok(_) => panic!("Should have been an error"), 406 | // Err(::errors::DnsError::ServiceNotFound) => (), 407 | // Err(error) => panic!("{:?}", error), 408 | // } 409 | 410 | // Add a service 411 | services.push(("added-service".to_string(), 412 | ::safe_nfs::metadata::directory_key::DirectoryKey::new(XorName::new([126; 64]), 413 | 15000, 414 | false, 415 | ::safe_nfs::AccessLevel::Public))); 416 | let services_size = services.len(); 417 | struct_data = unwrap_result!(dns_operations.add_service(&dns_name, services[services_size - 1].clone(), &secret_signing_key, None)); 418 | unwrap_result!(unwrap_result!(client.lock()).post(Data::Structured(struct_data), None)); 419 | 420 | // Get all services 421 | let services_vec = unwrap_result!(dns_operations_unregistered.get_all_services(&dns_name, None)); 422 | assert_eq!(services.len(), services_vec.len()); 423 | assert!(services.iter().all(|&(ref a, _)| services_vec.iter().find(|b| *a == **b).is_some())); 424 | } 425 | } 426 | -------------------------------------------------------------------------------- /src/errors.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 7 | // By contributing code to the SAFE Network Software, or to this project generally, you agree to be 8 | // bound by the terms of the MaidSafe Contributor Agreement, version 1.0. This, along with the 9 | // Licenses can be found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | use maidsafe_utilities::serialisation::SerialisationError; 19 | 20 | /// Intended for converting DNS Errors into numeric codes for propagating some error information 21 | /// across FFI boundaries and specially to C. 22 | pub const DNS_ERROR_START_RANGE: i32 = ::safe_nfs::errors::NFS_ERROR_START_RANGE - 500; 23 | 24 | /// Safe-Dns specific errors 25 | pub enum DnsError { 26 | /// Errors from Safe-Client 27 | CoreError(::safe_core::errors::CoreError), 28 | /// Errors from Safe-Nfs 29 | NfsError(::safe_nfs::errors::NfsError), 30 | /// Dns record already exists 31 | DnsNameAlreadyRegistered, 32 | /// Dns record not found 33 | DnsRecordNotFound, 34 | /// Service already exists 35 | ServiceAlreadyExists, 36 | /// Service not found 37 | ServiceNotFound, 38 | /// Dns Configuration file not found or corrupted 39 | DnsConfigFileNotFoundOrCorrupted, 40 | /// Unexpected, probably due to logical error 41 | Unexpected(String), 42 | /// Could not serialise or deserialise data 43 | UnsuccessfulEncodeDecode(SerialisationError), 44 | } 45 | 46 | impl From for DnsError { 47 | fn from(error: SerialisationError) -> DnsError { 48 | DnsError::UnsuccessfulEncodeDecode(error) 49 | } 50 | } 51 | impl From<::safe_core::errors::CoreError> for DnsError { 52 | fn from(error: ::safe_core::errors::CoreError) -> DnsError { 53 | DnsError::CoreError(error) 54 | } 55 | } 56 | 57 | impl From<::safe_nfs::errors::NfsError> for DnsError { 58 | fn from(error: ::safe_nfs::errors::NfsError) -> DnsError { 59 | DnsError::NfsError(error) 60 | } 61 | } 62 | 63 | impl<'a> From<&'a str> for DnsError { 64 | fn from(error: &'a str) -> DnsError { 65 | DnsError::Unexpected(error.to_string()) 66 | } 67 | } 68 | 69 | impl Into for DnsError { 70 | fn into(self) -> i32 { 71 | match self { 72 | DnsError::CoreError(error) => error.into(), 73 | DnsError::NfsError(error) => error.into(), 74 | DnsError::DnsNameAlreadyRegistered => DNS_ERROR_START_RANGE, 75 | DnsError::DnsRecordNotFound => DNS_ERROR_START_RANGE - 1, 76 | DnsError::ServiceAlreadyExists => DNS_ERROR_START_RANGE - 2, 77 | DnsError::ServiceNotFound => DNS_ERROR_START_RANGE - 3, 78 | DnsError::DnsConfigFileNotFoundOrCorrupted => DNS_ERROR_START_RANGE - 4, 79 | DnsError::Unexpected(_) => DNS_ERROR_START_RANGE - 5, 80 | DnsError::UnsuccessfulEncodeDecode(_) => DNS_ERROR_START_RANGE - 6, 81 | } 82 | } 83 | } 84 | 85 | impl ::std::fmt::Debug for DnsError { 86 | fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { 87 | match *self { 88 | DnsError::CoreError(ref error) => write!(f, "DnsError::CoreError -> {:?}", error), 89 | DnsError::NfsError(ref error) => write!(f, "DnsError::NfsError -> {:?}", error), 90 | DnsError::DnsNameAlreadyRegistered => write!(f, "DnsError::DnsNameAlreadyRegistered"), 91 | DnsError::DnsRecordNotFound => write!(f, "DnsError::DnsRecordNotFound"), 92 | DnsError::ServiceAlreadyExists => write!(f, "DnsError::ServiceAlreadyExists"), 93 | DnsError::ServiceNotFound => write!(f, "DnsError::ServiceNotFound"), 94 | DnsError::DnsConfigFileNotFoundOrCorrupted => write!(f, "DnsError::DnsConfigFileNotFoundOrCorrupted"), 95 | DnsError::Unexpected(ref error) => write!(f, "DnsError::Unexpected::{{{:?}}}", error), 96 | DnsError::UnsuccessfulEncodeDecode(ref err) => write!(f, "DnsError::UnsuccessfulEncodeDecode -> {:?}", err), 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 MaidSafe.net limited. 2 | // 3 | // This SAFE Network Software is licensed to you under (1) the MaidSafe.net Commercial License, 4 | // version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which 5 | // licence you accepted on initial access to the Software (the "Licences"). 6 | // 7 | // By contributing code to the SAFE Network Software, or to this project generally, you agree to be 8 | // bound by the terms of the MaidSafe Contributor Agreement, version 1.0. This, along with the 9 | // Licenses can be found in the root directory of this project at LICENSE, COPYING and CONTRIBUTOR. 10 | // 11 | // Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed 12 | // under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 13 | // KIND, either express or implied. 14 | // 15 | // Please review the Licences for the specific language governing permissions and limitations 16 | // relating to use of the SAFE Network Software. 17 | 18 | //! #Safe-Dns Library 19 | //! This crate allows registered clients to create, delete and manipulate their DNS records in the 20 | //! SAFE-Network while allowing unregistered clients (like browers designed for SAFE-Network) to 21 | //! access and display the contents of such records, if it were created with Public Accessibility, 22 | //! ie., non-encrypted content. 23 | //! 24 | //! [Project github page](https://github.com/maidsafe/safe_dns) 25 | 26 | #![doc(html_logo_url = 27 | "https://raw.githubusercontent.com/maidsafe/QA/master/Images/maidsafe_logo.png", 28 | html_favicon_url = "http://maidsafe.net/img/favicon.ico", 29 | html_root_url = "http://maidsafe.github.io/safe_dns")] 30 | 31 | // For explanation of lint checks, run `rustc -W help` or see 32 | // https://github.com/maidsafe/QA/blob/master/Documentation/Rust%20Lint%20Checks.md 33 | #![forbid(bad_style, exceeding_bitshifts, mutable_transmutes, no_mangle_const_items, 34 | unknown_crate_types, warnings)] 35 | #![deny(deprecated, drop_with_repr_extern, improper_ctypes, missing_docs, 36 | non_shorthand_field_patterns, overflowing_literals, plugin_as_library, 37 | private_no_mangle_fns, private_no_mangle_statics, stable_features, unconditional_recursion, 38 | unknown_lints, unsafe_code, unused, unused_allocation, unused_attributes, 39 | unused_comparisons, unused_features, unused_parens, while_true)] 40 | #![warn(trivial_casts, trivial_numeric_casts, unused_extern_crates, unused_import_braces, 41 | unused_qualifications, unused_results)] 42 | #![allow(box_pointers, fat_ptr_transmutes, missing_copy_implementations, 43 | missing_debug_implementations, variant_size_differences)] 44 | 45 | #![cfg_attr(feature="clippy", feature(plugin))] 46 | #![cfg_attr(feature="clippy", plugin(clippy))] 47 | #![cfg_attr(feature="clippy", deny(clippy, clippy_pedantic))] 48 | 49 | extern crate routing; 50 | extern crate xor_name; 51 | extern crate safe_nfs; 52 | extern crate safe_core; 53 | extern crate sodiumoxide; 54 | extern crate rustc_serialize; 55 | #[macro_use] extern crate log; 56 | #[macro_use] extern crate maidsafe_utilities; 57 | 58 | /// Safe-Dns errors 59 | pub mod errors; 60 | /// Contains interfaces for all dns related operations 61 | pub mod dns_operations; 62 | --------------------------------------------------------------------------------