Debian Codegraph @

contrib/epee/src/network_throttle.cpp

raw symbols SCIP
1 /**
2 @file
3 @author rfree (current maintainer in monero.cc project)
4 @brief interface for throttling of connection (count and rate-limit speed etc)
5 @details <PRE>
6
7 Throttling work by:
8 1) taking note of all traffic (hooks added e.g. to connection class) and measuring speed
9 2) depending on that information we sleep before sending out data (or send smaller portions of data)
10 3) depending on the information we can also sleep before sending requests or ask for smaller sets of data to download
11
12 </PRE>
13
14 @image html images/net/rate1-down-1k.png
15 @image html images/net/rate1-down-full.png
16 @image html images/net/rate1-up-10k.png
17 @image html images/net/rate1-up-full.png
18 @image html images/net/rate2-down-100k.png
19 @image html images/net/rate2-down-10k.png
20 @image html images/net/rate2-down-50k.png
21 @image html images/net/rate2-down-full.png
22 @image html images/net/rate2-up-100k.png
23 @image html images/net/rate2-up-10k.png
24 @image html images/net/rate3-up-10k.png
25
26
27 */
28
29 // Copyright (c) 2014-2022, The Monero Project
30 //
31 // All rights reserved.
32 //
33 // Redistribution and use in source and binary forms, with or without modification, are
34 // permitted provided that the following conditions are met:
35 //
36 // 1. Redistributions of source code must retain the above copyright notice, this list of
37 // conditions and the following disclaimer.
38 //
39 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
40 // of conditions and the following disclaimer in the documentation and/or other
41 // materials provided with the distribution.
42 //
43 // 3. Neither the name of the copyright holder nor the names of its contributors may be
44 // used to endorse or promote products derived from this software without specific
45 // prior written permission.
46 //
47 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
48 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
49 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
50 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
52 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
54 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
55 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
57 #include "net/network_throttle-detail.hpp"
58
59 namespace epee
60 {
61 namespace net_utils
62 {
63
64 // ================================================================================================
65 // network_throttle_manager
66 // ================================================================================================
67
68 // ================================================================================================
69 // static:
70 boost::mutex network_throttle_manager::m_lock_get_global_throttle_in;
71 boost::mutex network_throttle_manager::m_lock_get_global_throttle_inreq;
72 boost::mutex network_throttle_manager::m_lock_get_global_throttle_out;
73
74 // ================================================================================================
75 // methods:
76 i_network_throttle & network_throttle_manager::get_global_throttle_in() {
77 static network_throttle obj_get_global_throttle_in("in/all","<<< global-IN",10);
78 return obj_get_global_throttle_in;
79 }
80
81
82
83 i_network_throttle & network_throttle_manager::get_global_throttle_inreq() {
84 static network_throttle obj_get_global_throttle_inreq("inreq/all", "<== global-IN-REQ",10);
85 return obj_get_global_throttle_inreq;
86 }
87
88
89 i_network_throttle & network_throttle_manager::get_global_throttle_out() {
90 static network_throttle obj_get_global_throttle_out("out/all", ">>> global-OUT",10);
91 return obj_get_global_throttle_out;
92 }
93
94
95
96
97 network_throttle_bw::network_throttle_bw(const std::string &name1)
98 : m_in("in/"+name1, name1+"-DOWNLOAD"), m_inreq("inreq/"+name1, name1+"-DOWNLOAD-REQUESTS"), m_out("out/"+name1, name1+"-UPLOAD")
99 { }
100
101
102
103
104 } // namespace
105 } // namespace
106
107
108
109
110