diff --git a/cmd/downloader/downloader/downloader.go b/cmd/downloader/downloader/downloader.go index 5f6914fad06701d92585ff37134d3b21b994fc2d..f90f7844772984547ec071d2a5c6b004c0258eb0 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 b67d1fbea2f8677b66a9a585206ab0d4bd86a137..0f8ee48bd55e32d2c0e4d75c785e7e6d3bf9eab1 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 }