diff --git a/.gitignore b/.gitignore index 531dfcf..9f824df 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,7 @@ server/docker/__pycache__ p2p-rendering-computation p2prc config.json -.vscode/ \ No newline at end of file +.vscode/ + +#ignore generated iptables +p2p/iptable/ \ No newline at end of file diff --git a/config/config.go b/config/config.go index c4adc10..c7d54fe 100644 --- a/config/config.go +++ b/config/config.go @@ -2,6 +2,7 @@ package config import ( "github.com/spf13/viper" + "io" "os" ) @@ -39,6 +40,30 @@ func fileExists(name string) bool { return true } +// Copy the src file to dst. Any existing file will be overwritten and will not +// copy file attributes. +// Source: https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file +func Copy(src, dst string) error { + in, err := os.Open(src) + if err != nil { + return err + } + defer in.Close() + + out, err := os.Create(dst) + if err != nil { + return err + } + defer out.Close() + + _, err = io.Copy(out, in) + if err != nil { + return err + } + return out.Close() +} + + // SetDefaults This function to be called only during a // make install func SetDefaults() error { @@ -48,8 +73,15 @@ func SetDefaults() error { //Setting current directory to default path defaultPath = curDir + "/" + //Create ip_table.json in the json directory + err := Copy("p2p/ip_table.json","p2p/iptable/ip_table.json") + if err != nil { + return err + } + + //Setting default paths for the config file - defaults["IPTable"] = defaultPath + "p2p/ip_table.json" + defaults["IPTable"] = defaultPath + "p2p/iptable/ip_table.json" defaults["DefaultDockerFile"] = defaultPath + "server/docker/containers/docker-ubuntu-sshd/" defaults["DockerContainers"] = defaultPath + "server/docker/containers/" defaults["SpeedTestFile"] = defaultPath + "p2p/50.bin" @@ -68,7 +100,7 @@ func SetDefaults() error { } //Calling configuration file - _, err := ConfigInit() + _, err = ConfigInit() if err != nil { return err } diff --git a/p2p/ip_table.json b/p2p/ip_table.json index cdb78ef..f4007c9 100644 --- a/p2p/ip_table.json +++ b/p2p/ip_table.json @@ -1,16 +1,9 @@ { "ip_address": [ - { - "ipv4": "", - "ipv6": "2001:8f8:172d:7e27:f1ba:1531:413f:1177", - "latency": 500894, - "download": 0, - "upload": 0 - }, { "ipv4": "172.104.44.195", "ipv6": "", - "latency": 140786917, + "latency": 0, "download": 0, "upload": 0 } diff --git a/p2p/iptable/.gitkeep b/p2p/iptable/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/p2p/speedtest/speedtest.go b/p2p/speedtest/speedtest.go deleted file mode 100644 index 9aaab28..0000000 --- a/p2p/speedtest/speedtest.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "fmt" - "github.com/showwin/speedtest-go/speedtest" -) - -func main() { - user, _ := speedtest.FetchUserInfo() - - serverList, _ := speedtest.FetchServerList(user) - targets, _ := serverList.FindServer([]int{}) - - for _, s := range targets { - s.PingTest() - s.DownloadTest(false) - s.UploadTest(false) - - fmt.Printf("Latency: %s, Download: %f, Upload: %f\n", s.Latency, s.DLSpeed, s.ULSpeed) - } -} \ No newline at end of file