modifed shared object calls for python bindings
This commit is contained in:
@@ -7,8 +7,10 @@ import (
|
||||
"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"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The Client package where data-types
|
||||
@@ -19,8 +21,8 @@ import (
|
||||
// --------------------------------- Container Control ----------------------------------------
|
||||
|
||||
//export StartContainer
|
||||
func StartContainer(IP string, NumPorts int, GPU bool, ContainerName string, baseImage string) (output *C.char) {
|
||||
container, err := client.StartContainer(IP, NumPorts, GPU, ContainerName, baseImage)
|
||||
func StartContainer(IP string) (output *C.char) {
|
||||
container, err := client.StartContainer(IP, 0, false, "", "")
|
||||
if err != nil {
|
||||
return C.CString(err.Error())
|
||||
}
|
||||
@@ -115,6 +117,34 @@ func UpdateIPTable() (output *C.char) {
|
||||
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)
|
||||
|
||||
if err != nil {
|
||||
return C.CString(err.Error())
|
||||
}
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
ExposedPort, err := frp.StartFRPClientForServer(HostOutsideNATIP+":"+HostOutsideNATPort, serverPort, internalPort, "")
|
||||
if err != nil {
|
||||
return C.CString(err.Error())
|
||||
}
|
||||
|
||||
return C.CString(ExposedPort)
|
||||
}
|
||||
|
||||
//export MapPort
|
||||
func MapPort(Port string) *C.char {
|
||||
port, err := abstractions.MapPort(Port)
|
||||
if err != nil {
|
||||
return C.CString(err.Error())
|
||||
}
|
||||
return C.CString(port)
|
||||
}
|
||||
|
||||
// --------------------------------- Controlling Server ----------------------------------------
|
||||
|
||||
//export Server
|
||||
|
||||
BIN
Bindings/python/.DS_Store
vendored
Normal file
BIN
Bindings/python/.DS_Store
vendored
Normal file
Binary file not shown.
32
abstractions/base.go
Normal file
32
abstractions/base.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package abstractions
|
||||
|
||||
import (
|
||||
"github.com/Akilan1999/p2p-rendering-computation/config"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/server"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Init Initialises p2prc
|
||||
func Init(customConfig interface{}) (config *config.Config, err error) {
|
||||
// set the config file with default paths
|
||||
config, err = generate.SetDefaults("P2PRC", false, customConfig, false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Start p2prc in a server mode
|
||||
func Start() (*gin.Engine, error) {
|
||||
engine, err := server.Server()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
func MapPort(port string) (mapPort string, err error) {
|
||||
mapPort, err = server.MapPort(port)
|
||||
return
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package abstractions
|
||||
|
||||
import (
|
||||
"github.com/Akilan1999/p2p-rendering-computation/config"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/server"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Init Initialises p2prc
|
||||
func Init(customConfig interface{}) (config *config.Config, err error) {
|
||||
// set the config file with default paths
|
||||
config, err = generate.SetDefaults("P2PRC", false, customConfig, false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Start p2prc in a server mode
|
||||
func Start() (*gin.Engine, error) {
|
||||
engine, err := server.Server()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return engine, nil
|
||||
}
|
||||
BIN
artwork/.DS_Store
vendored
Normal file
BIN
artwork/.DS_Store
vendored
Normal file
Binary file not shown.
@@ -239,3 +239,60 @@ func Server() (*gin.Engine, error) {
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func MapPort(port string) (string, error) {
|
||||
//Get Server port based on the config file
|
||||
config, err := config.ConfigInit(nil, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// update IPTable with new port and ip address and update ip table
|
||||
var ProxyIpAddr p2p.IpAddress
|
||||
var lowestLatencyIpAddress p2p.IpAddress
|
||||
|
||||
clientIPTable.RemoveOfflineNodes()
|
||||
|
||||
table, err := p2p.ReadIpTable()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var lowestLatency int64
|
||||
// random large number
|
||||
lowestLatency = 10000000
|
||||
|
||||
for i, _ := range table.IpAddress {
|
||||
// Checks if the ping is the lowest and if the following node is acting as a proxy
|
||||
//if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && table.IpAddress[i].ProxyPort != "" {
|
||||
if table.IpAddress[i].Latency.Milliseconds() < lowestLatency && table.IpAddress[i].NAT != "" {
|
||||
lowestLatency = table.IpAddress[i].Latency.Milliseconds()
|
||||
lowestLatencyIpAddress = table.IpAddress[i]
|
||||
}
|
||||
}
|
||||
|
||||
// If there is an identified node
|
||||
if lowestLatency != 10000000 {
|
||||
serverPort, err := frp.GetFRPServerPort("http://" + lowestLatencyIpAddress.Ipv4 + ":" + lowestLatencyIpAddress.ServerPort)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// Create 3 second delay to allow FRP server to start
|
||||
time.Sleep(1 * time.Second)
|
||||
// Starts FRP as a client with
|
||||
proxyPort, err := frp.StartFRPClientForServer(lowestLatencyIpAddress.Ipv4, serverPort, port, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// updating with the current proxy address
|
||||
ProxyIpAddr.Ipv4 = lowestLatencyIpAddress.Ipv4
|
||||
ProxyIpAddr.ServerPort = proxyPort
|
||||
ProxyIpAddr.Name = config.MachineName
|
||||
ProxyIpAddr.NAT = "False"
|
||||
ProxyIpAddr.EscapeImplementation = "FRP"
|
||||
//ProxyIpAddr.CustomInformationKey = p2p.GenerateHashSHA256(config.IPTableKey)
|
||||
}
|
||||
|
||||
return ProxyIpAddr.Ipv4 + ":" + ProxyIpAddr.ServerPort, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user