From aa25792daf236b04abd7d346f3d9ea411519c53e Mon Sep 17 00:00:00 2001 From: Alex Sharov <AskAlexSharov@gmail.com> Date: Thu, 27 Jan 2022 13:02:44 +0700 Subject: [PATCH] Downloader: use default config (including db) #3359 --- cmd/downloader/downloader/downloader.go | 19 ++++++------------- cmd/downloader/main.go | 4 ++-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/cmd/downloader/downloader/downloader.go b/cmd/downloader/downloader/downloader.go index 5f6914fad0..f90f784477 100644 --- a/cmd/downloader/downloader/downloader.go +++ b/cmd/downloader/downloader/downloader.go @@ -22,11 +22,10 @@ import ( const ASSERT = false type Client struct { - Cli *torrent.Client - pieceCompletionStore storage.PieceCompletion + Cli *torrent.Client } -func TorrentConfig(snapshotsDir string, seeding bool, peerID string, verbosity lg.Level, downloadRate, uploadRate datasize.ByteSize, torrentPort int) (*torrent.ClientConfig, storage.PieceCompletion, error) { +func TorrentConfig(snapshotsDir string, seeding bool, peerID string, verbosity lg.Level, downloadRate, uploadRate datasize.ByteSize, torrentPort int) (*torrent.ClientConfig, error) { torrentConfig := DefaultTorrentConfig() torrentConfig.ListenPort = torrentPort torrentConfig.Seed = seeding @@ -44,23 +43,18 @@ func TorrentConfig(snapshotsDir string, seeding bool, peerID string, verbosity l } torrentConfig.Logger = NewAdapterLogger().FilterLevel(verbosity) - progressStore, err := storage.NewBoltPieceCompletion(snapshotsDir) - if err != nil { - return nil, nil, fmt.Errorf("NewBoltPieceCompletion: likely another process already run on this directory: %w", err) - } - torrentConfig.DefaultStorage = storage.NewMMapWithCompletion(snapshotsDir, progressStore) + torrentConfig.DefaultStorage = storage.NewMMap(snapshotsDir) - return torrentConfig, progressStore, nil + return torrentConfig, nil } -func New(cfg *torrent.ClientConfig, progressStore storage.PieceCompletion) (*Client, error) { +func New(cfg *torrent.ClientConfig) (*Client, error) { torrentClient, err := torrent.NewClient(cfg) if err != nil { return nil, fmt.Errorf("fail to start torrent client: %w", err) } return &Client{ - Cli: torrentClient, - pieceCompletionStore: progressStore, + Cli: torrentClient, }, nil } @@ -93,7 +87,6 @@ func (cli *Client) Close() { for _, tr := range cli.Cli.Torrents() { tr.Drop() } - cli.pieceCompletionStore.Close() cli.Cli.Close() } diff --git a/cmd/downloader/main.go b/cmd/downloader/main.go index b67d1fbea2..0f8ee48bd5 100644 --- a/cmd/downloader/main.go +++ b/cmd/downloader/main.go @@ -131,11 +131,11 @@ func Downloader(ctx context.Context, cmd *cobra.Command) error { return fmt.Errorf("get peer id: %w", err) } - cfg, pieceStore, err := downloader.TorrentConfig(snapshotsDir, seeding, string(peerID), torrentLogLevel, downloadRate, uploadRate, torrentPort) + cfg, err := downloader.TorrentConfig(snapshotsDir, seeding, string(peerID), torrentLogLevel, downloadRate, uploadRate, torrentPort) if err != nil { return fmt.Errorf("TorrentConfig: %w", err) } - t, err = downloader.New(cfg, pieceStore) + t, err = downloader.New(cfg) if err != nil { return err } -- GitLab