@@ -67,7 +67,8 @@ type MdnsManager struct {
6767
6868 providerSelection MdnsProviderSelection
6969
70- mux sync.Mutex
70+ mux ,
71+ muxAnnounced sync.Mutex
7172}
7273
7374func NewMDNS (
@@ -217,28 +218,45 @@ func (m *MdnsManager) AnnounceMdnsEntry() error {
217218 return err
218219 }
219220
220- m .isAnnounced = true
221+ m .mux .Lock ()
222+ defer m .mux .Unlock ()
223+
224+ m .setIsServiceAnnounce (true )
221225
222226 return nil
223227}
224228
225229// Stop the mDNS announcement on the network
226230func (m * MdnsManager ) UnannounceMdnsEntry () {
227- if ! m .isAnnounced || m .mdnsProvider == nil {
231+ if ! m .isServiceAnnounced () || m .mdnsProvider == nil {
228232 return
229233 }
230234
231235 m .mdnsProvider .Unannounce ()
232236 logging .Log ().Debug ("mdns: stop announcement" )
233237
234- m .isAnnounced = false
238+ m .setIsServiceAnnounce (false )
239+ }
240+
241+ func (m * MdnsManager ) isServiceAnnounced () bool {
242+ m .muxAnnounced .Lock ()
243+ defer m .muxAnnounced .Unlock ()
244+
245+ return m .isAnnounced
246+ }
247+
248+ func (m * MdnsManager ) setIsServiceAnnounce (value bool ) {
249+ m .muxAnnounced .Lock ()
250+ defer m .muxAnnounced .Unlock ()
251+
252+ m .isAnnounced = value
235253}
236254
237255func (m * MdnsManager ) SetAutoAccept (accept bool ) {
238256 m .autoaccept = accept
239257
240258 // if announcement is off, don't enforce a new announcement
241- if ! m .isAnnounced {
259+ if ! m .isServiceAnnounced () {
242260 return
243261 }
244262
@@ -393,7 +411,7 @@ func (m *MdnsManager) processMdnsEntry(elements map[string]string, name, host st
393411 }
394412
395413 entries := m .copyMdnsEntries ()
396- go m .report .ReportMdnsEntries (entries )
414+ go m .report .ReportMdnsEntries (entries , true )
397415}
398416
399417func (m * MdnsManager ) RequestMdnsEntries () {
@@ -402,5 +420,5 @@ func (m *MdnsManager) RequestMdnsEntries() {
402420 }
403421
404422 entries := m .copyMdnsEntries ()
405- go m .report .ReportMdnsEntries (entries )
423+ go m .report .ReportMdnsEntries (entries , false )
406424}
0 commit comments