added language bindings, python implementation and docs for the feature add

root node
This commit is contained in:
2025-04-28 23:15:35 +01:00
parent 51b253df15
commit 2283736cc6
7 changed files with 201 additions and 152 deletions

View File

@@ -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() {}

View File

@@ -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.

View File

@@ -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")