diff --git a/Bindings/Client.go b/Bindings/Client.go index c1ad90a..ef88700 100644 --- a/Bindings/Client.go +++ b/Bindings/Client.go @@ -2,11 +2,11 @@ package main import "C" import ( - "encoding/json" - "time" + "encoding/json" + "time" - "github.com/Akilan1999/p2p-rendering-computation/abstractions" - "github.com/Akilan1999/p2p-rendering-computation/p2p/frp" + "github.com/Akilan1999/p2p-rendering-computation/abstractions" + "github.com/Akilan1999/p2p-rendering-computation/p2p/frp" ) // The Client package where data-types @@ -18,20 +18,20 @@ import ( //export StartContainer func StartContainer(IP string) (output *C.char) { - container, err := abstractions.StartContainer(IP) - if err != nil { - return C.CString(err.Error()) - } - return ConvertStructToJSONString(container) + container, err := abstractions.StartContainer(IP) + if err != nil { + return C.CString(err.Error()) + } + return ConvertStructToJSONString(container) } //export RemoveContainer func RemoveContainer(IP string, ID string) (output *C.char) { - err := abstractions.RemoveContainer(IP, ID) - if err != nil { - return C.CString(err.Error()) - } - return C.CString("Success") + err := abstractions.RemoveContainer(IP, ID) + if err != nil { + return C.CString(err.Error()) + } + return C.CString("Success") } // --------------------------------- Plugin Control ---------------------------------------- @@ -77,20 +77,20 @@ func RemoveContainer(IP string, ID string) (output *C.char) { //export GetSpecs func GetSpecs(IP string) (output *C.char) { - specs, err := abstractions.GetSpecs(IP) - if err != nil { - return C.CString(err.Error()) - } - return ConvertStructToJSONString(specs) + specs, err := abstractions.GetSpecs(IP) + if err != nil { + return C.CString(err.Error()) + } + return ConvertStructToJSONString(specs) } //export Init func Init(customConfig string) (output *C.char) { - init, err := abstractions.Init(customConfig) - if err != nil { - return C.CString(err.Error()) - } - return ConvertStructToJSONString(init) + init, err := abstractions.Init(customConfig) + if err != nil { + return C.CString(err.Error()) + } + return ConvertStructToJSONString(init) } @@ -98,81 +98,90 @@ func Init(customConfig string) (output *C.char) { //export ViewIPTable func ViewIPTable() (output *C.char) { - table, err := abstractions.ViewIPTable() - if err != nil { - return C.CString(err.Error()) - } - return ConvertStructToJSONString(table) + table, err := abstractions.ViewIPTable() + if err != nil { + return C.CString(err.Error()) + } + return ConvertStructToJSONString(table) } //export UpdateIPTable func UpdateIPTable() (output *C.char) { - err := abstractions.UpdateIPTable() - if err != nil { - return C.CString(err.Error()) - } - return C.CString("Success") + err := abstractions.UpdateIPTable() + if err != nil { + return C.CString(err.Error()) + } + return C.CString("Success") } //export EscapeFirewall func EscapeFirewall(HostOutsideNATIP string, HostOutsideNATPort string, internalPort string) (output *C.char) { - // Get free port from P2PRC server node - serverPort, err := frp.GetFRPServerPort("http://" + HostOutsideNATIP + ":" + HostOutsideNATPort) + // Get free port from P2PRC server node + serverPort, err := frp.GetFRPServerPort("http://" + HostOutsideNATIP + ":" + HostOutsideNATPort) - if err != nil { - return C.CString(err.Error()) - } + if err != nil { + return C.CString(err.Error()) + } - time.Sleep(5 * time.Second) + time.Sleep(5 * time.Second) - ExposedPort, err := frp.StartFRPClientForServer(HostOutsideNATIP+":"+HostOutsideNATPort, serverPort, internalPort, "") - if err != nil { - return C.CString(err.Error()) - } + ExposedPort, err := frp.StartFRPClientForServer(HostOutsideNATIP+":"+HostOutsideNATPort, serverPort, internalPort, "") + if err != nil { + return C.CString(err.Error()) + } - return C.CString(ExposedPort) + return C.CString(ExposedPort) } //export MapPort func MapPort(Port string, DomainName string, ServerAddress string) *C.char { - Address, err := abstractions.MapPort(Port, DomainName, ServerAddress) - if err != nil { - return C.CString(err.Error()) - } - return C.CString(Address.EntireAddress) + Address, err := abstractions.MapPort(Port, DomainName, ServerAddress) + if err != nil { + return C.CString(err.Error()) + } + return C.CString(Address.EntireAddress) } //export CustomInformation func CustomInformation(CustomInformation string) *C.char { - err := abstractions.AddCustomInformation(CustomInformation) - if err != nil { - return C.CString(err.Error()) - } - return C.CString("Success") + err := abstractions.AddCustomInformation(CustomInformation) + if err != nil { + return C.CString(err.Error()) + } + return C.CString("Success") +} + +//export AddRootNode +func AddRootNode(IP string, Port string) *C.char { + err := abstractions.AddRootNode(IP, Port) + if err != nil { + return C.CString(err.Error()) + } + return C.CString("Success") } // --------------------------------- Controlling Server ---------------------------------------- //export Server func Server() (output *C.char) { - _, err := abstractions.Start() - if err != nil { - return C.CString(err.Error()) - } + _, err := abstractions.Start() + if err != nil { + return C.CString(err.Error()) + } - return ConvertStructToJSONString("") + return ConvertStructToJSONString("") } // --------------------------------- Helper Functions ---------------------------------------- func ConvertStructToJSONString(Struct interface{}) *C.char { - jsonBytes, err := json.Marshal(Struct) - if err != nil { - return C.CString(err.Error()) - } + jsonBytes, err := json.Marshal(Struct) + if err != nil { + return C.CString(err.Error()) + } - // Convert the JSON bytes to a string - return C.CString(string(jsonBytes)) + // Convert the JSON bytes to a string + return C.CString(string(jsonBytes)) } func main() {} diff --git a/Bindings/python/library.py b/Bindings/python/library.py index b211f1e..20bcc40 100644 --- a/Bindings/python/library.py +++ b/Bindings/python/library.py @@ -44,9 +44,9 @@ class Node: Upload: int ServerPort: str BareMetalSSHPort: str - NAT: str + NAT: bool EscapeImplementation: str - ProxyServer: str + ProxyServer: bool UnSafeMode: bool PublicKey: str CustomInformation: str @@ -98,6 +98,21 @@ def ListNodes(): dat: IPAddress = dacite.from_dict(IPAddress,ipTableObject) return dat +# Add a root node to P2RRC and overwrites all other nodes. +# To be only added before the network started and with +# the intention of a fresh protocol. +def AddRootNode(ip="", port="") -> bool: + ip = go_string(c_char_p(ip.encode('utf-8')), len(ip)) + port = go_string(c_char_p(port.encode('utf-8')), len(port)) + + p2prc.AddRootNode.restype = c_char_p + res = p2prc.AddRootNode(ip, port) + if str(res).strip("b'") == "Success": + return True + return False + + + # python function to pass-through custom # information to interpret which can be # interpreted as a DSL. diff --git a/Bindings/python/test.py b/Bindings/python/test.py index d3bc4aa..e094ba4 100644 --- a/Bindings/python/test.py +++ b/Bindings/python/test.py @@ -9,3 +9,6 @@ if __name__ == "__main__": # Add custom information to the network if AddCustomInformation("Test"): print("It worked") + + if AddRootNode("0.0.0.0", "8081"): + print("It worked for adding root node") diff --git a/Docs/Colored-On-Light-Image.png b/Docs/Colored-On-Light-Image.png new file mode 100644 index 0000000..968df7d Binary files /dev/null and b/Docs/Colored-On-Light-Image.png differ diff --git a/Docs/index.html b/Docs/index.html index 2cef8e0..b66adba 100644 --- a/Docs/index.html +++ b/Docs/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + @@ -26,12 +26,12 @@

