Skip to content

Commit

Permalink
Set existing torrent webseeds after download (#10149)
Browse files Browse the repository at this point in the history
Fix a timing hole where torrents that get created before webseeds have
been downloaded don't get webseeds set.
  • Loading branch information
mh0lt authored and AskAlexSharov committed May 2, 2024
1 parent 10f368e commit 8f5aaa4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 9 additions & 0 deletions erigon-lib/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,15 @@ func (d *Downloader) mainLoop(silent bool) error {
if err := d.addTorrentFilesFromDisk(true); err != nil && !errors.Is(err, context.Canceled) {
d.logger.Warn("[snapshots] addTorrentFilesFromDisk", "err", err)
}

d.lock.Lock()
defer d.lock.Unlock()

for _, t := range d.torrentClient.Torrents() {
if urls, ok := d.webseeds.ByFileName(t.Name()); ok {
t.AddWebSeeds(urls)
}
}
}()
}

Expand Down
9 changes: 4 additions & 5 deletions erigon-lib/downloader/webseed.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ type WebSeeds struct {
torrentUrls snaptype.TorrentUrls // HTTP urls of .torrent files
downloadTorrentFile bool
torrentsWhitelist snapcfg.Preverified

seeds []*url.URL
seeds []*url.URL

logger log.Logger
verbosity log.Lvl
Expand Down Expand Up @@ -97,10 +96,10 @@ func (d *WebSeeds) getWebDownloadInfo(ctx context.Context, t *torrent.Torrent) (
return infos, seedHashMismatches, nil
}

func (d *WebSeeds) SetTorrent(t *AtomicTorrentFS, whiteList snapcfg.Preverified, downloadTorrentFile bool) {
func (d *WebSeeds) SetTorrent(torrentFS *AtomicTorrentFS, whiteList snapcfg.Preverified, downloadTorrentFile bool) {
d.downloadTorrentFile = downloadTorrentFile
d.torrentsWhitelist = whiteList
d.torrentFiles = t
d.torrentFiles = torrentFS
}

func (d *WebSeeds) checkHasTorrents(manifestResponse snaptype.WebSeedsFromProvider, report *WebSeedCheckReport) {
Expand Down Expand Up @@ -405,8 +404,8 @@ func (d *WebSeeds) makeWebSeedUrls(listsOfFiles []snaptype.WebSeedsFromProvider,
}

d.lock.Lock()
defer d.lock.Unlock()
d.byFileName = webSeedUrls
d.lock.Unlock()
}

func (d *WebSeeds) TorrentUrls() snaptype.TorrentUrls {
Expand Down

0 comments on commit 8f5aaa4

Please sign in to comment.