chore(no-torrent)_: Made torrentClientReady() belong to TorrentManager
This commit is contained in:
parent
9b458c63e0
commit
93256fc252
|
@ -208,7 +208,7 @@ func (m *TorrentManager) StartTorrentClient() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *TorrentManager) StopTorrentClient() error {
|
func (m *TorrentManager) Stop() error {
|
||||||
if m.TorrentClientStarted() {
|
if m.TorrentClientStarted() {
|
||||||
m.StopHistoryArchiveTasksIntervals()
|
m.StopHistoryArchiveTasksIntervals()
|
||||||
m.logger.Info("Stopping torrent client")
|
m.logger.Info("Stopping torrent client")
|
||||||
|
@ -225,6 +225,15 @@ func (m *TorrentManager) TorrentClientStarted() bool {
|
||||||
return m.torrentClient != nil
|
return m.torrentClient != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *TorrentManager) IsReady() bool {
|
||||||
|
// Simply checking for `torrentConfig.Enabled` isn't enough
|
||||||
|
// as there's a possibility that the torrent client couldn't
|
||||||
|
// be instantiated (for example in case of port conflicts)
|
||||||
|
return m.torrentConfig != nil &&
|
||||||
|
m.torrentConfig.Enabled &&
|
||||||
|
m.TorrentClientStarted()
|
||||||
|
}
|
||||||
|
|
||||||
func (m *TorrentManager) GetCommunityChatsFilters(communityID types.HexBytes) ([]*transport.Filter, error) {
|
func (m *TorrentManager) GetCommunityChatsFilters(communityID types.HexBytes) ([]*transport.Filter, error) {
|
||||||
chatIDs, err := m.persistence.GetCommunityChatIDs(communityID)
|
chatIDs, err := m.persistence.GetCommunityChatIDs(communityID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -579,7 +579,7 @@ func NewMessenger(
|
||||||
ensVerifier.Stop,
|
ensVerifier.Stop,
|
||||||
pushNotificationClient.Stop,
|
pushNotificationClient.Stop,
|
||||||
communitiesManager.Stop,
|
communitiesManager.Stop,
|
||||||
torrentManager.StopTorrentClient,
|
torrentManager.Stop,
|
||||||
encryptionProtocol.Stop,
|
encryptionProtocol.Stop,
|
||||||
func() error {
|
func() error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||||
|
@ -829,7 +829,7 @@ func (m *Messenger) Start() (*MessengerResponse, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.torrentClientReady() {
|
if m.torrentManager.IsReady() {
|
||||||
available := m.SubscribeMailserverAvailable()
|
available := m.SubscribeMailserverAvailable()
|
||||||
go func() {
|
go func() {
|
||||||
<-available
|
<-available
|
||||||
|
@ -918,7 +918,7 @@ func (m *Messenger) handleConnectionChange(online bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update Communities manager
|
// Update torrent manager
|
||||||
if m.torrentManager != nil {
|
if m.torrentManager != nil {
|
||||||
m.torrentManager.SetOnline(online)
|
m.torrentManager.SetOnline(online)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1895,7 +1895,7 @@ func (m *Messenger) acceptRequestToJoinCommunity(requestToJoin *communities.Requ
|
||||||
Shard: community.Shard().Protobuffer(),
|
Shard: community.Shard().Protobuffer(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.torrentClientReady() && m.torrentManager.TorrentFileExists(community.IDString()) {
|
if m.torrentManager.IsReady() && m.torrentManager.TorrentFileExists(community.IDString()) {
|
||||||
magnetlink, err := m.torrentManager.GetHistoryArchiveMagnetlink(community.ID())
|
magnetlink, err := m.torrentManager.GetHistoryArchiveMagnetlink(community.ID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.logger.Warn("couldn't get magnet link for community", zap.Error(err))
|
m.logger.Warn("couldn't get magnet link for community", zap.Error(err))
|
||||||
|
@ -2804,7 +2804,7 @@ func (m *Messenger) EditCommunity(request *requests.EditCommunity) (*MessengerRe
|
||||||
|
|
||||||
id := community.ID()
|
id := community.ID()
|
||||||
|
|
||||||
if m.torrentClientReady() {
|
if m.torrentManager.IsReady() {
|
||||||
if !communitySettings.HistoryArchiveSupportEnabled {
|
if !communitySettings.HistoryArchiveSupportEnabled {
|
||||||
m.torrentManager.StopHistoryArchiveTasksInterval(id)
|
m.torrentManager.StopHistoryArchiveTasksInterval(id)
|
||||||
} else if !m.torrentManager.IsSeedingHistoryArchiveTorrent(id) {
|
} else if !m.torrentManager.IsSeedingHistoryArchiveTorrent(id) {
|
||||||
|
@ -2889,7 +2889,7 @@ func (m *Messenger) ImportCommunity(ctx context.Context, key *ecdsa.PrivateKey)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.torrentClientReady() {
|
if m.torrentManager.IsReady() {
|
||||||
var communities []*communities.Community
|
var communities []*communities.Community
|
||||||
communities = append(communities, community)
|
communities = append(communities, community)
|
||||||
go m.InitHistoryArchiveTasks(communities)
|
go m.InitHistoryArchiveTasks(communities)
|
||||||
|
@ -4167,7 +4167,7 @@ func (m *Messenger) DisableCommunityHistoryArchiveProtocol() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
m.torrentManager.StopTorrentClient()
|
m.torrentManager.Stop()
|
||||||
|
|
||||||
nodeConfig.TorrentConfig.Enabled = false
|
nodeConfig.TorrentConfig.Enabled = false
|
||||||
err = m.settings.SaveSetting("node-config", nodeConfig)
|
err = m.settings.SaveSetting("node-config", nodeConfig)
|
||||||
|
@ -4278,15 +4278,6 @@ func (m *Messenger) pinMessagesToWakuMessages(pinMessages []*common.PinMessage,
|
||||||
return wakuMessages, nil
|
return wakuMessages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) torrentClientReady() bool {
|
|
||||||
// Simply checking for `torrentConfig.Enabled` isn't enough
|
|
||||||
// as there's a possiblity that the torrent client couldn't
|
|
||||||
// be instantiated (for example in case of port conflicts)
|
|
||||||
return m.config.torrentConfig != nil &&
|
|
||||||
m.config.torrentConfig.Enabled &&
|
|
||||||
m.torrentManager.TorrentClientStarted()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Messenger) chatMessagesToWakuMessages(chatMessages []*common.Message, c *communities.Community) ([]*types.Message, error) {
|
func (m *Messenger) chatMessagesToWakuMessages(chatMessages []*common.Message, c *communities.Community) ([]*types.Message, error) {
|
||||||
wakuMessages := make([]*types.Message, 0)
|
wakuMessages := make([]*types.Message, 0)
|
||||||
for _, msg := range chatMessages {
|
for _, msg := range chatMessages {
|
||||||
|
|
|
@ -971,7 +971,7 @@ func (m *Messenger) RequestImportDiscordChannel(request *requests.ImportDiscordC
|
||||||
m.logger.Error("Failed to get community settings", zap.Error(err))
|
m.logger.Error("Failed to get community settings", zap.Error(err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if m.torrentClientReady() && communitySettings.HistoryArchiveSupportEnabled {
|
if m.torrentManager.IsReady() && communitySettings.HistoryArchiveSupportEnabled {
|
||||||
|
|
||||||
err = m.torrentManager.SeedHistoryArchiveTorrent(request.CommunityID)
|
err = m.torrentManager.SeedHistoryArchiveTorrent(request.CommunityID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1737,7 +1737,7 @@ func (m *Messenger) RequestImportDiscordCommunity(request *requests.ImportDiscor
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.torrentClientReady() && communitySettings.HistoryArchiveSupportEnabled {
|
if m.torrentManager.IsReady() && communitySettings.HistoryArchiveSupportEnabled {
|
||||||
|
|
||||||
err = m.torrentManager.SeedHistoryArchiveTorrent(discordCommunity.ID())
|
err = m.torrentManager.SeedHistoryArchiveTorrent(discordCommunity.ID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1342,7 +1342,7 @@ func (m *Messenger) HandleHistoryArchiveMagnetlinkMessage(state *ReceivedMessage
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.torrentClientReady() && settings.HistoryArchiveSupportEnabled {
|
if m.torrentManager.IsReady() && settings.HistoryArchiveSupportEnabled {
|
||||||
lastClock, err := m.communitiesManager.GetMagnetlinkMessageClock(id)
|
lastClock, err := m.communitiesManager.GetMagnetlinkMessageClock(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1728,7 +1728,7 @@ func (m *Messenger) HandleCommunityRequestToJoinResponse(state *ReceivedMessageS
|
||||||
}
|
}
|
||||||
|
|
||||||
magnetlink := requestToJoinResponseProto.MagnetUri
|
magnetlink := requestToJoinResponseProto.MagnetUri
|
||||||
if m.torrentClientReady() && communitySettings != nil && communitySettings.HistoryArchiveSupportEnabled && magnetlink != "" {
|
if m.torrentManager.IsReady() && communitySettings != nil && communitySettings.HistoryArchiveSupportEnabled && magnetlink != "" {
|
||||||
|
|
||||||
currentTask := m.torrentManager.GetHistoryArchiveDownloadTask(community.IDString())
|
currentTask := m.torrentManager.GetHistoryArchiveDownloadTask(community.IDString())
|
||||||
go func(currentTask *communities.HistoryArchiveDownloadTask) {
|
go func(currentTask *communities.HistoryArchiveDownloadTask) {
|
||||||
|
|
Loading…
Reference in New Issue