32 |
open BTOptions |
open BTOptions |
33 |
open BTGlobals |
open BTGlobals |
34 |
|
|
35 |
|
(* prints a new logline with date, module and starts newline *) |
36 |
|
let lprintf_nl () = |
37 |
|
lprintf "%s[BT] " |
38 |
|
(log_time ()); lprintf_nl2 |
39 |
|
|
40 |
|
(* prints a new logline with date, module and does not start newline *) |
41 |
|
let lprintf_n () = |
42 |
|
lprintf "%s[BT] " |
43 |
|
(log_time ()); lprintf |
44 |
|
|
45 |
(*given some files choose the next uploaders based on their behavior |
(*given some files choose the next uploaders based on their behavior |
46 |
Will choose max_uploaders_per_torrent uploaders for each file in list |
Will choose max_uploaders_per_torrent uploaders for each file in list |
67 |
possible_uploaders := (c::!possible_uploaders); |
possible_uploaders := (c::!possible_uploaders); |
68 |
end ) f.file_clients; |
end ) f.file_clients; |
69 |
if !verbose_upload then |
if !verbose_upload then |
70 |
lprintf_nl "[BT]: clients num %d as possible uploaders for file %s\n" (List.length !possible_uploaders) f.file_name; |
lprintf_nl () "clients num %d as possible uploaders for file %s" (List.length !possible_uploaders) f.file_name; |
71 |
(*Interested clients with a connection*) |
(*Interested clients with a connection*) |
72 |
let filtl = List.filter (fun c -> c.client_interested == true |
let filtl = List.filter (fun c -> c.client_interested == true |
73 |
&& (c.client_sock != NoConnection) |
&& (c.client_sock != NoConnection) |
91 |
full_list := !full_list @ to_add; |
full_list := !full_list @ to_add; |
92 |
if !verbose_upload then |
if !verbose_upload then |
93 |
begin |
begin |
94 |
lprintf "[BT]: potential uploaders count: %d list: [" (List.length to_add); |
lprintf_n () "potential uploaders count: %d list: [" (List.length to_add); |
95 |
List.iter (fun cr -> |
List.iter (fun cr -> |
96 |
let (ip,port) = cr.client_host in |
let (ip,port) = cr.client_host in |
97 |
lprintf " %s:%d" (Ip.to_string ip) port; |
lprintf " %s:%d" (Ip.to_string ip) port; |
98 |
) to_add; |
) to_add; |
99 |
lprintf_nl " ]"; |
lprintf_nl2 " ]"; |
100 |
end; |
end; |
101 |
|
|
102 |
) files; |
) files; |
140 |
begin |
begin |
141 |
if !verbose_upload then |
if !verbose_upload then |
142 |
begin |
begin |
143 |
lprintf "[BT]: next_uploaders: %d list: [" (List.length next_uploaders); |
lprintf_n () "next_uploaders: %d list: [" (List.length next_uploaders); |
144 |
List.iter (fun cr -> |
List.iter (fun cr -> |
145 |
let (ip,port) = cr.client_host in |
let (ip,port) = cr.client_host in |
146 |
lprintf " %s:%d" (Ip.to_string ip) port; |
lprintf " %s:%d" (Ip.to_string ip) port; |
147 |
) next_uploaders; |
) next_uploaders; |
148 |
lprintf_nl " ]"; |
lprintf_nl2 " ]"; |
149 |
end; |
end; |
150 |
if (List.length next_uploaders) > !!max_bt_uploaders then |
if (List.length next_uploaders) > !!max_bt_uploaders then |
151 |
let keep,rest = List2.cut !!max_bt_uploaders next_uploaders in |
let keep,rest = List2.cut !!max_bt_uploaders next_uploaders in |
152 |
begin |
begin |
153 |
if !verbose_upload then |
if !verbose_upload then |
154 |
begin |
begin |
155 |
lprintf "[BT]: cut next_uploaders: %d list: [" (List.length keep); |
lprintf_n () "cut next_uploaders: %d list: [" (List.length keep); |
156 |
List.iter (fun cr -> |
List.iter (fun cr -> |
157 |
let (ip,port) = cr.client_host in |
let (ip,port) = cr.client_host in |
158 |
lprintf " %s:%d" (Ip.to_string ip) port; |
lprintf " %s:%d" (Ip.to_string ip) port; |
159 |
) keep; |
) keep; |
160 |
lprintf_nl " ]"; |
lprintf_nl2 " ]"; |
161 |
end; |
end; |
162 |
keep |
keep |
163 |
end |
end |