Skip to content

Commit

Permalink
Fix reconnect bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0llx committed Mar 15, 2024
1 parent 14e3b09 commit c348daf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions hub/hub_pairing.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,21 @@ func (h *Hub) mapShipMessageExchangeState(state model.ShipMessageExchangeState,
return connState
}

func (h *Hub) checkHasStarted() bool {
h.muxStarted.Lock()
defer h.muxStarted.Unlock()
return h.hasStarted
}

// Sets the SKI as being paired or not
// Should be used for services which completed the pairing process and
// which were stored as having the process completed
func (h *Hub) RegisterRemoteSKI(ski string, enable bool) {
// this should only be invoked before start is invoked
h.muxStarted.Lock()
if h.hasStarted {
if h.checkHasStarted() {
logging.Log().Error("RegisterRemoteSKI should only be called before the service started!")
return
}
h.muxStarted.Unlock()

service := h.ServiceForSKI(ski)
service.SetTrusted(enable)
Expand Down
5 changes: 5 additions & 0 deletions hub/hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ func (s *HubSuite) Test_InitiateConnection() {
assert.Equal(s.T(), false, result)
}

func (s *HubSuite) Test_checkHasStarted() {
checked := s.sut.checkHasStarted()
assert.Equal(s.T(), s.sut.hasStarted, checked)
}

func (s *HubSuite) Test_IncreaseConnectionAttemptCounter() {
for _, test := range s.tests {
s.sut.increaseConnectionAttemptCounter(s.remoteSki)
Expand Down

0 comments on commit c348daf

Please sign in to comment.