Furrent
Public Member Functions | List of all members
fur::download::downloader::Downloader Class Reference

#include <downloader.hpp>

Public Member Functions

 Downloader (const TorrentFile &torrent, const Peer &peer)
 Construct a new Downloader. No TCP socket is established at this time. More...
 
Result< Downloaded, DownloaderErrortry_download (const Piece &)
 
Outcome< DownloaderErrorensure_connected ()
 

Detailed Description

Handles downloading of torrent pieces. Must be initialized with a TorrentFile and a Peer discovered from that same torrent. This type is intrinsically not copyable because it embeds an ASIO socket.

Constructor & Destructor Documentation

◆ Downloader()

fur::download::downloader::Downloader::Downloader ( const TorrentFile torrent,
const Peer peer 
)
explicit

Construct a new Downloader. No TCP socket is established at this time.

Member Function Documentation

◆ ensure_connected()

Outcome< DownloaderError > fur::download::downloader::Downloader::ensure_connected ( )

Ensures that the socket is present and in good health (not dropped, timed out and such). Should always call this method first, before accessing the socket.

◆ try_download()

Result< Downloaded, DownloaderError > fur::download::downloader::Downloader::try_download ( const Piece task)

Attempt downloading a piece using this Downloader. The function tries it best not to throw any exception (unless something truly exceptional happens). You can assume that any ordinary error will result in a std::nullopt being returned. Errors such as:

  • This peer not having the requested piece available
  • The connection timing out
  • The downloaded piece being corrupt

The documentation for this class was generated from the following files: