1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-08 05:47:07 +09:00

WIP periodic interface check

This commit is contained in:
mcrakhman 2023-04-25 18:17:59 +02:00 committed by Mikhail Iudin
parent 95d33a9137
commit cf5be48dce
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0
6 changed files with 80 additions and 58 deletions

44
net/addrs/common.go Normal file
View file

@ -0,0 +1,44 @@
package addrs
import (
"golang.org/x/exp/slices"
"net"
)
type Interface struct {
net.Interface
Addrs []InterfaceAddr
}
type InterfaceAddr struct {
Ip []byte
Prefix int
}
type InterfacesAddrs struct {
Interfaces []net.Interface
Addrs []net.Addr
}
func (i InterfacesAddrs) Equal(other InterfacesAddrs) bool {
if len(other.Interfaces) != len(i.Interfaces) {
return false
}
if len(other.Addrs) != len(i.Addrs) {
return false
}
myStr := getStrings(i)
otherStr := getStrings(other)
return slices.Equal(myStr, otherStr)
}
func getStrings(i InterfacesAddrs) (allStrings []string) {
for _, i := range i.Interfaces {
allStrings = append(allStrings, i.Name)
}
for _, i := range i.Addrs {
allStrings = append(allStrings, i.String())
}
slices.Sort(allStrings)
return
}

View file

@ -9,21 +9,6 @@ func SetInterfaceAddrsGetter(getter InterfaceAddrsGetter) {}
func SetInterfaceGetter(getter InterfaceGetter) {}
type Interface struct {
net.Interface
Addrs []InterfaceAddr
}
type InterfaceAddr struct {
Ip []byte
Prefix int
}
type InterfacesAddrs struct {
Interfaces []net.Interface
Addrs []net.Addr
}
type InterfaceGetter interface {
Interfaces() []Interface
}

View file

@ -22,21 +22,6 @@ func SetInterfaceGetter(getter InterfaceGetter) {
interfaceGetter = getter
}
type InterfaceAddr struct {
Ip []byte
Prefix int
}
type Interface struct {
net.Interface
Addrs []InterfaceAddr
}
type InterfacesAddrs struct {
Interfaces []net.Interface
Addrs []net.Addr
}
type InterfaceGetter interface {
Interfaces() []Interface
}