2023-12-13 20:07:22 +01:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2024-01-16 09:27:04 +01:00
|
|
|
"forge.cadoles.com/arcad/arcast/pkg/network"
|
2023-12-13 20:07:22 +01:00
|
|
|
"github.com/grandcat/zeroconf"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/wlynxg/anet"
|
|
|
|
"gitlab.com/wpetit/goweb/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
MDNSService = "_arcast._http._tcp"
|
|
|
|
MDNSDomain = "local."
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) startMDNServer(ctx context.Context) error {
|
|
|
|
logger.Debug(ctx, "starting mdns server")
|
|
|
|
ifaces, err := anet.Interfaces()
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
2024-01-16 09:27:04 +01:00
|
|
|
ips, err := network.GetLANIPv4Addrs()
|
2023-12-13 20:07:22 +01:00
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Debug(ctx, "advertising ips", logger.F("ips", ips))
|
|
|
|
|
|
|
|
server, err := zeroconf.RegisterProxy(s.instanceID, MDNSService, MDNSDomain, s.port, s.instanceID, ips, []string{}, ifaces)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
<-ctx.Done()
|
|
|
|
logger.Debug(ctx, "closing mdns server")
|
|
|
|
server.Shutdown()
|
|
|
|
}()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|