Skip to content

Commit

Permalink
Set existing torrent webseeds after download (#10177)
Browse files Browse the repository at this point in the history
Copy PR #10149 into main

Co-authored-by: Mark Holt <[email protected]>
  • Loading branch information
yperbasis and mh0lt authored May 2, 2024
1 parent f19669d commit 8f2cdbe
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 8f2cdbe

Please sign in to comment.