Shell: indentation

This commit is contained in:
Pierre Chambart 2018-06-26 20:01:46 +02:00
parent 3da1e56133
commit 3dd4d61b71

View File

@ -469,57 +469,57 @@ end = struct
let worker_loop state = let worker_loop state =
let shutdown = Lwt_canceler.cancelation state.canceler in let shutdown = Lwt_canceler.cancelation state.canceler in
let rec loop state = let rec loop state =
let timeout = compute_timeout state in let timeout = compute_timeout state in
Lwt.choose Lwt.choose
[ (state.events >|= fun _ -> ()) ; timeout ; shutdown ] >>= fun () -> [ (state.events >|= fun _ -> ()) ; timeout ; shutdown ] >>= fun () ->
if Lwt.state shutdown <> Lwt.Sleep then if Lwt.state shutdown <> Lwt.Sleep then
lwt_debug "terminating" >>= fun () -> lwt_debug "terminating" >>= fun () ->
Lwt.return_unit Lwt.return_unit
else if Lwt.state state.events <> Lwt.Sleep then else if Lwt.state state.events <> Lwt.Sleep then
let now = Unix.gettimeofday () in let now = Unix.gettimeofday () in
state.events >>= fun events -> state.events >>= fun events ->
state.events <- Lwt_pipe.pop_all state.queue ; state.events <- Lwt_pipe.pop_all state.queue ;
Lwt_list.iter_s (process_event state now) events >>= fun () -> Lwt_list.iter_s (process_event state now) events >>= fun () ->
loop state loop state
else else
lwt_debug "timeout" >>= fun () -> lwt_debug "timeout" >>= fun () ->
let now = Unix.gettimeofday () in let now = Unix.gettimeofday () in
let active_peers = Request.active state.param in let active_peers = Request.active state.param in
let requests = let requests =
Table.fold Table.fold
(fun key { peers ; next_request ; delay } acc -> (fun key { peers ; next_request ; delay } acc ->
if next_request > now +. 0.2 then if next_request > now +. 0.2 then
acc acc
else
let remaining_peers =
P2p_peer.Set.inter peers active_peers in
if P2p_peer.Set.is_empty remaining_peers &&
not (P2p_peer.Set.is_empty peers) then
( Table.remove state.pending key ; acc )
else else
let requested_peer = let remaining_peers =
P2p_peer.Id.Set.random_elt P2p_peer.Set.inter peers active_peers in
(if P2p_peer.Set.is_empty remaining_peers if P2p_peer.Set.is_empty remaining_peers &&
then active_peers not (P2p_peer.Set.is_empty peers) then
else remaining_peers) in ( Table.remove state.pending key ; acc )
let next = { peers = remaining_peers ; else
next_request = now +. delay ; let requested_peer =
delay = delay *. 1.5 } in P2p_peer.Id.Set.random_elt
Table.replace state.pending key next ; (if P2p_peer.Set.is_empty remaining_peers
let requests = then active_peers
try key :: P2p_peer.Map.find requested_peer acc else remaining_peers) in
with Not_found -> [key] in let next = { peers = remaining_peers ;
P2p_peer.Map.add requested_peer requests acc) next_request = now +. delay ;
state.pending P2p_peer.Map.empty in delay = delay *. 1.5 } in
P2p_peer.Map.iter (Request.send state.param) requests ; Table.replace state.pending key next ;
P2p_peer.Map.fold begin fun peer request acc -> let requests =
acc >>= fun () -> try key :: P2p_peer.Map.find requested_peer acc
Lwt_list.iter_s (fun key -> with Not_found -> [key] in
lwt_debug "requested %a from %a" P2p_peer.Map.add requested_peer requests acc)
Hash.pp key P2p_peer.Id.pp_short peer) state.pending P2p_peer.Map.empty in
request P2p_peer.Map.iter (Request.send state.param) requests ;
end requests Lwt.return_unit >>= fun () -> P2p_peer.Map.fold begin fun peer request acc ->
loop state acc >>= fun () ->
Lwt_list.iter_s (fun key ->
lwt_debug "requested %a from %a"
Hash.pp key P2p_peer.Id.pp_short peer)
request
end requests Lwt.return_unit >>= fun () ->
loop state
in in
loop state loop state