diff --git a/Bindings/Client.go b/Bindings/Client.go index 692fec7..5c6fea2 100644 --- a/Bindings/Client.go +++ b/Bindings/Client.go @@ -6,12 +6,7 @@ import ( "time" "github.com/Akilan1999/p2p-rendering-computation/abstractions" - "github.com/Akilan1999/p2p-rendering-computation/client" - "github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable" - "github.com/Akilan1999/p2p-rendering-computation/p2p" "github.com/Akilan1999/p2p-rendering-computation/p2p/frp" - "github.com/Akilan1999/p2p-rendering-computation/plugin" - "github.com/Akilan1999/p2p-rendering-computation/server" ) // The Client package where data-types @@ -23,7 +18,7 @@ import ( //export StartContainer func StartContainer(IP string) (output *C.char) { - container, err := client.StartContainer(IP, 0, false, "", "") + container, err := abstractions.StartContainer(IP) if err != nil { return C.CString(err.Error()) } @@ -32,7 +27,7 @@ func StartContainer(IP string) (output *C.char) { //export RemoveContainer func RemoveContainer(IP string, ID string) (output *C.char) { - err := client.RemoveContianer(IP, ID) + err := abstractions.RemoveContainer(IP, ID) if err != nil { return C.CString(err.Error()) } @@ -41,47 +36,48 @@ func RemoveContainer(IP string, ID string) (output *C.char) { // --------------------------------- Plugin Control ---------------------------------------- -//export ViewPlugin -func ViewPlugin() (output *C.char) { - plugins, err := plugin.DetectPlugins() - if err != nil { - return C.CString(err.Error()) - } - return ConvertStructToJSONString(plugins) -} - -//export PullPlugin -func PullPlugin(pluginUrl string) (output *C.char) { - err := plugin.DownloadPlugin(pluginUrl) - if err != nil { - return C.CString(err.Error()) - } - return C.CString("Success") -} - -//export DeletePlugin -func DeletePlugin(pluginName string) (output *C.char) { - err := plugin.DeletePlugin(pluginName) - if err != nil { - return C.CString(err.Error()) - } - return C.CString("Success") -} - -//export ExecutePlugin -func ExecutePlugin(pluginname string, ContainerID string) (output *C.char) { - err := plugin.RunPluginContainer(pluginname, ContainerID) - if err != nil { - return C.CString(err.Error()) - } - return C.CString("Success") -} +// DEPRECATED +////export ViewPlugin +//func ViewPlugin() (output *C.char) { +// plugins, err := plugin.DetectPlugins() +// if err != nil { +// return C.CString(err.Error()) +// } +// return ConvertStructToJSONString(plugins) +//} +// +////export PullPlugin +//func PullPlugin(pluginUrl string) (output *C.char) { +// err := plugin.DownloadPlugin(pluginUrl) +// if err != nil { +// return C.CString(err.Error()) +// } +// return C.CString("Success") +//} +// +////export DeletePlugin +//func DeletePlugin(pluginName string) (output *C.char) { +// err := plugin.DeletePlugin(pluginName) +// if err != nil { +// return C.CString(err.Error()) +// } +// return C.CString("Success") +//} +// +////export ExecutePlugin +//func ExecutePlugin(pluginname string, ContainerID string) (output *C.char) { +// err := plugin.RunPluginContainer(pluginname, ContainerID) +// if err != nil { +// return C.CString(err.Error()) +// } +// return C.CString("Success") +//} // --------------------------------- Get Specs ---------------------------------------- //export GetSpecs func GetSpecs(IP string) (output *C.char) { - specs, err := client.GetSpecs(IP) + specs, err := abstractions.GetSpecs(IP) if err != nil { return C.CString(err.Error()) } @@ -102,7 +98,7 @@ func Init(customConfig string) (output *C.char) { //export ViewIPTable func ViewIPTable() (output *C.char) { - table, err := p2p.ReadIpTable() + table, err := abstractions.ViewIPTable() if err != nil { return C.CString(err.Error()) } @@ -111,7 +107,7 @@ func ViewIPTable() (output *C.char) { //export UpdateIPTable func UpdateIPTable() (output *C.char) { - err := clientIPTable.UpdateIpTableListClient() + err := abstractions.UpdateIPTable() if err != nil { return C.CString(err.Error()) } @@ -139,18 +135,18 @@ func EscapeFirewall(HostOutsideNATIP string, HostOutsideNATPort string, internal //export MapPort func MapPort(Port string) *C.char { - port, err := abstractions.MapPort(Port) + entireAddress, _, err := abstractions.MapPort(Port) if err != nil { return C.CString(err.Error()) } - return C.CString(port) + return C.CString(entireAddress) } // --------------------------------- Controlling Server ---------------------------------------- //export Server func Server() (output *C.char) { - _, err := server.Server() + _, err := abstractions.Start() if err != nil { return C.CString(err.Error()) } diff --git a/Docs/Abstractions.md b/Docs/Abstractions.md index 9817ec2..7c9b806 100644 --- a/Docs/Abstractions.md +++ b/Docs/Abstractions.md @@ -8,6 +8,12 @@ The Abstractions package consists of black-boxed functions for P2PRC. ## Functions - ```Init()```: Initializes P2PRC with all the needed configurations. - ```Start()```: Starts p2prc as a server and makes it possible to extend by adding other routes and functionality to P2PRC. +- ```MapPort()```: On the local machine the port you want to export to world. +- ```StartContainer()```: The machine on the p2p network where you want to spin up a docker container. +- ```RemoveContainer(,)```: Terminate container based on the IP address and container name. +- ```GetSpecs()```: Get specs of a machine on the network based on the IP address. +- ```ViewIPTable()```: View the IP table which about nodes in the network. +- ```UpdateIPTable()```: Force update IP table to learn about new nodes faster. --- diff --git a/abstractions/base.go b/abstractions/base.go index 9986b91..0e9ff15 100644 --- a/abstractions/base.go +++ b/abstractions/base.go @@ -1,9 +1,14 @@ package abstractions +import "C" import ( + "github.com/Akilan1999/p2p-rendering-computation/client" + "github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable" Config "github.com/Akilan1999/p2p-rendering-computation/config" "github.com/Akilan1999/p2p-rendering-computation/config/generate" + "github.com/Akilan1999/p2p-rendering-computation/p2p" "github.com/Akilan1999/p2p-rendering-computation/server" + "github.com/Akilan1999/p2p-rendering-computation/server/docker" "github.com/gin-gonic/gin" "os" ) @@ -46,7 +51,38 @@ func Start() (*gin.Engine, error) { return engine, nil } +// MapPort Creates a reverse proxy connection and maps the appropriate port func MapPort(port string) (entireAddres string, mapPort string, err error) { entireAddres, mapPort, err = server.MapPort(port) return } + +// StartContainer Starts docker container on the remote machine +func StartContainer(IP string) (container *docker.DockerVM, err error) { + container, err = client.StartContainer(IP, 0, false, "", "") + return +} + +// RemoveContainer Removes docker container based on the IP address and ID +// provided +func RemoveContainer(IP string, ID string) error { + return client.RemoveContianer(IP, ID) +} + +// GetSpecs Get spec information about the remote server +func GetSpecs(IP string) (specs *server.SysInfo, err error) { + specs, err = client.GetSpecs(IP) + return +} + +// ViewIPTable View information of nodes in the network +func ViewIPTable() (table *p2p.IpAddresses, err error) { + table, err = p2p.ReadIpTable() + return +} + +// UpdateIPTable Force updates IP tables based on new +// new nodes discovered in the network +func UpdateIPTable() (err error) { + return clientIPTable.UpdateIpTableListClient() +}