mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
New detail in getMulticastInterfaces
admin endpoint
This commit is contained in:
parent
d3b4de46ea
commit
7790a19e4c
4 changed files with 57 additions and 16 deletions
|
@ -2,20 +2,47 @@ package multicast
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/Arceliar/phony"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
|
||||
)
|
||||
|
||||
type GetMulticastInterfacesRequest struct{}
|
||||
type GetMulticastInterfacesResponse struct {
|
||||
Interfaces []string `json:"multicast_interfaces"`
|
||||
Interfaces []MulticastInterfaceState `json:"multicast_interfaces"`
|
||||
}
|
||||
|
||||
type MulticastInterfaceState struct {
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
Beacon bool `json:"beacon"`
|
||||
Listen bool `json:"listen"`
|
||||
Password bool `json:"password"`
|
||||
}
|
||||
|
||||
func (m *Multicast) getMulticastInterfacesHandler(_ *GetMulticastInterfacesRequest, res *GetMulticastInterfacesResponse) error {
|
||||
res.Interfaces = []string{}
|
||||
for _, v := range m.Interfaces() {
|
||||
res.Interfaces = append(res.Interfaces, v.Name)
|
||||
}
|
||||
res.Interfaces = []MulticastInterfaceState{}
|
||||
phony.Block(m, func() {
|
||||
for name, intf := range m._interfaces {
|
||||
is := MulticastInterfaceState{
|
||||
Name: intf.iface.Name,
|
||||
Beacon: intf.beacon,
|
||||
Listen: intf.listen,
|
||||
Password: len(intf.password) > 0,
|
||||
}
|
||||
if li := m._listeners[name]; li != nil && li.listener != nil {
|
||||
is.Address = li.listener.Addr().String()
|
||||
} else {
|
||||
is.Address = "-"
|
||||
}
|
||||
res.Interfaces = append(res.Interfaces, is)
|
||||
}
|
||||
})
|
||||
slices.SortStableFunc(res.Interfaces, func(a, b MulticastInterfaceState) int {
|
||||
return strings.Compare(a.Name, b.Name)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue