[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Mldonkey-commits] mldonkey config/Makefile.in distrib/ChangeLog s...
From: |
mldonkey-commits |
Subject: |
[Mldonkey-commits] mldonkey config/Makefile.in distrib/ChangeLog s... |
Date: |
Sun, 09 Apr 2006 00:27:05 +0000 |
CVSROOT: /sources/mldonkey
Module name: mldonkey
Branch:
Changes by: spiralvoice <address@hidden> 06/04/09 00:27:04
Modified files:
config : Makefile.in
distrib : ChangeLog
src/daemon/common: commonDownloads.ml commonDownloads.mli
commonSwarming.ml
src/daemon/driver: driverCommands.ml driverMain.ml
src/networks/bittorrent: bTChooser.ml bTClients.ml
bTComplexOptions.ml bTGlobals.ml
bTInteractive.ml bTTypes.ml
src/networks/direct_connect: dcInteractive.ml
src/networks/donkey: donkeyClient.ml donkeyComplexOptions.ml
donkeyGlobals.ml donkeyInteractive.ml
donkeyOneFile.ml donkeyShare.ml
donkeyTypes.ml
src/networks/fasttrack: fasttrackGlobals.ml
src/networks/fileTP: fileTPClients.ml fileTPComplexOptions.ml
fileTPFTP.ml fileTPGlobals.ml fileTPHTTP.ml
fileTPInteractive.ml fileTPSSH.ml
fileTPTypes.ml
src/networks/gnutella: gnutellaClients.ml
gnutellaComplexOptions.ml
gnutellaGlobals.ml gnutellaHandler.ml
gnutellaInteractive.ml
gnutellaProtocol.ml gnutellaTypes.ml
src/networks/gnutella2: g2Handler.ml
Removed files:
src/daemon/common: commonSwarming2.ml commonSwarming2.mli
Log message:
patch #5031
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/config/Makefile.in.diff?tr1=1.154&tr2=1.155&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/distrib/ChangeLog.diff?tr1=1.795&tr2=1.796&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/daemon/common/commonDownloads.ml.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/daemon/common/commonDownloads.mli.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/daemon/common/commonSwarming.ml.diff?tr1=1.29&tr2=1.30&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/daemon/driver/driverCommands.ml.diff?tr1=1.134&tr2=1.135&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/daemon/driver/driverMain.ml.diff?tr1=1.105&tr2=1.106&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/bittorrent/bTChooser.ml.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/bittorrent/bTClients.ml.diff?tr1=1.66&tr2=1.67&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/bittorrent/bTComplexOptions.ml.diff?tr1=1.30&tr2=1.31&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/bittorrent/bTGlobals.ml.diff?tr1=1.54&tr2=1.55&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/bittorrent/bTInteractive.ml.diff?tr1=1.87&tr2=1.88&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/bittorrent/bTTypes.ml.diff?tr1=1.32&tr2=1.33&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/direct_connect/dcInteractive.ml.diff?tr1=1.24&tr2=1.25&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/donkey/donkeyClient.ml.diff?tr1=1.87&tr2=1.88&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/donkey/donkeyComplexOptions.ml.diff?tr1=1.45&tr2=1.46&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/donkey/donkeyGlobals.ml.diff?tr1=1.78&tr2=1.79&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/donkey/donkeyInteractive.ml.diff?tr1=1.98&tr2=1.99&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/donkey/donkeyOneFile.ml.diff?tr1=1.35&tr2=1.36&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/donkey/donkeyShare.ml.diff?tr1=1.40&tr2=1.41&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/donkey/donkeyTypes.ml.diff?tr1=1.38&tr2=1.39&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fasttrack/fasttrackGlobals.ml.diff?tr1=1.31&tr2=1.32&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fileTP/fileTPClients.ml.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fileTP/fileTPComplexOptions.ml.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fileTP/fileTPFTP.ml.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fileTP/fileTPGlobals.ml.diff?tr1=1.20&tr2=1.21&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fileTP/fileTPHTTP.ml.diff?tr1=1.20&tr2=1.21&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fileTP/fileTPInteractive.ml.diff?tr1=1.33&tr2=1.34&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fileTP/fileTPSSH.ml.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/fileTP/fileTPTypes.ml.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaClients.ml.diff?tr1=1.37&tr2=1.38&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml.diff?tr1=1.25&tr2=1.26&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaGlobals.ml.diff?tr1=1.35&tr2=1.36&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaHandler.ml.diff?tr1=1.10&tr2=1.11&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaInteractive.ml.diff?tr1=1.50&tr2=1.51&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaProtocol.ml.diff?tr1=1.19&tr2=1.20&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella/gnutellaTypes.ml.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/mldonkey/mldonkey/src/networks/gnutella2/g2Handler.ml.diff?tr1=1.17&tr2=1.18&r1=text&r2=text
Patches:
Index: mldonkey/config/Makefile.in
diff -u mldonkey/config/Makefile.in:1.154 mldonkey/config/Makefile.in:1.155
--- mldonkey/config/Makefile.in:1.154 Mon Apr 3 20:50:08 2006
+++ mldonkey/config/Makefile.in Sun Apr 9 00:27:03 2006
@@ -260,7 +260,6 @@
$(COMMON)/commonInteractive.ml \
$(COMMON)/commonChunks.ml \
$(COMMON)/commonSwarming.ml \
- $(COMMON)/commonSwarming2.ml \
$(COMMON)/commonDownloads.ml \
$(COMMON)/commonUploads.ml \
$(COMMON)/commonSources.ml \
Index: mldonkey/distrib/ChangeLog
diff -u mldonkey/distrib/ChangeLog:1.795 mldonkey/distrib/ChangeLog:1.796
--- mldonkey/distrib/ChangeLog:1.795 Sat Apr 8 02:16:21 2006
+++ mldonkey/distrib/ChangeLog Sun Apr 9 00:27:03 2006
@@ -14,6 +14,9 @@
ChangeLog
=========
+2006/04/09
+5031: Merge CommonSwarming and CommonSwarming2 code (pango)
+
2006/04/08
5029: EDK: Remove set_brothers command and brotherhood option
5030: Update config.guess and config.sub to version 2006-02-27
Index: mldonkey/src/daemon/common/commonDownloads.ml
diff -u mldonkey/src/daemon/common/commonDownloads.ml:1.12
mldonkey/src/daemon/common/commonDownloads.ml:1.13
--- mldonkey/src/daemon/common/commonDownloads.ml:1.12 Sun Oct 16 20:42:50 2005
+++ mldonkey/src/daemon/common/commonDownloads.ml Sun Apr 9 00:27:03 2006
@@ -122,9 +122,3 @@
end
end
-
-module Int64Swarmer = CommonSwarming2.Make(struct
- module CommonTypes = CommonTypes
- module CommonFile = CommonFile
- module CommonClient = CommonClient
- end)
Index: mldonkey/src/daemon/common/commonDownloads.mli
diff -u mldonkey/src/daemon/common/commonDownloads.mli:1.3
mldonkey/src/daemon/common/commonDownloads.mli:1.4
--- mldonkey/src/daemon/common/commonDownloads.mli:1.3 Thu Oct 6 10:19:29 2005
+++ mldonkey/src/daemon/common/commonDownloads.mli Sun Apr 9 00:27:03 2006
@@ -46,61 +46,3 @@
TcpBufferedSocket.t -> M.c -> M.f -> int -> (M.f, M.c) download
end
end
-
-
-open CommonSwarming
-module Int64Swarmer :
- sig
- type t
- type swarmer
- and range
- and uploader
- and block
- val create_swarmer : string -> int64 -> int64 -> swarmer
- val remove_swarmer : t option -> unit
- val create : swarmer -> CommonTypes.file -> int64 -> t
- val set_verifier : t -> CommonSwarming.verification -> unit
- val set_verified : t -> (int -> int -> unit) -> unit
- val set_present : t -> (int64 * int64) list -> unit
- val set_absent : t -> (int64 * int64) list -> unit
- val verified_bitmap : t -> string
- val set_verified_bitmap : t -> string -> unit
- val set_verified_chunk : t -> int -> unit
- val register_uploader : t -> CommonTypes.client -> chunks -> uploader
- val update_uploader : uploader -> chunks -> unit
- val clear_uploader_block : uploader -> unit
- val clear_uploader_ranges : uploader -> unit
- val unregister_uploader : uploader -> unit
- val find_block : uploader -> block
- val find_range : uploader -> int64 * int64 * range
- val current_block : uploader -> block
- val current_ranges : uploader -> (int64 * int64 * range) list
- val received : uploader -> int64 -> string -> int -> int -> unit
- val print_t : string -> t -> unit
- val range_range : range -> int64 * int64
- val print_block : block -> unit
- val block_num : t -> block -> int
- val availability : t -> string
- val downloaded : t -> int64
- val present_chunks : t -> (int64 * int64) list
- val partition_size : t -> int
- val compute_bitmap : t -> unit
- val is_interesting : uploader -> bool
- val print_uploader : uploader -> unit
- val verify_all_chunks : t -> bool -> unit
- val verify_one_chunk : t -> unit
- val verify_some_chunks : unit -> unit
- val get_checksums : t -> CommonTypes.uid_type array
- val compute_last_seen : t -> int array
- val print_uploaders : t -> unit
- val uploader_swarmer : uploader -> t
- val swarmer_to_value :
- t ->
- (string * Options.option_value) list ->
- (string * Options.option_value) list
- val value_to_swarmer : t -> (string * Options.option_value) list -> unit
- val has_multinet : bool
- val merge : CommonTypes.file -> CommonTypes.file -> unit
- val subfiles : t -> CommonTypes.file list
- val check_finished : t -> bool
- end
Index: mldonkey/src/daemon/common/commonSwarming.ml
diff -u mldonkey/src/daemon/common/commonSwarming.ml:1.29
mldonkey/src/daemon/common/commonSwarming.ml:1.30
--- mldonkey/src/daemon/common/commonSwarming.ml:1.29 Sat Nov 12 11:20:19 2005
+++ mldonkey/src/daemon/common/commonSwarming.ml Sun Apr 9 00:27:03 2006
@@ -28,49 +28,8 @@
let debug_present_chunks = false
let debug_all = false
-(*************************************************************************)
-(*************************************************************************)
-(*************************************************************************)
-(* *)
-(* MODULE Make *)
-(* *)
-(*************************************************************************)
-(*************************************************************************)
-(*************************************************************************)
-
open CommonTypes
-module type CommonEnv = sig
-
- module CommonTypes : sig
- type file
- type client
- end
-
- open CommonTypes
- module CommonClient : sig
- val client_num : client -> int
- val client_has_bitmap : client -> file -> string -> unit
- end
-
- module CommonFile : sig
- val file_num : file -> int
- val set_file_last_seen : file -> int -> unit
- val file_size : file -> int64
- val file_best_name : file -> string
- val file_state : file -> file_state
- val file_downloaded : file -> int64
- val add_file_downloaded : file -> int64 -> unit
- val file_write : file -> int64 -> string -> int -> int -> unit
- val file_verify : file -> uid_type -> int64 -> int64 -> bool
- val file_mtime : file -> float
- val file_copy : file -> file -> int64 -> int64 -> int64 -> unit
- val file_fd : file -> Unix32.t
- val set_file_fd : file -> Unix32.t -> unit
- val file_disk_name : file -> string
- end
- end
-
type strategy =
LinearStrategy (* one after the other one *)
| AdvancedStrategy (* first chunks first, rarest chunks second,
@@ -91,77 +50,3166 @@
| ForceVerification
| Verification of uid_type array
-module type Maker = functor (M : CommonEnv) -> sig
-
- type t
- type swarmer
- and range
- and uploader
- and block
-
- val create_swarmer : string -> int64 -> int64 -> swarmer
- val remove_swarmer : t option -> unit
- val create : swarmer -> M.CommonTypes.file -> int64 -> t
-
- val set_verifier : t -> verification -> unit
- val set_verified : t -> (int -> int -> unit) -> unit
-
- val set_present : t -> (int64 * int64) list -> unit
- val set_absent : t -> (int64 * int64) list -> unit
-
- val verified_bitmap : t -> string
- val set_verified_bitmap : t -> string -> unit
- val set_verified_chunk : t -> int -> unit
-
- val register_uploader : t -> M.CommonTypes.client -> chunks -> uploader
- val update_uploader : uploader -> chunks -> unit
- val clear_uploader_block : uploader -> unit
- val clear_uploader_ranges : uploader -> unit
- val unregister_uploader : uploader -> unit
-
- val find_block : uploader -> block
- val find_range : uploader -> int64 * int64 * range
- val current_block : uploader -> block
- val current_ranges : uploader -> (int64 * int64 * range) list
-
- val received : uploader -> int64 -> string -> int -> int -> unit
- val print_t : string -> t -> unit
- val range_range : range -> int64 * int64
-
-
- val print_block : block -> unit
- val block_num : t -> block -> int
- val availability : t -> string
- val downloaded : t -> int64
- val present_chunks : t -> (int64 * int64) list
- val partition_size : t -> int
- val compute_bitmap : t -> unit
- val is_interesting : uploader -> bool
- val print_uploader : uploader -> unit
-
-(* In these two function, the 'bool' is if verification should take place
- immediatly or not. *)
- val verify_all_chunks : t -> bool -> unit
-
-(* raise Exit if one block checksum has been computed *)
- val verify_one_chunk : t -> unit
- val verify_some_chunks : unit -> unit
- val get_checksums : t -> CommonTypes.uid_type array
-
- val compute_last_seen : t -> int array
- val print_uploaders : t -> unit
-
- val uploader_swarmer : uploader -> t
-
- val swarmer_to_value : t ->
- (string * Options.option_value) list ->
- (string * Options.option_value) list
-
- val value_to_swarmer : t -> (string * Options.option_value) list -> unit
-
- val has_multinet : bool
- val merge : M.CommonTypes.file -> M.CommonTypes.file -> unit
- val subfiles : t -> M.CommonTypes.file list
-
- val check_finished : t -> bool
-end
+(* let debug_all = true *)
+let exit_on_error = ref false
+
+(* prints a new logline with date, module and starts newline *)
+let lprintf_nl () =
+ lprintf "%s[cSw2] "
+ (log_time ()); lprintf_nl2
+
+(* prints a new logline with date, module and does not start newline *)
+let lprintf_n () =
+ lprintf "%s[cSw2] "
+ (log_time ()); lprintf
+
+open CommonTypes
+
+open Int64ops
+open CommonFile
+open CommonTypes
+open CommonClient
+
+
+(* Worst scenario?: 1 GB splitted in small ranges of 64 KB = 16 000 ranges.
+ In eDonkey, ranges are 180 kB long.
+*)
+
+(* If we want to become 'multinet', we should:
+* there shouldn't be any block_size, instead blocks should correspond
+ to the largest blocks which are completely included in one block for
+ every network.
+* the range_size should be the same for all networks.
+* a completed block should not be verified until all the blocks are
+ completed for all networks.
+* swarmers should be loaded before other files, so that they can be
+used and shared by different files.
+
+* Verification:
+ - must_verify_chunk
+
+TODO: s_last_seen is useless, only t_last_seen is useful, at least in the
+ first version.
+
+*)
+
+type chunk = {
+ chunk_uid : uid_type;
+ chunk_size : int64;
+ }
+
+type t = {
+ mutable t_primary : bool;
+ t_file : file;
+ mutable t_s : swarmer;
+ t_block_size : int64;
+
+ t_nchunks : int;
+ mutable t_converted_verified_bitmap : string;
+ mutable t_last_seen : int array;
+ mutable t_ncomplete_blocks : int;
+ mutable t_nverified_blocks : int;
+
+ mutable t_verifier : verification;
+ mutable t_verified : (int -> int -> unit);
+
+(* conversion from network blocks to swarmer blocks *)
+ mutable t_t2s_blocks : int list array;
+(* conversion from swarmer blocks to network blocks *)
+ mutable t_s2t_blocks : int array;
+ }
+
+and swarmer = {
+ mutable s_num : int;
+ mutable s_filename : string;
+
+ mutable s_networks : t list;
+ mutable s_size : int64;
+ mutable s_range_size : int64;
+ mutable s_strategy : strategy;
+
+ mutable s_verified_bitmap : string;
+ mutable s_availability : int array;
+ mutable s_nuploading : int array;
+(* mutable s_last_seen : int array; *)
+
+ mutable s_blocks : block_v array;
+ mutable s_block_pos : int64 array; (** offset of the beginning of
+ each block *)
+ }
+
+and block_v =
+ EmptyBlock
+| PartialBlock of block
+| CompleteBlock
+| VerifiedBlock
+
+and block = {
+ block_s : swarmer;
+ mutable block_num : int;
+ mutable block_begin : Int64.t;
+ mutable block_end : Int64.t;
+ mutable block_ranges : range; (** (first ?) [range] of the double-linked
+ list of ranges associated to the
+ [block] *)
+ mutable block_remaining : int64;
+ }
+
+and range = {
+ mutable range_block : block;
+ mutable range_begin : Int64.t; (* official begin int64 *)
+ mutable range_end : Int64.t;
+ mutable range_prev : range option;
+ mutable range_next : range option;
+ mutable range_current_begin : Int64.t; (* current begin pos *)
+(* mutable range_verified : bool; *)
+ mutable range_nuploading : int;
+ }
+
+and uploader = {
+ up_t : t;
+ up_client : client;
+
+ mutable up_declared : bool;
+
+ mutable up_chunks : chunks;
+ mutable up_complete_blocks : int array; (** block numbers *)
+ mutable up_ncomplete : int;
+
+ mutable up_partial_blocks : (int * int64 * int64) array; (** block
+ number,
+ begin_pos,
+ end_pos
+ *)
+ mutable up_npartial : int;
+
+ mutable up_block : block option;
+ mutable up_block_begin : int64;
+ mutable up_block_end : int64;
+
+ mutable up_ranges : (int64 * int64 * range) list;
+ }
+
+
+(*************************************************************************)
+(* *)
+(* Global values *)
+(* *)
+(*************************************************************************)
+
+module HS = Weak.Make(struct
+ type t = swarmer
+ let hash file = Hashtbl.hash file.s_filename
+
+ let equal x y = x.s_filename = y.s_filename
+ end)
+
+let swarmers_by_name = HS.create 31
+
+module HU = Weak.Make(struct
+ type t = uploader
+ let hash u = Hashtbl.hash (client_num u.up_client)
+
+ let equal x y = (client_num x.up_client) = (client_num y.up_client)
+ end)
+
+let uploaders_by_num = HU.create 113
+
+let edonkey_range_size = Int64.of_int (180 * 1024)
+
+let swarmer_counter = ref 0
+
+let has_multinet = true
+
+(*************************************************************************)
+(* *)
+(* dummy_swarmer *)
+(* *)
+(*************************************************************************)
+
+let dummy_swarmer = {
+ s_num = 0;
+ s_filename = "";
+ s_networks = [];
+ s_size = zero;
+ s_range_size = zero;
+ s_strategy = AdvancedStrategy;
+ s_verified_bitmap = "";
+ s_blocks = [||];
+ s_block_pos = [||];
+ s_availability = [||];
+ s_nuploading = [||];
+ }
+
+(** (debug) output an [uploader] to current log *)
+
+let print_uploader up =
+ lprintf_n () " interesting complete_blocks: %d\n " up.up_ncomplete;
+ Array.iter (fun i -> lprintf " %d " i) up.up_complete_blocks;
+ lprint_newline ();
+ lprintf_n () " interesting partial_blocks: %d\n " up.up_npartial;
+ Array.iter (fun (i, begin_pos, end_pos) ->
+ lprintf " %d[%Ld...%Ld] " i begin_pos end_pos
+ ) up.up_partial_blocks;
+ lprint_newline ()
+
+(** sets [t.t_last_seen] of the verified blocks to current time, and
+ associated file's [t.t_file] last seen value to the oldest of the
+ remaining last seen values *)
+
+let compute_last_seen t =
+ let last_seen_total = ref (BasicSocket.last_time ()) in
+ for i = 0 to String.length t.t_converted_verified_bitmap - 1 do
+ if t.t_converted_verified_bitmap.[i] > '2' then
+ t.t_last_seen.(i) <- BasicSocket.last_time ()
+ else
+ last_seen_total := min !last_seen_total t.t_last_seen.(i)
+ done;
+ set_file_last_seen t.t_file !last_seen_total;
+ t.t_last_seen
+
+(** if a swarmer is already associated with that [file_name], return it;
+ Otherwise create a new one with default values (including a default
+ [range_size] instead of the provided value ??) *)
+
+let create_swarmer file_name file_size range_size =
+
+ try
+ HS.find swarmers_by_name
+ { dummy_swarmer with
+ s_filename = file_name
+ }
+ with Not_found ->
+ incr swarmer_counter;
+
+(* Let be VERY conservative... *)
+ let range_size = edonkey_range_size in
+
+ let nchunks = 1 in
+ let rec s = {
+
+ s_num = !swarmer_counter;
+ s_filename = file_name;
+
+ s_networks = [];
+
+ s_size = file_size;
+ s_range_size = range_size;
+ s_strategy = AdvancedStrategy;
+
+ s_verified_bitmap = String.make nchunks '0';
+ s_blocks = Array.create nchunks EmptyBlock ;
+ s_block_pos = Array.create nchunks zero;
+ s_availability = Array.create nchunks 0;
+ s_nuploading = Array.create nchunks 0;
+(* s_last_seen = Array.create nchunks 0; *)
+ }
+ in
+ HS.add swarmers_by_name s;
+ s
+
+(** (internal) return the offset of the end of the [i]th block of
+ swarmer [s] *)
+
+let compute_block_end s i =
+ let b = s.s_block_pos in
+ if Array.length b = i + 1 then
+ s.s_size
+ else
+ b.(i+1)
+
+(** (internal) return the offset of the beginning of the [i]th block
+ of swarmer [s] *)
+
+let compute_block_begin s i =
+ let b = s.s_block_pos in
+ b.(i)
+
+(** (internal) return a 0 sized range at offset [pos], and assigned to
+ block [b] *)
+
+let void_range b pos =
+ let r = {
+ range_prev = None;
+ range_next = None;
+ range_begin = pos;
+ range_end = pos;
+ range_block = b;
+ range_nuploading = 0;
+ range_current_begin = pos;
+ }
+ in
+ r
+
+(** (internal) assigns range [r], and all other ranges along
+ [range_next] links, to block [b] *)
+
+let rec own_ranges b r =
+ r.range_block <- b;
+ match r.range_next with
+ None -> ()
+ | Some r -> own_ranges b r
+
+(** (internal)
+ Find (following [range_next] links) the first range that's not
+ totally before [cut_pos] offset.
+ If none is found, return a [void_range] at [cut_pos] offset.
+ otherwise, if a range is found,
+ if it is totally after [cut_pos], remove [range_prev] link, modify
+ owner block for all remaining ranges (including the one found),
+ and return that range.
+ if range found crossed [cut_pos] offset, create a similar range
+ with no [range_prev] link, [range_begin] with [cut_pos] value,
+ increase [range_current_begin] to [cut_pos] if it's smaller,
+ modify owner block for all remaining ranges (including that new
+ one), and return that range. *)
+
+let rec get_after_ranges b r cut_pos =
+ if r.range_begin >= cut_pos then begin
+ (match r.range_prev with
+ | None -> ()
+ | Some rp ->
+ rp.range_next <- None;
+ r.range_prev <- None);
+ own_ranges b r;
+ r
+ end else
+ if r.range_end <= cut_pos then
+ match r.range_next with
+ None -> void_range b cut_pos
+ | Some r -> get_after_ranges b r cut_pos
+ else
+ let split_r = { r with
+ range_prev = None;
+ range_begin = cut_pos;
+ range_current_begin = max r.range_current_begin cut_pos
+ } in
+ r.range_next <- None;
+ r.range_end <- cut_pos;
+ own_ranges b split_r;
+ split_r
+
+
+(** (internal)
+ if [r.range_current_begin] is after [cut_pos], return a
+ [void_range] at offset [cut_pos],
+
+*)
+
+let get_before_ranges b r cut_pos =
+ if r.range_current_begin >= cut_pos then
+ void_range b cut_pos
+ else
+ let rec iter b r cut_pos =
+ if r.range_end > cut_pos then begin
+ let split_r = { r with
+ range_end = cut_pos;
+ range_next = None } in
+ (match r.range_prev with
+ | None -> ()
+ | Some rp ->
+ rp.range_next <- Some split_r;
+ r.range_prev <- None);
+ r.range_current_begin <- cut_pos;
+ end else
+ if r.range_end = cut_pos then
+ match r.range_next with
+ | None -> ()
+ | Some rn ->
+ rn.range_prev <- None;
+ r.range_next <- None
+ else
+ match r.range_next with
+ | None -> ()
+ | Some rn ->
+ if rn.range_current_begin >= cut_pos then begin
+ rn.range_prev <- None;
+ r.range_next <- None
+ end else
+ iter b rn cut_pos
+ in
+ iter b r cut_pos;
+ r
+
+(** Return true if ranges fully "cover" their block:
+ first range's [range_current_begin] = block's [block_begin]
+ each range's [range_end] = next range's [range_current_begin]
+ last range's [range_end] = block(s [block_end] *)
+
+let empty_block b =
+ let rec iter begin_pos r =
+ r.range_current_begin = begin_pos &&
+ (match r.range_next with
+ Some rr -> iter r.range_end rr
+ | None -> r.range_end = b.block_end)
+ in
+ iter b.block_begin b.block_ranges
+
+(*************************************************************************)
+(* *)
+(* create *)
+(* *)
+(*************************************************************************)
+
+let split_blocks s chunk_size =
+
+ let size = s.s_size in
+
+ let nblocks = Array.length s.s_blocks in
+ let rec iter index_s chunk_begin new_blocks =
+(* lprintf "iter (1) %d/%d %Ld\n" index_s nblocks chunk_begin; *)
+ if index_s = nblocks then List.rev new_blocks else
+ let block_begin = compute_block_begin s index_s in
+ let block_end = compute_block_end s index_s in
+
+ let chunk_end = chunk_begin ++ chunk_size in
+ let chunk_end = min chunk_end size in
+
+ if chunk_end > block_end then begin
+
+ let new_blocks = (
+ s.s_blocks.(index_s),
+ block_begin,
+ s.s_verified_bitmap.[index_s]
+ ) :: new_blocks in
+ iter (index_s+1) chunk_begin new_blocks
+
+ end else
+
+ if chunk_end = block_end then begin
+
+ let new_blocks = (
+ s.s_blocks.(index_s),
+ block_begin,
+ s.s_verified_bitmap.[index_s]
+ ) :: new_blocks in
+ iter (index_s+1) chunk_end new_blocks
+
+ end else begin
+
+(* We need to split this block in two parts *)
+
+ s.s_block_pos.(index_s) <- chunk_end;
+ match s.s_blocks.(index_s) with
+ EmptyBlock | CompleteBlock | VerifiedBlock ->
+
+ let new_blocks = (
+ s.s_blocks.(index_s),
+ block_begin,
+ s.s_verified_bitmap.[index_s]
+ ) :: new_blocks in
+ iter index_s chunk_end new_blocks
+
+ | PartialBlock b1 ->
+
+ let b2 = {
+ block_s = s;
+
+ block_begin = chunk_end;
+ block_end = b1.block_end;
+ block_ranges = b1.block_ranges;
+ block_num = index_s + 1;
+ block_remaining = zero;
+ } in
+ b1.block_end <- chunk_end;
+
+ b2.block_ranges <- get_after_ranges b2 b2.block_ranges chunk_end;
+ b1.block_ranges <- get_before_ranges b1 b1.block_ranges chunk_end;
+
+
+ if empty_block b2 then begin
+(* lprintf "Partial block b2 should become EmptyBlock\n"; *)
+ s.s_blocks.(index_s) <- EmptyBlock;
+ s.s_verified_bitmap.[index_s] <- '0';
+ end else begin
+ s.s_blocks.(index_s) <- PartialBlock b2;
+ end;
+
+ let new_blocks =
+ (if empty_block b1 then
+(* lprintf "Partial block b1 should become EmptyBlock\n"; *)
+ (
+ EmptyBlock,
+ block_begin,
+ '0'
+ ) else (
+ PartialBlock b1,
+ block_begin,
+ s.s_verified_bitmap.[index_s]
+ ))
+ :: new_blocks in
+ iter index_s chunk_end new_blocks
+
+ end
+
+
+ in
+ let blocks = iter 0 zero [] in
+
+ let nblocks = List.length blocks in
+(* lprintf "%d blocks to generate\n" nblocks; *)
+
+ s.s_blocks <- Array.create nblocks EmptyBlock;
+ s.s_verified_bitmap <- String.make nblocks '0';
+ s.s_block_pos <- Array.create nblocks zero;
+ s.s_availability <- Array.create nblocks 0;
+ s.s_nuploading <- Array.create nblocks 0;
+(* s.s_last_seen <- Array.create nblocks 0; *)
+
+ let rec iter i list =
+ match list with
+ [] -> ()
+ | (b, pos, c) :: tail ->
+ begin
+ match b with
+ PartialBlock b -> b.block_num <- i
+ | _ -> ()
+ end;
+ s.s_blocks.(i) <- b;
+ s.s_verified_bitmap.[i] <- c;
+ s.s_block_pos.(i) <- pos;
+
+ iter (i+1) tail
+ in
+ iter 0 blocks
+
+(*************************************************************************)
+(* *)
+(* associate *)
+(* *)
+(*************************************************************************)
+
+let associate primary t s =
+
+ if not (List.memq t s.s_networks) then
+ let size = file_size t.t_file in
+
+ begin
+ if t.t_s != s then begin
+ t.t_s.s_networks <- [];
+ end;
+ end;
+
+ assert (s.s_size = size);
+
+ t.t_s <- s;
+ t.t_converted_verified_bitmap <- String.make t.t_nchunks '0';
+ t.t_last_seen <- Array.create t.t_nchunks 0;
+ t.t_s2t_blocks <- [||];
+ t.t_t2s_blocks <- Array.create t.t_nchunks [];
+
+ if primary then begin
+ t.t_primary <- true;
+ s.s_networks <- t :: s.s_networks;
+ end else begin
+ t.t_primary <- false;
+ s.s_networks <- s.s_networks @ [t];
+ Unix32.remove (file_fd t.t_file);
+ end;
+(* at this point, we are supposed to split the blocks in the swarmer
+in smaller blocks depending on the block_size of this network, and compute
+the t_s2t_blocks and t_t2s_blocks fields. *)
+
+ let chunk_size = t.t_block_size in
+
+ split_blocks s chunk_size;
+
+ let nblocks = Array.length s.s_blocks in
+(* For all networks, adjust the blocks *)
+ List.iter (fun t ->
+ let nchunks = String.length t.t_converted_verified_bitmap in
+ t.t_s2t_blocks <- Array.create nblocks 0;
+ t.t_t2s_blocks <- Array.create nchunks [];
+
+ let chunk_size = t.t_block_size in
+ for i = 0 to nblocks - 1 do
+ let block_begin = compute_block_begin s i in
+ let chunk = Int64.to_int (block_begin // chunk_size) in
+ t.t_s2t_blocks.(i) <- chunk;
+ t.t_t2s_blocks.(chunk) <- i :: t.t_t2s_blocks.(chunk)
+ done
+ ) s.s_networks;
+
+(* TODO: If not primary, set_file_downloaded should be called *)
+ if not primary then
+ add_file_downloaded t.t_file (zero -- file_downloaded t.t_file);
+
+ begin
+ match s.s_networks with
+ t :: tail when primary ->
+ List.iter (fun tt ->
+ assert (not tt.t_primary);
+ set_file_fd tt.t_file (file_fd t.t_file)
+ ) tail
+
+ | tt :: tail when tt.t_primary ->
+ assert (not primary);
+ set_file_fd t.t_file (file_fd tt.t_file)
+ | _ -> ()
+ end;
+
+ ()
+
+(*************************************************************************)
+(* *)
+(* create *)
+(* *)
+(*************************************************************************)
+
+let create ss file chunk_size =
+
+ let size = file_size file in
+ let nchunks =
+ 1 + Int64.to_int (Int64.pred size // chunk_size) in
+
+ let rec t = {
+
+ t_s = ss;
+ t_primary = true;
+ t_file = file;
+
+ t_nchunks = nchunks;
+ t_block_size = chunk_size;
+
+ t_ncomplete_blocks = 0;
+ t_nverified_blocks = 0;
+
+ t_converted_verified_bitmap = String.make nchunks '0';
+ t_last_seen = Array.create nchunks 0;
+
+ t_verifier = NoVerification;
+ t_verified = (fun _ _ -> ());
+
+ t_s2t_blocks = [||];
+ t_t2s_blocks = Array.create nchunks [];
+ }
+ in
+ associate true t ss;
+ t
+
+
+(*************************************************************************)
+(* *)
+(* clear_uploader_ranges *)
+(* *)
+(*************************************************************************)
+
+let clear_uploader_ranges up =
+ List.iter (fun (_,_,r) ->
+ r.range_nuploading <- r.range_nuploading - 1
+ ) up.up_ranges;
+ up.up_ranges <- []
+
+(*************************************************************************)
+(* *)
+(* clear_uploader_block *)
+(* *)
+(*************************************************************************)
+
+let clear_uploader_block up =
+ match up.up_block with
+ None -> ()
+ | Some b ->
+ up.up_block <- None;
+ let num = b.block_num in
+ let t = up.up_t in
+ let s = t.t_s in
+ s.s_nuploading.(num) <- s.s_nuploading.(num) - 1
+
+(*************************************************************************)
+(* *)
+(* compute_block_num (internal) *)
+(* *)
+(*************************************************************************)
+
+let compute_block_num s chunk_pos =
+ let b = s.s_block_pos in
+ let rec iter min max =
+ if min = max then min else
+ let medium = (max + min) / 2 in
+ let pos = b.(medium) in
+ if pos > chunk_pos then
+ iter min (medium - 1)
+ else
+ if min = medium then
+ iter min (max - 1)
+ else
+ iter medium max
+ in
+ let i = iter 0 (Array.length b - 1) in
+ if debug_all then
+ lprintf_nl () "%Ld is block %d [%Ld-%Ld]" chunk_pos i
+ (compute_block_begin s i) (compute_block_end s i);
+ i
+
+
+(*************************************************************************)
+(* *)
+(* apply_intervals (internal) *)
+(* *)
+(*************************************************************************)
+
+let apply_intervals s f chunks =
+ let nchunks = Array.length s.s_blocks in
+ let rec iter chunks =
+ match chunks with
+ [] -> ()
+ | (chunk_begin, chunk_end) :: tail ->
+ let chunk_begin = min chunk_begin s.s_size in
+ let chunk_end = min chunk_end s.s_size in
+(* lprintf "apply on %Ld-%Ld\n" chunk_begin chunk_end; *)
+ if chunk_begin < chunk_end then begin
+ let i0 = compute_block_num s chunk_begin in
+ let block_begin = compute_block_begin s i0 in
+ let rec iter_blocks i block_begin chunk_begin =
+
+(* lprintf "iter_blocks %d %Ld %Ld\n" i block_begin chunk_begin;
*)
+ if i < nchunks && block_begin < chunk_end then
+ let block_end = compute_block_end s i in
+
+ let current_end = min block_end chunk_end in
+
+ if debug_all then
+ lprintf_nl () "Apply: %d %Ld-%Ld %Ld-%Ld"
+ i block_begin block_end chunk_begin current_end;
+
+ f i block_begin block_end chunk_begin current_end;
+
+ iter_blocks (i+1) block_end block_end
+ in
+ iter_blocks i0 block_begin chunk_begin;
+ end;
+ iter tail
+ in
+ iter chunks
+
+
+(*************************************************************************)
+(* *)
+(* print_s *)
+(* *)
+(*************************************************************************)
+
+let print_s str s =
+ lprintf_nl () "Ranges after %s:" str;
+
+ let rec iter r =
+ lprintf_n () " %Ld(%Ld)-%Ld(%d)"
+ r.range_begin r.range_current_begin r.range_end r.range_nuploading;
+ match r.range_next with
+ None -> lprint_newline()
+ | Some r -> iter r
+ in
+
+ Array.iteri (fun i b ->
+ lprintf_n () " %d: " i;
+ let block_begin = compute_block_begin s i in
+ let block_end = compute_block_end s i in
+ lprintf "%Ld - %Ld [%Ld] %c " block_begin block_end
+ (block_end -- block_begin) s.s_verified_bitmap.[i];
+ List.iter (fun t ->
+ let j = t.t_s2t_blocks.(i) in
+ lprintf "(b %d %c [" j t.t_converted_verified_bitmap.[j];
+ List.iter (fun ii -> lprintf "%d " ii) t.t_t2s_blocks.(j);
+ lprintf "]";
+ ) s.s_networks;
+
+ match b with
+ PartialBlock b ->
+ lprintf " [%Ld .. %Ld] --> "
+ b.block_begin b.block_end;
+ iter b.block_ranges
+ | EmptyBlock -> lprintf_nl2 "_"
+ | CompleteBlock -> lprintf_nl2 "C"
+ | VerifiedBlock -> lprintf_nl2 "V"
+ ) s.s_blocks;
+
+ lprintf_nl () "Files:";
+ List.iter (fun t ->
+ lprintf_nl () " File num: %d" (file_num t.t_file);
+ lprintf_nl () " %s" (if t.t_primary then "primary" else "secondary");
+ lprintf_nl () " Downloaded: %Ld" (file_downloaded t.t_file);
+ lprintf_nl () " Bitmap: %s" t.t_converted_verified_bitmap
+ ) s.s_networks
+
+(*************************************************************************)
+(* *)
+(* iter_block_ranges *)
+(* *)
+(*************************************************************************)
+
+let iter_block_ranges f b =
+ let rec iter_range f r =
+ f r;
+ match r.range_next with
+ None -> ()
+ | Some rr -> iter_range f rr
+ in
+ iter_range f b.block_ranges
+
+(*************************************************************************)
+(* *)
+(* print_block *)
+(* *)
+(*************************************************************************)
+
+let print_block b =
+ lprintf_n () "Block %d: %Ld-%Ld"
+ b.block_num b.block_begin b.block_end;
+ lprint_newline ();
+ lprintf_nl () " ranges:";
+ let rec iter_range r =
+ lprintf_nl () " %Ld-%Ld" r.range_current_begin r.range_end;
+ match r.range_next with
+ None -> ()
+ | Some rr -> iter_range rr
+ in
+ iter_range b.block_ranges;
+ lprint_newline ()
+
+(*************************************************************************)
+(* *)
+(* add_file_downloaded *)
+(* *)
+(*************************************************************************)
+
+let add_file_downloaded maybe_t s size =
+(* lprintf "add_file_downloaded %Ld\n" size; *)
+ match s.s_networks with
+ t :: _ when t.t_primary ->
+ add_file_downloaded t.t_file size;
+ begin
+ match maybe_t with
+ None -> ()
+ | Some tt when t != tt ->
+ add_file_downloaded tt.t_file size;
+ | _ -> ()
+ end;
+ if file_downloaded t.t_file < zero then
+ lprintf_nl () "ERROR: file_downloaded < zero!";
+
+ | _ -> ()
+
+(*************************************************************************)
+(* *)
+(* close_ranges (internal) *)
+(* *)
+(*************************************************************************)
+
+let rec close_ranges maybe_t s r =
+
+ let added = r.range_end -- r.range_current_begin in
+ add_file_downloaded maybe_t s added;
+ let b = r.range_block in
+ b.block_remaining <- b.block_remaining -- added;
+
+ r.range_current_begin <- r.range_end;
+ match r.range_next with
+ None -> ()
+ | Some rr ->
+ r.range_prev <- None;
+ r.range_next <- None;
+ close_ranges maybe_t s rr
+
+
+(*************************************************************************)
+(* *)
+(* set_downloaded_block *)
+(* *)
+(*************************************************************************)
+
+let set_downloaded_block maybe_t s i =
+ match s.s_blocks.(i) with
+ EmptyBlock ->
+ let block_begin = compute_block_begin s i in
+ let block_end = compute_block_end s i in
+ add_file_downloaded maybe_t s (block_end -- block_begin)
+ | PartialBlock b ->
+ let rec iter r =
+ add_file_downloaded maybe_t s (r.range_end -- r.range_current_begin);
+ r.range_current_begin <- r.range_end;
+ match r.range_next with
+ None -> r.range_prev <- None; r
+ | Some rr ->
+ r.range_prev <- None;
+ r.range_next <- None;
+ iter rr
+ in
+ b.block_ranges <- iter b.block_ranges
+ | _ -> ()
+
+(*************************************************************************)
+(* *)
+(* set_verified_bitmap (internal) *)
+(* *)
+(*************************************************************************)
+
+(* For every swarmer, there is a "primary" verifier, and secondary verifiers.
+When a block is downloaded, it is tagged '2' in the verified_bitmap, and
+this '2' is propagated to the primary bitmap if possible (if all sub-blocks
+are also '2'). If the primary chunk becomes '2', then a verification is
+needed on the primary. If the verification works, the verified_bitmap
+becomes '3', and the secondary verifiers are tagged with '2' (if they use
+a different verification scheme) or '3' (if no verification scheme or
+a verification scheme that has already been used). *)
+
+(* corruption has been detected, and the block has been reset to 0 *)
+let set_bitmap_0 s i =
+ if s.s_verified_bitmap.[i] > '1' then begin
+ s.s_verified_bitmap.[i] <- '0';
+ List.iter (fun t ->
+ let j = t.t_s2t_blocks.(i) in
+ if List.for_all (fun i -> s.s_verified_bitmap.[i] = '0')
+ t.t_t2s_blocks.(j) then
+ t.t_converted_verified_bitmap.[j] <- '0'
+ ) s.s_networks
+ end
+
+(* we have started downloading this block, so mark all containing blocks
+ also as started. *)
+let set_bitmap_1 s i =
+ if s.s_verified_bitmap.[i] = '0' then begin
+ s.s_verified_bitmap.[i] <- '1';
+ List.iter (fun t ->
+ let j = t.t_s2t_blocks.(i) in
+ if t.t_converted_verified_bitmap.[j] = '0' then
+ t.t_converted_verified_bitmap.[j] <- '1'
+ ) s.s_networks
+ end
+
+(* we finished this block, we need know to verify it *)
+let set_bitmap_2 s i =
+ if s.s_verified_bitmap.[i] < '2' then begin
+ s.s_verified_bitmap.[i] <- '2';
+ match s.s_networks with
+ | t :: _ when t.t_primary ->
+ let j = t.t_s2t_blocks.(i) in
+ if List.for_all (fun i -> s.s_verified_bitmap.[i] = '2')
+ t.t_t2s_blocks.(j) &&
+ t.t_converted_verified_bitmap.[j] <> '3' then begin
+ t.t_ncomplete_blocks <- t.t_ncomplete_blocks + 1;
+ t.t_converted_verified_bitmap.[j] <- '2'
+ end
+ | [] -> assert false
+ | _ -> ()
+ end
+
+(* the primary verifier has worked, so let ask secondary ones for
+verification too *)
+let set_bitmap_3 s i =
+ if s.s_verified_bitmap.[i] < '3' then begin
+ s.s_verified_bitmap.[i] <- '3';
+(* lprintf "set_bitmap_3 %d done\n" i; *)
+ match s.s_networks with
+ [] -> assert false
+ | tprim :: tail ->
+ List.iter (fun t ->
+ let j = t.t_s2t_blocks.(i) in
+ if List.for_all (fun i -> s.s_verified_bitmap.[i] = '3')
+ t.t_t2s_blocks.(j) then
+ match t.t_verifier with
+ NoVerification ->
+ t.t_converted_verified_bitmap.[j] <- '3'
+ | _ ->
+ t.t_ncomplete_blocks <- t.t_ncomplete_blocks + 1;
+ t.t_converted_verified_bitmap.[j] <- '2'
+ ) tail
+ end
+
+(*************************************************************************)
+(* *)
+(* set_toverify_block (internal) *)
+(* *)
+(*************************************************************************)
+
+ (*
+let set_toverify_block s i = set_bitmap_2 s i
+ *)
+
+(*************************************************************************)
+(* *)
+(* set_completed_block (internal) *)
+(* *)
+(*************************************************************************)
+
+let set_completed_block maybe_t s i =
+ begin
+ match s.s_blocks.(i) with
+ PartialBlock b -> close_ranges maybe_t s b.block_ranges
+ | _ -> ()
+ end;
+ match s.s_blocks.(i) with
+ CompleteBlock | VerifiedBlock -> ()
+ | _ ->
+ set_downloaded_block maybe_t s i;
+ set_bitmap_2 s i;
+ s.s_blocks.(i) <- CompleteBlock
+
+(*************************************************************************)
+(* *)
+(* set_verified_block (internal) *)
+(* *)
+(*************************************************************************)
+
+let set_verified_block s j =
+ match s.s_blocks.(j) with
+ VerifiedBlock -> ()
+ | _ ->
+ set_completed_block None s j;
+ s.s_blocks.(j) <- VerifiedBlock;
+ set_bitmap_3 s j
+
+(*************************************************************************)
+(* *)
+(* set_verified_chunk (internal) *)
+(* *)
+(*************************************************************************)
+
+let set_verified_chunk t i =
+ t.t_nverified_blocks <- t.t_nverified_blocks + 1;
+ t.t_converted_verified_bitmap.[i] <- '3';
+ let s = t.t_s in
+ if t.t_primary then begin
+ (* The primary is supposed to propagate verified chunks to the file *)
+ List.iter (fun j -> set_verified_block s j) t.t_t2s_blocks.(i);
+ if !verbose_swarming then
+ print_s "VERIFIED" s
+ end
+
+(*************************************************************************)
+(* *)
+(* verify (internal) *)
+(* *)
+(*************************************************************************)
+
+let verify t chunks num begin_pos end_pos =
+ file_verify t.t_file chunks.(num) begin_pos end_pos
+
+(*************************************************************************)
+(* *)
+(* verify_chunk (internal) *)
+(* *)
+(*************************************************************************)
+
+let verify_chunk t i =
+ if t.t_converted_verified_bitmap.[i] = '2' then
+ let nblocks = String.length t.t_converted_verified_bitmap in
+ match t.t_verifier with
+ NoVerification
+ | VerificationNotAvailable -> ()
+
+ | ForceVerification ->
+ set_verified_chunk t i;
+ t.t_verified t.t_nverified_blocks i
+
+ | Verification chunks when Array.length chunks = nblocks ->
+
+ begin try
+ let s = t.t_s in
+ let block_begin = t.t_block_size *.. i in
+ let block_end = block_begin ++ t.t_block_size in
+ let block_end = min block_end s.s_size in
+ if verify t chunks i block_begin block_end then
+ begin
+ set_verified_chunk t i;
+ t.t_verified t.t_nverified_blocks i;
+ if !verbose_swarming || !verbose then
+ lprintf_nl () "Completed block %d/%d of %s"
+ (i + 1) t.t_nchunks (file_best_name t.t_file)
+ end
+ else
+ begin
+ t.t_ncomplete_blocks <- t.t_ncomplete_blocks - 1;
+
+ if List.for_all (fun i ->
+ s.s_verified_bitmap.[i] = '2'
+ ) t.t_t2s_blocks.(i)
+ then
+ begin
+ if !verbose_swarming || !verbose then
+ lprintf_nl () "Complete block %d/%d of %s failed
verification, reloading..."
+ (i + 1) t.t_nchunks (file_best_name t.t_file);
+
+ t.t_converted_verified_bitmap.[i] <- '0';
+
+ List.iter (fun i ->
+ match s.s_blocks.(i) with
+ EmptyBlock -> set_bitmap_0 s i
+ | PartialBlock _ -> set_bitmap_1 s i
+ | CompleteBlock ->
+ let block_begin = compute_block_begin s i in
+ let block_end = compute_block_end s i in
+ add_file_downloaded None s (block_begin --
block_end);
+
+ s.s_blocks.(i) <- EmptyBlock;
+ set_bitmap_0 s i
+
+ | VerifiedBlock -> assert false
+ ) t.t_t2s_blocks.(i)
+ end
+ else
+ begin
+ if !verbose_swarming then begin
+ let nsub = ref 0 in
+ lprintf_n () " Swarmer was incomplete: ";
+ List.iter (fun i ->
+ lprintf "%c" s.s_verified_bitmap.[i];
+ if s.s_verified_bitmap.[i] = '2' then incr nsub;
+ ) t.t_t2s_blocks.(i);
+ lprintf_nl2 " = %d/%d" !nsub (List.length
t.t_t2s_blocks.(i))
+ end;
+ t.t_converted_verified_bitmap.[i] <- '1'
+ end;
+ end
+ with VerifierNotReady -> ()
+ end
+
+ | Verification chunks ->
+ assert (Array.length chunks = 1);
+ let can_verify = ref true in
+ let nblocks= String.length t.t_converted_verified_bitmap in
+ for i = 0 to nblocks - 1 do
+ if t.t_converted_verified_bitmap.[i] < '2' then
+ can_verify := false
+ done;
+ if !can_verify then begin
+ try
+ let s = t.t_s in
+ if verify t chunks 0 zero s.s_size then begin
+ for i = 0 to nblocks - 1 do
+ if t.t_converted_verified_bitmap.[i] = '2' then begin
+
+ set_verified_chunk t i;
+ t.t_verified t.t_nverified_blocks i;
+ end
+ done
+
+ end else begin
+
+ lprintf_nl () "Verification of blocks for file %s FAILED\n"
+ (file_best_name t.t_file);
+
+ for i = 0 to nblocks - 1 do
+ if t.t_converted_verified_bitmap.[i] = '2' then begin
+
+ t.t_ncomplete_blocks <- t.t_ncomplete_blocks - 1;
+ if List.for_all (fun i ->
+ s.s_verified_bitmap.[i] = '2'
+ ) t.t_t2s_blocks.(i) then begin
+
+ t.t_converted_verified_bitmap.[i] <- '0';
+
+ List.iter (fun i ->
+ match s.s_blocks.(i) with
+ EmptyBlock -> set_bitmap_0 s i
+ | PartialBlock _ -> set_bitmap_1 s i
+ | CompleteBlock ->
+ let block_begin = compute_block_begin s i
in
+ let block_end = compute_block_end s i in
+ add_file_downloaded None s (block_begin --
block_end);
+
+ s.s_blocks.(i) <- EmptyBlock;
+ set_bitmap_0 s i
+
+ | VerifiedBlock -> assert false
+ ) t.t_t2s_blocks.(i)
+ end else begin
+ let nsub = ref 0 in
+
+ lprintf_n () " Swarmer was incomplete: ";
+ List.iter (fun i ->
+ lprintf "%c" s.s_verified_bitmap.[i];
+ if s.s_verified_bitmap.[i] = '2' then incr
nsub;
+ ) t.t_t2s_blocks.(i);
+ lprintf_nl2 " = %d/%d" !nsub (List.length
t.t_t2s_blocks.(i));
+
+ t.t_converted_verified_bitmap.[i] <- '1'
+ end;
+ end
+ done
+ end
+ with VerifierNotReady -> ()
+ end
+
+
+(*************************************************************************)
+(* *)
+(* must_verify_chunk (internal) *)
+(* *)
+(*************************************************************************)
+
+ (*
+let must_verify_chunk t i immediatly =
+ match t.t_verifier with
+ NoVerification -> ()
+ | _ ->
+ if t.t_converted_verified_bitmap.[i] < '2' then
+ set_toverify_chunk t i;
+ if t.t_converted_verified_bitmap.[i] = '2' && immediatly then
+ verify_chunk t i
+ *)
+
+(*************************************************************************)
+(* *)
+(* must_verify_block *)
+(* *)
+(*************************************************************************)
+
+let must_verify_block s i immediatly =
+ set_bitmap_2 s i;
+ if immediatly then
+ match s.s_networks with
+ [] -> assert false
+ | t :: _ when t.t_primary ->
+ let i = t.t_s2t_blocks.(i) in
+ t.t_converted_verified_bitmap.[i] <- '2';
+(* List.iter (fun j ->
+ if s.s_verified_bitmap.[j] <> '2' then begin
+ lprintf " block %d not downloaded\n" j;
+ exit_on_error := false;
+ end;
+ ) t.t_t2s_blocks.(i); *)
+ verify_chunk t i;
+(* exit_on_error := true; *)
+ | _ -> ()
+
+(*************************************************************************)
+(* *)
+(* verify_all_blocks *)
+(* *)
+(*************************************************************************)
+
+let verify_all_chunks t immediatly =
+ let s = t.t_s in
+ for i = 0 to String.length s.s_verified_bitmap - 1 do
+ must_verify_block s i immediatly
+ done
+
+(*************************************************************************)
+(* *)
+(* compute_bitmap *)
+(* *)
+(*************************************************************************)
+
+
+let compute_bitmap t =
+ if t.t_ncomplete_blocks > t.t_nverified_blocks then begin
+ for i = 0 to String.length t.t_converted_verified_bitmap - 1 do
+ if t.t_converted_verified_bitmap.[i] = '2' then
+ verify_chunk t i
+ done
+ end
+
+
+(*************************************************************************)
+(* *)
+(* split_range (internal) *)
+(* *)
+(*************************************************************************)
+
+let rec split_range r range_size =
+ assert (r.range_current_begin = r.range_begin);
+ let next_range = r.range_begin ++ range_size in
+(* lprintf " split_range: next_range %Ld\n" next_range; *)
+ if r.range_end > next_range then
+ let rr = {
+ range_block = r.range_block;
+ range_nuploading = 0;
+ range_next = r.range_next;
+ range_prev = Some r;
+ range_begin = next_range;
+ range_current_begin = next_range;
+ range_end = r.range_end;
+ } in
+ begin
+ match r.range_next with
+ None -> ()
+ | Some rrr ->
+(* lprintf "Another one ??\n"; *)
+ rrr.range_prev <- Some rr;
+ end;
+ r.range_next <- Some rr;
+ r.range_end <- next_range;
+(* lprintf " NEW RANGE: %Ld- OLD RANGE: %Ld-%Ld\n"
+ rr.range_begin r.range_begin r.range_end; *)
+
+ split_range rr range_size
+
+
+(*************************************************************************)
+(* *)
+(* new_block (internal) *)
+(* *)
+(*************************************************************************)
+
+let new_block s i =
+ let block_begin = compute_block_begin s i in
+ let block_end = compute_block_end s i in
+ let rec b = {
+ block_s = s;
+
+ block_begin = block_begin;
+ block_end = block_end;
+ block_ranges = range;
+ block_num = i;
+ block_remaining = block_end -- block_begin;
+ }
+
+ and range = {
+ range_prev = None;
+ range_next = None;
+ range_begin = block_begin;
+ range_end = block_end;
+ range_block = b;
+ range_nuploading = 0;
+ range_current_begin = block_begin;
+ }
+ in
+
+(* lprintf "New block %Ld-%Ld\n" block_begin block_end; *)
+ split_range range s.s_range_size;
+
+(*
+ let rec iter r =
+ lprintf " Range %Ld-%Ld\n" r.range_begin r.range_end;
+ match r.range_next with
+ None -> ()
+ | Some r -> iter r
+ in
+ iter b.block_ranges;
+*)
+
+ s.s_blocks.(i) <- PartialBlock b;
+ if s.s_verified_bitmap.[i] < '1' then
+ set_bitmap_1 s i;
+ if debug_all then lprintf_nl () "NB[%s]" s.s_verified_bitmap;
+ b
+
+
+(*************************************************************************)
+(* *)
+(* next_range (internal) *)
+(* *)
+(*************************************************************************)
+
+(*
+let next_range f r =
+ match r.range_next with
+ None -> ()
+ | Some rr -> f rr
+ *)
+
+
+(*************************************************************************)
+(* *)
+(* add_all_downloaded *)
+(* *)
+(*************************************************************************)
+
+(*
+let add_all_downloaded t old_downloaded =
+ let new_downloaded = t.t_downloaded in
+ if new_downloaded <> old_downloaded then
+ add_file_downloaded t.t_file (new_downloaded -- old_downloaded)
+ *)
+
+(*************************************************************************)
+(* *)
+(* range_received (internal) *)
+(* *)
+(*************************************************************************)
+
+let range_received maybe_t r chunk_begin chunk_end =
+(* lprintf " range_received: %Ld-%Ld for %Ld-%Ld\n"
+ chunk_begin chunk_end r.range_begin r.range_end; *)
+ if r.range_begin < chunk_end && r.range_end > chunk_begin then begin
+
+(* lprintf "... entered\n"; *)
+ let new_current_begin =
+ max (min chunk_end r.range_end) r.range_current_begin in
+ let downloaded = new_current_begin -- r.range_current_begin in
+ let b = r.range_block in
+ let s = b.block_s in
+ add_file_downloaded maybe_t s downloaded;
+ b.block_remaining <- b.block_remaining -- downloaded;
+ r.range_current_begin <- new_current_begin;
+ if r.range_current_begin = r.range_end then begin
+ (match r.range_next with
+ None -> ()
+ | Some rr -> rr.range_prev <- r.range_prev);
+ (match r.range_prev with
+ None ->
+ begin
+ match r.range_next with
+ None ->
+ begin
+ match s.s_blocks.(b.block_num) with
+ PartialBlock _ | EmptyBlock ->
+
+ begin
+ match s.s_networks with
+ [] -> assert false
+ | t :: _ when t.t_primary ->
+ begin
+ match t.t_verifier with
+ NoVerification ->
+ set_verified_block s b.block_num
+ | _ ->
+ set_completed_block (Some t) s
b.block_num;
+ must_verify_block s b.block_num false
+ end
+ | _ -> ()
+ end
+ | _ -> ()
+ end
+ | Some rr -> b.block_ranges <- rr
+ end;
+ | Some rr -> rr.range_next <- r.range_next);
+ r.range_next <- None;
+ r.range_prev <- None;
+ end (* else begin
+ lprintf " ... new range %Ld-%Ld\n" r.range_current_begin r.range_end;
+ end *)
+ end
+
+
+(*************************************************************************)
+(* *)
+(* set_present_block (internal) *)
+(* *)
+(*************************************************************************)
+
+(* Assumption: we never download ranges from the middle, so present chunks
+ can only overlap the beginning of a range *)
+let set_present_block b chunk_begin chunk_end =
+ let rec iter r =
+ let range_next = r.range_next in
+(* lprintf "iter range %Ld-%Ld\n" r.range_begin r.range_end; *)
+ (try range_received None r chunk_begin chunk_end
+ with e ->
+ lprintf_nl () "EXCEPTION IN range_received: %s"
+ (Printexc2.to_string e);
+ exit 2);
+ match range_next with
+ None -> ()
+ | Some rr ->
+ iter rr
+ in
+(* lprintf "BEFORE: "; print_block b; *)
+ iter b.block_ranges;
+(* lprintf "AFTER: "; print_block b *)
+ ()
+
+
+(*************************************************************************)
+(* *)
+(* set_present *)
+(* *)
+(*************************************************************************)
+
+let set_present s chunks =
+
+ apply_intervals s (fun i block_begin block_end chunk_begin chunk_end ->
+(* lprintf "interval: %Ld-%Ld in block %d [%Ld-%Ld]\n"
+ chunk_begin chunk_end i block_begin block_end; *)
+ match s.s_blocks.(i) with
+ EmptyBlock ->
+(* lprintf " EmptyBlock"; *)
+ if block_begin >= chunk_begin && block_end <= chunk_end then
+ begin
+(* lprintf " --> CompleteBlock\n"; *)
+ s.s_blocks.(i) <- CompleteBlock;
+ must_verify_block s i false;
+ add_file_downloaded None s (block_end -- block_begin)
+ end
+ else
+ let b = new_block s i in
+(* lprintf " ... set_present_block\n"; *)
+ set_present_block b chunk_begin chunk_end
+ | PartialBlock b ->
+(* lprintf " PartialBlock\n"; *)
+ set_present_block b chunk_begin chunk_end
+ | _ ->
+(* lprintf " Other\n"; *)
+ ()
+ ) chunks
+
+(*************************************************************************)
+(* *)
+(* end_present (internal) *)
+(* *)
+(*************************************************************************)
+
+let rec end_present present begin_present end_file list =
+ match list with
+ [] ->
+ let present =
+ if begin_present = end_file then present else
+ (begin_present, end_file) :: present
+ in
+ List.rev present
+ | (begin_absent, end_absent) :: tail ->
+ let present =
+ if begin_present = begin_absent then present
+ else (begin_present, begin_absent) :: present
+ in
+ end_present present end_absent end_file tail
+
+(*************************************************************************)
+(* *)
+(* set_absent *)
+(* *)
+(*************************************************************************)
+
+let set_absent s list =
+(* reverse absent/present in the list and call set_present *)
+ let list =
+ match list with [] -> [ Int64.zero, s.s_size ]
+ | (t1,t2) :: tail ->
+ if t1 = zero then
+ end_present [] t2 s.s_size tail
+ else
+ end_present [zero, t1] t2 s.s_size tail
+ in
+ set_present s list
+
+(*************************************************************************)
+(* *)
+(* chunks_to_string (internal) *)
+(* *)
+(*************************************************************************)
+
+let chunks_to_string s chunks =
+ match chunks with
+ AvailableRanges chunks ->
+ begin
+ let st = String.make (Array.length s.s_blocks) '0' in
+ apply_intervals s (fun i block_begin block_end chunk_begin chunk_end
-> st.[i] <- '1') chunks;
+ st
+ end
+ | AvailableCharBitmap st -> st
+ | AvailableBitv b -> Bitv.to_string b
+
+(*************************************************************************)
+(* *)
+(* update_uploader_chunks (internal) *)
+(* *)
+(*************************************************************************)
+
+let update_uploader_chunks up chunks =
+ if not up.up_declared then
+ let t = up.up_t in
+ let s = t.t_s in
+(* INVARIANT: complete_blocks must be in reverse order *)
+
+ let complete_blocks = ref [] in
+ let partial_blocks = ref [] in
+
+ begin
+ match chunks with
+ AvailableRanges chunks ->
+
+ apply_intervals s (fun i block_begin block_end
+ chunk_begin chunk_end ->
+(* lprintf "apply_intervals %d %Ld-%Ld %Ld-%Ld\n"
+ i block_begin block_end chunk_begin chunk_end; *)
+ s.s_availability.(i) <- s.s_availability.(i) + 1;
+
+ match s.s_blocks.(i) with
+ CompleteBlock | VerifiedBlock -> ()
+ | _ ->
+ if block_begin = chunk_begin && block_end = chunk_end then
+ complete_blocks := i :: !complete_blocks
+ else
+ partial_blocks :=
+ (i, chunk_begin, chunk_end) :: !partial_blocks
+ ) chunks;
+
+ | AvailableCharBitmap string ->
+ for i = 0 to String.length string - 1 do
+ if string.[i] = '1' then
+ List.iter (fun i ->
+ s.s_availability.(i) <- s.s_availability.(i) + 1;
+ complete_blocks := i :: !complete_blocks
+ ) t.t_t2s_blocks.(i)
+ done;
+ | AvailableBitv bitmap ->
+ for i = 0 to Bitv.length bitmap - 1 do
+ if Bitv.get bitmap i then
+ List.iter (fun i ->
+ s.s_availability.(i) <- s.s_availability.(i) + 1;
+ complete_blocks := i :: !complete_blocks
+ ) t.t_t2s_blocks.(i)
+ done;
+ end;
+
+ List.iter (fun i ->
+(* s.s_last_seen.(i) <- BasicSocket.last_time (); *)
+
+ let i = t.t_s2t_blocks.(i) in
+ t.t_last_seen.(i) <- BasicSocket.last_time ()
+
+ ) !complete_blocks;
+
+ let complete_blocks = Array.of_list !complete_blocks in
+ let partial_blocks = Array.of_list !partial_blocks in
+ up.up_chunks <- chunks;
+
+ up.up_complete_blocks <- complete_blocks;
+ up.up_ncomplete <- Array.length complete_blocks;
+
+ if Array.length partial_blocks > 0 then
+ lprintf_nl () "WARNING: partial_blocks = %d" (Array.length
partial_blocks);
+ up.up_partial_blocks <- partial_blocks;
+ up.up_npartial <- Array.length partial_blocks;
+
+ up.up_block <- None;
+ up.up_block_begin <- zero;
+ up.up_block_end <- zero;
+
+ up.up_declared <- true;
+
+ let bm = chunks_to_string s chunks in
+ client_has_bitmap up.up_client up.up_t.t_file bm;
+
+ if debug_all then print_uploader up
+
+(*************************************************************************)
+(* *)
+(* clean_uploader_chunks (internal) *)
+(* *)
+(*************************************************************************)
+
+
+let clean_uploader_chunks up =
+
+ if up.up_declared then
+
+ let decr_availability s i =
+ s.s_availability.(i) <- s.s_availability.(i) - 1
+ in
+(* lprintf "clean_uploader_chunks:\n"; *)
+
+ let t = up.up_t in
+ let s = t.t_s in
+ for i = 0 to Array.length up.up_complete_blocks - 1 do
+(* lprintf "decr_availability complete[%d] %d\n" i
+ up.up_complete_blocks.(i); *)
+ decr_availability s up.up_complete_blocks.(i)
+ done;
+ for i = 0 to Array.length up.up_partial_blocks - 1 do
+ let b,_,_ = up.up_partial_blocks.(i) in
+(* lprintf "decr_availability partial[%d] %d\n" i b; *)
+ decr_availability s b
+ done;
+ clear_uploader_block up;
+ up.up_declared <- false
+
+(*************************************************************************)
+(* *)
+(* register_uploader *)
+(* *)
+(*************************************************************************)
+
+let register_uploader t client chunks =
+
+ let up =
+ {
+ up_t = t;
+ up_client = client;
+
+ up_declared = false;
+ up_chunks = chunks;
+
+ up_complete_blocks = [||];
+ up_ncomplete = 0;
+
+ up_partial_blocks = [||];
+ up_npartial = 0;
+
+ up_block = None;
+ up_block_begin = zero;
+ up_block_end = zero;
+ up_ranges = [];
+ }
+ in
+ HU.add uploaders_by_num up;
+ update_uploader_chunks up chunks;
+ up
+
+(*************************************************************************)
+(* *)
+(* unregister_uploader *)
+(* *)
+(*************************************************************************)
+
+let unregister_uploader up =
+ clean_uploader_chunks up;
+ clear_uploader_block up;
+ clear_uploader_ranges up
+
+(*************************************************************************)
+(* *)
+(* update_uploader *)
+(* *)
+(*************************************************************************)
+
+let update_uploader up chunks =
+
+ clean_uploader_chunks up;
+ update_uploader_chunks up chunks
+
+(*************************************************************************)
+(* *)
+(* print_uploaders *)
+(* *)
+(*************************************************************************)
+
+let print_uploaders s =
+ let nblocks = Array.length s.s_blocks in
+ for i = 0 to nblocks - 1 do
+
+ match s.s_blocks.(i) with
+ EmptyBlock -> lprintf "_"
+ | CompleteBlock -> lprintf "C"
+ | VerifiedBlock -> lprintf "V"
+ | PartialBlock b ->
+ if s.s_nuploading.(i) > 9 then
+ lprintf "X"
+ else
+ lprintf "%d" s.s_nuploading.(i)
+ done;
+ lprint_newline ();
+ for i = 0 to nblocks - 1 do
+
+ match s.s_blocks.(i) with
+ EmptyBlock -> lprintf "_"
+ | CompleteBlock -> lprintf "C"
+ | VerifiedBlock -> lprintf "V"
+ | PartialBlock b ->
+ lprintf "{ %d : %d=" b.block_num
+ s.s_nuploading.(b.block_num);
+
+ let rec iter_range r =
+ lprintf "(%d)" r.range_nuploading;
+ match r.range_next with
+ None -> ()
+ | Some rr -> iter_range rr
+ in
+ iter_range b.block_ranges;
+ lprintf " }";
+
+ done;
+ lprint_newline ()
+
+(*************************************************************************)
+(* *)
+(* permute_and_return (internal) *)
+(* *)
+(*************************************************************************)
+
+let permute_and_return up n =
+ let b = up.up_complete_blocks.(n) in
+ if debug_all then lprintf "permute_and_return %d <> %d" n b;
+ up.up_complete_blocks.(n) <- up.up_complete_blocks.(up.up_ncomplete-1);
+ up.up_complete_blocks.(up.up_ncomplete-1) <- b;
+ up.up_ncomplete <- up.up_ncomplete - 1;
+ let t = up.up_t in
+ let s = t.t_s in
+ match s.s_blocks.(b) with
+ EmptyBlock ->
+ let b = new_block s b in
+ b, b.block_begin, b.block_end
+ | PartialBlock b ->
+ b, b.block_begin, b.block_end
+ | VerifiedBlock ->
+ lprintf_nl () "ERROR: verified block in permute_and_return %d\n" b;
+ assert false
+ | CompleteBlock ->
+ lprintf_nl () "ERROR: complete block in permute_and_return %d\n" b;
+ assert false
+
+(*************************************************************************)
+(* *)
+(* LinearStrategy.select_block (internal) *)
+(* *)
+(*************************************************************************)
+
+module LinearStrategy = struct
+ let select_block up =
+ let rec iter_complete up =
+ let n = up.up_ncomplete in
+ if n = 0 then iter_partial up
+ else
+ let b = up.up_complete_blocks.(n-1) in
+ up.up_ncomplete <- n-1;
+ let t = up.up_t in
+ let s = t.t_s in
+ match s.s_blocks.(b) with
+ CompleteBlock | VerifiedBlock ->
+ iter_complete up
+ | PartialBlock b ->
+ b, b.block_begin, b.block_end
+ | EmptyBlock ->
+ let b = new_block s b in
+ b, b.block_begin, b.block_end
+
+ and iter_partial up =
+ let n = up.up_npartial in
+ if n = 0 then raise Not_found;
+ let b, block_begin, block_end = up.up_partial_blocks.(n-1) in
+ let t = up.up_t in
+ let s = t.t_s in
+ match s.s_blocks.(b) with
+ CompleteBlock | VerifiedBlock ->
+ iter_partial up
+ | PartialBlock b ->
+ b, block_begin, block_end
+ | EmptyBlock ->
+ let b = new_block s b in
+ b, block_begin, block_end
+ in
+ iter_complete up
+ end
+
+(*************************************************************************)
+(* *)
+(* should_download_block (internal) *)
+(* *)
+(*************************************************************************)
+
+let should_download_block s n =
+(* lprintf "should_download_block %d\n" n; *)
+ let result =
+ match s.s_verified_bitmap.[n] with
+ '2' ->
+ begin
+ match s.s_networks with
+ [] -> assert false
+ | t :: _ when t.t_primary ->
+ begin
+ try
+ let n = t.t_s2t_blocks.(n) in
+ if t.t_converted_verified_bitmap.[n] = '2' then
+ verify_chunk t n
+ with VerifierNotReady -> ()
+ end
+ | _ -> ()
+ end;
+ s.s_verified_bitmap.[n] < '2'
+ | '0' | '1' -> true
+ | _ -> false
+ in
+(* if result then
+ lprintf "should_download_block %d\n" n; *)
+ result
+
+(*************************************************************************)
+(* *)
+(* select_block (internal) *)
+(* *)
+(*************************************************************************)
+
+exception BlockFound of int
+
+let random_int max =
+ let x = Random.int max in
+ if debug_all then lprintf_nl () "(Random %d -> %d)" max x;
+ x
+
+let select_block up =
+ let t = up.up_t in
+ let s = t.t_s in
+ try
+ match s.s_strategy with
+ LinearStrategy ->
+ LinearStrategy.select_block up
+ | _ ->
+ if up.up_ncomplete = 0 && up.up_npartial = 0 then raise Not_found;
+
+(**************
+
+This strategy sucks. It has to be improved.
+Important:
+1) never give a block to 2 clients if another one has 0 client.
+2) try to complete partial blocks as soon as possible.
+3) comfigure the chooser depending on the network (maybe BT might
+better work at the beginning if the first incomplete blocks are offered
+ to several clients.
+
+***************)
+
+
+
+ if up.up_ncomplete > 1 then begin
+(* let debug_all = true in *)
+ try
+
+ let rec iter_max_uploaders max_nuploaders =
+ let t = up.up_t in
+ let nblocks = Array.length s.s_blocks in
+
+(************* Try to download the movie index and the first minute to
+ allow preview of the file as soon as possible *)
+
+ if debug_all then lprintf_nl () "{First}";
+
+ let download_first n b =
+(* lprintf "download_first %d\n" n; *)
+ if
+ up.up_complete_blocks.(n) = b &&
+ s.s_nuploading.(b) < max_nuploaders &&
+ should_download_block s b then
+ raise (BlockFound n)
+ in
+
+(* lprintf "up_complete_blocks: %d\n"
+ (Array.length up.up_complete_blocks); *)
+
+(* This must be the position of the last block of the file *)
+ download_first 0 (nblocks-1);
+
+(* This can be the position of the first block of the file *)
+ download_first (up.up_ncomplete-1) 0;
+
+(* This can be the position of the first block of the file *)
+ download_first 0 0;
+
+(* This must be the position of the second last block of the file *)
+ download_first 0 (nblocks-2);
+
+(* These can be the positions of the second block of the file *)
+ download_first 0 1;
+ download_first (up.up_ncomplete-1) 1;
+ download_first (up.up_ncomplete-2) 1;
+
+(************* If the file can be verified, and we don't have a lot of blocks
+ yet, try to download the partial ones as soon as possible *)
+
+ if debug_all then lprintf_nl () "{PartialBlock}";
+
+ let download_partial max_uploaders =
+ let partial_block = ref (-1) in
+ let partial_remaining = ref zero in
+ for i = 0 to up.up_ncomplete - 1 do
+ let n = up.up_complete_blocks.(i) in
+ match s.s_blocks.(n) with
+ PartialBlock b ->
+ if (!partial_block = -1 ||
+ !partial_remaining > b.block_remaining) &&
+ s.s_nuploading.(n) < max_uploaders
+ then
+ begin
+ partial_block := i;
+ partial_remaining := b.block_remaining
+ end
+ | _ -> ()
+ done;
+ if !partial_block <> -1 then
+ raise (BlockFound !partial_block)
+ in
+
+ if t.t_verifier <> NoVerification &&
+ t.t_nverified_blocks < 2 then begin
+ download_partial max_nuploaders;
+ end;
+
+(************* Download partial chunks from the verification point of view *)
+
+ if List.length s.s_networks > 1 then begin
+ if debug_all then lprintf_n () "{PartialChunk}";
+
+ let my_t = if t.t_verifier <> NoVerification then t
+ else match s.s_networks with t :: _ -> t | _ -> t in
+
+ let download_partial max_uploaders =
+ let partial_block = ref (-1) in
+ let partial_remaining = ref 0 in
+ for i = 0 to up.up_ncomplete - 1 do
+ let n = up.up_complete_blocks.(i) in
+(* TODO move this after the first if... *)
+ let t_index = t.t_s2t_blocks.(n) in
+ let bs = List.filter (fun s_index ->
+ s.s_verified_bitmap.[s_index] = '2'
+ ) t.t_t2s_blocks.(t_index) in
+ let nbs = List.length bs in
+
+(* TODO remove this *)
+ let b = should_download_block s n in
+
+ if !verbose_swarming then
+ lprintf_nl2 " test %d %c %d %b %d"
+ n s.s_verified_bitmap.[n] s.s_nuploading.(n)
+ b nbs;
+
+ if s.s_verified_bitmap.[n] < '2' &&
+ s.s_nuploading.(n) < max_uploaders &&
+ should_download_block s n then
+
+ if (!partial_block = -1 || !partial_remaining < nbs)
+ then
+ begin
+ partial_block := i;
+ partial_remaining := nbs
+ end
+ done;
+ if !partial_block <> -1 then begin
+ if !verbose_swarming then
+ lprintf_n () "PartialChunk won for %d waiting
blocks"
+ !partial_remaining;
+ raise (BlockFound !partial_block)
+ end
+ in
+
+ if my_t.t_verifier <> NoVerification then begin
+ download_partial max_nuploaders;
+ end;
+ end;
+
+(************* Download rarest first only if other blocks are much more
+ available *)
+
+ if debug_all then lprintf "{Rarest}";
+
+ let sum_availability = ref 0 in
+ let min_availability = ref max_int in
+ for i = 0 to up.up_ncomplete - 1 do
+ let n = up.up_complete_blocks.(i) in
+ sum_availability := !sum_availability +
+ s.s_availability.(n);
+ min_availability := min !min_availability
+ s.s_availability.(n);
+ done;
+
+ let mean_availability =
+ !sum_availability / up.up_ncomplete in
+
+ if mean_availability > 5 && !min_availability < 3 then
+ for i = 0 to up.up_ncomplete - 1 do
+ let n = up.up_complete_blocks.(i) in
+ if s.s_availability.(n) < 3
+ && should_download_block s n
+ then
+ raise (BlockFound i)
+ done;
+
+(************* Otherwise, download in random order *)
+
+ if debug_all then lprintf "{Random}";
+ let find_random max_uploaders =
+ let list = ref [] in
+ if debug_all then lprintf " {NC: %d}" up.up_ncomplete;
+ for i = 0 to up.up_ncomplete - 1 do
+ let n = up.up_complete_blocks.(i) in
+ if s.s_nuploading.(n) < max_uploaders
+ && should_download_block s n
+ then
+ list := i :: !list
+ done;
+ match !list with
+ [] -> ()
+ | [i] -> raise (BlockFound i)
+ | list ->
+ let array = Array.of_list list in
+ raise (BlockFound (array.(
+ random_int (Array.length array))))
+ in
+
+ find_random max_nuploaders
+
+(************* Fall back on linear download if nothing worked *)
+
+ in
+ iter_max_uploaders !!sources_per_chunk;
+ iter_max_uploaders max_int;
+ raise Not_found
+ with
+ BlockFound n ->
+ if debug_all then lprintf "\nBlockFound %d\n"
+ up.up_complete_blocks.(n);
+ permute_and_return up n
+ end else
+ LinearStrategy.select_block up
+ with Not_found ->
+
+ (* print_s "NO BLOCK FOUND" s; *)
+ raise Not_found
+
+(*************************************************************************)
+(* *)
+(* find_block *)
+(* *)
+(*************************************************************************)
+
+let find_block up =
+ try
+ if debug_all then begin
+ lprintf "C: ";
+ for i = 0 to up.up_ncomplete - 1 do
+ lprintf "%d " up.up_complete_blocks.(i)
+ done;
+ end;
+
+ let t = up.up_t in
+ let s = t.t_s in
+ match file_state t.t_file with
+ | FilePaused
+ | FileAborted _
+ | FileCancelled -> raise Not_found
+ | _ ->
+
+
+ (match up.up_block with
+ None -> ()
+ | Some b ->
+ let num = b.block_num in
+ s.s_nuploading.(num) <- s.s_nuploading.(num) - 1;
+ up.up_block <- None;
+ );
+
+ let (b,block_begin,block_end) (* as result *) = select_block up in
+ let num = b.block_num in
+ s.s_nuploading.(num) <- s.s_nuploading.(num) + 1;
+ up.up_block <- Some b;
+ up.up_block_begin <- block_begin;
+ up.up_block_end <- block_end;
+ if debug_all then lprintf " = %d \n" num;
+ b
+ with e ->
+ if debug_all then lprintf_nl () "Exception %s" (Printexc2.to_string e);
+ raise e
+
+(*************************************************************************)
+(* *)
+(* clean_ranges (internal) *)
+(* *)
+(*************************************************************************)
+
+let clean_ranges up =
+
+ let rec iter list left =
+ match list with
+ [] -> List.rev left
+ | ((_,_,r) as rr) :: tail ->
+ iter tail
+ (if r.range_current_begin < r.range_end then rr :: left
+ else begin
+ r.range_nuploading <- r.range_nuploading - 1;
+ left
+ end)
+ in
+ up.up_ranges <- iter up.up_ranges []
+
+(*************************************************************************)
+(* *)
+(* current_ranges *)
+(* *)
+(*************************************************************************)
+
+let current_ranges up = up.up_ranges
+
+(*************************************************************************)
+(* *)
+(* current_block *)
+(* *)
+(*************************************************************************)
+
+let current_block up =
+ match up.up_block with
+ None -> raise Not_found
+ | Some b -> b
+
+(*************************************************************************)
+(* *)
+(* in_uploader_ranges *)
+(* *)
+(*************************************************************************)
+
+let rec in_uploader_ranges r list =
+ match list with
+ [] -> false
+ | (_,_,r') :: tail when r' == r -> true
+ | _ :: tail -> in_uploader_ranges r tail
+
+(*************************************************************************)
+(* *)
+(* find_range *)
+(* *)
+(*************************************************************************)
+
+let find_range up =
+ clean_ranges up;
+
+ let b =
+ match up.up_block with
+ None -> raise Not_found
+ | Some b -> b
+ in
+ let r = b.block_ranges in
+
+ let t = up.up_t in
+
+ match file_state t.t_file with
+ | FilePaused
+ | FileAborted _
+ | FileCancelled -> raise Not_found
+ | _ ->
+
+ let rec iter limit r =
+
+(* let use a very stupid heuristics: ask for the first non-used range.
+we thus might put a lot of clients on the same range !
+*)
+
+ if not (in_uploader_ranges r up.up_ranges) &&
+ r.range_current_begin < r.range_end &&
+ r.range_current_begin >= up.up_block_begin &&
+ r.range_end <= up.up_block_end &&
+ r.range_nuploading < limit
+ then begin
+ let key = r.range_current_begin, r.range_end, r in
+ up.up_ranges <- up.up_ranges @ [key];
+ r.range_nuploading <- r.range_nuploading + 1;
+ if r.range_current_begin = r.range_end then
+ lprintf_nl () "error: range is empty error";
+ key
+ end else
+ match r.range_next with
+ None -> raise Not_found
+ | Some rr -> iter limit rr
+ in
+ try
+(* try normal ranges *)
+ iter !!sources_per_chunk r
+ with Not_found ->
+(* force maximal uploading otherwise to finish it *)
+ iter max_int r
+
+(*************************************************************************)
+(* *)
+(* range_range *)
+(* *)
+(*************************************************************************)
+
+let range_range r = (r.range_current_begin, r.range_end)
+
+(*************************************************************************)
+(* *)
+(* received *)
+(* *)
+(*************************************************************************)
+
+let received (up : uploader) (file_begin : Int64.t)
+ (str:string) (string_begin:int) (string_len:int) =
+
+ if string_len > 0 then
+ let file_end = file_begin ++ (Int64.of_int string_len) in
+
+ if !verbose_swarming then
+ lprintf_nl () "received on %Ld-%Ld" file_begin file_end;
+
+(* TODO: check that everything we received has been required *)
+ let t = up.up_t in
+ let s = t.t_s in
+ try
+
+ List.iter (fun (_,_,r) ->
+ if r.range_current_begin < file_end &&
+ r.range_end > file_begin then begin
+
+ let file_end = min file_end r.range_end in
+ let written_len = file_end -- r.range_current_begin in
+
+ begin
+ match file_state t.t_file with
+ | FilePaused
+ | FileAborted _
+ | FileCancelled -> ()
+ | _ ->
+
+ let string_pos = string_begin +
+ Int64.to_int (r.range_current_begin -- file_begin) in
+ let string_length = Int64.to_int written_len in
+
+ if
+ string_pos < 0 ||
+ string_pos < string_begin ||
+ string_len < string_length then begin
+ if !verbose then
+ begin
+ lprintf_nl () "BAD WRITE in %s for range %Ld-%Ld
(string_pos %d)"
+ (file_best_name t.t_file) r.range_begin r.range_end
string_pos;
+ lprintf_nl () " received: file_pos:%Ld string:%d %d"
+ file_begin string_begin string_len;
+ lprintf_nl () " ranges:";
+ List.iter (fun (_,_,r) ->
+ lprintf_n () " range: %Ld-[%Ld]-%Ld"
+ r.range_begin r.range_current_begin
+ r.range_end;
+ (match r.range_next with
+ None -> ()
+ | Some rr ->
+ lprintf " next: %Ld" rr.range_begin);
+ (match r.range_prev with
+ None -> ()
+ | Some rr ->
+ lprintf " prev: %Ld" rr.range_begin);
+ lprint_newline ();
+ let b = r.range_block in
+ lprintf_n () " block: %d[%c] %Ld-%Ld [%s]"
+ b.block_num
+ s.s_verified_bitmap.[b.block_num]
+ b.block_begin b.block_end
+ (match s.s_blocks.(b.block_num) with
+ EmptyBlock -> "empty"
+ | PartialBlock _ -> "partial"
+ | CompleteBlock -> "complete"
+ | VerifiedBlock -> "verified"
+ );
+ let br = b.block_ranges in
+ lprintf " first range: %Ld(%Ld)"
+ br.range_begin
+ (br.range_end -- br.range_current_begin);
+ lprint_newline ();
+ ) up.up_ranges;
+ end;
+ if !exit_on_error then exit 2
+ end else
+ if string_length > 0 then
+ match s.s_networks with
+ [] -> assert false
+ | t :: _ when t.t_primary ->
+ file_write t.t_file
+ r.range_current_begin
+ str string_pos string_length;
+ | _ -> ()
+ end;
+ range_received (Some t) r r.range_current_begin file_end;
+
+ end
+ ) up.up_ranges;
+ clean_ranges up
+ with e ->
+ raise e
+
+
+(*************************************************************************)
+(* *)
+(* present_chunks *)
+(* *)
+(*************************************************************************)
+
+let present_chunks s =
+ let nblocks = Array.length s.s_blocks in
+(* lprintf "present_chunks...%d blocks\n" nblocks; *)
+
+ let rec iter_block_out i block_begin list =
+ if debug_present_chunks then
+ lprintf_nl () "iter_block_out %d bb: %Ld"
+ i block_begin;
+
+ if i = nblocks then List.rev list else
+ let block_end = compute_block_end s i in
+ match s.s_blocks.(i) with
+ EmptyBlock ->
+ iter_block_out (i+1) block_end list
+ | CompleteBlock | VerifiedBlock ->
+ let block_begin = compute_block_begin s i in
+ iter_block_in (i+1) block_end block_begin list
+ | PartialBlock b ->
+ iter_range_out i block_end block_begin b.block_ranges list
+
+ and iter_block_in i block_begin chunk_begin list =
+ if debug_present_chunks then
+ lprintf_nl () "iter_block_in %d bb: %Ld cb:%Ld"
+ i block_begin chunk_begin
+ ;
+
+ if i = nblocks then
+ let list = (chunk_begin, s.s_size) :: list in
+ List.rev list
+ else
+ let block_end = compute_block_end s i in
+ match s.s_blocks.(i) with
+ EmptyBlock ->
+ iter_block_out (i+1) block_end ( (chunk_begin, block_begin) :: list)
+ | CompleteBlock | VerifiedBlock ->
+ iter_block_in (i+1) block_end chunk_begin list
+ | PartialBlock b ->
+ iter_range_in i block_end
+ chunk_begin block_begin b.block_ranges list
+
+ and iter_range_out i block_end block_begin r list =
+ if debug_present_chunks then
+ lprintf_nl () "iter_range_out %d nb: %Ld bb:%Ld"
+ i block_end block_begin;
+
+ if r.range_begin > block_begin then
+ iter_range_in i block_end block_begin r.range_begin r list
+ else
+
+ if r.range_current_begin > block_begin then begin
+ if r.range_current_begin < r.range_end then
+ let list = (r.range_begin, r.range_current_begin) :: list in
+ match r.range_next with
+ None ->
+ iter_block_out (i+1) block_end list
+ | Some rr ->
+ iter_range_out i block_end r.range_end rr list
+ else
+ match r.range_next with
+ None ->
+ iter_block_in (i+1) block_end r.range_begin list
+ | Some rr ->
+ iter_range_in i block_end
+ r.range_begin r.range_end rr list
+ end else
+ match r.range_next with
+ None ->
+ iter_block_out (i+1) block_end list
+ | Some rr ->
+ iter_range_out i block_end r.range_end rr list
+
+
+ and iter_range_in i block_end chunk_begin chunk_end r list =
+ if debug_present_chunks then
+ lprintf_nl () "iter_range_in %d bn: %Ld cb:%Ld ce: %Ld"
+ i block_end chunk_begin chunk_end;
+
+ if r.range_current_begin < r.range_end then
+ let list = (chunk_begin, r.range_current_begin) :: list in
+ match r.range_next with
+ None ->
+ iter_block_out (i+1) block_end list
+ | Some rr ->
+ iter_range_out i block_end r.range_end rr list
+ else
+ match r.range_next with
+ None ->
+ iter_block_in (i+1) block_end chunk_begin list
+ | Some rr ->
+ iter_range_in i block_end chunk_begin r.range_end rr list
+ in
+ let chunks = iter_block_out 0 zero [] in
+(* lprintf "present_chunks done\n"; *)
+ chunks
+
+(*************************************************************************)
+(* *)
+(* propagate_chunk *)
+(* *)
+(*************************************************************************)
+
+let propagate_chunk t1 ts pos1 size =
+
+ (*
+ List.iter (fun (t2, i2, pos2) ->
+ lprintf "Should propagate chunk from %s %Ld to %s %Ld [%Ld]\n"
+ (file_best_name t1.t_file) pos1
+ (file_best_name t2.t_file) pos2 size;
+ Unix32.copy_chunk (file_fd t1.t_file) (file_fd t2.t_file)
+ pos1 pos2 (Int64.to_int size);
+
+ set_toverify_block t2 i2;
+ set_verified_block t2 i2;
+ ) ts
+*)
+ ()
+
+(*************************************************************************)
+(* *)
+(* duplicate_chunks *)
+(* *)
+(*************************************************************************)
+
+(* This is the least aggressive version. I was thinking of computing
+checksums for all possible schemas for all files, to be able to
+move chunks from/to BT files from/to ED2k files. *)
+
+let duplicate_chunks () =
+ (*
+ let chunks = Hashtbl.create 100 in
+ HS.iter (fun t ->
+ let rec iter i len pos bsize size =
+ if i < len then
+ let c = {
+ chunk_uid = t.t_checksums.(i);
+ chunk_size = min (size -- pos) bsize;
+ } in
+ let (has, has_not) = try
+ Hashtbl.find chunks c
+ with _ ->
+ let sw = (ref [], ref []) in
+ Hashtbl.add chunks c sw;
+ sw
+ in
+ let sw = if t.t_verified_bitmap.[i] = '3' then has else has_not in
+ sw := (t, i, pos) :: !sw;
+ iter (i+1) len (pos ++ bsize) bsize size
+ in
+ iter 0 (Array.length t.t_checksums) zero t.t_block_size t.t_size
+ ) swarmers_by_num;
+ Hashtbl.iter (fun c (has, has_not) ->
+ match !has, !has_not with
+ _ , []
+ | [], _ -> ()
+ | (t, _, pos) :: _, ts ->
+ propagate_chunk t ts pos c.chunk_size
+ ) chunks
+*)
+ ()
+
+(*************************************************************************)
+(* *)
+(* set_checksums *)
+(* *)
+(*************************************************************************)
+
+
+(* TODO: where is this used ? check that the fact of using the UID for
+ small files does not create any problem. *)
+let get_checksums t =
+ match t.t_verifier with
+ Verification tab -> tab
+ | _ -> [||]
+
+
+
+(*************************************************************************)
+(* *)
+(* primary (internal) *)
+(* *)
+(*************************************************************************)
+
+let primary t = t.t_primary
+
+(*************************************************************************)
+(* *)
+(* set_verified_bitmap *)
+(* *)
+(*************************************************************************)
+
+let set_verified_bitmap primary t bitmap =
+(* t.t_verified_bitmap <- bitmap; *)
+
+ for i = 0 to String.length bitmap - 1 do
+
+ match bitmap.[i] with
+ | '2' ->
+ if t.t_converted_verified_bitmap.[i] < '2' then begin
+ t.t_ncomplete_blocks <- t.t_ncomplete_blocks + 1;
+ t.t_converted_verified_bitmap.[i] <- '2'
+ end
+
+ | '3' ->
+(* lprintf "Setting 3 on %d\n" i; *)
+ t.t_converted_verified_bitmap.[i] <- '3';
+ if primary then
+ let s = t.t_s in
+ List.iter (fun i ->
+(* lprintf "Should set %d\n" i; *)
+ match s.s_blocks.(i) with
+ CompleteBlock ->
+(* lprintf "CompleteBlock\n"; *)
+ set_verified_block s i
+ | EmptyBlock | PartialBlock _ ->
+(* lprintf "EmptyBlock/PartialBlock\n"; *)
+ set_completed_block None s i;
+(* lprintf "set_verified_block\n"; *)
+ set_verified_block s i
+ | VerifiedBlock ->
+(* lprintf "Block already verified\n" *)
+ ()
+ ) t.t_t2s_blocks.(i);
+ if t.t_converted_verified_bitmap.[i] <> '3' then
+ lprintf_nl () "FIELD AS BEEN CLEARED"
+ | _ -> ()
+ done
+
+(*************************************************************************)
+(* *)
+(* verified_bitmap *)
+(* *)
+(*************************************************************************)
+
+let verified_bitmap t = t.t_converted_verified_bitmap
+
+(*************************************************************************)
+(* *)
+(* set_verifier *)
+(* *)
+(*************************************************************************)
+
+let set_verifier t f =
+ t.t_verifier <- f;
+(* TODO: check that false as primary is a good value to start with *)
+ set_verified_bitmap false t t.t_converted_verified_bitmap
+
+(*************************************************************************)
+(* *)
+(* set_verifier *)
+(* *)
+(*************************************************************************)
+
+let set_verified t f =
+ t.t_verified <- f
+
+(*************************************************************************)
+(* *)
+(* downloaded *)
+(* *)
+(*************************************************************************)
+
+let downloaded t = file_downloaded t.t_file
+
+(*************************************************************************)
+(* *)
+(* block_block *)
+(* *)
+(*************************************************************************)
+
+let block_num t b =
+ let n = t.t_s2t_blocks.(b.block_num) in
+ n
+
+(*************************************************************************)
+(* *)
+(* partition_size *)
+(* *)
+(*************************************************************************)
+
+let partition_size t = String.length t.t_converted_verified_bitmap
+
+let uploader_swarmer up = up.up_t
+
+
+(*************************************************************************)
+(* *)
+(* availability *)
+(* *)
+(*************************************************************************)
+
+let availability t =
+
+ let s = t.t_s in
+ let len = String.length t.t_converted_verified_bitmap in
+ let str = String.make len '\000' in
+ for i = 0 to len - 1 do
+ str.[i] <- char_of_int (
+ let v = List2.min
+ (List.map (fun i -> s.s_availability.(i)) t.t_t2s_blocks.(i)) in
+ if v < 0 then 0 else
+ if v > 200 then 200 else v)
+ done;
+ str
+
+(*************************************************************************)
+(* *)
+(* is_interesting *)
+(* *)
+(*************************************************************************)
+
+(*return true if s is interesting for p1
+ NB: works when s is a mask of 0s(absent bloc) and 1s(present bloc)
+ p1 can be a string 0(absent) 1(partial) 2(present unverified) or
+ 3(present verified)
+ s : 00001111
+ p1 : 01230123
+ is_interesting : 00001110
+*)
+
+let is_interesting up =
+ up.up_ncomplete > 0 || up.up_npartial > 0
+
+
+(*************************************************************************)
+(* *)
+(* value_to_int64_pair (internal) *)
+(* *)
+(*************************************************************************)
+
+let value_to_int64_pair v =
+ match v with
+ List [v1;v2] | SmallList [v1;v2] ->
+ (value_to_int64 v1, value_to_int64 v2)
+ | _ ->
+ failwith "Options: Not an int32 pair"
+
+(*************************************************************************)
+(* *)
+(* WRAPPERS *)
+(* *)
+(*************************************************************************)
+
+let set_present t = set_present t.t_s
+let set_absent t = set_absent t.t_s
+let present_chunks t = present_chunks t.t_s
+let print_t str t = print_s str t.t_s
+let print_uploaders t = print_uploaders t.t_s
+
+(*************************************************************************)
+(* *)
+(* value_to_swarmer *)
+(* *)
+(*************************************************************************)
+
+let value_to_swarmer t assocs =
+ let get_value name conv = conv (List.assoc name assocs) in
+
+
+ let primary =
+ try get_value "file_primary" value_to_bool with _ -> true
+ in
+
+ (try
+ let file_name = get_value "file_swarmer" value_to_string in
+ let s =
+ HS.find swarmers_by_name { dummy_swarmer with s_filename = file_name }
+ in
+ associate primary t s;
+(* TODO: make as many checks as possible to ensure the file and the swarmers
+ are correctly associed. *)
+ with Not_found -> ());
+
+ let _ =
+ let mtime = try file_mtime t.t_file with _ -> 0. in
+ let old_mtime =
+ try
+ value_to_float (List.assoc "file_mtime" assocs)
+ with Not_found -> mtime
+ in
+ old_mtime = mtime
+ in
+(* TODO: if set_bitmap is false, we should the bitmap to 2222222222 so that
+it is verified as soon as possible. *)
+ (try
+ try
+ set_verified_bitmap primary t
+ (get_value "file_chunks" value_to_string)
+ with Not_found ->
+ set_verified_bitmap primary t
+ (get_value "file_all_chunks" value_to_string)
+
+ with e ->
+ lprintf_nl () "Exception %s while loading bitmap"
+ (Printexc2.to_string e);
+ );
+
+ (*
+ lprintf "set_verified_bitmap: t = %s\n" t.t_converted_verified_bitmap;
+ lprintf "set_verified_bitmap: s = %s\n" t.t_s.s_verified_bitmap;
+*)
+
+ if primary then begin
+ if !verbose_swarming then lprintf_nl () "Loading present...";
+ let present = try
+ let present =
+ (get_value "file_present_chunks"
+ (value_to_list value_to_int64_pair))
+ in
+ set_present t present;
+ present
+ with e ->
+ lprintf_nl () "Exception %s while set present"
+ (Printexc2.to_string e);
+ []
+ in
+ if !verbose_swarming then lprintf_nl () "Downloaded after present %Ld"
(downloaded t);
+
+(*
+ if !verbose then lprintf_nl () "Loading absent...";
+ (try
+ set_absent t
+ (get_value "file_absent_chunks"
+ (value_to_list value_to_int64_pair));
+ with e ->
+ if !verbose_hidden_errors then lprintf_nl () "Exception %s while
set absent"
+ (Printexc2.to_string e);
+ );
+ if !verbose then lprintf_nl () "Downloaded after absent %Ld" (downloaded
t);
+*)
+ (try
+ let d = get_value "file_downloaded" value_to_int64 in
+
+ if d <> downloaded t && !verbose then begin
+ lprintf_nl () "ERROR: stored downloaded value not restored !!!
(%Ld/%Ld)" (downloaded t) d;
+ lprintf_nl () "ERROR: present:";
+ List.iter (fun (x,y) ->
+ lprintf_nl () " (%Ld,%Ld);" x y
+ ) present;
+
+ let p = present_chunks t in
+ lprintf_nl () "ERROR: present now:";
+
+ let total = ref zero in
+ List.iter (fun (x,y) ->
+ lprintf_nl () " (%Ld,%Ld);" x y;
+ total := !total ++ (y -- x);
+ ) p;
+
+ lprintf_nl () "ERROR: total %Ld" !total;
+ if p = present then begin
+ lprintf_nl () "ERROR: both appear to be the same!";
+ end;
+ if !exit_on_error then exit 2
+ end
+
+ with e -> ());
+ end;
+
+(* TODO re-implement this
+ (try
+ let last_seen = get_value "file_chunks_age"
+ (value_to_list value_to_int) in
+ t.t_last_seen <- Array.of_list last_seen
+ with _ -> ());
+*)
+
+ ()
+
+(*************************************************************************)
+(* *)
+(* set_verified_bitmap *)
+(* *)
+(*************************************************************************)
+
+let set_verified_bitmap t bitmap =
+ set_verified_bitmap (primary t) t bitmap
+
+(*************************************************************************)
+(* *)
+(* swarmer_to_value *)
+(* *)
+(*************************************************************************)
+
+let swarmer_to_value t other_vals =
+ ("file_primary", bool_to_value (primary t)) ::
+ ("file_swarmer", string_to_value t.t_s.s_filename) ::
+ ("file_mtime", float_to_value (try file_mtime t.t_file with _ -> 0.)) ::
+ ("file_chunks", string_to_value (verified_bitmap t)) ::
+ ("file_present_chunks", List
+ (List.map (fun (i1,i2) ->
+ SmallList [int64_to_value i1; int64_to_value i2])
+ (present_chunks t))) ::
+ ("file_downloaded", int64_to_value (downloaded t)) ::
+
+ ("file_chunks_age", List (Array.to_list
+ (Array.map int_to_value t.t_last_seen))) ::
+
+ other_vals
+
+(*************************************************************************)
+(* *)
+(* verify_one_chunk *)
+(* *)
+(*************************************************************************)
+
+let verify_one_chunk s =
+(* lprintf "verify_one_chunk: %d networks\n" (List.length s.s_networks); *)
+ List.iter (fun t ->
+(* lprintf "verify_one_chunk of file %d\n" (file_num t.t_file); *)
+ let bitmap = t.t_converted_verified_bitmap in
+ for i = 0 to String.length bitmap - 1 do
+ if bitmap.[i] = '2' then begin
+(* lprintf " verifying...\n"; *)
+ verify_chunk t i;
+ raise Exit
+ end
+ done
+ ) s.s_networks;
+(* lprintf "verify_one_chunk: nothing done\n"; *)
+ ()
+
+(*************************************************************************)
+(* *)
+(* verify_some_chunks *)
+(* *)
+(*************************************************************************)
+
+let verify_some_chunks () =
+ HS.iter (fun s ->
+ try
+ verify_one_chunk s
+ with _ -> ()) swarmers_by_name
+
+(*************************************************************************)
+(* *)
+(* verify_one_chunk *)
+(* *)
+(*************************************************************************)
+
+let verify_one_chunk t =
+ verify_one_chunk t.t_s
+
+(*************************************************************************)
+(* *)
+(* merge *)
+(* *)
+(*************************************************************************)
+
+let merge f1 f2 =
+
+ let s1 = HS.find swarmers_by_name { dummy_swarmer with s_filename =
file_disk_name f1 } in
+ let s2 = HS.find swarmers_by_name { dummy_swarmer with s_filename =
file_disk_name f2 } in
+
+ if s1 == s2 then
+ failwith "Files are already sharing their swarmer";
+
+ if s1.s_size <> s2.s_size then
+ failwith "Files don't have the same size";
+
+ let t2 = match s2.s_networks with
+ [t] -> t
+ | list ->
+ lprintf_nl () "s_networks: %d files" (List.length list);
+ failwith "Second file is already merged with other files"
+ in
+
+ let t1 =
+ match s1.s_networks with
+ [] -> assert false
+ | t1 :: _ ->
+ match t1.t_verifier with
+ NoVerification ->
+ failwith "Cannot use first file as a primary for swarming (no
verification scheme)"
+ | _ -> t1
+ in
+
+ begin
+ List.iter (fun (s, filename) ->
+ for i = 0 to Array.length s.s_nuploading - 1 do
+ if s.s_nuploading.(i) > 0 then
+ failwith (Printf.sprintf "%s is currently being downloaded"
filename)
+ done
+ ) [
+ s1, "First file";
+ s2, "Second file" ];
+ end;
+
+(* replace T2 swarmer *)
+ associate false t2 t1.t_s
+
+(*************************************************************************)
+(* *)
+(* has_secondaries *)
+(* *)
+(*************************************************************************)
+
+let has_secondaries t =
+ primary t && List.length t.t_s.s_networks > 1
+
+(*************************************************************************)
+(* *)
+(* Remove swarmer *)
+(* *)
+(*************************************************************************)
+
+let remove_swarmer file_swarmer =
+ match file_swarmer with
+ None -> ()
+ | Some sw -> if not (has_secondaries sw)
+ then HS.remove swarmers_by_name sw.t_s
+ else lprintf_nl () "Tried to remove swarmer with secondaries"
+
+(*************************************************************************)
+(* *)
+(* subfiles *)
+(* *)
+(*************************************************************************)
+
+let subfiles t =
+ List.map (fun t -> t.t_file) t.t_s.s_networks
+
+(*************************************************************************)
+(* *)
+(* SwarmerOption *)
+(* *)
+(*************************************************************************)
+
+module SwarmerOption = struct
+
+ let value_to_swarmer v =
+ match v with
+ Module assocs ->
+ let get_value name conv = conv (List.assoc name assocs) in
+ let file_size = get_value "file_size" value_to_int64 in
+ let file_name = get_value "file_name" value_to_string in
+ let s = create_swarmer file_name file_size edonkey_range_size in
+ let block_sizes = get_value "file_chunk_sizes"
+ (value_to_list value_to_int64) in
+ List.iter (fun bsize ->
+ split_blocks s bsize
+ ) block_sizes;
+ s
+
+ | _ -> assert false
+
+ let swarmer_to_value s =
+ Module [
+ ("file_size", int64_to_value s.s_size);
+ ("file_name", string_to_value s.s_filename);
+ ("file_bitmap", string_to_value s.s_verified_bitmap);
+ ("file_chunk_sizes", list_to_value int64_to_value
+ (List.map (fun t -> t.t_block_size) s.s_networks));
+ ]
+
+ let t =
+ define_option_class "Swarmer" value_to_swarmer swarmer_to_value
+
+ end
+
+(*************************************************************************)
+(* *)
+(* check_swarmer *)
+(* *)
+(*************************************************************************)
+
+let check_swarmer s =
+ try
+ match s.s_networks with
+ [] -> ()
+ | t :: tail ->
+ assert t.t_primary;
+
+ for i = 0 to t.t_nchunks - 1 do
+ List.iter (fun j ->
+ if t.t_converted_verified_bitmap.[i] = '3' then begin
+ if s.s_verified_bitmap.[j] <> '3' then
+ failwith "Bad propagation of 3 from primary to main";
+ end
+ else
+ if s.s_verified_bitmap.[j] = '3' then begin
+ failwith "Main has 3 not coming from primary";
+ end
+ ) t.t_t2s_blocks.(i)
+ done;
+
+ let fd = file_fd t.t_file in
+
+ List.iter (fun t ->
+ assert (not t.t_primary);
+ assert (file_fd t.t_file == fd);
+
+ for i = 0 to t.t_nchunks - 1 do
+ List.iter (fun j ->
+ if t.t_converted_verified_bitmap.[i] = '3' then begin
+ if s.s_verified_bitmap.[j] <> '3' then
+ failwith "3 in secondary without 3 in primary";
+ end
+ else
+ if t.t_converted_verified_bitmap.[i] = '2' then begin
+ if s.s_verified_bitmap.[j] <> '3' then
+ failwith "2 in secondary without 3 in primary";
+ end
+ ) t.t_t2s_blocks.(i)
+ done;
+ ) tail
+ with e ->
+ print_s "ERROR" s;
+ raise e
+
+(*************************************************************************)
+(* *)
+(* Option swarmers *)
+(* *)
+(*************************************************************************)
+
+let swarmers =
+ define_option CommonComplexOptions.swarmers_section
+ ["swarmers"] "All the swarmers used" (list_option SwarmerOption.t) []
+
+(*************************************************************************)
+(* *)
+(* Options hooks *)
+(* *)
+(*************************************************************************)
+
+let _ =
+ set_after_save_hook files_ini (fun _ -> swarmers =:= []);
+ set_before_save_hook files_ini (fun _ ->
+ let list = ref [] in
+ HS.iter (fun s ->
+ if s.s_networks <> [] then
+ list := s :: !list) swarmers_by_name;
+ swarmers =:= !list
+ );
+ set_after_load_hook files_ini (fun _ ->
+ List.iter (fun s ->
+ check_swarmer s;
+ ) !!swarmers;
+
+ swarmers =:= [])
+
+
+(*************************************************************************)
+(* *)
+(* MAIN *)
+(* *)
+(*************************************************************************)
+
+(* Compute an approximation of the storage used by this module *)
+
+let _ =
+ BasicSocket.add_infinite_timer 300. duplicate_chunks;
+ Heap.add_memstat "CommonSwarming" (fun level buf ->
+ let counter = ref 0 in
+ let nchunks = ref 0 in
+ let nblocks = ref 0 in
+ let nranges = ref 0 in
+ HS.iter (fun s ->
+ let n = String.length s.s_verified_bitmap in
+ nchunks := !nchunks + n;
+
+ Array.iter (fun b ->
+ match b with
+ | PartialBlock b ->
+ incr nblocks;
+ iter_block_ranges (fun _ -> incr nranges) b
+ | _ -> ()
+ ) s.s_blocks;
+
+ incr counter
+ ) swarmers_by_name;
+ Printf.bprintf buf " Swarmers: %d\n" !counter;
+ Printf.bprintf buf " nchunks: %d nblocks: %d nranges: %d\n"
+ !nchunks !nblocks !nranges;
+ Printf.bprintf buf " Storage (without blocks): %d bytes\n"
+ ( !counter * 108 +
+ !nchunks * 17 +
+ !nblocks * 64 +
+ !nranges * 84);
+
+ let counter = ref 0 in
+ let storage = ref 0 in
+ HU.iter (fun up ->
+ storage := !storage + 76 +
+ Array.length up.up_complete_blocks * 4 +
+ List.length up.up_ranges * (12 + 16 + 12 + 12 + 4) +
+ Array.length up.up_partial_blocks * (16 + 12 + 12) +
+ (8 + match up.up_chunks with
+ AvailableRanges list -> List.length list * (12 + 12 + 12 + 12)
+ | AvailableCharBitmap s -> 8 + String.length s
+ | AvailableBitv b -> let ws = Sys.word_size in (ws/8) + ((ws / 8)
* (Bitv.length b / (ws - 2)))
+ ) ;
+ incr counter;
+ ) uploaders_by_num;
+ Printf.bprintf buf " Uploaders: %d\n" !counter;
+ Printf.bprintf buf " Storage: %d bytes\n" !storage;
+ )
+
+let check_finished t =
+ try
+ let file = t.t_file in
+ match file_state file with
+ FileCancelled | FileShared | FileDownloaded -> false
+ | _ ->
+ let bitmap = verified_bitmap t in
+ for i = 0 to String.length bitmap - 1 do
+ if bitmap.[i] <> '3' then raise Not_found;
+ done;
+ if file_size file <> downloaded t then
+ lprintf_nl () "Downloaded size differs after complete verification";
+ true
+ with _ -> false
+
+
Index: mldonkey/src/daemon/driver/driverCommands.ml
diff -u mldonkey/src/daemon/driver/driverCommands.ml:1.134
mldonkey/src/daemon/driver/driverCommands.ml:1.135
--- mldonkey/src/daemon/driver/driverCommands.ml:1.134 Wed Mar 29 15:41:33 2006
+++ mldonkey/src/daemon/driver/driverCommands.ml Sun Apr 9 00:27:03 2006
@@ -3027,7 +3027,7 @@
"merge", Arg_two (fun f1 f2 o ->
let file1 = file_find (int_of_string f1) in
let file2 = file_find (int_of_string f2) in
- Int64Swarmer.merge file1 file2;
+ CommonSwarming.merge file1 file2;
"The two files are now merged"
), "<num1> <num2> :\t\t\ttry to swarm downloads from file <num2>
(secondary) to file <num1> (primary)";
Index: mldonkey/src/daemon/driver/driverMain.ml
diff -u mldonkey/src/daemon/driver/driverMain.ml:1.105
mldonkey/src/daemon/driver/driverMain.ml:1.106
--- mldonkey/src/daemon/driver/driverMain.ml:1.105 Mon Apr 3 20:50:08 2006
+++ mldonkey/src/daemon/driver/driverMain.ml Sun Apr 9 00:27:03 2006
@@ -74,7 +74,7 @@
CommonInteractive.force_download_quotas ();
CommonResult.dummy_result.result_time <- last_time ();
(try
- Int64Swarmer.verify_some_chunks ()
+ CommonSwarming.verify_some_chunks ()
with _ -> ());
CommonClient.clear_upload_slots ()
Index: mldonkey/src/networks/bittorrent/bTChooser.ml
diff -u mldonkey/src/networks/bittorrent/bTChooser.ml:1.10
mldonkey/src/networks/bittorrent/bTChooser.ml:1.11
--- mldonkey/src/networks/bittorrent/bTChooser.ml:1.10 Sun Oct 16 20:42:53 2005
+++ mldonkey/src/networks/bittorrent/bTChooser.ml Sun Apr 9 00:27:03 2006
@@ -110,11 +110,11 @@
((file_size a) -- (match a.file_swarmer with
| None -> Int64.zero
| Some swarmer ->
- CommonDownloads.Int64Swarmer.downloaded
swarmer))
+ CommonSwarming.downloaded swarmer))
((file_size b) -- (match b.file_swarmer with
| None -> Int64.zero
| Some swarmer ->
-
CommonDownloads.Int64Swarmer.downloaded swarmer))
+ CommonSwarming.downloaded
swarmer))
) files in
let files = List.stable_sort
(fun a b -> compare
Index: mldonkey/src/networks/bittorrent/bTClients.ml
diff -u mldonkey/src/networks/bittorrent/bTClients.ml:1.66
mldonkey/src/networks/bittorrent/bTClients.ml:1.67
--- mldonkey/src/networks/bittorrent/bTClients.ml:1.66 Wed Mar 29 15:41:33 2006
+++ mldonkey/src/networks/bittorrent/bTClients.ml Sun Apr 9 00:27:03 2006
@@ -109,7 +109,7 @@
end
| Some swarmer ->
- let local_downloaded = Int64Swarmer.downloaded swarmer in
+ let local_downloaded = CommonSwarming.downloaded swarmer in
let left = file_size file -- local_downloaded in
match event with
| "completed" -> [("event", "completed")],false,zero,zero
@@ -268,7 +268,7 @@
| Connection sock ->
close sock reason;
try
-(* List.iter (fun r -> Int64Swarmer.free_range r) c.client_ranges; *)
+(* List.iter (fun r -> CommonSwarming.free_range r) c.client_ranges;
*)
set_client_disconnected c reason;
(try if c.client_good then count_seen c with _ -> ());
(* this is not useful already done in the match
@@ -296,7 +296,7 @@
we must unregister him to update the swarmer
(Useful for availability)
*)
- Int64Swarmer.unregister_uploader up
+ CommonSwarming.unregister_uploader up
(* c.client_registered_bitfield <- false;
for i = 0 to String.length c.client_bitmap - 1 do
c.client_bitmap.[0] <- '0';
@@ -347,7 +347,7 @@
(*CommonComplexOptions.file_completed*)
file_completed (as_file file);
(* Remove the swarmer for this file as it is not useful anymore... *)
- Int64Swarmer.remove_swarmer file.file_swarmer;
+ CommonSwarming.remove_swarmer file.file_swarmer;
file.file_swarmer <- None;
(* At this point, the file state is FileDownloaded. We should not
remove
the file, because we continue to upload. *)
@@ -359,7 +359,7 @@
@param file The file to check status
*)
let check_finished swarmer file =
- if Int64Swarmer.check_finished swarmer then
+ if CommonSwarming.check_finished swarmer then
download_finished file
let bits = [| 128; 64; 32;16;8;4;2;1 |]
@@ -401,7 +401,7 @@
(* This must be a seeded file... *)
String.make (Array.length c.client_file.file_chunks) '3'
| Some swarmer ->
- Int64Swarmer.verified_bitmap swarmer
+ CommonSwarming.verified_bitmap swarmer
in
if !verbose_download then lprintf_nl () "Sending verified bitmap: [%s]"
bitmap;
@@ -560,7 +560,7 @@
let up =
match c.client_uploader with
None ->
- let up = Int64Swarmer.register_uploader swarmer (as_client c)
+ let up = CommonSwarming.register_uploader swarmer (as_client c)
(AvailableRanges []) in
c.client_uploader <- Some up;
up
@@ -570,7 +570,7 @@
let bitmap = match c.client_bitmap with
None ->
- let len = Int64Swarmer.partition_size swarmer in
+ let len = CommonSwarming.partition_size swarmer in
let bitmap = Bitv.create len false in
c.client_bitmap <- Some bitmap;
bitmap
@@ -581,7 +581,7 @@
let chunks = c.client_new_chunks in
c.client_new_chunks <- [];
List.iter (fun n -> Bitv.set bitmap n true) chunks;
- Int64Swarmer.update_uploader up (AvailableBitv bitmap);
+ CommonSwarming.update_uploader up (AvailableBitv bitmap);
end
@@ -603,7 +603,7 @@
let up = match c.client_uploader with
None -> assert false
| Some up -> up in
- let swarmer = Int64Swarmer.uploader_swarmer up in
+ let swarmer = CommonSwarming.uploader_swarmer up in
try
@@ -625,7 +625,7 @@
lprintf_n () "Current ranges: ";
List.iter (fun (p1,p2, r) ->
- let (x,y) = Int64Swarmer.range_range r in
+ let (x,y) = CommonSwarming.range_range r in
lprintf "%Ld-%Ld[%Ld-%Ld] " p1 p2 x y
) c.client_ranges_sent;
@@ -639,7 +639,7 @@
match c.client_block with
| None -> lprintf "none"
- | Some b -> Int64Swarmer.print_block b;
+ | Some b -> CommonSwarming.print_block b;
lprint_newline ();
@@ -660,11 +660,11 @@
if !verbose_swarming then lprintf_nl () "No block";
update_client_bitmap c;
- (try Int64Swarmer.verify_one_chunk swarmer with _ -> ());
+ (try CommonSwarming.verify_one_chunk swarmer with _ -> ());
(*Find a free block in the swarmer*)
- let b = Int64Swarmer.find_block up in
+ let b = CommonSwarming.find_block up in
if !verbose_swarming then begin
- lprintf_n () "Block Found: "; Int64Swarmer.print_block b;
+ lprintf_n () "Block Found: "; CommonSwarming.print_block b;
lprint_newline ()
end;
c.client_block <- Some b;
@@ -679,7 +679,7 @@
| Some b ->
if !verbose_swarming then begin
- lprintf_n () "Current Block: "; Int64Swarmer.print_block b;
+ lprintf_n () "Current Block: "; CommonSwarming.print_block b;
lprint_newline ()
end;
@@ -691,7 +691,7 @@
c.client_range_waiting <- None;
(x,y,r)
| None ->
- Int64Swarmer.find_range up
+ CommonSwarming.find_range up
in
let (x,y,r) =
@@ -704,9 +704,9 @@
in
c.client_ranges_sent <- c.client_ranges_sent @ [x,y, r];
-(* Int64Swarmer.alloc_range r; *)
+(* CommonSwarming.alloc_range r; *)
- let num = Int64Swarmer.block_num swarmer b in
+ let num = CommonSwarming.block_num swarmer b in
if !verbose_swarming then
lprintf_nl () "Asking %d For Range %Ld-%Ld" num x y;
@@ -736,7 +736,7 @@
*)
if !verbose_swarming then
lprintf_nl () "Unable to get a block !!";
- Int64Swarmer.compute_bitmap swarmer;
+ CommonSwarming.compute_bitmap swarmer;
check_finished swarmer file;
raise Not_found
in
@@ -748,7 +748,7 @@
(client_num c) (Sha1.to_string c.client_uid) x y
with Not_found ->
- if not (Int64Swarmer.check_finished swarmer) && !verbose_download then
+ if not (CommonSwarming.check_finished swarmer) && !verbose_download
then
lprintf_nl () "BTClient.get_from_client ERROR: can't find a block to
download and file is not yet finished for file : %s..." file.file_name
@@ -778,7 +778,7 @@
[] -> ()
| b :: tail when tail == c.client_blocks_sent ->
c.client_blocks_sent <- list;
- let (num,_,_) = Int64Swarmer.block_block b in
+ let (num,_,_) = CommonSwarming.block_block b in
send_client c (Have (Int64.of_int num))
| _ :: tail -> iter tail
in
@@ -797,26 +797,26 @@
let up = match c.client_uploader with
None -> assert false
| Some up -> up in
- let swarmer = Int64Swarmer.uploader_swarmer up in
+ let swarmer = CommonSwarming.uploader_swarmer up in
if !verbose_msg_clients then
(match c.client_ranges_sent with
[] -> lprintf_nl () "EMPTY Ranges !!!"
| (p1,p2,r) :: _ ->
- let (x,y) = Int64Swarmer.range_range r in
+ let (x,y) = CommonSwarming.range_range r in
lprintf_nl () "Current range from %s : %Ld [%d] (asked
%Ld-%Ld[%Ld-%Ld])"
(brand_to_string c.client_brand) position len
p1 p2 x y
);
let old_downloaded =
- Int64Swarmer.downloaded swarmer in
-(* List.iter Int64Swarmer.free_range c.client_ranges; *)
- Int64Swarmer.received up
+ CommonSwarming.downloaded swarmer in
+(* List.iter CommonSwarming.free_range c.client_ranges; *)
+ CommonSwarming.received up
position s pos len;
-(* List.iter Int64Swarmer.alloc_range c.client_ranges; *)
+(* List.iter CommonSwarming.alloc_range c.client_ranges; *)
let new_downloaded =
- Int64Swarmer.downloaded swarmer in
+ CommonSwarming.downloaded swarmer in
(*Update rate and amount of data received from client*)
count_download c (new_downloaded -- old_downloaded);
@@ -826,7 +826,7 @@
(match c.client_ranges_sent with
[] -> lprintf_nl () "EMPTY Ranges !!!"
| (p1,p2,r) :: _ ->
- let (x,y) = Int64Swarmer.range_range r in
+ let (x,y) = CommonSwarming.range_range r in
lprintf_nl () "Received %Ld [%d] %Ld-%Ld[%Ld-%Ld] -> %Ld"
position len
p1 p2 x y
@@ -842,7 +842,7 @@
match c.client_ranges_sent with
[] -> ()
| r :: tail ->
-(* Int64Swarmer.free_range r; *)
+(* CommonSwarming.free_range r; *)
c.client_ranges_sent <- tail;
end;
get_from_client sock c;
@@ -909,7 +909,7 @@
| Some swarmer ->
c.client_new_chunks <- [];
- let npieces = Int64Swarmer.partition_size swarmer in
+ let npieces = CommonSwarming.partition_size swarmer in
let nbits = String.length p * 8 in
if nbits < npieces then begin
@@ -917,7 +917,7 @@
disconnect_client c (Closed_for_error "Wrong bitfield length")
end else begin
- let verified = Int64Swarmer.verified_bitmap swarmer in
+ let verified = CommonSwarming.verified_bitmap swarmer in
for i = 0 to npieces - 1 do
if is_bit_set p i then begin
@@ -952,7 +952,7 @@
None -> ()
| Some swarmer ->
let n = Int64.to_int n in
- let verified = Int64Swarmer.verified_bitmap swarmer in
+ let verified = CommonSwarming.verified_bitmap swarmer in
(* lprintf_nl "verified: %c;" verified.[n]; *)
(* if the peer has a chunk we don't, tell him we're interested
and update his bitmap *)
if verified.[n] < '2' then begin
@@ -965,11 +965,11 @@
(* begin
match c.client_bitmap, c.client_uploader with
Some bitmap, Some up ->
- let swarmer = Int64Swarmer.uploader_swarmer up in
+ let swarmer = CommonSwarming.uploader_swarmer up in
let n = Int64.to_int n in
if bitmap.[n] <> '1' then
- let verified = Int64Swarmer.verified_bitmap swarmer in
+ let verified = CommonSwarming.verified_bitmap swarmer in
if verified.[n] < '2' then begin
c.client_interesting <- true;
send_interested c;
@@ -1005,7 +1005,7 @@
if !verbose_msg_clients then lprintf_nl () "%s:%d with
software %s : Choke send, but no client bitmap"
(Ip.to_string ip) port (brand_to_string c.client_brand)
| Some up ->
- Int64Swarmer.clear_uploader_ranges up
+ CommonSwarming.clear_uploader_ranges up
end;
c.client_ranges_sent <- [];
c.client_range_waiting <- None;
Index: mldonkey/src/networks/bittorrent/bTComplexOptions.ml
diff -u mldonkey/src/networks/bittorrent/bTComplexOptions.ml:1.30
mldonkey/src/networks/bittorrent/bTComplexOptions.ml:1.31
--- mldonkey/src/networks/bittorrent/bTComplexOptions.ml:1.30 Fri Dec 16
20:59:42 2005
+++ mldonkey/src/networks/bittorrent/bTComplexOptions.ml Sun Apr 9
00:27:03 2006
@@ -210,7 +210,7 @@
(match file.file_swarmer with
None -> ()
| Some swarmer ->
- Int64Swarmer.value_to_swarmer swarmer assocs;
+ CommonSwarming.value_to_swarmer swarmer assocs;
);
(*
@@ -262,7 +262,7 @@
match file.file_swarmer with
None -> assocs
| Some swarmer ->
- Int64Swarmer.swarmer_to_value swarmer assocs
+ CommonSwarming.swarmer_to_value swarmer assocs
with
e ->
lprintf_nl () "exception %s in file_to_value"
Index: mldonkey/src/networks/bittorrent/bTGlobals.ml
diff -u mldonkey/src/networks/bittorrent/bTGlobals.ml:1.54
mldonkey/src/networks/bittorrent/bTGlobals.ml:1.55
--- mldonkey/src/networks/bittorrent/bTGlobals.ml:1.54 Sat Apr 1 23:20:55 2006
+++ mldonkey/src/networks/bittorrent/bTGlobals.ml Sun Apr 9 00:27:03 2006
@@ -133,25 +133,25 @@
None -> assert false
| Some up -> up
in
- let swarmer = Int64Swarmer.uploader_swarmer up in
+ let swarmer = CommonSwarming.uploader_swarmer up in
let must_send =
(* The client has nothing to propose to us *)
- (not (Int64Swarmer.is_interesting up )) &&
+ (not (CommonSwarming.is_interesting up )) &&
(* All the requested ranges are useless *)
(List.filter (fun (_,_,r) ->
- let x,y = Int64Swarmer.range_range r in
+ let x,y = CommonSwarming.range_range r in
x < y) c.client_ranges_sent = []) &&
(match c.client_range_waiting with
None -> true
| Some (x,y,r) ->
- let x,y = Int64Swarmer.range_range r in
+ let x,y = CommonSwarming.range_range r in
x < y) &&
(* The current block is also useless *)
(match c.client_block with
None -> true
| Some b ->
- let block_num = Int64Swarmer.block_num swarmer b in
- let bitmap = Int64Swarmer.verified_bitmap swarmer in
+ let block_num = CommonSwarming.block_num swarmer b in
+ let bitmap = CommonSwarming.verified_bitmap swarmer in
bitmap.[block_num] <> '3')
in
if must_send then
@@ -252,12 +252,12 @@
else
set_trackers file [t.torrent_announce];
if file_state <> FileShared then begin
- let kernel = Int64Swarmer.create_swarmer file_temp (file_size file)
+ let kernel = CommonSwarming.create_swarmer file_temp (file_size file)
(min max_range_len file.file_piece_size) in
- let swarmer = Int64Swarmer.create kernel (as_file file)
+ let swarmer = CommonSwarming.create kernel (as_file file)
file.file_piece_size in
file.file_swarmer <- Some swarmer;
- Int64Swarmer.set_verified swarmer (fun _ num ->
+ CommonSwarming.set_verified swarmer (fun _ num ->
file.file_blocks_downloaded <- (num) ::
file.file_blocks_downloaded;
file_must_update file;
@@ -277,7 +277,7 @@
) file.file_clients
);
- Int64Swarmer.set_verifier swarmer (Verification
+ CommonSwarming.set_verifier swarmer (Verification
(Array.map (fun sha1 -> Sha1 sha1) file.file_chunks));
end;
current_files := file :: !current_files;
Index: mldonkey/src/networks/bittorrent/bTInteractive.ml
diff -u mldonkey/src/networks/bittorrent/bTInteractive.ml:1.87
mldonkey/src/networks/bittorrent/bTInteractive.ml:1.88
--- mldonkey/src/networks/bittorrent/bTInteractive.ml:1.87 Wed Mar 15
20:55:15 2006
+++ mldonkey/src/networks/bittorrent/bTInteractive.ml Sun Apr 9 00:27:03 2006
@@ -81,11 +81,11 @@
match file.file_swarmer with
None -> [CommonFile.as_file impl]
| Some swarmer ->
- Int64Swarmer.subfiles swarmer
+ CommonSwarming.subfiles swarmer
let op_file_debug file =
let buf = Buffer.create 100 in
-(* Int64Swarmer.debug_print buf file.file_swarmer; *)
+(* CommonSwarming.debug_print buf file.file_swarmer; *)
Hashtbl.iter (fun _ c ->
Printf.bprintf buf "Client %d: %s\n" (client_num c)
(match c.client_sock with
@@ -97,7 +97,7 @@
Buffer.contents buf
let op_file_commit file new_name =
- Int64Swarmer.remove_swarmer file.file_swarmer;
+ CommonSwarming.remove_swarmer file.file_swarmer;
file.file_swarmer <- None;
if file_state file <> FileShared then
begin
@@ -279,7 +279,7 @@
let chunks = (match file.file_swarmer with
None -> "" | Some swarmer ->
- Int64Swarmer.verified_bitmap swarmer) in
+ CommonSwarming.verified_bitmap swarmer) in
let header_list = [
( "1", "srh br ac", "Client number", "Num" ) ;
@@ -372,14 +372,14 @@
None ->
lprintf_nl () "verify_chunks: no swarmer to verify chunks"
| Some swarmer ->
- Int64Swarmer.verify_all_chunks swarmer true
+ CommonSwarming.verify_all_chunks swarmer true
let remove_all_clients file =
Hashtbl.clear file.file_clients;
file.file_clients_num <- 0
let op_file_cancel file =
- Int64Swarmer.remove_swarmer file.file_swarmer;
+ CommonSwarming.remove_swarmer file.file_swarmer;
file.file_swarmer <- None;
BTClients.file_stop file;
remove_file file;
@@ -399,7 +399,7 @@
let last_seen = match file.file_swarmer with
None -> [| last_time () |]
- | Some swarmer -> Int64Swarmer.compute_last_seen swarmer in
+ | Some swarmer -> CommonSwarming.compute_last_seen swarmer in
{ (impl_file_info file.file_file) with
@@ -408,11 +408,11 @@
P.file_names = [file.file_name, P.noips()];
P.file_chunks = (match file.file_swarmer with
None -> "" | Some swarmer ->
- Int64Swarmer.verified_bitmap swarmer);
+ CommonSwarming.verified_bitmap swarmer);
P.file_availability =
[network.network_num,(match file.file_swarmer with
None -> "" | Some swarmer ->
- Int64Swarmer.availability swarmer)];
+ CommonSwarming.availability swarmer)];
P.file_chunks_age = last_seen;
P.file_uids = [Uid.create (BTUrl file.file_id)];
Index: mldonkey/src/networks/bittorrent/bTTypes.ml
diff -u mldonkey/src/networks/bittorrent/bTTypes.ml:1.32
mldonkey/src/networks/bittorrent/bTTypes.ml:1.33
--- mldonkey/src/networks/bittorrent/bTTypes.ml:1.32 Sat Apr 1 23:20:55 2006
+++ mldonkey/src/networks/bittorrent/bTTypes.ml Sun Apr 9 00:27:03 2006
@@ -181,11 +181,11 @@
mutable client_sock : tcp_connection;
mutable client_host : Ip.t * int;
mutable client_chunks : (int64 * int64) list;
- mutable client_uploader : Int64Swarmer.uploader option;
- mutable client_ranges_sent : (int64 * int64 * Int64Swarmer.range) list;
+ mutable client_uploader : CommonSwarming.uploader option;
+ mutable client_ranges_sent : (int64 * int64 * CommonSwarming.range) list;
mutable client_range_waiting :
- (int64 * int64 * Int64Swarmer.range) option;
- mutable client_block : Int64Swarmer.block option;
+ (int64 * int64 * CommonSwarming.range) option;
+ mutable client_block : CommonSwarming.block option;
mutable client_received_peer_id : bool;
mutable client_sent_choke : bool; (* we sent a Choke to the client *)
@@ -244,7 +244,7 @@
file_creation_date : int64;
file_modified_by : string;
file_encoding : string;
- mutable file_swarmer : Int64Swarmer.t option;
+ mutable file_swarmer : CommonSwarming.t option;
mutable file_clients : ((Ip.t*int), client) Hashtbl.t ;
mutable file_clients_num : int ;
mutable file_chunks : Sha1.t array;
Index: mldonkey/src/networks/direct_connect/dcInteractive.ml
diff -u mldonkey/src/networks/direct_connect/dcInteractive.ml:1.24
mldonkey/src/networks/direct_connect/dcInteractive.ml:1.25
--- mldonkey/src/networks/direct_connect/dcInteractive.ml:1.24 Fri Dec 16
20:56:31 2005
+++ mldonkey/src/networks/direct_connect/dcInteractive.ml Sun Apr 9
00:27:03 2006
@@ -323,7 +323,7 @@
match file.file_swarmer with
None -> [CommonFile.as_file impl]
| Some swarmer ->
- Int64Swarmer.subfiles swarmer)
+ CommonSwarming.subfiles swarmer)
; *)
(*
file_ops.op_file_save_as <- (fun file new_name ->
Index: mldonkey/src/networks/donkey/donkeyClient.ml
diff -u mldonkey/src/networks/donkey/donkeyClient.ml:1.87
mldonkey/src/networks/donkey/donkeyClient.ml:1.88
--- mldonkey/src/networks/donkey/donkeyClient.ml:1.87 Wed Mar 29 15:41:33 2006
+++ mldonkey/src/networks/donkey/donkeyClient.ml Sun Apr 9 00:27:03 2006
@@ -282,7 +282,7 @@
(try DonkeyOneFile.clean_current_download c with _ -> ());
List.iter (fun (file, chunks, up) ->
- try Int64Swarmer.unregister_uploader up with _ -> ()
+ try CommonSwarming.unregister_uploader up with _ -> ()
)
files;
c.client_file_queue <- [];
@@ -862,7 +862,7 @@
match file.file_swarmer with
None -> false
| Some swarmer ->
- let bitmap = Int64Swarmer.verified_bitmap swarmer in
+ let bitmap = CommonSwarming.verified_bitmap swarmer in
let rec iter bitmap chunks i len =
if i = len then false else
if Bitv.get chunks i && bitmap.[i] < '2' then true else
@@ -879,7 +879,7 @@
match file.file_swarmer with
None -> ()
| Some swarmer ->
- lprintf_nl () " %s" (Int64Swarmer.verified_bitmap swarmer);
+ lprintf_nl () " %s" (CommonSwarming.verified_bitmap swarmer);
end;
let chunks =
@@ -1296,7 +1296,7 @@
| Some (file,up) ->
if !verbose_download then
lprintf_nl () "Clear download";
- Int64Swarmer.clear_uploader_ranges up;
+ CommonSwarming.clear_uploader_ranges up;
c.client_download <- None
| None ->
match c.client_file_queue with
@@ -1384,7 +1384,7 @@
| Some (file,up) ->
if !verbose_download then
lprintf_nl () "Slot closed during download";
- Int64Swarmer.clear_uploader_ranges up
+ CommonSwarming.clear_uploader_ranges up
end;
(* DonkeyOneFile.clean_current_download c; *)
c.client_slot <- SlotNotAsked;
@@ -1477,7 +1477,7 @@
match file.file_swarmer with
None -> ()
| Some swarmer ->
- Int64Swarmer.set_verifier swarmer
+ CommonSwarming.set_verifier swarmer
(Verification [| Ed2k file.file_md4 |])
end else
if t.Q.chunks = [||] then
@@ -1518,7 +1518,7 @@
match file.file_swarmer with
None -> ()
| Some swarmer ->
- Int64Swarmer.set_verifier swarmer
+ CommonSwarming.set_verifier swarmer
(Verification (Array.map (fun m -> Ed2k m) md4s))
end
@@ -1946,7 +1946,7 @@
asume that we have all chunks! *)
Bitv.create file.file_nchunks true
| Some swarmer ->
- let bitmap = Int64Swarmer.verified_bitmap swarmer in
+ let bitmap = CommonSwarming.verified_bitmap swarmer in
Bitv.init (String.length bitmap)
(fun i -> bitmap.[i] = '3')
(* This is not very smart, as we might get banned for this
request.
@@ -2538,7 +2538,7 @@
match file.file_swarmer with
None -> None
| Some swarmer ->
- let bitmap = Int64Swarmer.verified_bitmap swarmer in
+ let bitmap = CommonSwarming.verified_bitmap swarmer in
let chunks =
Bitv.init (String.length bitmap)
(fun i -> bitmap.[i] = '3')
Index: mldonkey/src/networks/donkey/donkeyComplexOptions.ml
diff -u mldonkey/src/networks/donkey/donkeyComplexOptions.ml:1.45
mldonkey/src/networks/donkey/donkeyComplexOptions.ml:1.46
--- mldonkey/src/networks/donkey/donkeyComplexOptions.ml:1.45 Sat Apr 8
02:16:21 2006
+++ mldonkey/src/networks/donkey/donkeyComplexOptions.ml Sun Apr 9
00:27:03 2006
@@ -297,8 +297,8 @@
(match file.file_swarmer with
None -> ()
| Some swarmer ->
- Int64Swarmer.value_to_swarmer swarmer assocs;
- Int64Swarmer.set_verifier swarmer (if md4s = [||] then
+ CommonSwarming.value_to_swarmer swarmer assocs;
+ CommonSwarming.set_verifier swarmer (if md4s = [||] then
VerificationNotAvailable
else
Verification
@@ -321,7 +321,7 @@
match file.file_swarmer with
None -> fields
| Some swarmer ->
- Int64Swarmer.swarmer_to_value swarmer fields
+ CommonSwarming.swarmer_to_value swarmer fields
in
fields
Index: mldonkey/src/networks/donkey/donkeyGlobals.ml
diff -u mldonkey/src/networks/donkey/donkeyGlobals.ml:1.78
mldonkey/src/networks/donkey/donkeyGlobals.ml:1.79
--- mldonkey/src/networks/donkey/donkeyGlobals.ml:1.78 Sat Apr 8 01:27:29 2006
+++ mldonkey/src/networks/donkey/donkeyGlobals.ml Sun Apr 9 00:27:03 2006
@@ -397,12 +397,12 @@
(match file_state with
FileShared -> ()
| _ ->
- let kernel = Int64Swarmer.create_swarmer file_diskname file_size
zone_size in
- let swarmer = Int64Swarmer.create kernel (as_file file) block_size
+ let kernel = CommonSwarming.create_swarmer file_diskname file_size
zone_size in
+ let swarmer = CommonSwarming.create kernel (as_file file)
block_size
in
file.file_swarmer <- Some swarmer;
(*
- Int64Swarmer.set_writer swarmer (fun offset s pos len ->
+ CommonSwarming.set_writer swarmer (fun offset s pos len ->
(*
lprintf "DOWNLOADED: %d/%d/%d\n" pos len (String.length s);
AnyEndian.dump_sub s pos len;
@@ -413,11 +413,11 @@
else
Unix32.write t offset s pos len
); *)
- Int64Swarmer.set_verifier swarmer
+ CommonSwarming.set_verifier swarmer
(if md4s = [] then VerificationNotAvailable else
Verification (Array.of_list (List.map (fun md4 -> Ed2k md4)
md4s))
);
- Int64Swarmer.set_verified swarmer (fun nblocks num ->
+ CommonSwarming.set_verified swarmer (fun nblocks num ->
if nblocks = 1 then begin
new_shared_files := file :: !new_shared_files;
file_must_update file
Index: mldonkey/src/networks/donkey/donkeyInteractive.ml
diff -u mldonkey/src/networks/donkey/donkeyInteractive.ml:1.98
mldonkey/src/networks/donkey/donkeyInteractive.ml:1.99
--- mldonkey/src/networks/donkey/donkeyInteractive.ml:1.98 Sat Apr 8
02:16:21 2006
+++ mldonkey/src/networks/donkey/donkeyInteractive.ml Sun Apr 9 00:27:03 2006
@@ -246,7 +246,7 @@
None -> assert false
| Some swarmer ->
let absents = Sort.list (fun (p1,_) (p2,_) -> p1 <= p2) absents in
- Int64Swarmer.set_absent swarmer absents
+ CommonSwarming.set_absent swarmer absents
end;
if !verbose then lprintf_nl () "Started new download, file %s, size %Ld, md4
%s"
@@ -498,7 +498,7 @@
match file.file_swarmer with
None -> ()
| Some swarmer ->
- let bitmap = Int64Swarmer.verified_bitmap swarmer in
+ let bitmap = CommonSwarming.verified_bitmap swarmer in
Printf.bprintf buf "\nChunks: %s\n" bitmap
*)
@@ -507,7 +507,7 @@
match file.file_swarmer with
None -> ()
| Some swarmer ->
- Int64Swarmer.verify_all_chunks swarmer false
+ CommonSwarming.verify_all_chunks swarmer false
(*
if file.file_chunks <> [||] then
@@ -613,7 +613,7 @@
match file.file_swarmer with
None -> ()
| Some swarmer ->
- Int64Swarmer.verify_all_chunks swarmer true
+ CommonSwarming.verify_all_chunks swarmer true
let register_commands list =
register_commands
@@ -747,9 +747,9 @@
None -> ()
| Some swarmer ->
let segments = CommonFile.recover_bytes (as_file file)
in
- let old_downloaded = Int64Swarmer.downloaded swarmer in
- Int64Swarmer.set_present swarmer segments;
- let new_downloaded = Int64Swarmer.downloaded swarmer in
+ let old_downloaded = CommonSwarming.downloaded swarmer
in
+ CommonSwarming.set_present swarmer segments;
+ let new_downloaded = CommonSwarming.downloaded swarmer
in
Printf.bprintf buf "Recovered %Ld bytes for %s\n"
(new_downloaded -- old_downloaded)
(file_best_name file)
@@ -975,7 +975,7 @@
file_ops.op_file_commit <- (fun file new_name ->
- Int64Swarmer.remove_swarmer file.file_swarmer;
+ CommonSwarming.remove_swarmer file.file_swarmer;
file.file_swarmer <- None;
(* DonkeyStats.save_download_history file; *)
@@ -1031,7 +1031,7 @@
try
let last_seen = match file.file_swarmer with
None -> [| last_time () |]
- | Some swarmer -> Int64Swarmer.compute_last_seen swarmer
+ | Some swarmer -> CommonSwarming.compute_last_seen swarmer
in
let v =
{ (impl_file_info file.file_file) with
@@ -1044,13 +1044,13 @@
P.file_chunks =
(match file.file_swarmer with
| None -> ""
- | Some swarmer -> Int64Swarmer.verified_bitmap swarmer);
+ | Some swarmer -> CommonSwarming.verified_bitmap swarmer);
P.file_availability =
[
network.network_num,
(match file.file_swarmer with
| None -> ""
- | Some swarmer -> Int64Swarmer.availability swarmer)
+ | Some swarmer -> CommonSwarming.availability swarmer)
];
P.file_format = file.file_format;
P.file_chunks_age = last_seen;
@@ -1305,7 +1305,7 @@
let chunks =
(match file.file_swarmer with
None -> "" | Some swarmer ->
- Int64Swarmer.verified_bitmap swarmer)
+ CommonSwarming.verified_bitmap swarmer)
in
html_mods_table_header buf "sourcesTable" "sources al" ([
@@ -1445,7 +1445,7 @@
);
file_ops.op_file_cancel <- (fun file ->
- Int64Swarmer.remove_swarmer file.file_swarmer;
+ CommonSwarming.remove_swarmer file.file_swarmer;
file.file_swarmer <- None;
Hashtbl.remove files_by_md4 file.file_md4;
current_files := List2.removeq file !current_files;
@@ -1466,7 +1466,7 @@
match file.file_swarmer with
None -> [CommonFile.as_file impl]
| Some swarmer ->
- Int64Swarmer.subfiles swarmer)
+ CommonSwarming.subfiles swarmer)
let try_recover_temp_file filename md4 =
try
Index: mldonkey/src/networks/donkey/donkeyOneFile.ml
diff -u mldonkey/src/networks/donkey/donkeyOneFile.ml:1.35
mldonkey/src/networks/donkey/donkeyOneFile.ml:1.36
--- mldonkey/src/networks/donkey/donkeyOneFile.ml:1.35 Fri Feb 17 22:24:41 2006
+++ mldonkey/src/networks/donkey/donkeyOneFile.ml Sun Apr 9 00:27:03 2006
@@ -134,7 +134,7 @@
let declare_completed_file file =
DonkeyShare.remember_shared_info file (file_disk_name file);
file_completed (as_file file);
- Int64Swarmer.remove_swarmer file.file_swarmer;
+ CommonSwarming.remove_swarmer file.file_swarmer;
file.file_swarmer <- None;
unshare_file file;
ignore (CommonShared.new_shared "completed" 0 (
@@ -166,7 +166,7 @@
match file.file_swarmer with
None -> ()
| Some swarmer ->
- let bitmap = Int64Swarmer.verified_bitmap swarmer in
+ let bitmap = CommonSwarming.verified_bitmap swarmer in
(* lprintf "Verified bitmap: [%s]\n" bitmap; *)
let rec iter i =
if i = String.length bitmap then true
@@ -175,7 +175,7 @@
in
let verified = iter 0 in
- let downloaded = Int64Swarmer.downloaded swarmer in
+ let downloaded = CommonSwarming.downloaded swarmer in
if file_downloaded file <> downloaded then begin
lprintf_nl () "ERROR: file_downloaded file (%Ld) <> downloaded
swarmer (%Ld)"
(file_downloaded file) downloaded
@@ -197,7 +197,7 @@
match file.file_swarmer with
None -> ()
| Some swarmer ->
- let bitmap = Int64Swarmer.verified_bitmap swarmer in
+ let bitmap = CommonSwarming.verified_bitmap swarmer in
let rec iter i len =
if i < len then
if bitmap.[i] = '3' then
@@ -217,13 +217,13 @@
(f, chunks, up) :: tail ->
if f != file then iter tail
else begin
- Int64Swarmer.update_uploader up
+ CommonSwarming.update_uploader up
(AvailableBitv client_chunks);
Bitv.blit client_chunks 0 chunks 0 (Bitv.length chunks)
end
| [] ->
- let up = Int64Swarmer.register_uploader swarmer (as_client c)
+ let up = CommonSwarming.register_uploader swarmer (as_client c)
(AvailableBitv client_chunks) in
c.client_file_queue <- c.client_file_queue @
[file, client_chunks, up]
@@ -239,8 +239,8 @@
match c.client_download with
None -> ()
| Some (file, up) ->
- Int64Swarmer.clear_uploader_block up;
- Int64Swarmer.clear_uploader_ranges up;
+ CommonSwarming.clear_uploader_block up;
+ CommonSwarming.clear_uploader_ranges up;
c.client_download <- None
let send_get_range_request c file ranges =
@@ -324,8 +324,8 @@
| Some (file,up) ->
try
- let _ = Int64Swarmer.current_block up in
- let ranges = Int64Swarmer.current_ranges up in
+ let _ = CommonSwarming.current_block up in
+ let ranges = CommonSwarming.current_ranges up in
let before_find_range = List.length ranges in
(* lprintf "WAITING FOR %d BLOCS\n" before_find_range; *)
@@ -333,7 +333,7 @@
let rec iter n =
if n < 3 then
try
- ignore (Int64Swarmer.find_range up);
+ ignore (CommonSwarming.find_range up);
iter (n+1)
with
Not_found -> n
@@ -342,7 +342,7 @@
let after_find_range = iter before_find_range in
if after_find_range > before_find_range then
- let ranges = Int64Swarmer.current_ranges up in
+ let ranges = CommonSwarming.current_ranges up in
send_get_range_request c file ranges;
else
@@ -361,14 +361,14 @@
with Not_found ->
(* lprintf "get_from_client: no range\n"; *)
try
- let swarmer = Int64Swarmer.uploader_swarmer up in
- (try Int64Swarmer.verify_one_chunk swarmer with _ -> ());
- let _ = Int64Swarmer.find_block up in
+ let swarmer = CommonSwarming.uploader_swarmer up in
+ (try CommonSwarming.verify_one_chunk swarmer with _ -> ());
+ let _ = CommonSwarming.find_block up in
get_from_client c
with Not_found ->
(* lprintf "get_from_client: no block\n"; *)
- match Int64Swarmer.current_ranges up with
+ match CommonSwarming.current_ranges up with
[] ->
(* We have nothing to wait for in the current file *)
begin
@@ -376,7 +376,7 @@
(* lprintf "get_from_client: no expected ranges\n"; *)
c.client_download <- None;
- Int64Swarmer.unregister_uploader up;
+ CommonSwarming.unregister_uploader up;
match c.client_file_queue with
[] -> assert false
| _ :: tail ->
@@ -434,12 +434,12 @@
(* TODO: verify the received data has been requested *)
- let swarmer = Int64Swarmer.uploader_swarmer up in
- let old_downloaded = Int64Swarmer.downloaded swarmer in
+ let swarmer = CommonSwarming.uploader_swarmer up in
+ let old_downloaded = CommonSwarming.downloaded swarmer in
begin
try
- Int64Swarmer.received up begin_pos bloc bloc_pos bloc_len
+ CommonSwarming.received up begin_pos bloc bloc_pos bloc_len
with
| e ->
let m =
@@ -459,9 +459,9 @@
end;
-(* List.iter Int64Swarmer.alloc_range c.client_ranges; *)
+(* List.iter CommonSwarming.alloc_range c.client_ranges; *)
let new_downloaded =
- Int64Swarmer.downloaded swarmer in
+ CommonSwarming.downloaded swarmer in
count_download c (new_downloaded -- old_downloaded);
(*
if not (List.mem c.client_ip bb.block_contributors) then
Index: mldonkey/src/networks/donkey/donkeyShare.ml
diff -u mldonkey/src/networks/donkey/donkeyShare.ml:1.40
mldonkey/src/networks/donkey/donkeyShare.ml:1.41
--- mldonkey/src/networks/donkey/donkeyShare.ml:1.40 Sat Mar 18 18:35:54 2006
+++ mldonkey/src/networks/donkey/donkeyShare.ml Sun Apr 9 00:27:03 2006
@@ -107,7 +107,7 @@
(* file.file_all_chunks <- String.make file.file_nchunks '1'; *)
(* Should we trust mtimes, or reverify each file. If we trust
* mtimes, I guess we have to call
- * Int64Swarmer.set_verified_bitmap "333..."
+ * CommonSwarming.set_verified_bitmap "333..."
* this seems unspeakably ugly, but the alternative is to reverify
* every shared file every hour.
*
@@ -122,15 +122,15 @@
match file.file_swarmer with
Some s -> (let len = Array.length md4s in
let ver_str = String.make len '3' in
- Int64Swarmer.set_verified_bitmap s ver_str;
+ CommonSwarming.set_verified_bitmap s ver_str;
(*
- Int64Swarmer.set_present s [(Int64.zero, file_size file)];
+ CommonSwarming.set_present s [(Int64.zero, file_size file)];
(* If we don't verify now, it will never happen! *)
- Int64Swarmer.verify_all_blocks s true;
+ CommonSwarming.verify_all_blocks s true;
*)
if !verbose_share then
lprintf_nl () "verified map of %s = %s"
- (codedname) (Int64Swarmer.verified_bitmap s))
+ (codedname) (CommonSwarming.verified_bitmap s))
| None -> if !verbose_share then lprintf_nl () "no swarmer for %s"
codedname;
(try
file.file_format <- CommonMultimedia.get_info
Index: mldonkey/src/networks/donkey/donkeyTypes.ml
diff -u mldonkey/src/networks/donkey/donkeyTypes.ml:1.38
mldonkey/src/networks/donkey/donkeyTypes.ml:1.39
--- mldonkey/src/networks/donkey/donkeyTypes.ml:1.38 Thu Feb 9 11:41:39 2006
+++ mldonkey/src/networks/donkey/donkeyTypes.ml Sun Apr 9 00:27:03 2006
@@ -656,14 +656,14 @@
(* mutable client_chunks : availability; *)
(* mutable client_sock : tcp_connection; *)
mutable client_ip : Ip.t;
- mutable client_download : (file * Int64Swarmer.uploader) option;
-(* mutable client_block : Int64Swarmer.block option; *)
-(* mutable client_zones : (int64 * int64 * Int64Swarmer.range) list; *)
+ mutable client_download : (file * CommonSwarming.uploader) option;
+(* mutable client_block : CommonSwarming.block option; *)
+(* mutable client_zones : (int64 * int64 * CommonSwarming.range) list; *)
(* mutable client_connection_control : connection_control; *)
mutable client_file_queue : (
file * (* has displayed when connected *)
Bitv.t *
- Int64Swarmer.uploader
+ CommonSwarming.uploader
) list;
mutable client_next_view_files : int;
mutable client_all_files : result list option;
@@ -780,7 +780,7 @@
file_md4 : Md4.t;
(* file_exists : bool; *)
- mutable file_swarmer : Int64Swarmer.t option;
+ mutable file_swarmer : CommonSwarming.t option;
mutable file_nchunks : int;
mutable file_diskname : string;
Index: mldonkey/src/networks/fasttrack/fasttrackGlobals.ml
diff -u mldonkey/src/networks/fasttrack/fasttrackGlobals.ml:1.31
mldonkey/src/networks/fasttrack/fasttrackGlobals.ml:1.32
--- mldonkey/src/networks/fasttrack/fasttrackGlobals.ml:1.31 Wed Jan 11
19:12:35 2006
+++ mldonkey/src/networks/fasttrack/fasttrackGlobals.ml Sun Apr 9 00:27:04 2006
@@ -298,18 +298,18 @@
}
in
incr search_num;
- let kernel = Int64Swarmer.create_swarmer file_temp file_size min_range_size
in
- let swarmer = Int64Swarmer.create kernel (as_file file)
+ let kernel = CommonSwarming.create_swarmer file_temp file_size
min_range_size in
+ let swarmer = CommonSwarming.create kernel (as_file file)
file_chunk_size in
file.file_swarmer <- Some swarmer;
Hashtbl.add searches_by_uid search.search_uid search;
(* lprintf "SET SIZE : %Ld\n" file_size;*)
- Int64Swarmer.set_verifier swarmer ForceVerification;
- Int64Swarmer.set_verified swarmer (fun _ _ ->
+ CommonSwarming.set_verifier swarmer ForceVerification;
+ CommonSwarming.set_verified swarmer (fun _ _ ->
file_must_update file;
);
(*
- Int64Swarmer.set_writer swarmer (fun offset s pos len ->
+ CommonSwarming.set_writer swarmer (fun offset s pos len ->
(*
lprintf "DOWNLOADED: %d/%d/%d\n" pos len (String.length s);
Index: mldonkey/src/networks/fileTP/fileTPClients.ml
diff -u mldonkey/src/networks/fileTP/fileTPClients.ml:1.17
mldonkey/src/networks/fileTP/fileTPClients.ml:1.18
--- mldonkey/src/networks/fileTP/fileTPClients.ml:1.17 Thu Feb 23 10:50:36 2006
+++ mldonkey/src/networks/fileTP/fileTPClients.ml Sun Apr 9 00:27:04 2006
@@ -73,7 +73,7 @@
match d.download_uploader with
None -> ()
| Some up ->
- Int64Swarmer.unregister_uploader up;
+ CommonSwarming.unregister_uploader up;
d.download_ranges <- [];
d.download_uploader <- None;
) c.client_downloads;
@@ -124,7 +124,7 @@
let check_finished swarmer file =
if file_state file <> FileDownloaded &&
- (file_size file = Int64Swarmer.downloaded swarmer) then begin
+ (file_size file = CommonSwarming.downloaded swarmer) then begin
download_finished file
end
@@ -154,10 +154,10 @@
List.iter (fun (x,y) -> lprintf "%Ld-%Ld " x y)
d.download_chunks;
lprintf "\n Current ranges: ";
List.iter (fun (x,y,r) ->
-(* let (x,y) = Int64Swarmer.range_range r in *)
+(* let (x,y) = CommonSwarming.range_range r in *)
lprintf "%Ld-%Ld " x y) d.download_ranges;
lprintf "\n Current blocks: ";
-(* List.iter (fun b -> Int64Swarmer.print_block b)
d.download_blocks; *)
+(* List.iter (fun b -> CommonSwarming.print_block b)
d.download_blocks; *)
lprintf "\n\nFinding Range: \n";
end;
let range =
@@ -172,29 +172,29 @@
match d.download_block with
None ->
if !verbose_swarming then lprintf "No block\n";
- let b = Int64Swarmer.find_block up in
+ let b = CommonSwarming.find_block up in
(* lprintf "GOT BLOCK:\n"; *)
- if !verbose_swarming then
Int64Swarmer.print_uploaders swarmer;
+ if !verbose_swarming then
CommonSwarming.print_uploaders swarmer;
if !verbose_swarming then begin
- lprintf "Block Found: ";
Int64Swarmer.print_block b;
+ lprintf "Block Found: ";
CommonSwarming.print_block b;
end;
d.download_block <- Some b;
iter ()
| Some b ->
if !verbose_swarming then begin
- lprintf "Current Block: ";
Int64Swarmer.print_block b;
+ lprintf "Current Block: ";
CommonSwarming.print_block b;
end;
try
- let (x,y,r) = Int64Swarmer.find_range up in
+ let (x,y,r) = CommonSwarming.find_range up in
(* lprintf "GOT RANGE:\n"; *)
- if !verbose_swarming then
Int64Swarmer.print_uploaders swarmer;
+ if !verbose_swarming then
CommonSwarming.print_uploaders swarmer;
d.download_ranges <- d.download_ranges @ [x,y,r];
-(* Int64Swarmer.alloc_range r; *)
+(* CommonSwarming.alloc_range r; *)
(x,y)
with Not_found ->
if !verbose_swarming then
@@ -267,7 +267,7 @@
None -> assert false | Some sw -> sw
in
let chunks = [ Int64.zero, file_size file ] in
- let up = Int64Swarmer.register_uploader swarmer
+ let up = CommonSwarming.register_uploader swarmer
(as_client c)
(AvailableRanges chunks) in
d.download_uploader <- Some up
Index: mldonkey/src/networks/fileTP/fileTPComplexOptions.ml
diff -u mldonkey/src/networks/fileTP/fileTPComplexOptions.ml:1.14
mldonkey/src/networks/fileTP/fileTPComplexOptions.ml:1.15
--- mldonkey/src/networks/fileTP/fileTPComplexOptions.ml:1.14 Thu Feb 23
10:50:36 2006
+++ mldonkey/src/networks/fileTP/fileTPComplexOptions.ml Sun Apr 9
00:27:04 2006
@@ -84,7 +84,7 @@
(match file.file_swarmer with
None -> ()
| Some swarmer ->
- Int64Swarmer.value_to_swarmer swarmer assocs;
+ CommonSwarming.value_to_swarmer swarmer assocs;
);
(try
@@ -118,7 +118,7 @@
match file.file_swarmer with
None -> assocs
| Some swarmer ->
- Int64Swarmer.swarmer_to_value swarmer assocs
+ CommonSwarming.swarmer_to_value swarmer assocs
let old_files =
define_option fileTP_section ["old_urls"]
Index: mldonkey/src/networks/fileTP/fileTPFTP.ml
diff -u mldonkey/src/networks/fileTP/fileTPFTP.ml:1.11
mldonkey/src/networks/fileTP/fileTPFTP.ml:1.12
--- mldonkey/src/networks/fileTP/fileTPFTP.ml:1.11 Thu Feb 23 10:50:36 2006
+++ mldonkey/src/networks/fileTP/fileTPFTP.ml Sun Apr 9 00:27:04 2006
@@ -79,15 +79,15 @@
None -> assert false
| Some up ->
- let swarmer = Int64Swarmer.uploader_swarmer up in
+ let swarmer = CommonSwarming.uploader_swarmer up in
let old_downloaded =
- Int64Swarmer.downloaded swarmer in
+ CommonSwarming.downloaded swarmer in
- Int64Swarmer.received up
+ CommonSwarming.received up
!counter_pos b.buf b.pos to_read_int;
let new_downloaded =
- Int64Swarmer.downloaded swarmer in
+ CommonSwarming.downloaded swarmer in
c.client_downloaded <- c.client_downloaded ++ (new_downloaded --
old_downloaded);
@@ -95,12 +95,12 @@
download_finished file;
with e ->
- lprintf "FT: Exception %s in Int64Swarmer.received\n"
+ lprintf "FT: Exception %s in CommonSwarming.received\n"
(Printexc2.to_string e)
end;
c.client_reconnect <- true;
(* List.iter (fun (_,_,r) ->
- Int64Swarmer.alloc_range r) d.download_ranges; *)
+ CommonSwarming.alloc_range r) d.download_ranges; *)
(match d.download_ranges with
[] -> lprintf "EMPTY Ranges !!!\n"
Index: mldonkey/src/networks/fileTP/fileTPGlobals.ml
diff -u mldonkey/src/networks/fileTP/fileTPGlobals.ml:1.20
mldonkey/src/networks/fileTP/fileTPGlobals.ml:1.21
--- mldonkey/src/networks/fileTP/fileTPGlobals.ml:1.20 Thu Feb 23 10:50:36 2006
+++ mldonkey/src/networks/fileTP/fileTPGlobals.ml Sun Apr 9 00:27:04 2006
@@ -120,16 +120,16 @@
in
file.file_file.impl_file_size <- size;
let file_temp = Unix32.filename (file_fd file) in
- let kernel = Int64Swarmer.create_swarmer file_temp size min_range_size in
- let swarmer = Int64Swarmer.create kernel (as_file file)
+ let kernel = CommonSwarming.create_swarmer file_temp size min_range_size
in
+ let swarmer = CommonSwarming.create kernel (as_file file)
file_chunk_size in
file.file_swarmer <- Some swarmer;
- Int64Swarmer.set_verified swarmer (fun _ _ ->
+ CommonSwarming.set_verified swarmer (fun _ _ ->
file_must_update (as_file file);
);
file_must_update (as_file file)
(*
- Int64Swarmer.set_writer swarmer (fun offset s pos len ->
+ CommonSwarming.set_writer swarmer (fun offset s pos len ->
(*
lprintf "DOWNLOADED: %d/%d/%d\n" pos len (String.length s);
@@ -218,8 +218,8 @@
if not (List.memq c file.file_clients) then begin
let chunks = [ Int64.zero, file_size file ] in
(*
- let bs = Int64Swarmer.register_uploader file.file_swarmer
- (Int64Swarmer.AvailableRanges chunks) in *)
+ let bs = CommonSwarming.register_uploader file.file_swarmer
+ (CommonSwarming.AvailableRanges chunks) in *)
c.client_downloads <- c.client_downloads @ [{
download_file = file;
download_url = url;
Index: mldonkey/src/networks/fileTP/fileTPHTTP.ml
diff -u mldonkey/src/networks/fileTP/fileTPHTTP.ml:1.20
mldonkey/src/networks/fileTP/fileTPHTTP.ml:1.21
--- mldonkey/src/networks/fileTP/fileTPHTTP.ml:1.20 Thu Feb 23 10:50:36 2006
+++ mldonkey/src/networks/fileTP/fileTPHTTP.ml Sun Apr 9 00:27:04 2006
@@ -261,28 +261,28 @@
let swarmer = match file.file_swarmer with
None -> assert false | Some sw -> sw
in
-(* List.iter (fun (_,_,r) -> Int64Swarmer.free_range r)
+(* List.iter (fun (_,_,r) -> CommonSwarming.free_range r)
d.download_ranges; *)
let old_downloaded =
- Int64Swarmer.downloaded swarmer in
+ CommonSwarming.downloaded swarmer in
begin
try
match d.download_uploader with
None -> assert false
| Some up ->
- Int64Swarmer.received up
+ CommonSwarming.received up
!counter_pos b.buf b.pos to_read_int;
with e ->
- lprintf_nl () "Exception %s in Int64Swarmer.received"
+ lprintf_nl () "Exception %s in CommonSwarming.received"
(Printexc2.to_string e)
end;
c.client_reconnect <- true;
(* List.iter (fun (_,_,r) ->
- Int64Swarmer.alloc_range r) d.download_ranges; *)
+ CommonSwarming.alloc_range r) d.download_ranges; *)
let new_downloaded =
- Int64Swarmer.downloaded swarmer in
+ CommonSwarming.downloaded swarmer in
c.client_downloaded <- c.client_downloaded ++ (new_downloaded --
old_downloaded);
@@ -290,7 +290,7 @@
[] -> lprintf_nl () "EMPTY Ranges!"
| r :: _ ->
(*
- let (x,y) = Int64Swarmer.range_range r in
+ let (x,y) = CommonSwarming.range_range r in
if !verbose then lprintf_nl "Received %Ld [%Ld] (%Ld-%Ld) -> %Ld"
!counter_pos to_read
x y
@@ -315,7 +315,7 @@
lprintf "Ready for next chunk (version %s)\nHEADER:%s\n" http
(String.escaped header);
*)
-(* Int64Swarmer.free_range r; *)
+(* CommonSwarming.free_range r; *)
d.download_ranges <- tail;
(* If we have no more range to receive, disconnect *)
if d.download_ranges = [] then raise Exit;
Index: mldonkey/src/networks/fileTP/fileTPInteractive.ml
diff -u mldonkey/src/networks/fileTP/fileTPInteractive.ml:1.33
mldonkey/src/networks/fileTP/fileTPInteractive.ml:1.34
--- mldonkey/src/networks/fileTP/fileTPInteractive.ml:1.33 Wed Mar 15
20:56:43 2006
+++ mldonkey/src/networks/fileTP/fileTPInteractive.ml Sun Apr 9 00:27:04 2006
@@ -68,7 +68,7 @@
let _ =
file_ops.op_file_cancel <- (fun file ->
- Int64Swarmer.remove_swarmer file.file_swarmer;
+ CommonSwarming.remove_swarmer file.file_swarmer;
file.file_swarmer <- None;
remove_file file;
);
@@ -90,11 +90,11 @@
P.file_download_rate = file_download_rate file.file_file;
P.file_chunks = (match file.file_swarmer with
None -> "" | Some swarmer ->
- Int64Swarmer.verified_bitmap swarmer);
+ CommonSwarming.verified_bitmap swarmer);
P.file_availability =
[network.network_num,(match file.file_swarmer with
None -> "" | Some swarmer ->
- Int64Swarmer.availability swarmer)];
+ CommonSwarming.availability swarmer)];
P.file_format = FormatNotComputed 0;
P.file_chunks_age = [|0|];
P.file_age = file_age file;
Index: mldonkey/src/networks/fileTP/fileTPSSH.ml
diff -u mldonkey/src/networks/fileTP/fileTPSSH.ml:1.8
mldonkey/src/networks/fileTP/fileTPSSH.ml:1.9
--- mldonkey/src/networks/fileTP/fileTPSSH.ml:1.8 Thu Feb 23 10:50:36 2006
+++ mldonkey/src/networks/fileTP/fileTPSSH.ml Sun Apr 9 00:27:04 2006
@@ -92,16 +92,16 @@
None -> assert false
| Some up ->
- let swarmer = Int64Swarmer.uploader_swarmer up in
+ let swarmer = CommonSwarming.uploader_swarmer up in
let old_downloaded =
- Int64Swarmer.downloaded swarmer in
+ CommonSwarming.downloaded swarmer in
- Int64Swarmer.received up
+ CommonSwarming.received up
pos s 0 (String.length s);
let new_downloaded =
- Int64Swarmer.downloaded swarmer in
+ CommonSwarming.downloaded swarmer in
c.client_downloaded <- c.client_downloaded ++ (new_downloaded --
old_downloaded);
@@ -109,12 +109,12 @@
download_finished file;
with e ->
- lprintf "FT: Exception %s in Int64Swarmer.received\n"
+ lprintf "FT: Exception %s in CommonSwarming.received\n"
(Printexc2.to_string e)
end;
c.client_reconnect <- true;
(* List.iter (fun (_,_,r) ->
- Int64Swarmer.alloc_range r) d.download_ranges; *)
+ CommonSwarming.alloc_range r) d.download_ranges; *)
(*
lprintf "READ %Ld\n" (new_downloaded -- old_downloaded);
lprintf "READ: buf_used %d\n" to_read_int;
@@ -122,7 +122,7 @@
(match d.download_ranges with
| (xx,yy,r) :: tail when pos >= xx && pos <= yy ->
- let (x,y) = Int64Swarmer.range_range r in
+ let (x,y) = CommonSwarming.range_range r in
lprintf "Remaining: %Ld-%Ld/%Ld-%Ld\n"
x y xx yy;
if x = y then begin
@@ -138,7 +138,7 @@
lprintf "\n ********** RANGE DOWNLOADED ********** \n";
end
| (xx,yy,r) :: tail ->
- let (x,y) = Int64Swarmer.range_range r in
+ let (x,y) = CommonSwarming.range_range r in
lprintf "Bad range (%Ld): %Ld-%Ld/%Ld-%Ld\n" pos
x y xx yy;
| [] ->
Index: mldonkey/src/networks/fileTP/fileTPTypes.ml
diff -u mldonkey/src/networks/fileTP/fileTPTypes.ml:1.9
mldonkey/src/networks/fileTP/fileTPTypes.ml:1.10
--- mldonkey/src/networks/fileTP/fileTPTypes.ml:1.9 Thu Feb 23 10:50:36 2006
+++ mldonkey/src/networks/fileTP/fileTPTypes.ml Sun Apr 9 00:27:04 2006
@@ -45,7 +45,7 @@
file_file : file CommonFile.file_impl;
file_id : Md4.t;
(* mutable file_name : string;*)
- mutable file_swarmer : Int64Swarmer.t option;
+ mutable file_swarmer : CommonSwarming.t option;
mutable file_clients : client list;
mutable file_filenames : (string * ips_list) list;
mutable file_clients_queue : client Queues.Queue.t;
@@ -56,9 +56,9 @@
download_file : file;
download_url : Url.url;
mutable download_chunks : (int64 * int64) list;
- mutable download_uploader : Int64Swarmer.uploader option;
- mutable download_ranges : (int64 * int64 * Int64Swarmer.range) list;
- mutable download_block : Int64Swarmer.block option;
+ mutable download_uploader : CommonSwarming.uploader option;
+ mutable download_ranges : (int64 * int64 * CommonSwarming.range) list;
+ mutable download_block : CommonSwarming.block option;
}
and tp_proto = {
Index: mldonkey/src/networks/gnutella/gnutellaClients.ml
diff -u mldonkey/src/networks/gnutella/gnutellaClients.ml:1.37
mldonkey/src/networks/gnutella/gnutellaClients.ml:1.38
--- mldonkey/src/networks/gnutella/gnutellaClients.ml:1.37 Wed Jan 11
19:12:35 2006
+++ mldonkey/src/networks/gnutella/gnutellaClients.ml Sun Apr 9 00:27:04 2006
@@ -90,7 +90,7 @@
let download_finished file =
if List.memq file !current_files then begin
file_completed (as_file file);
- Int64Swarmer.remove_swarmer file.file_swarmer;
+ CommonSwarming.remove_swarmer file.file_swarmer;
file.file_swarmer <- None;
(* TODO: maybe this remove file may have a bad effect on sharing *)
GnutellaGlobals.remove_file file;
@@ -107,7 +107,7 @@
(*************************************************************************)
let check_finished swarmer file =
- if Int64Swarmer.check_finished swarmer then
+ if CommonSwarming.check_finished swarmer then
download_finished file
(*************************************************************************)
@@ -243,7 +243,7 @@
| Some swarmer ->
if !verbose_msg_clients then
lprintf "[TTR] set_verifier\n";
- Int64Swarmer.set_verifier swarmer
+ CommonSwarming.set_verifier swarmer
(Verification (Array.map (fun ttr -> TigerTree ttr) array))
);
@@ -274,10 +274,10 @@
begin
try
- Int64Swarmer.received up
+ CommonSwarming.received up
counter_pos b.buf b.pos to_read_int;
with e ->
- lprintf "FT: Exception %s in Int64Swarmer.received\n"
+ lprintf "FT: Exception %s in CommonSwarming.received\n"
(Printexc2.to_string e);
(* TODO: we should pause the download !!! *)
end;
@@ -477,7 +477,7 @@
let up = match d.download_uploader with
None ->
let chunks = [ Int64.zero, file_size file ] in
- let up = Int64Swarmer.register_uploader swarmer
+ let up = CommonSwarming.register_uploader swarmer
(as_client c)
(AvailableRanges chunks) in
d.download_uploader <- Some up;
@@ -500,7 +500,7 @@
List.iter (fun req ->
match req with
RANGEReq (x,y,r) ->
-(* let (x,y) = Int64Swarmer.range_range r in *)
+(* let (x,y) = CommonSwarming.range_range r in *)
lprintf "%Ld-%Ld " x y
| HEADReq ->
lprintf "HEAD"
@@ -509,7 +509,7 @@
) d.download_ranges;
lprintf "\n Current blocks: ";
-(* List.iter (fun b -> Int64Swarmer.print_block b) d.download_blocks;
*)
+(* List.iter (fun b -> CommonSwarming.print_block b)
d.download_blocks; *)
lprintf "\n\nFinding Range: \n";
end;
let range =
@@ -518,13 +518,13 @@
match d.download_block with
None ->
if !verbose_swarming then lprintf "No block\n";
- (try Int64Swarmer.verify_one_chunk swarmer with _ -> ());
- let b = Int64Swarmer.find_block up in
+ (try CommonSwarming.verify_one_chunk swarmer with _ ->
());
+ let b = CommonSwarming.find_block up in
if !verbose_swarming then begin
lprintf "GOT BLOCK:\n";
- Int64Swarmer.print_uploaders swarmer;
- lprintf "Block Found: "; Int64Swarmer.print_block b;
+ CommonSwarming.print_uploaders swarmer;
+ lprintf "Block Found: "; CommonSwarming.print_block
b;
end;
d.download_block <- Some b;
@@ -532,15 +532,15 @@
| Some b ->
(*
if !verbose_swarming then begin
- lprintf "Current Block: "; Int64Swarmer.print_block b;
+ lprintf "Current Block: "; CommonSwarming.print_block b;
end;
*)
try
- let (x,y,r) = Int64Swarmer.find_range up in
+ let (x,y,r) = CommonSwarming.find_range up in
if !verbose_swarming then begin
lprintf "GOT RANGE:\n";
- Int64Swarmer.print_uploaders swarmer;
+ CommonSwarming.print_uploaders swarmer;
end;
d.download_ranges <- d.download_ranges @
[RANGEReq (x,y,r)];
@@ -603,7 +603,7 @@
None -> ()
| Some up ->
d.download_uploader <- None;
- Int64Swarmer.unregister_uploader up;
+ CommonSwarming.unregister_uploader up;
d.download_block <- None;
d.download_ranges <- [];
) c.client_downloads;
Index: mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml
diff -u mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml:1.25
mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml:1.26
--- mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml:1.25 Mon Jan
9 00:22:35 2006
+++ mldonkey/src/networks/gnutella/gnutellaComplexOptions.ml Sun Apr 9
00:27:04 2006
@@ -140,8 +140,8 @@
(match file.file_swarmer with
None -> ()
| Some swarmer ->
- Int64Swarmer.value_to_swarmer swarmer assocs;
- Int64Swarmer.set_verifier swarmer (
+ CommonSwarming.value_to_swarmer swarmer assocs;
+ CommonSwarming.set_verifier swarmer (
match file.file_ttr with
None -> ForceVerification
| Some ttr ->
@@ -183,7 +183,7 @@
(* "file_present_chunks", List
(List.map (fun (i1,i2) ->
SmallList [int64_to_value i1; int64_to_value i2])
- (Int64Swarmer.present_chunks file.file_swarmer));
+ (CommonSwarming.present_chunks file.file_swarmer));
*)
]
in
@@ -196,7 +196,7 @@
match file.file_swarmer with
None -> assocs
| Some swarmer ->
- Int64Swarmer.swarmer_to_value swarmer assocs
+ CommonSwarming.swarmer_to_value swarmer assocs
(*
Index: mldonkey/src/networks/gnutella/gnutellaGlobals.ml
diff -u mldonkey/src/networks/gnutella/gnutellaGlobals.ml:1.35
mldonkey/src/networks/gnutella/gnutellaGlobals.ml:1.36
--- mldonkey/src/networks/gnutella/gnutellaGlobals.ml:1.35 Wed Jan 11
19:12:35 2006
+++ mldonkey/src/networks/gnutella/gnutellaGlobals.ml Sun Apr 9 00:27:04 2006
@@ -325,10 +325,10 @@
in
if !verbose then
lprintf "SET SIZE : %Ld\n" file_size;
- let kernel = Int64Swarmer.create_swarmer file_temp file_size
+ let kernel = CommonSwarming.create_swarmer file_temp file_size
(Int64.of_int (256 * 1024)) in
- let swarmer = Int64Swarmer.create kernel (as_file file) megabyte in
- Int64Swarmer.set_verifier swarmer ForceVerification;
+ let swarmer = CommonSwarming.create kernel (as_file file) megabyte in
+ CommonSwarming.set_verifier swarmer ForceVerification;
(* TODO: we could generalize this approach to any UID that is computed
on the complete file (md5, sha1,...) *)
@@ -336,7 +336,7 @@
List.iter (fun uid ->
match Uid.to_uid uid with
(Sha1 _) as uid ->
- Int64Swarmer.set_verifier swarmer (Verification [| uid |])
+ CommonSwarming.set_verifier swarmer (Verification [| uid |])
| _ ->()) file_uids;
file.file_swarmer <- Some swarmer;
current_files := file :: !current_files;
@@ -442,8 +442,8 @@
lprintf "Adding file to client\n";
if not (List.memq c file.file_clients) then begin
let chunks = [ Int64.zero, file_size file ] in
-(* let up = Int64Swarmer.register_uploader file.file_swarmer
- (Int64Swarmer.AvailableRanges chunks) in *)
+(* let up = CommonSwarming.register_uploader file.file_swarmer
+ (CommonSwarming.AvailableRanges chunks) in *)
c.client_downloads <- c.client_downloads @ [{
download_file = file;
download_uri = index;
Index: mldonkey/src/networks/gnutella/gnutellaHandler.ml
diff -u mldonkey/src/networks/gnutella/gnutellaHandler.ml:1.10
mldonkey/src/networks/gnutella/gnutellaHandler.ml:1.11
--- mldonkey/src/networks/gnutella/gnutellaHandler.ml:1.10 Mon Jan 9
00:22:35 2006
+++ mldonkey/src/networks/gnutella/gnutellaHandler.ml Sun Apr 9 00:27:04 2006
@@ -282,7 +282,7 @@
failwith "GnutellaHandler: Recover with old size 0 not
implemented"
(*
- Int64Swarmer.set_size file.file_swarmer f.Q.size;
+ CommonSwarming.set_size file.file_swarmer f.Q.size;
file_must_update file; *)
end;
Index: mldonkey/src/networks/gnutella/gnutellaInteractive.ml
diff -u mldonkey/src/networks/gnutella/gnutellaInteractive.ml:1.50
mldonkey/src/networks/gnutella/gnutellaInteractive.ml:1.51
--- mldonkey/src/networks/gnutella/gnutellaInteractive.ml:1.50 Thu Jan 26
10:34:54 2006
+++ mldonkey/src/networks/gnutella/gnutellaInteractive.ml Sun Apr 9
00:27:04 2006
@@ -242,7 +242,7 @@
match file.file_swarmer with
None -> [CommonFile.as_file impl]
| Some swarmer ->
- Int64Swarmer.subfiles swarmer)
+ CommonSwarming.subfiles swarmer)
;
file_ops.op_file_active_sources <- file_ops.op_file_all_sources;
file_ops.op_file_check <- (fun file ->
@@ -252,7 +252,7 @@
match file.file_ttr with
None -> failwith "No TTR for verification"
| Some ttt ->
- Int64Swarmer.verify_all_chunks swarmer true
+ CommonSwarming.verify_all_chunks swarmer true
);
file_ops.op_file_recover <- (fun file ->
@@ -272,13 +272,13 @@
let _ =
file_ops.op_file_cancel <- (fun file ->
- Int64Swarmer.remove_swarmer file.file_swarmer;
+ CommonSwarming.remove_swarmer file.file_swarmer;
file.file_swarmer <- None;
remove_file file;
GnutellaProto.cancel_recover_files file
);
file_ops.op_file_commit <- (fun file new_name ->
- Int64Swarmer.remove_swarmer file.file_swarmer;
+ CommonSwarming.remove_swarmer file.file_swarmer;
file.file_swarmer <- None;
);
file_ops.op_file_info <- (fun file ->
@@ -289,11 +289,11 @@
P.file_chunks = (match file.file_swarmer with
None -> "" | Some swarmer ->
- Int64Swarmer.verified_bitmap swarmer);
+ CommonSwarming.verified_bitmap swarmer);
P.file_availability = [network.network_num,
(match file.file_swarmer with
None -> "" | Some swarmer ->
- Int64Swarmer.availability swarmer)];
+ CommonSwarming.availability swarmer)];
P.file_chunks_age = [|0|];
P.file_last_seen = BasicSocket.last_time ();
Index: mldonkey/src/networks/gnutella/gnutellaProtocol.ml
diff -u mldonkey/src/networks/gnutella/gnutellaProtocol.ml:1.19
mldonkey/src/networks/gnutella/gnutellaProtocol.ml:1.20
--- mldonkey/src/networks/gnutella/gnutellaProtocol.ml:1.19 Wed Jan 11
19:12:35 2006
+++ mldonkey/src/networks/gnutella/gnutellaProtocol.ml Sun Apr 9 00:27:04 2006
@@ -452,7 +452,7 @@
None -> assert false | Some sw -> sw
in
let chunks = [ Int64.zero, file_size file ] in
- let bs = Int64Swarmer.register_uploader swarmer
+ let bs = CommonSwarming.register_uploader swarmer
(as_client c)
(AvailableRanges chunks) in
d.download_uploader <- Some bs
Index: mldonkey/src/networks/gnutella/gnutellaTypes.ml
diff -u mldonkey/src/networks/gnutella/gnutellaTypes.ml:1.17
mldonkey/src/networks/gnutella/gnutellaTypes.ml:1.18
--- mldonkey/src/networks/gnutella/gnutellaTypes.ml:1.17 Mon Nov 1
11:23:01 2004
+++ mldonkey/src/networks/gnutella/gnutellaTypes.ml Sun Apr 9 00:27:04 2006
@@ -107,7 +107,7 @@
}
and download_request =
- RANGEReq of int64 * int64 * Int64Swarmer.range
+ RANGEReq of int64 * int64 * CommonSwarming.range
| HEADReq
| TTRReq of int
@@ -116,7 +116,7 @@
file_file : file CommonFile.file_impl;
file_temp : string;
mutable file_name : string;
- mutable file_swarmer : Int64Swarmer.t option;
+ mutable file_swarmer : CommonSwarming.t option;
mutable file_clients : client list;
mutable file_uids : Uid.t list;
mutable file_searches : local_search list;
@@ -130,9 +130,9 @@
download_file : file;
mutable download_uri : GnutellaNetwork.file_uri;
mutable download_chunks : (int64 * int64) list;
- mutable download_uploader : Int64Swarmer.uploader option;
+ mutable download_uploader : CommonSwarming.uploader option;
mutable download_ranges : download_request list;
- mutable download_block : Int64Swarmer.block option;
+ mutable download_block : CommonSwarming.block option;
mutable download_head_requested : bool;
mutable download_ttr_requested : bool;
}
@@ -182,4 +182,4 @@
let plugin_enable_hooks = ref ([] : (bool ref -> unit) list)
-let plugin_disable_hooks = ref [(fun () -> ())]
\ No newline at end of file
+let plugin_disable_hooks = ref [(fun () -> ())]
Index: mldonkey/src/networks/gnutella2/g2Handler.ml
diff -u mldonkey/src/networks/gnutella2/g2Handler.ml:1.17
mldonkey/src/networks/gnutella2/g2Handler.ml:1.18
--- mldonkey/src/networks/gnutella2/g2Handler.ml:1.17 Wed Jan 11 19:12:35 2006
+++ mldonkey/src/networks/gnutella2/g2Handler.ml Sun Apr 9 00:27:04 2006
@@ -524,7 +524,7 @@
failwith "G2Handler: recover from size 0 not
implemented"
(*
file.file_file.impl_file_size <- size;
- Int64Swarmer.set_size file.file_swarmer size;
+ CommonSwarming.set_size file.file_swarmer size;
file_must_update file;
*)
end);