Akilan1999 / p2p-rendering-computation

p2p network to enable running distributed computation and rendering.
https://p2prc.akilan.io/
GNU General Public License v2.0
27 stars 10 forks source link

Extension p2prc you create your own modification #69

Closed Akilan1999 closed 3 years ago

Akilan1999 commented 3 years ago

Generate Module

P2PRC is a great layer of abstraction. This means that in many cases it is not an end product but rather a tool that customized as an end product. An example would be writing your own billing module to monetize the computation power available. The generate module copies the current with the appropriate git histories and keeps only the go files which would be useful to edit. To use the generate module the user will need to have a go compiler present in his computer. Due to the introduction of this module there will 2 releases:

How does this work ?

Struct information

    //----------------------------------------------------------------
    // Action performed:
    // - Ensuring main.go file exists
    // - Skipping all .go files apart from the ones listed above
    // - Skipping .idea/ directory
    // - Skipping Makefile file
    //----------------------------------------------------------------
    Options.Skip = func(src string) (bool, error) {
        switch {
        case strings.HasSuffix(src, "main.go"):
            return false, nil
        case strings.HasSuffix(src, ".go"):
            return true, nil
        case strings.HasSuffix(src, ".idea"):
            return true, nil
        case strings.HasSuffix(src, "Makefile"):
            return true, nil
        default:
            return false, nil
        }
    }

    // Doing the copy 
    err = copy.Copy("<P2PRC folder you want to copy from>", "<PATH to the directory>", Options)

Unfortunately currently this will have to be manually edited in the Generate.go file. When using the generate module the user also creates their own Go module which is the modified version of P2PRC. This means if the 1 modified package is using another modified package then the appropriate import have to be modified in the file where the import is called:

Ex:

 //Sample Project module name = Test 
 //Package names:
 //- Test/Genius
 //- Test/GeGeGenuis
 //
 // When we call the generate function with the new project with the module name = MicDrop 
 // The new package name would be:
 // - MicDrop/Genius 
 // - MicDrop/GeGeGenuis

 // Test/Genius code depends on the package Test/GeGeGenuis
 import (
    "Test/GeGeGenuis"
 )

// When we create a new module with the copy of the 
// existing project we need change:
import (
 "MicDrop/GeGeGenuis"
)

To do this we have built functions which can modify import names in the Go file provided. To customize the use case of your generate module you would need to manually add your own imports which are supposed to be replaced and in which files they are supposed to be replaced in.

// 1.0 - Test/Genius.go -> GeGeGenuis module
// a is struct of type NewProject 
    a.FileNameAST = "<path to project to copy from>/Test/Genius.go"
    // Get AST information of the file
    err := a.GetASTGoFile()
    if err != nil {
        return err
    }
    // Change the appropriate Go file
    err = a.ChangeImports("Test/GeGeGenuis", "MicDrop/GeGeGenuis")
    if err != nil {
        return err
    }
    // Writes the change to the appropriate file
    err = a.WriteGoAst()
    if err != nil {
        return err
    }

Higher order of execution of Generate.go:

  1. Copy entire P2PRC project and ignores files which are not meant to be copied
  2. The folder name will be based on the new project name and the module name based on the new module name provided.
  3. Modifies the appropriate imports in the project as instructed in the code.
  4. Creates a commit with the new changes in the new project.

Cli command

p2prc --gen <project name> --mod <go module name>