fix abstraction
This commit is contained in:
41
Simulation/simulation.sh
Normal file
41
Simulation/simulation.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
# Spin up seperate P2PRC instances
|
||||
|
||||
# Unset P2PRC
|
||||
unset P2PRC
|
||||
|
||||
|
||||
# Create P2PRC instances
|
||||
# Parameters:
|
||||
# 1. Number of nodes
|
||||
P2PRC_instances() {
|
||||
local rootPort
|
||||
for (( counter=0; counter<$1; counter++ )); do
|
||||
mkdir test-$counter/
|
||||
cd test-$counter/
|
||||
p2prc --dc
|
||||
|
||||
# change port no
|
||||
NEW_PORT=$(shuf -i 2000-65000 -n 1)
|
||||
|
||||
if [ counter == 0 ]; then
|
||||
rootPort = $NEW_PORT
|
||||
fi
|
||||
|
||||
echo $rootPort
|
||||
|
||||
p2prc --arn --ip 0.0.0.0 --port $rootPort
|
||||
|
||||
sed -i.bak "s/\"ServerPort\": \"[0-9]*\"/\"ServerPort\": \"$NEW_PORT\"/" "./config.json"
|
||||
|
||||
p2prc --ls
|
||||
|
||||
cd ..
|
||||
done
|
||||
|
||||
# remove all instances
|
||||
rm -rf test-*
|
||||
}
|
||||
|
||||
P2PRC_instances 2
|
||||
|
||||
|
||||
@@ -1,109 +1,108 @@
|
||||
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"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Init Initialises p2prc
|
||||
func Init(customConfig interface{}) (config *Config.Config, err error) {
|
||||
|
||||
// Get config file path
|
||||
// Checks P2PRC path initially
|
||||
// - Get PATH if environment varaible
|
||||
path, err := Config.GetPathP2PRC("P2PRC")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// check if the config file exists
|
||||
if _, err = os.Stat(path + "config.json"); err != nil {
|
||||
// Initialize with base p2prc config files
|
||||
// set the config file with default paths
|
||||
config, err = generate.SetDefaults("P2PRC", false, customConfig, false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// If the configs are available then use them over generating new ones.
|
||||
config, err = Config.ConfigInit(nil, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
// Get config file path
|
||||
// Checks P2PRC path initially
|
||||
// - Get PATH if environment varaible
|
||||
path, err := Config.GetPathP2PRC("P2PRC")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// check if the config file exists
|
||||
if _, err = os.Stat(path + "config.json"); err != nil {
|
||||
// Initialize with base p2prc config files
|
||||
// set the config file with default paths
|
||||
config, err = generate.SetDefaults("P2PRC", false, customConfig, false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// If the configs are available then use them over generating new ones.
|
||||
config, err = Config.ConfigInit(nil, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
engine, err := server.Server()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
// MapPort Creates a reverse proxy connection and maps the appropriate port
|
||||
func MapPort(port string, domainName string, serverAddress string) (response *client.ResponseMAPPort, err error) {
|
||||
response, err = client.MAPPort(port, domainName, serverAddress)
|
||||
return
|
||||
response, err = client.MAPPort(port, domainName, serverAddress)
|
||||
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
|
||||
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)
|
||||
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
|
||||
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
|
||||
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()
|
||||
return clientIPTable.UpdateIpTableListClient()
|
||||
}
|
||||
|
||||
// AddCustomInformation allows to pass custom information
|
||||
// through the network to which can be listened on
|
||||
// all peers in the network to execute a task.
|
||||
func AddCustomInformation(information string) error {
|
||||
return clientIPTable.AddCustomInformationToIPTable(information)
|
||||
return clientIPTable.AddCustomInformationToIPTable(information)
|
||||
}
|
||||
|
||||
// AddRootNode Adds root node to the network by using defaults except for
|
||||
// ip address and port no. Supports only IPV4 as of now.
|
||||
func AddRootNode(rootIP string, portNo string) error {
|
||||
var rootNode []p2p.IpAddress
|
||||
var rootNode []p2p.IpAddress
|
||||
|
||||
rootNode = append(rootNode, p2p.IpAddress{
|
||||
Name: "",
|
||||
Ipv4: rootIP,
|
||||
ServerPort: portNo,
|
||||
NAT: false,
|
||||
})
|
||||
return generate.GenerateIPTableFile(rootNode)
|
||||
rootNode = append(rootNode, p2p.IpAddress{
|
||||
Name: "",
|
||||
Ipv4: rootIP,
|
||||
ServerPort: portNo,
|
||||
NAT: false,
|
||||
})
|
||||
return generate.GenerateIPTableFile(rootNode)
|
||||
}
|
||||
|
||||
BIN
p2prc.wasm
Executable file
BIN
p2prc.wasm
Executable file
Binary file not shown.
BIN
wasm/p2prc.wasm
Executable file
BIN
wasm/p2prc.wasm
Executable file
Binary file not shown.
Reference in New Issue
Block a user