mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-01-11 18:43:43 +00:00
New detail in getMulticastInterfaces
admin endpoint
This commit is contained in:
parent
d3b4de46ea
commit
7790a19e4c
@ -281,9 +281,21 @@ func run() int {
|
|||||||
if err := json.Unmarshal(recv.Response, &resp); err != nil {
|
if err := json.Unmarshal(recv.Response, &resp); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
table.SetHeader([]string{"Interface"})
|
fmtBool := func(b bool) string {
|
||||||
|
if b {
|
||||||
|
return "Yes"
|
||||||
|
}
|
||||||
|
return "-"
|
||||||
|
}
|
||||||
|
table.SetHeader([]string{"Name", "Listen Address", "Beacon", "Listen", "Password"})
|
||||||
for _, p := range resp.Interfaces {
|
for _, p := range resp.Interfaces {
|
||||||
table.Append([]string{p})
|
table.Append([]string{
|
||||||
|
p.Name,
|
||||||
|
p.Address,
|
||||||
|
fmtBool(p.Beacon),
|
||||||
|
fmtBool(p.Listen),
|
||||||
|
fmtBool(p.Password),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
table.Render()
|
table.Render()
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ package config
|
|||||||
func getDefaults() platformDefaultParameters {
|
func getDefaults() platformDefaultParameters {
|
||||||
return platformDefaultParameters{
|
return platformDefaultParameters{
|
||||||
// Admin
|
// Admin
|
||||||
DefaultAdminListen: "tcp://localhost:9001",
|
DefaultAdminListen: "unix:///var/run/yggdrasil.sock",
|
||||||
|
|
||||||
// Configuration (used for yggdrasilctl)
|
// Configuration (used for yggdrasilctl)
|
||||||
DefaultConfigFile: "/etc/yggdrasil.conf",
|
DefaultConfigFile: "/etc/yggdrasil.conf",
|
||||||
|
@ -2,20 +2,47 @@ package multicast
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Arceliar/phony"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
|
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetMulticastInterfacesRequest struct{}
|
type GetMulticastInterfacesRequest struct{}
|
||||||
type GetMulticastInterfacesResponse 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 {
|
func (m *Multicast) getMulticastInterfacesHandler(_ *GetMulticastInterfacesRequest, res *GetMulticastInterfacesResponse) error {
|
||||||
res.Interfaces = []string{}
|
res.Interfaces = []MulticastInterfaceState{}
|
||||||
for _, v := range m.Interfaces() {
|
phony.Block(m, func() {
|
||||||
res.Interfaces = append(res.Interfaces, v.Name)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,13 @@ func (m *Multicast) _updateInterfaces() {
|
|||||||
delete(interfaces, name)
|
delete(interfaces, name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
info.addrs = addrs
|
for _, addr := range addrs {
|
||||||
|
addrIP, _, err := net.ParseCIDR(addr.String())
|
||||||
|
if err != nil || addrIP.To4() != nil || !addrIP.IsLinkLocalUnicast() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
info.addrs = append(info.addrs, addr)
|
||||||
|
}
|
||||||
interfaces[name] = info
|
interfaces[name] = info
|
||||||
m.log.Debugf("Discovered addresses for interface %s: %s", name, addrs)
|
m.log.Debugf("Discovered addresses for interface %s: %s", name, addrs)
|
||||||
}
|
}
|
||||||
@ -299,13 +305,9 @@ func (m *Multicast) _announce() {
|
|||||||
for _, info := range m._interfaces {
|
for _, info := range m._interfaces {
|
||||||
iface := info.iface
|
iface := info.iface
|
||||||
for _, addr := range info.addrs {
|
for _, addr := range info.addrs {
|
||||||
addrIP, _, _ := net.ParseCIDR(addr.String())
|
addrIP, _, err := net.ParseCIDR(addr.String())
|
||||||
// Ignore IPv4 addresses
|
// Ignore IPv4 addresses or non-link-local addresses
|
||||||
if addrIP.To4() != nil {
|
if err != nil || addrIP.To4() != nil || !addrIP.IsLinkLocalUnicast() {
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Ignore non-link-local addresses
|
|
||||||
if !addrIP.IsLinkLocalUnicast() {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if info.listen {
|
if info.listen {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user