chore(no-torrent)_: Replaced entirely LogStdout with default logger
This commit is contained in:
parent
210c8bd8c6
commit
a9c7db6f25
|
@ -178,7 +178,6 @@ type ArchiveContract interface {
|
|||
type TorrentContract interface {
|
||||
ArchiveContract
|
||||
|
||||
LogStdout(string, ...zap.Field)
|
||||
SetOnline(bool)
|
||||
SetTorrentConfig(*params.TorrentConfig)
|
||||
StartTorrentClient() error
|
||||
|
|
|
@ -33,8 +33,6 @@ type ArchiveManager struct {
|
|||
torrentConfig *params.TorrentConfig
|
||||
|
||||
logger *zap.Logger
|
||||
stdoutLogger *zap.Logger
|
||||
|
||||
persistence *Persistence
|
||||
identity *ecdsa.PrivateKey
|
||||
encryptor *encryption.Protocol
|
||||
|
@ -42,11 +40,10 @@ type ArchiveManager struct {
|
|||
publisher Publisher
|
||||
}
|
||||
|
||||
func NewArchiveManager(torrentConfig *params.TorrentConfig, logger, stdoutLogger *zap.Logger, persistence *Persistence, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) *ArchiveManager {
|
||||
func NewArchiveManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) *ArchiveManager {
|
||||
return &ArchiveManager{
|
||||
torrentConfig: torrentConfig,
|
||||
logger: logger,
|
||||
stdoutLogger: stdoutLogger,
|
||||
persistence: persistence,
|
||||
identity: identity,
|
||||
encryptor: encryptor,
|
||||
|
@ -54,12 +51,6 @@ func NewArchiveManager(torrentConfig *params.TorrentConfig, logger, stdoutLogger
|
|||
}
|
||||
}
|
||||
|
||||
// LogStdout appears to be some kind of debug tool specifically for torrent functionality
|
||||
func (m *ArchiveManager) LogStdout(msg string, fields ...zap.Field) {
|
||||
m.stdoutLogger.Info(msg, fields...)
|
||||
m.logger.Debug(msg, fields...)
|
||||
}
|
||||
|
||||
func (m *ArchiveManager) createHistoryArchiveTorrent(communityID types.HexBytes, msgs []*types.Message, topics []types.TopicType, startDate time.Time, endDate time.Time, partition time.Duration, encrypt bool) ([]string, error) {
|
||||
|
||||
loadFromDB := len(msgs) == 0
|
||||
|
@ -114,7 +105,7 @@ func (m *ArchiveManager) createHistoryArchiveTorrent(communityID types.HexBytes,
|
|||
CommunityID: communityID.String(),
|
||||
}})
|
||||
|
||||
m.LogStdout("creating archives",
|
||||
m.logger.Debug("creating archives",
|
||||
zap.Any("startDate", startDate),
|
||||
zap.Any("endDate", endDate),
|
||||
zap.Duration("partition", partition),
|
||||
|
@ -123,7 +114,7 @@ func (m *ArchiveManager) createHistoryArchiveTorrent(communityID types.HexBytes,
|
|||
if from.Equal(endDate) || from.After(endDate) {
|
||||
break
|
||||
}
|
||||
m.LogStdout("creating message archive",
|
||||
m.logger.Debug("creating message archive",
|
||||
zap.Any("from", from),
|
||||
zap.Any("to", to),
|
||||
)
|
||||
|
@ -144,7 +135,7 @@ func (m *ArchiveManager) createHistoryArchiveTorrent(communityID types.HexBytes,
|
|||
|
||||
if len(messages) == 0 {
|
||||
// No need to create an archive with zero messages
|
||||
m.LogStdout("no messages in this partition")
|
||||
m.logger.Debug("no messages in this partition")
|
||||
from = to
|
||||
to = to.Add(partition)
|
||||
if to.After(endDate) {
|
||||
|
@ -153,7 +144,7 @@ func (m *ArchiveManager) createHistoryArchiveTorrent(communityID types.HexBytes,
|
|||
continue
|
||||
}
|
||||
|
||||
m.LogStdout("creating archive with messages", zap.Int("messagesCount", len(messages)))
|
||||
m.logger.Debug("creating archive with messages", zap.Int("messagesCount", len(messages)))
|
||||
|
||||
// Not only do we partition messages, we also chunk them
|
||||
// roughly by size, such that each chunk will not exceed a given
|
||||
|
@ -308,7 +299,7 @@ func (m *ArchiveManager) createHistoryArchiveTorrent(communityID types.HexBytes,
|
|||
return archiveIDs, err
|
||||
}
|
||||
|
||||
m.LogStdout("torrent created", zap.Any("from", startDate.Unix()), zap.Any("to", endDate.Unix()))
|
||||
m.logger.Debug("torrent created", zap.Any("from", startDate.Unix()), zap.Any("to", endDate.Unix()))
|
||||
|
||||
m.publisher.publish(&Subscription{
|
||||
HistoryArchivesCreatedSignal: &signal.HistoryArchivesCreatedSignal{
|
||||
|
@ -318,7 +309,7 @@ func (m *ArchiveManager) createHistoryArchiveTorrent(communityID types.HexBytes,
|
|||
},
|
||||
})
|
||||
} else {
|
||||
m.LogStdout("no archives created")
|
||||
m.logger.Debug("no archives created")
|
||||
m.publisher.publish(&Subscription{
|
||||
NoHistoryArchivesCreatedSignal: &signal.NoHistoryArchivesCreatedSignal{
|
||||
CommunityID: communityID.String(),
|
||||
|
@ -433,22 +424,22 @@ func (m *ArchiveManager) ExtractMessagesFromHistoryArchive(communityID types.Hex
|
|||
}
|
||||
defer dataFile.Close()
|
||||
|
||||
m.LogStdout("extracting messages from history archive",
|
||||
m.logger.Debug("extracting messages from history archive",
|
||||
zap.String("communityID", communityID.String()),
|
||||
zap.String("archiveID", archiveID))
|
||||
metadata := index.Archives[archiveID]
|
||||
|
||||
_, err = dataFile.Seek(int64(metadata.Offset), 0)
|
||||
if err != nil {
|
||||
m.LogStdout("failed to seek archive data file", zap.Error(err))
|
||||
m.logger.Error("failed to seek archive data file", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := make([]byte, metadata.Size-metadata.Padding)
|
||||
m.LogStdout("loading history archive data into memory", zap.Float64("data_size_MB", float64(metadata.Size-metadata.Padding)/1024.0/1024.0))
|
||||
m.logger.Debug("loading history archive data into memory", zap.Float64("data_size_MB", float64(metadata.Size-metadata.Padding)/1024.0/1024.0))
|
||||
_, err = dataFile.Read(data)
|
||||
if err != nil {
|
||||
m.LogStdout("failed failed to read archive data", zap.Error(err))
|
||||
m.logger.Error("failed failed to read archive data", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -460,23 +451,23 @@ func (m *ArchiveManager) ExtractMessagesFromHistoryArchive(communityID types.Hex
|
|||
var protocolMessage encryption.ProtocolMessage
|
||||
err := proto.Unmarshal(data, &protocolMessage)
|
||||
if err != nil {
|
||||
m.LogStdout("failed to unmarshal protocol message", zap.Error(err))
|
||||
m.logger.Error("failed to unmarshal protocol message", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pk, err := crypto.DecompressPubkey(communityID)
|
||||
if err != nil {
|
||||
m.logger.Debug("failed to decompress community pubkey", zap.Error(err))
|
||||
m.logger.Error("failed to decompress community pubkey", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
decryptedBytes, err := m.encryptor.HandleMessage(m.identity, pk, &protocolMessage, make([]byte, 0))
|
||||
if err != nil {
|
||||
m.LogStdout("failed to decrypt message archive", zap.Error(err))
|
||||
m.logger.Error("failed to decrypt message archive", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
err = proto.Unmarshal(decryptedBytes.DecryptedMessage, archive)
|
||||
if err != nil {
|
||||
m.LogStdout("failed to unmarshal message archive", zap.Error(err))
|
||||
m.logger.Error("failed to unmarshal message archive", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ func (s *ManagerSuite) buildManagers(ownerVerifier OwnerVerifier) (*Manager, Tor
|
|||
s.Require().NoError(m.Start())
|
||||
|
||||
tc := buildTorrentConfig()
|
||||
t, err := NewTorrentManager(&tc, logger, m.GetPersistence(), nil, key, nil, m)
|
||||
t := NewTorrentManager(&tc, logger, m.GetPersistence(), nil, key, nil, m)
|
||||
s.Require().NoError(err)
|
||||
|
||||
return m, t
|
||||
|
|
|
@ -64,8 +64,6 @@ type TorrentManager struct {
|
|||
historyArchiveTasks sync.Map // stores `chan struct{}`
|
||||
|
||||
logger *zap.Logger
|
||||
stdoutLogger *zap.Logger
|
||||
|
||||
persistence *Persistence
|
||||
transport *transport.Transport
|
||||
identity *ecdsa.PrivateKey
|
||||
|
@ -79,19 +77,13 @@ type TorrentManager struct {
|
|||
// In this case this version of NewTorrentManager will return the full Desktop TorrentManager ensuring that the
|
||||
// build command will import and build the torrent deps for the Desktop OSes.
|
||||
// NOTE: It is intentional that this file contains the identical function name as in "manager_torrent_mobile.go"
|
||||
func NewTorrentManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) (TorrentContract, error) {
|
||||
stdoutLogger, err := zap.NewDevelopment()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create archive logger %w", err)
|
||||
}
|
||||
|
||||
func NewTorrentManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) *TorrentManager {
|
||||
return &TorrentManager{
|
||||
torrentConfig: torrentConfig,
|
||||
torrentTasks: make(map[string]metainfo.Hash),
|
||||
historyArchiveDownloadTasks: make(map[string]*HistoryArchiveDownloadTask),
|
||||
|
||||
logger: logger,
|
||||
stdoutLogger: stdoutLogger,
|
||||
|
||||
persistence: persistence,
|
||||
transport: transport,
|
||||
|
@ -99,8 +91,8 @@ func NewTorrentManager(torrentConfig *params.TorrentConfig, logger *zap.Logger,
|
|||
encryptor: encryptor,
|
||||
|
||||
publisher: publisher,
|
||||
ArchiveManager: NewArchiveManager(torrentConfig, logger, stdoutLogger, persistence, identity, encryptor, publisher),
|
||||
}, nil
|
||||
ArchiveManager: NewArchiveManager(torrentConfig, logger, persistence, identity, encryptor, publisher),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *TorrentManager) SetOnline(online bool) {
|
||||
|
@ -108,7 +100,7 @@ func (m *TorrentManager) SetOnline(online bool) {
|
|||
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))
|
||||
m.logger.Error("couldn't start torrent client", zap.Error(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -270,7 +262,7 @@ func (m *TorrentManager) getLastMessageArchiveEndDate(communityID types.HexBytes
|
|||
func (m *TorrentManager) GetHistoryArchivePartitionStartTimestamp(communityID types.HexBytes) (uint64, error) {
|
||||
filters, err := m.GetCommunityChatsFilters(communityID)
|
||||
if err != nil {
|
||||
m.LogStdout("failed to get community chats filters", zap.Error(err))
|
||||
m.logger.Error("failed to get community chats filters", zap.Error(err))
|
||||
return 0, err
|
||||
}
|
||||
|
||||
|
@ -289,7 +281,7 @@ func (m *TorrentManager) GetHistoryArchivePartitionStartTimestamp(communityID ty
|
|||
|
||||
lastArchiveEndDateTimestamp, err := m.getLastMessageArchiveEndDate(communityID)
|
||||
if err != nil {
|
||||
m.LogStdout("failed to get last archive end date", zap.Error(err))
|
||||
m.logger.Error("failed to get last archive end date", zap.Error(err))
|
||||
return 0, err
|
||||
}
|
||||
|
||||
|
@ -300,13 +292,13 @@ func (m *TorrentManager) GetHistoryArchivePartitionStartTimestamp(communityID ty
|
|||
// this community
|
||||
lastArchiveEndDateTimestamp, err = m.getOldestWakuMessageTimestamp(topics)
|
||||
if err != nil {
|
||||
m.LogStdout("failed to get oldest waku message timestamp", zap.Error(err))
|
||||
m.logger.Error("failed to get oldest waku message timestamp", zap.Error(err))
|
||||
return 0, err
|
||||
}
|
||||
if lastArchiveEndDateTimestamp == 0 {
|
||||
// This means there's no waku message stored for this community so far
|
||||
// (even after requesting possibly missed messages), so no messages exist yet that can be archived
|
||||
m.LogStdout("can't find valid `lastArchiveEndTimestamp`")
|
||||
m.logger.Debug("can't find valid `lastArchiveEndTimestamp`")
|
||||
return 0, nil
|
||||
}
|
||||
}
|
||||
|
@ -326,7 +318,7 @@ func (m *TorrentManager) CreateAndSeedHistoryArchive(communityID types.HexBytes,
|
|||
func (m *TorrentManager) StartHistoryArchiveTasksInterval(community *Community, interval time.Duration) {
|
||||
id := community.IDString()
|
||||
if _, exists := m.historyArchiveTasks.Load(id); exists {
|
||||
m.LogStdout("history archive tasks interval already in progress", zap.String("id", id))
|
||||
m.logger.Error("history archive tasks interval already in progress", zap.String("id", id))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -337,27 +329,27 @@ func (m *TorrentManager) StartHistoryArchiveTasksInterval(community *Community,
|
|||
ticker := time.NewTicker(interval)
|
||||
defer ticker.Stop()
|
||||
|
||||
m.LogStdout("starting history archive tasks interval", zap.String("id", id))
|
||||
m.logger.Debug("starting history archive tasks interval", zap.String("id", id))
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
m.LogStdout("starting archive task...", zap.String("id", id))
|
||||
m.logger.Debug("starting archive task...", zap.String("id", id))
|
||||
lastArchiveEndDateTimestamp, err := m.GetHistoryArchivePartitionStartTimestamp(community.ID())
|
||||
if err != nil {
|
||||
m.LogStdout("failed to get last archive end date", zap.Error(err))
|
||||
m.logger.Error("failed to get last archive end date", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
|
||||
if lastArchiveEndDateTimestamp == 0 {
|
||||
// This means there are no waku messages for this community,
|
||||
// so nothing to do here
|
||||
m.LogStdout("couldn't determine archive start date - skipping")
|
||||
m.logger.Debug("couldn't determine archive start date - skipping")
|
||||
continue
|
||||
}
|
||||
|
||||
topics, err := m.GetCommunityChatsTopics(community.ID())
|
||||
if err != nil {
|
||||
m.LogStdout("failed to get community chat topics ", zap.Error(err))
|
||||
m.logger.Error("failed to get community chat topics ", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -367,7 +359,7 @@ func (m *TorrentManager) StartHistoryArchiveTasksInterval(community *Community,
|
|||
|
||||
err = m.CreateAndSeedHistoryArchive(community.ID(), topics, lastArchiveEndDate, to, interval, community.Encrypted())
|
||||
if err != nil {
|
||||
m.LogStdout("failed to create and seed history archive", zap.Error(err))
|
||||
m.logger.Error("failed to create and seed history archive", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
case <-cancel:
|
||||
|
@ -436,7 +428,7 @@ func (m *TorrentManager) SeedHistoryArchiveTorrent(communityID types.HexBytes) e
|
|||
|
||||
magnetLink := metaInfo.Magnet(nil, &info).String()
|
||||
|
||||
m.LogStdout("seeding torrent", zap.String("id", id), zap.String("magnetLink", magnetLink))
|
||||
m.logger.Debug("seeding torrent", zap.String("id", id), zap.String("magnetLink", magnetLink))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -500,12 +492,12 @@ func (m *TorrentManager) DownloadHistoryArchivesByMagnetlink(communityID types.H
|
|||
m.torrentTasks[id] = ml.InfoHash
|
||||
timeout := time.After(20 * time.Second)
|
||||
|
||||
m.LogStdout("fetching torrent info", zap.String("magnetlink", magnetlink))
|
||||
m.logger.Debug("fetching torrent info", zap.String("magnetlink", magnetlink))
|
||||
select {
|
||||
case <-timeout:
|
||||
return nil, ErrTorrentTimedout
|
||||
case <-cancelTask:
|
||||
m.LogStdout("cancelled fetching torrent info")
|
||||
m.logger.Debug("cancelled fetching torrent info")
|
||||
downloadTaskInfo.Cancelled = true
|
||||
return downloadTaskInfo, nil
|
||||
case <-torrent.GotInfo():
|
||||
|
@ -521,14 +513,14 @@ func (m *TorrentManager) DownloadHistoryArchivesByMagnetlink(communityID types.H
|
|||
indexFile := files[i]
|
||||
indexFile.Download()
|
||||
|
||||
m.LogStdout("downloading history archive index")
|
||||
m.logger.Debug("downloading history archive index")
|
||||
ticker := time.NewTicker(100 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-cancelTask:
|
||||
m.LogStdout("cancelled downloading archive index")
|
||||
m.logger.Debug("cancelled downloading archive index")
|
||||
downloadTaskInfo.Cancelled = true
|
||||
return downloadTaskInfo, nil
|
||||
case <-ticker.C:
|
||||
|
@ -545,7 +537,7 @@ func (m *TorrentManager) DownloadHistoryArchivesByMagnetlink(communityID types.H
|
|||
}
|
||||
|
||||
if len(existingArchiveIDs) == len(index.Archives) {
|
||||
m.LogStdout("download cancelled, no new archives")
|
||||
m.logger.Debug("download cancelled, no new archives")
|
||||
return downloadTaskInfo, nil
|
||||
}
|
||||
|
||||
|
@ -586,8 +578,8 @@ func (m *TorrentManager) DownloadHistoryArchivesByMagnetlink(communityID types.H
|
|||
endIndex := startIndex + int(metadata.Size)/pieceLength
|
||||
|
||||
downloadMsg := fmt.Sprintf("downloading data for message archive (%d/%d)", downloadTaskInfo.TotalDownloadedArchivesCount+1, downloadTaskInfo.TotalArchivesCount)
|
||||
m.LogStdout(downloadMsg, zap.String("hash", hash))
|
||||
m.LogStdout("pieces (start, end)", zap.Any("startIndex", startIndex), zap.Any("endIndex", endIndex-1))
|
||||
m.logger.Debug(downloadMsg, zap.String("hash", hash))
|
||||
m.logger.Debug("pieces (start, end)", zap.Any("startIndex", startIndex), zap.Any("endIndex", endIndex-1))
|
||||
torrent.DownloadPieces(startIndex, endIndex)
|
||||
|
||||
piecesCompleted := make(map[int]bool)
|
||||
|
@ -615,7 +607,7 @@ func (m *TorrentManager) DownloadHistoryArchivesByMagnetlink(communityID types.H
|
|||
break downloadLoop
|
||||
}
|
||||
case <-cancelTask:
|
||||
m.LogStdout("downloading archive data interrupted")
|
||||
m.logger.Debug("downloading archive data interrupted")
|
||||
downloadTaskInfo.Cancelled = true
|
||||
return downloadTaskInfo, nil
|
||||
}
|
||||
|
@ -623,7 +615,7 @@ func (m *TorrentManager) DownloadHistoryArchivesByMagnetlink(communityID types.H
|
|||
downloadTaskInfo.TotalDownloadedArchivesCount++
|
||||
err = m.persistence.SaveMessageArchiveID(communityID, hash)
|
||||
if err != nil {
|
||||
m.LogStdout("couldn't save message archive ID", zap.Error(err))
|
||||
m.logger.Error("couldn't save message archive ID", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
m.publisher.publish(&Subscription{
|
||||
|
@ -639,7 +631,7 @@ func (m *TorrentManager) DownloadHistoryArchivesByMagnetlink(communityID types.H
|
|||
CommunityID: communityID.String(),
|
||||
},
|
||||
})
|
||||
m.LogStdout("finished downloading archives")
|
||||
m.logger.Debug("finished downloading archives")
|
||||
return downloadTaskInfo, nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,14 +24,10 @@ type TorrentManagerMobile struct {
|
|||
// In this case this version of NewTorrentManager will return the mobile "nil" TorrentManagerMobile ensuring that the
|
||||
// build command will not import or build the torrent deps for the mobile OS.
|
||||
// NOTE: It is intentional that this file contains the identical function name as in "manager_torrent.go"
|
||||
func NewTorrentManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) (TorrentContract, error) {
|
||||
func NewTorrentManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) *TorrentManagerMobile {
|
||||
return &TorrentManagerMobile{
|
||||
logger: logger,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (tmm *TorrentManagerMobile) LogStdout(input string, fields ...zap.Field) {
|
||||
tmm.logger.Debug(input, fields...)
|
||||
}
|
||||
|
||||
func (tmm *TorrentManagerMobile) SetOnline(online bool) {}
|
||||
|
|
|
@ -501,7 +501,7 @@ func NewMessenger(
|
|||
// Depending on the OS go will choose whether to use the "communities/manager_torrent_mobile.go" or
|
||||
// "communities/manager_torrent.go" version of this function based on the build instructions for those files.
|
||||
// See those file for more details.
|
||||
torrentManager, err := communities.NewTorrentManager(c.torrentConfig, logger, communitiesManager.GetPersistence(), transp, identity, encryptionProtocol, communitiesManager)
|
||||
torrentManager := communities.NewTorrentManager(c.torrentConfig, logger, communitiesManager.GetPersistence(), transp, identity, encryptionProtocol, communitiesManager)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -3780,18 +3780,18 @@ func (m *Messenger) HandleSyncCommunitySettings(messageState *ReceivedMessageSta
|
|||
|
||||
func (m *Messenger) InitHistoryArchiveTasks(communities []*communities.Community) {
|
||||
|
||||
m.torrentManager.LogStdout("initializing history archive tasks")
|
||||
m.logger.Debug("initializing history archive tasks")
|
||||
|
||||
for _, c := range communities {
|
||||
|
||||
if c.Joined() {
|
||||
settings, err := m.communitiesManager.GetCommunitySettingsByID(c.ID())
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to get community settings", zap.Error(err))
|
||||
m.logger.Error("failed to get community settings", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
if !settings.HistoryArchiveSupportEnabled {
|
||||
m.torrentManager.LogStdout("history archive support disabled for community", zap.String("id", c.IDString()))
|
||||
m.logger.Debug("history archive support disabled for community", zap.String("id", c.IDString()))
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -3799,18 +3799,18 @@ func (m *Messenger) InitHistoryArchiveTasks(communities []*communities.Community
|
|||
if m.torrentManager.TorrentFileExists(c.IDString()) {
|
||||
err = m.torrentManager.SeedHistoryArchiveTorrent(c.ID())
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to seed history archive", zap.Error(err))
|
||||
m.logger.Error("failed to seed history archive", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
filters, err := m.torrentManager.GetCommunityChatsFilters(c.ID())
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to get community chats filters for community", zap.Error(err))
|
||||
m.logger.Error("failed to get community chats filters for community", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
|
||||
if len(filters) == 0 {
|
||||
m.torrentManager.LogStdout("no filters or chats for this community starting interval", zap.String("id", c.IDString()))
|
||||
m.logger.Debug("no filters or chats for this community starting interval", zap.String("id", c.IDString()))
|
||||
go m.torrentManager.StartHistoryArchiveTasksInterval(c, messageArchiveInterval)
|
||||
continue
|
||||
}
|
||||
|
@ -3826,7 +3826,7 @@ func (m *Messenger) InitHistoryArchiveTasks(communities []*communities.Community
|
|||
// possibly missed since then
|
||||
latestWakuMessageTimestamp, err := m.communitiesManager.GetLatestWakuMessageTimestamp(topics)
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to get Latest waku message timestamp", zap.Error(err))
|
||||
m.logger.Error("failed to get Latest waku message timestamp", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -3844,7 +3844,7 @@ func (m *Messenger) InitHistoryArchiveTasks(communities []*communities.Community
|
|||
ms := m.getActiveMailserver(c.ID().String())
|
||||
_, err = m.syncFiltersFrom(*ms, filters, uint32(latestWakuMessageTimestamp))
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to request missing messages", zap.Error(err))
|
||||
m.logger.Error("failed to request missing messages", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -3853,7 +3853,7 @@ func (m *Messenger) InitHistoryArchiveTasks(communities []*communities.Community
|
|||
// If the last end date is at least `interval` ago, we create an archive immediately first
|
||||
lastArchiveEndDateTimestamp, err := m.torrentManager.GetHistoryArchivePartitionStartTimestamp(c.ID())
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to get archive partition start timestamp", zap.Error(err))
|
||||
m.logger.Error("failed to get archive partition start timestamp", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -3871,15 +3871,15 @@ func (m *Messenger) InitHistoryArchiveTasks(communities []*communities.Community
|
|||
// Seed current archive in the meantime
|
||||
err := m.torrentManager.SeedHistoryArchiveTorrent(c.ID())
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to seed history archive", zap.Error(err))
|
||||
m.logger.Error("failed to seed history archive", zap.Error(err))
|
||||
}
|
||||
timeToNextInterval := messageArchiveInterval - durationSinceLastArchive
|
||||
|
||||
m.torrentManager.LogStdout("starting history archive tasks interval in", zap.Any("timeLeft", timeToNextInterval))
|
||||
m.logger.Debug("starting history archive tasks interval in", zap.Any("timeLeft", timeToNextInterval))
|
||||
time.AfterFunc(timeToNextInterval, func() {
|
||||
err := m.torrentManager.CreateAndSeedHistoryArchive(c.ID(), topics, lastArchiveEndDate, to.Add(timeToNextInterval), messageArchiveInterval, c.Encrypted())
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to get create and seed history archive", zap.Error(err))
|
||||
m.logger.Error("failed to get create and seed history archive", zap.Error(err))
|
||||
}
|
||||
go m.torrentManager.StartHistoryArchiveTasksInterval(c, messageArchiveInterval)
|
||||
})
|
||||
|
@ -3889,7 +3889,7 @@ func (m *Messenger) InitHistoryArchiveTasks(communities []*communities.Community
|
|||
// creation loop
|
||||
err := m.torrentManager.CreateAndSeedHistoryArchive(c.ID(), topics, lastArchiveEndDate, to, messageArchiveInterval, c.Encrypted())
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to get create and seed history archive", zap.Error(err))
|
||||
m.logger.Error("failed to get create and seed history archive", zap.Error(err))
|
||||
}
|
||||
|
||||
go m.torrentManager.StartHistoryArchiveTasksInterval(c, messageArchiveInterval)
|
||||
|
@ -3959,7 +3959,7 @@ func (m *Messenger) resumeHistoryArchivesImport(communityID types.HexBytes) erro
|
|||
defer task.Waiter.Done()
|
||||
err := m.importHistoryArchives(communityID, task.CancelChan)
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to import history archives", zap.Error(err))
|
||||
m.logger.Error("failed to import history archives", zap.Error(err))
|
||||
}
|
||||
m.config.messengerSignalsHandler.DownloadingHistoryArchivesFinished(types.EncodeHex(communityID))
|
||||
}()
|
||||
|
|
|
@ -684,7 +684,7 @@ func (m *Messenger) RequestImportDiscordChannel(request *requests.ImportDiscordC
|
|||
chunksCount := len(discordMessageChunks)
|
||||
|
||||
for ii, msgs := range discordMessageChunks {
|
||||
m.torrentManager.LogStdout(fmt.Sprintf("saving %d/%d chunk with %d discord messages", ii+1, chunksCount, len(msgs)))
|
||||
m.logger.Debug(fmt.Sprintf("saving %d/%d chunk with %d discord messages", ii+1, chunksCount, len(msgs)))
|
||||
err := m.persistence.SaveDiscordMessages(msgs)
|
||||
if err != nil {
|
||||
m.cleanUpImportChannel(request.CommunityID.String(), newChat.ID)
|
||||
|
@ -727,7 +727,7 @@ func (m *Messenger) RequestImportDiscordChannel(request *requests.ImportDiscordC
|
|||
chunksCount = len(messageChunks)
|
||||
|
||||
for ii, msgs := range messageChunks {
|
||||
m.torrentManager.LogStdout(fmt.Sprintf("saving %d/%d chunk with %d app messages", ii+1, chunksCount, len(msgs)))
|
||||
m.logger.Debug(fmt.Sprintf("saving %d/%d chunk with %d app messages", ii+1, chunksCount, len(msgs)))
|
||||
err := m.persistence.SaveMessages(msgs)
|
||||
if err != nil {
|
||||
m.cleanUpImportChannel(request.CommunityID.String(), request.DiscordChannelID)
|
||||
|
@ -791,7 +791,7 @@ func (m *Messenger) RequestImportDiscordChannel(request *requests.ImportDiscordC
|
|||
go func(id string, author *protobuf.DiscordMessageAuthor) {
|
||||
defer wg.Done()
|
||||
|
||||
m.torrentManager.LogStdout(fmt.Sprintf("downloading asset %d/%d", assetCounter.Value()+1, totalAssetsCount))
|
||||
m.logger.Debug(fmt.Sprintf("downloading asset %d/%d", assetCounter.Value()+1, totalAssetsCount))
|
||||
imagePayload, err := discord.DownloadAvatarAsset(author.AvatarUrl)
|
||||
if err != nil {
|
||||
errmsg := fmt.Sprintf("Couldn't download profile avatar '%s': %s", author.AvatarUrl, err.Error())
|
||||
|
@ -845,7 +845,7 @@ func (m *Messenger) RequestImportDiscordChannel(request *requests.ImportDiscordC
|
|||
defer wg.Done()
|
||||
for ii, attachment := range attachments {
|
||||
|
||||
m.torrentManager.LogStdout(fmt.Sprintf("downloading asset %d/%d", assetCounter.Value()+1, totalAssetsCount))
|
||||
m.logger.Debug(fmt.Sprintf("downloading asset %d/%d", assetCounter.Value()+1, totalAssetsCount))
|
||||
|
||||
assetPayload, contentType, err := discord.DownloadAsset(attachment.Url)
|
||||
if err != nil {
|
||||
|
@ -889,7 +889,7 @@ func (m *Messenger) RequestImportDiscordChannel(request *requests.ImportDiscordC
|
|||
chunksCount = len(attachmentChunks)
|
||||
|
||||
for ii, attachments := range attachmentChunks {
|
||||
m.torrentManager.LogStdout(fmt.Sprintf("saving %d/%d chunk with %d discord message attachments", ii+1, chunksCount, len(attachments)))
|
||||
m.logger.Debug(fmt.Sprintf("saving %d/%d chunk with %d discord message attachments", ii+1, chunksCount, len(attachments)))
|
||||
err := m.persistence.SaveDiscordMessageAttachments(attachments)
|
||||
if err != nil {
|
||||
importProgress.AddTaskError(discord.DownloadAssetsTask, discord.Warning(err.Error()))
|
||||
|
@ -1460,7 +1460,7 @@ func (m *Messenger) RequestImportDiscordCommunity(request *requests.ImportDiscor
|
|||
chunksCount := len(discordMessageChunks)
|
||||
|
||||
for ii, msgs := range discordMessageChunks {
|
||||
m.torrentManager.LogStdout(fmt.Sprintf("saving %d/%d chunk with %d discord messages", ii+1, chunksCount, len(msgs)))
|
||||
m.logger.Debug(fmt.Sprintf("saving %d/%d chunk with %d discord messages", ii+1, chunksCount, len(msgs)))
|
||||
err = m.persistence.SaveDiscordMessages(msgs)
|
||||
if err != nil {
|
||||
m.cleanUpImport(communityID)
|
||||
|
@ -1503,7 +1503,7 @@ func (m *Messenger) RequestImportDiscordCommunity(request *requests.ImportDiscor
|
|||
chunksCount = len(messageChunks)
|
||||
|
||||
for ii, msgs := range messageChunks {
|
||||
m.torrentManager.LogStdout(fmt.Sprintf("saving %d/%d chunk with %d app messages", ii+1, chunksCount, len(msgs)))
|
||||
m.logger.Debug(fmt.Sprintf("saving %d/%d chunk with %d app messages", ii+1, chunksCount, len(msgs)))
|
||||
err = m.persistence.SaveMessages(msgs)
|
||||
if err != nil {
|
||||
m.cleanUpImport(communityID)
|
||||
|
@ -1563,7 +1563,7 @@ func (m *Messenger) RequestImportDiscordCommunity(request *requests.ImportDiscor
|
|||
go func(id string, author *protobuf.DiscordMessageAuthor) {
|
||||
defer wg.Done()
|
||||
|
||||
m.torrentManager.LogStdout(fmt.Sprintf("downloading asset %d/%d", assetCounter.Value()+1, totalAssetsCount))
|
||||
m.logger.Debug(fmt.Sprintf("downloading asset %d/%d", assetCounter.Value()+1, totalAssetsCount))
|
||||
imagePayload, err := discord.DownloadAvatarAsset(author.AvatarUrl)
|
||||
if err != nil {
|
||||
errmsg := fmt.Sprintf("Couldn't download profile avatar '%s': %s", author.AvatarUrl, err.Error())
|
||||
|
@ -1615,7 +1615,7 @@ func (m *Messenger) RequestImportDiscordCommunity(request *requests.ImportDiscor
|
|||
defer wg.Done()
|
||||
for ii, attachment := range attachments {
|
||||
|
||||
m.torrentManager.LogStdout(fmt.Sprintf("downloading asset %d/%d", assetCounter.Value()+1, totalAssetsCount))
|
||||
m.logger.Debug(fmt.Sprintf("downloading asset %d/%d", assetCounter.Value()+1, totalAssetsCount))
|
||||
|
||||
assetPayload, contentType, err := discord.DownloadAsset(attachment.Url)
|
||||
if err != nil {
|
||||
|
@ -1659,7 +1659,7 @@ func (m *Messenger) RequestImportDiscordCommunity(request *requests.ImportDiscor
|
|||
chunksCount = len(attachmentChunks)
|
||||
|
||||
for ii, attachments := range attachmentChunks {
|
||||
m.torrentManager.LogStdout(fmt.Sprintf("saving %d/%d chunk with %d discord message attachments", ii+1, chunksCount, len(attachments)))
|
||||
m.logger.Debug(fmt.Sprintf("saving %d/%d chunk with %d discord message attachments", ii+1, chunksCount, len(attachments)))
|
||||
err = m.persistence.SaveDiscordMessageAttachments(attachments)
|
||||
if err != nil {
|
||||
m.cleanUpImport(communityID)
|
||||
|
|
|
@ -1356,7 +1356,7 @@ func (m *Messenger) HandleHistoryArchiveMagnetlinkMessage(state *ReceivedMessage
|
|||
// part of and doesn't own the private key at the same time
|
||||
if !community.IsControlNode() && community.Joined() && clock >= lastClock {
|
||||
if lastSeenMagnetlink == magnetlink {
|
||||
m.torrentManager.LogStdout("already processed this magnetlink")
|
||||
m.logger.Debug("already processed this magnetlink")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -1401,28 +1401,28 @@ func (m *Messenger) downloadAndImportHistoryArchives(id types.HexBytes, magnetli
|
|||
if err != nil {
|
||||
logMsg := "failed to download history archive data"
|
||||
if err == communities.ErrTorrentTimedout {
|
||||
m.torrentManager.LogStdout("torrent has timed out, trying once more...")
|
||||
m.logger.Debug("torrent has timed out, trying once more...")
|
||||
downloadTaskInfo, err = m.torrentManager.DownloadHistoryArchivesByMagnetlink(id, magnetlink, cancel)
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout(logMsg, zap.Error(err))
|
||||
m.logger.Error(logMsg, zap.Error(err))
|
||||
return
|
||||
}
|
||||
} else {
|
||||
m.torrentManager.LogStdout(logMsg, zap.Error(err))
|
||||
m.logger.Debug(logMsg, zap.Error(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if downloadTaskInfo.Cancelled {
|
||||
if downloadTaskInfo.TotalDownloadedArchivesCount > 0 {
|
||||
m.torrentManager.LogStdout(fmt.Sprintf("downloaded %d of %d archives so far", downloadTaskInfo.TotalDownloadedArchivesCount, downloadTaskInfo.TotalArchivesCount))
|
||||
m.logger.Debug(fmt.Sprintf("downloaded %d of %d archives so far", downloadTaskInfo.TotalDownloadedArchivesCount, downloadTaskInfo.TotalArchivesCount))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
err = m.communitiesManager.UpdateLastSeenMagnetlink(id, magnetlink)
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("couldn't update last seen magnetlink", zap.Error(err))
|
||||
m.logger.Error("couldn't update last seen magnetlink", zap.Error(err))
|
||||
}
|
||||
|
||||
err = m.checkIfIMemberOfCommunity(id)
|
||||
|
@ -1432,7 +1432,7 @@ func (m *Messenger) downloadAndImportHistoryArchives(id types.HexBytes, magnetli
|
|||
|
||||
err = m.importHistoryArchives(id, cancel)
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to import history archives", zap.Error(err))
|
||||
m.logger.Error("failed to import history archives", zap.Error(err))
|
||||
m.config.messengerSignalsHandler.DownloadingHistoryArchivesFinished(types.EncodeHex(id))
|
||||
return
|
||||
}
|
||||
|
@ -1475,13 +1475,13 @@ func (m *Messenger) handleArchiveMessages(archiveMessages []*protobuf.WakuMessag
|
|||
|
||||
err := m.handleImportedMessages(importedMessages)
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to handle imported messages", zap.Error(err))
|
||||
m.logger.Error("failed to handle imported messages", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response, err := m.handleRetrievedMessages(otherMessages, false, true)
|
||||
if err != nil {
|
||||
m.torrentManager.LogStdout("failed to write history archive messages to database", zap.Error(err))
|
||||
m.logger.Error("failed to write history archive messages to database", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue