Audit changes.
This commit is contained in:
@@ -26,11 +26,19 @@ var mcAddr = net.UDPAddrFromAddrPort(netip.AddrPortFrom(
|
||||
// RunMCWriter broadcasts a signed beacon on the local multicast group every
|
||||
// mcBroadcastInterval so that LAN peers can discover our WireGuard endpoint.
|
||||
func RunMCWriter(selfVPNIP netip.Addr, pubKey wgtypes.Key, wgPort uint16, signKey *[64]byte) {
|
||||
for {
|
||||
runMCWriterInner(selfVPNIP, pubKey, wgPort, signKey)
|
||||
time.Sleep(mcErrorRetryInterval)
|
||||
}
|
||||
}
|
||||
|
||||
func runMCWriterInner(selfVPNIP netip.Addr, pubKey wgtypes.Key, wgPort uint16, signKey *[64]byte) {
|
||||
conn, err := net.ListenMulticastUDP("udp", nil, mcAddr)
|
||||
if err != nil {
|
||||
log.Printf("[MCWriter] bind: %v", err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
payload := buildBeacon(selfVPNIP, pubKey, wgPort)
|
||||
signed := sign.Sign(nil, payload, signKey)
|
||||
@@ -38,9 +46,11 @@ func RunMCWriter(selfVPNIP netip.Addr, pubKey wgtypes.Key, wgPort uint16, signKe
|
||||
if _, err := conn.WriteToUDP(signed, mcAddr); err != nil {
|
||||
log.Printf("[MCWriter] write: %v", err)
|
||||
}
|
||||
|
||||
for range time.Tick(mcBroadcastInterval) {
|
||||
if _, err := conn.WriteToUDP(signed, mcAddr); err != nil {
|
||||
log.Printf("[MCWriter] write: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user