3 Commits

Author SHA1 Message Date
ce7fa2ccf3 Haskell bindings 2024-09-30 18:22:05 +01:00
4115451875 Haskell bindings 2024-09-30 18:21:50 +01:00
3a40e687a5 work in progress haskell bindings 2024-07-26 21:48:04 +01:00
2 changed files with 25 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ package main
import "C" import "C"
import ( import (
"encoding/json" "encoding/json"
"fmt"
"time" "time"
"github.com/Akilan1999/p2p-rendering-computation/abstractions" "github.com/Akilan1999/p2p-rendering-computation/abstractions"
@@ -17,8 +18,8 @@ import (
// --------------------------------- Container Control ---------------------------------------- // --------------------------------- Container Control ----------------------------------------
//export StartContainer //export StartContainer
func StartContainer(IP string) (output *C.char) { func StartContainer(IP *C.char) (output *C.char) {
container, err := abstractions.StartContainer(IP) container, err := abstractions.StartContainer(C.GoString(IP))
if err != nil { if err != nil {
return C.CString(err.Error()) return C.CString(err.Error())
} }
@@ -26,8 +27,8 @@ func StartContainer(IP string) (output *C.char) {
} }
//export RemoveContainer //export RemoveContainer
func RemoveContainer(IP string, ID string) (output *C.char) { func RemoveContainer(IP *C.char, ID *C.char) (output *C.char) {
err := abstractions.RemoveContainer(IP, ID) err := abstractions.RemoveContainer(C.GoString(IP), C.GoString(ID))
if err != nil { if err != nil {
return C.CString(err.Error()) return C.CString(err.Error())
} }
@@ -76,8 +77,8 @@ func RemoveContainer(IP string, ID string) (output *C.char) {
// --------------------------------- Get Specs ---------------------------------------- // --------------------------------- Get Specs ----------------------------------------
//export GetSpecs //export GetSpecs
func GetSpecs(IP string) (output *C.char) { func GetSpecs(IP *C.char) (output *C.char) {
specs, err := abstractions.GetSpecs(IP) specs, err := abstractions.GetSpecs(C.GoString(IP))
if err != nil { if err != nil {
return C.CString(err.Error()) return C.CString(err.Error())
} }
@@ -85,13 +86,12 @@ func GetSpecs(IP string) (output *C.char) {
} }
//export Init //export Init
func Init(customConfig string) (output *C.char) { func Init(customConfig *C.char) (output *C.char) {
init, err := abstractions.Init(customConfig) init, err := abstractions.Init(C.GoString(customConfig))
if err != nil { if err != nil {
return C.CString(err.Error()) return C.CString(err.Error())
} }
return ConvertStructToJSONString(init) return ConvertStructToJSONString(init)
} }
// --------------------------------- P2P Controls ----------------------------------- // --------------------------------- P2P Controls -----------------------------------
@@ -115,9 +115,9 @@ func UpdateIPTable() (output *C.char) {
} }
//export EscapeFirewall //export EscapeFirewall
func EscapeFirewall(HostOutsideNATIP string, HostOutsideNATPort string, internalPort string) (output *C.char) { func EscapeFirewall(HostOutsideNATIP *C.char, HostOutsideNATPort *C.char, internalPort *C.char) (output *C.char) {
// Get free port from P2PRC server node // Get free port from P2PRC server node
serverPort, err := frp.GetFRPServerPort("http://" + HostOutsideNATIP + ":" + HostOutsideNATPort) serverPort, err := frp.GetFRPServerPort("http://" + C.GoString(HostOutsideNATIP) + ":" + C.GoString(HostOutsideNATPort))
if err != nil { if err != nil {
return C.CString(err.Error()) return C.CString(err.Error())
@@ -125,7 +125,7 @@ func EscapeFirewall(HostOutsideNATIP string, HostOutsideNATPort string, internal
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
ExposedPort, err := frp.StartFRPClientForServer(HostOutsideNATIP+":"+HostOutsideNATPort, serverPort, internalPort, "") ExposedPort, err := frp.StartFRPClientForServer(C.GoString(HostOutsideNATIP)+":"+C.GoString(HostOutsideNATPort), serverPort, C.GoString(internalPort), "")
if err != nil { if err != nil {
return C.CString(err.Error()) return C.CString(err.Error())
} }
@@ -134,8 +134,9 @@ func EscapeFirewall(HostOutsideNATIP string, HostOutsideNATPort string, internal
} }
//export MapPort //export MapPort
func MapPort(Port string) *C.char { func MapPort(Port *C.char) *C.char {
entireAddress, _, err := abstractions.MapPort(Port) fmt.Println(C.GoString(Port))
entireAddress, _, err := abstractions.MapPort(C.GoString(Port))
if err != nil { if err != nil {
return C.CString(err.Error()) return C.CString(err.Error())
} }

View File

@@ -68,7 +68,7 @@ USAGE:
p2prc [global options] command [command options] [arguments...] p2prc [global options] command [command options] [arguments...]
VERSION: VERSION:
<version no> 2.0.0
COMMANDS: COMMANDS:
help, h Shows a list of commands or help for one command help, h Shows a list of commands or help for one command
@@ -81,6 +81,7 @@ GLOBAL OPTIONS:
--ViewImages value, --vi value View images available on the server IP address [$VIEW_IMAGES] --ViewImages value, --vi value View images available on the server IP address [$VIEW_IMAGES]
--CreateVM value, --touch value Creates Docker container on the selected server [$CREATE_VM] --CreateVM value, --touch value Creates Docker container on the selected server [$CREATE_VM]
--ContainerName value, --cn value Specifying the container run on the server side [$CONTAINER_NAME] --ContainerName value, --cn value Specifying the container run on the server side [$CONTAINER_NAME]
--BaseImage value, --bi value Specifying the docker base image to template the dockerfile [$CONTAINER_NAME]
--RemoveVM value, --rm value Stop and Remove Docker container (IP:port) accompanied by container ID via --ID or --id [$REMOVE_VM] --RemoveVM value, --rm value Stop and Remove Docker container (IP:port) accompanied by container ID via --ID or --id [$REMOVE_VM]
--ID value, --id value Docker Container ID [$ID] --ID value, --id value Docker Container ID [$ID]
--Ports value, -p value Number of ports to open for the Docker Container [$NUM_PORTS] --Ports value, -p value Number of ports to open for the Docker Container [$NUM_PORTS]
@@ -96,10 +97,13 @@ GLOBAL OPTIONS:
--Groups, --groups View all groups (default: false) [$GROUPS] --Groups, --groups View all groups (default: false) [$GROUPS]
--RemoveContainerGroup, --rmcgroup Remove specific container in the group (default: false) [$REMOVE_CONTAINER_GROUP] --RemoveContainerGroup, --rmcgroup Remove specific container in the group (default: false) [$REMOVE_CONTAINER_GROUP]
--RemoveGroup value, --rmgroup value Removes the entire group [$REMOVE_GROUP] --RemoveGroup value, --rmgroup value Removes the entire group [$REMOVE_GROUP]
--MAPPort value, --mp value Maps port for a specific port provided as the parameter [$MAPPORT]
--DomainName value, --dn value While mapping ports allows to set a domain name to create a mapping in the proxy server [$DOMAINNAME]
--Generate value, --gen value Generates a new copy of P2PRC which can be modified based on your needs [$GENERATE] --Generate value, --gen value Generates a new copy of P2PRC which can be modified based on your needs [$GENERATE]
--ModuleName value, --mod value New go project module name [$MODULENAME] --ModuleName value, --mod value New go project module name [$MODULENAME]
--PullPlugin value, --pp value Pulls plugin from git repos [$PULLPLUGIN] --PullPlugin value, --pp value Pulls plugin from git repos [$PULLPLUGIN]
--RemovePlugin value, --rp value Removes plugin [$REMOVEPLUGIN] --RemovePlugin value, --rp value Removes plugin [$REMOVEPLUGIN]
--AddMetaData value, --amd value Adds metadata about the current node in the p2p network which is then propagated through the network [$ADDMETADATA]
--help, -h show help (default: false) --help, -h show help (default: false)
--version, -v print the version (default: false) --version, -v print the version (default: false)
@@ -213,6 +217,11 @@ p2prc --rp <plugin name>
p2prc --amd "custom metadata" p2prc --amd "custom metadata"
``` ```
### Map port
```
p2prc --mp <internal port no from your machine> --dn <domain name you want the port linked to>
```
<br> <br>
-------------- --------------