Files
cunicu/pkg/core/interface_list.go
Steffen Vogel dad8d5996b update Go module path
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
2022-09-08 17:42:12 +02:00

33 lines
569 B
Go

package core
import (
"github.com/stv0g/cunicu/pkg/crypto"
)
// InterfaceList stores all WireGuard interfaces indexed by their unique ifindex
type InterfaceList map[string]*Interface
func (l *InterfaceList) ByIndex(index int) *Interface {
for _, i := range *l {
if i.KernelDevice.Index() == index {
return i
}
}
return nil
}
func (l *InterfaceList) ByName(name string) *Interface {
return (*l)[name]
}
func (l *InterfaceList) ByPublicKey(pk crypto.Key) *Interface {
for _, i := range *l {
if i.PublicKey() == pk {
return i
}
}
return nil
}