diff --git a/pkg/visor/visorconfig/values_darwin.go b/pkg/visor/visorconfig/values_darwin.go index c9210d6add..639a275e4b 100644 --- a/pkg/visor/visorconfig/values_darwin.go +++ b/pkg/visor/visorconfig/values_darwin.go @@ -4,11 +4,14 @@ package visorconfig import ( + "net" "os/user" "runtime" + "time" "github.com/google/uuid" "github.com/jaypipes/ghw" + "github.com/zcalusic/sysinfo" "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire/pkg/skyenv" @@ -29,10 +32,12 @@ func UserConfig() skyenv.PkgConfig { // Survey system hardware survey struct type Survey struct { + Timestamp time.Time `json:"timestamp"` PubKey cipher.PubKey `json:"public_key,omitempty"` SkycoinAddress string `json:"skycoin_address,omitempty"` GOOS string `json:"go_os,omitempty"` GOARCH string `json:"go_arch,omitempty"` + SYSINFO customSysinfo `json:"zcalusic_sysinfo,omitempty"` IPAddr string `json:"ip_address,omitempty"` Disks *ghw.BlockInfo `json:"ghw_blockinfo,omitempty"` UUID uuid.UUID `json:"uuid,omitempty"` @@ -47,17 +52,11 @@ func SystemSurvey() (Survey, error) { if err != nil { return Survey{}, err } - // var ipAddr string - // for { - // ipAddr, err = FetchIP(dmsgDisc) - // if err == nil { - // break - // } - // } s := Survey{ - // IPAddr: ipAddr, + Timestamp: time.Now(), GOOS: runtime.GOOS, GOARCH: runtime.GOARCH, + SYSINFO: getMacAddr(), UUID: uuid.New(), Disks: disks, SkywireVersion: Version(), @@ -70,3 +69,25 @@ func IsRoot() bool { userLvl, _ := user.Current() //nolint return userLvl.Username == "root" } + +type customSysinfo struct { + Network []sysinfo.NetworkDevice `json:"network,omitempty"` +} + +func getMacAddr() customSysinfo { + var sysInfo customSysinfo + si := make([]sysinfo.NetworkDevice, 1) + interfaces, err := net.Interfaces() + if err != nil { + return sysInfo + } + + for _, ifa := range interfaces { + si[0].MACAddress = ifa.HardwareAddr.String() + if si[0].MACAddress != "" { + sysInfo.Network = si + return sysInfo + } + } + return sysInfo +} diff --git a/pkg/visor/visorconfig/values_linux.go b/pkg/visor/visorconfig/values_linux.go index fa28c69964..7d24bbb942 100644 --- a/pkg/visor/visorconfig/values_linux.go +++ b/pkg/visor/visorconfig/values_linux.go @@ -64,16 +64,9 @@ func SystemSurvey() (Survey, error) { if err != nil && !strings.Contains(err.Error(), "Could not determine total usable bytes of memory") { return Survey{}, err } - // var ipAddr string - // for { - // ipAddr, err = FetchIP(dmsgDisc) - // if err == nil { - // break - // } - // } + s := Survey{ - Timestamp: time.Now(), - // IPAddr: ipAddr, + Timestamp: time.Now(), GOOS: runtime.GOOS, GOARCH: runtime.GOARCH, SYSINFO: si, diff --git a/pkg/visor/visorconfig/values_windows.go b/pkg/visor/visorconfig/values_windows.go index 29b5cbf053..ecdfacc601 100644 --- a/pkg/visor/visorconfig/values_windows.go +++ b/pkg/visor/visorconfig/values_windows.go @@ -7,6 +7,7 @@ import ( "log" "net" "runtime" + "time" "golang.org/x/sys/windows" @@ -32,11 +33,12 @@ func UserConfig() skyenv.PkgConfig { // Survey system hardware survey struct type Survey struct { + Timestamp time.Time `json:"timestamp"` PubKey cipher.PubKey `json:"public_key,omitempty"` SkycoinAddress string `json:"skycoin_address,omitempty"` GOOS string `json:"go_os,omitempty"` GOARCH string `json:"go_arch,omitempty"` - SYSINFO []NetworkDevice `json:"zcalusic_sysinfo,omitempty"` + SYSINFO customSysinfo `json:"zcalusic_sysinfo,omitempty"` IPAddr string `json:"ip_address,omitempty"` Disks *ghw.BlockInfo `json:"ghw_blockinfo,omitempty"` Product *ghw.ProductInfo `json:"ghw_productinfo,omitempty"` @@ -61,16 +63,9 @@ func SystemSurvey() (Survey, error) { if err != nil { return Survey{}, err } - // var ipAddr string - // for { - // ipAddr, err = FetchIP(dmsgDisc) - // if err == nil { - // break - // } - // } s := Survey{ - // IPAddr: ipAddr, + Timestamp: time.Now(), GOOS: runtime.GOOS, GOARCH: runtime.GOARCH, SYSINFO: getMacAddr(), @@ -83,28 +78,29 @@ func SystemSurvey() (Survey, error) { return s, nil } -type NetworkDevice struct { - Name string `json:"name,omitempty"` - Driver string `json:"driver,omitempty"` +type customSysinfo struct { + Network []networkDevice `json:"network,omitempty"` +} +type networkDevice struct { MACAddress string `json:"macaddress,omitempty"` - Port string `json:"port,omitempty"` - Speed uint `json:"speed,omitempty"` // device max supported speed in Mbps } -func getMacAddr() []NetworkDevice { - si := make([]NetworkDevice, 1) - ifas, err := net.Interfaces() +func getMacAddr() customSysinfo { + var sysInfo customSysinfo + si := make([]networkDevice, 1) + interfaces, err := net.Interfaces() if err != nil { - return nil + return sysInfo } - for _, ifa := range ifas { + for _, ifa := range interfaces { si[0].MACAddress = ifa.HardwareAddr.String() if si[0].MACAddress != "" { - return si + sysInfo.Network = si + return sysInfo } } - return nil + return sysInfo } // IsRoot checks for root permissions