fix(communities)_: delay starting torrent client until connection is established

Fixes # 14510
This commit is contained in:
Andrey Bocharnikov 2024-05-06 19:54:35 +04:00
parent 529c658374
commit 6b5315b1fd
3 changed files with 24 additions and 6 deletions

View File

@ -444,15 +444,18 @@ func (m *Manager) Start() error {
if m.ownerVerifier != nil {
m.runOwnerVerificationLoop()
}
return nil
}
if m.torrentConfig != nil && m.torrentConfig.Enabled {
err := m.StartTorrentClient()
if err != nil {
m.LogStdout("couldn't start torrent client", zap.Error(err))
func (m *Manager) SetOnline(online bool) {
if online {
if m.torrentConfig != nil && m.torrentConfig.Enabled && !m.TorrentClientStarted() {
err := m.StartTorrentClient()
if err != nil {
m.LogStdout("couldn't start torrent client", zap.Error(err))
}
}
}
return nil
}
func (m *Manager) runENSVerificationLoop() {

View File

@ -501,6 +501,16 @@ func (s *ManagerSuite) TestStopTorrentClient_ShouldStopHistoryArchiveTasks() {
s.Require().Equal(count, 0)
}
func (s *ManagerSuite) TestStartTorrentClient_DelayedUntilOnline() {
torrentConfig := buildTorrentConfig()
s.manager.SetTorrentConfig(&torrentConfig)
s.Require().False(s.manager.TorrentClientStarted())
s.manager.SetOnline(true)
s.Require().True(s.manager.TorrentClientStarted())
}
func (s *ManagerSuite) TestCreateHistoryArchiveTorrent_WithoutMessages() {
torrentConfig := buildTorrentConfig()

View File

@ -899,6 +899,11 @@ func (m *Messenger) handleConnectionChange(online bool) {
}
}
// Update Communities manager
if m.communitiesManager != nil {
m.communitiesManager.SetOnline(online)
}
// Publish contact code
if online && m.shouldPublishContactCode {
if err := m.publishContactCode(); err != nil {