defaultargs.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. # The contents of this file are subject to the BitTorrent Open Source License
  2. # Version 1.1 (the License). You may not copy or use this file, in either
  3. # source code or executable form, except in compliance with the License. You
  4. # may obtain a copy of the License at http://www.bittorrent.com/license/.
  5. #
  6. # Software distributed under the License is distributed on an AS IS basis,
  7. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  8. # for the specific language governing rights and limitations under the
  9. # License.
  10. # Needs redesign. Many if's on uiname. Blech. --Dave
  11. import os
  12. import sys
  13. from BTL.translation import _
  14. ### add your favorite here
  15. BAD_LIBC_WORKAROUND_DEFAULT = False
  16. if os.name == 'posix':
  17. if os.uname()[0] in ['Darwin', 'FreeBSD']:
  18. BAD_LIBC_WORKAROUND_DEFAULT = True
  19. MAX_INCOMPLETE = 100
  20. MAX_FILES_OPEN = 50
  21. if os.name == 'nt':
  22. import ctypes
  23. from BitTorrent.platform import win_version_num
  24. # starting in XP SP2 the incomplete outgoing connection limit was set to 10
  25. if win_version_num >= (2, 5, 1, 2, 0):
  26. MAX_INCOMPLETE = 10
  27. # try to set it as high as possible
  28. # technically 2048 is max, but I see 512 sometimes, and I think win98
  29. # defaults to 50. If we're not the last person to call it, I think we get
  30. # errors, so screw it for now.
  31. #ctypes.cdll.msvcrt._setmaxstdio(512)
  32. # -3 for stdin, stdout, and stderr
  33. # -15 for a buffer
  34. MAX_FILES_OPEN = ctypes.cdll.msvcrt._getmaxstdio() - 3 - 15
  35. if os.name == 'nt':
  36. CONFIRM_QUIT_DEFAULT = True
  37. else:
  38. CONFIRM_QUIT_DEFAULT = False
  39. from BTL.language import languages
  40. from BTL.platform import app_name
  41. basic_options = [
  42. ('data_dir', u'',
  43. _("directory under which variable data such as fastresume information "
  44. "and GUI state is saved. Defaults to subdirectory 'data' of the "
  45. "bittorrent config directory.")),
  46. ('language', '',
  47. _("ISO Language code to use") + ': ' + ', '.join(languages)),
  48. ('use_factory_defaults', False,
  49. _("Starts the application in a debug mode. All settings revert to "
  50. "default except those provided as command-line options. Creates "
  51. "temporary directories for dot, data, incomplete torrents and "
  52. "complete torrents. Allows multiple clients on the same machine to "
  53. "communicate with each other." )),
  54. ('tf_owner', '',
  55. _("The tf-user to run the torrent as." )),
  56. ('seed_limit', '0',
  57. _("Die when ratio reaches this amount." )),
  58. ('die_when_done', 'False',
  59. _("Die when the torrent is finished. Please seed your Torrents !" )),
  60. ]
  61. common_options = [
  62. ('ip', '',
  63. _("ip to report to the tracker (has no effect unless you are on the same "
  64. "local network as the tracker)")),
  65. ('forwarded_port', 0,
  66. _("world-visible port number if it's different from the one the client "
  67. "listens on locally")),
  68. ('minport', 6881,
  69. _("minimum port to listen on, counts up if unavailable")),
  70. ('maxport', 6999,
  71. _("maximum port to listen on")),
  72. ('bind', '',
  73. _("ip to bind to locally")),
  74. ('display_interval', 1.0,
  75. _("seconds between updates of displayed information")),
  76. ('rerequest_interval', 5 * 60,
  77. _("minutes to wait between requesting more peers")),
  78. ('min_peers', 40,
  79. _("minimum number of peers to not do rerequesting")),
  80. ('max_initiate', 200,
  81. _("number of peers at which to stop initiating new connections")),
  82. ('max_incomplete', MAX_INCOMPLETE,
  83. _("max number of outgoing incomplete connections")),
  84. ('max_allow_in', 80,
  85. _("maximum number of connections to allow, after this new incoming "
  86. "connections will be immediately closed")),
  87. ('check_hashes', True,
  88. _("whether to check hashes on disk")),
  89. ('max_upload_rate', 125000000, # 1 GBit local net = 125MB/s
  90. _("maximum B/s to upload at")),
  91. ('max_download_rate', 125000000, # 1 GBit local net = 125MB/s
  92. _("average maximum B/s to download at")),
  93. ("download_rate_limiter_interval", 0.25,
  94. _("download rate limiter's leaky bucket update interval.")),
  95. ('bandwidth_management', os.name == 'nt',
  96. _("automatic bandwidth management (Windows only)")),
  97. ('min_uploads', 2,
  98. _("the number of uploads to fill out to with extra optimistic unchokes")),
  99. ('max_files_open', MAX_FILES_OPEN,
  100. _("the maximum number of files in a multifile torrent to keep open at a "
  101. "time, 0 means no limit. Used to avoid running out of file descriptors.")),
  102. ('start_trackerless_client', True,
  103. _("Initialize a trackerless client. This must be enabled in order to download trackerless torrents.")),
  104. ('upnp', False,
  105. _("Enable automatic port mapping")+' (UPnP)'),
  106. ('resolve_hostnames', True,
  107. _("Resolve hostnames in peer list")),
  108. ("use_local_discovery", True, _("Scan local network for other BitTorrent clients "
  109. "with the desired content.")),
  110. # Not currently used.
  111. #('xmlrpc_port', -1,
  112. #_("Start the XMLRPC interface on the specified port. This "
  113. # "XML-RPC-based RPC allows a remote program to control the client "
  114. # "to enable automated hosting, conformance testing, and benchmarking.")),
  115. ]
  116. # In anticipation of running a large number of tests for tuning, I thought it
  117. # worthwhile to make these values settable. We will probably
  118. # remove these options later, because we won't want users
  119. # messing with them. --Dave
  120. bandwidth_management_options = [
  121. ('xicmp_port', 19669, _("port number upon which xicmp should sit.")),
  122. ('congestion_estimator', 'variance', #'chebyshev',
  123. "method for estimating congestion levels."),
  124. ('control_law', 'aimd', # allowed values = [aimd, aiad]
  125. "method for adjusting rates." ),
  126. #('propagation_estimator', 'median_of_window',
  127. # "method for estimating the round-trip propagation delay."),
  128. #('delay_on_full_estimator', 'median_of_window',
  129. # "method for estimating the round-trip time when the bottleneck "
  130. # "buffer is full (for bandwidth management)."),
  131. #('rtt_estimator', 'average_of_window',
  132. # # allowed values = [average_of_window, median_of_window, ewma]
  133. # 'method for estimating ping round-trip time'),
  134. ('increase_delta', 1000, "additive increase in bytes per second."),
  135. ('decrease_delta', 1000,
  136. "additive decrease in bytes per second (for aiad only)."),
  137. ('decrease_factor', 0.8, "multiplicative decrease (for aimd only)."),
  138. ('window_size', 10, "window used in averaging round-trip times"),
  139. ('ewma', 0.1, "averaging weight, smaller is slower convention."),
  140. ('cheby_max_consecutive', 10,
  141. ("maximum number of consecutive samples above the threshold before "
  142. "signalling congestion.")),
  143. ('cheby_max_threshold', 0.9,
  144. ("maximum delay threshold expressed as fraction of the distance between "
  145. "propagation delay and buffer-full delay.")),
  146. ('cheby_false_positive_probability', 0.05,
  147. "target upper bound on the probability of a false positive."),
  148. ('min_upload_rate_limit', 10000,
  149. "minimum upload rate limit to prevent starvation of BitTorrent traffic."),
  150. ]
  151. rare_options = [
  152. ('keepalive_interval', 120.0,
  153. _("number of seconds to pause between sending keepalives")),
  154. ('pex_interval', 60.0,
  155. _("number of seconds to pause between sending peer exchange messages")),
  156. ('download_chunk_size', 2 ** 14,
  157. _("how many bytes to query for per request.")),
  158. ('max_message_length', 2 ** 23,
  159. _("maximum length prefix encoding you'll accept over the wire - larger "
  160. "values get the connection dropped.")),
  161. ('socket_timeout', 300.0,
  162. _("seconds to wait between closing sockets which nothing has been "
  163. "received on")),
  164. ('max_chunk_length', 32768,
  165. _("maximum length chunk to send to peers, close connection if a larger "
  166. "request is received")),
  167. ('max_rate_period', 20.0,
  168. _("maximum time interval over which to estimate the current upload and download rates")),
  169. ('max_announce_retry_interval', 1800,
  170. _("maximum time to wait between retrying announces if they keep failing")),
  171. ('snub_time', 30.0,
  172. _("seconds to wait for data to come in over a connection before assuming "
  173. "it's semi-permanently choked")),
  174. ('rarest_first_cutoff', 4,
  175. _("number of downloads at which to switch from random to rarest first")),
  176. ('upload_unit_size', 1380,
  177. _("how many bytes to write into network buffers at once.")),
  178. ('retaliate_to_garbled_data', True,
  179. _("refuse further connections from addresses with broken or intentionally "
  180. "hostile peers that send incorrect data")),
  181. ('one_connection_per_ip', True,
  182. _("do not connect to several peers that have the same IP address")),
  183. ('one_download_per_torrent', True,
  184. _("do not allow simultaneous downloads of the same torrent.")),
  185. ('peer_socket_tos', 8,
  186. _("if nonzero, set the TOS option for peer connections to this value")),
  187. ('bad_libc_workaround', BAD_LIBC_WORKAROUND_DEFAULT,
  188. _("enable workaround for a bug in BSD libc that makes file reads very slow.")),
  189. ('tracker_proxy', '',
  190. _("address of HTTP proxy to use for tracker connections")),
  191. ('close_with_rst', 0,
  192. _("close connections with RST and avoid the TCP TIME_WAIT state")),
  193. ('num_disk_threads', 3,
  194. _("number of read threads to use in the storage object")),
  195. ('num_piece_checks', 2,
  196. _("number of simultaneous piece checks to run per torrent, set to a low number like 2 or 3")),
  197. ('num_fast', 10,
  198. _("Number of pieces allowed fast.")),
  199. ('show_hidden_torrents', False,
  200. _("Show hidden torrents in the UI.")),
  201. ('show_variance_line', False,
  202. _("Show variance line in bandwidth graph.")),
  203. # Future.
  204. #('stream_priority', 2,
  205. # _("Priority for pieces that are needed soon.")),
  206. ]
  207. tracker_options = [
  208. ('port', 80,
  209. _("Port to listen on.")),
  210. ('dfile', u'',
  211. _("file to store recent downloader info in")),
  212. ('bind', '',
  213. _("ip to bind to locally")),
  214. ('socket_timeout', 15,
  215. _("timeout for closing connections")),
  216. ('close_with_rst', 0,
  217. _("close connections with RST and avoid the TCP TIME_WAIT state")),
  218. ('save_dfile_interval', 5 * 60,
  219. _("seconds between saving dfile")),
  220. ('timeout_downloaders_interval', 45 * 60,
  221. _("seconds between expiring downloaders")),
  222. ('reannounce_interval', 30 * 60,
  223. _("seconds downloaders should wait between reannouncements")),
  224. ('response_size', 50,
  225. _("default number of peers to send an info message to if the "
  226. "client does not specify a number")),
  227. ('nat_check', 3,
  228. _("how many times to check if a downloader is behind a NAT "
  229. "(0 = don't check)")),
  230. ('log_nat_checks', 0,
  231. _("whether to add entries to the log for nat-check results")),
  232. ('min_time_between_log_flushes', 3.0,
  233. _("minimum time it must have been since the last flush to do "
  234. "another one")),
  235. ('min_time_between_cache_refreshes', 600.0,
  236. _("minimum time in seconds before a cache is considered stale "
  237. "and is flushed")),
  238. ('allowed_dir', u'',
  239. _("only allow downloads for .torrents in this dir (and recursively in "
  240. "subdirectories of directories that have no .torrent files "
  241. "themselves). If set, torrents in this directory show up on "
  242. "infopage/scrape whether they have peers or not")),
  243. ('parse_dir_interval', 60,
  244. _("how often to rescan the torrent directory, in seconds")),
  245. ('allowed_controls', 0,
  246. _("allow special keys in torrents in the allowed_dir to affect "
  247. "tracker access")),
  248. ('hupmonitor', 0,
  249. _("whether to reopen the log file upon receipt of HUP signal")),
  250. ('show_infopage', 1,
  251. _("whether to display an info page when the tracker's root dir "
  252. "is loaded")),
  253. ('infopage_redirect', '',
  254. _("a URL to redirect the info page to")),
  255. ('show_names', 1,
  256. _("whether to display names from allowed dir")),
  257. ('favicon', '',
  258. _("file containing x-icon data to return when browser requests "
  259. "favicon.ico")),
  260. ('only_local_override_ip', 2,
  261. _("ignore the ip GET parameter from machines which aren't on "
  262. "local network IPs (0 = never, 1 = always, 2 = ignore if NAT "
  263. "checking is not enabled). HTTP proxy headers giving address "
  264. "of original client are treated the same as --ip.")),
  265. ('logfile', '',
  266. _("file to write the tracker logs, use - for stdout (default)")),
  267. ('allow_get', 0,
  268. _("use with allowed_dir; adds a /file?hash={hash} url that "
  269. "allows users to download the torrent file")),
  270. ('keep_dead', 0,
  271. _("keep dead torrents after they expire (so they still show up on your "
  272. "/scrape and web page). Only matters if allowed_dir is not set")),
  273. ('scrape_allowed', 'full',
  274. _("scrape access allowed (can be none, specific or full)")),
  275. ('max_give', 200,
  276. _("maximum number of peers to give with any one request")),
  277. ('twisted', -1,
  278. _("Use Twisted network libraries for network connections. 1 means use twisted, 0 means do not use twisted, -1 means autodetect, and prefer twisted")),
  279. ('pid', 'bittorrent-tracker.pid',
  280. "Path to PID file"),
  281. ('max_incomplete', MAX_INCOMPLETE,
  282. _("max number of outgoing incomplete connections")),
  283. ]
  284. def get_defaults(ui):
  285. assert ui in ("bittorrent" , "bittorrent-curses", "bittorrent-console" ,
  286. "maketorrent", "maketorrent-console",
  287. "launchmany-curses", "launchmany-console" ,
  288. "bittorrent-tracker" ,
  289. )
  290. r = []
  291. if ui == "bittorrent-tracker":
  292. r.extend(tracker_options)
  293. elif ui.startswith('bittorrent') or ui.startswith('launchmany'):
  294. r.extend(common_options)
  295. if ui == 'bittorrent':
  296. r.extend([
  297. ('publish', '',
  298. _("path to the file that you are publishing (seeding).")),
  299. ('verbose', False,
  300. _("display verbose information in user interface")),
  301. ('debug', False,
  302. _("provide debugging tools in user interface")),
  303. ('pause', False,
  304. _("start downloader in paused state")),
  305. ('open_from', u'',
  306. 'local directory to look in for .torrent files to open'),
  307. ('start_minimized', False,
  308. _("Start %s minimized")%app_name),
  309. ('force_start_minimized', False,
  310. _("Start %s minimized (but do not save that preference)")%app_name),
  311. ('confirm_quit', CONFIRM_QUIT_DEFAULT,
  312. _("Confirm before quitting %s")%app_name),
  313. ('new_version', '',
  314. _("override the version provided by the http version check "
  315. "and enable version check debugging mode")),
  316. ('current_version', '',
  317. _("override the current version used in the version check "
  318. "and enable version check debugging mode")),
  319. # remember GUI state
  320. ('geometry', '',
  321. _("specify window size and position, in the format: "
  322. "WIDTHxHEIGHT+XOFFSET+YOFFSET")),
  323. ('start_maximized', False,
  324. _("Start %s maximized")%app_name),
  325. ('column_widths', {},
  326. _("Widths of columns in torrent list in main window")),
  327. ('column_order', ['name', 'progress', 'eta', 'drate',
  328. 'urate', 'peers', 'priority', 'state'],
  329. _("Order of columns in torrent list in main window")),
  330. ('enabled_columns', ['name', 'progress', 'eta', 'drate',
  331. 'priority'],
  332. _("Enabled columns in torrent list in main window")),
  333. ('sort_column', 'name',
  334. _("Default sort column in torrent list in main window")),
  335. ('sort_ascending', True,
  336. _("Default sort order in torrent list in main window")),
  337. ('toolbar_text', True,
  338. _("Whether to show text on the toolbar or not")),
  339. ('toolbar_size', 24,
  340. _("Size in pixels of toolbar icons")),
  341. ('show_details', False,
  342. _("Show details panel on startup")),
  343. ('settings_tab', 0,
  344. _("Which tab in the settings window to show by default")),
  345. ('details_tab', 0,
  346. _("Which tab in the details panel to show by default")),
  347. ('splitter_height', 300,
  348. _("Height of the details splitter when it is enabled")),
  349. ('ask_for_save', True,
  350. _("whether or not to ask for a location to save downloaded "
  351. "files in")),
  352. ('max_upload_rate', 40960, # 40KB/s up
  353. _("maximum B/s to upload at")),
  354. ])
  355. if os.name == 'nt':
  356. r.extend([
  357. ('launch_on_startup', True,
  358. _("Launch %s when Windows starts") % app_name),
  359. ('minimize_to_tray', True,
  360. _("Minimize to the system tray")),
  361. ('close_to_tray', True,
  362. _("Close to the system tray")),
  363. ('enforce_association', True,
  364. _("Enforce .torrent file associations on startup")),
  365. ])
  366. progress_bar = ['progressbar_style', 3,
  367. _("The style of progressbar to show. 0 means no progress "
  368. "bar. 1 is an ordinary progress bar. 2 is a progress "
  369. "bar that shows transferring, available and missing "
  370. "percentages as well. 3 is a piece bar which "
  371. "color-codes each piece in the torrent based on its "
  372. "availability.")]
  373. if sys.platform == "darwin":
  374. # listctrl placement of the progress bars does not work on Carbon
  375. progress_bar[1] = 0
  376. r.extend([ progress_bar,
  377. ])
  378. if ui in ('bittorrent', 'maketorrent'):
  379. r.append(
  380. ('theme', 'default',
  381. _("Icon theme to use"))
  382. )
  383. if ui.startswith('bittorrent') and ui != "bittorrent-tracker":
  384. r.extend([
  385. ('max_uploads', -1,
  386. _("the maximum number of uploads to allow at once. -1 means a "
  387. "(hopefully) reasonable number based on --max_upload_rate. "
  388. "The automatic values are only sensible when running one "
  389. "torrent at a time.")),
  390. ('save_in', u'',
  391. _("local directory where the torrent contents will be saved. The "
  392. "file (single-file torrents) or directory (batch torrents) will "
  393. "be created under this directory using the default name "
  394. "specified in the .torrent file. See also --save_as.")),
  395. ('save_incomplete_in', u'',
  396. _("local directory where the incomplete torrent downloads will be "
  397. "stored until completion. Upon completion, downloads will be "
  398. "moved to the directory specified by --save_in.")),
  399. ])
  400. r.extend(bandwidth_management_options)
  401. if ui.startswith('launchmany'):
  402. r.extend([
  403. ('max_uploads', 6,
  404. _("the maximum number of uploads to allow at once. -1 means a "
  405. "(hopefully) reasonable number based on --max_upload_rate. The "
  406. "automatic values are only sensible when running one torrent at "
  407. "a time.")),
  408. ('save_in', u'',
  409. _("local directory where the torrents will be saved, using a "
  410. "name determined by --saveas_style. If this is left empty "
  411. "each torrent will be saved under the directory of the "
  412. "corresponding .torrent file")),
  413. ('save_incomplete_in', u'',
  414. _("local directory where the incomplete torrent downloads will be "
  415. "stored until completion. Upon completion, downloads will be "
  416. "moved to the directory specified by --save_in.")),
  417. ('parse_dir_interval', 60,
  418. _("how often to rescan the torrent directory, in seconds") ),
  419. ('launch_delay', 0,
  420. _("wait this many seconds after noticing a torrent before starting it, to avoid race with tracker")),
  421. ('saveas_style', 4,
  422. _("How to name torrent downloads: "
  423. "1: use name OF torrent file (minus .torrent); "
  424. "2: use name encoded IN torrent file; "
  425. "3: create a directory with name OF torrent file "
  426. "(minus .torrent) and save in that directory using name "
  427. "encoded IN torrent file; "
  428. "4: if name OF torrent file (minus .torrent) and name "
  429. "encoded IN torrent file are identical, use that "
  430. "name (style 1/2), otherwise create an intermediate "
  431. "directory as in style 3; "
  432. "CAUTION: options 1 and 2 have the ability to "
  433. "overwrite files without warning and may present "
  434. "security issues."
  435. ) ),
  436. ('display_path', ui == 'launchmany-console' and True or False,
  437. _("whether to display the full path or the torrent contents for "
  438. "each torrent") ),
  439. ])
  440. if ui.startswith('launchmany') or ui == 'maketorrent':
  441. r.append(
  442. ('torrent_dir', u'',
  443. _("directory to look for .torrent files (semi-recursive)")),)
  444. if ui.startswith('maketorrent'):
  445. r.append(
  446. ('content_type', '',_("file's default mime type.")))
  447. # HEREDAVE batch torrents must be handled differently.
  448. if ui in ('bittorrent-curses', 'bittorrent-console'):
  449. r.extend([
  450. ('save_as', u'',
  451. _("file name (for single-file torrents) or directory name (for "
  452. "batch torrents) to save the torrent as, overriding the "
  453. "default name in the torrent. See also --save_in")),
  454. ('spew', False,
  455. _("whether to display diagnostic info to stdout")),])
  456. if ui == 'bittorrent-console' :
  457. r.extend([
  458. ('display_interval', 1,
  459. _("seconds between updates of displayed information")),
  460. ] )
  461. elif ui.startswith('launchmany-console'):
  462. r.extend([
  463. ('display_interval', 60,
  464. _("seconds between updates of displayed information")),
  465. ] )
  466. elif ui.startswith('launchmany-curses'):
  467. r.extend([
  468. ('display_interval', 3,
  469. _("seconds between updates of displayed information")),
  470. ] )
  471. if ui.startswith('maketorrent'):
  472. r.extend([
  473. ('title', '',
  474. _("optional human-readable title for entire .torrent")),
  475. ('comment', '',
  476. _("optional human-readable comment to put in .torrent")),
  477. ('piece_size_pow2', 0,
  478. _("which power of two to set the piece size to, "
  479. "0 means pick a good piece size")),
  480. ('tracker_name', '',
  481. _("default tracker name")),
  482. ('tracker_list', '', ''),
  483. ('use_tracker', True,
  484. _("if false then make a trackerless torrent, instead of "
  485. "announce URL, use reliable node in form of <ip>:<port> or an "
  486. "empty string to pull some nodes from your routing table")),
  487. ('verbose', False,
  488. _("display verbose information in user interface")),
  489. ('debug', False,
  490. _("provide debugging tools in user interface")),
  491. ])
  492. r.extend(basic_options)
  493. if (ui.startswith('bittorrent') or ui.startswith('launchmany')) \
  494. and ui != "bittorrent-tracker":
  495. r.extend(rare_options)
  496. return r