logarion/lib/peers.ml

26 lines
961 B
OCaml

let text_dir = Filename.concat (File_store.txtdir ()) "peers"
type t = { path: string; pack: Header_pack.t }
let fold fn init = match Sys.readdir text_dir with
| exception (Sys_error msg) -> prerr_endline msg; init
| dirs ->
let read_pack init path =
let fullpath = Filename.concat text_dir path in
if Sys.is_directory fullpath then begin
let pack_path = Filename.concat fullpath "index.pck" in
match Sys.file_exists pack_path with
| false -> Printf.eprintf "Missing index.pck for %s\n" path; init
| true -> match Header_pack.of_string (File_store.to_string pack_path) with
| Error s -> Printf.eprintf "%s %s\n" s pack_path; init
| Ok pack -> fn init { path; pack }
end else init
in
Array.fold_left read_pack init dirs
let scheme url =
let colon_idx = String.index_from url 0 ':' in
let scheme = String.sub url 0 colon_idx in
(* let remain = String.(sub url (colon_idx+1) (length url - length scheme - 1)) in*)
scheme