Skip to content

Commit

Permalink
Revert "Introduce logger for community archive related activity"
Browse files Browse the repository at this point in the history
This reverts commit 3aed7af.
  • Loading branch information
0x-r4bbit committed May 10, 2022
1 parent 299f4cc commit 1b49784
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions protocol/communities/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type Manager struct {
ensVerifier *ens.Verifier
identity *ecdsa.PublicKey
logger *zap.Logger
archiveLogger *zap.Logger
transport *transport.Transport
quit chan struct{}
torrentConfig *params.TorrentConfig
Expand All @@ -65,16 +64,8 @@ func NewManager(identity *ecdsa.PublicKey, db *sql.DB, logger *zap.Logger, verif
}
}

lc := zap.NewDevelopmentConfig()
lc.OutputPaths = []string{"stdout"}
archiveLogger, err := lc.Build()
if err != nil {
return nil, errors.Wrap(err, "failed to create a archive logger")
}

manager := &Manager{
logger: logger,
archiveLogger: archiveLogger,
identity: identity,
quit: make(chan struct{}),
transport: transport,
Expand Down Expand Up @@ -205,7 +196,7 @@ func (m *Manager) StartTorrentClient() error {
}
}

m.archiveLogger.Info("starting torrent client", zap.Any("port", m.torrentConfig.Port))
m.logger.Info("Starting torrent client", zap.Any("port", m.torrentConfig.Port))
// Instantiating the client will make it bootstrap and listen eagerly,
// so no go routine is needed here
client, err := torrent.NewClient(config)
Expand All @@ -219,7 +210,7 @@ func (m *Manager) StartTorrentClient() error {
func (m *Manager) StopTorrentClient() []error {
if m.TorrentClientStarted() {
m.StopHistoryArchiveTasksIntervals()
m.archiveLogger.Info("stopping torrent client")
m.logger.Info("Stopping torrent client")
errs := m.torrentClient.Close()
if len(errs) > 0 {
return errs
Expand Down Expand Up @@ -1249,7 +1240,7 @@ func (m *Manager) StartHistoryArchiveTasksInterval(community *Community, interva
_, exists := m.historyArchiveTasks[id]

if exists {
m.archiveLogger.Debug("history archive tasks interval already runs for community: ", zap.Any("id", id))
m.logger.Debug("History archive tasks interval already runs for community: ", zap.Any("id", id))
return
}

Expand All @@ -1260,11 +1251,11 @@ func (m *Manager) StartHistoryArchiveTasksInterval(community *Community, interva
ticker := time.NewTicker(interval)
defer ticker.Stop()

m.archiveLogger.Debug("starting history archive tasks interval", zap.Any("id", id))
m.logger.Debug("Starting history archive tasks interval", zap.Any("id", id))
for {
select {
case <-ticker.C:
m.archiveLogger.Debug("executing history archive tasks", zap.Any("id", id))
m.logger.Debug("Executing history archive tasks", zap.Any("id", id))
lastArchiveEndDateTimestamp, err := m.GetHistoryArchivePartitionStartTimestamp(community.ID())
if err != nil {
m.logger.Debug("failed to get last archive end date", zap.Error(err))
Expand Down Expand Up @@ -1314,7 +1305,7 @@ func (m *Manager) StopHistoryArchiveTasksIntervals() {
func (m *Manager) StopHistoryArchiveTasksInterval(communityID types.HexBytes) {
task, ok := m.historyArchiveTasks[communityID.String()]
if ok {
m.archiveLogger.Info("stopping history archive tasks interval", zap.Any("id", communityID.String()))
m.logger.Info("Stopping history archive tasks interval", zap.Any("id", communityID.String()))
close(task)
}
}
Expand Down Expand Up @@ -1376,7 +1367,7 @@ func (m *Manager) CreateHistoryArchiveTorrent(communityID types.HexBytes, topics
CommunityID: communityID.String(),
}})

m.archiveLogger.Debug("creating archives...",
m.logger.Debug("Creating archives...",
zap.Any("startDate", startDate),
zap.Any("endDate", endDate),
zap.Duration("partition", partition),
Expand All @@ -1385,7 +1376,7 @@ func (m *Manager) CreateHistoryArchiveTorrent(communityID types.HexBytes, topics
if from.Equal(endDate) || from.After(endDate) {
break
}
m.archiveLogger.Debug("creating message archive",
m.logger.Debug("Creating message archive",
zap.Duration("partition", partition),
zap.Any("from", from),
zap.Any("to", to),
Expand All @@ -1397,7 +1388,7 @@ func (m *Manager) CreateHistoryArchiveTorrent(communityID types.HexBytes, topics

if len(messages) == 0 {
// No need to create an archive with zero messages
m.archiveLogger.Debug("no messages in this partition")
m.logger.Debug("No messages in this partition")
from = to
to = to.Add(partition)
if to.After(endDate) {
Expand Down Expand Up @@ -1517,7 +1508,7 @@ func (m *Manager) CreateHistoryArchiveTorrent(communityID types.HexBytes, topics
},
})
} else {
m.archiveLogger.Debug("no archives created")
m.logger.Debug("No archives created")
m.publish(&Subscription{
NoHistoryArchivesCreatedSignal: &signal.NoHistoryArchivesCreatedSignal{
CommunityID: communityID.String(),
Expand Down Expand Up @@ -1577,8 +1568,8 @@ func (m *Manager) SeedHistoryArchiveTorrent(communityID types.HexBytes) error {
CommunityID: communityID.String(),
},
})
m.archiveLogger.Info("seeding torrent", zap.String("id", id))
m.archiveLogger.Info(metaInfo.Magnet(nil, &info).String())
m.logger.Info("Seeding torrent", zap.String("id", id))
m.logger.Info(metaInfo.Magnet(nil, &info).String())
return nil
}

Expand All @@ -1589,7 +1580,7 @@ func (m *Manager) UnseedHistoryArchiveTorrent(communityID types.HexBytes) {
if exists {
torrent, ok := m.torrentClient.Torrent(hash)
if ok {
m.archiveLogger.Debug("unseeding and dropping torrent for community: ", zap.Any("id", id))
m.logger.Debug("Unseeding and dropping torrent for community: ", zap.Any("id", id))
torrent.Drop()
delete(m.torrentTasks, id)

Expand Down Expand Up @@ -1617,7 +1608,7 @@ func (m *Manager) DownloadHistoryArchivesByMagnetlink(communityID types.HexBytes
return nil, err
}

m.archiveLogger.Debug("adding torrent via magnetlink for community", zap.String("id", id), zap.String("magnetlink", magnetlink))
m.logger.Debug("adding torrent via magnetlink for community", zap.String("id", id), zap.String("magnetlink", magnetlink))
torrent, err := m.torrentClient.AddMagnet(magnetlink)
if err != nil {
return nil, err
Expand All @@ -1638,7 +1629,7 @@ func (m *Manager) DownloadHistoryArchivesByMagnetlink(communityID types.HexBytes

indexFile := files[i]
indexFile.Download()
m.archiveLogger.Debug("downloading history archive index")
m.logger.Debug("downloading history archive index")

ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
Expand Down Expand Up @@ -1666,7 +1657,7 @@ func (m *Manager) DownloadHistoryArchivesByMagnetlink(communityID types.HexBytes
metadata := index.Archives[hash]
hasArchive, err := m.persistence.HasMessageArchiveID(communityID, hash)
if err != nil {
m.logger.Debug("failed to check if has message archive id", zap.Error(err))
m.logger.Debug("Failed to check if has message archive id", zap.Error(err))
continue
}
if hasArchive {
Expand All @@ -1676,8 +1667,8 @@ func (m *Manager) DownloadHistoryArchivesByMagnetlink(communityID types.HexBytes
startIndex := int(metadata.Offset) / pieceLength
endIndex := startIndex + int(metadata.Size)/pieceLength

m.archiveLogger.Debug("downloading data for message archive", zap.String("hash", hash))
m.archiveLogger.Debug("pieces (start, end)", zap.Any("startIndex", startIndex), zap.Any("endIndex", endIndex-1))
m.logger.Debug("downloading data for message archive", zap.String("hash", hash))
m.logger.Debug("pieces (start, end)", zap.Any("startIndex", startIndex), zap.Any("endIndex", endIndex-1))
torrent.DownloadPieces(startIndex, endIndex)

psc := torrent.SubscribePieceStateChanges()
Expand Down

0 comments on commit 1b49784

Please sign in to comment.