P2P: refactor for less indenting
This commit is contained in:
parent
517893f707
commit
6a1265255f
@ -218,11 +218,9 @@ module Make (P: PARAMS) = struct
|
||||
(* send a message over a TCP socket *)
|
||||
let send_msg ?crypt fd buf msg =
|
||||
Lwt.catch begin fun () ->
|
||||
match Data_encoding.Binary.write msg_encoding msg buf hdrlen with
|
||||
| None -> Error_monad.fail Encoding_error
|
||||
| Some len ->
|
||||
match crypt with
|
||||
| None ->
|
||||
match crypt, Data_encoding.Binary.write msg_encoding msg buf hdrlen with
|
||||
| _, None -> Error_monad.fail Encoding_error
|
||||
| None, Some len ->
|
||||
if len > maxlen then Error_monad.fail Message_too_big
|
||||
else begin
|
||||
EndianBigstring.BigEndian.set_int16 buf 0 (len - hdrlen) ;
|
||||
@ -230,7 +228,7 @@ module Make (P: PARAMS) = struct
|
||||
Lwt_utils.write_mbytes ~len fd buf >>= fun () ->
|
||||
Error_monad.return len
|
||||
end
|
||||
| Some crypt ->
|
||||
| Some crypt, Some len ->
|
||||
let encbuf = crypt (MBytes.sub buf hdrlen (len - hdrlen)) in
|
||||
let len = MBytes.length encbuf in
|
||||
if len > maxlen then Error_monad.fail Message_too_big
|
||||
@ -244,7 +242,6 @@ module Make (P: PARAMS) = struct
|
||||
end
|
||||
(fun exn -> Lwt.return @@ Error_monad.error_exn exn)
|
||||
|
||||
|
||||
(* The (internal) type of network events, those dispatched from peer
|
||||
workers to the net and others internal to net workers. *)
|
||||
type event =
|
||||
|
Loading…
Reference in New Issue
Block a user