From 28620b61ad4ba3e6ea763544470bac72c32beff1 Mon Sep 17 00:00:00 2001 From: Akilan Selvacoumar Date: Thu, 8 Jul 2021 19:42:41 +0400 Subject: [PATCH] fixed ipv6 dectection error --- config/config.go | 12 ++++++------ p2p/ip_table.json | 11 +++++++++-- p2p/iptable.go | 37 +++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/config/config.go b/config/config.go index 76f6b65..c4adc10 100644 --- a/config/config.go +++ b/config/config.go @@ -12,8 +12,6 @@ var ( "DockerContainers": "/home/akilan/Documents/p2prendering/p2p-redering-computation/server/docker/containers/", "DefaultDockerFile": "/home/akilan/Documents/p2prendering/p2p-redering-computation/server/docker/containers/docker-ubuntu-sshd/", "SpeedTestFile":"/etc/p2p-rendering/50.bin", - "NetworkInterface": "wlp0s20f3", - "NetworkInterfaceIPV6Index": "1", } configName = "config" configType = "json" @@ -26,8 +24,9 @@ type Config struct { DockerContainers string DefaultDockerFile string SpeedTestFile string - NetworkInterface string - NetworkInterfaceIPV6Index int + IPV6Address string + //NetworkInterface string + //NetworkInterfaceIPV6Index int } // Exists reports whether the named file or directory exists. @@ -54,8 +53,9 @@ func SetDefaults() error { defaults["DefaultDockerFile"] = defaultPath + "server/docker/containers/docker-ubuntu-sshd/" defaults["DockerContainers"] = defaultPath + "server/docker/containers/" defaults["SpeedTestFile"] = defaultPath + "p2p/50.bin" - defaults["NetworkInterface"] = "wlp0s20f3" - defaults["NetworkInterfaceIPV6Index"] = "2" + defaults["IPV6Address"] = "" + //defaults["NetworkInterface"] = "wlp0s20f3" + //defaults["NetworkInterfaceIPV6Index"] = "2" //Paths to search for config file configPaths = append(configPaths, defaultPath) diff --git a/p2p/ip_table.json b/p2p/ip_table.json index 43d7e54..38e0b20 100644 --- a/p2p/ip_table.json +++ b/p2p/ip_table.json @@ -2,8 +2,15 @@ "ip_address": [ { "ipv4": "", - "ipv6": "2001:8f8:172d:ee93:8105:563b:dc98:6dbf", - "latency": 567539, + "ipv6": "2001:8f8:172d:7e27:f1ba:1531:413f:1177", + "latency": 435699, + "download": 0, + "upload": 0 + }, + { + "ipv4": "172.104.44.195", + "ipv6": "", + "latency": 0, "download": 0, "upload": 0 } diff --git a/p2p/iptable.go b/p2p/iptable.go index d7cf46e..69511b7 100644 --- a/p2p/iptable.go +++ b/p2p/iptable.go @@ -2,7 +2,6 @@ package p2p import ( "encoding/json" - "errors" "fmt" "git.sr.ht/~akilan1999/p2p-rendering-computation/config" "io/ioutil" @@ -175,23 +174,25 @@ func GetCurrentIPV6()(string,error){ if err != nil { return "",err } - byNameInterface, err := net.InterfaceByName(Config.NetworkInterface) - if err != nil { - return "",err - } - addresses, err := byNameInterface.Addrs() - if err != nil { - return "",err - } - if addresses[1].String() == "" { - return "",errors.New("IPV6 address not detected") - } - IP,_,err := net.ParseCIDR(addresses[Config.NetworkInterfaceIPV6Index].String()) - if err != nil { - return "",err - } - return IP.String(), nil + // Fix in future release + //byNameInterface, err := net.InterfaceByName(Config.NetworkInterface) + //if err != nil { + // return "",err + //} + //addresses, err := byNameInterface.Addrs() + //if err != nil { + // return "",err + //} + //if addresses[1].String() == "" { + // return "",errors.New("IPV6 address not detected") + //} + //IP,_,err := net.ParseCIDR(addresses[Config.NetworkInterfaceIPV6Index].String()) + //if err != nil { + // return "",err + //} + + return Config.IPV6Address, nil } // ViewNetworkInterface This function is created to view the network interfaces available @@ -230,6 +231,6 @@ func Ip4or6(s string) string { return "version 6" } } - return "unknown" + return "version 6" } \ No newline at end of file