Panda3D
config_downloader.cxx
1 // Filename: config_downloader.cxx
2 // Created by: mike (19Mar00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "dconfig.h"
16 #include "config_downloader.h"
17 #include "httpChannel.h"
18 #include "virtualFileHTTP.h"
19 #include "virtualFileMountHTTP.h"
20 #include "pandaSystem.h"
21 
22 
23 ConfigureDef(config_downloader);
24 NotifyCategoryDef(downloader, "");
25 
26 ConfigVariableInt downloader_byte_rate
27 ("downloader-byte-rate", 500000,
28  PRC_DESC("Specifies the default max bytes per second of throughput that is "
29  "supported by any HTTP connections with download-throttle enabled. "
30  "This may also be set on a per-channel basis with "
31  "HTTPChannel::set_max_bytes_per_second(). It has no effect unless "
32  "download-throttle (or HTTPChannel::set_download_throttle) is true."));
33 
34 ConfigVariableBool download_throttle
35 ("download-throttle", false,
36  PRC_DESC("When this is true, all HTTP channels will be bandwidth-limited "
37  "so as not to consume more than downloader-byte-rate bytes per "
38  "second."));
39 
40 ConfigVariableDouble downloader_frequency
41 ("downloader-frequency", 0.2,
42  PRC_DESC("Frequency of download chunk requests in seconds (or fractions of) "
43  "(Estimated 200 msec round-trip to server)."));
44 
45 ConfigVariableInt downloader_timeout
46 ("downloader-timeout", 15);
47 
48 ConfigVariableInt downloader_timeout_retries
49 ("downloader-timeout-retries", 5);
50 
51 ConfigVariableDouble decompressor_step_time
52 ("decompressor-step-time", 0.005,
53  PRC_DESC("Specifies the maximum amount of time that should be consumed by "
54  "a single call to Decompressor::run()."));
55 
56 ConfigVariableDouble extractor_step_time
57 ("extractor-step-time", 0.005,
58  PRC_DESC("Specifies the maximum amount of time that should be consumed by "
59  "a single call to Extractor::step()."));
60 
61 ConfigVariableInt patcher_buffer_size
62 ("patcher-buffer-size", 16384,
63  PRC_DESC("Limits the size of the buffer used in a single call to "
64  "Patcher::run(). Increasing this may help the Patcher "
65  "perform more work before returning."));
66 
67 ConfigVariableBool http_proxy_tunnel
68 ("http-proxy-tunnel", false,
69  PRC_DESC("This specifies the default value for HTTPChannel::set_proxy_tunnel(). "
70  "If this is true, we will tunnel through a proxy for all connections, "
71  "instead of asking the proxy to serve documents normally."));
72 
73 ConfigVariableDouble http_connect_timeout
74 ("http-connect-timeout", 10.0,
75  PRC_DESC("This is the default amount of time to wait for a TCP/IP connection "
76  "to be established, in seconds."));
77 
78 ConfigVariableDouble http_timeout
79 ("http-timeout", 20.0,
80  PRC_DESC("This is the default amount of time to wait for the HTTP server (or "
81  "proxy) to finish sending its response to our request, in seconds. "
82  "It starts counting after the TCP connection has been established "
83  "(http_connect_timeout, above) and the request has been sent."));
84 
85 ConfigVariableInt http_skip_body_size
86 ("http-skip-body-size", 8192,
87  PRC_DESC("This is the maximum number of bytes in a received "
88  "(but unwanted) body that will be skipped past, in "
89  "order to reset to a new request. "
90  "See HTTPChannel::set_skip_body_size()."));
91 
92 ConfigVariableDouble http_idle_timeout
93 ("http-idle-timeout", 5.0,
94  PRC_DESC("This the amount of time, in seconds, in which a "
95  "previously-established connection is allowed to remain open "
96  "and unused. If a previous connection has remained unused for "
97  "at least this number of seconds, it will be closed and a new "
98  "connection will be opened; otherwise, the same connection "
99  "will be reused for the next request (for a particular "
100  "HTTPChannel)."));
101 
102 ConfigVariableInt http_max_connect_count
103 ("http-max-connect-count", 10,
104  PRC_DESC("This is the maximum number of times to try reconnecting to the "
105  "server on any one document attempt. This is just a failsafe to "
106  "prevent the code from attempting runaway connections; this limit "
107  "should never be reached in practice."));
108 
109 ConfigVariableInt tcp_header_size
110 ("tcp-header-size", 2,
111  PRC_DESC("Specifies the number of bytes to use to specify the datagram "
112  "length when writing a datagram on a TCP stream. This may be "
113  "0, 2, or 4. The server and client must agree on this value."));
114 
115 ConfigureFn(config_downloader) {
116  init_libdownloader();
117 }
118 
119 ////////////////////////////////////////////////////////////////////
120 // Function: init_libdownloader
121 // Description: Initializes the library. This must be called at
122 // least once before any of the functions or classes in
123 // this library can be used. Normally it will be
124 // called by the static initializers and need not be
125 // called explicitly, but special cases exist.
126 ////////////////////////////////////////////////////////////////////
127 void
128 init_libdownloader() {
129  static bool initialized = false;
130  if (initialized) {
131  return;
132  }
133  initialized = true;
134 
135 #ifdef HAVE_OPENSSL
136  HTTPChannel::init_type();
137  VirtualFileHTTP::init_type();
138  VirtualFileMountHTTP::init_type();
139 
140  VirtualFileMountHTTP::reload_vfs_mount_url();
141 
142  // We need to define this here, rather than above, to guarantee that
143  // it has been initialized by the time we check it.
144  ConfigVariableBool early_random_seed
145  ("early-random-seed", false,
146  PRC_DESC("Configure this true to compute the SSL random seed "
147  "early on in the application (specifically, when the libpandaexpress "
148  "library is loaded), or false to defer this until it is actually "
149  "needed (which will be the first time you open an https connection "
150  "or otherwise use encryption services). You can also call "
151  "HTTPClient::init_random_seed() to "
152  "do this when you are ready. The issue is that on Windows, "
153  "OpenSSL will attempt to "
154  "randomize its seed by crawling through the entire heap of "
155  "allocated memory, which can be extremely large in a Panda "
156  "application, especially if you have already opened a window and "
157  "started rendering; and so this can take as much as 30 seconds "
158  "or more. For this reason it is best to initialize the random "
159  "seed at startup, when the application is still very small."));
160  if (early_random_seed) {
161  HTTPClient::init_random_seed();
162  }
163 
165  ps->add_system("OpenSSL");
166 #endif // HAVE_OPENSSL
167 }
static PandaSystem * get_global_ptr()
Returns the global PandaSystem object.
This class is used as a namespace to group several global properties of Panda.
Definition: pandaSystem.h:29
This is a convenience class to specialize ConfigVariable as a boolean type.
void add_system(const string &system)
Intended for use by each subsystem to register itself at startup.
This is a convenience class to specialize ConfigVariable as a floating-point type.
This is a convenience class to specialize ConfigVariable as an integer type.