feat(communities): retry downloading archive data
When fetching torrent info after receiving a magnet link, it can happen that the request times out. We want to retry downloading the data again at least once more before giving up
This commit is contained in:
parent
dd49c4c954
commit
69e84b5673
|
@ -36,6 +36,8 @@ var defaultAnnounceList = [][]string{
|
||||||
}
|
}
|
||||||
var pieceLength = 100 * 1024
|
var pieceLength = 100 * 1024
|
||||||
|
|
||||||
|
var ErrTorrentTimedout = errors.New("torrent has timed out")
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
persistence *Persistence
|
persistence *Persistence
|
||||||
ensSubscription chan []*ens.VerificationRecord
|
ensSubscription chan []*ens.VerificationRecord
|
||||||
|
@ -1929,7 +1931,7 @@ func (m *Manager) DownloadHistoryArchivesByMagnetlink(communityID types.HexBytes
|
||||||
m.LogStdout("fetching torrent info", zap.String("magnetlink", magnetlink))
|
m.LogStdout("fetching torrent info", zap.String("magnetlink", magnetlink))
|
||||||
select {
|
select {
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
return nil, errors.New("torrent has timed out")
|
return nil, ErrTorrentTimedout
|
||||||
case <-torrent.GotInfo():
|
case <-torrent.GotInfo():
|
||||||
files := torrent.Files()
|
files := torrent.Files()
|
||||||
|
|
||||||
|
|
|
@ -925,10 +925,19 @@ func (m *Messenger) HandleHistoryArchiveMagnetlinkMessage(state *ReceivedMessage
|
||||||
go func() {
|
go func() {
|
||||||
downloadedArchiveIDs, err := m.communitiesManager.DownloadHistoryArchivesByMagnetlink(id, magnetlink)
|
downloadedArchiveIDs, err := m.communitiesManager.DownloadHistoryArchivesByMagnetlink(id, magnetlink)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("failed to download history archive data", err)
|
logMsg := "failed to download history archive data"
|
||||||
m.logger.Debug("failed to download history archive data", zap.Error(err))
|
if err == communities.ErrTorrentTimedout {
|
||||||
|
m.communitiesManager.LogStdout("torrent has timed out, trying once more...")
|
||||||
|
downloadedArchiveIDs, err = m.communitiesManager.DownloadHistoryArchivesByMagnetlink(id, magnetlink)
|
||||||
|
if err != nil {
|
||||||
|
m.communitiesManager.LogStdout(logMsg, zap.Error(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
m.communitiesManager.LogStdout(logMsg, zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
messagesToHandle, err := m.communitiesManager.ExtractMessagesFromHistoryArchives(id, downloadedArchiveIDs)
|
messagesToHandle, err := m.communitiesManager.ExtractMessagesFromHistoryArchives(id, downloadedArchiveIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue