From a11a6be51a03a9673d1ab2709e3a457bfe553204 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Fri, 18 Oct 2024 10:59:17 +0100 Subject: [PATCH 01/50] integrating haskell orchestration --- .gitignore | 1 + haskell/.gitignore | 9 + haskell/LICENSE | 674 ++++++++++++++++++++++++++++++++++++ haskell/app/Main.hs | 111 ++++++ haskell/p2prc-haskell.cabal | 77 ++++ 5 files changed, 872 insertions(+) create mode 100644 haskell/.gitignore create mode 100644 haskell/LICENSE create mode 100644 haskell/app/Main.hs create mode 100644 haskell/p2prc-haskell.cabal diff --git a/.gitignore b/.gitignore index 1f8f00a..78e96b4 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ test* # Ignore public and private keys p2prc.publicKey p2prc.privateKey +p2prc.PublicKeyBareMetal diff --git a/haskell/.gitignore b/haskell/.gitignore new file mode 100644 index 0000000..f64da14 --- /dev/null +++ b/haskell/.gitignore @@ -0,0 +1,9 @@ +CHANGELOG.md +client +config.json +dist-newstyle +p2p +p2prc.privateKey +p2prc.PublicKeyBareMetal +plugin +server diff --git a/haskell/LICENSE b/haskell/LICENSE new file mode 100644 index 0000000..45644ff --- /dev/null +++ b/haskell/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs new file mode 100644 index 0000000..3bae81c --- /dev/null +++ b/haskell/app/Main.hs @@ -0,0 +1,111 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Main where + + +import Data.Aeson + +import Data.List + +import System.Process (readProcess, terminateProcess, ProcessHandle, spawnProcess) + +import Control.Monad (MonadPlus(mzero)) + +import Control.Concurrent (threadDelay) + +import qualified Data.ByteString.Lazy as LB +import qualified Data.ByteString.Lazy.Char8 as LBC8 + + +import qualified Data.Text as T + + +main :: IO () +main = do + + -- outputStr <- execProcP2Prc ["-dc"] + + cmdOut <- getP2PrcCmd + putStrLn cmdOut + + -- startProcessHandle <- spawnProcP2Prc ["-s"] + + -- sleepNSecs 5 + + -- outputStr <- (execProcP2PrcParser ["-ls"] :: IO (Either String IPAdressTable)) + -- print outputStr + + -- outputStr <- execProcP2Prc ["--help"] + -- print outputStr + + -- terminateProcess startProcessHandle + + +newtype IPAdressTable + = MkIPAdressTable [ServerInfo] + deriving Show + +instance FromJSON IPAdressTable where + parseJSON = withObject "IPAdressTable" $ + \v -> + MkIPAdressTable <$> v .: "ip_address" + + + +data ServerInfo = MkServerInfo + { serverInfoName :: String + -- , serverInfoIp4 :: String + -- , serverInfoIp6 :: String + -- , serverInfoLatency :: Int + -- , serverInfoDownload :: Int + -- , serverInfoUpload :: Int + -- , serverInfoServerPort :: Int + -- , serverInfoBareMetalSSHPort :: Maybe Int + -- , serverInfoNat :: Bool + -- , serverInfoEscapeImplementation :: Maybe String + -- , serverInfoCustomInformation :: Maybe String + } + deriving Show + + +instance FromJSON ServerInfo where + parseJSON (Object o) = MkServerInfo + <$> o .: "Name" + -- <*> o .: "IPV4" + -- <*> o .: "IPV6" + -- <*> o .: "Latency" + -- <*> o .: "Download" + -- <*> o .: "Upload" + -- <*> o .: "ServerPort" + -- <*> o .: "BareMetalSSHPort" + -- <*> o .: "NAT" + -- <*> o .: "EscapeImplementation" + -- <*> o .: "CustomInformation" + parseJSON _ = mzero + + + +sleepNSecs :: Int -> IO () +sleepNSecs i = threadDelay (i * 1000000) + + + +execProcP2PrcParser :: FromJSON a => [String] -> IO (Either String a) +execProcP2PrcParser opts = eitherDecode . LBC8.pack <$> execProcP2Prc opts + + +execProcP2Prc :: [String] -> IO String +execProcP2Prc opts = readProcess p2prcCmd opts "" + +spawnProcP2Prc :: [String] -> IO ProcessHandle +spawnProcP2Prc = spawnProcess p2prcCmd + + +p2prcCmd = "/home/xecarlox/Desktop/p2p-rendering-computation/p2prc" :: String + + +getP2PrcCmd :: IO String +getP2PrcCmd = do + pwdOut <- readProcess "pwd" [] "" + readProcess "sed" ["s/haskell/p2prc/"] pwdOut + diff --git a/haskell/p2prc-haskell.cabal b/haskell/p2prc-haskell.cabal new file mode 100644 index 0000000..002f336 --- /dev/null +++ b/haskell/p2prc-haskell.cabal @@ -0,0 +1,77 @@ +cabal-version: 3.0 +-- The cabal-version field refers to the version of the .cabal specification, +-- and can be different from the cabal-install (the tool) version and the +-- Cabal (the library) version you are using. As such, the Cabal (the library) +-- version used must be equal or greater than the version stated in this field. +-- Starting from the specification version 2.2, the cabal-version field must be +-- the first thing in the cabal file. + +-- Initial package description 'p2prc-haskell' generated by +-- 'cabal init'. For further documentation, see: +-- http://haskell.org/cabal/users-guide/ +-- +-- The name of the package. +name: p2prc-haskell + +-- The package version. +-- See the Haskell package versioning policy (PVP) for standards +-- guiding when and how versions should be incremented. +-- https://pvp.haskell.org +-- PVP summary: +-+------- breaking API changes +-- | | +----- non-breaking API additions +-- | | | +--- code changes with no API change +version: 0.1.0.0 + +-- A short (one-line) description of the package. +-- synopsis: + +-- A longer description of the package. +-- description: + +-- The license under which the package is released. +license: GPL-3.0-only + +-- The file containing the license text. +license-file: LICENSE + +-- The package author(s). +author: xecarlox94 + +-- An email address to which users can send suggestions, bug reports, and patches. +maintainer: jf94.uk@gmail.com + +-- A copyright notice. +-- copyright: +category: Network +build-type: Simple + +-- Extra doc files to be distributed with the package, such as a CHANGELOG or a README. +extra-doc-files: CHANGELOG.md + +-- Extra source files to be distributed with the package, such as examples, or a tutorial module. +-- extra-source-files: + +common warnings + ghc-options: -Wall + +executable p2prc-haskell + -- Import common warning flags. + import: warnings + + -- .hs or .lhs file containing the Main module. + main-is: Main.hs + + -- Modules included in this executable, other than Main. + -- other-modules: + + -- LANGUAGE extensions used by modules in this package. + other-extensions: OverloadedStrings + + -- Other library packages from which modules are imported. + build-depends: base, text, aeson, process, bytestring + + -- Directories containing source files. + hs-source-dirs: app + + -- Base language which the package is written in. + default-language: GHC2021 From 35b16db6b930b17c1e7882a7d8e22e29c3246a11 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Fri, 18 Oct 2024 11:37:13 +0100 Subject: [PATCH 02/50] adding todos --- haskell/app/Main.hs | 25 +++++++++++++++++-------- haskell/p2prc-haskell.cabal | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 3bae81c..8ec3df3 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -3,9 +3,8 @@ module Main where -import Data.Aeson -import Data.List +import Data.Aeson import System.Process (readProcess, terminateProcess, ProcessHandle, spawnProcess) @@ -13,16 +12,24 @@ import Control.Monad (MonadPlus(mzero)) import Control.Concurrent (threadDelay) -import qualified Data.ByteString.Lazy as LB import qualified Data.ByteString.Lazy.Char8 as LBC8 -import qualified Data.Text as T +-- TODO: Use it +-- import qualified Data.Text as T + +-- TODO: create library to abstract shell and go-level logic + main :: IO () main = do + -- TODO: add IO arguments; flag to cleanup environment + + -- TODO create record with all functions needed + + -- TODO: initialise environment; perhaps cleanup state files -- outputStr <- execProcP2Prc ["-dc"] cmdOut <- getP2PrcCmd @@ -52,6 +59,7 @@ instance FromJSON IPAdressTable where +-- TODO: refactor this datatype; better definition data ServerInfo = MkServerInfo { serverInfoName :: String -- , serverInfoIp4 :: String @@ -84,13 +92,14 @@ instance FromJSON ServerInfo where parseJSON _ = mzero - sleepNSecs :: Int -> IO () sleepNSecs i = threadDelay (i * 1000000) - -execProcP2PrcParser :: FromJSON a => [String] -> IO (Either String a) +execProcP2PrcParser :: + FromJSON a => + -- TODO: add error Type + [String] -> IO (Either String a) execProcP2PrcParser opts = eitherDecode . LBC8.pack <$> execProcP2Prc opts @@ -107,5 +116,5 @@ p2prcCmd = "/home/xecarlox/Desktop/p2p-rendering-computation/p2prc" :: String getP2PrcCmd :: IO String getP2PrcCmd = do pwdOut <- readProcess "pwd" [] "" - readProcess "sed" ["s/haskell/p2prc/"] pwdOut + readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut diff --git a/haskell/p2prc-haskell.cabal b/haskell/p2prc-haskell.cabal index 002f336..5eb92eb 100644 --- a/haskell/p2prc-haskell.cabal +++ b/haskell/p2prc-haskell.cabal @@ -1,4 +1,5 @@ cabal-version: 3.0 + -- The cabal-version field refers to the version of the .cabal specification, -- and can be different from the cabal-install (the tool) version and the -- Cabal (the library) version you are using. As such, the Cabal (the library) From fcda233ddb34a2ad7a8ecc1faaedd40cbf4ac593 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 19 Oct 2024 12:39:24 +0100 Subject: [PATCH 03/50] adding data types to inputs and outputs of shell commands --- haskell/app/Main.hs | 84 +++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 26 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 8ec3df3..9f51929 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -30,23 +30,23 @@ main = do -- TODO create record with all functions needed -- TODO: initialise environment; perhaps cleanup state files - -- outputStr <- execProcP2Prc ["-dc"] + outputStr <- execProcP2Prc [MkOptAtomic "-dc"] cmdOut <- getP2PrcCmd + + startProcessHandle <- spawnProcP2Prc [MkOptAtomic "-s"] + + sleepNSecs 5 + + outputStr <- (execProcP2PrcParser [MkOptAtomic "-ls"] :: IO (Either Error IPAdressTable)) + print outputStr + + outputStr <- execProcP2Prc [MkOptAtomic "--help"] + print outputStr + + terminateProcess startProcessHandle putStrLn cmdOut - -- startProcessHandle <- spawnProcP2Prc ["-s"] - - -- sleepNSecs 5 - - -- outputStr <- (execProcP2PrcParser ["-ls"] :: IO (Either String IPAdressTable)) - -- print outputStr - - -- outputStr <- execProcP2Prc ["--help"] - -- print outputStr - - -- terminateProcess startProcessHandle - newtype IPAdressTable = MkIPAdressTable [ServerInfo] @@ -92,29 +92,61 @@ instance FromJSON ServerInfo where parseJSON _ = mzero -sleepNSecs :: Int -> IO () -sleepNSecs i = threadDelay (i * 1000000) - - execProcP2PrcParser :: FromJSON a => - -- TODO: add error Type - [String] -> IO (Either String a) -execProcP2PrcParser opts = eitherDecode . LBC8.pack <$> execProcP2Prc opts + [CLIOpt] -> IO (Either Error a) +execProcP2PrcParser opts = + eitherErrorDecode . eitherDecode . LBC8.pack <$> execProcP2Prc opts -execProcP2Prc :: [String] -> IO String -execProcP2Prc opts = readProcess p2prcCmd opts "" +data CLIOpt + = MkOptAtomic String + | MkOptTuple (String, String) -spawnProcP2Prc :: [String] -> IO ProcessHandle -spawnProcP2Prc = spawnProcess p2prcCmd +type CLIOptsInput = [String] + +optsToCLI :: [CLIOpt] -> CLIOptsInput +optsToCLI = concatMap _optToCLI + where + + _optToCLI :: CLIOpt -> CLIOptsInput + _optToCLI (MkOptAtomic o) = [o] + _optToCLI (MkOptTuple (o, v)) = [o, show v] + + +execProcP2Prc :: [CLIOpt] -> IO String +execProcP2Prc opts = readProcess p2prcCmd (optsToCLI opts) "" + +spawnProcP2Prc :: [CLIOpt] -> IO ProcessHandle +spawnProcP2Prc opts = spawnProcess p2prcCmd $ optsToCLI opts p2prcCmd = "/home/xecarlox/Desktop/p2p-rendering-computation/p2prc" :: String + getP2PrcCmd :: IO String getP2PrcCmd = do - pwdOut <- readProcess "pwd" [] "" - readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + -- assumes the program is ran inside the haskell module in p2prc's repo + readProcess "pwd" [] "" >>= + \pwdOut -> + -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" + readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + + +eitherErrorDecode :: + Either String a -> Either Error a +eitherErrorDecode esa = case esa of + (Left s) -> Left $ assignError s + (Right v) -> Right v + +data Error = MkError String + deriving Show + +assignError :: String -> Error +assignError = MkError + +sleepNSecs :: Int -> IO () +sleepNSecs i = threadDelay (i * 1000000) + From 65265c08b0e3ecce130c0dce7019644c85e9cefe Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 19 Oct 2024 13:12:38 +0100 Subject: [PATCH 04/50] adding data types to inputs and outputs of shell commands --- haskell/app/Main.hs | 58 +++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 9f51929..ee877ca 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -30,7 +30,7 @@ main = do -- TODO create record with all functions needed -- TODO: initialise environment; perhaps cleanup state files - outputStr <- execProcP2Prc [MkOptAtomic "-dc"] + _ <- execProcP2Prc [MkOptAtomic "-dc"] MkEmpty cmdOut <- getP2PrcCmd @@ -38,13 +38,11 @@ main = do sleepNSecs 5 - outputStr <- (execProcP2PrcParser [MkOptAtomic "-ls"] :: IO (Either Error IPAdressTable)) - print outputStr - - outputStr <- execProcP2Prc [MkOptAtomic "--help"] + outputStr <- (execProcP2PrcParser [MkOptAtomic "-ls"] MkEmpty :: IOEitherError IPAdressTable) print outputStr terminateProcess startProcessHandle + putStrLn cmdOut @@ -92,11 +90,34 @@ instance FromJSON ServerInfo where parseJSON _ = mzero +data StdInput + = MkEmpty + +instance Show StdInput where + show MkEmpty = "" + + + +type IOEitherError a = IO (Either Error a) + execProcP2PrcParser :: FromJSON a => - [CLIOpt] -> IO (Either Error a) -execProcP2PrcParser opts = - eitherErrorDecode . eitherDecode . LBC8.pack <$> execProcP2Prc opts + [CLIOpt] -> StdInput -> IOEitherError a +execProcP2PrcParser opts stdInput = + eitherErrDecode + <$> execProcP2Prc opts stdInput + + where + + eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack + + +execProcP2Prc :: [CLIOpt] -> StdInput -> IO String +execProcP2Prc ops stdi = + readProcess + p2prcCmd + (optsToCLI ops) + (show stdi) data CLIOpt @@ -114,14 +135,12 @@ optsToCLI = concatMap _optToCLI _optToCLI (MkOptTuple (o, v)) = [o, show v] -execProcP2Prc :: [CLIOpt] -> IO String -execProcP2Prc opts = readProcess p2prcCmd (optsToCLI opts) "" - spawnProcP2Prc :: [CLIOpt] -> IO ProcessHandle -spawnProcP2Prc opts = spawnProcess p2prcCmd $ optsToCLI opts +spawnProcP2Prc = + spawnProcess p2prcCmd . optsToCLI -p2prcCmd = "/home/xecarlox/Desktop/p2p-rendering-computation/p2prc" :: String +p2prcCmd = "/home/xecarlox/Desktop/p2p-rendering-computation/p2p-rendering-computation" :: String @@ -134,17 +153,20 @@ getP2PrcCmd = do readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut -eitherErrorDecode :: - Either String a -> Either Error a -eitherErrorDecode esa = case esa of - (Left s) -> Left $ assignError s - (Right v) -> Right v +eitherErrorDecode :: Either String a -> Either Error a +eitherErrorDecode esa = + case esa of + (Left s) -> Left $ assignError s + (Right v) -> Right v + data Error = MkError String deriving Show assignError :: String -> Error assignError = MkError +-- TODO: add megaparsec to parse Error Messages + sleepNSecs :: Int -> IO () sleepNSecs i = threadDelay (i * 1000000) From 1e773748fc134a08f4b4c30b7a9e8d27746b509d Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 19 Oct 2024 14:26:11 +0100 Subject: [PATCH 05/50] finished parsing Server information data --- haskell/app/Main.hs | 134 +++++++++++++++++++++++++++----------------- 1 file changed, 83 insertions(+), 51 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index ee877ca..0d978a2 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -2,14 +2,10 @@ module Main where - - import Data.Aeson import System.Process (readProcess, terminateProcess, ProcessHandle, spawnProcess) -import Control.Monad (MonadPlus(mzero)) - import Control.Concurrent (threadDelay) import qualified Data.ByteString.Lazy.Char8 as LBC8 @@ -19,18 +15,19 @@ import qualified Data.ByteString.Lazy.Char8 as LBC8 -- import qualified Data.Text as T - -- TODO: create library to abstract shell and go-level logic - main :: IO () main = do + -- TODO: add IO arguments; flag to optionally cleanup environment + -- TODO: add GDTA syntax to data types - -- TODO: add IO arguments; flag to cleanup environment + -- -- TODO: initialise environment; perhaps cleanup state files + -- _ <- execProcP2Prc [MkOptAtomic "-dc"] MkEmpty - -- TODO create record with all functions needed - -- TODO: initialise environment; perhaps cleanup state files - _ <- execProcP2Prc [MkOptAtomic "-dc"] MkEmpty + -- TODO: create record with all functions needed + -- + -- TODO: Add loop to print servers list cmdOut <- getP2PrcCmd @@ -56,38 +53,75 @@ instance FromJSON IPAdressTable where MkIPAdressTable <$> v .: "ip_address" - --- TODO: refactor this datatype; better definition data ServerInfo = MkServerInfo - { serverInfoName :: String - -- , serverInfoIp4 :: String - -- , serverInfoIp6 :: String - -- , serverInfoLatency :: Int - -- , serverInfoDownload :: Int - -- , serverInfoUpload :: Int - -- , serverInfoServerPort :: Int - -- , serverInfoBareMetalSSHPort :: Maybe Int - -- , serverInfoNat :: Bool - -- , serverInfoEscapeImplementation :: Maybe String - -- , serverInfoCustomInformation :: Maybe String + { name :: String + , ip :: IPAddress + , latency :: Int + , download :: Int + , upload :: Int + , serverPort :: Int -- TODO: verify if it is Maybe value + , bareMetalSSHPort :: Maybe Int -- TODO: verify if it is Maybe value + , nat :: Bool + , escapeImplementation :: Maybe String + , customInformation :: Maybe String } deriving Show +data IPAddress + = MkIPv4 String + | MkIPv6 String + deriving Show + + instance FromJSON ServerInfo where - parseJSON (Object o) = MkServerInfo - <$> o .: "Name" - -- <*> o .: "IPV4" - -- <*> o .: "IPV6" - -- <*> o .: "Latency" - -- <*> o .: "Download" - -- <*> o .: "Upload" - -- <*> o .: "ServerPort" - -- <*> o .: "BareMetalSSHPort" - -- <*> o .: "NAT" - -- <*> o .: "EscapeImplementation" - -- <*> o .: "CustomInformation" - parseJSON _ = mzero + parseJSON = withObject "ServerInfo" $ \o -> do + name <- o .: "Name" + ip4str <- o .: "IPV4" + ip6str <- o .: "IPV6" + latency <- o .: "Latency" + download <- o .: "Download" + upload <- o .: "Upload" + serverPort <- o .: "ServerPort" + bmSshPort <- o .: "BareMetalSSHPort" + nat <- o .: "NAT" + mEscImpl <- o .: "EscapeImplementation" + custInfo <- o .: "CustomInformation" + + pure $ + MkServerInfo + { name = name + , ip = getIPAddress ip4str ip6str + , latency = latency + , download = download + , upload = upload + , serverPort = getPortUNSAFE serverPort + , bareMetalSSHPort = getBMShhPort bmSshPort + , nat = getNat nat + , escapeImplementation = mEscImpl + , customInformation = custInfo + } + + where + + getNat :: String -> Bool + getNat ('T':_) = True + getNat _ = False + + getBMShhPort :: String -> Maybe Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! + getBMShhPort [] = Nothing + getBMShhPort bmSshPort = Just $ getPortUNSAFE bmSshPort + + getPortUNSAFE :: String -> Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! + getPortUNSAFE = read + + getIPAddress :: String -> String -> IPAddress + getIPAddress [] ip6 = MkIPv6 ip6 + getIPAddress ip4 _ = MkIPv4 ip4 + + +-- TODO: remove this variable +p2prcCmd = "/home/xecarlox/Desktop/p2p-rendering-computation/p2p-rendering-computation" :: String data StdInput @@ -103,9 +137,10 @@ type IOEitherError a = IO (Either Error a) execProcP2PrcParser :: FromJSON a => [CLIOpt] -> StdInput -> IOEitherError a -execProcP2PrcParser opts stdInput = - eitherErrDecode - <$> execProcP2Prc opts stdInput +execProcP2PrcParser opts stdInput + = + eitherErrDecode + <$> execProcP2Prc opts stdInput where @@ -125,6 +160,7 @@ data CLIOpt | MkOptTuple (String, String) type CLIOptsInput = [String] +type CLICmd = String optsToCLI :: [CLIOpt] -> CLIOptsInput optsToCLI = concatMap _optToCLI @@ -140,18 +176,6 @@ spawnProcP2Prc = spawnProcess p2prcCmd . optsToCLI -p2prcCmd = "/home/xecarlox/Desktop/p2p-rendering-computation/p2p-rendering-computation" :: String - - - -getP2PrcCmd :: IO String -getP2PrcCmd = do - -- assumes the program is ran inside the haskell module in p2prc's repo - readProcess "pwd" [] "" >>= - \pwdOut -> - -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" - readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut - eitherErrorDecode :: Either String a -> Either Error a eitherErrorDecode esa = @@ -172,3 +196,11 @@ sleepNSecs :: Int -> IO () sleepNSecs i = threadDelay (i * 1000000) + +getP2PrcCmd :: IO String +getP2PrcCmd = do + -- assumes the program is ran inside the haskell module in p2prc's repo + readProcess "pwd" [] "" >>= + \pwdOut -> + -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" + readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut From 4a9d1e237fd221960ec8e39d550963cecf04f121 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 19 Oct 2024 18:47:50 +0100 Subject: [PATCH 06/50] fixed cmd location issue --- haskell/app/Main.hs | 49 ++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 0d978a2..20aacab 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -12,7 +12,7 @@ import qualified Data.ByteString.Lazy.Char8 as LBC8 -- TODO: Use it --- import qualified Data.Text as T +import qualified Data.Text as T -- TODO: create library to abstract shell and go-level logic @@ -29,18 +29,23 @@ main = do -- -- TODO: Add loop to print servers list - cmdOut <- getP2PrcCmd - startProcessHandle <- spawnProcP2Prc [MkOptAtomic "-s"] + -- solve this issue + p2prcCmd <- getP2PrcCmd + + startProcessHandle <- spawnProcP2Prc p2prcCmd [MkOptAtomic "-s"] sleepNSecs 5 - outputStr <- (execProcP2PrcParser [MkOptAtomic "-ls"] MkEmpty :: IOEitherError IPAdressTable) + let execProcP2PrcParser = execProcP2PrcParser_ p2prcCmd + + outputStr <- execProcP2PrcParser [MkOptAtomic "-ls"] MkEmpty :: IOEitherError IPAdressTable print outputStr terminateProcess startProcessHandle - putStrLn cmdOut + +-- getP2PRCapi :: newtype IPAdressTable @@ -54,7 +59,7 @@ instance FromJSON IPAdressTable where data ServerInfo = MkServerInfo - { name :: String + { name :: T.Text , ip :: IPAddress , latency :: Int , download :: Int @@ -62,8 +67,8 @@ data ServerInfo = MkServerInfo , serverPort :: Int -- TODO: verify if it is Maybe value , bareMetalSSHPort :: Maybe Int -- TODO: verify if it is Maybe value , nat :: Bool - , escapeImplementation :: Maybe String - , customInformation :: Maybe String + , escapeImplementation :: Maybe T.Text + , customInformation :: Maybe T.Text } deriving Show @@ -120,9 +125,6 @@ instance FromJSON ServerInfo where getIPAddress ip4 _ = MkIPv4 ip4 --- TODO: remove this variable -p2prcCmd = "/home/xecarlox/Desktop/p2p-rendering-computation/p2p-rendering-computation" :: String - data StdInput = MkEmpty @@ -134,21 +136,21 @@ instance Show StdInput where type IOEitherError a = IO (Either Error a) -execProcP2PrcParser :: +execProcP2PrcParser_ :: FromJSON a => - [CLIOpt] -> StdInput -> IOEitherError a -execProcP2PrcParser opts stdInput + CLICmd -> [CLIOpt] -> StdInput -> IOEitherError a +execProcP2PrcParser_ p2prcCmd opts stdInput = eitherErrDecode - <$> execProcP2Prc opts stdInput + <$> execProcP2Prc_ p2prcCmd opts stdInput where eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack -execProcP2Prc :: [CLIOpt] -> StdInput -> IO String -execProcP2Prc ops stdi = +execProcP2Prc_ :: CLICmd -> [CLIOpt] -> StdInput -> IO String +execProcP2Prc_ p2prcCmd ops stdi = readProcess p2prcCmd (optsToCLI ops) @@ -171,8 +173,8 @@ optsToCLI = concatMap _optToCLI _optToCLI (MkOptTuple (o, v)) = [o, show v] -spawnProcP2Prc :: [CLIOpt] -> IO ProcessHandle -spawnProcP2Prc = +spawnProcP2Prc :: CLICmd -> [CLIOpt] -> IO ProcessHandle +spawnProcP2Prc p2prcCmd = spawnProcess p2prcCmd . optsToCLI @@ -201,6 +203,11 @@ getP2PrcCmd :: IO String getP2PrcCmd = do -- assumes the program is ran inside the haskell module in p2prc's repo readProcess "pwd" [] "" >>= - \pwdOut -> + \pwdOut -> do -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" - readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + + -- need to strip the newline and return a String again + let strip = T.unpack . T.strip . T.pack + + strip <$> readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + From b2a03312a8924e817c91336190090343d44a4567 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 19 Oct 2024 20:25:55 +0100 Subject: [PATCH 07/50] working on haskell API --- haskell/app/Main.hs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 20aacab..d2c5a2f 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -29,8 +29,6 @@ main = do -- -- TODO: Add loop to print servers list - - -- solve this issue p2prcCmd <- getP2PrcCmd startProcessHandle <- spawnProcP2Prc p2prcCmd [MkOptAtomic "-s"] @@ -45,7 +43,26 @@ main = do terminateProcess startProcessHandle --- getP2PRCapi :: +{- +data P2PRCapi = + MkP2PRCapi + { startServer :: IO ProcessHandle + , defineConfiguration :: IO String + , getListServers :: IOEitherError IPAdressTable + } + +getP2PRCapi :: IO P2PRCapi +getP2PRCapi = do + p2prcCmd <- getP2PrcCmd + + startProcessHandle <- spawnProcP2Prc p2prcCmd [MkOptAtomic "-s"] + + sleepNSecs 5 + + let execProcP2PrcParser = execProcP2PrcParser_ p2prcCmd + + outputStr <- execProcP2PrcParser [MkOptAtomic "-ls"] MkEmpty :: IOEitherError IPAdressTable +-} newtype IPAdressTable @@ -109,7 +126,7 @@ instance FromJSON ServerInfo where where - getNat :: String -> Bool + getNat :: String -> Bool -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! getNat ('T':_) = True getNat _ = False @@ -201,13 +218,14 @@ sleepNSecs i = threadDelay (i * 1000000) getP2PrcCmd :: IO String getP2PrcCmd = do + -- assumes the program is ran inside the haskell module in p2prc's repo readProcess "pwd" [] "" >>= \pwdOut -> do - -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" -- need to strip the newline and return a String again let strip = T.unpack . T.strip . T.pack + -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" strip <$> readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut From 10c1548b283cba2eedee3f815593fb97e21e4ef1 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 19 Oct 2024 20:36:17 +0100 Subject: [PATCH 08/50] added stdInput and shell options --- haskell/app/Main.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index d2c5a2f..7938cc5 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -37,7 +37,7 @@ main = do let execProcP2PrcParser = execProcP2PrcParser_ p2prcCmd - outputStr <- execProcP2PrcParser [MkOptAtomic "-ls"] MkEmpty :: IOEitherError IPAdressTable + outputStr <- execProcP2PrcParser [MkOptAtomic "-ls"] MkEmptyStdInput :: IOEitherError IPAdressTable print outputStr terminateProcess startProcessHandle @@ -81,8 +81,8 @@ data ServerInfo = MkServerInfo , latency :: Int , download :: Int , upload :: Int - , serverPort :: Int -- TODO: verify if it is Maybe value - , bareMetalSSHPort :: Maybe Int -- TODO: verify if it is Maybe value + , serverPort :: Int + , bareMetalSSHPort :: Maybe Int , nat :: Bool , escapeImplementation :: Maybe T.Text , customInformation :: Maybe T.Text @@ -144,10 +144,12 @@ instance FromJSON ServerInfo where data StdInput - = MkEmpty + = MkEmptyStdInput + | MkStdInputVal String instance Show StdInput where - show MkEmpty = "" + show MkEmptyStdInput = "" + show (MkStdInputVal v) = show v @@ -175,7 +177,8 @@ execProcP2Prc_ p2prcCmd ops stdi = data CLIOpt - = MkOptAtomic String + = MkEmptyOpts + | MkOptAtomic String | MkOptTuple (String, String) type CLIOptsInput = [String] @@ -186,7 +189,8 @@ optsToCLI = concatMap _optToCLI where _optToCLI :: CLIOpt -> CLIOptsInput - _optToCLI (MkOptAtomic o) = [o] + _optToCLI MkEmptyOpts = [] + _optToCLI (MkOptAtomic o) = [o] _optToCLI (MkOptTuple (o, v)) = [o, show v] @@ -215,7 +219,6 @@ sleepNSecs :: Int -> IO () sleepNSecs i = threadDelay (i * 1000000) - getP2PrcCmd :: IO String getP2PrcCmd = do @@ -229,3 +232,4 @@ getP2PrcCmd = do -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" strip <$> readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + From be1e2ec384817cd37a83bede46a2e02f21231e12 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 19 Oct 2024 22:39:23 +0100 Subject: [PATCH 09/50] finished initial API --- haskell/app/Main.hs | 123 +++++++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 53 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 7938cc5..8fed60a 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -21,48 +21,59 @@ main = do -- TODO: add IO arguments; flag to optionally cleanup environment -- TODO: add GDTA syntax to data types - -- -- TODO: initialise environment; perhaps cleanup state files - -- _ <- execProcP2Prc [MkOptAtomic "-dc"] MkEmpty + p2prcAPI <- getP2prcAPI + let + ( MkP2prAPI + { startServer = startServer + , execInitConfig = execInitConfig + , execListServers = execListServers + } + ) = p2prcAPI + + -- TODO: initialise environment; perhaps cleanup state files + -- + -- TODO: make it pure environment by default + _ <- execInitConfig -- TODO: create record with all functions needed -- -- TODO: Add loop to print servers list - p2prcCmd <- getP2PrcCmd - - startProcessHandle <- spawnProcP2Prc p2prcCmd [MkOptAtomic "-s"] + startProcessHandle <- startServer sleepNSecs 5 - let execProcP2PrcParser = execProcP2PrcParser_ p2prcCmd - - outputStr <- execProcP2PrcParser [MkOptAtomic "-ls"] MkEmptyStdInput :: IOEitherError IPAdressTable + outputStr <- execListServers print outputStr terminateProcess startProcessHandle -{- -data P2PRCapi = - MkP2PRCapi - { startServer :: IO ProcessHandle - , defineConfiguration :: IO String - , getListServers :: IOEitherError IPAdressTable - } -getP2PRCapi :: IO P2PRCapi -getP2PRCapi = do + +data P2prAPI = MkP2prAPI + { startServer :: IO ProcessHandle + , execInitConfig :: IO String + , execListServers :: IOEitherError IPAdressTable + } + + +getP2prcAPI :: IO P2prAPI +getP2prcAPI = do + p2prcCmd <- getP2PrcCmd - startProcessHandle <- spawnProcP2Prc p2prcCmd [MkOptAtomic "-s"] - - sleepNSecs 5 - let execProcP2PrcParser = execProcP2PrcParser_ p2prcCmd + let execProcP2Prc = execProcP2Prc_ p2prcCmd + + return $ + MkP2prAPI + { startServer = spawnProcP2Prc p2prcCmd [MkOptAtomic "-s"] + , execInitConfig = execProcP2Prc [MkOptAtomic "-dc"] MkEmptyStdInput + , execListServers = execProcP2PrcParser [MkOptAtomic "-ls"] MkEmptyStdInput + } - outputStr <- execProcP2PrcParser [MkOptAtomic "-ls"] MkEmpty :: IOEitherError IPAdressTable --} newtype IPAdressTable @@ -97,32 +108,34 @@ data IPAddress instance FromJSON ServerInfo where - parseJSON = withObject "ServerInfo" $ \o -> do - name <- o .: "Name" - ip4str <- o .: "IPV4" - ip6str <- o .: "IPV6" - latency <- o .: "Latency" - download <- o .: "Download" - upload <- o .: "Upload" - serverPort <- o .: "ServerPort" - bmSshPort <- o .: "BareMetalSSHPort" - nat <- o .: "NAT" - mEscImpl <- o .: "EscapeImplementation" - custInfo <- o .: "CustomInformation" + parseJSON = withObject "ServerInfo" $ + \o -> do - pure $ - MkServerInfo - { name = name - , ip = getIPAddress ip4str ip6str - , latency = latency - , download = download - , upload = upload - , serverPort = getPortUNSAFE serverPort - , bareMetalSSHPort = getBMShhPort bmSshPort - , nat = getNat nat - , escapeImplementation = mEscImpl - , customInformation = custInfo - } + name <- o .: "Name" + ip4str <- o .: "IPV4" + ip6str <- o .: "IPV6" + latency <- o .: "Latency" + download <- o .: "Download" + upload <- o .: "Upload" + serverPort <- o .: "ServerPort" + bmSshPort <- o .: "BareMetalSSHPort" + nat <- o .: "NAT" + mEscImpl <- o .: "EscapeImplementation" + custInfo <- o .: "CustomInformation" + + pure $ + MkServerInfo + { name = name + , ip = getIPAddress ip4str ip6str + , latency = latency + , download = download + , upload = upload + , serverPort = getPortUNSAFE serverPort + , bareMetalSSHPort = getBMShhPort bmSshPort + , nat = getNat nat + , escapeImplementation = mEscImpl + , customInformation = custInfo + } where @@ -152,7 +165,6 @@ instance Show StdInput where show (MkStdInputVal v) = show v - type IOEitherError a = IO (Either Error a) execProcP2PrcParser_ :: @@ -165,9 +177,13 @@ execProcP2PrcParser_ p2prcCmd opts stdInput where + eitherErrDecode :: + FromJSON a => + String -> Either Error a eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack + execProcP2Prc_ :: CLICmd -> [CLIOpt] -> StdInput -> IO String execProcP2Prc_ p2prcCmd ops stdi = readProcess @@ -181,9 +197,11 @@ data CLIOpt | MkOptAtomic String | MkOptTuple (String, String) + type CLIOptsInput = [String] type CLICmd = String + optsToCLI :: [CLIOpt] -> CLIOptsInput optsToCLI = concatMap _optToCLI where @@ -215,10 +233,6 @@ assignError = MkError -- TODO: add megaparsec to parse Error Messages -sleepNSecs :: Int -> IO () -sleepNSecs i = threadDelay (i * 1000000) - - getP2PrcCmd :: IO String getP2PrcCmd = do @@ -233,3 +247,6 @@ getP2PrcCmd = do strip <$> readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + +sleepNSecs :: Int -> IO () +sleepNSecs i = threadDelay (i * 1000000) From 02be206221a42c3a4d2e0fca729d280aff447db2 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 19 Oct 2024 22:52:39 +0100 Subject: [PATCH 10/50] brainstorming: basic use case --- haskell/app/Main.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 8fed60a..8d1bb9c 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -44,6 +44,16 @@ main = do sleepNSecs 5 + -- Loop (Run replica of haskell program on different $NODES) + -- - Start server + -- - wait 4 seconds + -- - Identify new node running p2prc with SSH external port exposed + -- - SSH into machine + -- - Use simple File transfer to setup files + -- - Run server + -- - Use remote machine p2prc cmd to map a port using --mp + -- - Return back the exposed public IP and port number back to stdout + outputStr <- execListServers print outputStr From 5766623d7d8d60360a7e57e70543e322912b0eb7 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 19 Oct 2024 23:22:38 +0100 Subject: [PATCH 11/50] adding next API end point goal --- haskell/app/Main.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 8d1bb9c..f4eee09 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -44,6 +44,13 @@ main = do sleepNSecs 5 + outputStr <- execListServers + print outputStr + + -- Mapport - Number + + terminateProcess startProcessHandle + -- Loop (Run replica of haskell program on different $NODES) -- - Start server -- - wait 4 seconds @@ -54,12 +61,6 @@ main = do -- - Use remote machine p2prc cmd to map a port using --mp -- - Return back the exposed public IP and port number back to stdout - outputStr <- execListServers - print outputStr - - terminateProcess startProcessHandle - - data P2prAPI = MkP2prAPI From 182f7fb10f1f6718b125db3258b5624dea0a5b7f Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 20 Oct 2024 21:33:43 +0100 Subject: [PATCH 12/50] working on cleaning environment and map port function --- haskell/app/Main.hs | 75 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index f4eee09..d011e26 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -10,6 +10,8 @@ import Control.Concurrent (threadDelay) import qualified Data.ByteString.Lazy.Char8 as LBC8 +-- TODO: Change Standard Library + -- TODO: Use it import qualified Data.Text as T @@ -28,13 +30,12 @@ main = do { startServer = startServer , execInitConfig = execInitConfig , execListServers = execListServers + , execMapPort = execMapPort } ) = p2prcAPI - -- TODO: initialise environment; perhaps cleanup state files - -- - -- TODO: make it pure environment by default - _ <- execInitConfig + confOut <- execInitConfig + putStrLn confOut -- TODO: create record with all functions needed -- @@ -47,7 +48,8 @@ main = do outputStr <- execListServers print outputStr - -- Mapport - Number + mapPortOut <- execMapPort 3333 + putStrLn mapPortOut terminateProcess startProcessHandle @@ -67,26 +69,47 @@ data P2prAPI = MkP2prAPI { startServer :: IO ProcessHandle , execInitConfig :: IO String , execListServers :: IOEitherError IPAdressTable + , execMapPort :: Int -> IO String } getP2prcAPI :: IO P2prAPI getP2prcAPI = do - p2prcCmd <- getP2PrcCmd + p2prcCmd <- cleanEnvAndgetP2PrcCmd + let execProcP2PrcParser = execProcP2PrcParser_ p2prcCmd let execProcP2Prc = execProcP2Prc_ p2prcCmd + -- TODO: initialise environment; perhaps cleanup state files + -- + -- TODO: make it pure environment by default + let execInitConfig = execProcP2Prc [MkOptAtomic "--dc"] MkEmptyStdInput + -- TODO: get name of host server from config json + -- TODO: change some default config attributes + -- TODO: parse config file + + return $ MkP2prAPI - { startServer = spawnProcP2Prc p2prcCmd [MkOptAtomic "-s"] - , execInitConfig = execProcP2Prc [MkOptAtomic "-dc"] MkEmptyStdInput - , execListServers = execProcP2PrcParser [MkOptAtomic "-ls"] MkEmptyStdInput + { startServer = spawnProcP2Prc p2prcCmd [MkOptAtomic "--s"] + , execInitConfig = execInitConfig + , execListServers = execProcP2PrcParser [MkOptAtomic "--ls"] MkEmptyStdInput + , execMapPort = + \portNumber -> + execProcP2Prc + [ MkOptTuple + ( "--mp" + , show portNumber + ) + ] + MkEmptyStdInput } + newtype IPAdressTable = MkIPAdressTable [ServerInfo] deriving Show @@ -150,7 +173,7 @@ instance FromJSON ServerInfo where where - getNat :: String -> Bool -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! + getNat :: String -> Bool -- TODO: Change it to normal JSON getNat ('T':_) = True getNat _ = False @@ -244,20 +267,42 @@ assignError = MkError -- TODO: add megaparsec to parse Error Messages -getP2PrcCmd :: IO String -getP2PrcCmd = do +cleanEnvAndgetP2PrcCmd :: IO String +cleanEnvAndgetP2PrcCmd = do -- assumes the program is ran inside the haskell module in p2prc's repo readProcess "pwd" [] "" >>= - \pwdOut -> do + \pOut -> do -- need to strip the newline and return a String again - let strip = T.unpack . T.strip . T.pack + let pwdOut = T.unpack . T.strip . T.pack $ pOut + + putStrLn pOut + + -- cleanEnvironment -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" - strip <$> readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut +cleanEnvironment :: IO () +cleanEnvironment = do + + lsOut <- readProcess "ls" [] [] + putStrLn lsOut + + -- rmOut <- readProcess "rm" ["config.json"] [] -- client/ p2prc.* plugin/ server/" + -- putStrLn rmOut + + -- rmOut <- readProcess "rm" [ "config.json" , "-r", "plugin/" , "-r", "client/" ] [] + -- p2prc.* plugin/ server/" + -- putStrLn rmOut + + putStrLn "\n\ncleaning environment..." + + lsOut <- readProcess "ls" [] [] + putStrLn lsOut + sleepNSecs :: Int -> IO () sleepNSecs i = threadDelay (i * 1000000) From 7855859c3abbe53875bb237e3baf4773747e75f7 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 20 Oct 2024 21:54:14 +0100 Subject: [PATCH 13/50] fixing string issue --- haskell/app/Main.hs | 2 +- haskell/p2prc-haskell.cabal | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index d011e26..432f862 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -243,7 +243,7 @@ optsToCLI = concatMap _optToCLI _optToCLI :: CLIOpt -> CLIOptsInput _optToCLI MkEmptyOpts = [] _optToCLI (MkOptAtomic o) = [o] - _optToCLI (MkOptTuple (o, v)) = [o, show v] + _optToCLI (MkOptTuple (o, v)) = [o, v] spawnProcP2Prc :: CLICmd -> [CLIOpt] -> IO ProcessHandle diff --git a/haskell/p2prc-haskell.cabal b/haskell/p2prc-haskell.cabal index 5eb92eb..0b20e21 100644 --- a/haskell/p2prc-haskell.cabal +++ b/haskell/p2prc-haskell.cabal @@ -69,7 +69,11 @@ executable p2prc-haskell other-extensions: OverloadedStrings -- Other library packages from which modules are imported. - build-depends: base, text, aeson, process, bytestring + build-depends: base + , text + , aeson + , process + , bytestring -- Directories containing source files. hs-source-dirs: app From 7ab6471c75219ff29f32c26048e2a46ff7bcefc1 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 20 Oct 2024 22:02:08 +0100 Subject: [PATCH 14/50] fixing haskell API issue --- haskell/app/Main.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 432f862..b682144 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -196,7 +196,7 @@ data StdInput instance Show StdInput where show MkEmptyStdInput = "" - show (MkStdInputVal v) = show v + show (MkStdInputVal v) = v type IOEitherError a = IO (Either Error a) From cc08e35d82f8b355874a101fb1d2f1146298f88c Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Mon, 21 Oct 2024 01:14:13 +0100 Subject: [PATCH 15/50] finished cleaning environment functionality --- haskell/.gitignore | 4 + haskell/app/Main.hs | 175 ++++++++++++++++++++++++------------ haskell/p2prc-haskell.cabal | 1 + 3 files changed, 121 insertions(+), 59 deletions(-) diff --git a/haskell/.gitignore b/haskell/.gitignore index f64da14..14613be 100644 --- a/haskell/.gitignore +++ b/haskell/.gitignore @@ -7,3 +7,7 @@ p2prc.privateKey p2prc.PublicKeyBareMetal plugin server + + +key.pem +cert.pem diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index b682144..e02e80b 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -2,29 +2,45 @@ module Main where -import Data.Aeson -import System.Process (readProcess, terminateProcess, ProcessHandle, spawnProcess) +import System.Process + ( readProcess + , terminateProcess + , spawnProcess + , ProcessHandle + ) + +import System.Directory + ( doesDirectoryExist + , doesFileExist + , removeDirectoryRecursive + , removeFile + ) import Control.Concurrent (threadDelay) - -import qualified Data.ByteString.Lazy.Char8 as LBC8 +import Control.Monad (when) -- TODO: Change Standard Library - --- TODO: Use it import qualified Data.Text as T +import qualified Data.ByteString.Lazy.Char8 as LBC8 + +import Data.Aeson + + --- TODO: create library to abstract shell and go-level logic main :: IO () main = do + -- TODO: add IO arguments; flag to optionally cleanup environment + -- TODO: create DSL from the standard input + -- -- TODO: add GDTA syntax to data types p2prcAPI <- getP2prcAPI + let ( MkP2prAPI { startServer = startServer @@ -34,25 +50,31 @@ main = do } ) = p2prcAPI - confOut <- execInitConfig - putStrLn confOut + _ <- execInitConfig - -- TODO: create record with all functions needed - -- - -- TODO: Add loop to print servers list startProcessHandle <- startServer + -- TODO: get name of host server from config json + -- TODO: add option to change some default config attributes + -- TODO: parse config file + -- + -- TODO: abstract init and server running logic into its function + -- work on looping function sleepNSecs 5 outputStr <- execListServers print outputStr - mapPortOut <- execMapPort 3333 + mapPortOut <- execMapPort 3333 -- TODO: add domain name + -- + -- TODO: Add loop to print servers list + -- putStrLn mapPortOut terminateProcess startProcessHandle + -- Loop (Run replica of haskell program on different $NODES) -- - Start server -- - wait 4 seconds @@ -69,33 +91,35 @@ data P2prAPI = MkP2prAPI { startServer :: IO ProcessHandle , execInitConfig :: IO String , execListServers :: IOEitherError IPAdressTable - , execMapPort :: Int -> IO String + , execMapPort :: Int -> IO String -- TODO: Parse JSON data } getP2prcAPI :: IO P2prAPI getP2prcAPI = do - p2prcCmd <- cleanEnvAndgetP2PrcCmd + cleanEnvironment + p2prcCmd <- getP2PrcCmd let execProcP2PrcParser = execProcP2PrcParser_ p2prcCmd let execProcP2Prc = execProcP2Prc_ p2prcCmd - -- TODO: initialise environment; perhaps cleanup state files - -- - -- TODO: make it pure environment by default - let execInitConfig = execProcP2Prc [MkOptAtomic "--dc"] MkEmptyStdInput - -- TODO: get name of host server from config json - -- TODO: change some default config attributes - -- TODO: parse config file - return $ MkP2prAPI - { startServer = spawnProcP2Prc p2prcCmd [MkOptAtomic "--s"] - , execInitConfig = execInitConfig - , execListServers = execProcP2PrcParser [MkOptAtomic "--ls"] MkEmptyStdInput + { startServer = spawnProcP2Prc p2prcCmd [MkOptAtomic "--s"] + + , execInitConfig = + execProcP2Prc + [MkOptAtomic "--dc"] + MkEmptyStdInput + + , execListServers = + execProcP2PrcParser + [MkOptAtomic "--ls"] + MkEmptyStdInput + , execMapPort = \portNumber -> execProcP2Prc @@ -103,13 +127,16 @@ getP2prcAPI = do ( "--mp" , show portNumber ) + -- , MkOptTuple -- TODO: add domain parameter + -- ( "--dm" + -- , domainName + -- ) ] MkEmptyStdInput } - newtype IPAdressTable = MkIPAdressTable [ServerInfo] deriving Show @@ -135,9 +162,9 @@ data ServerInfo = MkServerInfo deriving Show -data IPAddress - = MkIPv4 String - | MkIPv6 String +data IPAddress -- TODO: add extra type information to data type + = MkIPv4 String -- TODO: list of numbers + | MkIPv6 String -- TODO: list of numbers deriving Show @@ -165,10 +192,10 @@ instance FromJSON ServerInfo where , download = download , upload = upload , serverPort = getPortUNSAFE serverPort - , bareMetalSSHPort = getBMShhPort bmSshPort + , bareMetalSSHPort = getBMShhPort bmSshPort -- TODO: add perhaps null placeholder?? , nat = getNat nat , escapeImplementation = mEscImpl - , customInformation = custInfo + , customInformation = custInfo -- TODO: deal with null value } where @@ -217,9 +244,13 @@ execProcP2PrcParser_ p2prcCmd opts stdInput eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack - execProcP2Prc_ :: CLICmd -> [CLIOpt] -> StdInput -> IO String execProcP2Prc_ p2prcCmd ops stdi = + -- + -- TODO: improve readProcess to return (Either Error String) + -- TODO: improve error handling at type level + -- TODO: use the "withReadProcess" + -- readProcess p2prcCmd (optsToCLI ops) @@ -233,7 +264,7 @@ data CLIOpt type CLIOptsInput = [String] -type CLICmd = String +type CLICmd = String optsToCLI :: [CLIOpt] -> CLIOptsInput @@ -248,60 +279,86 @@ optsToCLI = concatMap _optToCLI spawnProcP2Prc :: CLICmd -> [CLIOpt] -> IO ProcessHandle spawnProcP2Prc p2prcCmd = + -- + -- TODO: improve spawnProcess to return (Either Error String) + -- TODO: improve error handling at type level + -- spawnProcess p2prcCmd . optsToCLI - eitherErrorDecode :: Either String a -> Either Error a eitherErrorDecode esa = case esa of - (Left s) -> Left $ assignError s + (Left s) -> Left $ assignError s (Right v) -> Right v -data Error = MkError String +data Error = MkUnknownError String deriving Show + assignError :: String -> Error -assignError = MkError +assignError = MkUnknownError -- TODO: add megaparsec to parse Error Messages +-- +-- TODO: add error when internet connection is off -cleanEnvAndgetP2PrcCmd :: IO String -cleanEnvAndgetP2PrcCmd = do +getP2PrcCmd :: IO String +getP2PrcCmd = do -- assumes the program is ran inside the haskell module in p2prc's repo - readProcess "pwd" [] "" >>= - \pOut -> do - -- need to strip the newline and return a String again - let pwdOut = T.unpack . T.strip . T.pack $ pOut + -- TODO: change to safe type of function + pOut <- readProcess "pwd" [] "" - putStrLn pOut + -- need to strip the newline and return a String again + let pwdOut = T.unpack . T.strip . T.pack $ pOut - -- cleanEnvironment - - -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" - readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" + readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + -- TODO: change to safe type of function cleanEnvironment :: IO () cleanEnvironment = do - lsOut <- readProcess "ls" [] [] - putStrLn lsOut + mapM_ removeFileIfExists + [ "cert.pem" + , "config.json" + , "key.pem" + , "p2prc.privateKey" + , "p2prc.PublicKeyBareMetal" + ] - -- rmOut <- readProcess "rm" ["config.json"] [] -- client/ p2prc.* plugin/ server/" - -- putStrLn rmOut + mapM_ removeDirRIfExists + [ "client" + , "p2p" + , "plugin" + , "server" + ] - -- rmOut <- readProcess "rm" [ "config.json" , "-r", "plugin/" , "-r", "client/" ] [] - -- p2prc.* plugin/ server/" - -- putStrLn rmOut + where - putStrLn "\n\ncleaning environment..." + removeIfExists + :: (FilePath -> IO Bool) + -> (FilePath -> IO ()) + -> FilePath + -> IO () + removeIfExists doesItExists rmIt filePath = + do + res <- doesItExists filePath + when res $ rmIt filePath - lsOut <- readProcess "ls" [] [] - putStrLn lsOut + removeDirRIfExists = + removeIfExists + doesDirectoryExist + removeDirectoryRecursive + + removeFileIfExists = + removeIfExists + doesFileExist + removeFile sleepNSecs :: Int -> IO () diff --git a/haskell/p2prc-haskell.cabal b/haskell/p2prc-haskell.cabal index 0b20e21..baec90d 100644 --- a/haskell/p2prc-haskell.cabal +++ b/haskell/p2prc-haskell.cabal @@ -74,6 +74,7 @@ executable p2prc-haskell , aeson , process , bytestring + , directory -- Directories containing source files. hs-source-dirs: app From 46a21949df87402fe59d5ae27791a2c375990e09 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Wed, 23 Oct 2024 23:02:37 +0100 Subject: [PATCH 16/50] improving shell command execution --- haskell/app/Main.hs | 52 ++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index e02e80b..1306da4 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -3,8 +3,12 @@ module Main where +import System.Exit (ExitCode(ExitFailure)) + + import System.Process - ( readProcess + ( readProcessWithExitCode + , readProcess , terminateProcess , spawnProcess , ProcessHandle @@ -244,6 +248,16 @@ execProcP2PrcParser_ p2prcCmd opts stdInput eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack +data CLIOpt + = MkEmptyOpts + | MkOptAtomic String + | MkOptTuple (String, String) + + +type CLIOptsInput = [String] +type CLICmd = String + + execProcP2Prc_ :: CLICmd -> [CLIOpt] -> StdInput -> IO String execProcP2Prc_ p2prcCmd ops stdi = -- @@ -257,14 +271,18 @@ execProcP2Prc_ p2prcCmd ops stdi = (show stdi) -data CLIOpt - = MkEmptyOpts - | MkOptAtomic String - | MkOptTuple (String, String) +eitherExecProcess :: CLICmd -> [CLIOpt] -> StdInput -> IO (Either Error String) +eitherExecProcess cmd opts input = + do + (code, out, err) <- readProcessWithExitCode + cmd + (optsToCLI opts) + (show input) + case code of + ExitFailure i -> pure (Left (MkSystemError i err)) + _ -> pure (Right out) -type CLIOptsInput = [String] -type CLICmd = String optsToCLI :: [CLIOpt] -> CLIOptsInput @@ -293,7 +311,9 @@ eitherErrorDecode esa = (Right v) -> Right v -data Error = MkUnknownError String +data Error + = MkUnknownError String + | MkSystemError Int String deriving Show @@ -306,18 +326,16 @@ assignError = MkUnknownError getP2PrcCmd :: IO String getP2PrcCmd = do - -- assumes the program is ran inside the haskell module in p2prc's repo - - -- TODO: change to safe type of function - pOut <- readProcess "pwd" [] "" - - -- need to strip the newline and return a String again - let pwdOut = T.unpack . T.strip . T.pack $ pOut - -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" - readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + -- TODO: change to safe type of function + T.unpack . T.strip . T.pack <$> readProcess "pwd" [] "" >>= + \pwdOut -> + + -- TODO: change to safe type of function + readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + cleanEnvironment :: IO () From 8081dd8b094be3d5a8dfdcc1d90f032603a26ae2 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Wed, 23 Oct 2024 23:39:59 +0100 Subject: [PATCH 17/50] improving spawn command execution --- haskell/app/Main.hs | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 1306da4..e7c366e 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -3,13 +3,15 @@ module Main where -import System.Exit (ExitCode(ExitFailure)) +import System.Exit ( ExitCode(ExitFailure) ) import System.Process ( readProcessWithExitCode - , readProcess + , proc + , createProcess , terminateProcess + , readProcess , spawnProcess , ProcessHandle ) @@ -37,7 +39,7 @@ import Data.Aeson main :: IO () main = do - -- TODO: add IO arguments; flag to optionally cleanup environment + -- TODO: add IO arguments; -- TODO: create DSL from the standard input -- -- TODO: add GDTA syntax to data types @@ -271,6 +273,7 @@ execProcP2Prc_ p2prcCmd ops stdi = (show stdi) +-- TODO: replace this for execProcP2Prc_ eitherExecProcess :: CLICmd -> [CLIOpt] -> StdInput -> IO (Either Error String) eitherExecProcess cmd opts input = do @@ -304,6 +307,26 @@ spawnProcP2Prc p2prcCmd = spawnProcess p2prcCmd . optsToCLI +-- TODO: replace spawnProcess with this +eitherSpawnProcP2Prc :: CLICmd -> [CLIOpt] -> IO (Either Error ProcessHandle) +eitherSpawnProcP2Prc cmd opts = + do + + let prc = proc cmd (optsToCLI opts) + + creationResult <- createProcess prc + + let (_, _, _, ph) = creationResult + + case creationResult of + (_, _, Just _, _) -> do + terminateProcess ph + pure $ Left $ MkErrorSpawningProcess $ "Error executing: " ++ cmd + + _ -> pure $ Right ph + + + eitherErrorDecode :: Either String a -> Either Error a eitherErrorDecode esa = case esa of @@ -313,6 +336,7 @@ eitherErrorDecode esa = data Error = MkUnknownError String + | MkErrorSpawningProcess String | MkSystemError Int String deriving Show @@ -329,11 +353,11 @@ getP2PrcCmd = do -- assumes the program is ran inside the haskell module in p2prc's repo -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" - -- TODO: change to safe type of function + -- TODO: change to "eitherExecProcess" T.unpack . T.strip . T.pack <$> readProcess "pwd" [] "" >>= \pwdOut -> - -- TODO: change to safe type of function + -- TODO: change to "eitherExecProcess" readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut From 2a111bd22db7f4d52da1e0b030e1db09ef9ceb18 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Wed, 23 Oct 2024 23:43:23 +0100 Subject: [PATCH 18/50] improving safety commands --- haskell/app/Main.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index e7c366e..a36ee25 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -283,8 +283,8 @@ eitherExecProcess cmd opts input = (show input) case code of - ExitFailure i -> pure (Left (MkSystemError i err)) - _ -> pure (Right out) + ExitFailure i -> pure $ Left $ MkSystemError i err + _ -> pure $ Right out @@ -319,6 +319,7 @@ eitherSpawnProcP2Prc cmd opts = let (_, _, _, ph) = creationResult case creationResult of + (_, _, Just _, _) -> do terminateProcess ph pure $ Left $ MkErrorSpawningProcess $ "Error executing: " ++ cmd From 98988454da62d63efd525e67252bbba5be93a721 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Thu, 24 Oct 2024 21:44:48 +0100 Subject: [PATCH 19/50] fixing readProcess and spawnProcess --- haskell/app/Main.hs | 113 +++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 60 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index a36ee25..0389b10 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -12,7 +12,6 @@ import System.Process , createProcess , terminateProcess , readProcess - , spawnProcess , ProcessHandle ) @@ -59,7 +58,8 @@ main = do _ <- execInitConfig - startProcessHandle <- startServer + eitherStartProcessHandle <- startServer + -- -- TODO: get name of host server from config json -- TODO: add option to change some default config attributes -- TODO: parse config file @@ -67,18 +67,27 @@ main = do -- TODO: abstract init and server running logic into its function -- work on looping function - sleepNSecs 5 + case eitherStartProcessHandle of + (Right startProcessHandle) -> do - outputStr <- execListServers - print outputStr + sleepNSecs 5 - mapPortOut <- execMapPort 3333 -- TODO: add domain name - -- - -- TODO: Add loop to print servers list - -- - putStrLn mapPortOut + outputStr <- execListServers + print outputStr + + mapPortOut <- execMapPort 3333 -- TODO: add domain name + -- + -- TODO: Add loop to print servers list + -- + + case mapPortOut of + (Right v) -> putStrLn v + (Left e) -> print e + + terminateProcess startProcessHandle + + (Left err) -> print err - terminateProcess startProcessHandle -- Loop (Run replica of haskell program on different $NODES) @@ -94,10 +103,10 @@ main = do data P2prAPI = MkP2prAPI - { startServer :: IO ProcessHandle - , execInitConfig :: IO String + { startServer :: IOEitherError ProcessHandle + , execInitConfig :: IOEitherError String , execListServers :: IOEitherError IPAdressTable - , execMapPort :: Int -> IO String -- TODO: Parse JSON data + , execMapPort :: Int -> IOEitherError String -- TODO: Parse JSON data } @@ -109,7 +118,7 @@ getP2prcAPI = do p2prcCmd <- getP2PrcCmd let execProcP2PrcParser = execProcP2PrcParser_ p2prcCmd - let execProcP2Prc = execProcP2Prc_ p2prcCmd + let execProcP2Prc = eitherExecProcess p2prcCmd return $ @@ -142,7 +151,6 @@ getP2prcAPI = do } - newtype IPAdressTable = MkIPAdressTable [ServerInfo] deriving Show @@ -237,10 +245,14 @@ type IOEitherError a = IO (Either Error a) execProcP2PrcParser_ :: FromJSON a => CLICmd -> [CLIOpt] -> StdInput -> IOEitherError a -execProcP2PrcParser_ p2prcCmd opts stdInput - = - eitherErrDecode - <$> execProcP2Prc_ p2prcCmd opts stdInput +execProcP2PrcParser_ p2prcCmd opts stdInput = + do + val <- eitherExecProcess p2prcCmd opts stdInput + + pure $ case val of + (Right v) -> eitherErrDecode v + (Left e) -> Left e + where @@ -260,31 +272,19 @@ type CLIOptsInput = [String] type CLICmd = String -execProcP2Prc_ :: CLICmd -> [CLIOpt] -> StdInput -> IO String -execProcP2Prc_ p2prcCmd ops stdi = - -- - -- TODO: improve readProcess to return (Either Error String) - -- TODO: improve error handling at type level - -- TODO: use the "withReadProcess" - -- - readProcess - p2prcCmd - (optsToCLI ops) - (show stdi) - - --- TODO: replace this for execProcP2Prc_ -eitherExecProcess :: CLICmd -> [CLIOpt] -> StdInput -> IO (Either Error String) +eitherExecProcess :: CLICmd -> [CLIOpt] -> StdInput -> IOEitherError String eitherExecProcess cmd opts input = do - (code, out, err) <- readProcessWithExitCode + (code, out, err) <- + readProcessWithExitCode cmd (optsToCLI opts) (show input) - case code of - ExitFailure i -> pure $ Left $ MkSystemError i err - _ -> pure $ Right out + pure $ + case code of + ExitFailure i -> Left $ MkSystemError i err + _ -> Right out @@ -298,34 +298,23 @@ optsToCLI = concatMap _optToCLI _optToCLI (MkOptTuple (o, v)) = [o, v] -spawnProcP2Prc :: CLICmd -> [CLIOpt] -> IO ProcessHandle -spawnProcP2Prc p2prcCmd = - -- - -- TODO: improve spawnProcess to return (Either Error String) - -- TODO: improve error handling at type level - -- - spawnProcess p2prcCmd . optsToCLI - - --- TODO: replace spawnProcess with this -eitherSpawnProcP2Prc :: CLICmd -> [CLIOpt] -> IO (Either Error ProcessHandle) -eitherSpawnProcP2Prc cmd opts = +spawnProcP2Prc :: CLICmd -> [CLIOpt] -> IOEitherError ProcessHandle +spawnProcP2Prc cmd opts = do - - let prc = proc cmd (optsToCLI opts) + let prc = proc cmd $ optsToCLI opts creationResult <- createProcess prc let (_, _, _, ph) = creationResult case creationResult of + (_, _, Just _, _) -> + do + terminateProcess ph + pure $ Left + $ MkErrorSpawningProcess $ "Error executing: " ++ cmd - (_, _, Just _, _) -> do - terminateProcess ph - pure $ Left $ MkErrorSpawningProcess $ "Error executing: " ++ cmd - - _ -> pure $ Right ph - + _-> pure $ Right ph eitherErrorDecode :: Either String a -> Either Error a @@ -351,11 +340,15 @@ assignError = MkUnknownError getP2PrcCmd :: IO String getP2PrcCmd = do + -- assumes the program is ran inside the haskell module in p2prc's repo -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" + let trimString = T.unpack . T.strip . T.pack + -- TODO: change to "eitherExecProcess" - T.unpack . T.strip . T.pack <$> readProcess "pwd" [] "" >>= + + trimString <$> readProcess "pwd" [] "" >>= \pwdOut -> -- TODO: change to "eitherExecProcess" From 410d2ae1119b9a9f698e61acfd404a59790e785c Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Thu, 24 Oct 2024 23:59:35 +0100 Subject: [PATCH 20/50] implemented safer version of code for shell calls --- haskell/app/Main.hs | 174 ++++++++++++++++++++++++-------------------- 1 file changed, 94 insertions(+), 80 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 0389b10..0e2f4bc 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -11,7 +11,6 @@ import System.Process , proc , createProcess , terminateProcess - , readProcess , ProcessHandle ) @@ -38,53 +37,61 @@ import Data.Aeson main :: IO () main = do + -- TODO: add IO arguments; -- TODO: create DSL from the standard input -- -- TODO: add GDTA syntax to data types - - p2prcAPI <- getP2prcAPI - - - let - ( MkP2prAPI - { startServer = startServer - , execInitConfig = execInitConfig - , execListServers = execListServers - , execMapPort = execMapPort - } - ) = p2prcAPI - - _ <- execInitConfig - - - eitherStartProcessHandle <- startServer -- - -- TODO: get name of host server from config json - -- TODO: add option to change some default config attributes - -- TODO: parse config file - -- - -- TODO: abstract init and server running logic into its function - -- work on looping function + -- TODO: need monad transformers to refactor the code - case eitherStartProcessHandle of - (Right startProcessHandle) -> do - sleepNSecs 5 + eitherP2prcAPI <- getP2prcAPI - outputStr <- execListServers - print outputStr + case eitherP2prcAPI of + (Right p2prcAPI) -> do - mapPortOut <- execMapPort 3333 -- TODO: add domain name + let + ( MkP2prAPI + { startServer = startServer + , execInitConfig = execInitConfig + , execListServers = execListServers + , execMapPort = execMapPort + } + ) = p2prcAPI + + _ <- execInitConfig + + + eitherStartProcessHandle <- startServer -- - -- TODO: Add loop to print servers list + -- TODO: get name of host server from config json + -- TODO: add option to change some default config attributes + -- TODO: parse config file -- + -- TODO: abstract init and server running logic into its function + -- work on looping function - case mapPortOut of - (Right v) -> putStrLn v - (Left e) -> print e + case eitherStartProcessHandle of + (Right startProcessHandle) -> do - terminateProcess startProcessHandle + sleepNSecs 5 + + outputStr <- execListServers + print outputStr + + mapPortOut <- execMapPort 3333 -- TODO: add domain name + -- + -- TODO: Add loop to print servers list + -- + + case mapPortOut of + (Right v) -> putStrLn v + (Left e) -> print e + + terminateProcess startProcessHandle + + (Left err) -> print err (Left err) -> print err @@ -110,45 +117,49 @@ data P2prAPI = MkP2prAPI } -getP2prcAPI :: IO P2prAPI +getP2prcAPI :: IOEitherError P2prAPI getP2prcAPI = do cleanEnvironment - p2prcCmd <- getP2PrcCmd + eitherP2prcCmd <- getP2PrcCmd - let execProcP2PrcParser = execProcP2PrcParser_ p2prcCmd - let execProcP2Prc = eitherExecProcess p2prcCmd + pure $ case eitherP2prcCmd of + (Right p2prcCmd) -> do + + let execProcP2PrcParser = execProcP2PrcParser_ p2prcCmd + let execProcP2Prc = eitherExecProcess p2prcCmd - return $ - MkP2prAPI - { startServer = spawnProcP2Prc p2prcCmd [MkOptAtomic "--s"] + Right $ MkP2prAPI + { startServer = spawnProcP2Prc p2prcCmd [MkOptAtomic "--s"] - , execInitConfig = - execProcP2Prc - [MkOptAtomic "--dc"] - MkEmptyStdInput - - , execListServers = - execProcP2PrcParser - [MkOptAtomic "--ls"] - MkEmptyStdInput - - , execMapPort = - \portNumber -> + , execInitConfig = execProcP2Prc - [ MkOptTuple - ( "--mp" - , show portNumber - ) - -- , MkOptTuple -- TODO: add domain parameter - -- ( "--dm" - -- , domainName - -- ) - ] + [MkOptAtomic "--dc"] MkEmptyStdInput - } + + , execListServers = + execProcP2PrcParser + [MkOptAtomic "--ls"] + MkEmptyStdInput + + , execMapPort = + \portNumber -> + execProcP2Prc + [ MkOptTuple + ( "--mp" + , show portNumber + ) + -- , MkOptTuple -- TODO: add domain parameter + -- ( "--dm" + -- , domainName + -- ) + ] + MkEmptyStdInput + } + + (Left err) -> Left err newtype IPAdressTable @@ -281,10 +292,9 @@ eitherExecProcess cmd opts input = (optsToCLI opts) (show input) - pure $ - case code of - ExitFailure i -> Left $ MkSystemError i err - _ -> Right out + pure $ case code of + ExitFailure i -> Left $ MkSystemError i cmd err + _ -> Right out @@ -308,11 +318,11 @@ spawnProcP2Prc cmd opts = let (_, _, _, ph) = creationResult case creationResult of - (_, _, Just _, _) -> - do - terminateProcess ph - pure $ Left - $ MkErrorSpawningProcess $ "Error executing: " ++ cmd + (_, _, Just _, _) -> do + + terminateProcess ph + + pure $ Left $ MkErrorSpawningProcess cmd _-> pure $ Right ph @@ -327,7 +337,7 @@ eitherErrorDecode esa = data Error = MkUnknownError String | MkErrorSpawningProcess String - | MkSystemError Int String + | MkSystemError Int String String deriving Show @@ -338,7 +348,7 @@ assignError = MkUnknownError -- TODO: add error when internet connection is off -getP2PrcCmd :: IO String +getP2PrcCmd :: IOEitherError String getP2PrcCmd = do -- assumes the program is ran inside the haskell module in p2prc's repo @@ -346,14 +356,18 @@ getP2PrcCmd = do let trimString = T.unpack . T.strip . T.pack - -- TODO: change to "eitherExecProcess" + eitherErrPwd <- eitherExecProcess "pwd" [MkEmptyOpts] MkEmptyStdInput - trimString <$> readProcess "pwd" [] "" >>= - \pwdOut -> + case eitherErrPwd of - -- TODO: change to "eitherExecProcess" - readProcess "sed" ["s/haskell/p2p-rendering-computation/"] pwdOut + (Right pwdOut) -> + eitherExecProcess + "sed" + [MkOptAtomic "s/haskell/p2p-rendering-computation/"] + $ MkStdInputVal + $ trimString pwdOut + err -> pure err cleanEnvironment :: IO () From b3ba2c906ea31515c18bad7ab3c520829aabe6ee Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 26 Oct 2024 19:24:16 +0100 Subject: [PATCH 21/50] parsing config file started --- haskell/app/Main.hs | 65 ++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 0e2f4bc..a06cc9a 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -5,6 +5,7 @@ module Main where import System.Exit ( ExitCode(ExitFailure) ) +import System.IO import System.Process ( readProcessWithExitCode @@ -22,7 +23,7 @@ import System.Directory ) import Control.Concurrent (threadDelay) -import Control.Monad (when) +import Control.Monad (when, mzero) -- TODO: Change Standard Library @@ -60,11 +61,14 @@ main = do } ) = p2prcAPI - _ <- execInitConfig + configValue <- execInitConfig + + print configValue + putStrLn "\n\n\n" eitherStartProcessHandle <- startServer - -- + -- TODO: get name of host server from config json -- TODO: add option to change some default config attributes -- TODO: parse config file @@ -111,7 +115,7 @@ main = do data P2prAPI = MkP2prAPI { startServer :: IOEitherError ProcessHandle - , execInitConfig :: IOEitherError String + , execInitConfig :: IOEitherError P2prcConfig -- TODO: add parameters that can be modified , execListServers :: IOEitherError IPAdressTable , execMapPort :: Int -> IOEitherError String -- TODO: Parse JSON data } @@ -134,11 +138,6 @@ getP2prcAPI = do Right $ MkP2prAPI { startServer = spawnProcP2Prc p2prcCmd [MkOptAtomic "--s"] - , execInitConfig = - execProcP2Prc - [MkOptAtomic "--dc"] - MkEmptyStdInput - , execListServers = execProcP2PrcParser [MkOptAtomic "--ls"] @@ -157,11 +156,43 @@ getP2prcAPI = do -- ) ] MkEmptyStdInput + + , execInitConfig = do + + confInitRes <- execProcP2Prc + [MkOptAtomic "--dc"] + MkEmptyStdInput + + case confInitRes of + (Right _) -> do + + -- TODO: get config file name dynamically + let fname = "/home/xecarlox/Desktop/p2p-rendering-computation/haskell/config.json" :: FilePath + + -- TODO: change values before loading file + + configContent <- readFile fname + + pure $ eitherErrDecode configContent + + (Left err) -> pure $ Left err } (Left err) -> Left err +data P2prcConfig = MkP2prConfig + { machineName :: String + } + deriving Show + +instance FromJSON P2prcConfig where + -- TODO: parse values into the proper data types + parseJSON (Object o) = MkP2prConfig + <$> o .: "MachineName" + + parseJSON _ = mzero + newtype IPAdressTable = MkIPAdressTable [ServerInfo] deriving Show @@ -187,9 +218,9 @@ data ServerInfo = MkServerInfo deriving Show -data IPAddress -- TODO: add extra type information to data type - = MkIPv4 String -- TODO: list of numbers - | MkIPv6 String -- TODO: list of numbers +data IPAddress + = MkIPv4 String + | MkIPv6 String deriving Show @@ -265,12 +296,10 @@ execProcP2PrcParser_ p2prcCmd opts stdInput = (Left e) -> Left e - where - - eitherErrDecode :: - FromJSON a => - String -> Either Error a - eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack +eitherErrDecode :: + FromJSON a => + String -> Either Error a +eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack data CLIOpt From 1bbf06685c43382109ff4efcfefb370cf30c9045 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 26 Oct 2024 22:36:06 +0100 Subject: [PATCH 22/50] fixing parsing of json --- haskell/app/Main.hs | 97 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 23 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index a06cc9a..55684ed 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -2,7 +2,6 @@ module Main where - import System.Exit ( ExitCode(ExitFailure) ) import System.IO @@ -23,7 +22,11 @@ import System.Directory ) import Control.Concurrent (threadDelay) -import Control.Monad (when, mzero) + +import Control.Monad + ( when + , mzero + ) -- TODO: Change Standard Library @@ -85,12 +88,13 @@ main = do print outputStr mapPortOut <- execMapPort 3333 -- TODO: add domain name + -- -- TODO: Add loop to print servers list -- case mapPortOut of - (Right v) -> putStrLn v + (Right v) -> putStrLn $ show v (Left e) -> print e terminateProcess startProcessHandle @@ -117,7 +121,7 @@ data P2prAPI = MkP2prAPI { startServer :: IOEitherError ProcessHandle , execInitConfig :: IOEitherError P2prcConfig -- TODO: add parameters that can be modified , execListServers :: IOEitherError IPAdressTable - , execMapPort :: Int -> IOEitherError String -- TODO: Parse JSON data + , execMapPort :: Int -> IOEitherError MapPortResponse } @@ -131,37 +135,34 @@ getP2prcAPI = do pure $ case eitherP2prcCmd of (Right p2prcCmd) -> do - let execProcP2PrcParser = execProcP2PrcParser_ p2prcCmd + let execProcP2PrcParser = eitherExecProcessParser p2prcCmd let execProcP2Prc = eitherExecProcess p2prcCmd Right $ MkP2prAPI - { startServer = spawnProcP2Prc p2prcCmd [MkOptAtomic "--s"] + { startServer = spawnProcP2Prc p2prcCmd [ MkOptAtomic "--s" ] , execListServers = - execProcP2PrcParser - [MkOptAtomic "--ls"] - MkEmptyStdInput + execProcP2PrcParser [ MkOptAtomic "--ls" ] MkEmptyStdInput , execMapPort = - \portNumber -> - execProcP2Prc + \ portNumber -> + execProcP2PrcParser [ MkOptTuple ( "--mp" , show portNumber ) + ] + MkEmptyStdInput + -- , MkOptTuple -- TODO: add domain parameter -- ( "--dm" -- , domainName -- ) - ] - MkEmptyStdInput , execInitConfig = do - confInitRes <- execProcP2Prc - [MkOptAtomic "--dc"] - MkEmptyStdInput + confInitRes <- execProcP2Prc [ MkOptAtomic "--dc" ] MkEmptyStdInput case confInitRes of (Right _) -> do @@ -171,6 +172,7 @@ getP2prcAPI = do -- TODO: change values before loading file + -- TODO: read config check if file exists configContent <- readFile fname pure $ eitherErrDecode configContent @@ -181,18 +183,67 @@ getP2prcAPI = do (Left err) -> Left err +data MapPortResponse + = MkMapPortResponse + { ipAddress :: String + -- , ipAddress :: IPAddress -- TODO: fix the api output + -- , port :: Int -- TODO: fix the api output + } + deriving Show + + +instance FromJSON MapPortResponse where + parseJSON (Object o) = do + + ipAddress <- o .: "IPAddress" + + pure $ + MkMapPortResponse + { ipAddress=ipAddress + } + + parseJSON _ = mzero + + data P2prcConfig = MkP2prConfig - { machineName :: String + { machineName :: String + -- , iPTable :: File + -- , dockerContainers :: Directory + -- , defaultDockerFile :: Directory + -- , dockerRunLogs :: Directory + -- , speedTestFile :: File + -- , iPV6Address :: Maybe String + -- , pluginPath :: Directory + -- , trackContainersPath :: File + -- , hostServerPort :: Int + -- , proxyPort :: Maybe Int + -- , groupTrackContainersPath :: File + -- , fRPServerPort :: Bool -- TODO: fix string to boolean + -- , behindNAT :: Bool -- TODO: fix string to boolean + -- , iPTableKey :: String + -- , publicKeyFile :: File + -- , privateKeyFile :: File + -- , pemFile :: File + -- , keyFile :: File + -- , bareMetal :: Bool -- TODO: fix string to boolean + -- , customConfig -- TODO: fix this field } deriving Show + instance FromJSON P2prcConfig where - -- TODO: parse values into the proper data types - parseJSON (Object o) = MkP2prConfig - <$> o .: "MachineName" + parseJSON (Object o) = do + + machineName <- o .: "MachineName" + + pure + $ MkP2prConfig + { machineName=machineName + } parseJSON _ = mzero + newtype IPAdressTable = MkIPAdressTable [ServerInfo] deriving Show @@ -284,10 +335,10 @@ instance Show StdInput where type IOEitherError a = IO (Either Error a) -execProcP2PrcParser_ :: +eitherExecProcessParser :: FromJSON a => CLICmd -> [CLIOpt] -> StdInput -> IOEitherError a -execProcP2PrcParser_ p2prcCmd opts stdInput = +eitherExecProcessParser p2prcCmd opts stdInput = do val <- eitherExecProcess p2prcCmd opts stdInput @@ -392,7 +443,7 @@ getP2PrcCmd = do (Right pwdOut) -> eitherExecProcess "sed" - [MkOptAtomic "s/haskell/p2p-rendering-computation/"] + [ MkOptAtomic "s/haskell/p2p-rendering-computation/" ] $ MkStdInputVal $ trimString pwdOut From 6bb45f40fe7928ed9c7e3a57bf96034acfaab5d6 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 26 Oct 2024 23:09:51 +0100 Subject: [PATCH 23/50] improved p2prc API --- haskell/app/Main.hs | 125 ++++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 52 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index 55684ed..a74024e 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -2,9 +2,9 @@ module Main where -import System.Exit ( ExitCode(ExitFailure) ) - -import System.IO +import System.Exit + ( ExitCode(ExitFailure) + ) import System.Process ( readProcessWithExitCode @@ -28,8 +28,6 @@ import Control.Monad , mzero ) --- TODO: Change Standard Library - import qualified Data.Text as T import qualified Data.ByteString.Lazy.Char8 as LBC8 @@ -37,6 +35,10 @@ import qualified Data.ByteString.Lazy.Char8 as LBC8 import Data.Aeson +-- import System.IO +-- +-- TODO: Change Standard Library + main :: IO () main = do @@ -61,23 +63,23 @@ main = do , execInitConfig = execInitConfig , execListServers = execListServers , execMapPort = execMapPort - } - ) = p2prcAPI + }) = p2prcAPI - configValue <- execInitConfig + configValue <- execInitConfig $ MkConfigParams "dummy" print configValue putStrLn "\n\n\n" eitherStartProcessHandle <- startServer + -- TODO: get name of host server from config json -- TODO: add option to change some default config attributes -- TODO: parse config file -- - -- TODO: abstract init and server running logic into its function - -- work on looping function + -- TODO: work on looping function + case eitherStartProcessHandle of (Right startProcessHandle) -> do @@ -87,15 +89,26 @@ main = do outputStr <- execListServers print outputStr - mapPortOut <- execMapPort 3333 -- TODO: add domain name + mapPortOut <- execMapPort $ MkMapPortRequest 3333 "domain" + + case mapPortOut of + (Right v) -> print v + (Left e) -> print e -- -- TODO: Add loop to print servers list -- + -- + -- Loop (Run replica of haskell program on different $NODES) + -- - Start server + -- - wait 4 seconds + -- - Identify new node running p2prc with SSH external port exposed + -- - SSH into machine + -- - Use simple File transfer to setup files + -- - Run server + -- - Use remote machine p2prc cmd to map a port using --mp + -- - Return back the exposed public IP and port number back to stdout - case mapPortOut of - (Right v) -> putStrLn $ show v - (Left e) -> print e terminateProcess startProcessHandle @@ -105,26 +118,24 @@ main = do - -- Loop (Run replica of haskell program on different $NODES) - -- - Start server - -- - wait 4 seconds - -- - Identify new node running p2prc with SSH external port exposed - -- - SSH into machine - -- - Use simple File transfer to setup files - -- - Run server - -- - Use remote machine p2prc cmd to map a port using --mp - -- - Return back the exposed public IP and port number back to stdout - - - data P2prAPI = MkP2prAPI { startServer :: IOEitherError ProcessHandle - , execInitConfig :: IOEitherError P2prcConfig -- TODO: add parameters that can be modified + , execInitConfig :: ConfigParams -> IOEitherError P2prcConfig , execListServers :: IOEitherError IPAdressTable - , execMapPort :: Int -> IOEitherError MapPortResponse + , execMapPort :: MapPortRequest -> IOEitherError MapPortResponse } +data ConfigParams = MkConfigParams String + + +type DomainName = String +type PortNumber = Int + +data MapPortRequest + = MkMapPortRequest PortNumber DomainName + + getP2prcAPI :: IOEitherError P2prAPI getP2prcAPI = do @@ -133,11 +144,17 @@ getP2prcAPI = do eitherP2prcCmd <- getP2PrcCmd pure $ case eitherP2prcCmd of - (Right p2prcCmd) -> do + (Right p2prcCmd) -> let - let execProcP2PrcParser = eitherExecProcessParser p2prcCmd - let execProcP2Prc = eitherExecProcess p2prcCmd + execProcP2PrcParser :: + FromJSON a => + [CLIOpt] -> StdInput -> IOEitherError a + execProcP2PrcParser = eitherExecProcessParser p2prcCmd + -- TODO: GHC question, why does it scope down instead staying generic + execProcP2Prc = eitherExecProcess p2prcCmd + + in do Right $ MkP2prAPI { startServer = spawnProcP2Prc p2prcCmd [ MkOptAtomic "--s" ] @@ -146,38 +163,39 @@ getP2prcAPI = do execProcP2PrcParser [ MkOptAtomic "--ls" ] MkEmptyStdInput , execMapPort = - \ portNumber -> + \ (MkMapPortRequest portNumber _) -> execProcP2PrcParser [ MkOptTuple ( "--mp" , show portNumber ) - ] - MkEmptyStdInput - -- , MkOptTuple -- TODO: add domain parameter -- ( "--dm" -- , domainName -- ) + ] + MkEmptyStdInput - , execInitConfig = do + , execInitConfig = + \ (MkConfigParams _) -> do - confInitRes <- execProcP2Prc [ MkOptAtomic "--dc" ] MkEmptyStdInput + confInitRes <- execProcP2Prc [ MkOptAtomic "--dc" ] MkEmptyStdInput - case confInitRes of - (Right _) -> do + case confInitRes of + (Right _) -> do - -- TODO: get config file name dynamically - let fname = "/home/xecarlox/Desktop/p2p-rendering-computation/haskell/config.json" :: FilePath + -- TODO: get config file name dynamically + let fname = "/home/xecarlox/Desktop/p2p-rendering-computation/haskell/config.json" :: FilePath - -- TODO: change values before loading file + -- TODO: change values before loading file - -- TODO: read config check if file exists - configContent <- readFile fname + -- TODO: read config check if file exists + configContent <- readFile fname - pure $ eitherErrDecode configContent + pure $ eitherErrDecode configContent + + (Left err) -> pure $ Left err - (Left err) -> pure $ Left err } (Left err) -> Left err @@ -248,6 +266,7 @@ newtype IPAdressTable = MkIPAdressTable [ServerInfo] deriving Show + instance FromJSON IPAdressTable where parseJSON = withObject "IPAdressTable" $ \v -> @@ -260,8 +279,8 @@ data ServerInfo = MkServerInfo , latency :: Int , download :: Int , upload :: Int - , serverPort :: Int - , bareMetalSSHPort :: Maybe Int + , serverPort :: PortNumber + , bareMetalSSHPort :: Maybe PortNumber , nat :: Bool , escapeImplementation :: Maybe T.Text , customInformation :: Maybe T.Text @@ -311,11 +330,11 @@ instance FromJSON ServerInfo where getNat ('T':_) = True getNat _ = False - getBMShhPort :: String -> Maybe Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! + getBMShhPort :: String -> Maybe PortNumber -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! getBMShhPort [] = Nothing getBMShhPort bmSshPort = Just $ getPortUNSAFE bmSshPort - getPortUNSAFE :: String -> Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! + getPortUNSAFE :: String -> PortNumber -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! getPortUNSAFE = read getIPAddress :: String -> String -> IPAddress @@ -323,11 +342,11 @@ instance FromJSON ServerInfo where getIPAddress ip4 _ = MkIPv4 ip4 - data StdInput = MkEmptyStdInput | MkStdInputVal String + instance Show StdInput where show MkEmptyStdInput = "" show (MkStdInputVal v) = v @@ -335,6 +354,7 @@ instance Show StdInput where type IOEitherError a = IO (Either Error a) + eitherExecProcessParser :: FromJSON a => CLICmd -> [CLIOpt] -> StdInput -> IOEitherError a @@ -377,7 +397,6 @@ eitherExecProcess cmd opts input = _ -> Right out - optsToCLI :: [CLIOpt] -> CLIOptsInput optsToCLI = concatMap _optToCLI where @@ -423,9 +442,11 @@ data Error assignError :: String -> Error assignError = MkUnknownError +-- -- TODO: add megaparsec to parse Error Messages -- -- TODO: add error when internet connection is off +-- getP2PrcCmd :: IOEitherError String From 36a00f99b0cf2e00b571aae7d68fee556ce17f11 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Tue, 5 Nov 2024 22:38:28 +0000 Subject: [PATCH 24/50] adding planning for next stage; adding github issues --- haskell/app/Main.hs | 165 ++++++++++++++++++++++++++++---------------- 1 file changed, 104 insertions(+), 61 deletions(-) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index a74024e..c5e9798 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -34,22 +34,46 @@ import qualified Data.ByteString.Lazy.Char8 as LBC8 import Data.Aeson - -- import System.IO + + +-- URGENT TASKS -- --- TODO: Change Standard Library +-- TODO: setup the project as a haskell library +-- TODO: splitting code on different files and directories +-- TODO: lock cabal index +-- TODO: setup nix flake package +-- +-- TODO: P2PRC setup + -- p2prc runtime packaging + -- Perhaps create internal script to run P2PRC from nix flake + -- "nix flake run ..." + -- simplify packaging + -- check version P2PRC: only run if version if above a certain value + -- setup p2prc command + -- check if p2prc command is available in environment first + -- otherwise check folder above +-- +-- TODO: add Haddock documentation +-- +-- TODO: add quickcheck testing (quickchecking-dynamic) +-- +-- TODO: publish haskell library main :: IO () main = do - -- TODO: add IO arguments; - -- TODO: create DSL from the standard input + -- important but not urgent yet -- + -- TODO: Change Standard Library -- TODO: add GDTA syntax to data types - -- -- TODO: need monad transformers to refactor the code + -- + -- TODO: parse IO arguments; + -- TODO: create DSL from the standard input + -- eitherP2prcAPI <- getP2prcAPI @@ -63,10 +87,13 @@ main = do , execInitConfig = execInitConfig , execListServers = execListServers , execMapPort = execMapPort - }) = p2prcAPI + } + ) = p2prcAPI - configValue <- execInitConfig $ MkConfigParams "dummy" + configValue <- execInitConfig + + -- TODO: get name of host server from config json print configValue putStrLn "\n\n\n" @@ -74,13 +101,6 @@ main = do eitherStartProcessHandle <- startServer - -- TODO: get name of host server from config json - -- TODO: add option to change some default config attributes - -- TODO: parse config file - -- - -- TODO: work on looping function - - case eitherStartProcessHandle of (Right startProcessHandle) -> do @@ -95,9 +115,9 @@ main = do case mapPortOut of (Right v) -> print v (Left e) -> print e - -- - -- TODO: Add loop to print servers list - -- + + + -- TODO: work on looping function -- -- Loop (Run replica of haskell program on different $NODES) -- - Start server @@ -120,20 +140,14 @@ main = do data P2prAPI = MkP2prAPI { startServer :: IOEitherError ProcessHandle - , execInitConfig :: ConfigParams -> IOEitherError P2prcConfig + , execInitConfig :: IOEitherError P2prcConfig , execListServers :: IOEitherError IPAdressTable , execMapPort :: MapPortRequest -> IOEitherError MapPortResponse } -data ConfigParams = MkConfigParams String - - -type DomainName = String -type PortNumber = Int - data MapPortRequest - = MkMapPortRequest PortNumber DomainName + = MkMapPortRequest Int String getP2prcAPI :: IOEitherError P2prAPI @@ -160,7 +174,7 @@ getP2prcAPI = do { startServer = spawnProcP2Prc p2prcCmd [ MkOptAtomic "--s" ] , execListServers = - execProcP2PrcParser [ MkOptAtomic "--ls" ] MkEmptyStdInput + execProcP2PrcParser [ MkOptAtomic "--ls" ] MkEmptyStdInput , execMapPort = \ (MkMapPortRequest portNumber _) -> @@ -176,25 +190,25 @@ getP2prcAPI = do ] MkEmptyStdInput - , execInitConfig = - \ (MkConfigParams _) -> do + , execInitConfig = do - confInitRes <- execProcP2Prc [ MkOptAtomic "--dc" ] MkEmptyStdInput + confInitRes <- execProcP2Prc [ MkOptAtomic "--dc" ] MkEmptyStdInput - case confInitRes of - (Right _) -> do + case confInitRes of + (Right _) -> do - -- TODO: get config file name dynamically - let fname = "/home/xecarlox/Desktop/p2p-rendering-computation/haskell/config.json" :: FilePath + -- TODO: get config file name dynamically - -- TODO: change values before loading file + -- TODO: change values before loading file + let fname = "/home/xecarlox/Desktop/p2p-rendering-computation/haskell/config.json" :: FilePath - -- TODO: read config check if file exists - configContent <- readFile fname - pure $ eitherErrDecode configContent + -- TODO: read config check if file exists + configContent <- readFile fname - (Left err) -> pure $ Left err + pure $ eitherErrDecode configContent + + (Left err) -> pure $ Left err } @@ -210,6 +224,7 @@ data MapPortResponse deriving Show + instance FromJSON MapPortResponse where parseJSON (Object o) = do @@ -223,32 +238,60 @@ instance FromJSON MapPortResponse where parseJSON _ = mzero + data P2prcConfig = MkP2prConfig { machineName :: String - -- , iPTable :: File - -- , dockerContainers :: Directory - -- , defaultDockerFile :: Directory - -- , dockerRunLogs :: Directory - -- , speedTestFile :: File + -- , iPTable :: String -- File + -- , dockerContainers :: String -- Directory + -- , defaultDockerFile :: String -- Directory + -- , dockerRunLogs :: String -- Directory + -- , speedTestFile :: String -- File -- , iPV6Address :: Maybe String - -- , pluginPath :: Directory - -- , trackContainersPath :: File + -- , pluginPath :: String -- Directory + -- , trackContainersPath :: String -- File -- , hostServerPort :: Int -- , proxyPort :: Maybe Int -- , groupTrackContainersPath :: File - -- , fRPServerPort :: Bool -- TODO: fix string to boolean - -- , behindNAT :: Bool -- TODO: fix string to boolean + -- , fRPServerPort :: Bool + -- , behindNAT :: Bool -- , iPTableKey :: String - -- , publicKeyFile :: File - -- , privateKeyFile :: File - -- , pemFile :: File - -- , keyFile :: File - -- , bareMetal :: Bool -- TODO: fix string to boolean - -- , customConfig -- TODO: fix this field + -- , publicKeyFile :: String -- File + -- , privateKeyFile :: String -- File + -- , pemFile :: String -- File + -- , keyFile :: String -- File + -- , bareMetal :: Bool + -- , customConfig } deriving Show +-- TODO: p2prc API + -- + -- ListServers + -- remove "ip_address" root field if not needed + -- "Nat field" returning a JSON Boolean + -- serverPort as a JSON number + -- baremetalPort as a JSON number + -- have either IPV4 or IPV6 field visible + -- remove "customInformation" if not needed anymore + -- remove "escapeImplementation" if not needed anymore + -- + -- Config file + -- + -- Fix JSON number: ServerPort + -- Fix: IPV6Address dont show if value does not exist + -- Fix JSON number: ProxyPort to number (dont show if it does not exist) + -- Fix JSON number: fRPServerPort + -- Fix JSON boolean: fRPServerPort + -- Fix JSON boolean: behindNAT + -- Fix JSON boolean: bareMetal + -- remove "customConfig" if not needed + -- + -- MapPort + -- to have a dedicated ip address (with type either IPV6 or IPV4 fields) + -- to have a dedicated port field + + instance FromJSON P2prcConfig where parseJSON (Object o) = do @@ -269,7 +312,7 @@ newtype IPAdressTable instance FromJSON IPAdressTable where parseJSON = withObject "IPAdressTable" $ - \v -> + \ v -> MkIPAdressTable <$> v .: "ip_address" @@ -279,8 +322,8 @@ data ServerInfo = MkServerInfo , latency :: Int , download :: Int , upload :: Int - , serverPort :: PortNumber - , bareMetalSSHPort :: Maybe PortNumber + , serverPort :: Int + , bareMetalSSHPort :: Maybe Int , nat :: Bool , escapeImplementation :: Maybe T.Text , customInformation :: Maybe T.Text @@ -296,7 +339,7 @@ data IPAddress instance FromJSON ServerInfo where parseJSON = withObject "ServerInfo" $ - \o -> do + \ o -> do name <- o .: "Name" ip4str <- o .: "IPV4" @@ -310,6 +353,7 @@ instance FromJSON ServerInfo where mEscImpl <- o .: "EscapeImplementation" custInfo <- o .: "CustomInformation" + pure $ MkServerInfo { name = name @@ -318,7 +362,7 @@ instance FromJSON ServerInfo where , download = download , upload = upload , serverPort = getPortUNSAFE serverPort - , bareMetalSSHPort = getBMShhPort bmSshPort -- TODO: add perhaps null placeholder?? + , bareMetalSSHPort = getBMShhPort bmSshPort , nat = getNat nat , escapeImplementation = mEscImpl , customInformation = custInfo -- TODO: deal with null value @@ -330,11 +374,11 @@ instance FromJSON ServerInfo where getNat ('T':_) = True getNat _ = False - getBMShhPort :: String -> Maybe PortNumber -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! + getBMShhPort :: String -> Maybe Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! getBMShhPort [] = Nothing getBMShhPort bmSshPort = Just $ getPortUNSAFE bmSshPort - getPortUNSAFE :: String -> PortNumber -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! + getPortUNSAFE :: String -> Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! getPortUNSAFE = read getIPAddress :: String -> String -> IPAddress @@ -446,7 +490,6 @@ assignError = MkUnknownError -- TODO: add megaparsec to parse Error Messages -- -- TODO: add error when internet connection is off --- getP2PrcCmd :: IOEitherError String From 780da3bb6d309a2e3eef5b4a5b3bcf3d114f7b82 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 9 Nov 2024 18:51:10 +0000 Subject: [PATCH 25/50] adding dummy library for haskell package --- haskell/app/Main.hs | 18 ++++++++---- haskell/lib/P2Prc.hs | 6 ++++ haskell/{p2prc-haskell.cabal => p2prc.cabal} | 30 ++++++++++++++++---- 3 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 haskell/lib/P2Prc.hs rename haskell/{p2prc-haskell.cabal => p2prc.cabal} (82%) diff --git a/haskell/app/Main.hs b/haskell/app/Main.hs index c5e9798..5351d07 100644 --- a/haskell/app/Main.hs +++ b/haskell/app/Main.hs @@ -2,6 +2,9 @@ module Main where + +import P2Prc + import System.Exit ( ExitCode(ExitFailure) ) @@ -42,7 +45,7 @@ import Data.Aeson -- TODO: setup the project as a haskell library -- TODO: splitting code on different files and directories -- TODO: lock cabal index --- TODO: setup nix flake package +-- TODO: add Haddock documentation -- -- TODO: P2PRC setup -- p2prc runtime packaging @@ -54,11 +57,11 @@ import Data.Aeson -- check if p2prc command is available in environment first -- otherwise check folder above -- --- TODO: add Haddock documentation --- --- TODO: add quickcheck testing (quickchecking-dynamic) --- -- TODO: publish haskell library +-- +-- TODO: add use case examples (extra-source_files) + + main :: IO () @@ -74,6 +77,9 @@ main = do -- TODO: parse IO arguments; -- TODO: create DSL from the standard input -- + -- TODO: setup nix flake package + -- TODO: add quickcheck testing (quickchecking-dynamic) + eitherP2prcAPI <- getP2prcAPI @@ -132,6 +138,8 @@ main = do terminateProcess startProcessHandle + print siuu + (Left err) -> print err (Left err) -> print err diff --git a/haskell/lib/P2Prc.hs b/haskell/lib/P2Prc.hs new file mode 100644 index 0000000..0ad2d20 --- /dev/null +++ b/haskell/lib/P2Prc.hs @@ -0,0 +1,6 @@ +module P2Prc where + + +siuu :: String +siuu = "SIUUU" + diff --git a/haskell/p2prc-haskell.cabal b/haskell/p2prc.cabal similarity index 82% rename from haskell/p2prc-haskell.cabal rename to haskell/p2prc.cabal index baec90d..6e5c319 100644 --- a/haskell/p2prc-haskell.cabal +++ b/haskell/p2prc.cabal @@ -7,12 +7,12 @@ cabal-version: 3.0 -- Starting from the specification version 2.2, the cabal-version field must be -- the first thing in the cabal file. --- Initial package description 'p2prc-haskell' generated by +-- Initial package description 'p2prc' generated by -- 'cabal init'. For further documentation, see: -- http://haskell.org/cabal/users-guide/ -- -- The name of the package. -name: p2prc-haskell +name: p2prc -- The package version. -- See the Haskell package versioning policy (PVP) for standards @@ -55,7 +55,7 @@ extra-doc-files: CHANGELOG.md common warnings ghc-options: -Wall -executable p2prc-haskell +executable p2prc -- Import common warning flags. import: warnings @@ -63,21 +63,41 @@ executable p2prc-haskell main-is: Main.hs -- Modules included in this executable, other than Main. - -- other-modules: + -- other-modules: Example -- LANGUAGE extensions used by modules in this package. other-extensions: OverloadedStrings -- Other library packages from which modules are imported. - build-depends: base + build-depends: base , text , aeson , process , bytestring , directory + , p2prc -- Directories containing source files. hs-source-dirs: app -- Base language which the package is written in. default-language: GHC2021 + +library + + import: warnings + + build-depends: base + , text + , aeson + , process + , bytestring + , directory + + hs-source-dirs: lib + + exposed-modules: P2Prc + + other-extensions: OverloadedStrings + + default-language: GHC2021 From 427f47cdf4013a2c627047ebaddda4eb1b946a09 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 9 Nov 2024 18:53:03 +0000 Subject: [PATCH 26/50] renamed app directory to src directory --- haskell/p2prc.cabal | 2 +- haskell/{app => src}/Main.hs | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename haskell/{app => src}/Main.hs (100%) diff --git a/haskell/p2prc.cabal b/haskell/p2prc.cabal index 6e5c319..a39a2fc 100644 --- a/haskell/p2prc.cabal +++ b/haskell/p2prc.cabal @@ -78,7 +78,7 @@ executable p2prc , p2prc -- Directories containing source files. - hs-source-dirs: app + hs-source-dirs: src -- Base language which the package is written in. default-language: GHC2021 diff --git a/haskell/app/Main.hs b/haskell/src/Main.hs similarity index 100% rename from haskell/app/Main.hs rename to haskell/src/Main.hs From c481eb0b5c1a9960898cda3722c3118d67d3a626 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 9 Nov 2024 19:28:05 +0000 Subject: [PATCH 27/50] improving cabal build configuration --- haskell/.gitignore | 1 + haskell/cabal.project | 4 ++++ haskell/p2prc.cabal | 21 +++++++-------------- 3 files changed, 12 insertions(+), 14 deletions(-) create mode 100644 haskell/cabal.project diff --git a/haskell/.gitignore b/haskell/.gitignore index 14613be..c7af4d1 100644 --- a/haskell/.gitignore +++ b/haskell/.gitignore @@ -11,3 +11,4 @@ server key.pem cert.pem +cabal.project.local diff --git a/haskell/cabal.project b/haskell/cabal.project new file mode 100644 index 0000000..3293760 --- /dev/null +++ b/haskell/cabal.project @@ -0,0 +1,4 @@ + +packages: ./p2prc.cabal + +index-state: 2024-11-09T17:56:52Z diff --git a/haskell/p2prc.cabal b/haskell/p2prc.cabal index a39a2fc..3ab21d5 100644 --- a/haskell/p2prc.cabal +++ b/haskell/p2prc.cabal @@ -1,19 +1,12 @@ cabal-version: 3.0 --- The cabal-version field refers to the version of the .cabal specification, --- and can be different from the cabal-install (the tool) version and the --- Cabal (the library) version you are using. As such, the Cabal (the library) --- version used must be equal or greater than the version stated in this field. --- Starting from the specification version 2.2, the cabal-version field must be --- the first thing in the cabal file. --- Initial package description 'p2prc' generated by --- 'cabal init'. For further documentation, see: -- http://haskell.org/cabal/users-guide/ --- + -- The name of the package. name: p2prc + -- The package version. -- See the Haskell package versioning policy (PVP) for standards -- guiding when and how versions should be incremented. @@ -24,10 +17,10 @@ name: p2prc version: 0.1.0.0 -- A short (one-line) description of the package. --- synopsis: +synopsis: p2prc haskell library -- A longer description of the package. --- description: +description: Implements a client interface to the P2Prc networking runtime -- The license under which the package is released. license: GPL-3.0-only @@ -59,6 +52,9 @@ executable p2prc -- Import common warning flags. import: warnings + -- Directories containing source files. + hs-source-dirs: src + -- .hs or .lhs file containing the Main module. main-is: Main.hs @@ -77,9 +73,6 @@ executable p2prc , directory , p2prc - -- Directories containing source files. - hs-source-dirs: src - -- Base language which the package is written in. default-language: GHC2021 From 4a103679ad00c51f1d024660a831c2cc4e6db5e1 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 9 Nov 2024 19:52:56 +0000 Subject: [PATCH 28/50] moved code to library side --- haskell/lib/P2Prc.hs | 566 ++++++++++++++++++++++++++++++++++++++++++- haskell/p2prc.cabal | 5 +- haskell/src/Main.hs | 562 +----------------------------------------- 3 files changed, 566 insertions(+), 567 deletions(-) diff --git a/haskell/lib/P2Prc.hs b/haskell/lib/P2Prc.hs index 0ad2d20..9e25599 100644 --- a/haskell/lib/P2Prc.hs +++ b/haskell/lib/P2Prc.hs @@ -1,6 +1,566 @@ -module P2Prc where +{-# LANGUAGE OverloadedStrings #-} + +module P2Prc + ( runP2Prc + ) + where -siuu :: String -siuu = "SIUUU" +import System.Exit + ( ExitCode(ExitFailure) + ) +import System.Process + ( readProcessWithExitCode + , proc + , createProcess + , terminateProcess + , ProcessHandle + ) + +import System.Directory + ( doesDirectoryExist + , doesFileExist + , removeDirectoryRecursive + , removeFile + ) + +import Control.Concurrent (threadDelay) + +import Control.Monad + ( when + , mzero + ) + +import qualified Data.Text as T + +import qualified Data.ByteString.Lazy.Char8 as LBC8 + +import Data.Aeson + +-- import System.IO + + +-- URGENT TASKS +-- +-- TODO: setup the project as a haskell library +-- TODO: splitting code on different files and directories +-- TODO: lock cabal index +-- TODO: add Haddock documentation +-- +-- TODO: P2PRC setup + -- p2prc runtime packaging + -- Perhaps create internal script to run P2PRC from nix flake + -- "nix flake run ..." + -- simplify packaging + -- check version P2PRC: only run if version if above a certain value + -- setup p2prc command + -- check if p2prc command is available in environment first + -- otherwise check folder above +-- +-- TODO: publish haskell library +-- +-- TODO: add use case examples (extra-source_files) + + + + +runP2Prc :: IO () +runP2Prc = do + + + -- important but not urgent yet + -- + -- TODO: Change Standard Library + -- TODO: add GDTA syntax to data types + -- TODO: need monad transformers to refactor the code + -- + -- TODO: parse IO arguments; + -- TODO: create DSL from the standard input + -- + -- TODO: setup nix flake package + -- TODO: add quickcheck testing (quickchecking-dynamic) + + + + eitherP2prcAPI <- getP2prcAPI + + case eitherP2prcAPI of + (Right p2prcAPI) -> do + + let + ( MkP2prAPI + { startServer = startServer + , execInitConfig = execInitConfig + , execListServers = execListServers + , execMapPort = execMapPort + } + ) = p2prcAPI + + + configValue <- execInitConfig + + -- TODO: get name of host server from config json + + print configValue + putStrLn "\n\n\n" + + eitherStartProcessHandle <- startServer + + + case eitherStartProcessHandle of + (Right startProcessHandle) -> do + + sleepNSecs 5 + + outputStr <- execListServers + print outputStr + + mapPortOut <- execMapPort $ MkMapPortRequest 3333 "domain" + + + case mapPortOut of + (Right v) -> print v + (Left e) -> print e + + + -- TODO: work on looping function + -- + -- Loop (Run replica of haskell program on different $NODES) + -- - Start server + -- - wait 4 seconds + -- - Identify new node running p2prc with SSH external port exposed + -- - SSH into machine + -- - Use simple File transfer to setup files + -- - Run server + -- - Use remote machine p2prc cmd to map a port using --mp + -- - Return back the exposed public IP and port number back to stdout + + + terminateProcess startProcessHandle + + (Left err) -> print err + + (Left err) -> print err + + + +data P2prAPI = MkP2prAPI + { startServer :: IOEitherError ProcessHandle + , execInitConfig :: IOEitherError P2prcConfig + , execListServers :: IOEitherError IPAdressTable + , execMapPort :: MapPortRequest -> IOEitherError MapPortResponse + } + + +data MapPortRequest + = MkMapPortRequest Int String + + +getP2prcAPI :: IOEitherError P2prAPI +getP2prcAPI = do + + cleanEnvironment + + eitherP2prcCmd <- getP2PrcCmd + + pure $ case eitherP2prcCmd of + (Right p2prcCmd) -> let + + execProcP2PrcParser :: + FromJSON a => + [CLIOpt] -> StdInput -> IOEitherError a + execProcP2PrcParser = eitherExecProcessParser p2prcCmd + -- TODO: GHC question, why does it scope down instead staying generic + + execProcP2Prc = eitherExecProcess p2prcCmd + + in do + + Right $ MkP2prAPI + { startServer = spawnProcP2Prc p2prcCmd [ MkOptAtomic "--s" ] + + , execListServers = + execProcP2PrcParser [ MkOptAtomic "--ls" ] MkEmptyStdInput + + , execMapPort = + \ (MkMapPortRequest portNumber _) -> + execProcP2PrcParser + [ MkOptTuple + ( "--mp" + , show portNumber + ) + -- , MkOptTuple -- TODO: add domain parameter + -- ( "--dm" + -- , domainName + -- ) + ] + MkEmptyStdInput + + , execInitConfig = do + + confInitRes <- execProcP2Prc [ MkOptAtomic "--dc" ] MkEmptyStdInput + + case confInitRes of + (Right _) -> do + + -- TODO: get config file name dynamically + + -- TODO: change values before loading file + let fname = "/home/xecarlox/Desktop/p2p-rendering-computation/haskell/config.json" :: FilePath + + + -- TODO: read config check if file exists + configContent <- readFile fname + + pure $ eitherErrDecode configContent + + (Left err) -> pure $ Left err + + } + + (Left err) -> Left err + + +newtype MapPortResponse + = MkMapPortResponse + { ipAddress :: String + -- , ipAddress :: IPAddress -- TODO: fix the api output + -- , port :: Int -- TODO: fix the api output + } + deriving Show + + + +instance FromJSON MapPortResponse where + parseJSON (Object o) = do + + ipAddress <- o .: "IPAddress" + + pure $ + MkMapPortResponse + { ipAddress=ipAddress + } + + parseJSON _ = mzero + + + +newtype P2prcConfig = MkP2prConfig + { machineName :: String + -- , iPTable :: String -- File + -- , dockerContainers :: String -- Directory + -- , defaultDockerFile :: String -- Directory + -- , dockerRunLogs :: String -- Directory + -- , speedTestFile :: String -- File + -- , iPV6Address :: Maybe String + -- , pluginPath :: String -- Directory + -- , trackContainersPath :: String -- File + -- , hostServerPort :: Int + -- , proxyPort :: Maybe Int + -- , groupTrackContainersPath :: File + -- , fRPServerPort :: Bool + -- , behindNAT :: Bool + -- , iPTableKey :: String + -- , publicKeyFile :: String -- File + -- , privateKeyFile :: String -- File + -- , pemFile :: String -- File + -- , keyFile :: String -- File + -- , bareMetal :: Bool + -- , customConfig + } + deriving Show + + +-- TODO: p2prc API + -- + -- ListServers + -- remove "ip_address" root field if not needed + -- "Nat field" returning a JSON Boolean + -- serverPort as a JSON number + -- baremetalPort as a JSON number + -- have either IPV4 or IPV6 field visible + -- remove "customInformation" if not needed anymore + -- remove "escapeImplementation" if not needed anymore + -- + -- Config file + -- + -- Fix JSON number: ServerPort + -- Fix: IPV6Address dont show if value does not exist + -- Fix JSON number: ProxyPort to number (dont show if it does not exist) + -- Fix JSON number: fRPServerPort + -- Fix JSON boolean: fRPServerPort + -- Fix JSON boolean: behindNAT + -- Fix JSON boolean: bareMetal + -- remove "customConfig" if not needed + -- + -- MapPort + -- to have a dedicated ip address (with type either IPV6 or IPV4 fields) + -- to have a dedicated port field + + +instance FromJSON P2prcConfig where + parseJSON (Object o) = do + + machineName <- o .: "MachineName" + + pure + $ MkP2prConfig + { machineName=machineName + } + + parseJSON _ = mzero + + +newtype IPAdressTable + = MkIPAdressTable [ServerInfo] + deriving Show + + +instance FromJSON IPAdressTable where + parseJSON = withObject "IPAdressTable" $ + \ v -> + MkIPAdressTable <$> v .: "ip_address" + + +data ServerInfo = MkServerInfo + { name :: T.Text + , ip :: IPAddress + , latency :: Int + , download :: Int + , upload :: Int + , serverPort :: Int + , bareMetalSSHPort :: Maybe Int + , nat :: Bool + , escapeImplementation :: Maybe T.Text + , customInformation :: Maybe T.Text + } + deriving Show + + +data IPAddress + = MkIPv4 String + | MkIPv6 String + deriving Show + + +instance FromJSON ServerInfo where + parseJSON = withObject "ServerInfo" $ + \ o -> do + + name <- o .: "Name" + ip4str <- o .: "IPV4" + ip6str <- o .: "IPV6" + latency <- o .: "Latency" + download <- o .: "Download" + upload <- o .: "Upload" + serverPort <- o .: "ServerPort" + bmSshPort <- o .: "BareMetalSSHPort" + nat <- o .: "NAT" + mEscImpl <- o .: "EscapeImplementation" + custInfo <- o .: "CustomInformation" + + + pure $ + MkServerInfo + { name = name + , ip = getIPAddress ip4str ip6str + , latency = latency + , download = download + , upload = upload + , serverPort = getPortUNSAFE serverPort + , bareMetalSSHPort = getBMShhPort bmSshPort + , nat = getNat nat + , escapeImplementation = mEscImpl + , customInformation = custInfo -- TODO: deal with null value + } + + where + + getNat :: String -> Bool -- TODO: Change it to normal JSON + getNat ('T':_) = True + getNat _ = False + + getBMShhPort :: String -> Maybe Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! + getBMShhPort [] = Nothing + getBMShhPort bmSshPort = Just $ getPortUNSAFE bmSshPort + + getPortUNSAFE :: String -> Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! + getPortUNSAFE = read + + getIPAddress :: String -> String -> IPAddress + getIPAddress [] ip6 = MkIPv6 ip6 + getIPAddress ip4 _ = MkIPv4 ip4 + + +data StdInput + = MkEmptyStdInput + | MkStdInputVal String + + +instance Show StdInput where + show MkEmptyStdInput = "" + show (MkStdInputVal v) = v + + +type IOEitherError a = IO (Either Error a) + + +eitherExecProcessParser :: + FromJSON a => + CLICmd -> [CLIOpt] -> StdInput -> IOEitherError a +eitherExecProcessParser p2prcCmd opts stdInput = + do + val <- eitherExecProcess p2prcCmd opts stdInput + + pure $ case val of + (Right v) -> eitherErrDecode v + (Left e) -> Left e + + +eitherErrDecode :: + FromJSON a => + String -> Either Error a +eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack + + +data CLIOpt + = MkEmptyOpts + | MkOptAtomic String + | MkOptTuple (String, String) + + +type CLIOptsInput = [String] +type CLICmd = String + + +eitherExecProcess :: CLICmd -> [CLIOpt] -> StdInput -> IOEitherError String +eitherExecProcess cmd opts input = + do + (code, out, err) <- + readProcessWithExitCode + cmd + (optsToCLI opts) + (show input) + + pure $ case code of + ExitFailure i -> Left $ MkSystemError i cmd err + _ -> Right out + + +optsToCLI :: [CLIOpt] -> CLIOptsInput +optsToCLI = concatMap _optToCLI + where + + _optToCLI :: CLIOpt -> CLIOptsInput + _optToCLI MkEmptyOpts = [] + _optToCLI (MkOptAtomic o) = [o] + _optToCLI (MkOptTuple (o, v)) = [o, v] + + +spawnProcP2Prc :: CLICmd -> [CLIOpt] -> IOEitherError ProcessHandle +spawnProcP2Prc cmd opts = + do + let prc = proc cmd $ optsToCLI opts + + creationResult <- createProcess prc + + let (_, _, _, ph) = creationResult + + case creationResult of + (_, _, Just _, _) -> do + + terminateProcess ph + + pure $ Left $ MkErrorSpawningProcess cmd + + _-> pure $ Right ph + + +eitherErrorDecode :: Either String a -> Either Error a +eitherErrorDecode esa = + case esa of + (Left s) -> Left $ assignError s + (Right v) -> Right v + + +data Error + = MkUnknownError String + | MkErrorSpawningProcess String + | MkSystemError Int String String + deriving Show + + +assignError :: String -> Error +assignError = MkUnknownError +-- +-- TODO: add megaparsec to parse Error Messages +-- +-- TODO: add error when internet connection is off + + +getP2PrcCmd :: IOEitherError String +getP2PrcCmd = do + + -- assumes the program is ran inside the haskell module in p2prc's repo + -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" + + let trimString = T.unpack . T.strip . T.pack + + eitherErrPwd <- eitherExecProcess "pwd" [MkEmptyOpts] MkEmptyStdInput + + case eitherErrPwd of + + (Right pwdOut) -> + eitherExecProcess + "sed" + [ MkOptAtomic "s/haskell/p2p-rendering-computation/" ] + $ MkStdInputVal + $ trimString pwdOut + + err -> pure err + + +cleanEnvironment :: IO () +cleanEnvironment = do + + mapM_ removeFileIfExists + [ "cert.pem" + , "config.json" + , "key.pem" + , "p2prc.privateKey" + , "p2prc.PublicKeyBareMetal" + ] + + mapM_ removeDirRIfExists + [ "client" + , "p2p" + , "plugin" + , "server" + ] + + where + + removeIfExists + :: (FilePath -> IO Bool) + -> (FilePath -> IO ()) + -> FilePath + -> IO () + removeIfExists doesItExists rmIt filePath = + do + res <- doesItExists filePath + when res $ rmIt filePath + + removeDirRIfExists = + removeIfExists + doesDirectoryExist + removeDirectoryRecursive + + removeFileIfExists = + removeIfExists + doesFileExist + removeFile + + +sleepNSecs :: Int -> IO () +sleepNSecs i = threadDelay (i * 1000000) diff --git a/haskell/p2prc.cabal b/haskell/p2prc.cabal index 3ab21d5..1f0ba9b 100644 --- a/haskell/p2prc.cabal +++ b/haskell/p2prc.cabal @@ -67,11 +67,8 @@ executable p2prc -- Other library packages from which modules are imported. build-depends: base , text - , aeson - , process - , bytestring - , directory , p2prc + , process -- Base language which the package is written in. default-language: GHC2021 diff --git a/haskell/src/Main.hs b/haskell/src/Main.hs index 5351d07..a6764d8 100644 --- a/haskell/src/Main.hs +++ b/haskell/src/Main.hs @@ -1,567 +1,9 @@ -{-# LANGUAGE OverloadedStrings #-} module Main where - -import P2Prc - -import System.Exit - ( ExitCode(ExitFailure) - ) - -import System.Process - ( readProcessWithExitCode - , proc - , createProcess - , terminateProcess - , ProcessHandle - ) - -import System.Directory - ( doesDirectoryExist - , doesFileExist - , removeDirectoryRecursive - , removeFile - ) - -import Control.Concurrent (threadDelay) - -import Control.Monad - ( when - , mzero - ) - -import qualified Data.Text as T - -import qualified Data.ByteString.Lazy.Char8 as LBC8 - -import Data.Aeson - --- import System.IO - - --- URGENT TASKS --- --- TODO: setup the project as a haskell library --- TODO: splitting code on different files and directories --- TODO: lock cabal index --- TODO: add Haddock documentation --- --- TODO: P2PRC setup - -- p2prc runtime packaging - -- Perhaps create internal script to run P2PRC from nix flake - -- "nix flake run ..." - -- simplify packaging - -- check version P2PRC: only run if version if above a certain value - -- setup p2prc command - -- check if p2prc command is available in environment first - -- otherwise check folder above --- --- TODO: publish haskell library --- --- TODO: add use case examples (extra-source_files) - - +import P2Prc (runP2Prc) main :: IO () main = do - - - -- important but not urgent yet - -- - -- TODO: Change Standard Library - -- TODO: add GDTA syntax to data types - -- TODO: need monad transformers to refactor the code - -- - -- TODO: parse IO arguments; - -- TODO: create DSL from the standard input - -- - -- TODO: setup nix flake package - -- TODO: add quickcheck testing (quickchecking-dynamic) - - - - eitherP2prcAPI <- getP2prcAPI - - case eitherP2prcAPI of - (Right p2prcAPI) -> do - - let - ( MkP2prAPI - { startServer = startServer - , execInitConfig = execInitConfig - , execListServers = execListServers - , execMapPort = execMapPort - } - ) = p2prcAPI - - - configValue <- execInitConfig - - -- TODO: get name of host server from config json - - print configValue - putStrLn "\n\n\n" - - eitherStartProcessHandle <- startServer - - - case eitherStartProcessHandle of - (Right startProcessHandle) -> do - - sleepNSecs 5 - - outputStr <- execListServers - print outputStr - - mapPortOut <- execMapPort $ MkMapPortRequest 3333 "domain" - - - case mapPortOut of - (Right v) -> print v - (Left e) -> print e - - - -- TODO: work on looping function - -- - -- Loop (Run replica of haskell program on different $NODES) - -- - Start server - -- - wait 4 seconds - -- - Identify new node running p2prc with SSH external port exposed - -- - SSH into machine - -- - Use simple File transfer to setup files - -- - Run server - -- - Use remote machine p2prc cmd to map a port using --mp - -- - Return back the exposed public IP and port number back to stdout - - - terminateProcess startProcessHandle - - print siuu - - (Left err) -> print err - - (Left err) -> print err - - - -data P2prAPI = MkP2prAPI - { startServer :: IOEitherError ProcessHandle - , execInitConfig :: IOEitherError P2prcConfig - , execListServers :: IOEitherError IPAdressTable - , execMapPort :: MapPortRequest -> IOEitherError MapPortResponse - } - - -data MapPortRequest - = MkMapPortRequest Int String - - -getP2prcAPI :: IOEitherError P2prAPI -getP2prcAPI = do - - cleanEnvironment - - eitherP2prcCmd <- getP2PrcCmd - - pure $ case eitherP2prcCmd of - (Right p2prcCmd) -> let - - execProcP2PrcParser :: - FromJSON a => - [CLIOpt] -> StdInput -> IOEitherError a - execProcP2PrcParser = eitherExecProcessParser p2prcCmd - -- TODO: GHC question, why does it scope down instead staying generic - - execProcP2Prc = eitherExecProcess p2prcCmd - - in do - - Right $ MkP2prAPI - { startServer = spawnProcP2Prc p2prcCmd [ MkOptAtomic "--s" ] - - , execListServers = - execProcP2PrcParser [ MkOptAtomic "--ls" ] MkEmptyStdInput - - , execMapPort = - \ (MkMapPortRequest portNumber _) -> - execProcP2PrcParser - [ MkOptTuple - ( "--mp" - , show portNumber - ) - -- , MkOptTuple -- TODO: add domain parameter - -- ( "--dm" - -- , domainName - -- ) - ] - MkEmptyStdInput - - , execInitConfig = do - - confInitRes <- execProcP2Prc [ MkOptAtomic "--dc" ] MkEmptyStdInput - - case confInitRes of - (Right _) -> do - - -- TODO: get config file name dynamically - - -- TODO: change values before loading file - let fname = "/home/xecarlox/Desktop/p2p-rendering-computation/haskell/config.json" :: FilePath - - - -- TODO: read config check if file exists - configContent <- readFile fname - - pure $ eitherErrDecode configContent - - (Left err) -> pure $ Left err - - } - - (Left err) -> Left err - - -data MapPortResponse - = MkMapPortResponse - { ipAddress :: String - -- , ipAddress :: IPAddress -- TODO: fix the api output - -- , port :: Int -- TODO: fix the api output - } - deriving Show - - - -instance FromJSON MapPortResponse where - parseJSON (Object o) = do - - ipAddress <- o .: "IPAddress" - - pure $ - MkMapPortResponse - { ipAddress=ipAddress - } - - parseJSON _ = mzero - - - -data P2prcConfig = MkP2prConfig - { machineName :: String - -- , iPTable :: String -- File - -- , dockerContainers :: String -- Directory - -- , defaultDockerFile :: String -- Directory - -- , dockerRunLogs :: String -- Directory - -- , speedTestFile :: String -- File - -- , iPV6Address :: Maybe String - -- , pluginPath :: String -- Directory - -- , trackContainersPath :: String -- File - -- , hostServerPort :: Int - -- , proxyPort :: Maybe Int - -- , groupTrackContainersPath :: File - -- , fRPServerPort :: Bool - -- , behindNAT :: Bool - -- , iPTableKey :: String - -- , publicKeyFile :: String -- File - -- , privateKeyFile :: String -- File - -- , pemFile :: String -- File - -- , keyFile :: String -- File - -- , bareMetal :: Bool - -- , customConfig - } - deriving Show - - --- TODO: p2prc API - -- - -- ListServers - -- remove "ip_address" root field if not needed - -- "Nat field" returning a JSON Boolean - -- serverPort as a JSON number - -- baremetalPort as a JSON number - -- have either IPV4 or IPV6 field visible - -- remove "customInformation" if not needed anymore - -- remove "escapeImplementation" if not needed anymore - -- - -- Config file - -- - -- Fix JSON number: ServerPort - -- Fix: IPV6Address dont show if value does not exist - -- Fix JSON number: ProxyPort to number (dont show if it does not exist) - -- Fix JSON number: fRPServerPort - -- Fix JSON boolean: fRPServerPort - -- Fix JSON boolean: behindNAT - -- Fix JSON boolean: bareMetal - -- remove "customConfig" if not needed - -- - -- MapPort - -- to have a dedicated ip address (with type either IPV6 or IPV4 fields) - -- to have a dedicated port field - - -instance FromJSON P2prcConfig where - parseJSON (Object o) = do - - machineName <- o .: "MachineName" - - pure - $ MkP2prConfig - { machineName=machineName - } - - parseJSON _ = mzero - - -newtype IPAdressTable - = MkIPAdressTable [ServerInfo] - deriving Show - - -instance FromJSON IPAdressTable where - parseJSON = withObject "IPAdressTable" $ - \ v -> - MkIPAdressTable <$> v .: "ip_address" - - -data ServerInfo = MkServerInfo - { name :: T.Text - , ip :: IPAddress - , latency :: Int - , download :: Int - , upload :: Int - , serverPort :: Int - , bareMetalSSHPort :: Maybe Int - , nat :: Bool - , escapeImplementation :: Maybe T.Text - , customInformation :: Maybe T.Text - } - deriving Show - - -data IPAddress - = MkIPv4 String - | MkIPv6 String - deriving Show - - -instance FromJSON ServerInfo where - parseJSON = withObject "ServerInfo" $ - \ o -> do - - name <- o .: "Name" - ip4str <- o .: "IPV4" - ip6str <- o .: "IPV6" - latency <- o .: "Latency" - download <- o .: "Download" - upload <- o .: "Upload" - serverPort <- o .: "ServerPort" - bmSshPort <- o .: "BareMetalSSHPort" - nat <- o .: "NAT" - mEscImpl <- o .: "EscapeImplementation" - custInfo <- o .: "CustomInformation" - - - pure $ - MkServerInfo - { name = name - , ip = getIPAddress ip4str ip6str - , latency = latency - , download = download - , upload = upload - , serverPort = getPortUNSAFE serverPort - , bareMetalSSHPort = getBMShhPort bmSshPort - , nat = getNat nat - , escapeImplementation = mEscImpl - , customInformation = custInfo -- TODO: deal with null value - } - - where - - getNat :: String -> Bool -- TODO: Change it to normal JSON - getNat ('T':_) = True - getNat _ = False - - getBMShhPort :: String -> Maybe Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! - getBMShhPort [] = Nothing - getBMShhPort bmSshPort = Just $ getPortUNSAFE bmSshPort - - getPortUNSAFE :: String -> Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! - getPortUNSAFE = read - - getIPAddress :: String -> String -> IPAddress - getIPAddress [] ip6 = MkIPv6 ip6 - getIPAddress ip4 _ = MkIPv4 ip4 - - -data StdInput - = MkEmptyStdInput - | MkStdInputVal String - - -instance Show StdInput where - show MkEmptyStdInput = "" - show (MkStdInputVal v) = v - - -type IOEitherError a = IO (Either Error a) - - -eitherExecProcessParser :: - FromJSON a => - CLICmd -> [CLIOpt] -> StdInput -> IOEitherError a -eitherExecProcessParser p2prcCmd opts stdInput = - do - val <- eitherExecProcess p2prcCmd opts stdInput - - pure $ case val of - (Right v) -> eitherErrDecode v - (Left e) -> Left e - - -eitherErrDecode :: - FromJSON a => - String -> Either Error a -eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack - - -data CLIOpt - = MkEmptyOpts - | MkOptAtomic String - | MkOptTuple (String, String) - - -type CLIOptsInput = [String] -type CLICmd = String - - -eitherExecProcess :: CLICmd -> [CLIOpt] -> StdInput -> IOEitherError String -eitherExecProcess cmd opts input = - do - (code, out, err) <- - readProcessWithExitCode - cmd - (optsToCLI opts) - (show input) - - pure $ case code of - ExitFailure i -> Left $ MkSystemError i cmd err - _ -> Right out - - -optsToCLI :: [CLIOpt] -> CLIOptsInput -optsToCLI = concatMap _optToCLI - where - - _optToCLI :: CLIOpt -> CLIOptsInput - _optToCLI MkEmptyOpts = [] - _optToCLI (MkOptAtomic o) = [o] - _optToCLI (MkOptTuple (o, v)) = [o, v] - - -spawnProcP2Prc :: CLICmd -> [CLIOpt] -> IOEitherError ProcessHandle -spawnProcP2Prc cmd opts = - do - let prc = proc cmd $ optsToCLI opts - - creationResult <- createProcess prc - - let (_, _, _, ph) = creationResult - - case creationResult of - (_, _, Just _, _) -> do - - terminateProcess ph - - pure $ Left $ MkErrorSpawningProcess cmd - - _-> pure $ Right ph - - -eitherErrorDecode :: Either String a -> Either Error a -eitherErrorDecode esa = - case esa of - (Left s) -> Left $ assignError s - (Right v) -> Right v - - -data Error - = MkUnknownError String - | MkErrorSpawningProcess String - | MkSystemError Int String String - deriving Show - - -assignError :: String -> Error -assignError = MkUnknownError --- --- TODO: add megaparsec to parse Error Messages --- --- TODO: add error when internet connection is off - - -getP2PrcCmd :: IOEitherError String -getP2PrcCmd = do - - -- assumes the program is ran inside the haskell module in p2prc's repo - -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" - - let trimString = T.unpack . T.strip . T.pack - - eitherErrPwd <- eitherExecProcess "pwd" [MkEmptyOpts] MkEmptyStdInput - - case eitherErrPwd of - - (Right pwdOut) -> - eitherExecProcess - "sed" - [ MkOptAtomic "s/haskell/p2p-rendering-computation/" ] - $ MkStdInputVal - $ trimString pwdOut - - err -> pure err - - -cleanEnvironment :: IO () -cleanEnvironment = do - - mapM_ removeFileIfExists - [ "cert.pem" - , "config.json" - , "key.pem" - , "p2prc.privateKey" - , "p2prc.PublicKeyBareMetal" - ] - - mapM_ removeDirRIfExists - [ "client" - , "p2p" - , "plugin" - , "server" - ] - - where - - removeIfExists - :: (FilePath -> IO Bool) - -> (FilePath -> IO ()) - -> FilePath - -> IO () - removeIfExists doesItExists rmIt filePath = - do - res <- doesItExists filePath - when res $ rmIt filePath - - removeDirRIfExists = - removeIfExists - doesDirectoryExist - removeDirectoryRecursive - - removeFileIfExists = - removeIfExists - doesFileExist - removeFile - - -sleepNSecs :: Int -> IO () -sleepNSecs i = threadDelay (i * 1000000) + runP2Prc From 4a384f2c5cf4114f03d30876b9e4453bcafcb8f3 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 9 Nov 2024 20:24:42 +0000 Subject: [PATCH 29/50] organising library files --- haskell/lib/API.hs | 0 haskell/lib/CLI.hs | 0 haskell/lib/Environment.hs | 0 haskell/lib/JSON.hs | 0 haskell/lib/P2Prc.hs | 75 +++++++++++++++++++------------------- haskell/p2prc.cabal | 4 -- 6 files changed, 38 insertions(+), 41 deletions(-) create mode 100644 haskell/lib/API.hs create mode 100644 haskell/lib/CLI.hs create mode 100644 haskell/lib/Environment.hs create mode 100644 haskell/lib/JSON.hs diff --git a/haskell/lib/API.hs b/haskell/lib/API.hs new file mode 100644 index 0000000..e69de29 diff --git a/haskell/lib/CLI.hs b/haskell/lib/CLI.hs new file mode 100644 index 0000000..e69de29 diff --git a/haskell/lib/Environment.hs b/haskell/lib/Environment.hs new file mode 100644 index 0000000..e69de29 diff --git a/haskell/lib/JSON.hs b/haskell/lib/JSON.hs new file mode 100644 index 0000000..e69de29 diff --git a/haskell/lib/P2Prc.hs b/haskell/lib/P2Prc.hs index 9e25599..d128fea 100644 --- a/haskell/lib/P2Prc.hs +++ b/haskell/lib/P2Prc.hs @@ -1,14 +1,10 @@ {-# LANGUAGE OverloadedStrings #-} -module P2Prc - ( runP2Prc - ) +module P2Prc ( runP2Prc ) where -import System.Exit - ( ExitCode(ExitFailure) - ) +import System.Exit ( ExitCode(ExitFailure) ) import System.Process ( readProcessWithExitCode @@ -25,7 +21,7 @@ import System.Directory , removeFile ) -import Control.Concurrent (threadDelay) +import Control.Concurrent ( threadDelay ) import Control.Monad ( when @@ -64,6 +60,7 @@ import Data.Aeson +-- Module: API runP2Prc :: IO () runP2Prc = do @@ -87,7 +84,6 @@ runP2Prc = do case eitherP2prcAPI of (Right p2prcAPI) -> do - let ( MkP2prAPI { startServer = startServer @@ -111,6 +107,8 @@ runP2Prc = do case eitherStartProcessHandle of (Right startProcessHandle) -> do + let sleepNSecs i = threadDelay (i * 1000000) + sleepNSecs 5 outputStr <- execListServers @@ -222,6 +220,9 @@ getP2prcAPI = do (Left err) -> Left err + +-- Module: JSON + newtype MapPortResponse = MkMapPortResponse { ipAddress :: String @@ -393,6 +394,26 @@ instance FromJSON ServerInfo where getIPAddress ip4 _ = MkIPv4 ip4 +-- Module Error + +data Error + = MkUnknownError String + | MkErrorSpawningProcess String + | MkSystemError Int String String + deriving Show + +type IOEitherError a = IO (Either Error a) + +assignError :: String -> Error +assignError = MkUnknownError +-- +-- TODO: add megaparsec to parse Error Messages +-- +-- TODO: add error when internet connection is off + + +-- Module: CLI + data StdInput = MkEmptyStdInput | MkStdInputVal String @@ -403,7 +424,13 @@ instance Show StdInput where show (MkStdInputVal v) = v -type IOEitherError a = IO (Either Error a) +data CLIOpt + = MkEmptyOpts + | MkOptAtomic String + | MkOptTuple (String, String) + +type CLIOptsInput = [String] +type CLICmd = String eitherExecProcessParser :: @@ -424,16 +451,6 @@ eitherErrDecode :: eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack -data CLIOpt - = MkEmptyOpts - | MkOptAtomic String - | MkOptTuple (String, String) - - -type CLIOptsInput = [String] -type CLICmd = String - - eitherExecProcess :: CLICmd -> [CLIOpt] -> StdInput -> IOEitherError String eitherExecProcess cmd opts input = do @@ -484,21 +501,6 @@ eitherErrorDecode esa = (Right v) -> Right v -data Error - = MkUnknownError String - | MkErrorSpawningProcess String - | MkSystemError Int String String - deriving Show - - -assignError :: String -> Error -assignError = MkUnknownError --- --- TODO: add megaparsec to parse Error Messages --- --- TODO: add error when internet connection is off - - getP2PrcCmd :: IOEitherError String getP2PrcCmd = do @@ -521,6 +523,8 @@ getP2PrcCmd = do err -> pure err +-- Module: Environment + cleanEnvironment :: IO () cleanEnvironment = do @@ -561,6 +565,3 @@ cleanEnvironment = do doesFileExist removeFile - -sleepNSecs :: Int -> IO () -sleepNSecs i = threadDelay (i * 1000000) diff --git a/haskell/p2prc.cabal b/haskell/p2prc.cabal index 1f0ba9b..a095c37 100644 --- a/haskell/p2prc.cabal +++ b/haskell/p2prc.cabal @@ -66,9 +66,7 @@ executable p2prc -- Other library packages from which modules are imported. build-depends: base - , text , p2prc - , process -- Base language which the package is written in. default-language: GHC2021 @@ -88,6 +86,4 @@ library exposed-modules: P2Prc - other-extensions: OverloadedStrings - default-language: GHC2021 From 86dab8919ecf28c215fcb7cfe10cf827054b2097 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 9 Nov 2024 20:50:41 +0000 Subject: [PATCH 30/50] organised library for p2prc; moved Error, Environment and JSON logic to their own files --- haskell/lib/API.hs | 4 + haskell/lib/CLI.hs | 3 + haskell/lib/Environment.hs | 54 ++++++++ haskell/lib/Error.hs | 17 +++ haskell/lib/JSON.hs | 189 ++++++++++++++++++++++++++++ haskell/lib/P2Prc.hs | 251 +------------------------------------ haskell/p2prc.cabal | 6 + 7 files changed, 277 insertions(+), 247 deletions(-) create mode 100644 haskell/lib/Error.hs diff --git a/haskell/lib/API.hs b/haskell/lib/API.hs index e69de29..6c25ad1 100644 --- a/haskell/lib/API.hs +++ b/haskell/lib/API.hs @@ -0,0 +1,4 @@ + +module API where + +a=0 diff --git a/haskell/lib/CLI.hs b/haskell/lib/CLI.hs index e69de29..7eb2699 100644 --- a/haskell/lib/CLI.hs +++ b/haskell/lib/CLI.hs @@ -0,0 +1,3 @@ +module CLI where + +a=0 diff --git a/haskell/lib/Environment.hs b/haskell/lib/Environment.hs index e69de29..0eca44e 100644 --- a/haskell/lib/Environment.hs +++ b/haskell/lib/Environment.hs @@ -0,0 +1,54 @@ +module Environment ( cleanEnvironment ) where + + +import System.Directory + ( doesDirectoryExist + , doesFileExist + , removeDirectoryRecursive + , removeFile + ) + +import Control.Monad ( when ) + + + +cleanEnvironment :: IO () +cleanEnvironment = do + + mapM_ removeFileIfExists + [ "cert.pem" + , "config.json" + , "key.pem" + , "p2prc.privateKey" + , "p2prc.PublicKeyBareMetal" + ] + + mapM_ removeDirRIfExists + [ "client" + , "p2p" + , "plugin" + , "server" + ] + + where + + removeIfExists + :: (FilePath -> IO Bool) + -> (FilePath -> IO ()) + -> FilePath + -> IO () + removeIfExists doesItExists rmIt filePath = + do + res <- doesItExists filePath + when res $ rmIt filePath + + removeDirRIfExists = + removeIfExists + doesDirectoryExist + removeDirectoryRecursive + + removeFileIfExists = + removeIfExists + doesFileExist + removeFile + diff --git a/haskell/lib/Error.hs b/haskell/lib/Error.hs new file mode 100644 index 0000000..1a5d6dd --- /dev/null +++ b/haskell/lib/Error.hs @@ -0,0 +1,17 @@ +module Error where + + +data Error + = MkUnknownError String + | MkErrorSpawningProcess String + | MkSystemError Int String String + deriving Show + +type IOEitherError a = IO (Either Error a) + +assignError :: String -> Error +assignError = MkUnknownError +-- +-- TODO: add megaparsec to parse Error Messages +-- +-- TODO: add error when internet connection is off diff --git a/haskell/lib/JSON.hs b/haskell/lib/JSON.hs index e69de29..134fc1e 100644 --- a/haskell/lib/JSON.hs +++ b/haskell/lib/JSON.hs @@ -0,0 +1,189 @@ +{-# LANGUAGE OverloadedStrings #-} + +module JSON + ( P2prcConfig + , IPAdressTable + , MapPortResponse + ) + where + + +import Control.Monad ( mzero ) + +import qualified Data.Text as T + +import Data.Aeson + + +newtype MapPortResponse + = MkMapPortResponse + { ipAddress :: String + -- , ipAddress :: IPAddress -- TODO: fix the api output + -- , port :: Int -- TODO: fix the api output + } + deriving Show + + + +instance FromJSON MapPortResponse where + parseJSON (Object o) = do + + ipAddress <- o .: "IPAddress" + + pure $ + MkMapPortResponse + { ipAddress=ipAddress + } + + parseJSON _ = mzero + + + +newtype P2prcConfig = MkP2prConfig + { machineName :: String + -- , iPTable :: String -- File + -- , dockerContainers :: String -- Directory + -- , defaultDockerFile :: String -- Directory + -- , dockerRunLogs :: String -- Directory + -- , speedTestFile :: String -- File + -- , iPV6Address :: Maybe String + -- , pluginPath :: String -- Directory + -- , trackContainersPath :: String -- File + -- , hostServerPort :: Int + -- , proxyPort :: Maybe Int + -- , groupTrackContainersPath :: File + -- , fRPServerPort :: Bool + -- , behindNAT :: Bool + -- , iPTableKey :: String + -- , publicKeyFile :: String -- File + -- , privateKeyFile :: String -- File + -- , pemFile :: String -- File + -- , keyFile :: String -- File + -- , bareMetal :: Bool + -- , customConfig + } + deriving Show + + +-- TODO: p2prc API + -- + -- ListServers + -- remove "ip_address" root field if not needed + -- "Nat field" returning a JSON Boolean + -- serverPort as a JSON number + -- baremetalPort as a JSON number + -- have either IPV4 or IPV6 field visible + -- remove "customInformation" if not needed anymore + -- remove "escapeImplementation" if not needed anymore + -- + -- Config file + -- + -- Fix JSON number: ServerPort + -- Fix: IPV6Address dont show if value does not exist + -- Fix JSON number: ProxyPort to number (dont show if it does not exist) + -- Fix JSON number: fRPServerPort + -- Fix JSON boolean: fRPServerPort + -- Fix JSON boolean: behindNAT + -- Fix JSON boolean: bareMetal + -- remove "customConfig" if not needed + -- + -- MapPort + -- to have a dedicated ip address (with type either IPV6 or IPV4 fields) + -- to have a dedicated port field + + +instance FromJSON P2prcConfig where + parseJSON (Object o) = do + + machineName <- o .: "MachineName" + + pure + $ MkP2prConfig + { machineName=machineName + } + + parseJSON _ = mzero + + +newtype IPAdressTable + = MkIPAdressTable [ServerInfo] + deriving Show + + +instance FromJSON IPAdressTable where + parseJSON = withObject "IPAdressTable" $ + \ v -> + MkIPAdressTable <$> v .: "ip_address" + + +data ServerInfo = MkServerInfo + { name :: T.Text + , ip :: IPAddress + , latency :: Int + , download :: Int + , upload :: Int + , serverPort :: Int + , bareMetalSSHPort :: Maybe Int + , nat :: Bool + , escapeImplementation :: Maybe T.Text + , customInformation :: Maybe T.Text + } + deriving Show + + +data IPAddress + = MkIPv4 String + | MkIPv6 String + deriving Show + + +instance FromJSON ServerInfo where + parseJSON = withObject "ServerInfo" $ + \ o -> do + + name <- o .: "Name" + ip4str <- o .: "IPV4" + ip6str <- o .: "IPV6" + latency <- o .: "Latency" + download <- o .: "Download" + upload <- o .: "Upload" + serverPort <- o .: "ServerPort" + bmSshPort <- o .: "BareMetalSSHPort" + nat <- o .: "NAT" + mEscImpl <- o .: "EscapeImplementation" + custInfo <- o .: "CustomInformation" + + + pure $ + MkServerInfo + { name = name + , ip = getIPAddress ip4str ip6str + , latency = latency + , download = download + , upload = upload + , serverPort = getPortUNSAFE serverPort + , bareMetalSSHPort = getBMShhPort bmSshPort + , nat = getNat nat + , escapeImplementation = mEscImpl + , customInformation = custInfo -- TODO: deal with null value + } + + where + + getNat :: String -> Bool -- TODO: Change it to normal JSON + getNat ('T':_) = True + getNat _ = False + + getBMShhPort :: String -> Maybe Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! + getBMShhPort [] = Nothing + getBMShhPort bmSshPort = Just $ getPortUNSAFE bmSshPort + + getPortUNSAFE :: String -> Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! + getPortUNSAFE = read + + getIPAddress :: String -> String -> IPAddress + getIPAddress [] ip6 = MkIPv6 ip6 + getIPAddress ip4 _ = MkIPv4 ip4 + + + diff --git a/haskell/lib/P2Prc.hs b/haskell/lib/P2Prc.hs index d128fea..b090db5 100644 --- a/haskell/lib/P2Prc.hs +++ b/haskell/lib/P2Prc.hs @@ -14,19 +14,8 @@ import System.Process , ProcessHandle ) -import System.Directory - ( doesDirectoryExist - , doesFileExist - , removeDirectoryRecursive - , removeFile - ) - import Control.Concurrent ( threadDelay ) -import Control.Monad - ( when - , mzero - ) import qualified Data.Text as T @@ -34,7 +23,10 @@ import qualified Data.ByteString.Lazy.Char8 as LBC8 import Data.Aeson --- import System.IO + +import Environment ( cleanEnvironment ) +import Error (IOEitherError, Error(..), assignError) +import JSON -- URGENT TASKS @@ -221,197 +213,6 @@ getP2prcAPI = do --- Module: JSON - -newtype MapPortResponse - = MkMapPortResponse - { ipAddress :: String - -- , ipAddress :: IPAddress -- TODO: fix the api output - -- , port :: Int -- TODO: fix the api output - } - deriving Show - - - -instance FromJSON MapPortResponse where - parseJSON (Object o) = do - - ipAddress <- o .: "IPAddress" - - pure $ - MkMapPortResponse - { ipAddress=ipAddress - } - - parseJSON _ = mzero - - - -newtype P2prcConfig = MkP2prConfig - { machineName :: String - -- , iPTable :: String -- File - -- , dockerContainers :: String -- Directory - -- , defaultDockerFile :: String -- Directory - -- , dockerRunLogs :: String -- Directory - -- , speedTestFile :: String -- File - -- , iPV6Address :: Maybe String - -- , pluginPath :: String -- Directory - -- , trackContainersPath :: String -- File - -- , hostServerPort :: Int - -- , proxyPort :: Maybe Int - -- , groupTrackContainersPath :: File - -- , fRPServerPort :: Bool - -- , behindNAT :: Bool - -- , iPTableKey :: String - -- , publicKeyFile :: String -- File - -- , privateKeyFile :: String -- File - -- , pemFile :: String -- File - -- , keyFile :: String -- File - -- , bareMetal :: Bool - -- , customConfig - } - deriving Show - - --- TODO: p2prc API - -- - -- ListServers - -- remove "ip_address" root field if not needed - -- "Nat field" returning a JSON Boolean - -- serverPort as a JSON number - -- baremetalPort as a JSON number - -- have either IPV4 or IPV6 field visible - -- remove "customInformation" if not needed anymore - -- remove "escapeImplementation" if not needed anymore - -- - -- Config file - -- - -- Fix JSON number: ServerPort - -- Fix: IPV6Address dont show if value does not exist - -- Fix JSON number: ProxyPort to number (dont show if it does not exist) - -- Fix JSON number: fRPServerPort - -- Fix JSON boolean: fRPServerPort - -- Fix JSON boolean: behindNAT - -- Fix JSON boolean: bareMetal - -- remove "customConfig" if not needed - -- - -- MapPort - -- to have a dedicated ip address (with type either IPV6 or IPV4 fields) - -- to have a dedicated port field - - -instance FromJSON P2prcConfig where - parseJSON (Object o) = do - - machineName <- o .: "MachineName" - - pure - $ MkP2prConfig - { machineName=machineName - } - - parseJSON _ = mzero - - -newtype IPAdressTable - = MkIPAdressTable [ServerInfo] - deriving Show - - -instance FromJSON IPAdressTable where - parseJSON = withObject "IPAdressTable" $ - \ v -> - MkIPAdressTable <$> v .: "ip_address" - - -data ServerInfo = MkServerInfo - { name :: T.Text - , ip :: IPAddress - , latency :: Int - , download :: Int - , upload :: Int - , serverPort :: Int - , bareMetalSSHPort :: Maybe Int - , nat :: Bool - , escapeImplementation :: Maybe T.Text - , customInformation :: Maybe T.Text - } - deriving Show - - -data IPAddress - = MkIPv4 String - | MkIPv6 String - deriving Show - - -instance FromJSON ServerInfo where - parseJSON = withObject "ServerInfo" $ - \ o -> do - - name <- o .: "Name" - ip4str <- o .: "IPV4" - ip6str <- o .: "IPV6" - latency <- o .: "Latency" - download <- o .: "Download" - upload <- o .: "Upload" - serverPort <- o .: "ServerPort" - bmSshPort <- o .: "BareMetalSSHPort" - nat <- o .: "NAT" - mEscImpl <- o .: "EscapeImplementation" - custInfo <- o .: "CustomInformation" - - - pure $ - MkServerInfo - { name = name - , ip = getIPAddress ip4str ip6str - , latency = latency - , download = download - , upload = upload - , serverPort = getPortUNSAFE serverPort - , bareMetalSSHPort = getBMShhPort bmSshPort - , nat = getNat nat - , escapeImplementation = mEscImpl - , customInformation = custInfo -- TODO: deal with null value - } - - where - - getNat :: String -> Bool -- TODO: Change it to normal JSON - getNat ('T':_) = True - getNat _ = False - - getBMShhPort :: String -> Maybe Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! - getBMShhPort [] = Nothing - getBMShhPort bmSshPort = Just $ getPortUNSAFE bmSshPort - - getPortUNSAFE :: String -> Int -- TODO: Dangerous partial function call !!!!!!!!!!!!!!!!!!! - getPortUNSAFE = read - - getIPAddress :: String -> String -> IPAddress - getIPAddress [] ip6 = MkIPv6 ip6 - getIPAddress ip4 _ = MkIPv4 ip4 - - --- Module Error - -data Error - = MkUnknownError String - | MkErrorSpawningProcess String - | MkSystemError Int String String - deriving Show - -type IOEitherError a = IO (Either Error a) - -assignError :: String -> Error -assignError = MkUnknownError --- --- TODO: add megaparsec to parse Error Messages --- --- TODO: add error when internet connection is off - - -- Module: CLI data StdInput @@ -521,47 +322,3 @@ getP2PrcCmd = do $ trimString pwdOut err -> pure err - - --- Module: Environment - -cleanEnvironment :: IO () -cleanEnvironment = do - - mapM_ removeFileIfExists - [ "cert.pem" - , "config.json" - , "key.pem" - , "p2prc.privateKey" - , "p2prc.PublicKeyBareMetal" - ] - - mapM_ removeDirRIfExists - [ "client" - , "p2p" - , "plugin" - , "server" - ] - - where - - removeIfExists - :: (FilePath -> IO Bool) - -> (FilePath -> IO ()) - -> FilePath - -> IO () - removeIfExists doesItExists rmIt filePath = - do - res <- doesItExists filePath - when res $ rmIt filePath - - removeDirRIfExists = - removeIfExists - doesDirectoryExist - removeDirectoryRecursive - - removeFileIfExists = - removeIfExists - doesFileExist - removeFile - diff --git a/haskell/p2prc.cabal b/haskell/p2prc.cabal index a095c37..d5b8f8a 100644 --- a/haskell/p2prc.cabal +++ b/haskell/p2prc.cabal @@ -86,4 +86,10 @@ library exposed-modules: P2Prc + other-modules: API + , CLI + , Environment + , JSON + , Error + default-language: GHC2021 From b6926e0998a78133bc3fadf47b949b9b2215f583 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 9 Nov 2024 21:19:17 +0000 Subject: [PATCH 31/50] moving code to different files --- haskell/dev_run.sh | 3 + haskell/lib/CLI.hs | 134 +++++++++++++++++++++++++++++++++++++++- haskell/lib/Error.hs | 2 + haskell/lib/P2Prc.hs | 143 ++++++------------------------------------- haskell/src/Main.hs | 3 +- 5 files changed, 158 insertions(+), 127 deletions(-) create mode 100755 haskell/dev_run.sh diff --git a/haskell/dev_run.sh b/haskell/dev_run.sh new file mode 100755 index 0000000..44b89f7 --- /dev/null +++ b/haskell/dev_run.sh @@ -0,0 +1,3 @@ +# rm -rf *pem client/ plugin/ server/ p2p/ p2prc.[pP]* config.json dist-newstyle/ &&\ + cabal clean &&\ + cabal run diff --git a/haskell/lib/CLI.hs b/haskell/lib/CLI.hs index 7eb2699..1750df9 100644 --- a/haskell/lib/CLI.hs +++ b/haskell/lib/CLI.hs @@ -1,3 +1,135 @@ module CLI where -a=0 +import System.Process + ( readProcessWithExitCode + , proc + , createProcess + , terminateProcess + , ProcessHandle + ) + +import System.Exit ( ExitCode(ExitFailure) ) + +import Data.Aeson + +import Error + ( IOEitherError + , Error(..) + , assignError + ) + +import qualified Data.Text as T + +import qualified Data.ByteString.Lazy.Char8 as LBC8 + + + +data StdInput + = MkEmptyStdInput + | MkStdInputVal String + + +instance Show StdInput where + show MkEmptyStdInput = "" + show (MkStdInputVal v) = v + + +data CLIOpt + = MkEmptyOpts + | MkOptAtomic String + | MkOptTuple (String, String) + +type CLIOptsInput = [String] +type CLICmd = String + + +eitherExecProcessParser :: + FromJSON a => + CLICmd -> [CLIOpt] -> StdInput -> IOEitherError a +eitherExecProcessParser p2prcCmd opts stdInput = + do + val <- eitherExecProcess p2prcCmd opts stdInput + + pure $ case val of + (Right v) -> eitherErrDecode v + (Left e) -> Left e + + +eitherErrDecode :: + FromJSON a => + String -> Either Error a +eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack + + +eitherExecProcess :: CLICmd -> [CLIOpt] -> StdInput -> IOEitherError String +eitherExecProcess cmd opts input = + do + (code, out, err) <- + readProcessWithExitCode + cmd + (optsToCLI opts) + (show input) + + pure $ case code of + ExitFailure i -> Left $ MkSystemError i cmd err + _ -> Right out + + +optsToCLI :: [CLIOpt] -> CLIOptsInput +optsToCLI = concatMap _optToCLI + where + + _optToCLI :: CLIOpt -> CLIOptsInput + _optToCLI MkEmptyOpts = [] + _optToCLI (MkOptAtomic o) = [o] + _optToCLI (MkOptTuple (o, v)) = [o, v] + + +spawnProcP2Prc :: CLICmd -> [CLIOpt] -> IOEitherError ProcessHandle +spawnProcP2Prc cmd opts = + do + let prc = proc cmd $ optsToCLI opts + + creationResult <- createProcess prc + + let (_, _, _, ph) = creationResult + + case creationResult of + (_, _, Just _, _) -> do + + terminateProcess ph + + pure $ Left $ MkErrorSpawningProcess cmd + + _-> pure $ Right ph + + +eitherErrorDecode :: Either String a -> Either Error a +eitherErrorDecode esa = + case esa of + (Left s) -> Left $ assignError s + (Right v) -> Right v + + +getP2PrcCmd :: IOEitherError String +getP2PrcCmd = do + + -- assumes the program is ran inside the haskell module in p2prc's repo + -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" + + let trimString = T.unpack . T.strip . T.pack + + eitherErrPwd <- eitherExecProcess "pwd" [MkEmptyOpts] MkEmptyStdInput + + case eitherErrPwd of + + (Right pwdOut) -> + eitherExecProcess + "sed" + [ MkOptAtomic "s/haskell/p2p-rendering-computation/" ] + $ MkStdInputVal + $ trimString pwdOut + + err -> pure err + + diff --git a/haskell/lib/Error.hs b/haskell/lib/Error.hs index 1a5d6dd..92c1e21 100644 --- a/haskell/lib/Error.hs +++ b/haskell/lib/Error.hs @@ -15,3 +15,5 @@ assignError = MkUnknownError -- TODO: add megaparsec to parse Error Messages -- -- TODO: add error when internet connection is off +-- +-- MkSystemError 1 "/home/xecarlox/Desktop/p2p-rendering-computation/p2p-rendering-computation" "2024/11/09 21:08:06 Get \"http://0.0.0.0:8088/MAPPort?port=3333&domain_name=\": dial tcp 0.0.0.0:8088: connect: connection refused\n" diff --git a/haskell/lib/P2Prc.hs b/haskell/lib/P2Prc.hs index b090db5..5aa03f7 100644 --- a/haskell/lib/P2Prc.hs +++ b/haskell/lib/P2Prc.hs @@ -4,36 +4,32 @@ module P2Prc ( runP2Prc ) where -import System.Exit ( ExitCode(ExitFailure) ) - -import System.Process - ( readProcessWithExitCode - , proc - , createProcess - , terminateProcess - , ProcessHandle - ) +import System.Process ( ProcessHandle, terminateProcess ) import Control.Concurrent ( threadDelay ) -import qualified Data.Text as T - -import qualified Data.ByteString.Lazy.Char8 as LBC8 - import Data.Aeson -import Environment ( cleanEnvironment ) -import Error (IOEitherError, Error(..), assignError) +import Environment ( cleanEnvironment ) + +import Error (IOEitherError) + import JSON + ( IPAdressTable + , MapPortResponse + , P2prcConfig + ) + +import CLI -- URGENT TASKS -- --- TODO: setup the project as a haskell library +-- -- TODO: splitting code on different files and directories --- TODO: lock cabal index +-- -- TODO: add Haddock documentation -- -- TODO: P2PRC setup @@ -69,6 +65,11 @@ runP2Prc = do -- -- TODO: setup nix flake package -- TODO: add quickcheck testing (quickchecking-dynamic) + -- + -- Extra: + -- + -- TODO: Error + -- assign error: should parse other error @@ -213,112 +214,4 @@ getP2prcAPI = do --- Module: CLI -data StdInput - = MkEmptyStdInput - | MkStdInputVal String - - -instance Show StdInput where - show MkEmptyStdInput = "" - show (MkStdInputVal v) = v - - -data CLIOpt - = MkEmptyOpts - | MkOptAtomic String - | MkOptTuple (String, String) - -type CLIOptsInput = [String] -type CLICmd = String - - -eitherExecProcessParser :: - FromJSON a => - CLICmd -> [CLIOpt] -> StdInput -> IOEitherError a -eitherExecProcessParser p2prcCmd opts stdInput = - do - val <- eitherExecProcess p2prcCmd opts stdInput - - pure $ case val of - (Right v) -> eitherErrDecode v - (Left e) -> Left e - - -eitherErrDecode :: - FromJSON a => - String -> Either Error a -eitherErrDecode = eitherErrorDecode . eitherDecode . LBC8.pack - - -eitherExecProcess :: CLICmd -> [CLIOpt] -> StdInput -> IOEitherError String -eitherExecProcess cmd opts input = - do - (code, out, err) <- - readProcessWithExitCode - cmd - (optsToCLI opts) - (show input) - - pure $ case code of - ExitFailure i -> Left $ MkSystemError i cmd err - _ -> Right out - - -optsToCLI :: [CLIOpt] -> CLIOptsInput -optsToCLI = concatMap _optToCLI - where - - _optToCLI :: CLIOpt -> CLIOptsInput - _optToCLI MkEmptyOpts = [] - _optToCLI (MkOptAtomic o) = [o] - _optToCLI (MkOptTuple (o, v)) = [o, v] - - -spawnProcP2Prc :: CLICmd -> [CLIOpt] -> IOEitherError ProcessHandle -spawnProcP2Prc cmd opts = - do - let prc = proc cmd $ optsToCLI opts - - creationResult <- createProcess prc - - let (_, _, _, ph) = creationResult - - case creationResult of - (_, _, Just _, _) -> do - - terminateProcess ph - - pure $ Left $ MkErrorSpawningProcess cmd - - _-> pure $ Right ph - - -eitherErrorDecode :: Either String a -> Either Error a -eitherErrorDecode esa = - case esa of - (Left s) -> Left $ assignError s - (Right v) -> Right v - - -getP2PrcCmd :: IOEitherError String -getP2PrcCmd = do - - -- assumes the program is ran inside the haskell module in p2prc's repo - -- assumes that last path segment is "haskell" and that p2prc binary's name is "p2p-rendering-computation" - - let trimString = T.unpack . T.strip . T.pack - - eitherErrPwd <- eitherExecProcess "pwd" [MkEmptyOpts] MkEmptyStdInput - - case eitherErrPwd of - - (Right pwdOut) -> - eitherExecProcess - "sed" - [ MkOptAtomic "s/haskell/p2p-rendering-computation/" ] - $ MkStdInputVal - $ trimString pwdOut - - err -> pure err diff --git a/haskell/src/Main.hs b/haskell/src/Main.hs index a6764d8..33b16b7 100644 --- a/haskell/src/Main.hs +++ b/haskell/src/Main.hs @@ -1,9 +1,10 @@ + module Main where import P2Prc (runP2Prc) main :: IO () -main = do +main = runP2Prc From a9400d9079a10dbb4cd53ec10c93db8f38d5b48d Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 9 Nov 2024 21:28:31 +0000 Subject: [PATCH 32/50] moving API code --- haskell/lib/Error.hs | 1 + haskell/lib/P2Prc.hs | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/haskell/lib/Error.hs b/haskell/lib/Error.hs index 92c1e21..ad4fd9c 100644 --- a/haskell/lib/Error.hs +++ b/haskell/lib/Error.hs @@ -16,4 +16,5 @@ assignError = MkUnknownError -- -- TODO: add error when internet connection is off -- +-- Left (MkUnknownError "Unexpected end-of-input, expecting JSON value") -- MkSystemError 1 "/home/xecarlox/Desktop/p2p-rendering-computation/p2p-rendering-computation" "2024/11/09 21:08:06 Get \"http://0.0.0.0:8088/MAPPort?port=3333&domain_name=\": dial tcp 0.0.0.0:8088: connect: connection refused\n" diff --git a/haskell/lib/P2Prc.hs b/haskell/lib/P2Prc.hs index 5aa03f7..6ae52e8 100644 --- a/haskell/lib/P2Prc.hs +++ b/haskell/lib/P2Prc.hs @@ -1,15 +1,15 @@ {-# LANGUAGE OverloadedStrings #-} -module P2Prc ( runP2Prc ) - where +module P2Prc ( runP2Prc ) where - -import System.Process ( ProcessHandle, terminateProcess ) +import System.Process + ( ProcessHandle + , terminateProcess + ) import Control.Concurrent ( threadDelay ) - -import Data.Aeson +import Data.Aeson ( FromJSON ) import Environment ( cleanEnvironment ) @@ -23,6 +23,14 @@ import JSON ) import CLI + ( StdInput(..) + , CLIOpt(..) + , eitherErrDecode + , getP2PrcCmd + , eitherExecProcess + , eitherExecProcessParser + , spawnProcP2Prc + ) -- URGENT TASKS @@ -47,9 +55,6 @@ import CLI -- TODO: add use case examples (extra-source_files) - --- Module: API - runP2Prc :: IO () runP2Prc = do @@ -135,6 +140,7 @@ runP2Prc = do (Left err) -> print err +-- Module: API data P2prAPI = MkP2prAPI { startServer :: IOEitherError ProcessHandle From a11efa624da934162dc30d107fd248dac9d1933f Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sat, 9 Nov 2024 21:47:27 +0000 Subject: [PATCH 33/50] finished moving code into their respective library modules --- haskell/dev_run.sh | 2 +- haskell/lib/API.hs | 111 ++++++++++++++++++++++++++++++++++- haskell/lib/P2Prc.hs | 134 ++++++------------------------------------- 3 files changed, 129 insertions(+), 118 deletions(-) diff --git a/haskell/dev_run.sh b/haskell/dev_run.sh index 44b89f7..949f6cc 100755 --- a/haskell/dev_run.sh +++ b/haskell/dev_run.sh @@ -1,3 +1,3 @@ -# rm -rf *pem client/ plugin/ server/ p2p/ p2prc.[pP]* config.json dist-newstyle/ &&\ +rm -rf *pem client/ plugin/ server/ p2p/ p2prc.[pP]* config.json dist-newstyle/ &&\ cabal clean &&\ cabal run diff --git a/haskell/lib/API.hs b/haskell/lib/API.hs index 6c25ad1..2fec7cc 100644 --- a/haskell/lib/API.hs +++ b/haskell/lib/API.hs @@ -1,4 +1,111 @@ -module API where +module API + ( P2prAPI(..) + , MapPortRequest(..) + , getP2prcAPI + ) + where + +import System.Process ( ProcessHandle ) + +import Data.Aeson ( FromJSON ) + +import Error (IOEitherError) + +import JSON + ( IPAdressTable + , MapPortResponse + , P2prcConfig + ) + +import CLI + ( StdInput(..) + , CLIOpt(..) + , eitherErrDecode + , getP2PrcCmd + , eitherExecProcess + , eitherExecProcessParser + , spawnProcP2Prc + ) + +import Environment ( cleanEnvironment ) + + + +data P2prAPI = MkP2prAPI + { startServer :: IOEitherError ProcessHandle + , execInitConfig :: IOEitherError P2prcConfig + , execListServers :: IOEitherError IPAdressTable + , execMapPort :: MapPortRequest -> IOEitherError MapPortResponse + } + + +data MapPortRequest + = MkMapPortRequest Int String + + +getP2prcAPI :: IOEitherError P2prAPI +getP2prcAPI = do + + cleanEnvironment + + eitherP2prcCmd <- getP2PrcCmd + + pure $ case eitherP2prcCmd of + (Right p2prcCmd) -> let + + execProcP2PrcParser :: + FromJSON a => + [CLIOpt] -> StdInput -> IOEitherError a + execProcP2PrcParser = eitherExecProcessParser p2prcCmd + -- TODO: GHC question, why does it scope down instead staying generic + + execProcP2Prc = eitherExecProcess p2prcCmd + + in do + + Right $ MkP2prAPI + { startServer = spawnProcP2Prc p2prcCmd [ MkOptAtomic "--s" ] + + , execListServers = + execProcP2PrcParser [ MkOptAtomic "--ls" ] MkEmptyStdInput + + , execMapPort = + \ (MkMapPortRequest portNumber _) -> + execProcP2PrcParser + [ MkOptTuple + ( "--mp" + , show portNumber + ) + -- , MkOptTuple -- TODO: add domain parameter + -- ( "--dm" + -- , domainName + -- ) + ] + MkEmptyStdInput + + , execInitConfig = do + + confInitRes <- execProcP2Prc [ MkOptAtomic "--dc" ] MkEmptyStdInput + + case confInitRes of + (Right _) -> do + + -- TODO: get config file name dynamically + + -- TODO: change values before loading file + let fname = "/home/xecarlox/Desktop/p2p-rendering-computation/haskell/config.json" :: FilePath + + + -- TODO: read config check if file exists + configContent <- readFile fname + + pure $ eitherErrDecode configContent + + (Left err) -> pure $ Left err + + } + + (Left err) -> Left err + -a=0 diff --git a/haskell/lib/P2Prc.hs b/haskell/lib/P2Prc.hs index 6ae52e8..2970ff3 100644 --- a/haskell/lib/P2Prc.hs +++ b/haskell/lib/P2Prc.hs @@ -2,74 +2,59 @@ module P2Prc ( runP2Prc ) where -import System.Process - ( ProcessHandle - , terminateProcess - ) +import System.Process ( terminateProcess ) import Control.Concurrent ( threadDelay ) -import Data.Aeson ( FromJSON ) - - -import Environment ( cleanEnvironment ) - -import Error (IOEitherError) - -import JSON - ( IPAdressTable - , MapPortResponse - , P2prcConfig - ) - -import CLI - ( StdInput(..) - , CLIOpt(..) - , eitherErrDecode - , getP2PrcCmd - , eitherExecProcess - , eitherExecProcessParser - , spawnProcP2Prc +import API + ( P2prAPI(..) + , MapPortRequest(..) + , getP2prcAPI ) -- URGENT TASKS -- -- --- TODO: splitting code on different files and directories --- -- TODO: add Haddock documentation -- -- TODO: P2PRC setup - -- p2prc runtime packaging - -- Perhaps create internal script to run P2PRC from nix flake - -- "nix flake run ..." - -- simplify packaging -- check version P2PRC: only run if version if above a certain value -- setup p2prc command -- check if p2prc command is available in environment first -- otherwise check folder above -- +-- TODO: Fix API TODOS +-- +-- TODO: Fix JSON TODOS +-- +-- create DSL to start and orchestrate network +-- -- TODO: publish haskell library -- --- TODO: add use case examples (extra-source_files) runP2Prc :: IO () runP2Prc = do - -- important but not urgent yet -- -- TODO: Change Standard Library -- TODO: add GDTA syntax to data types -- TODO: need monad transformers to refactor the code -- + -- TODO: add quickcheck testing (quickchecking-dynamic) + -- -- TODO: parse IO arguments; -- TODO: create DSL from the standard input -- + -- TODO: add use case examples (extra-source_files) + -- -- TODO: setup nix flake package - -- TODO: add quickcheck testing (quickchecking-dynamic) + -- Nix p2prc runtime packaging + -- Perhaps create internal script to run P2PRC from nix flake + -- "nix flake run ..." + -- simplify packaging -- -- Extra: -- @@ -140,84 +125,3 @@ runP2Prc = do (Left err) -> print err --- Module: API - -data P2prAPI = MkP2prAPI - { startServer :: IOEitherError ProcessHandle - , execInitConfig :: IOEitherError P2prcConfig - , execListServers :: IOEitherError IPAdressTable - , execMapPort :: MapPortRequest -> IOEitherError MapPortResponse - } - - -data MapPortRequest - = MkMapPortRequest Int String - - -getP2prcAPI :: IOEitherError P2prAPI -getP2prcAPI = do - - cleanEnvironment - - eitherP2prcCmd <- getP2PrcCmd - - pure $ case eitherP2prcCmd of - (Right p2prcCmd) -> let - - execProcP2PrcParser :: - FromJSON a => - [CLIOpt] -> StdInput -> IOEitherError a - execProcP2PrcParser = eitherExecProcessParser p2prcCmd - -- TODO: GHC question, why does it scope down instead staying generic - - execProcP2Prc = eitherExecProcess p2prcCmd - - in do - - Right $ MkP2prAPI - { startServer = spawnProcP2Prc p2prcCmd [ MkOptAtomic "--s" ] - - , execListServers = - execProcP2PrcParser [ MkOptAtomic "--ls" ] MkEmptyStdInput - - , execMapPort = - \ (MkMapPortRequest portNumber _) -> - execProcP2PrcParser - [ MkOptTuple - ( "--mp" - , show portNumber - ) - -- , MkOptTuple -- TODO: add domain parameter - -- ( "--dm" - -- , domainName - -- ) - ] - MkEmptyStdInput - - , execInitConfig = do - - confInitRes <- execProcP2Prc [ MkOptAtomic "--dc" ] MkEmptyStdInput - - case confInitRes of - (Right _) -> do - - -- TODO: get config file name dynamically - - -- TODO: change values before loading file - let fname = "/home/xecarlox/Desktop/p2p-rendering-computation/haskell/config.json" :: FilePath - - - -- TODO: read config check if file exists - configContent <- readFile fname - - pure $ eitherErrDecode configContent - - (Left err) -> pure $ Left err - - } - - (Left err) -> Left err - - - - From c89e73eb3bb1b9188ae953ab9bf6066cb8b67cc6 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 10 Nov 2024 18:32:43 +0000 Subject: [PATCH 34/50] small housekeeping tasks --- haskell/README.md | 4 ++++ haskell/lib/API.hs | 18 +++++++++--------- haskell/lib/P2Prc.hs | 11 ++++++----- haskell/p2prc.cabal | 28 +++------------------------- haskell/src/Main.hs | 1 - 5 files changed, 22 insertions(+), 40 deletions(-) create mode 100644 haskell/README.md diff --git a/haskell/README.md b/haskell/README.md new file mode 100644 index 0000000..e8cb455 --- /dev/null +++ b/haskell/README.md @@ -0,0 +1,4 @@ + +# P2PRC Haskell library doc + + diff --git a/haskell/lib/API.hs b/haskell/lib/API.hs index 2fec7cc..361c519 100644 --- a/haskell/lib/API.hs +++ b/haskell/lib/API.hs @@ -1,6 +1,6 @@ module API - ( P2prAPI(..) + ( P2PRCapi(..) , MapPortRequest(..) , getP2prcAPI ) @@ -32,7 +32,7 @@ import Environment ( cleanEnvironment ) -data P2prAPI = MkP2prAPI +data P2PRCapi = MkP2PRCapi { startServer :: IOEitherError ProcessHandle , execInitConfig :: IOEitherError P2prcConfig , execListServers :: IOEitherError IPAdressTable @@ -44,7 +44,7 @@ data MapPortRequest = MkMapPortRequest Int String -getP2prcAPI :: IOEitherError P2prAPI +getP2prcAPI :: IOEitherError P2PRCapi getP2prcAPI = do cleanEnvironment @@ -64,23 +64,23 @@ getP2prcAPI = do in do - Right $ MkP2prAPI + Right $ MkP2PRCapi { startServer = spawnProcP2Prc p2prcCmd [ MkOptAtomic "--s" ] , execListServers = execProcP2PrcParser [ MkOptAtomic "--ls" ] MkEmptyStdInput , execMapPort = - \ (MkMapPortRequest portNumber _) -> + \ (MkMapPortRequest portNumber domainName) -> execProcP2PrcParser [ MkOptTuple ( "--mp" , show portNumber ) - -- , MkOptTuple -- TODO: add domain parameter - -- ( "--dm" - -- , domainName - -- ) + , MkOptTuple + ( "--dn" + , domainName + ) ] MkEmptyStdInput diff --git a/haskell/lib/P2Prc.hs b/haskell/lib/P2Prc.hs index 2970ff3..9b710f4 100644 --- a/haskell/lib/P2Prc.hs +++ b/haskell/lib/P2Prc.hs @@ -7,8 +7,8 @@ import System.Process ( terminateProcess ) import Control.Concurrent ( threadDelay ) import API - ( P2prAPI(..) - , MapPortRequest(..) + ( P2PRCapi(..) + , MapPortRequest(MkMapPortRequest) , getP2prcAPI ) @@ -37,13 +37,14 @@ import API runP2Prc :: IO () runP2Prc = do - + -- + -- TODO: add quickcheck testing (quickchecking-dynamic) -- -- TODO: Change Standard Library -- TODO: add GDTA syntax to data types + -- -- TODO: need monad transformers to refactor the code -- - -- TODO: add quickcheck testing (quickchecking-dynamic) -- -- TODO: parse IO arguments; -- TODO: create DSL from the standard input @@ -68,7 +69,7 @@ runP2Prc = do case eitherP2prcAPI of (Right p2prcAPI) -> do let - ( MkP2prAPI + ( MkP2PRCapi { startServer = startServer , execInitConfig = execInitConfig , execListServers = execListServers diff --git a/haskell/p2prc.cabal b/haskell/p2prc.cabal index d5b8f8a..db05be8 100644 --- a/haskell/p2prc.cabal +++ b/haskell/p2prc.cabal @@ -1,13 +1,7 @@ cabal-version: 3.0 - --- http://haskell.org/cabal/users-guide/ - --- The name of the package. name: p2prc - --- The package version. -- See the Haskell package versioning policy (PVP) for standards -- guiding when and how versions should be incremented. -- https://pvp.haskell.org @@ -16,59 +10,43 @@ name: p2prc -- | | | +--- code changes with no API change version: 0.1.0.0 --- A short (one-line) description of the package. synopsis: p2prc haskell library --- A longer description of the package. -description: Implements a client interface to the P2Prc networking runtime +description: Implements a client interface to the P2PRC networking runtime --- The license under which the package is released. license: GPL-3.0-only --- The file containing the license text. license-file: LICENSE --- The package author(s). author: xecarlox94 --- An email address to which users can send suggestions, bug reports, and patches. maintainer: jf94.uk@gmail.com --- A copyright notice. --- copyright: category: Network build-type: Simple --- Extra doc files to be distributed with the package, such as a CHANGELOG or a README. -extra-doc-files: CHANGELOG.md +extra-doc-files: README.md --- Extra source files to be distributed with the package, such as examples, or a tutorial module. --- extra-source-files: common warnings ghc-options: -Wall executable p2prc - -- Import common warning flags. + import: warnings - -- Directories containing source files. hs-source-dirs: src - -- .hs or .lhs file containing the Main module. main-is: Main.hs -- Modules included in this executable, other than Main. -- other-modules: Example - -- LANGUAGE extensions used by modules in this package. other-extensions: OverloadedStrings - -- Other library packages from which modules are imported. build-depends: base , p2prc - -- Base language which the package is written in. default-language: GHC2021 library diff --git a/haskell/src/Main.hs b/haskell/src/Main.hs index 33b16b7..55d6b1d 100644 --- a/haskell/src/Main.hs +++ b/haskell/src/Main.hs @@ -1,5 +1,4 @@ - module Main where import P2Prc (runP2Prc) From 2e1ca514864b86280c7bf1a1a39821babdcbf5a5 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 10 Nov 2024 18:54:39 +0000 Subject: [PATCH 35/50] refactored library interface --- haskell/lib/{P2Prc.hs => Engine.hs} | 13 +++++++++---- haskell/lib/P2PRC.hs | 9 +++++++++ haskell/p2prc.cabal | 30 ++++++++++++++--------------- haskell/src/Main.hs | 6 ++++-- 4 files changed, 36 insertions(+), 22 deletions(-) rename haskell/lib/{P2Prc.hs => Engine.hs} (93%) create mode 100644 haskell/lib/P2PRC.hs diff --git a/haskell/lib/P2Prc.hs b/haskell/lib/Engine.hs similarity index 93% rename from haskell/lib/P2Prc.hs rename to haskell/lib/Engine.hs index 9b710f4..ee0d232 100644 --- a/haskell/lib/P2Prc.hs +++ b/haskell/lib/Engine.hs @@ -1,9 +1,14 @@ {-# LANGUAGE OverloadedStrings #-} -module P2Prc ( runP2Prc ) where +module Engine + ( runP2PRC + ) + where + import System.Process ( terminateProcess ) + import Control.Concurrent ( threadDelay ) import API @@ -34,8 +39,8 @@ import API -- -runP2Prc :: IO () -runP2Prc = do +runP2PRC :: Int -> String -> IO () +runP2PRC portNumber domainName = do -- -- TODO: add quickcheck testing (quickchecking-dynamic) @@ -98,7 +103,7 @@ runP2Prc = do outputStr <- execListServers print outputStr - mapPortOut <- execMapPort $ MkMapPortRequest 3333 "domain" + mapPortOut <- execMapPort $ MkMapPortRequest portNumber domainName case mapPortOut of diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs new file mode 100644 index 0000000..a5aaad4 --- /dev/null +++ b/haskell/lib/P2PRC.hs @@ -0,0 +1,9 @@ +module P2PRC + ( runP2PRC + ) + where + + +import Engine + ( runP2PRC + ) diff --git a/haskell/p2prc.cabal b/haskell/p2prc.cabal index db05be8..1b0228c 100644 --- a/haskell/p2prc.cabal +++ b/haskell/p2prc.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 -name: p2prc +name: p2prc -- See the Haskell package versioning policy (PVP) for standards -- guiding when and how versions should be incremented. @@ -10,9 +10,9 @@ name: p2prc -- | | | +--- code changes with no API change version: 0.1.0.0 -synopsis: p2prc haskell library +synopsis: P2PRC haskell library -description: Implements a client interface to the P2PRC networking runtime +description: Implements a client interface to the P2PRC networking runtime license: GPL-3.0-only @@ -29,29 +29,26 @@ extra-doc-files: README.md common warnings - ghc-options: -Wall + ghc-options: -Wall executable p2prc - import: warnings + import: warnings - hs-source-dirs: src + hs-source-dirs: src - main-is: Main.hs + main-is: Main.hs - -- Modules included in this executable, other than Main. - -- other-modules: Example - - other-extensions: OverloadedStrings + other-extensions: OverloadedStrings build-depends: base , p2prc - default-language: GHC2021 + default-language: GHC2021 library - import: warnings + import: warnings build-depends: base , text @@ -60,14 +57,15 @@ library , bytestring , directory - hs-source-dirs: lib + hs-source-dirs: lib - exposed-modules: P2Prc + exposed-modules: P2PRC other-modules: API + , Engine , CLI , Environment , JSON , Error - default-language: GHC2021 + default-language: GHC2021 diff --git a/haskell/src/Main.hs b/haskell/src/Main.hs index 55d6b1d..fe3d37c 100644 --- a/haskell/src/Main.hs +++ b/haskell/src/Main.hs @@ -1,9 +1,11 @@ module Main where -import P2Prc (runP2Prc) +import P2PRC + ( runP2PRC + ) main :: IO () main = - runP2Prc + runP2PRC 3333 "jose.akilan.io" From 030eb6d022c00bc978d8d9f68de2780ad719bc5e Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 10 Nov 2024 19:23:23 +0000 Subject: [PATCH 36/50] tested example --- haskell/lib/Engine.hs | 20 +++++++++++++++++--- haskell/src/Main.hs | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/haskell/lib/Engine.hs b/haskell/lib/Engine.hs index ee0d232..51562a1 100644 --- a/haskell/lib/Engine.hs +++ b/haskell/lib/Engine.hs @@ -6,10 +6,14 @@ module Engine where +import Control.Concurrent +import Data.Char (toLower) +import System.IO +import Control.Monad (when) + import System.Process ( terminateProcess ) -import Control.Concurrent ( threadDelay ) import API ( P2PRCapi(..) @@ -105,7 +109,6 @@ runP2PRC portNumber domainName = do mapPortOut <- execMapPort $ MkMapPortRequest portNumber domainName - case mapPortOut of (Right v) -> print v (Left e) -> print e @@ -123,11 +126,22 @@ runP2PRC portNumber domainName = do -- - Use remote machine p2prc cmd to map a port using --mp -- - Return back the exposed public IP and port number back to stdout + exitOnQ $ terminateProcess startProcessHandle - terminateProcess startProcessHandle (Left err) -> print err (Left err) -> print err + where + + + exitOnQ :: IO () -> IO () + exitOnQ f = do + hSetBuffering stdin NoBuffering + c <- getChar + when (toLower c /= 'q') $ exitOnQ f + f + + diff --git a/haskell/src/Main.hs b/haskell/src/Main.hs index fe3d37c..cfe4a4c 100644 --- a/haskell/src/Main.hs +++ b/haskell/src/Main.hs @@ -8,4 +8,4 @@ import P2PRC main :: IO () main = - runP2PRC 3333 "jose.akilan.io" + runP2PRC 8080 "jose.akilan.io" From 1034a4c0b3a8e1aaa4d304035276ce0bdc7d9b20 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 10 Nov 2024 19:33:39 +0000 Subject: [PATCH 37/50] change module exports --- haskell/lib/Engine.hs | 17 +++++++---------- haskell/lib/P2PRC.hs | 5 +++++ haskell/src/Main.hs | 6 ++++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/haskell/lib/Engine.hs b/haskell/lib/Engine.hs index 51562a1..17f748f 100644 --- a/haskell/lib/Engine.hs +++ b/haskell/lib/Engine.hs @@ -43,8 +43,8 @@ import API -- -runP2PRC :: Int -> String -> IO () -runP2PRC portNumber domainName = do +runP2PRC :: MapPortRequest -> IO () +runP2PRC (MkMapPortRequest portNumber domainName) = do -- -- TODO: add quickcheck testing (quickchecking-dynamic) @@ -135,13 +135,10 @@ runP2PRC portNumber domainName = do where - exitOnQ :: IO () -> IO () - exitOnQ f = do - hSetBuffering stdin NoBuffering - c <- getChar - when (toLower c /= 'q') $ exitOnQ f - f - - + exitOnQ exitF = do + hSetBuffering stdin NoBuffering + c <- getChar + when (toLower c /= 'q') $ exitOnQ exitF + exitF diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs index a5aaad4..86b9207 100644 --- a/haskell/lib/P2PRC.hs +++ b/haskell/lib/P2PRC.hs @@ -1,5 +1,6 @@ module P2PRC ( runP2PRC + , MapPortRequest(MkMapPortRequest) ) where @@ -7,3 +8,7 @@ module P2PRC import Engine ( runP2PRC ) + +import API + ( MapPortRequest(MkMapPortRequest) + ) diff --git a/haskell/src/Main.hs b/haskell/src/Main.hs index cfe4a4c..3f691f8 100644 --- a/haskell/src/Main.hs +++ b/haskell/src/Main.hs @@ -3,9 +3,11 @@ module Main where import P2PRC ( runP2PRC + , MapPortRequest(MkMapPortRequest) ) - main :: IO () main = - runP2PRC 8080 "jose.akilan.io" + runP2PRC + ( MkMapPortRequest 8080 "jose.akilan.io" + ) From 9265c616efabc6561274aae38a7819cca3d93210 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 10 Nov 2024 20:17:44 +0000 Subject: [PATCH 38/50] change module exports --- haskell/src/Main.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/haskell/src/Main.hs b/haskell/src/Main.hs index 3f691f8..97d8636 100644 --- a/haskell/src/Main.hs +++ b/haskell/src/Main.hs @@ -1,4 +1,3 @@ - module Main where import P2PRC From c3259e957bdc67eca2d4f0bf3dbb480247a190d6 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 10 Nov 2024 20:29:51 +0000 Subject: [PATCH 39/50] adding gitignore for haddocks --- haskell/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/haskell/.gitignore b/haskell/.gitignore index c7af4d1..07ead31 100644 --- a/haskell/.gitignore +++ b/haskell/.gitignore @@ -8,6 +8,7 @@ p2prc.PublicKeyBareMetal plugin server +haddocks/ key.pem cert.pem From ec2f16915304fef8c6e8dc3d41daa5262e553710 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Tue, 12 Nov 2024 17:41:16 +0000 Subject: [PATCH 40/50] refactoring main imports --- haskell/dev_run.sh | 4 ++-- haskell/lib/P2PRC.hs | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/haskell/dev_run.sh b/haskell/dev_run.sh index 949f6cc..869ecc4 100755 --- a/haskell/dev_run.sh +++ b/haskell/dev_run.sh @@ -1,3 +1,3 @@ rm -rf *pem client/ plugin/ server/ p2p/ p2prc.[pP]* config.json dist-newstyle/ &&\ - cabal clean &&\ - cabal run + cabal clean #&&\ + # cabal run diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs index 86b9207..619eae6 100644 --- a/haskell/lib/P2PRC.hs +++ b/haskell/lib/P2PRC.hs @@ -1,6 +1,7 @@ + module P2PRC ( runP2PRC - , MapPortRequest(MkMapPortRequest) + , MapPortRequest(..) ) where @@ -9,6 +10,7 @@ import Engine ( runP2PRC ) + import API ( MapPortRequest(MkMapPortRequest) ) From c5ce6de385e0113149a0e643d5090d87dc3ad354 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Wed, 13 Nov 2024 20:07:00 +0000 Subject: [PATCH 41/50] working on documentation --- haskell/README.md | 93 ++++++++++++++++++++++++++++++++++++++++++- haskell/dev_run.sh | 4 +- haskell/lib/Engine.hs | 2 +- haskell/lib/P2PRC.hs | 33 +++++++++++++++ 4 files changed, 128 insertions(+), 4 deletions(-) diff --git a/haskell/README.md b/haskell/README.md index e8cb455..70eb919 100644 --- a/haskell/README.md +++ b/haskell/README.md @@ -1,4 +1,95 @@ +::: {#package-header} +[p2prc-0.1.0.0: P2PRC haskell library]{.caption} -# P2PRC Haskell library doc +- [Contents](index.html) +- [Index](doc-index.html) +::: +::: {#content} +::: {#module-header} + -------------- ----------------------------------------- + Copyright Copyright (C) 2006-2024 John MacFarlane + License GNU GPL, version 2 or above + Maintainer John MacFarlane \ + Stability alpha + Portability portable + Safe Haskell Safe-Inferred + Language GHC2021 + -------------- ----------------------------------------- +P2PRC +::: + +::: {#description} +Description + +::: doc +This helper module exports the main writers, readers, and data structure +definitions from the Pandoc libraries. + +A typical application will chain together a reader and a writer to +convert strings from one format to another. For example, the following +simple program will act as a filter converting markdown fragments to +reStructuredText, using reference-style links instead of inline links: + + module Main where + import Text.Pandoc + import Data.Text (Text) + import qualified Data.Text.IO as T + + mdToRST :: Text -> IO Text + mdToRST txt = runIOorExplode $ + readMarkdown def txt + >>= writeRST def{ writerReferenceLinks = True } + + main :: IO () + main = do + T.getContents >>= mdToRST >>= T.putStrLn +::: +::: + +::: {#synopsis} +Synopsis + +- [runP2PRC](#v:runP2PRC) :: + [MapPortRequest](P2PRC.html#t:MapPortRequest "P2PRC") -\> + [IO]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/System-IO.html#t:IO "System.IO") + () +- [data]{.keyword} [MapPortRequest](#t:MapPortRequest) = + [MkMapPortRequest](#v:MkMapPortRequest) + [Int]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-Int.html#t:Int "Data.Int") + [String]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-String.html#t:String "Data.String") +::: + +::: {#interface} +# Documentation + +::: top +[runP2PRC]{#v:runP2PRC .def} :: +[MapPortRequest](P2PRC.html#t:MapPortRequest "P2PRC") -\> +[IO]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/System-IO.html#t:IO "System.IO") +() [\#](#v:runP2PRC){.selflink} + +::: doc +Hello World +::: +::: + +::: top +[data]{.keyword} [MapPortRequest]{#t:MapPortRequest .def} +[\#](#t:MapPortRequest){.selflink} + +::: {.subs .constructors} +Constructors + + -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --- + [MkMapPortRequest]{#v:MkMapPortRequest .def} [Int]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-Int.html#t:Int "Data.Int") [String]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-String.html#t:String "Data.String")   + -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --- +::: +::: +::: +::: + +::: {#footer} +Produced by [Haddock](http://www.haskell.org/haddock/) version 2.29.2 +::: diff --git a/haskell/dev_run.sh b/haskell/dev_run.sh index 869ecc4..949f6cc 100755 --- a/haskell/dev_run.sh +++ b/haskell/dev_run.sh @@ -1,3 +1,3 @@ rm -rf *pem client/ plugin/ server/ p2p/ p2prc.[pP]* config.json dist-newstyle/ &&\ - cabal clean #&&\ - # cabal run + cabal clean &&\ + cabal run diff --git a/haskell/lib/Engine.hs b/haskell/lib/Engine.hs index 17f748f..51dad78 100644 --- a/haskell/lib/Engine.hs +++ b/haskell/lib/Engine.hs @@ -42,7 +42,7 @@ import API -- TODO: publish haskell library -- - +-- | Hello World runP2PRC :: MapPortRequest -> IO () runP2PRC (MkMapPortRequest portNumber domainName) = do diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs index 619eae6..b98db68 100644 --- a/haskell/lib/P2PRC.hs +++ b/haskell/lib/P2PRC.hs @@ -1,3 +1,36 @@ +{- | + Module : Text.Pandoc + Copyright : Copyright (C) 2006-2024 John MacFarlane + License : GNU GPL, version 2 or above + + Maintainer : John MacFarlane + Stability : alpha + Portability : portable + +This helper module exports the main writers, readers, and data +structure definitions from the Pandoc libraries. + +A typical application will chain together a reader and a writer +to convert strings from one format to another. For example, the +following simple program will act as a filter converting markdown +fragments to reStructuredText, using reference-style links instead of +inline links: + +> module Main where +> import Text.Pandoc +> import Data.Text (Text) +> import qualified Data.Text.IO as T +> +> mdToRST :: Text -> IO Text +> mdToRST txt = runIOorExplode $ +> readMarkdown def txt +> >>= writeRST def{ writerReferenceLinks = True } +> +> main :: IO () +> main = do +> T.getContents >>= mdToRST >>= T.putStrLn + +-} module P2PRC ( runP2PRC From a9ec5332b4dd90471cdd6666ce348a2142de0535 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Wed, 13 Nov 2024 20:09:03 +0000 Subject: [PATCH 42/50] working on documentation --- haskell/README.md | 127 +++++++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 51 deletions(-) diff --git a/haskell/README.md b/haskell/README.md index 70eb919..a5c96dd 100644 --- a/haskell/README.md +++ b/haskell/README.md @@ -1,29 +1,36 @@ -::: {#package-header} -[p2prc-0.1.0.0: P2PRC haskell library]{.caption} +
-- [Contents](index.html) -- [Index](doc-index.html) -::: +p2prc-0.1.0.0: P2PRC haskell library -::: {#content} -::: {#module-header} - -------------- ----------------------------------------- - Copyright Copyright (C) 2006-2024 John MacFarlane - License GNU GPL, version 2 or above - Maintainer John MacFarlane \ - Stability alpha - Portability portable - Safe Haskell Safe-Inferred - Language GHC2021 - -------------- ----------------------------------------- +- [Contents](index.html) +- [Index](doc-index.html) + +
+ +
+ +
+ +| | | +|--------------|-----------------------------------------| +| Copyright | Copyright (C) 2006-2024 John MacFarlane | +| License | GNU GPL, version 2 or above | +| Maintainer | John MacFarlane \ | +| Stability | alpha | +| Portability | portable | +| Safe Haskell | Safe-Inferred | +| Language | GHC2021 | P2PRC -::: -::: {#description} +
+ +
+ Description -::: doc +
+ This helper module exports the main writers, readers, and data structure definitions from the Pandoc libraries. @@ -45,51 +52,69 @@ reStructuredText, using reference-style links instead of inline links: main :: IO () main = do T.getContents >>= mdToRST >>= T.putStrLn -::: -::: -::: {#synopsis} +
+ +
+ +
+ Synopsis -- [runP2PRC](#v:runP2PRC) :: - [MapPortRequest](P2PRC.html#t:MapPortRequest "P2PRC") -\> - [IO]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/System-IO.html#t:IO "System.IO") - () -- [data]{.keyword} [MapPortRequest](#t:MapPortRequest) = - [MkMapPortRequest](#v:MkMapPortRequest) - [Int]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-Int.html#t:Int "Data.Int") - [String]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-String.html#t:String "Data.String") -::: +- [runP2PRC](#v:runP2PRC) :: + [MapPortRequest](P2PRC.html#t:MapPortRequest "P2PRC") -\> + [IO]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/System-IO.html#t:IO "System.IO") + () +- data [MapPortRequest](#t:MapPortRequest) + = [MkMapPortRequest](#v:MkMapPortRequest) + [Int]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-Int.html#t:Int "Data.Int") + [String]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-String.html#t:String "Data.String") + +
+ +
-::: {#interface} # Documentation -::: top -[runP2PRC]{#v:runP2PRC .def} :: +
+ +runP2PRC :: [MapPortRequest](P2PRC.html#t:MapPortRequest "P2PRC") -\> [IO]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/System-IO.html#t:IO "System.IO") -() [\#](#v:runP2PRC){.selflink} +() # + +
-::: doc Hello World -::: -::: -::: top -[data]{.keyword} [MapPortRequest]{#t:MapPortRequest .def} -[\#](#t:MapPortRequest){.selflink} +
+ +
+ +
+ +data MapPortRequest +# + +
-::: {.subs .constructors} Constructors - -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --- - [MkMapPortRequest]{#v:MkMapPortRequest .def} [Int]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-Int.html#t:Int "Data.Int") [String]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-String.html#t:String "Data.String")   - -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --- -::: -::: -::: -::: +| | | +|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----| +| MkMapPortRequest [Int]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-Int.html#t:Int "Data.Int") [String]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-String.html#t:String "Data.String") |   | + +
+ +
+ +
+ +
+ + From 55d1a5ec3f47487e1ce098f66118fe6296317cf1 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Wed, 13 Nov 2024 21:01:15 +0000 Subject: [PATCH 43/50] working on main page documentation --- haskell/LICENSE | 880 +++++++++++++------------------------------ haskell/lib/P2PRC.hs | 62 +-- 2 files changed, 312 insertions(+), 630 deletions(-) diff --git a/haskell/LICENSE b/haskell/LICENSE index 45644ff..9efa6fb 100644 --- a/haskell/LICENSE +++ b/haskell/LICENSE @@ -1,626 +1,285 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble + Preamble - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to this License. - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. - 13. Use with the GNU Affero General Public License. +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. - 14. Revised Versions of this License. +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. + NO WARRANTY - 15. Disclaimer of Warranty. + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. - 16. Limitation of Liability. + END OF TERMS AND CONDITIONS - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs + How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it @@ -628,15 +287,15 @@ free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least +convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) - This program is free software: you can redistribute it and/or modify + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or + the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -644,31 +303,36 @@ the "copyright" line and a pointer to where the full notice is found. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU General Public License along + with this program; if not, see . Also add information on how to contact you by electronic and paper mail. - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Moe Ghoul, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs index b98db68..f502f47 100644 --- a/haskell/lib/P2PRC.hs +++ b/haskell/lib/P2PRC.hs @@ -1,40 +1,48 @@ +{-# OPTIONS_HADDOCK show-extensions #-} + + {- | - Module : Text.Pandoc - Copyright : Copyright (C) 2006-2024 John MacFarlane + Module : P2PRC + Copyright : Copyright (C) 2024-2024 Jose Fernandes License : GNU GPL, version 2 or above - Maintainer : John MacFarlane - Stability : alpha + Maintainer : Jose Fernandes + Stability : beta Portability : portable -This helper module exports the main writers, readers, and data -structure definitions from the Pandoc libraries. +This helper module exports the main functions and data type definitions necessary to get started with the P2PRC api. -A typical application will chain together a reader and a writer -to convert strings from one format to another. For example, the -following simple program will act as a filter converting markdown -fragments to reStructuredText, using reference-style links instead of -inline links: +A minimal application will require the import of "runP2PRC" function that accepts a "MapPortRequest" value that exposes a specific port number and associates it with a domain name in the internet. + +This is a small template to get quickly get started with this interface. We assume the user has already an application listening on the tcp socket "8080". > module Main where -> import Text.Pandoc -> import Data.Text (Text) -> import qualified Data.Text.IO as T > -> mdToRST :: Text -> IO Text -> mdToRST txt = runIOorExplode $ -> readMarkdown def txt -> >>= writeRST def{ writerReferenceLinks = True } +> import P2PRC +> ( runP2PRC +> , MapPortRequest(MkMapPortRequest) +> ) +> +> > > main :: IO () -> main = do -> T.getContents >>= mdToRST >>= T.putStrLn +> main = +> runP2PRC +> ( MkMapPortRequest 8080 "jose.akilan.io" +> ) -} + module P2PRC - ( runP2PRC - , MapPortRequest(..) + ( MapPortRequest(..) + , P2PRCapi + , IPAdressTable + , MapPortResponse + , P2prcConfig + , IOEitherError + , getP2prcAPI + , runP2PRC ) where @@ -43,7 +51,17 @@ import Engine ( runP2PRC ) +import JSON + ( IPAdressTable + , MapPortResponse + , P2prcConfig + ) import API ( MapPortRequest(MkMapPortRequest) + , P2PRCapi + , getP2prcAPI ) + + +import Error (IOEitherError) From 6d6c997df576b458d31d7d432f77f51c3efa9b85 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Wed, 13 Nov 2024 21:57:57 +0000 Subject: [PATCH 44/50] working on documentation --- haskell/lib/API.hs | 19 ++++++++++++++++--- haskell/lib/CLI.hs | 11 ++++++++--- haskell/lib/Environment.hs | 5 ++++- haskell/lib/Error.hs | 21 ++++++++++++++++----- haskell/lib/P2PRC.hs | 16 +++++++++++----- 5 files changed, 55 insertions(+), 17 deletions(-) diff --git a/haskell/lib/API.hs b/haskell/lib/API.hs index 361c519..444ab2f 100644 --- a/haskell/lib/API.hs +++ b/haskell/lib/API.hs @@ -10,7 +10,9 @@ import System.Process ( ProcessHandle ) import Data.Aeson ( FromJSON ) -import Error (IOEitherError) +import Error + ( IOEitherError + ) import JSON ( IPAdressTable @@ -40,8 +42,19 @@ data P2PRCapi = MkP2PRCapi } -data MapPortRequest - = MkMapPortRequest Int String +{- | + +__Example:__ + +@ +port = 'MkMapPortRequest' 8080 \"jose.akilan.io\" +@ + +-} +data MapPortRequest = + MkMapPortRequest + Int -- ^ TCP socket number + String -- ^ Network domain name getP2prcAPI :: IOEitherError P2PRCapi diff --git a/haskell/lib/CLI.hs b/haskell/lib/CLI.hs index 1750df9..fba2cf7 100644 --- a/haskell/lib/CLI.hs +++ b/haskell/lib/CLI.hs @@ -8,9 +8,9 @@ import System.Process , ProcessHandle ) -import System.Exit ( ExitCode(ExitFailure) ) - -import Data.Aeson +import System.Exit + ( ExitCode(ExitFailure) + ) import Error ( IOEitherError @@ -18,6 +18,11 @@ import Error , assignError ) +import Data.Aeson + ( FromJSON + , eitherDecode + ) + import qualified Data.Text as T import qualified Data.ByteString.Lazy.Char8 as LBC8 diff --git a/haskell/lib/Environment.hs b/haskell/lib/Environment.hs index 0eca44e..88edd1b 100644 --- a/haskell/lib/Environment.hs +++ b/haskell/lib/Environment.hs @@ -1,4 +1,7 @@ -module Environment ( cleanEnvironment ) where +module Environment + ( cleanEnvironment + ) + where import System.Directory diff --git a/haskell/lib/Error.hs b/haskell/lib/Error.hs index ad4fd9c..6cae2d3 100644 --- a/haskell/lib/Error.hs +++ b/haskell/lib/Error.hs @@ -1,13 +1,24 @@ -module Error where +module Error + ( Error(..) + , IOEitherError + , assignError + ) where +-- ^ Error type for the application data Error - = MkUnknownError String - | MkErrorSpawningProcess String - | MkSystemError Int String String + = MkUnknownError + String -- ^ error message + | MkErrorSpawningProcess + String -- ^ error message + | MkSystemError + Int -- ^ System error code + String -- ^ String1 + String -- ^ String2 deriving Show -type IOEitherError a = IO (Either Error a) +-- ^ Type synonym for an IO action with either returns an Error or a parsed value +type IOEitherError a = IO ( Either Error a) assignError :: String -> Error assignError = MkUnknownError diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs index f502f47..fc5096d 100644 --- a/haskell/lib/P2PRC.hs +++ b/haskell/lib/P2PRC.hs @@ -12,7 +12,7 @@ This helper module exports the main functions and data type definitions necessary to get started with the P2PRC api. -A minimal application will require the import of "runP2PRC" function that accepts a "MapPortRequest" value that exposes a specific port number and associates it with a domain name in the internet. +A minimal application will require the import of 'runP2PRC' function that accepts a 'MapPortRequest' value that exposes a specific port number and associates it with a domain name in the internet. This is a small template to get quickly get started with this interface. We assume the user has already an application listening on the tcp socket "8080". @@ -35,14 +35,15 @@ This is a small template to get quickly get started with this interface. We assu module P2PRC - ( MapPortRequest(..) + ( getP2prcAPI + , runP2PRC + , MapPortRequest(..) , P2PRCapi , IPAdressTable , MapPortResponse , P2prcConfig + , Error , IOEitherError - , getP2prcAPI - , runP2PRC ) where @@ -64,4 +65,9 @@ import API ) -import Error (IOEitherError) +import Error + ( Error + , IOEitherError + ) + + From 95620ba509c0fba169525612f80b019982d68c9d Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Thu, 21 Nov 2024 19:35:37 +0000 Subject: [PATCH 45/50] removing license --- haskell/LICENSE | 338 -------------------------------------------- haskell/p2prc.cabal | 4 - 2 files changed, 342 deletions(-) delete mode 100644 haskell/LICENSE diff --git a/haskell/LICENSE b/haskell/LICENSE deleted file mode 100644 index 9efa6fb..0000000 --- a/haskell/LICENSE +++ /dev/null @@ -1,338 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, see . - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Moe Ghoul, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/haskell/p2prc.cabal b/haskell/p2prc.cabal index 1b0228c..55af357 100644 --- a/haskell/p2prc.cabal +++ b/haskell/p2prc.cabal @@ -14,10 +14,6 @@ synopsis: P2PRC haskell library description: Implements a client interface to the P2PRC networking runtime -license: GPL-3.0-only - -license-file: LICENSE - author: xecarlox94 maintainer: jf94.uk@gmail.com From 5394e8a657b2d6398d701c74e544ade913536e66 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Thu, 21 Nov 2024 21:58:23 +0000 Subject: [PATCH 46/50] working on documentation; finished upper structure --- haskell/lib/JSON.hs | 1 + haskell/lib/P2PRC.hs | 35 ++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/haskell/lib/JSON.hs b/haskell/lib/JSON.hs index 134fc1e..3463792 100644 --- a/haskell/lib/JSON.hs +++ b/haskell/lib/JSON.hs @@ -39,6 +39,7 @@ instance FromJSON MapPortResponse where +-- | Host P2prc configuration newtype P2prcConfig = MkP2prConfig { machineName :: String -- , iPTable :: String -- File diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs index fc5096d..acf9d1c 100644 --- a/haskell/lib/P2PRC.hs +++ b/haskell/lib/P2PRC.hs @@ -5,12 +5,13 @@ Module : P2PRC Copyright : Copyright (C) 2024-2024 Jose Fernandes License : GNU GPL, version 2 or above - Maintainer : Jose Fernandes Stability : beta Portability : portable -This helper module exports the main functions and data type definitions necessary to get started with the P2PRC api. +This library provides an interface to the P2Prc runtime. + +This Module intends to export the main functions and data type definitions necessary to get started with the P2PRC api. A minimal application will require the import of 'runP2PRC' function that accepts a 'MapPortRequest' value that exposes a specific port number and associates it with a domain name in the internet. @@ -23,8 +24,6 @@ This is a small template to get quickly get started with this interface. We assu > , MapPortRequest(MkMapPortRequest) > ) > -> -> > main :: IO () > main = > runP2PRC @@ -35,14 +34,32 @@ This is a small template to get quickly get started with this interface. We assu module P2PRC - ( getP2prcAPI - , runP2PRC - , MapPortRequest(..) + ( + -- * Functions + {- | These are the available functions available to interact with the P2Prc environment, at a lower level of abstraction. + It is intended this way to give freedom to the developer to implement their own orchestration strategies. + -} + runP2PRC + , getP2prcAPI + + -- * Data Types + {- | This section describes and explains the library's type system, more specifically, the interfaces and primitive types. + -} + + -- ** Interface data types + -- | This section gives an overview on the runtime and host machine interfaces. , P2PRCapi - , IPAdressTable - , MapPortResponse , P2prcConfig + + -- ** Primitive data types + -- | These types represent the core data that is communicated between requests and the runtime. + , IPAdressTable + , MapPortRequest(..) + , MapPortResponse , Error + + -- ** Type Synonyms + -- | This section is reserved to some useful type synonyms that add significant ergonomics. , IOEitherError ) where From 0254bbbd43818098313b0e10612e9d1f6e3faab0 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 1 Dec 2024 17:40:11 +0000 Subject: [PATCH 47/50] improving documentation --- haskell/lib/API.hs | 32 ++++++++++++++++++++++++++++++++ haskell/lib/CLI.hs | 2 +- haskell/lib/Engine.hs | 30 +++++++++++++++++++++--------- haskell/lib/Error.hs | 25 +++++++++++++++---------- haskell/lib/JSON.hs | 23 +++++++++++++---------- haskell/lib/P2PRC.hs | 6 +++--- 6 files changed, 85 insertions(+), 33 deletions(-) diff --git a/haskell/lib/API.hs b/haskell/lib/API.hs index 444ab2f..f682cd7 100644 --- a/haskell/lib/API.hs +++ b/haskell/lib/API.hs @@ -34,6 +34,11 @@ import Environment ( cleanEnvironment ) +{- | + +Haskell API + +-} data P2PRCapi = MkP2PRCapi { startServer :: IOEitherError ProcessHandle , execInitConfig :: IOEitherError P2prcConfig @@ -57,6 +62,33 @@ data MapPortRequest = String -- ^ Network domain name +{-| + This function cleans the previous running state (ensuring a pure P2PRC runtime state) and builds up a conditional 'P2PRCapi' instance. + + __The following example show how this function can be used to expose the runtime functionalities:__ + + @ + example :: IOEitherError P2PRCapi + example = do + + eitherP2prcAPI <- getP2prcAPI + + case eitherP2prcAPI of + ( Right + ( MkP2PRCapi + { startServer = startServer + , execInitConfig = execInitConfig + , execListServers = execListServers + , execMapPort = execMapPort + } + )) -> do + + -- Your code logic + + errValue -> errValue + @ +-} +{-# WARNING getP2prcAPI "This function is currently unstable since it assumes that the Haskell program is executed from the P2PRC \"haskell\" subfolder and the \"p2prc\" executable in the the root folder." #-} getP2prcAPI :: IOEitherError P2PRCapi getP2prcAPI = do diff --git a/haskell/lib/CLI.hs b/haskell/lib/CLI.hs index fba2cf7..6a1afc2 100644 --- a/haskell/lib/CLI.hs +++ b/haskell/lib/CLI.hs @@ -76,7 +76,7 @@ eitherExecProcess cmd opts input = (show input) pure $ case code of - ExitFailure i -> Left $ MkSystemError i cmd err + ExitFailure i -> Left $ MkCLISystemError i cmd err _ -> Right out diff --git a/haskell/lib/Engine.hs b/haskell/lib/Engine.hs index 51dad78..479fd37 100644 --- a/haskell/lib/Engine.hs +++ b/haskell/lib/Engine.hs @@ -42,7 +42,19 @@ import API -- TODO: publish haskell library -- --- | Hello World +{-| + This function starts and bootstraps the P2PRC runtime that associates the a specific host's machine port to a DNS address to expose a certain application to the P2PRC network. You will only need to also import the 'MkMapPortRequest' data constructor to represent the this port request. + + __This example demonstrates how it can be ran on the IO context:__ + + @ + example :: IO () + example = do + runP2PRC + ( MkMapPortRequest 8080 "jose.akilan.io" + ) + @ +-} runP2PRC :: MapPortRequest -> IO () runP2PRC (MkMapPortRequest portNumber domainName) = do @@ -76,15 +88,15 @@ runP2PRC (MkMapPortRequest portNumber domainName) = do eitherP2prcAPI <- getP2prcAPI case eitherP2prcAPI of - (Right p2prcAPI) -> do + (Right + ( MkP2PRCapi + { startServer = startServer + , execInitConfig = execInitConfig + , execListServers = execListServers + , execMapPort = execMapPort + } + )) -> do let - ( MkP2PRCapi - { startServer = startServer - , execInitConfig = execInitConfig - , execListServers = execListServers - , execMapPort = execMapPort - } - ) = p2prcAPI configValue <- execInitConfig diff --git a/haskell/lib/Error.hs b/haskell/lib/Error.hs index 6cae2d3..2857fab 100644 --- a/haskell/lib/Error.hs +++ b/haskell/lib/Error.hs @@ -5,19 +5,24 @@ module Error ) where --- ^ Error type for the application +{- | + Haskell-side Error value. This type is designed to parse and track System and P2PRC's error signals in a safe and effective manner. + + It does have an 'MkUnknownError' value which is meant to be warn about new kinds of error not yet accounted in this client. Github issues and pull requests are very welcome to improve error handling by parsing more types of errors. + +-} data Error - = MkUnknownError - String -- ^ error message - | MkErrorSpawningProcess - String -- ^ error message - | MkSystemError - Int -- ^ System error code - String -- ^ String1 - String -- ^ String2 + = MkCLISystemError -- ^ This is a CLI System Error + Int -- ^ System error code + String -- ^ Command name executed + String -- ^ Error output + | MkErrorSpawningProcess -- ^ Spawing process error + String -- ^ Spawning executable name + | MkUnknownError -- ^ This is an unparsed P2PRC's error + String -- ^ Unparsed error message deriving Show --- ^ Type synonym for an IO action with either returns an Error or a parsed value +-- | Type synonym for an IO action with either returns an Error or a parsed value type IOEitherError a = IO ( Either Error a) assignError :: String -> Error diff --git a/haskell/lib/JSON.hs b/haskell/lib/JSON.hs index 3463792..eecb00f 100644 --- a/haskell/lib/JSON.hs +++ b/haskell/lib/JSON.hs @@ -3,7 +3,7 @@ module JSON ( P2prcConfig , IPAdressTable - , MapPortResponse + , MapPortResponse(..) ) where @@ -15,13 +15,16 @@ import qualified Data.Text as T import Data.Aeson -newtype MapPortResponse - = MkMapPortResponse - { ipAddress :: String - -- , ipAddress :: IPAddress -- TODO: fix the api output - -- , port :: Int -- TODO: fix the api output +{-# WARNING MapPortResponse "This newtype is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015" #-} + +-- | This record type represents P2PRC's response to the TCP port and DNS address allocation. +data MapPortResponse + = MkMapPortResponse -- ^ Single data constructor + { ipAddress :: String -- ^ Column separated Host's IP address and Port } deriving Show + -- , ipAddress :: IPAddress -- TODO: fix the api output + -- , port :: Int -- TODO: fix the api output @@ -30,15 +33,13 @@ instance FromJSON MapPortResponse where ipAddress <- o .: "IPAddress" - pure $ - MkMapPortResponse - { ipAddress=ipAddress - } + pure $ MkMapPortResponse ipAddress parseJSON _ = mzero +{-# WARNING P2prcConfig "This type is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015" #-} -- | Host P2prc configuration newtype P2prcConfig = MkP2prConfig { machineName :: String @@ -106,6 +107,8 @@ instance FromJSON P2prcConfig where parseJSON _ = mzero +{-# WARNING IPAdressTable "This newtype is highly unstable due to undergoing work on improving P2PRC's server api. For more information, visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114" #-} + newtype IPAdressTable = MkIPAdressTable [ServerInfo] deriving Show diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs index acf9d1c..fc4253a 100644 --- a/haskell/lib/P2PRC.hs +++ b/haskell/lib/P2PRC.hs @@ -56,7 +56,7 @@ module P2PRC , IPAdressTable , MapPortRequest(..) , MapPortResponse - , Error + , Error(..) -- ** Type Synonyms -- | This section is reserved to some useful type synonyms that add significant ergonomics. @@ -71,7 +71,7 @@ import Engine import JSON ( IPAdressTable - , MapPortResponse + , MapPortResponse(..) , P2prcConfig ) @@ -83,7 +83,7 @@ import API import Error - ( Error + ( Error(..) , IOEitherError ) From bf24c304705665953ffbbdd7f7155119a33147b2 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 1 Dec 2024 18:16:38 +0000 Subject: [PATCH 48/50] improving documentation --- haskell/lib/API.hs | 18 +++++------------- haskell/lib/Engine.hs | 2 +- haskell/lib/JSON.hs | 13 +++++-------- haskell/lib/P2PRC.hs | 2 +- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/haskell/lib/API.hs b/haskell/lib/API.hs index f682cd7..d8136bb 100644 --- a/haskell/lib/API.hs +++ b/haskell/lib/API.hs @@ -16,7 +16,7 @@ import Error import JSON ( IPAdressTable - , MapPortResponse + , MapPortResponse(..) , P2prcConfig ) @@ -47,19 +47,11 @@ data P2PRCapi = MkP2PRCapi } -{- | - -__Example:__ - -@ -port = 'MkMapPortRequest' 8080 \"jose.akilan.io\" -@ - --} +-- | This type defines the request required to create an association between a TCP socket port and a DNS server in the network. If successful, it makes a resource available in the network. data MapPortRequest = - MkMapPortRequest - Int -- ^ TCP socket number - String -- ^ Network domain name + MkMapPortRequest -- ^ P2PRC's port allocation request value + Int -- ^ TCP socket number + String -- ^ Network domain name {-| diff --git a/haskell/lib/Engine.hs b/haskell/lib/Engine.hs index 479fd37..c7833cf 100644 --- a/haskell/lib/Engine.hs +++ b/haskell/lib/Engine.hs @@ -17,7 +17,7 @@ import System.Process ( terminateProcess ) import API ( P2PRCapi(..) - , MapPortRequest(MkMapPortRequest) + , MapPortRequest(..) , getP2prcAPI ) diff --git a/haskell/lib/JSON.hs b/haskell/lib/JSON.hs index eecb00f..9388d69 100644 --- a/haskell/lib/JSON.hs +++ b/haskell/lib/JSON.hs @@ -15,16 +15,13 @@ import qualified Data.Text as T import Data.Aeson -{-# WARNING MapPortResponse "This newtype is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015" #-} +-- {-# WARNING MapPortResponse "This newtype is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015" #-} --- | This record type represents P2PRC's response to the TCP port and DNS address allocation. -data MapPortResponse - = MkMapPortResponse -- ^ Single data constructor - { ipAddress :: String -- ^ Column separated Host's IP address and Port - } +-- ^ This newtype represents P2PRC's response to the TCP port and DNS address allocation. This value will confirm the successful allocation and return information about it. +newtype MapPortResponse + = MkMapPortResponse -- ^ Allocation information value + String -- ^ Column separated Host's IP address and Port String deriving Show - -- , ipAddress :: IPAddress -- TODO: fix the api output - -- , port :: Int -- TODO: fix the api output diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs index fc4253a..5010380 100644 --- a/haskell/lib/P2PRC.hs +++ b/haskell/lib/P2PRC.hs @@ -55,7 +55,7 @@ module P2PRC -- | These types represent the core data that is communicated between requests and the runtime. , IPAdressTable , MapPortRequest(..) - , MapPortResponse + , MapPortResponse(..) , Error(..) -- ** Type Synonyms From 2b170c7ea1dc15dd675f5fadf07c30d32fea2214 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Mon, 2 Dec 2024 00:35:48 +0000 Subject: [PATCH 49/50] improving documentation --- haskell/lib/API.hs | 23 +++++------ haskell/lib/Engine.hs | 4 +- haskell/lib/JSON.hs | 89 +++++++++++++++++++++++-------------------- haskell/lib/P2PRC.hs | 18 +++++---- 4 files changed, 71 insertions(+), 63 deletions(-) diff --git a/haskell/lib/API.hs b/haskell/lib/API.hs index d8136bb..f22e7b2 100644 --- a/haskell/lib/API.hs +++ b/haskell/lib/API.hs @@ -15,7 +15,7 @@ import Error ) import JSON - ( IPAdressTable + ( IPAdressTable(..) , MapPortResponse(..) , P2prcConfig ) @@ -33,21 +33,16 @@ import CLI import Environment ( cleanEnvironment ) - -{- | - -Haskell API - --} -data P2PRCapi = MkP2PRCapi - { startServer :: IOEitherError ProcessHandle - , execInitConfig :: IOEitherError P2prcConfig - , execListServers :: IOEitherError IPAdressTable - , execMapPort :: MapPortRequest -> IOEitherError MapPortResponse - } +data P2PRCapi -- ^ Haskell API + = MkP2PRCapi -- ^ Main Constructor + { startServer :: IOEitherError ProcessHandle -- ^ start server + , execInitConfig :: IOEitherError P2prcConfig + , execListServers :: IOEitherError IPAdressTable + , execMapPort :: MapPortRequest -> IOEitherError MapPortResponse + } --- | This type defines the request required to create an association between a TCP socket port and a DNS server in the network. If successful, it makes a resource available in the network. +-- | This defines the request required to create an association between a TCP socket port and a DNS server in the network. If successful, it makes a resource available in the network. data MapPortRequest = MkMapPortRequest -- ^ P2PRC's port allocation request value Int -- ^ TCP socket number diff --git a/haskell/lib/Engine.hs b/haskell/lib/Engine.hs index c7833cf..773516b 100644 --- a/haskell/lib/Engine.hs +++ b/haskell/lib/Engine.hs @@ -55,7 +55,9 @@ import API ) @ -} -runP2PRC :: MapPortRequest -> IO () +runP2PRC + :: MapPortRequest -- ^ TCP Port Request + -> IO () runP2PRC (MkMapPortRequest portNumber domainName) = do -- diff --git a/haskell/lib/JSON.hs b/haskell/lib/JSON.hs index 9388d69..89549e7 100644 --- a/haskell/lib/JSON.hs +++ b/haskell/lib/JSON.hs @@ -1,8 +1,10 @@ {-# LANGUAGE OverloadedStrings #-} module JSON - ( P2prcConfig - , IPAdressTable + ( P2prcConfig(..) + , IPAdressTable(..) + , IPAddress(..) + , ServerInfo(..) , MapPortResponse(..) ) where @@ -17,7 +19,7 @@ import Data.Aeson -- {-# WARNING MapPortResponse "This newtype is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015" #-} --- ^ This newtype represents P2PRC's response to the TCP port and DNS address allocation. This value will confirm the successful allocation and return information about it. +-- ^ This represents P2PRC's response to the TCP port and DNS address allocation. This value will confirm the successful allocation and return information about it. newtype MapPortResponse = MkMapPortResponse -- ^ Allocation information value String -- ^ Column separated Host's IP address and Port String @@ -37,31 +39,31 @@ instance FromJSON MapPortResponse where {-# WARNING P2prcConfig "This type is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015" #-} --- | Host P2prc configuration -newtype P2prcConfig = MkP2prConfig - { machineName :: String - -- , iPTable :: String -- File - -- , dockerContainers :: String -- Directory - -- , defaultDockerFile :: String -- Directory - -- , dockerRunLogs :: String -- Directory - -- , speedTestFile :: String -- File - -- , iPV6Address :: Maybe String - -- , pluginPath :: String -- Directory - -- , trackContainersPath :: String -- File - -- , hostServerPort :: Int - -- , proxyPort :: Maybe Int - -- , groupTrackContainersPath :: File - -- , fRPServerPort :: Bool - -- , behindNAT :: Bool - -- , iPTableKey :: String - -- , publicKeyFile :: String -- File - -- , privateKeyFile :: String -- File - -- , pemFile :: String -- File - -- , keyFile :: String -- File - -- , bareMetal :: Bool - -- , customConfig - } - deriving Show +newtype P2prcConfig -- ^ Host P2prc configuration + = MkP2prConfig -- ^ Unique Constructor + { machineName :: String -- ^ Machine Name + } + deriving Show + -- , iPTable :: String -- File + -- , dockerContainers :: String -- Directory + -- , defaultDockerFile :: String -- Directory + -- , dockerRunLogs :: String -- Directory + -- , speedTestFile :: String -- File + -- , iPV6Address :: Maybe String + -- , pluginPath :: String -- Directory + -- , trackContainersPath :: String -- File + -- , hostServerPort :: Int + -- , proxyPort :: Maybe Int + -- , groupTrackContainersPath :: File + -- , fRPServerPort :: Bool + -- , behindNAT :: Bool + -- , iPTableKey :: String + -- , publicKeyFile :: String -- File + -- , privateKeyFile :: String -- File + -- , pemFile :: String -- File + -- , keyFile :: String -- File + -- , bareMetal :: Bool + -- , customConfig -- TODO: p2prc API @@ -106,8 +108,11 @@ instance FromJSON P2prcConfig where {-# WARNING IPAdressTable "This newtype is highly unstable due to undergoing work on improving P2PRC's server api. For more information, visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114" #-} + +-- | IP Table newtype IPAdressTable - = MkIPAdressTable [ServerInfo] + = MkIPAdressTable -- ^ Constructor + [ServerInfo] -- ^ List Servers deriving Show @@ -117,18 +122,20 @@ instance FromJSON IPAdressTable where MkIPAdressTable <$> v .: "ip_address" -data ServerInfo = MkServerInfo - { name :: T.Text - , ip :: IPAddress - , latency :: Int - , download :: Int - , upload :: Int - , serverPort :: Int - , bareMetalSSHPort :: Maybe Int - , nat :: Bool - , escapeImplementation :: Maybe T.Text - , customInformation :: Maybe T.Text - } +{-# WARNING ServerInfo "This type is highly unstable due to undergoing work on improving P2PRC's server api. For more information, visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114" #-} +data ServerInfo = + MkServerInfo + { name :: T.Text + , ip :: IPAddress + , latency :: Int + , download :: Int + , upload :: Int + , serverPort :: Int + , bareMetalSSHPort :: Maybe Int + , nat :: Bool + , escapeImplementation :: Maybe T.Text + , customInformation :: Maybe T.Text + } deriving Show diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs index 5010380..c4bac51 100644 --- a/haskell/lib/P2PRC.hs +++ b/haskell/lib/P2PRC.hs @@ -48,12 +48,14 @@ module P2PRC -- ** Interface data types -- | This section gives an overview on the runtime and host machine interfaces. - , P2PRCapi - , P2prcConfig + , P2PRCapi(..) + , P2prcConfig(..) -- ** Primitive data types -- | These types represent the core data that is communicated between requests and the runtime. - , IPAdressTable + , IPAdressTable(..) + , ServerInfo(..) + , IPAddress(..) , MapPortRequest(..) , MapPortResponse(..) , Error(..) @@ -70,14 +72,16 @@ import Engine ) import JSON - ( IPAdressTable + ( IPAdressTable(..) + , ServerInfo(..) + , IPAddress(..) , MapPortResponse(..) - , P2prcConfig + , P2prcConfig(..) ) import API - ( MapPortRequest(MkMapPortRequest) - , P2PRCapi + ( MapPortRequest(..) + , P2PRCapi(..) , getP2prcAPI ) From 2ba8355fb182ed60589209e5350b339508fdaf82 Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Tue, 3 Dec 2024 00:33:28 +0000 Subject: [PATCH 50/50] finished first version of documentation --- Docs/haskell/P2PRC.html | 36 ++ Docs/haskell/P2PRC.md | 120 ++++ Docs/haskell/README.md | 120 ++++ Docs/haskell/doc-index.html | 1 + Docs/haskell/doc-index.md | 30 + Docs/haskell/haddock-bundle.min.js | 2 + Docs/haskell/index.html | 1 + Docs/haskell/index.md | 44 ++ Docs/haskell/linuwial.css | 881 +++++++++++++++++++++++++++++ Docs/haskell/meta.json | 1 + Docs/haskell/p2prc.haddock | Bin 0 -> 5515 bytes Docs/haskell/quick-jump.css | 221 ++++++++ Docs/haskell/synopsis.png | Bin 0 -> 11327 bytes haskell/gen_docs.sh | 9 + haskell/lib/API.hs | 20 +- haskell/lib/Engine.hs | 4 +- haskell/lib/JSON.hs | 77 +-- haskell/lib/P2PRC.hs | 8 +- 18 files changed, 1528 insertions(+), 47 deletions(-) create mode 100644 Docs/haskell/P2PRC.html create mode 100644 Docs/haskell/P2PRC.md create mode 100644 Docs/haskell/README.md create mode 100644 Docs/haskell/doc-index.html create mode 100644 Docs/haskell/doc-index.md create mode 100644 Docs/haskell/haddock-bundle.min.js create mode 100644 Docs/haskell/index.html create mode 100644 Docs/haskell/index.md create mode 100644 Docs/haskell/linuwial.css create mode 100644 Docs/haskell/meta.json create mode 100644 Docs/haskell/p2prc.haddock create mode 100644 Docs/haskell/quick-jump.css create mode 100644 Docs/haskell/synopsis.png create mode 100755 haskell/gen_docs.sh diff --git a/Docs/haskell/P2PRC.html b/Docs/haskell/P2PRC.html new file mode 100644 index 0000000..9c67729 --- /dev/null +++ b/Docs/haskell/P2PRC.html @@ -0,0 +1,36 @@ +P2PRC
p2prc-0.1.0.0: P2PRC haskell library
CopyrightCopyright (C) 2024-2024 Jose Fernandes
LicenseGNU GPL, version 2 or above
MaintainerJose Fernandes <jf94.uk@gmail.com>
Stabilitybeta
Portabilityportable
Safe HaskellSafe-Inferred
LanguageGHC2021

P2PRC

Description

This library provides an interface to the P2Prc runtime.

This Module intends to export the main functions and data type definitions necessary to get started with the P2PRC api.

A minimal application will require the import of runP2PRC function that accepts a MapPortRequest value that exposes a specific port number and associates it with a domain name in the internet.

This is a small template to get quickly get started with this interface. We assume the user has already an application listening on the tcp socket "8080".

module Main where
+
+import P2PRC
+  ( runP2PRC
+  , MapPortRequest(MkMapPortRequest)
+  )
+
+main :: IO ()
+main =
+  runP2PRC
+    ( MkMapPortRequest 8080 "jose.akilan.io"
+    )

Functions

These are the available functions available to interact with the P2Prc environment, at a lower level of abstraction. + It is intended this way to give freedom to the developer to implement their own orchestration strategies.

runP2PRC #

Arguments

:: MapPortRequest

TCP Port Request

-> IO () 

This function starts and bootstraps the P2PRC runtime that associates the a specific host's machine port to a DNS address to expose a certain application to the P2PRC network. You will only need to also import the MkMapPortRequest data constructor to represent the this port request.

Example

Expand

This example demonstrates how it can be ran on the IO context:

 example :: IO ()
+ example = do
+   runP2PRC
+     ( MkMapPortRequest 8080 "jose.akilan.io"
+     )
+ 

getP2prcAPI :: IOEitherError P2PRCapi #

Warning: This function is currently unstable since it assumes that the Haskell program is executed from the P2PRC "haskell" subfolder and the "p2prc" executable in the the root folder.

This function cleans the previous running state (ensuring a pure P2PRC runtime state) and builds up a conditional P2PRCapi instance.

Example

Expand

The following example show how this function can be used to expose the runtime functionalities:

 example :: IOEitherError P2PRCapi
+ example = do
+
+   eitherP2prcAPI <- getP2prcAPI
+
+   case eitherP2prcAPI of
+     ( Right
+       ( MkP2PRCapi
+         { startServer     = startServer
+         , execInitConfig  = execInitConfig
+         , execListServers = execListServers
+         , execMapPort     = execMapPort
+         }
+       )) -> do
+
+       -- Your code logic
+
+     errValue -> errValue
+ 

Data Types

This section describes and explains the library's type system, more specifically, the interfaces and primitive types.

Interface data types

This section gives an overview on the runtime and host machine interfaces.

data P2PRCapi #

Lower level P2PRC Haskell api that exposes basic functionality necessary to joint the network.

Constructors

MkP2PRCapi 

Fields

newtype P2prcConfig #

Warning: This type is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015

This represents the server configuration that defines its attributes and behaviours in the network, as well as, the location of the runtime persistence artifacts.

Constructors

MkP2prConfig 

Fields

Instances

Instances details
FromJSON P2prcConfig # 
Instance details

Defined in JSON

Show P2prcConfig # 
Instance details

Defined in JSON

data MapPortRequest #

This defines the request required to create an association between a TCP socket port and a DNS server in the network. If successful, it makes a resource available in the network.

Constructors

MkMapPortRequest

P2PRC's port allocation request value

Fields

  • Int

    TCP socket number

  • String

    Network domain name

newtype MapPortResponse #

Warning: This newtype is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015

This represents P2PRC's response to the TCP port and DNS address allocation. This value will confirm the successful allocation and return information about it.

Constructors

MkMapPortResponse

Allocation information value

Fields

  • String

    Column separated Host's IP address and Port String

Instances

Instances details
FromJSON MapPortResponse # 
Instance details

Defined in JSON

Show MapPortResponse # 
Instance details

Defined in JSON

Primitive data types

These types represent the core data that is communicated between requests and the runtime.

newtype IPAddressTable #

Warning: This newtype is highly unstable due to undergoing work on improving P2PRC's server api. For more information, visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114

This is a wrapper value that parses a json key value from the list of ip addresses in the network.

Constructors

MkIPAddressTable

Wrapping constructor

Fields

Instances

Instances details
FromJSON IPAddressTable # 
Instance details

Defined in JSON

Show IPAddressTable # 
Instance details

Defined in JSON

data ServerInfo #

Warning: This type is highly unstable due to undergoing work on improving P2PRC's server api. For more information, visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114

This is a record that keeps track of the current state of every node in the network. It is crucial information required for orchestration strategies.

Constructors

MkServerInfo 

Fields

Instances

Instances details
FromJSON ServerInfo # 
Instance details

Defined in JSON

Show ServerInfo # 
Instance details

Defined in JSON

data IPAddress #

This is a simple representation of the IP address of nodes in the network.

Constructors

MkIPv4 String

IP version 4 address

MkIPv6 String

IP version 6 address

Instances

Instances details
Show IPAddress # 
Instance details

Defined in JSON

data Error #

Haskell-side Error value. This type is designed to parse and track System and P2PRC's error signals in a safe and effective manner.

It does have an MkUnknownError value which is meant to be warn about new kinds of error not yet accounted in this client. Github issues and pull requests are very welcome to improve error handling by parsing more types of errors.

Constructors

MkCLISystemError

This is a CLI System Error

Fields

MkErrorSpawningProcess

Spawing process error

Fields

  • String

    Spawning executable name

MkUnknownError

This is an unparsed P2PRC's error

Fields

Instances

Instances details
Show Error # 
Instance details

Defined in Error

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

Type Synonyms

This section is reserved to some useful type synonyms that add significant ergonomics.

type IOEitherError a = IO (Either Error a) #

Type synonym for an IO action with either returns an Error or a parsed value

\ No newline at end of file diff --git a/Docs/haskell/P2PRC.md b/Docs/haskell/P2PRC.md new file mode 100644 index 0000000..a5c96dd --- /dev/null +++ b/Docs/haskell/P2PRC.md @@ -0,0 +1,120 @@ +
+ +p2prc-0.1.0.0: P2PRC haskell library + +- [Contents](index.html) +- [Index](doc-index.html) + +
+ +
+ +
+ +| | | +|--------------|-----------------------------------------| +| Copyright | Copyright (C) 2006-2024 John MacFarlane | +| License | GNU GPL, version 2 or above | +| Maintainer | John MacFarlane \ | +| Stability | alpha | +| Portability | portable | +| Safe Haskell | Safe-Inferred | +| Language | GHC2021 | + +P2PRC + +
+ +
+ +Description + +
+ +This helper module exports the main writers, readers, and data structure +definitions from the Pandoc libraries. + +A typical application will chain together a reader and a writer to +convert strings from one format to another. For example, the following +simple program will act as a filter converting markdown fragments to +reStructuredText, using reference-style links instead of inline links: + + module Main where + import Text.Pandoc + import Data.Text (Text) + import qualified Data.Text.IO as T + + mdToRST :: Text -> IO Text + mdToRST txt = runIOorExplode $ + readMarkdown def txt + >>= writeRST def{ writerReferenceLinks = True } + + main :: IO () + main = do + T.getContents >>= mdToRST >>= T.putStrLn + +
+ +
+ +
+ +Synopsis + +- [runP2PRC](#v:runP2PRC) :: + [MapPortRequest](P2PRC.html#t:MapPortRequest "P2PRC") -\> + [IO]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/System-IO.html#t:IO "System.IO") + () +- data [MapPortRequest](#t:MapPortRequest) + = [MkMapPortRequest](#v:MkMapPortRequest) + [Int]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-Int.html#t:Int "Data.Int") + [String]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-String.html#t:String "Data.String") + +
+ +
+ +# Documentation + +
+ +runP2PRC :: +[MapPortRequest](P2PRC.html#t:MapPortRequest "P2PRC") -\> +[IO]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/System-IO.html#t:IO "System.IO") +() # + +
+ +Hello World + +
+ +
+ +
+ +data MapPortRequest +# + +
+ +Constructors + +| | | +|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----| +| MkMapPortRequest [Int]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-Int.html#t:Int "Data.Int") [String]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-String.html#t:String "Data.String") |   | + +
+ +
+ +
+ +
+ + diff --git a/Docs/haskell/README.md b/Docs/haskell/README.md new file mode 100644 index 0000000..a5c96dd --- /dev/null +++ b/Docs/haskell/README.md @@ -0,0 +1,120 @@ +
+ +p2prc-0.1.0.0: P2PRC haskell library + +- [Contents](index.html) +- [Index](doc-index.html) + +
+ +
+ +
+ +| | | +|--------------|-----------------------------------------| +| Copyright | Copyright (C) 2006-2024 John MacFarlane | +| License | GNU GPL, version 2 or above | +| Maintainer | John MacFarlane \ | +| Stability | alpha | +| Portability | portable | +| Safe Haskell | Safe-Inferred | +| Language | GHC2021 | + +P2PRC + +
+ +
+ +Description + +
+ +This helper module exports the main writers, readers, and data structure +definitions from the Pandoc libraries. + +A typical application will chain together a reader and a writer to +convert strings from one format to another. For example, the following +simple program will act as a filter converting markdown fragments to +reStructuredText, using reference-style links instead of inline links: + + module Main where + import Text.Pandoc + import Data.Text (Text) + import qualified Data.Text.IO as T + + mdToRST :: Text -> IO Text + mdToRST txt = runIOorExplode $ + readMarkdown def txt + >>= writeRST def{ writerReferenceLinks = True } + + main :: IO () + main = do + T.getContents >>= mdToRST >>= T.putStrLn + +
+ +
+ +
+ +Synopsis + +- [runP2PRC](#v:runP2PRC) :: + [MapPortRequest](P2PRC.html#t:MapPortRequest "P2PRC") -\> + [IO]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/System-IO.html#t:IO "System.IO") + () +- data [MapPortRequest](#t:MapPortRequest) + = [MkMapPortRequest](#v:MkMapPortRequest) + [Int]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-Int.html#t:Int "Data.Int") + [String]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-String.html#t:String "Data.String") + +
+ +
+ +# Documentation + +
+ +runP2PRC :: +[MapPortRequest](P2PRC.html#t:MapPortRequest "P2PRC") -\> +[IO]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/System-IO.html#t:IO "System.IO") +() # + +
+ +Hello World + +
+ +
+ +
+ +data MapPortRequest +# + +
+ +Constructors + +| | | +|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----| +| MkMapPortRequest [Int]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-Int.html#t:Int "Data.Int") [String]($%7Bpkgroot%7D/../../../../dcnyq1a8qi8x59n5p53d0dx42cl8hf8x-ghc-9.6.5-doc/share/doc/ghc/html/libraries/base-4.18.2.1/Data-String.html#t:String "Data.String") |   | + +
+ +
+ +
+ +
+ + diff --git a/Docs/haskell/doc-index.html b/Docs/haskell/doc-index.html new file mode 100644 index 0000000..f5cfe01 --- /dev/null +++ b/Docs/haskell/doc-index.html @@ -0,0 +1 @@ +p2prc-0.1.0.0: P2PRC haskell library (Index)
p2prc-0.1.0.0: P2PRC haskell library

Index

bareMetalSSHPortP2PRC
customInformationP2PRC
downloadP2PRC
ErrorP2PRC
escapeImplementationP2PRC
execInitConfigP2PRC
execListServersP2PRC
execMapPortP2PRC
getP2prcAPIP2PRC
IOEitherErrorP2PRC
ipP2PRC
IPAddressP2PRC
IPAddressTableP2PRC
latencyP2PRC
machineNameP2PRC
MapPortRequestP2PRC
MapPortResponseP2PRC
MkCLISystemErrorP2PRC
MkErrorSpawningProcessP2PRC
MkIPAddressTableP2PRC
MkIPv4P2PRC
MkIPv6P2PRC
MkMapPortRequestP2PRC
MkMapPortResponseP2PRC
MkP2PRCapiP2PRC
MkP2prConfigP2PRC
MkServerInfoP2PRC
MkUnknownErrorP2PRC
nameP2PRC
natP2PRC
P2PRCapiP2PRC
P2prcConfigP2PRC
runP2PRCP2PRC
ServerInfoP2PRC
serverPortP2PRC
startServerP2PRC
uploadP2PRC
\ No newline at end of file diff --git a/Docs/haskell/doc-index.md b/Docs/haskell/doc-index.md new file mode 100644 index 0000000..11b10db --- /dev/null +++ b/Docs/haskell/doc-index.md @@ -0,0 +1,30 @@ +
+ +p2prc-0.1.0.0: P2PRC haskell library + +- [Contents](index.html) +- [Index](doc-index.html) + +
+ +
+ +
+ +Index + +| | | +|------------------|------------------------------------------------| +| MapPortRequest | [P2PRC](P2PRC.html#t:MapPortRequest "P2PRC") | +| MkMapPortRequest | [P2PRC](P2PRC.html#v:MkMapPortRequest "P2PRC") | +| runP2PRC | [P2PRC](P2PRC.html#v:runP2PRC "P2PRC") | + +
+ +
+ + diff --git a/Docs/haskell/haddock-bundle.min.js b/Docs/haskell/haddock-bundle.min.js new file mode 100644 index 0000000..4b2fa13 --- /dev/null +++ b/Docs/haskell/haddock-bundle.min.js @@ -0,0 +1,2 @@ +!function i(s,a,l){function c(t,e){if(!a[t]){if(!s[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(u)return u(t,!0);var o=new Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}var r=a[t]={exports:{}};s[t][0].call(r.exports,function(e){return c(s[t][1][e]||e)},r,r.exports,i,s,a,l)}return a[t].exports}for(var u="function"==typeof require&&require,e=0;e element with id '"+e+"'");return t}function x(){return u.defaultInstanceState==i.Open}function w(e){for(var t=S(e.target.id),n=t.element.open,o=0,r=t.toggles;owindow.innerHeight?this.searchResults.scrollTop+=e.bottom-window.innerHeight+80:e.topn)return u(e,this.pattern,o);var r=this.options,i=r.location,s=r.distance,a=r.threshold,l=r.findAllMatches,c=r.minMatchCharLength;return d(e,this.pattern,this.patternAlphabet,{location:i,distance:s,threshold:a,findAllMatches:l,minMatchCharLength:c})}}]),y}();e.exports=r},function(e,t,n){"use strict";var u=n(0);e.exports=function(e,t){return function e(t,n,o){if(n){var r=n.indexOf("."),i=n,s=null;-1!==r&&(i=n.slice(0,r),s=n.slice(r+1));var a=t[i];if(null!=a)if(s||"string"!=typeof a&&"number"!=typeof a)if(u(a))for(var l=0,c=a.length;l 0 and <= 1");p=p.name}else a[p]={weight:1};this._analyze({key:p,value:this.options.getFn(u,p),record:u,index:l},{resultMap:o,results:r,tokenSearchers:e,fullSearcher:t})}return{weights:a,results:r}}},{key:"_analyze",value:function(e,t){var n=e.key,o=e.arrayIndex,r=void 0===o?-1:o,i=e.value,s=e.record,a=e.index,l=t.tokenSearchers,c=void 0===l?[]:l,u=t.fullSearcher,d=void 0===u?[]:u,h=t.resultMap,p=void 0===h?{}:h,f=t.results,v=void 0===f?[]:f;if(null!=i){var g=!1,m=-1,y=0;if("string"==typeof i){this._log("\nKey: "+(""===n?"-":n));var _=d.search(i);if(this._log('Full text: "'+i+'", score: '+_.score),this.options.tokenize){for(var b=i.split(this.options.tokenSeparator),k=[],S=0;S=c.length;if(this._log("\nCheck Matches: "+T),(g||_.isMatch)&&T){var N=p[a];N?N.output.push({key:n,arrayIndex:r,value:i,score:A,matchedIndices:_.matchedIndices}):(p[a]={item:s,output:[{key:n,arrayIndex:r,value:i,score:A,matchedIndices:_.matchedIndices}]},v.push(p[a]))}}else if(V(i))for(var P=0,j=i.length;Pp2prc-0.1.0.0: P2PRC haskell library
p2prc-0.1.0.0: P2PRC haskell library

p2prc-0.1.0.0: P2PRC haskell library

Implements a client interface to the P2PRC networking runtime

Modules

p2prc-0.1.0.0

\ No newline at end of file diff --git a/Docs/haskell/index.md b/Docs/haskell/index.md new file mode 100644 index 0000000..5a74ed5 --- /dev/null +++ b/Docs/haskell/index.md @@ -0,0 +1,44 @@ +
+ +p2prc-0.1.0.0: P2PRC haskell library + +- [Contents](index.html) +- [Index](doc-index.html) + +
+ +
+ +
+ +# p2prc-0.1.0.0: P2PRC haskell library + +
+ +Implements a client interface to the P2PRC networking runtime + +
+ +
+ +
+ +Modules + +
+ +p2prc-0.1.0.0 + +-  [P2PRC](P2PRC.html) + +
+ +
+ +
+ + diff --git a/Docs/haskell/linuwial.css b/Docs/haskell/linuwial.css new file mode 100644 index 0000000..4164b84 --- /dev/null +++ b/Docs/haskell/linuwial.css @@ -0,0 +1,881 @@ +/* @group Fundamentals */ + +* { margin: 0; padding: 0 } + +/* Is this portable? */ +html { + background-color: white; + width: 100%; + height: 100%; +} + +body { + background: #fefefe; + color: #111; + text-align: left; + min-height: 100vh; + position: relative; + -webkit-text-size-adjust: 100%; + -webkit-font-feature-settings: "kern" 1, "liga" 0; + -moz-font-feature-settings: "kern" 1, "liga" 0; + -o-font-feature-settings: "kern" 1, "liga" 0; + font-feature-settings: "kern" 1, "liga" 0; + letter-spacing: 0.0015rem; +} + +#content a { + overflow-wrap: break-word; +} + +p { + margin: 0.8em 0; +} + +ul, ol { + margin: 0.8em 0 0.8em 2em; +} + +dl { + margin: 0.8em 0; +} + +dt { + font-weight: bold; +} +dd { + margin-left: 2em; +} + +a { text-decoration: none; } +a[href]:link { color: #9E358F; } +a[href]:visited {color: #6F5F9C; } +a[href]:hover { text-decoration:underline; } + +a[href].def:link, a[href].def:visited { color: rgba(69, 59, 97, 0.8); } +a[href].def:hover { color: rgb(78, 98, 114); } + +/* @end */ + +/* @group Show and hide with JS */ + +body.js-enabled .hide-when-js-enabled { + display: none; +} + +/* @end */ + + +/* @group responsive */ + +#package-header .caption { + margin: 0px 1em 0 2em; +} + +@media only screen and (min-width: 1280px) { + #content { + width: 63vw; + max-width: 1450px; + } + + #table-of-contents { + position: fixed; + max-width: 10vw; + top: 10.2em; + left: 2em; + bottom: 1em; + overflow-y: auto; + } + + #synopsis { + display: block; + position: fixed; + float: left; + top: 5em; + bottom: 1em; + right: 0; + max-width: 65vw; + overflow-y: auto; + /* Ensure that synopsis covers everything (including MathJAX markup) */ + z-index: 1; + } + + #synopsis .show { + border: 1px solid #5E5184; + padding: 0.7em; + max-height: 65vh; + } + +} + +@media only screen and (max-width: 1279px) { + #content { + width: 80vw; + } + + #synopsis { + display: block; + padding: 0; + position: relative; + margin: 0; + width: 100%; + } +} + +@media only screen and (max-width: 999px) { + #content { + width: 93vw; + } +} + + +/* menu for wider screens + + Display the package name at the left and the menu links at the right, + inline with each other: + The package name Source . Contents . Index +*/ +@media only screen and (min-width: 1000px) { + #package-header { + text-align: left; + white-space: nowrap; + height: 40px; + padding: 4px 1.5em 0px 1.5em; + overflow: visible; + + display: flex; + justify-content: space-between; + align-items: center; + } + + #package-header .caption { + display: inline-block; + margin: 0; + } + + #package-header ul.links { + margin: 0; + display: inline-table; + } + + #package-header .caption + ul.links { + margin-left: 1em; + } +} + +/* menu for smaller screens + +Display the package name on top of the menu links and center both elements: + The package name + Source . Contents . Index +*/ +@media only screen and (max-width: 999px) { + #package-header { + text-align: center; + padding: 6px 0 4px 0; + overflow: hidden; + } + + #package-header ul.links { + display: block; + text-align: center; + margin: 0; + + /* Hide scrollbar but allow scrolling menu links horizontally */ + white-space: nowrap; + overflow-x: auto; + overflow-y: hidden; + margin-bottom: -17px; + height: 50px; + } + + #package-header .caption { + display: block; + margin: 4px 0; + text-align: center; + } + + #package-header ul.links::-webkit-scrollbar { + display: none; + } + + #package-header ul.links li:first-of-type { + padding-left: 1em; + } + + #package-header ul.links li:last-of-type { + /* + The last link of the menu should offer the same distance to the right + as the #package-header enforces at the left. + */ + padding-right: 1em; + } + + #package-header .caption + ul.links { + padding-top: 9px; + } + + #module-header table.info { + float: none; + top: 0; + margin: 0 auto; + overflow: hidden; + max-width: 80vw; + } +} + +/* @end */ + + +/* @group Fonts & Sizes */ + +/* Basic technique & IE workarounds from YUI 3 + For reasons, see: + http://yui.yahooapis.com/3.1.1/build/cssfonts/fonts.css + */ + + body, button { + font: 400 14px/1.4 'PT Sans', + /* Fallback Font Stack */ + -apple-system, + BlinkMacSystemFont, + 'Segoe UI', + Roboto, + Oxygen-Sans, + Cantarell, + 'Helvetica Neue', + sans-serif; + *font-size: medium; /* for IE */ + *font:x-small; /* for IE in quirks mode */ + } + +h1 { font-size: 146.5%; /* 19pt */ } +h2 { font-size: 131%; /* 17pt */ } +h3 { font-size: 116%; /* 15pt */ } +h4 { font-size: 100%; /* 13pt */ } +h5 { font-size: 100%; /* 13pt */ } + +table { + font-size:inherit; + font:100%; +} + +pre, code, kbd, samp, tt, .src { + font-family:monospace; +} + +.links, .link { + font-size: 85%; /* 11pt */ +} + +#module-header .caption { + font-size: 182%; /* 24pt */ +} + +#module-header .caption sup { + font-size: 80%; + font-weight: normal; +} + +#package-header #page-menu a:link, #package-header #page-menu a:visited { color: white; } + + +.info { + font-size: 90%; +} + + +/* @end */ + +/* @group Common */ + +.caption, h1, h2, h3, h4, h5, h6, summary { + font-weight: bold; + color: #5E5184; + margin: 1.5em 0 1em 0; +} + + +* + h1, * + h2, * + h3, * + h4, * + h5, * + h6 { + margin-top: 2em; +} + +h1 + h2, h2 + h3, h3 + h4, h4 + h5, h5 + h6 { + margin-top: inherit; +} + +ul li + li { + margin-top: 0.2rem; +} + +ul + p { + margin-top: 0.93em; +} + +p + ul { + margin-top: 0.5em; +} + +p { + margin-top: 0.7rem; +} + +ul, ol { + margin: 0.8em 0 0.8em 2em; +} + +ul.links { + list-style: none; + text-align: left; + font-size: 0.95em; +} + +#package-header ul.links, #package-header ul.links button { + font-size: 1rem; +} + +ul.links li { + display: inline; + white-space: nowrap; + padding: 0; +} + +ul.links > li + li:before { + content: '\00B7'; +} + +ul.links li a { + padding: 0.2em 0.5em; +} + +.hide { display: none; } +.show { display: inherit; } +.clear { clear: both; } + +.collapser:before, .expander:before, .noexpander:before { + font-size: 1.2em; + color: #9C5791; + display: inline-block; + padding-right: 7px; +} + +.collapser:before { + content: '▿'; +} +.expander:before { + content: '▹'; +} +.noexpander:before { + content: '▿'; + visibility: hidden; +} + +.collapser, .expander { + cursor: pointer; +} + +.instance.collapser, .instance.expander { + margin-left: 0px; + background-position: left center; + min-width: 9px; + min-height: 9px; +} + +summary { + cursor: pointer; + outline: none; +} + +pre { + padding: 0.5rem 1rem; + margin: 1em 0 0 0; + background-color: #f7f7f7; + overflow: auto; + border: 1px solid #ddd; + border-radius: 0.3em; +} + +pre + p { + margin-top: 1em; +} + +pre + pre { + margin-top: 0.5em; +} + +blockquote { + border-left: 3px solid #c7a5d3; + background-color: #eee4f1; + margin: 0.5em; + padding: 0.0005em 0.3em 0.5em 0.5em; +} + +.src { + background: #f2f2f2; + padding: 0.2em 0.5em; +} + +.keyword { font-weight: normal; } +.def { font-weight: bold; } + +@media print { + #footer { display: none; } +} + +/* @end */ + +/* @group Page Structure */ + +#content { + margin: 3em auto 6em auto; + padding: 0; +} + +#package-header { + background: #5E5184; + border-bottom: 5px solid rgba(69, 59, 97, 0.5); + color: #ddd; + position: relative; + font-size: 1.2em; + text-align: left; + margin: 0 auto; +} + +#package-header .caption { + color: white; + font-style: normal; + font-size: 1rem; + font-weight: bold; +} + +#module-header .caption { + font-weight: bold; + border-bottom: 1px solid #ddd; +} + +table.info { + float: right; + padding: 0.5em 1em; + border: 1px solid #ddd; + color: rgb(78,98,114); + background-color: #fff; + max-width: 60%; + border-spacing: 0; + position: relative; + top: -0.78em; + margin: 0 0 0 2em; +} + +.info th { + padding: 0 1em 0 0; + text-align: right; +} + +#style-menu li { + display: block; + border-style: none; + list-style-type: none; +} + +#footer { + background: #ededed; + border-top: 1px solid #aaa; + padding: 0.5em 0; + color: #222; + text-align: center; + width: 100%; + height: 3em; + margin-top: 3em; + position: relative; + clear: both; +} + +/* @end */ + +/* @group Front Matter */ + +#synopsis .caption, +#contents-list .caption { + font-size: 1rem; +} + +#synopsis, #table-of-contents { + font-size: 16px; +} + +#contents-list { + background: #f4f4f4; + padding: 1em; + margin: 0; +} + +#contents-list .caption { + text-align: left; + margin: 0; +} + +#contents-list ul { + list-style: none; + margin: 0; + margin-top: 10px; + font-size: 14px; +} + +#contents-list ul ul { + margin-left: 1.5em; +} + +#description .caption { + display: none; +} + +#synopsis summary { + display: block; + float: right; + width: 29px; + color: rgba(255,255,255,0); + height: 110px; + margin: 0; + font-size: 1px; + padding: 0; + background: url(synopsis.png) no-repeat 0px -8px; +} + +#synopsis details[open] > summary { + background: url(synopsis.png) no-repeat -75px -8px; +} + +#synopsis details:not([open]) > ul { + visibility: hidden; +} + +#synopsis ul { + height: 100%; + overflow: auto; + padding: 0.5em; + margin: 0; +} + +#synopsis ul ul { + overflow: hidden; +} + +#synopsis ul, +#synopsis ul li.src { + background-color: rgb(250,247,224); + white-space: nowrap; + list-style: none; + margin-left: 0; +} + +#interface td.src { + white-space: nowrap; +} + +/* @end */ + +/* @group Main Content */ + +#interface div.top + div.top { + margin-top: 1.5em; +} + +#interface p + div.top, +#interface h1 + div.top, +#interface h2 + div.top, +#interface h3 + div.top, +#interface h4 + div.top, +#interface h5 + div.top { + margin-top: 1em; +} +#interface .src .selflink, +#interface .src .link { + float: right; + color: #888; + padding: 0 7px; + -moz-user-select: none; + font-weight: bold; + line-height: 30px; +} +#interface .src .selflink { + margin: 0 -0.5em 0 0.5em; +} + +#interface span.fixity { + color: #919191; + border-left: 1px solid #919191; + padding: 0.2em 0.5em 0.2em 0.5em; + margin: 0 -1em 0 1em; +} + +#interface span.rightedge { + border-left: 1px solid #919191; + padding: 0.2em 0 0.2em 0; + margin: 0 0 0 1em; +} + +#interface table { border-spacing: 2px; } +#interface td { + vertical-align: top; + padding-left: 0.5em; +} + +#interface td.doc p { + margin: 0; +} +#interface td.doc p + p { + margin-top: 0.8em; +} + +.doc table { + border-collapse: collapse; + border-spacing: 0px; +} + +.doc th, +.doc td { + padding: 5px; + border: 1px solid #ddd; +} + +.doc th { + background-color: #f0f0f0; +} + +.clearfix:after { + clear: both; + content: " "; + display: block; + height: 0; + visibility: hidden; +} + +.subs, .top > .doc, .subs > .doc { + padding-left: 1em; + border-left: 1px solid gainsboro; + margin-bottom: 1em; +} + +.top .subs { + margin-bottom: 0.6em; +} + +.subs.fields ul { + list-style: none; + display: table; + margin: 0; +} + +.subs.fields ul li { + display: table-row; +} + +.subs ul li dfn { + display: table-cell; + font-style: normal; + font-weight: bold; + margin: 1px 0; + white-space: nowrap; +} + +.subs ul li > .doc { + display: table-cell; + padding-left: 0.5em; + margin-bottom: 0.5em; +} + +.subs ul li > .doc p { + margin: 0; +} + +.subs .subs p.src { + border: none; + background-color: #f8f8f8; +} + +.subs .subs .caption { + margin-top: 1em ; + margin-bottom: 0px; +} + +.subs p.caption { + margin-top: 0; +} + +.subs .subs .caption + .src { + margin: 0px; + margin-top: 8px; +} + +.subs .subs .src + .src { + margin: 7px 0 0 0; +} + +/* Render short-style data instances */ +.inst ul { + height: 100%; + padding: 0.5em; + margin: 0; +} + +.inst, .inst li { + list-style: none; + margin-left: 1em; +} + +/* Workaround for bug in Firefox (issue #384) */ +.inst-left { + float: left; +} + +.top p.src { + border-bottom: 3px solid #e5e5e5; + line-height: 2rem; + margin-bottom: 1em; +} + +.warning { + color: red; +} + +.arguments { + margin-top: -0.4em; +} +.arguments .caption { + display: none; +} + +.fields { padding-left: 1em; } + +.fields .caption { display: none; } + +.fields p { margin: 0 0; } + +/* this seems bulky to me +.methods, .constructors { + background: #f8f8f8; + border: 1px solid #eee; +} +*/ + +/* @end */ + +/* @group Auxillary Pages */ + + +.extension-list { + list-style-type: none; + margin-left: 0; +} + +#mini { + margin: 0 auto; + padding: 0 1em 1em; +} + +#mini > * { + font-size: 93%; /* 12pt */ +} + +#mini #module-list .caption, +#mini #module-header .caption { + font-size: 125%; /* 15pt */ +} + +#mini #interface h1, +#mini #interface h2, +#mini #interface h3, +#mini #interface h4 { + font-size: 109%; /* 13pt */ + margin: 1em 0 0; +} + +#mini #interface .top, +#mini #interface .src { + margin: 0; +} + +#mini #module-list ul { + list-style: none; + margin: 0; +} + +#alphabet ul { + list-style: none; + padding: 0; + margin: 0.5em 0 0; + text-align: center; +} + +#alphabet li { + display: inline; + margin: 0 0.25em; +} + +#alphabet a { + font-weight: bold; +} + +#index .caption, +#module-list .caption { font-size: 131%; /* 17pt */ } + +#index table { + margin-left: 2em; +} + +#index .src { + font-weight: bold; +} +#index .alt { + font-size: 77%; /* 10pt */ + font-style: italic; + padding-left: 2em; +} + +#index td + td { + padding-left: 1em; +} + +#module-list ul { + list-style: none; + margin: 0 0 0 2em; +} + +#module-list li { + clear: right; +} + +#module-list span.collapser, +#module-list span.expander { + background-position: 0 0.3em; +} + +#module-list .package { + float: right; +} + +:target { + background: -webkit-linear-gradient(top, transparent 0%, transparent 65%, #fbf36d 60%, #fbf36d 100%); + background: -moz-linear-gradient(top, transparent 0%, transparent 65%, #fbf36d 60%, #fbf36d 100%); + background: -o-linear-gradient(top, transparent 0%, transparent 65%, #fbf36d 60%, #fbf36d 100%); + background: -ms-linear-gradient(top, transparent 0%, transparent 65%, #fbf36d 60%, #fbf36d 100%); + background: linear-gradient(to bottom, transparent 0%, transparent 65%, #fbf36d 60%, #fbf36d 100%); +} + +:target:hover { + background: -webkit-linear-gradient(top, transparent 0%, transparent 0%, #fbf36d 0%, #fbf36d 100%); + background: -moz-linear-gradient(top, transparent 0%, transparent 0%, #fbf36d 0%, #fbf36d 100%); + background: -o-linear-gradient(top, transparent 0%, transparent 0%, #fbf36d 0%, #fbf36d 100%); + background: -ms-linear-gradient(top, transparent 0%, transparent 0%, #fbf36d 0%, #fbf36d 100%); + background: linear-gradient(to bottom, transparent 0%, transparent 0%, #fbf36d 0%, #fbf36d 100%); +} + +/* @end */ + +/* @group Dropdown menus */ + +#preferences-menu, #style-menu { + width: 25em; + overflow-y: auto; +} + +/* @end */ diff --git a/Docs/haskell/meta.json b/Docs/haskell/meta.json new file mode 100644 index 0000000..4e0bb86 --- /dev/null +++ b/Docs/haskell/meta.json @@ -0,0 +1 @@ +{"haddock_version":"2.29.2"} \ No newline at end of file diff --git a/Docs/haskell/p2prc.haddock b/Docs/haskell/p2prc.haddock new file mode 100644 index 0000000000000000000000000000000000000000..af23673d7ed3ab9cfc543e39655cf8096876b8a0 GIT binary patch literal 5515 zcma)ATW{OQ6{bX)zR363&du3OoSVICX&tYVX453Cp}2__u_MGzi$2oiNMb~h>u zx(vDkx(d1mx(-?g-2iNMrpmEPxl`dOdbLlqv74j@EALZR5UV*fG|nDQ+lP5J3b9Whfrr zZga?e##!HuA};E7sl3=snICh>x-R-5J5IGy{%c7~%m&@S>yj9K?nWueaLU=h75MIH zoTV({1J(;7U$VHJuN}oH8}bw?^5QH?AvvT-X-i%h@F=abmrz)Cim%EH3)6OzEDWK* zU*SDPkKpW#iy<5E(2M(=mJRxeh#{fgUl)_YAnLHwp;8Jx_G3&Vtr=Nly zg%~btylxh{Q%7YRuGQnj9nj~noX2IZ(28NWHTq1%vM4{^bK1Ad0OANjOZg#b!M)fw zFtE$3jku4q@LA+yoBRX!GAL|J=vgHngQ}A(waNGPjgR0u0B&4=URJL zh^W`^V@qy_JEgK+vF>Se0O0?pIaDyXcz<*2^Dnk*^)GiG?0&WP@R6PdtN-*gvd`() zD-%Z6zgZ)t0h;{;k_w&(E&&Hu84}O~BVx@KbA2BJ>I@?&OJSIXBAyOn(W^V=vnyZ+ zP9$04UNLd<)8mhd@hLO@`;rk$a4#0HtFD`}9_I-RP?=aRn3utmzyKuVjxC=d`9(X65%t(yMj zqTeWN){HK`o)40!$Q=vX?6un}Yei(z^K)6YQohUb}k6PI;xrFx;AnNg9 zKG+ucFu^ViWJ>29Bn5yjLUPqCxAF^GgT(Q004Xq##$wHk|4~D3gnqybi%6|uOlb$5 zEJuWbqR-nnei#9{#S|Mog@eE&R0j>ZXF;5ak4F{<^-tK;5s z{WYC-Ve7fa$xlaK8|U0@#9`KtFa`v{$b9xHmMP+|F-Rq2i;PACbZzbOm6g>AXL4$~ zIx{;rzp%KpeCa9#B`=EXMg2aNlFSEF*UfhRq*Y%4gLIq+PW7+c3v}-ZPM!(@-IX$i zCsJL8cre#S$lX0tqXVr~)uWboMhLlR2}bLz^# zW9=+b>6se_=@5Z~@Z%z#fLh+i0i`ieS`klfnx$rsQ&>S^ji#S9VaiBMg^2 zSwTqaP#I>v&W2(6i*=BTtCXG}k5VO>L}+YArI)1OevFmJtmk&|wGvXee`^<4>>6nn zay9K(5M#+jNCt~nxq^;gn>>=4a+*j`Go(#gt%X}qOk3K?WI>4JE`#?YtMmhc5ky3m zc%wW6+atwzyk07;R4$b#4?egQ-R<(fAQMNJ!}+Rgit7O;yYYY#rIZjFk%3brmKmkW zI3<0Y>X-_d3RXH(1j#4W^0zkl)N<^}6XfIvDh=29lG+c@F*9O$hAekxhOstWBVr8v<1n$iT3=5dpHpN;nv zlNsBFc-(77LE2ERpBT^ge9TMe(%+Ri?^w^r%!h8G{EwD^KAiU$#@`f=TU)I5ywDL% zsMXjnVb(Zxq&Q*R2|T47C{T!>(`| z%I5&c^Eg+oqi~O~KjOf3DdAqwh8yW>kA5z>0XVgnEYehiRu~8uDQyTDKp5l^7vpB( z!sn1?ad$+di=&V{l!iTSZ0e#zF@q+-$kxjbneV2`_=;(P{7e81dyt$`MP~Z=l5G{{uE=)e z4Qo)5apZt|tFLzK@y_ENw(%amy6*N6E24T3Z)k3Ou5@QS#4Zws6n^vBbm#;MV!GFe zlc69}WSfmGw!5>tSEGh~gKx8+aS_3{a#_0m^5`9V*?PS_x+v_bd-*BulBJFF%+4sqt*nkmc?5lR z;rjo$aO^)qk-|nPrGi_URiT1Pg(@l)DycX&YAOyDRUE3SI5x^E4%Jm03xyTOLS@CV zP+D;;)K(k|#TCawb;YqzUU4kcR~!ok7RN$`#j#Ohaj3@P*eJ3%RAq52Mz6Q%6}C2M z-$nz~~wkq3iJpg*feast3_oAmXTx ztJ=f?RYGiB^()^Tzd5qu?45(CgKT>4T&!3;?14vL($$o;!=Cyt?$<3{2$(Ay!a+B>866we;^%u9v5TscT4^DEhupWnlrOkKNXq`CtT z-WN|%067HgLfoyW!;ai^g-g#(c$2~_ZBONMOP;y`(PH@(bABY&3BeVcJKs@N5lu%M z$VYGbrJB1rO7s^-R;zRQr7=6!J@X?DRkFb{=R2lGLD9s=>R3>mKOf~5=yfcRRmWmg zbu2tj6%J-m%C(L+xagn-$_*f literal 0 HcmV?d00001 diff --git a/Docs/haskell/quick-jump.css b/Docs/haskell/quick-jump.css new file mode 100644 index 0000000..cf10eee --- /dev/null +++ b/Docs/haskell/quick-jump.css @@ -0,0 +1,221 @@ +/* @group Fundamentals */ + +.hidden { + display: none; +} + +/* @end */ + +/* @group Search box layout */ + +#search { + position: fixed; + top: 3.2em; + bottom: 0; + left: calc(50% - 22em); + width: 44em; + z-index: 1000; + overflow-y: auto; +} + +@media only screen and (max-width: 999px) { + #search { + top: 5.7em; + } +} + +#search-form, #search-results { + box-shadow: 2px 2px 6px rgb(199, 204, 208); + pointer-events: all; +} + +#search-form input { + font-size: 1.25em; line-height: 2.3em; height: 2.4em; + display: block; + box-sizing: border-box; + width: 100%; + margin: 0; + padding: 0 0.75em; + border: 0.05em solid rgb(151, 179, 202); +} + +#search input:focus { + outline: none; +} + +#search p.error { + color: rgb(107, 24, 24); + font-weight: bold; +} + +#search-results { + box-sizing: border-box; + border: 0.05em solid #b2d5fb; + background: #e8f3ff; + max-height: 80%; + overflow: scroll; +} + +#search-form input + #search-results { + border-top: none; + top: 3em; + max-height: calc(100% - 3em); +} + +/* @end */ + +/* @group search results */ + +#search-results > ul { + margin: 0; + list-style: none; +} + +#search-results > ul > li, +#search-results > p, +#search-results > table { + padding: 0.5em 1em; + margin: 0; +} + +#search-results > ul > li { + border-bottom: 1px solid #b2d5fb; +} + +#search-results > ul > li > ul { + list-style: none; +} + +.search-module h4 { + margin: 0; +} + +.search-module > ul { + margin: 0.5em 0 0.5em 2em; +} + +.search-module > ul > li > a[href] { + display: block; + color: inherit; + padding: 0.25em 0.5em; +} + +.search-module > ul > li > a[href].active-link { + background: #faf9dc; +} + +.search-module a[href]:hover { + text-decoration: none; +} + +.search-result a a { + pointer-events: none; +} + +.search-result ul.subs { + display: inline-block; + margin: 0; padding: 0; +} + +.search-result ul.subs li { + display: none; +} + +.search-result ul.subs::after { + display: inline-block; + content: "..."; + color: rgb(78,98,114); + margin: 0 0.25em; +} + +.more-results { + color: rgb(99, 141, 173); + position: relative; +} + +.more-results::before { + content: "+"; + display: inline-block; + color: #b2d5fb; + font-weight: bold; + font-size: 1.25em; line-height: inherit; + position: absolute; + left: -1em; +} + +/* @end */ + +/* @group Keyboard shortcuts table */ + +.keyboard-shortcuts { + line-height: 1.6em; +} + +.keyboard-shortcuts th { + color: rgb(78,98,114); +} + +.keyboard-shortcuts td:first-child, +.keyboard-shortcuts th:first-child { + text-align: right; + padding-right: 0.6em; +} + +.key { + display: inline-block; + font-size: 0.9em; + min-width: 0.8em; line-height: 1.2em; + text-align: center; + background: #b2d5fb; + border: 1px solid #74a3d6; + padding: 0 0.2em; + margin: 0 0.1em; +} + +/* @end */ + +/* @group Dropdown menus */ + +/* Based on #search styling above. */ + +.dropdown-menu { + position: fixed; + /* Not robust to window size changes. */ + top: 3.2em; + right: 0; + /* To display on top of synopsis menu on right side. */ + z-index: 1000; + border: 0.05em solid #b2d5fb; + background: #e8f3ff; +} + +@media only screen and (max-width: 999px) { + .dropdown-menu { + top: 5.7em; + } +} + +.dropdown-menu * { + margin: 0.1em; +} + +.dropdown-menu button { + border: 1px #5E5184 solid; + border-radius: 3px; + background: #5E5184; + padding: 3px; + color: #f4f4f4; + min-width: 6em; +} + +.dropdown-menu button:hover { + color: #5E5184; + background: #f4f4f4; +} + +.dropdown-menu button:active { + color: #f4f4f4; + background: #5E5184; +} + +/* @end */ diff --git a/Docs/haskell/synopsis.png b/Docs/haskell/synopsis.png new file mode 100644 index 0000000000000000000000000000000000000000..85fb86ec84907bcc86531dc82871948ff4d471fa GIT binary patch literal 11327 zcmV-FEWp!=P)4Tx0C)k_S!GyNTeqHT_l8Y(cXyX`gGi?cY`Qxn1VID|MJXwjPC)?)F$h6K zMMOd+6hs7sqbPzXbr*U(-*=zy-hcPcUC*=TdiNM(jyd-lv&OpsU|J&v2m2!^0SE{T z54F(O;E2!K(!rTCW z%wV;vdzf1QjBf#e&~gh74F>?Z4a=WLg$KhJ^$5nap>PLbJadS>e&h8+?D`9%QNL`g zEVKbYGXj7k5Q(8)0Fd#*a?VIMFW3*64geVHKzE-&0BG!BtmfuTbO(T`0Jaeg2nagF z{V*1E{Wm{e|AvV~*MEExiC+KU-~R=!2{)|c6Bg`GjQ;iG|FQ`1kAUCTuZtQk34#8{ z4r4(3g7#|{=Z@d+d#}7f!3C=>=26vx*jwA8>@MS>RG@Tt_zt3hie^T z_?0%9VUd=)Fos7I z^ghPh%Jy%YZ|)vCf6EaFPai$Q-!=$ppK!y&wrJs)bNdAuANB!m3n34Tfj{s75g-&U z1A!Pg3bcXF-=!Gv1VmU93G2duANT;{0JugFTqg*|oPXPC|A$2HS3NJd-hcPV3EW`Y zh=1Dr-5Mv{<{zIvz#Ybay&^Vcn^E_`qRfl{{bzYkp)4~$~NAx_VB;E z{?P)PU)DbV{Qi#~0H0@T9czDj06@6MNq8OrpdAz(9qQxd9nPr<&s+~tPQySqaZyfb zNh!%g_5YjeaLxMN*$sv_p;d%b#U$Wpz0Geb0U>E+EOsEQ;I!&= zNC6q(BFFWohy&t- zL?CHM5mJM6p`(xmWDmJOUQi$u0mVUQpbRJ*DuT+OI;a`C4fR4p&?xj8nuk`Puh35f z55*JWF{C0=8)=GkKzbrWk@3iMWInPS*@Wyu4kE{pbI3L14-^JPgW^Pq!Q<2bWsPz} zg`nb5nW!REEvg;Wj~YYGqt;RTXfiY_S_G|(HbmQ@z0gtU6m&ki8r_B-Ku@3-(OVb{ zh8`n;QNS2r>@mKWSWG773g!l;2Q!LUz-(f%SSG9pRuyZCC1S&|DcC~nb!<2G1$Gg; zjU&Zz;G}VSI0sxHE(w>9tH<5Py}&KucJP#VKD;vC6z`6Y#%JLx@m=^4{33pbgo;Ff zM3uyf#Fr$Iq=2M}WPoIbWP_BHl$%tE)ST3Z^fYM!=}po{r1PXd2-E~&f;PdC5J9*= zs3G(aUK2LR$jJD~G{_vt!pSa>)sa0QdqcKOPD3tEZbLrbsZB|wjHfK7yiNI%a+8XNN{Y&qDu61Js-9|yYMB~K%}=dM z?M|IcT|xbTdVvN>!$YG@<3@9arjllWW|0;{D?n>V>r0zK+erJ2cAbuzPL|Gw?j&6? z-95TFdL%tRy&=6neHMKS{UrTQ1~vvw1`mcbh9-s=4Br`97&RC@7}FVVFitT3Wa4Df zW%6UX#MHqw%Zy?cW;SPzV!p~ez`Vvn%c8>K#*)s`!ZO8*U=?PyV2x$1V13HE$;Qs6 z&lb#9$o7D3jh&udgWZ=sm;FBb3I`2`8ix-@E=M=VM@~9UO-_H#0?vNUbuLye1Fi_J zGOlM_JKO@?*4#+T3Fgmx>$N#hD=6JCPAiC=8LR|tcUDX*;jHjawc-Aa(!}p@(S{y z@=fw93cLy~3MC3J6=@aC6f+ecDWR3LloFKgD*aHFR}NQhQU0tVrsAhkud;kZ;E2bO z$|DP^+^R&?GSxXXPBj;`QnfjCE_I@Mx%xW|9u0SmYKzbdmB(*}d+O)oF zD{G(9?$JT&=D|u+DJZ zNWtioQNJ<4*wVPj_}x+AqoGH;Ob{kUCOIZE$M}u~9_ug#riP|Drn6=OW+7&G%rWL> z=Ede8ETk;rECwxUES)XuEw`++tg@`8tp%+ktov*zY#eRsY`)v-*k;?#*-6-)vU_6B zZ0}>=>40^xaj16KJg$2@@A#sloMVdPRon; zro?jMrmLZAiR-$Xw%cX5Rd)^dT=x|ZRgY|sB~Mk)Y|mvcRj(Yc6>oL#eD5_MZJ#2a zFTMu8*L=VGnflfE9r)Y&-w413xCGn|qz?28>kOxb4~I`91S8Hy%txw47DsMJ*+jLTq&gXR@@ceibXxRMj9yGtEGpJ5wl9t= zE-`NYl;)|jcqraAzAu3%Avt03wEpSZM3O|m#Ni~#r0k?`XKc@OC9@@;PF^^xf3_io zJS8;cWvWW*wR5O*KIfjL$)pvg?Wen^KhBWM$j{i#bjy5vUg~_o`GX6d7oKIwXI;IB zxfpnH@{;j<`HmaI~Pakhkz+;ck(4 z(L}LU@r@GJlC+ZVSKP0>xT6f*a^OxsWU@9UjK2+LN4pu2v z)m1ZBXH@Ui1lG*eTGaN}Db&@~v({%dAQ~bXR<1ijt)TYR@l+GyI++oAU8_Vo_$j=4_z&e7XOxBI$Oy4voD->JFFb+`B) z-My^)B=?i=A9TlbZ}tTDto3^JF7!F~O+T=EFy3$8|7^f`;L$_9hYtod2fH7sKDs-k zJaqf9;^U4d@=w~I$~|oxmK$z+CjYE`L}8@!xzh8l(IcbxU#P$69n%?mIBq!pWa8Mw z=%n@JtCx;1=U%zLT7K>S`pZ=0)Xwzj8T3s0Eahze8`d}FZ-w68n3JEoH?K4Q^qu9q z=>@li)%RiVcNddCkbTHs;#jI%mR`QQqPOz=CgGy+9whdp4g`BLCvp!8U&;uov(!a2t+bEnRv6HXyi9t`-YglcEo`$K zI8GTZXYLH1F5YE+b^&9-c%dfYc~N>X1MygiCdpZ8N*OKLV7W5+5rusvVP$KTgd_E; zV`@J%*flk^Jhjj1)aX9cTQC5ItVZ(2W=FkE;*aH-)|+*kk6SET?pjmWaNEk+>D${o z_#cmV%sNr-bj$gX%QW$m8{|&wA?SI;%go!uC))SCU%7vKz~jI-L0?1Ap^RZ7;i?hG zB3+__P9{WW#uUa@#oavB8Q+`m==5;nXwvwZiR6j1<0+%5!{;8Q^`_s>XwIxTUvlAM z)|rdpmprp=bM$iM@_6#8@((Vr7Q8HcP;{fXs3iGH;8nY8TBRaov}JqcixtC_ZBw07?YBCLI#1vB=rX<|d6)j~ z?!9;SA9XkN4rDD83J6N{$`!z{xG&lW}=KCd6md=WHe zF)la3F!5t@`sLkMS6?Sg5vR3gcxTbGOK%>(y*_twKH{Cjg64anMViI^4{J-a%g0=3|@n*5+(H4=G;Z`Bm z0XDw2UUnY#t`5ZG&WObDFO_)C zCe0{aEki1k_dNXt+=U-mA1_W_8p^(%Qj|@Mb z9sM+h7-yIepVWIvd=>Y)XzKR#)XeT1jH zI8-@&65hs?W6g0$Tn9b?K9MevmJ{6JljSOT6GbGYHWfM5G<6M41g#z&E8Qx6H$yI? z50eHn6Z1ODBi1suSavH8F-{EUJXaTYHjh8AJ|73)7XPq7gt>OirQ5IDz)!g7S$y<#pnvPn` zTCcP(>sag3>W=B<=vx}l7>pa{8`&AN7|$LpGx0noeC)GnyV)so9SefRgyl6WA8Q%w zeVfO&`F8I1(hk7k+3~B6fhW|RD4pIpx4EPekGo2^q1>k2n?25Xx_BviQ+coYJoGK~ zi}SY&kPV~?{2VkK+z^r;>Jw%VE)ao-y@)AN%A4?QY z!X(X~xtpASHaNvFl_z!g+(cSqdP;^mD`$^mG5`i zpn$&+Rk%>pUtCp^dd2Um*){o6wlZ|t=klqF!OHfk>gs};%-W>7nEHr@(CeX%5lwM7 zQg7xp*S7SwzHLLbOLn+*Uc0?`NAB*$d)wWCJsW)~{h|X4gV%@BpPU*_8L1qd8t0!( zdySmVd!st{bK%K{=9Rj&=Ffv)KX1|hFxkC)82{hg(&3(fkq6-NB>?O?0kGBtAd?QJ zm0$~|LIBLj0I*U5i1iA9XzK$|?dCuG2lOlFq=GX}9v}f{nuc(O=>uZH1yBw;!3bD_ zU{(i`gLA_m=mOLPjX+-zbO8W#QsA+O&>1m7Uxak_`<>>nu%o*kx!T2DqomQ{`*59GHMHWa@qZ7S~^!Kl)z@vEz7SZjuAWovinywxMoS2FN7 zEH|1t%4A}H?2754xrD_j%Moi{n>gE7_6iP##}7_;J59Lg5Ifz(-D^B~y{dc!eQ)?H z1`GsQ2d{)Cgfm98MOmHv9&;s5@6?xs(nO0hxa6LcxN|CLdl`M_GqP+i31t7w9nHU9 zkY40hVt!S*RG^%pl2DDR1@+)Ms)_U_Lks^c#r9*J-d)LeEAIFAEIl9{kQ}rbihXiz zxOZfJbZ?wtQtXx5l+ld&8>=~scSi5kK8P(dtn9DO{nh=s_)Emb(M`^+uiKA)7VrA) zEB#tO5ODlSVZM$P@WWh#2Fx+Iz|6u~m`%6|24UXdCqxG`1g0=2kOkd@#-Q&AR(P%P zMdTpvAy(jBM;jT2tUyk{D~~EF3{{U>K(nFk;T(JdLx-`&6l3PF0@xsI7Y>87!d2q7 z@J9GD{0|aKlAELyq`{in5#@A}YP&ZEYQ#XH-V)Gsvv6_^~14ao?j4lj=6k7|w9iW!UZJhhvUlPHq(FxfQ) zq?V>>q`%8dxgeZ1aw#H*HTOZjUjc35y<*QR6jwV-iRB~}tyPXS=-S45n}+?ysv9OZ zzqJ(K(rR1j$hs}xHG4PtzG(M&@2Lj@{VyISJQ5#z^W@U7{hV|l=i6Vte3RLV-yYuK+dKCw{z!laG%#N$3ABJM%p<0O zYA^skKqQbP%m$r-WBwLFh0ujLomRwONMWQ8vL5*f<`CmhgJ?Rm2f718hVj63W7)9r z*mpQXTq~XnpG|@xNg&xFjU_!Gq>|CVvs#J#1w}9=HDxE2J2egUAWZ`85!yYvKKcv> zJ4PYKJ*G+KW|m8=VQlv7TJY|}%00wyKDli~41a=UN19Bb{{JVSQ=?d&3H&&qviwE*<+| zre!9^?4cDF}{Txa*#Kx+jZQvyZXwvVVG@WYFu7)G)>HwaCho zPBE;pGpDX4cqED@Z6)`nTsY^LE}F4-ek7|Lj+#LpTmF}Vfuf?4z^j_2v}GSEI;v7@ ztn0YySFg7=Mcq_r{?^*qM(m*I?Cd&z=li|$-7G!jeOwO;25=992SX5MzsmCeV$vtN*Wk9q%cvGzm6 zlGZYQ`Nc~9M~79`)tR-DzwAEIeH!_EZe4SI`^$~5?i-97Prt=)N^Q<3ePg@o zht*Hi&(|HuI*eO3a z*sFk(4fq>KkN@xQ6^F(cm~$_2K14li9;XkV|9<@!M&f%8Nam8p00009a7bBm000XU z000XU0RWnu7ytkil}SWFRCodHT?u#;Rkr@KbUNvfeG_5`YY-wNfPp{+o{ADgGcxep z5O;8ydCWk3pWowCbe1RjK4lzy;4&jKqk}U-a1=+ud7z@;LLwlFC>S)v1jwFrI_XY2 zop;WyuIf%_F~x?x|CCgE~7q5lBOq0>MKUdH^|7ARquk zTn+*P5DlHMG@8ELxbaVWHf?&T znHpfF&E_pZ&^rD;1;7qozi0Q$(`V)7{8<+kI>wdbHk%E>!9AN2eO+^{$KB)hHtVU6 z4;0@%KYw`%{kM%aj|)L>`1``u*EM%B_Ep|f_7iHT~t6&rZsneaT;XVt##n z3*O&%0=#!k4Gq$@x_XoAC663)d$?Wm=UXTrha?_sgD)BZa!4dhf)W5g$)o+5f!@!6p= z7>#E6lGpa0z~7?)*juclePn!mT$U>W2F?VqT7?}(LqHHhL#3+DoNXk5_#Pb{(lwSP zZ<=X|iSbjYeFoatR`H}3=!RdX3qeSTbc>FTPC&5WKoW3vT<}n4p!jve)Qtntp05&Y$`N~L&mauhNrjZlt#E%Rdnz*4RdA(~WsS0P~4Cker*^h9K3rID79 zAhx!)2_f*-6tD+E@|~5o_HbR*DQEm#fix64W;xPOIEsuwz3>ej`Mg}wlx+M?%^s;7 zt7<_1|D+24j|zb6{d*Duo)R*nQ%A&N`m}UK6}Gim#oV|jr-^I5{&3u6Y!z0&JjK=N zf~iA{0UNr_&1RH*=FkdaRxmwXu@ih1pW6b!KwO1@&&hNBf0 z=VYU~zns|bF>|Ig{pE8Oi&e4q8Sf>;d>$HnJ*g4^2E{@!BWJXj|MK2>t{)#4iCiKM z_X3_Wd3!22SVWGECF_5t9Wx1ebdVe1IRabo*K&Me+mp(08G`jsI~A7O*rz=A?*I(Ym_y4*ZBHj<`2EIL z@XCfeuGtW8G6RGFlFM<@CjE-OtU#5a;0kB%yXw(N%<3n(~sBeG(H{~)Y9EAyo%kT#Rg2j zpdOnacnjrpoDswQL%S&=xD)LJZ^c?^7~tUKxVSW2U-+UJ`I8c2{Q|sd4FLUcTr-0M zaqMa26wFKpz7U~s3AlNV^qhrHMbm9<`9gTLcVV_VCkYcW$bp+1aV?*4j`n;5NQvl5P$NHC1)DVqF ze?14Uta}S5dTDmrRR#Fn;tPAZ>c6M&cw`%zt17X5(`x+mXPZPMYENh$xHA{IIn#Q& z^ zG}YF_5*3HIuofIEDMeLB1jc8M#;C+D(d52>)gx`#@~i9ZqkAV_+e~x*&R~QFvHtHw zX=O8P?QIyJ9Ss9*B|&g;0hMp z3Alm-uHb+xn7Ts16&!E{`__2XkJh+p1UhOAxPk+&;D9SQ;0g}7f`^~4p*Mp`Hum_uHM8Ep9TllPO>m-^Cs zpVwg1bK6i`-w1z*2vDs7WXVaJJHyU=rk@Vk3#W^iKzdl}7D4^3u#E2B8*>%rGlt8u z5=Bg)^vMF>N2OW-kTeo=C=#;#Uwg6hiz=At%UPznGuZL$9uX3jIcgXzEoL+}ne7De zePX!NLIZ__1sfvpaY5fTR( zUH5HKQ7-^w@TCk-ATqS$+;^2Y-9Yg{p~En8>~LcE&~OCN2SO-y!qgT7qsff0kWR!$ z^D81!lBm$TfXL;}=Y9YJK+SF{!{d*=}ZDsk}pA}{0WdF3_)n|T5 zFNK7P(SF;zrP#jx9qieE2>F-K@p;gyHGt(@rI_!hEt)McpP}lbFn3v=a0JCAI=-Ld z^HfmLKw}#PgVO)j-n&3BpR3@}{)WrPilHHGIK3w22T8R6=u<`rMwjnBh~jFy5zt}A zN81hv!KkMXNNPDnh1mq7H@>uwma1@k3;2!wtQCOj+9tn%uigkWBw{AL|5)BofhX2& zA+XZ302%fCsUzg9CimQPVv`f;C6O8|{n>ML#6sZcPqU_9DPe!$!>g7coyleK6R!5=0O9Kit+4(r(6 ziv6QJ8-P(X4Sa3SakRGjFIv?a0G4_jZD3}d!^RD-cH>&cq5?d2jrKkeAp_;!Ur#;& z9W7Y4e9epUX=T6m-g%gom8l&2YDT>Vpn#D2K2TLOYC9;D1)wkDRn>N#8T3J_^Lk0W z2GEDo5^3Wxdgdfd9w7&WOIUcVywJ$#^9sz{H)rNATQUdN%*}+3f?}K#TL)6Cfb&`3 z%&Qjw3IaWJ_$1z;4dDsM&%YQ~=42pUgopbkSWmW!9lu+5e2Bl(Hp~!=)psw#l#5d7 z<59t4!9`Er%bRtn7l4p3WRMY9&31sf7Q0{HC$^-K>G(;07G_Pk5PmWfQbk{$>nD;C z$aX+;iw(co_@<~Qn^p+B=a%_MiWA>XQ&sn1{z<(6(1#*dufHEF>#Fe8m!&8!F2%dw zHlg}-8UFYJZG<8tdn)d^eHPNC3G-m$^7_440RBMV3*u1l6Q_-MckXuK!rmQ$k)#dR$sG z@^U71!@qOSF|2)@pOpG;Qm+AE#NKTmpy<6aRJ-8I$ex7UR10>zRSMI&Dx4*+aC%oe z$>ksZdHCl3@33X-u5M#~!F>8s>bP;(@Z1iZ5DQ57E(pe>^RmdH=2Rkv1Y;;r0f4a|kUQI?AO7tZbEf zJ(*E203jiWBR5FKRnt*$=_L9l06hS)bRb+XpPQ(|6)W>G1u?i-W6WoCJgUlRkTWYJ9y;~2lKhQP~5|72z2_#^8q&npdI^OKWZnM4)jd~lxFIKK%PKOm(9u+`!IG4P>PAtq9@Rh0JE!{0DuH! zkK`y|6ZXDM&ju*fYcM2?dkd?0BQd?AvKl9=rI$l^%Bzo%82pwp_ z3!t@d`N^j}MPee&>2}gr!FRvB)4o^~UCPYDMfxiI>b@c+MsVI_ZG?n%#SdILF9)yD z8iBv~&32h6$j=)^`5;_--)1F7aK==Pycf`JwRRcIa&EjD`NGhX@h9M+TM4YCmA;oJ zrO3=nv3MeD1n(z%`&dZj&7(JU#eehVv~0XE^yJ%^arZ3+;^s6cinJi_LRv*8MlRsh z{Xp^er2%-zvwii|iPQND<~cxwB;)S&_u$&{D%8_7aQMh%>8YP30yAe!z=De>;j*0J zN>6b7(K|VAAJyy)=J$-BZpMp7n5{I{+sN@1<}jm{UYm<6az zC)2KLBDKeY!To$ha&qG2BZqfAotPNM^BbQ^H8u4$*;5z(vZ|_v=c1LgH4&aJ8cR)s zhZ25=_;#ffO9d0sLd30K^&jiDoI6+3R|Htse-FYDw`bL=buUu;*yY6jR@v$9iMtOO z{Jm)a77X@ba%$f%7edh>l!!{woQDqvAyLn?wOiY*$B%zo zv32X~pEWczvH$rLZ56cfy6vr`0a$epDA9d}4E`PkfT>4BU?%e$j!CrfB%e1P1~}M{ zuQ8DZRRHLI>|J6XE5CNbPoY`u^Tv~L_DESt0J@K9biv&;RPgs@1TwMtC4bqg&n_U& z^RqpU@fmCZV8(Krcxd8Db|Y=v9v+%_sqO*ye5%7a4GH|cY5=AL^#T?U?(IAraOf}Z znfd(s?_l?Sx}{(;kM%5!ES&ry9?r8?uz9NYQ(Ynr1^j&q08@d8z|&jaWMSaE-1`Sx z2*lKk?$1KN8*2mJGw(g3`l+riN$dE3Q~;P7LCd=wx?7hW&8J3pu z_e%g|LIn2Oqk!C_wTCQ#s9zKa2tdEcq}@UR0njdQ`-LnZ0R1A9b_)drK)bx{7qWl= z^ovZ|Eff#{?eex?$N~b;FEVMjP(T2*%iDe-`+v|7m{y$1dn*6{002ovPDHLkV1lnB B5rhB$ literal 0 HcmV?d00001 diff --git a/haskell/gen_docs.sh b/haskell/gen_docs.sh new file mode 100755 index 0000000..d732d17 --- /dev/null +++ b/haskell/gen_docs.sh @@ -0,0 +1,9 @@ +#!/bin/bash + + +cabal haddock + + +rm -rf ../Docs/haskell + +cp -r ./dist-newstyle/build/x86_64-linux/ghc-9.6.5/p2prc-0.1.0.0/doc/html/p2prc/ ../Docs/haskell diff --git a/haskell/lib/API.hs b/haskell/lib/API.hs index f22e7b2..e949f11 100644 --- a/haskell/lib/API.hs +++ b/haskell/lib/API.hs @@ -15,7 +15,7 @@ import Error ) import JSON - ( IPAdressTable(..) + ( IPAddressTable(..) , MapPortResponse(..) , P2prcConfig ) @@ -33,12 +33,18 @@ import CLI import Environment ( cleanEnvironment ) -data P2PRCapi -- ^ Haskell API - = MkP2PRCapi -- ^ Main Constructor - { startServer :: IOEitherError ProcessHandle -- ^ start server +-- | Lower level P2PRC Haskell api that exposes basic functionality necessary to joint the network. + +data P2PRCapi + = MkP2PRCapi + { startServer :: IOEitherError ProcessHandle + -- ^ Start server , execInitConfig :: IOEitherError P2prcConfig - , execListServers :: IOEitherError IPAdressTable + -- ^ Instantiate server configuration + , execListServers :: IOEitherError IPAddressTable + -- ^ List servers in network , execMapPort :: MapPortRequest -> IOEitherError MapPortResponse + -- ^ Exposes and associates a local TCP port with a remote DNS address } @@ -52,7 +58,9 @@ data MapPortRequest = {-| This function cleans the previous running state (ensuring a pure P2PRC runtime state) and builds up a conditional 'P2PRCapi' instance. - __The following example show how this function can be used to expose the runtime functionalities:__ + ==== __Example__ + + The following example show how this function can be used to expose the runtime functionalities: @ example :: IOEitherError P2PRCapi diff --git a/haskell/lib/Engine.hs b/haskell/lib/Engine.hs index 773516b..15838df 100644 --- a/haskell/lib/Engine.hs +++ b/haskell/lib/Engine.hs @@ -45,7 +45,9 @@ import API {-| This function starts and bootstraps the P2PRC runtime that associates the a specific host's machine port to a DNS address to expose a certain application to the P2PRC network. You will only need to also import the 'MkMapPortRequest' data constructor to represent the this port request. - __This example demonstrates how it can be ran on the IO context:__ + ==== __Example__ + + This example demonstrates how it can be ran on the IO context: @ example :: IO () diff --git a/haskell/lib/JSON.hs b/haskell/lib/JSON.hs index 89549e7..9affc8c 100644 --- a/haskell/lib/JSON.hs +++ b/haskell/lib/JSON.hs @@ -2,7 +2,7 @@ module JSON ( P2prcConfig(..) - , IPAdressTable(..) + , IPAddressTable(..) , IPAddress(..) , ServerInfo(..) , MapPortResponse(..) @@ -17,7 +17,7 @@ import qualified Data.Text as T import Data.Aeson --- {-# WARNING MapPortResponse "This newtype is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015" #-} +{-# WARNING MapPortResponse "This newtype is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015" #-} -- ^ This represents P2PRC's response to the TCP port and DNS address allocation. This value will confirm the successful allocation and return information about it. newtype MapPortResponse @@ -39,31 +39,34 @@ instance FromJSON MapPortResponse where {-# WARNING P2prcConfig "This type is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015" #-} -newtype P2prcConfig -- ^ Host P2prc configuration - = MkP2prConfig -- ^ Unique Constructor + +-- | This represents the server configuration that defines its attributes and behaviours in the network, as well as, the location of the runtime persistence artifacts. +newtype P2prcConfig + = MkP2prConfig { machineName :: String -- ^ Machine Name - } - deriving Show + } deriving Show + + -- , hostServerPort :: Int + -- , iPV6Address :: Maybe String + -- , proxyPort :: Maybe Int + -- , fRPServerPort :: Bool + -- , behindNAT :: Bool + -- , iPTableKey :: String + -- , bareMetal :: Bool + -- , customConfig :: String + -- -- , iPTable :: String -- File -- , dockerContainers :: String -- Directory -- , defaultDockerFile :: String -- Directory -- , dockerRunLogs :: String -- Directory -- , speedTestFile :: String -- File - -- , iPV6Address :: Maybe String -- , pluginPath :: String -- Directory -- , trackContainersPath :: String -- File - -- , hostServerPort :: Int - -- , proxyPort :: Maybe Int - -- , groupTrackContainersPath :: File - -- , fRPServerPort :: Bool - -- , behindNAT :: Bool - -- , iPTableKey :: String -- , publicKeyFile :: String -- File -- , privateKeyFile :: String -- File -- , pemFile :: String -- File -- , keyFile :: String -- File - -- , bareMetal :: Bool - -- , customConfig + -- , groupTrackContainersPath :: String -- File -- TODO: p2prc API @@ -106,42 +109,44 @@ instance FromJSON P2prcConfig where parseJSON _ = mzero -{-# WARNING IPAdressTable "This newtype is highly unstable due to undergoing work on improving P2PRC's server api. For more information, visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114" #-} +{-# WARNING IPAddressTable "This newtype is highly unstable due to undergoing work on improving P2PRC's server api. For more information, visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114" #-} - --- | IP Table -newtype IPAdressTable - = MkIPAdressTable -- ^ Constructor - [ServerInfo] -- ^ List Servers +-- | This is a wrapper value that parses a json key value from the list of ip addresses in the network. +newtype IPAddressTable + = MkIPAddressTable -- ^ Wrapping constructor + [ServerInfo] -- ^ List current network servers deriving Show -instance FromJSON IPAdressTable where +instance FromJSON IPAddressTable where parseJSON = withObject "IPAdressTable" $ \ v -> - MkIPAdressTable <$> v .: "ip_address" + MkIPAddressTable <$> v .: "ip_address" {-# WARNING ServerInfo "This type is highly unstable due to undergoing work on improving P2PRC's server api. For more information, visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114" #-} +{- | + This is a record that keeps track of the current state of every node in the network. It is crucial information required for orchestration strategies. +-} data ServerInfo = MkServerInfo - { name :: T.Text - , ip :: IPAddress - , latency :: Int - , download :: Int - , upload :: Int - , serverPort :: Int - , bareMetalSSHPort :: Maybe Int - , nat :: Bool - , escapeImplementation :: Maybe T.Text - , customInformation :: Maybe T.Text + { name :: T.Text -- ^ Machine name + , ip :: IPAddress -- ^ Machine IP address + , latency :: Int -- ^ Response latency + , download :: Int -- ^ Download speed + , upload :: Int -- ^ Upload speed + , serverPort :: Int -- ^ Server port number + , bareMetalSSHPort :: Maybe Int -- ^ SSH machine port number + , nat :: Bool -- ^ Checking if node is behind a NAT + , escapeImplementation :: Maybe T.Text -- ^ Type of NAT trasversal technique + , customInformation :: Maybe T.Text -- ^ Custom String information } deriving Show - +-- | This is a simple representation of the IP address of nodes in the network. data IPAddress - = MkIPv4 String - | MkIPv6 String + = MkIPv4 String -- ^ IP version 4 address + | MkIPv6 String -- ^ IP version 6 address deriving Show diff --git a/haskell/lib/P2PRC.hs b/haskell/lib/P2PRC.hs index c4bac51..72e3f11 100644 --- a/haskell/lib/P2PRC.hs +++ b/haskell/lib/P2PRC.hs @@ -50,14 +50,14 @@ module P2PRC -- | This section gives an overview on the runtime and host machine interfaces. , P2PRCapi(..) , P2prcConfig(..) + , MapPortRequest(..) + , MapPortResponse(..) -- ** Primitive data types -- | These types represent the core data that is communicated between requests and the runtime. - , IPAdressTable(..) + , IPAddressTable(..) , ServerInfo(..) , IPAddress(..) - , MapPortRequest(..) - , MapPortResponse(..) , Error(..) -- ** Type Synonyms @@ -72,7 +72,7 @@ import Engine ) import JSON - ( IPAdressTable(..) + ( IPAddressTable(..) , ServerInfo(..) , IPAddress(..) , MapPortResponse(..)