libzypp 17.31.23
mirrorcontrol_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_MIRRORCONTROL_P_H
15#define ZYPP_CURL_NG_NETWORK_PRIVATE_MIRRORCONTROL_P_H
16
17#include <zypp-core/zyppng/core/Url>
18#include <zypp-core/zyppng/base/Signals>
19#include <zypp-core/zyppng/base/Base>
20#include <zypp-core/zyppng/base/Timer>
23#include <zypp-curl/parser/MetaLinkParser>
24#include <vector>
25#include <unordered_map>
26
27namespace zyppng {
28
29 class MirrorControl : public Base {
30
31 public:
32
33 struct Mirror {
34
36 uint rating = 100; // rating based on connection time higher is worse
37 uint penalty = 0; //additional value that is added to the rating when sorting the mirrors, is increased and lowered for failed or successful transactions
38 uint maxRanges = 0; //the maximum number of ranges that can be requested from this mirror
39 uint finishedTransfers = 0; //how many transfers did we already send to the mirror
40 uint runningTransfers = 0; //currently running transfers
41 uint failedTransfers = 0; //how many transfers have failed in a row using this mirror
42 uint successfulTransfers = 0; //how many transfers were successful
43
44 void startTransfer();
45 void finishTransfer( const bool success );
46 void cancelTransfer();
47 uint maxConnections () const;
48 bool hasFreeConnections () const;
49
50 private:
51 Mirror( MirrorControl &parent );
52 void transferUnref ();
53
54 private:
55 friend class MirrorControl;
58 sigc::connection _finishedConn;
59
60 uint _maxConnections = 0; //the maximum number of concurrent connections to this mirror, 0 means use system default
61 };
62
63 using Ptr = std::shared_ptr<MirrorControl>;
64 using MirrorHandle = std::shared_ptr<Mirror>;
65 using MirrorPick = std::pair< std::vector<Url>::const_iterator, MirrorHandle >;
66
67 static Ptr create ();
68 virtual ~MirrorControl();
69 void registerMirrors( const std::vector<zypp::media::MetalinkMirror> &urls );
70
75 struct PickResult {
76 enum {
82 };
83 PickResult pickBestMirror( const std::vector<Url> &mirrors );
84
85 bool allMirrorsReady () const;
86
87 SignalProxy<void()> sigNewMirrorsReady();
88 SignalProxy<void()> sigAllMirrorsReady();
89 private:
91 std::string makeKey ( const zypp::Url &url ) const;
92 sigc::connection _queueEmptyConn;
93 NetworkRequestDispatcher::Ptr _dispatcher; //Mirror Control using its own NetworkRequestDispatcher, to avoid waiting for other downloads
94 std::unordered_map<std::string, MirrorHandle> _handles;
95
96 Timer::Ptr _newMirrSigDelay; // we use a delay timer to emit the "someMirrorsReady" signal
97
98 Signal<void()> _sigAllMirrorsReady;
99 Signal<void()> _sigNewMirrorsReady;
100 };
101
102#if 0
103
107 class MirrorRef
108 {
109 public:
110 MirrorRef ( MirrorControl::MirrorHandle handle );
111 ~MirrorRef();
112
113 void startTransfer();
114 void finishTransfer( const bool success );
115 void cancelTransfer();
116 operator bool() const;
117
119
120 private:
121 struct Helper {
122 ~Helper();
124 bool _cancelOnDestruct = false;
125 };
126 std::shared_ptr<Helper> _data;
127 };
128#endif
129
130}
131
132#endif // ZYPP_CURL_NG_NETWORK_PRIVATE_MIRRORCONTROL_P_H
std::list< PublicKeyData > _data
Definition: KeyRing.cc:191
Url manipulation class.
Definition: Url.h:92
std::pair< std::vector< Url >::const_iterator, MirrorHandle > MirrorPick
PickResult pickBestMirror(const std::vector< Url > &mirrors)
sigc::connection _queueEmptyConn
bool allMirrorsReady() const
std::shared_ptr< Mirror > MirrorHandle
void registerMirrors(const std::vector< zypp::media::MetalinkMirror > &urls)
std::string makeKey(const zypp::Url &url) const
std::shared_ptr< MirrorControl > Ptr
SignalProxy< void()> sigAllMirrorsReady()
SignalProxy< void()> sigNewMirrorsReady()
Signal< void()> _sigNewMirrorsReady
NetworkRequestDispatcher::Ptr _dispatcher
std::unordered_map< std::string, MirrorHandle > _handles
Signal< void()> _sigAllMirrorsReady
std::shared_ptr< NetworkRequest > Ptr
Definition: request.h:44
void finishTransfer(const bool success)
NetworkRequest::Ptr _request
enum zyppng::MirrorControl::PickResult::@1 code