fixed ipv6 dectection error

This commit is contained in:
2021-07-08 19:42:41 +04:00
parent 6f6072f598
commit 28620b61ad
3 changed files with 34 additions and 26 deletions

View File

@@ -12,8 +12,6 @@ var (
"DockerContainers": "/home/akilan/Documents/p2prendering/p2p-redering-computation/server/docker/containers/", "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/", "DefaultDockerFile": "/home/akilan/Documents/p2prendering/p2p-redering-computation/server/docker/containers/docker-ubuntu-sshd/",
"SpeedTestFile":"/etc/p2p-rendering/50.bin", "SpeedTestFile":"/etc/p2p-rendering/50.bin",
"NetworkInterface": "wlp0s20f3",
"NetworkInterfaceIPV6Index": "1",
} }
configName = "config" configName = "config"
configType = "json" configType = "json"
@@ -26,8 +24,9 @@ type Config struct {
DockerContainers string DockerContainers string
DefaultDockerFile string DefaultDockerFile string
SpeedTestFile string SpeedTestFile string
NetworkInterface string IPV6Address string
NetworkInterfaceIPV6Index int //NetworkInterface string
//NetworkInterfaceIPV6Index int
} }
// Exists reports whether the named file or directory exists. // 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["DefaultDockerFile"] = defaultPath + "server/docker/containers/docker-ubuntu-sshd/"
defaults["DockerContainers"] = defaultPath + "server/docker/containers/" defaults["DockerContainers"] = defaultPath + "server/docker/containers/"
defaults["SpeedTestFile"] = defaultPath + "p2p/50.bin" defaults["SpeedTestFile"] = defaultPath + "p2p/50.bin"
defaults["NetworkInterface"] = "wlp0s20f3" defaults["IPV6Address"] = ""
defaults["NetworkInterfaceIPV6Index"] = "2" //defaults["NetworkInterface"] = "wlp0s20f3"
//defaults["NetworkInterfaceIPV6Index"] = "2"
//Paths to search for config file //Paths to search for config file
configPaths = append(configPaths, defaultPath) configPaths = append(configPaths, defaultPath)

View File

@@ -2,8 +2,15 @@
"ip_address": [ "ip_address": [
{ {
"ipv4": "", "ipv4": "",
"ipv6": "2001:8f8:172d:ee93:8105:563b:dc98:6dbf", "ipv6": "2001:8f8:172d:7e27:f1ba:1531:413f:1177",
"latency": 567539, "latency": 435699,
"download": 0,
"upload": 0
},
{
"ipv4": "172.104.44.195",
"ipv6": "",
"latency": 0,
"download": 0, "download": 0,
"upload": 0 "upload": 0
} }

View File

@@ -2,7 +2,6 @@ package p2p
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"git.sr.ht/~akilan1999/p2p-rendering-computation/config" "git.sr.ht/~akilan1999/p2p-rendering-computation/config"
"io/ioutil" "io/ioutil"
@@ -175,23 +174,25 @@ func GetCurrentIPV6()(string,error){
if err != nil { if err != nil {
return "",err 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 // ViewNetworkInterface This function is created to view the network interfaces available
@@ -230,6 +231,6 @@ func Ip4or6(s string) string {
return "version 6" return "version 6"
} }
} }
return "unknown" return "version 6"
} }