Skip to content

Commit a6f0e03

Browse files
committed
Merge branch 'release/v0.5.3'
2 parents 23931b8 + 9cd4550 commit a6f0e03

22 files changed

+75
-44
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# ship-go
22

3-
[![Build Status](https://github.com/enbility/ship-go/actions/workflows/default.yml/badge.svg?branch=main)](https://github.com/enbility/ship-go/actions/workflows/default.yml/badge.svg?branch=main)
3+
[![Build Status](https://github.com/enbility/ship-go/actions/workflows/default.yml/badge.svg?branch=master)](https://github.com/enbility/ship-go/actions/workflows/default.yml/badge.svg?branch=master)
44
[![GoDoc](https://img.shields.io/badge/godoc-reference-5272B4)](https://godoc.org/github.com/enbility/ship-go)
5-
[![Coverage Status](https://coveralls.io/repos/github/enbility/ship-go/badge.svg?branch=main)](https://coveralls.io/github/enbility/ship-go?branch=main)
5+
[![Coverage Status](https://coveralls.io/repos/github/enbility/ship-go/badge.svg?branch=master)](https://coveralls.io/github/enbility/ship-go?branch=master)
66
[![Go report](https://goreportcard.com/badge/github.com/enbility/ship-go)](https://goreportcard.com/report/github.com/enbility/ship-go)
77
[![CodeFactor](https://www.codefactor.io/repository/github/enbility/ship-go/badge)](https://www.codefactor.io/repository/github/enbility/ship-go)
88

api/mdns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type MdnsEntry struct {
2020

2121
// implemented by Hub, used by mdns
2222
type MdnsReportInterface interface {
23-
ReportMdnsEntries(entries map[string]*MdnsEntry)
23+
ReportMdnsEntries(entries map[string]*MdnsEntry, newEntries bool)
2424
}
2525

2626
// implemented by mdns, used by Hub

hub/hub.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,9 @@ func (h *Hub) checkAutoReannounce() {
160160

161161
if countPairedServices > countConnections {
162162
_ = h.mdns.AnnounceMdnsEntry()
163+
164+
// also check currently known mDNS entries to see if they
165+
// already contain the not connected remote service
166+
h.mdns.RequestMdnsEntries()
163167
}
164168
}

hub/hub_mdns.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import (
1111
var _ api.MdnsReportInterface = (*Hub)(nil)
1212

1313
// Process reported mDNS services
14-
func (h *Hub) ReportMdnsEntries(entries map[string]*api.MdnsEntry) {
15-
h.muxMdns.Lock()
16-
defer h.muxMdns.Unlock()
17-
14+
func (h *Hub) ReportMdnsEntries(entries map[string]*api.MdnsEntry, newEntries bool) {
1815
var mdnsEntries []*api.MdnsEntry
1916

2017
for ski, entry := range entries {
@@ -52,7 +49,11 @@ func (h *Hub) ReportMdnsEntries(entries map[string]*api.MdnsEntry) {
5249
return a < b
5350
})
5451

55-
h.knownMdnsEntries = mdnsEntries
52+
if newEntries {
53+
h.muxMdns.Lock()
54+
h.knownMdnsEntries = mdnsEntries
55+
h.muxMdns.Unlock()
56+
}
5657

5758
var remoteServices []api.RemoteService
5859

hub/hub_pairing.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,12 @@ func (h *Hub) RegisterRemoteSKI(ski string) {
102102
return
103103
}
104104

105-
// if the hub has started, trigger a search and conneciton attempt
105+
// if the hub has started, trigger a search and connection attempt
106106
conn := h.connectionForSKI(ski)
107107

108+
service := h.ServiceForSKI(ski)
109+
service.SetTrusted(true)
110+
108111
// remotely initiated?
109112
if conn != nil {
110113
conn.ApprovePendingHandshake()
@@ -113,8 +116,6 @@ func (h *Hub) RegisterRemoteSKI(ski string) {
113116
}
114117

115118
// locally initiated
116-
service := h.ServiceForSKI(ski)
117-
service.SetTrusted(true)
118119
service.ConnectionStateDetail().SetState(api.ConnectionStateQueued)
119120

120121
h.hubReader.ServicePairingDetailUpdate(ski, service.ConnectionStateDetail())

hub/hub_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ func (s *HubSuite) Test_ReportMdnsEntries() {
632632
entries := make(map[string]*api.MdnsEntry)
633633

634634
s.hubReader.EXPECT().VisibleRemoteServicesUpdated(gomock.Any()).AnyTimes()
635-
s.sut.ReportMdnsEntries(entries)
635+
s.sut.ReportMdnsEntries(entries, true)
636636

637637
entries[testski1] = &api.MdnsEntry{
638638
Ski: testski1,
@@ -648,7 +648,7 @@ func (s *HubSuite) Test_ReportMdnsEntries() {
648648
service2.SetTrusted(true)
649649
service2.SetIPv4("127.0.0.1")
650650

651-
s.sut.ReportMdnsEntries(entries)
651+
s.sut.ReportMdnsEntries(entries, true)
652652
}
653653

654654
func createInvalidCertificate(organizationalUnit, organization, country, commonName string) (tls.Certificate, error) {

mdns/mdns.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ type MdnsManager struct {
6767

6868
providerSelection MdnsProviderSelection
6969

70-
mux sync.Mutex
70+
mux,
71+
muxAnnounced sync.Mutex
7172
}
7273

7374
func 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
226230
func (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

237255
func (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

399417
func (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
}

mdns/mdns_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (s *MdnsSuite) BeforeTest(suiteName, testName string) {
3131
s.mdnsService = mocks.NewMdnsInterface(s.T())
3232

3333
s.mdnsSearch = mocks.NewMdnsReportInterface(s.T())
34-
s.mdnsSearch.On("ReportMdnsEntries", mock.Anything).Maybe().Return()
34+
s.mdnsSearch.On("ReportMdnsEntries", mock.Anything, mock.Anything).Maybe().Return()
3535

3636
s.mdnsProvider = mocks.NewMdnsProviderInterface(s.T())
3737
s.mdnsProvider.On("ResolveEntries", mock.Anything, mock.Anything).Maybe().Return()
@@ -164,7 +164,7 @@ func (s *MdnsSuite) Test_MdnsEntries() {
164164
err := s.sut.Start(s.mdnsSearch)
165165
assert.Nil(s.T(), err)
166166

167-
s.mdnsSearch.EXPECT().ReportMdnsEntries(mock.Anything).Maybe()
167+
s.mdnsSearch.EXPECT().ReportMdnsEntries(mock.Anything, mock.Anything).Maybe()
168168

169169
s.sut.RequestMdnsEntries()
170170

@@ -175,7 +175,7 @@ func (s *MdnsSuite) Test_ProcessMdnsEntry() {
175175
err := s.sut.Start(s.mdnsSearch)
176176
assert.Nil(s.T(), err)
177177

178-
s.mdnsSearch.EXPECT().ReportMdnsEntries(mock.Anything).Maybe()
178+
s.mdnsSearch.EXPECT().ReportMdnsEntries(mock.Anything, mock.Anything).Maybe()
179179

180180
elements := make(map[string]string, 1)
181181

mdns/zeroconf.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,18 @@ func (z *ZeroconfProvider) Announce(serviceName string, port int, txt []string)
5858
return err
5959
}
6060

61+
z.mux.Lock()
62+
defer z.mux.Unlock()
63+
6164
z.zc = mDNSServer
6265

6366
return nil
6467
}
6568

6669
func (z *ZeroconfProvider) Unannounce() {
70+
z.mux.Lock()
71+
defer z.mux.Unlock()
72+
6773
if z.zc == nil {
6874
return
6975
}

mocks/HubInterface.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)