Panda3D
 All Classes Functions Variables Enumerations
config_downloader.cxx
00001 // Filename: config_downloader.cxx
00002 // Created by:  mike (19Mar00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "dconfig.h"
00016 #include "config_downloader.h"
00017 #include "httpChannel.h"
00018 #include "virtualFileHTTP.h"
00019 #include "virtualFileMountHTTP.h"
00020 #include "pandaSystem.h"
00021 
00022 
00023 ConfigureDef(config_downloader);
00024 NotifyCategoryDef(downloader, "");
00025 
00026 ConfigVariableInt downloader_byte_rate
00027 ("downloader-byte-rate", 500000,
00028  PRC_DESC("Specifies the default max bytes per second of throughput that is "
00029           "supported by any HTTP connections with download-throttle enabled.  "
00030           "This may also be set on a per-channel basis with "
00031           "HTTPChannel::set_max_bytes_per_second().  It has no effect unless "
00032           "download-throttle (or HTTPChannel::set_download_throttle) is true."));
00033 
00034 ConfigVariableBool download_throttle
00035 ("download-throttle", false,
00036  PRC_DESC("When this is true, all HTTP channels will be bandwidth-limited "
00037           "so as not to consume more than downloader-byte-rate bytes per "
00038           "second."));
00039 
00040 ConfigVariableDouble downloader_frequency
00041 ("downloader-frequency", 0.2,
00042  PRC_DESC("Frequency of download chunk requests in seconds (or fractions of) "
00043           "(Estimated 200 msec round-trip to server)."));
00044 
00045 ConfigVariableInt downloader_timeout
00046 ("downloader-timeout", 15);
00047 
00048 ConfigVariableInt downloader_timeout_retries
00049 ("downloader-timeout-retries", 5);
00050 
00051 ConfigVariableDouble decompressor_step_time
00052 ("decompressor-step-time", 0.005,
00053  PRC_DESC("Specifies the maximum amount of time that should be consumed by "
00054           "a single call to Decompressor::run()."));
00055 
00056 ConfigVariableDouble extractor_step_time
00057 ("extractor-step-time", 0.005,
00058  PRC_DESC("Specifies the maximum amount of time that should be consumed by "
00059           "a single call to Extractor::step()."));
00060 
00061 ConfigVariableInt patcher_buffer_size
00062 ("patcher-buffer-size", 16384,
00063   PRC_DESC("Limits the size of the buffer used in a single call to "
00064            "Patcher::run().  Increasing this may help the Patcher "
00065            "perform more work before returning."));
00066 
00067 ConfigVariableBool http_proxy_tunnel
00068 ("http-proxy-tunnel", false,
00069  PRC_DESC("This specifies the default value for HTTPChannel::set_proxy_tunnel().  "
00070           "If this is true, we will tunnel through a proxy for all connections, "
00071           "instead of asking the proxy to serve documents normally."));
00072 
00073 ConfigVariableDouble http_connect_timeout
00074 ("http-connect-timeout", 10.0,
00075  PRC_DESC("This is the default amount of time to wait for a TCP/IP connection "
00076           "to be established, in seconds."));
00077 
00078 ConfigVariableDouble http_timeout
00079 ("http-timeout", 20.0,
00080  PRC_DESC("This is the default amount of time to wait for the HTTP server (or "
00081           "proxy) to finish sending its response to our request, in seconds. "
00082           "It starts counting after the TCP connection has been established "
00083           "(http_connect_timeout, above) and the request has been sent."));
00084 
00085 ConfigVariableInt http_skip_body_size
00086 ("http-skip-body-size", 8192,
00087  PRC_DESC("This is the maximum number of bytes in a received "
00088           "(but unwanted) body that will be skipped past, in "
00089           "order to reset to a new request.  "
00090           "See HTTPChannel::set_skip_body_size()."));
00091 
00092 ConfigVariableDouble http_idle_timeout
00093 ("http-idle-timeout", 5.0,
00094  PRC_DESC("This the amount of time, in seconds, in which a "
00095           "previously-established connection is allowed to remain open "
00096           "and unused.  If a previous connection has remained unused for "
00097           "at least this number of seconds, it will be closed and a new "
00098           "connection will be opened; otherwise, the same connection "
00099           "will be reused for the next request (for a particular "
00100           "HTTPChannel)."));
00101 
00102 ConfigVariableInt http_max_connect_count
00103 ("http-max-connect-count", 10,
00104  PRC_DESC("This is the maximum number of times to try reconnecting to the "
00105           "server on any one document attempt.  This is just a failsafe to "
00106           "prevent the code from attempting runaway connections; this limit "
00107           "should never be reached in practice."));
00108 
00109 ConfigVariableInt tcp_header_size
00110 ("tcp-header-size", 2,
00111  PRC_DESC("Specifies the number of bytes to use to specify the datagram "
00112           "length when writing a datagram on a TCP stream.  This may be "
00113           "0, 2, or 4.  The server and client must agree on this value."));
00114 
00115 ConfigureFn(config_downloader) {
00116   init_libdownloader();
00117 }
00118 
00119 ////////////////////////////////////////////////////////////////////
00120 //     Function: init_libdownloader
00121 //  Description: Initializes the library.  This must be called at
00122 //               least once before any of the functions or classes in
00123 //               this library can be used.  Normally it will be
00124 //               called by the static initializers and need not be
00125 //               called explicitly, but special cases exist.
00126 ////////////////////////////////////////////////////////////////////
00127 void
00128 init_libdownloader() {
00129   static bool initialized = false;
00130   if (initialized) {
00131     return;
00132   }
00133   initialized = true;
00134 
00135 #ifdef HAVE_OPENSSL
00136   HTTPChannel::init_type();
00137   VirtualFileHTTP::init_type();
00138   VirtualFileMountHTTP::init_type();
00139 
00140   VirtualFileMountHTTP::reload_vfs_mount_url();
00141 
00142   // We need to define this here, rather than above, to guarantee that
00143   // it has been initialized by the time we check it.
00144   ConfigVariableBool early_random_seed
00145     ("early-random-seed", false,
00146      PRC_DESC("Configure this true to compute the SSL random seed "
00147               "early on in the application (specifically, when the libpandaexpress "
00148               "library is loaded), or false to defer this until it is actually "
00149               "needed (which will be the first time you open an https connection "
00150               "or otherwise use encryption services).  You can also call "
00151               "HTTPClient::init_random_seed() to "
00152               "do this when you are ready.  The issue is that on Windows, "
00153               "OpenSSL will attempt to "
00154               "randomize its seed by crawling through the entire heap of "
00155               "allocated memory, which can be extremely large in a Panda "
00156               "application, especially if you have already opened a window and "
00157               "started rendering; and so this can take as much as 30 seconds "
00158               "or more.  For this reason it is best to initialize the random "
00159               "seed at startup, when the application is still very small."));
00160   if (early_random_seed) {
00161     HTTPClient::init_random_seed();
00162   }
00163 
00164   PandaSystem *ps = PandaSystem::get_global_ptr();
00165   ps->add_system("OpenSSL");
00166 #endif  // HAVE_OPENSSL
00167 }
 All Classes Functions Variables Enumerations