1 (* Copyright 2001, 2002 b52_simon :), b8_bavard, b8_fee_carabine, INRIA *)
3 This file is part of mldonkey.
5 mldonkey is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 mldonkey is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mldonkey; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 let bittorrent_ini = create_options_file
"bittorrent.ini"
26 let bittorrent_section = file_section
bittorrent_ini ["Bittorrent"] "Bittorrent options"
28 let client_port = define_option
bittorrent_section ["client_port"]
30 "The port to bind the client to"
33 (* Generate client_uid *)
34 (* current_version could be "2.6.6.CVS" (why send the dots?)
35 perhaps of use: Autoconf.major_version Autoconf.minor_version Autoconf.sub_version
37 let generate_client_uid =
38 let client_uid_from_version = "-ML" ^
Autoconf.current_version ^
"-" in
39 let client_uid_random_tail = Bytes.create
(20 - (String.length
client_uid_from_version)) in
40 let sl_client_uid_random_tail = Bytes.length
client_uid_random_tail in
41 if sl_client_uid_random_tail > 0 then
42 for i
= 0 to sl_client_uid_random_tail - 1 do
43 client_uid_random_tail.[i
] <- char_of_int
(Random.int 256)
45 client_uid_from_version ^
Bytes.unsafe_to_string
client_uid_random_tail
47 let client_uid = define_option
bittorrent_section ["client_uid"]
48 "The UID of this client"
49 Sha1.option (Sha1.direct_of_string
generate_client_uid)
51 (* Check if the uid is in sync with Autoconf.current_version *)
52 let check_client_uid () =
53 let s = Sha1.direct_to_string
!!client_uid in
54 if Autoconf.current_version
<> String.sub
s 3 ((
56 String.index_from
s 1 s.[0]
60 client_uid =:= Sha1.direct_of_string
generate_client_uid
63 Printf.sprintf
"BT-%s" (shortname o
)
65 let gui_bittorrent_options_panel =
67 "Port", shortname client_port, "T";
70 let ask_tracker_threshold = define_option
bittorrent_section ["ask_tracker_threshold"]
71 "Ask the tracker for new sources only if you have fewer than that number of sources"
75 * Some tracker implements load balancing
76 * and failover using redirect
78 let max_tracker_redirect = define_option
bittorrent_section ["max_tracker_redirect"]
79 "Maximum number of HTTP redirects before reaching the tracker - maximum 10, 0 to disable"
83 let send_key = define_option
bittorrent_section ["send_key"]
84 "Send client key to trackers"
87 let max_bt_uploaders = define_option
bittorrent_section ["max_bt_uploaders"]
88 "Maximum number of uploaders for bittorrent, can not be higher than max_upload_slots"
91 let max_uploaders_per_torrent = define_option
bittorrent_section ["max_uploaders_per_torrent"]
92 "Maximum number of uploaders for one torrent, can not be higher than max_bt_uploaders"
95 (* numwant: Optional. Number of peers that the client would like to receive from the tracker.
96 This value is permitted to be zero. If omitted, typically defaults to 50 peers. *)
98 let numwant = define_option
bittorrent_section ["numwant"]
99 "Number of peers to request from tracker (Negative # = let tracker decide)"
102 let import_new_torrents_interval = define_option
bittorrent_section ["import_new_torrents_interval"]
104 "Interval in seconds 'torrents/incoming' is scanned for new torrent files to be downloaded, 0 to deactivate"
107 let tracker_retries = define_option
bittorrent_section ["tracker_retries"]
108 "Number of retries before a tracker is disabled, use 0 to not disable trackers"
111 let check_bt_uploaders () =
112 if !!max_bt_uploaders > !!max_upload_slots
then
113 max_bt_uploaders =:= !!max_upload_slots
;
114 if !!max_uploaders_per_torrent > !!max_bt_uploaders then
115 max_uploaders_per_torrent =:= !!max_bt_uploaders
119 option_hook
max_uploaders_per_torrent
121 let v = int_of_string
(strings_of_option
max_uploaders_per_torrent).option_default
in
122 if !!max_uploaders_per_torrent < 1 then max_uploaders_per_torrent =:= v;
123 check_bt_uploaders ()
125 option_hook
max_bt_uploaders
127 if !!max_bt_uploaders < 1 then
128 max_bt_uploaders =:= int_of_string
(strings_of_option
max_bt_uploaders).option_default
;
129 check_bt_uploaders ()
131 option_hook
max_tracker_redirect (* #4541 [egs] **)
133 if !!max_tracker_redirect < 0 then max_tracker_redirect =:= 0
134 else if !!max_tracker_redirect > 10 then max_tracker_redirect =:= 10) ;
137 let min_tracker_reask_interval = define_option
bittorrent_section ["min_tracker_reask_interval"]
138 "Minimum time in seconds to wait between asking the tracker for sources"
141 let client_timeout = define_option
bittorrent_section ["client_timeout"]
142 "Timeout on client connections"
145 let user_agent = define_option
bittorrent_section ["user_agent"]
146 "User agent string (default = \"default\")"
147 string_option
"default"
149 let options_version = define_option
bittorrent_section ["options_version"]
154 let old_files = define_option
bittorrent_section ["old_files"]
156 (list_option
(tuple2_option
(string_option
, int64_option
))) []
158 let tracked_files_list = define_option
bittorrent_section ["tracked_files"]
160 (list_option
Sha1.option) []
162 let get_user_agent () =
163 if !!user_agent = "default" then
164 CommonOptions.get_user_agent ()
167 let dht_port = define_option
bittorrent_section ["dht_port"]
168 "DHT port (UDP, set 0 to disable)"
169 port_option
(2000 + Random.int 20000)
171 let use_trackers = define_option
bittorrent_section ["use_trackers"]
172 "Send announces to trackers"
175 let dht_bootstrap_nodes = define_option
bittorrent_section ["dht_bootstrap_nodes"]
176 "Addresses of nodes used to bootstrap DHT network. Tried in order until enough nodes are found."
177 (list_option addr_option
)
179 "service.ygrek.org.ua",6881;
180 "router.bittorrent.com", 8991;