libzypp  17.31.31
base_p.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 ----------------------------------------------------------------------/
9 *
10 * This file contains private API, this might break at any time between releases.
11 * You have been warned!
12 *
13 */
14 #ifndef ZYPP_CURL_NG_NETWORK_PRIVATE_DOWNLOADERSTATES_BASE_P_H_INCLUDED
15 #define ZYPP_CURL_NG_NETWORK_PRIVATE_DOWNLOADERSTATES_BASE_P_H_INCLUDED
16 
17 #include <zypp-core/zyppng/base/private/base_p.h>
18 #include <zypp-core/zyppng/base/signals.h>
19 #include <zypp-core/TriBool.h>
20 #include <zypp-curl/ng/network/Downloader>
21 #include <zypp-curl/ng/network/DownloadSpec>
22 #include <zypp-core/zyppng/core/ByteArray>
24 #include <zypp-curl/ng/network/TransferSettings>
27 #include <zypp-media/auth/CredentialManager>
28 
29 namespace zyppng {
30 
31  class NetworkRequestDispatcher;
32  class DownloadPrivate;
33 
41  {
42  ZYPP_DECLARE_PUBLIC(Download)
43  public:
44  DownloadPrivateBase ( Downloader &parent, std::shared_ptr<NetworkRequestDispatcher> requestDispatcher, std::shared_ptr<MirrorControl> mirrors, DownloadSpec &&spec, Download &p );
46 
47  struct Block {
48  off_t start = 0;
49  size_t len = 0;
50 
51  std::string chksumtype;
52  std::optional<UByteArray> chksumVec;
53  std::optional<size_t> chksumCompareLen; //< initialized if only the first few bytes of the checksum should be considered
54  std::optional<size_t> chksumPad; //< initialized if the hashed blocks for a digest need to be padded if a block is smaller ( e.g. last block in a zsync file )
55 
56  int _retryCount = 0; //< how many times was this request restarted
57  NetworkRequestError _failedWithErr; //< what was the error this request failed with
58  };
59 
60  struct Request : public NetworkRequest {
61 
63  using Ptr = std::shared_ptr<Request>;
64  using WeakPtr = std::shared_ptr<Request>;
65 
66  template <typename Receiver>
67  void connectSignals ( Receiver &dl ) {
68  _sigStartedConn = connect ( &NetworkRequest::sigStarted, dl, &Receiver::onRequestStarted );
69  _sigProgressConn = connect ( &NetworkRequest::sigProgress, dl, &Receiver::onRequestProgress );
70  _sigFinishedConn = connect ( &NetworkRequest::sigFinished, dl, &Receiver::onRequestFinished );
71  }
72  void disconnectSignals ();
73 
74  time_t _authTimestamp = 0; //< timestamp of the AuthData we tried already
75  Url _originalUrl; //< The unstripped URL as it was passed to Download , before transfer settings are removed
77 
78  connection _sigStartedConn;
79  connection _sigProgressConn;
80  connection _sigFinishedConn;
81  };
82 
83 
84  bool _emittedSigStart = false;
85  bool handleRequestAuthError(std::shared_ptr<Request> req, const zyppng::NetworkRequestError &err);
86 
88 
89 #if ENABLE_ZCHUNK_COMPRESSION
90  bool hasZckInfo () const;
91 #endif
92 
93  std::shared_ptr<NetworkRequestDispatcher> _requestDispatcher;
94  std::shared_ptr<MirrorControl> _mirrorControl;
95 
96  zypp::media::CredentialManager::CredentialSet _credCache; //< the credential cache for this download
97 
98  DownloadSpec _spec; // the download settings
99  mutable zypp::TriBool _specHasZckInfo = zypp::indeterminate;
100 
101  Downloader *_parent = nullptr;
102 
103  time_t _lastTriedAuthTime = 0; //< if initialized this shows the last timestamp that got from user code for a auth request
104  bool _stopOnMetalink = false; //< Stop the download if a metalink was received for external parsing
105  bool _stoppedOnMetalink = false; //< Statemachine was stopped after receiving a metalink file
107 
108  Signal< void ( Download &req )> _sigStarted;
109  Signal< void ( Download &req, Download::State state )> _sigStateChanged;
110  Signal< void ( Download &req, off_t dlnow )> _sigAlive;
111  Signal< void ( Download &req, off_t dltotal, off_t dlnow )> _sigProgress;
112  Signal< void ( Download &req )> _sigFinished;
113  Signal< void ( zyppng::Download &req, zyppng::NetworkAuthData &auth, const std::string &availAuth )> _sigAuthRequired;
114 
115  };
116 
117 }
118 
119 #endif
Signal< void(Download &req, off_t dltotal, off_t dlnow)> _sigProgress
Definition: base_p.h:111
std::optional< UByteArray > chksumVec
Definition: base_p.h:52
The Downloader class.
Definition: downloader.h:38
Downloader * _parent
Definition: base_p.h:101
DownloadSpec _spec
Definition: base_p.h:98
std::optional< size_t > chksumCompareLen
Definition: base_p.h:53
bool handleRequestAuthError(std::shared_ptr< Request > req, const zyppng::NetworkRequestError &err)
Definition: downloader.cc:31
Holds transfer setting.
DownloadPrivateBase(Downloader &parent, std::shared_ptr< NetworkRequestDispatcher > requestDispatcher, std::shared_ptr< MirrorControl > mirrors, DownloadSpec &&spec, Download &p)
Definition: downloader.cc:20
zypp::TriBool _specHasZckInfo
Definition: base_p.h:99
std::shared_ptr< Request > Ptr
Definition: base_p.h:63
NetworkRequest(Url url, zypp::Pathname targetFile, FileMode fMode=WriteExclusive)
Definition: request.cc:724
Signal< void(Download &req, Download::State state)> _sigStateChanged
Definition: base_p.h:109
NetworkRequest::Priority _defaultSubRequestPriority
Definition: base_p.h:106
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:30
Signal< void(Download &req, off_t dlnow)> _sigAlive
Definition: base_p.h:110
std::shared_ptr< MirrorControl > _mirrorControl
Definition: base_p.h:94
Signal< void(Download &req)> _sigStarted
Definition: base_p.h:108
The NetworkRequestError class Represents a error that occured in.
MirrorControl::MirrorHandle _myMirror
Definition: base_p.h:76
NetworkRequestError _failedWithErr
Definition: base_p.h:57
std::shared_ptr< Request > WeakPtr
Definition: base_p.h:64
std::optional< size_t > chksumPad
Definition: base_p.h:54
std::shared_ptr< NetworkRequestDispatcher > _requestDispatcher
Definition: base_p.h:93
NetworkRequestError safeFillSettingsFromURL(const Url &url, TransferSettings &set)
Definition: downloader.cc:153
std::shared_ptr< Mirror > MirrorHandle
std::set< AuthData_Ptr, AuthDataComparator > CredentialSet
Signal< void(zyppng::Download &req, zyppng::NetworkAuthData &auth, const std::string &availAuth)> _sigAuthRequired
Definition: base_p.h:113
SignalProxy< void(NetworkRequest &req, const NetworkRequestError &err)> sigFinished()
Signals that the download finished.
Definition: request.cc:1035
SignalProxy< void(NetworkRequest &req)> sigStarted()
Signals that the dispatcher dequeued the request and actually starts downloading data.
Definition: request.cc:1020
void connectSignals(Receiver &dl)
Definition: base_p.h:67
Signal< void(Download &req)> _sigFinished
Definition: base_p.h:112
SignalProxy< void(NetworkRequest &req, off_t dltotal, off_t dlnow, off_t ultotal, off_t ulnow)> sigProgress()
Signals if there was data read from the download.
Definition: request.cc:1030
zypp::media::CredentialManager::CredentialSet _credCache
Definition: base_p.h:96