Table of Contents

@@ -108,8 +109,8 @@
  • 6.3. Current languages supported
  • @@ -126,22 +127,22 @@
  • 10. Client mode
  • -
  • 11. Blog posts +
  • 11. Blog posts
  • -
  • 12. Ideas for future potencial features +
  • 12. Ideas for future potencial features @@ -150,26 +151,26 @@
  • -
    -

    Colored-On-Light-Image.png +

    +

    Colored-On-Light-Image.png

    -
    -

    1. Guide through video

    +
    +

    1. Guide through video

    -
    -

    1.0.1. The video below shows the setup and usage of P2PRC.

    +
    +

    1.0.1. The video below shows the setup and usage of P2PRC.

    -
    +

    maxresdefault.jpg

    -
    @@ -258,7 +259,7 @@ Go API to create and interact with the containers. to install docker GPU

    -
    +
     // Do ensure that the docker command does not need sudo to run
     sudo chmod 666 /var/run/docker.sock
     
    @@ -272,7 +273,7 @@ To set up the internal dependencies and build the entire go code into a single binary

    -
    +
     make
     
    @@ -284,7 +285,7 @@ To set up P2PRC on Windows, simply run this batch file. Make sure you are not in admin mode when running this.

    -
    +
     .\install.bat
     
    @@ -294,7 +295,7 @@ are not in admin mode when running this.

    3.2.4. Add appropriate paths to .bashrc

    -
    +
     export P2PRC=/<PATH>/p2p-rendering-computation
     export PATH=/<PATH>/p2p-rendering-computation:${PATH}
     
    @@ -303,14 +304,14 @@ export PATH=/<PATH>/p2p-rendering-computation:${PATH}

    3.2.5. Test if binary works

    -
    +
     p2prc --help
     
    1. Output:
      -
      +
       NAME:
          p2p-rendering-computation - p2p cli application to create and access VMs in other servers
       
      @@ -372,7 +373,7 @@ GLOBAL OPTIONS:
       

      4.0.1. Start as a server

      -
      +
       p2prc -s 
       
      @@ -380,7 +381,7 @@ p2prc -s

      4.0.2. View server Specification

      -
      +
       p2prc --specs=<ip address>
       
      @@ -392,7 +393,7 @@ p2prc --specs=<ip address> use the --gpu if you know the other machine has a gpu.

      -
      +
       p2prc --touch=<server ip address> -p <number of ports> --gpu
       
      @@ -404,7 +405,7 @@ p2prc --touch=<server ip address> -p <number of ports> --gpu The docker id is present in the output where you create a container

      -
      +
       p2prc --rm=<server ip address> --id=<docker container id> 
       
      @@ -412,7 +413,7 @@ p2prc --rm=<server ip address> --id=<docker container id>

      4.0.5. Adding servers to ip table

      -
      +
       p2prc --as=<server ip address you want to add> 
       
      @@ -420,7 +421,7 @@ p2prc --as=<server ip address you want to add>

      4.0.6. Update ip table

      -
      +
       p2prc --us 
       
      @@ -428,7 +429,7 @@ p2prc --us

      4.0.7. List Servers

      -
      +
       p2prc --ls 
       
      @@ -436,7 +437,7 @@ p2prc --ls

      4.0.8. View Network interfaces

      -
      +
       p2prc --ni
       
      @@ -444,7 +445,7 @@ p2prc --ni

      4.0.9. Viewing Containers created Client side

      -
      +
       p2prc --tc
       
      @@ -452,7 +453,7 @@ p2prc --tc

      4.0.10. Running plugin

      -
      +
       p2prc --plugin <plugin name> --id <container id or group id>
       
      @@ -460,7 +461,7 @@ p2prc --plugin <plugin name> --id <container id or group id>

      4.0.11. Create group

      -
      +
       p2prc --cgroup
       
      @@ -468,7 +469,7 @@ p2prc --cgroup

      4.0.12. Add container to group

      -
      +
       p2prc --group <group id> --id <container id>
       
      @@ -476,7 +477,7 @@ p2prc --group <group id> --id <container id>

      4.0.13. View groups

      -
      +
       p2prc --groups
       
      @@ -484,7 +485,7 @@ p2prc --groups

      4.0.14. View specific group

      -
      +
       p2prc --group <group id>
       
      @@ -492,7 +493,7 @@ p2prc --group <group id>

      4.0.15. Delete container from group

      -
      +
       p2prc --rmcgroup --group <group id> --id <container id> 
       
      @@ -500,7 +501,7 @@ p2prc --rmcgroup --group <group id> --id <container id>

      4.0.16. Delete entire group

      -
      +
       p2prc --rmgroup <group id>
       
      @@ -508,7 +509,7 @@ p2prc --rmgroup <group id>

      4.0.17. Pulling plugin from a remote repo

      -
      +
       p2prc --pp <repo link>
       
      @@ -516,7 +517,7 @@ p2prc --pp <repo link>

      4.0.18. Deleting plugin from the plugin directory

      -
      +
       p2prc --rp <plugin name> 
       
      @@ -524,28 +525,28 @@ p2prc --rp <plugin name>

      4.0.19. Added custom metadata about the current node

      -
      +
       p2prc --amd "custom metadata"
       
      -
      -

      4.0.20. MapPort and link to domain name

      +
      +

      4.0.20. MapPort and link to domain name

      Allows to expose remote ports from a machine in the P2P network.

      -
      +
       p2prc --mp <port no to map> --dn <domain name to link Mapped port against>
       
        -
      1. MapPort in remote machine
        +
      2. MapPort in remote machine

        This is to ensure ports on remote machines on the P2PRC can be easily opened.

        -
        +
         p2prc --mp <port no to map> --dn <domain name to link Mapped port against> --ra <remote server address>
         
        @@ -554,6 +555,19 @@ p2prc --mp <port no to map> --dn <domain name to link Mapped port again
      +
      +

      4.0.21. Add root node

      +
      +

      +Adds a root node to P2RRC and overwrites all other nodes in the ip table. +To be only added before the network is started and with +the intention of a fresh instance. +

      +
      +p2prc --arn --ip <root node ip address> -p <root node port no>
      +
      +
      +

      5. P2P Module Implementation

      @@ -660,7 +674,7 @@ from the TURN server. The flow below describes the workflow.
    2. Call /FRPPort
    3. -
      +
       http://<turn server ip>:<server port no>/FRPport
       
      @@ -749,7 +763,7 @@ p2prc.h p2prc.so Below are a sample set of commands to open the bindings implementation.

      -
      +
       # run
       cd Bindings/
       # list files
      @@ -837,7 +851,7 @@ that convert a go object to JSON string initially and converts it to
       
    4. A Pseudo code to refer to the common function implementation shape could be represented as:
      -
      +
       func <Function name> (output *C.char) {
             <response>,<error> := <P2PRC function name>(<parameters if needed>)
             if <error> != nil {
      @@ -855,8 +869,8 @@ func <Function name> (output *C.char) {
       

      6.3. Current languages supported

      -
      -

      6.3.1. Python

      +
      +

      6.3.1. Python

        @@ -893,8 +907,8 @@ called from other programming languages.
      -
      -

      6.3.2. Haskell

      +
      +

      6.3.2. Haskell

      P2PRC officially supports Haskell bindings and will further support @@ -1006,7 +1020,7 @@ from the TURN server. The flow below describes the workflow.

    5. Call /FRPPort
    6. -
      +
       http://<turn server ip>:<server port no>/FRPport
       
      @@ -1037,12 +1051,12 @@ func main() {
      -
      -

      11. Blog posts

      +
      +

      11. Blog posts

      -
      -

      11.1. Self host within 5 minutes any program

      +
      +

      11.1. Self host within 5 minutes any program

      -
      +

      maxresdefault.jpg

      @@ -1064,8 +1078,8 @@ This is a fun expirement for anyone to try to quickly run a server and quickly do a map port and domain name mapping in a single command.

      -
      -

      11.1.1. 1. Find a program you want to run

      +
      +

      11.1.1. 1. Find a program you want to run

      Let's try to setup a really easy program (Let's do with Linkwarden @@ -1074,7 +1088,7 @@ compose installed on your local machine.

        -
      1. Let's run Linkwarden using docker compose and P2PRC
        +
      2. Let's run Linkwarden using docker compose and P2PRC
      -
      -

      12. Ideas for future potencial features

      +
      +

      12. Ideas for future potencial features

      Consists of personal loideas for the future of P2PRC. At moment only has main contributors writiing to this.

      -
      -

      12.1. To support hetrogenous set of Nodes that cannot run P2PRC

      +
      +

      12.1. To support hetrogenous set of Nodes that cannot run P2PRC

      This stems from a personal issue I have when doing research @@ -1188,8 +1202,8 @@ and would introduce a new layer fault tolerance within a local network nodes.

      -
      -

      12.1.1. Assumptions:

      +
      +

      12.1.1. Assumptions:

      • I have a Morello board that cannot run P2PRC
      • @@ -1202,8 +1216,8 @@ as well look into custom tasks into the hetrogenous hardware.
      -
      -

      12.1.2. Set of interesting possible:

      +
      +

      12.1.2. Set of interesting possible:

      We build a cool set possibilities before and use this to build up the implementation @@ -1220,8 +1234,8 @@ weight hypervisors.

    -
    -

    12.1.3. Implementation

    +
    +

    12.1.3. Implementation

    • To use implementations similar to socat to ensure we can bind address of local @@ -1235,7 +1249,7 @@ other nodes can access the Morello board who have permission access.
    -
    +

    P2PRCRemoteNodes.png

    Figure 1: Implementation idea (To be improved upon)

    @@ -1247,7 +1261,7 @@ other nodes can access the Morello board who have permission access.

    Author: Akilan

    -

    Created: 2025-04-25 Fri 23:17

    +

    Created: 2025-04-28 Mon 23:14

    Validate

    diff --git a/Docs/index.org b/Docs/index.org index ed74e4f..265680e 100644 --- a/Docs/index.org +++ b/Docs/index.org @@ -4,7 +4,7 @@ #+HTML_HEAD: #+attr_html: :width 300px -[[../artwork/p2prc-logos/Colored-On-Light-Image.png]] +[[./Colored-On-Light-Image.png]] * Guide through video *** The video below shows the setup and usage of P2PRC. @@ -356,6 +356,14 @@ p2prc --mp --dn --ra -------------- +*** Add root node +Adds a root node to P2RRC and overwrites all other nodes in the ip table. +To be only added before the network is started and with +the intention of a fresh instance. +#+begin_example +p2prc --arn --ip -p +#+end_example + * P2P Module Implementation :PROPERTIES: :CUSTOM_ID: p2p-module-implementation diff --git a/cmd/action.go b/cmd/action.go index f9d9578..11b059a 100644 --- a/cmd/action.go +++ b/cmd/action.go @@ -238,7 +238,7 @@ var CliAction = func(ctx *cli.Context) error { func standardOutput(err error, i interface{}) { if err != nil { fmt.Println(err) - } else if i != nil { + } else if i == nil { fmt.Println("Success") } else { client.PrettyPrint(i)