Skip to content

Commit

Permalink
Encoder for ACK
Browse files Browse the repository at this point in the history
Signed-off-by: Romain Calascibetta <[email protected]>
  • Loading branch information
Julow authored and dinosaure committed Nov 22, 2023
1 parent 96d2111 commit da063d9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/not-so-smart/find_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ let find_common (type t) scheduler io flow cfg
consume_shallow_list scheduler io flow cfg None hex ctx
>>= fun _shallows ->
let rec loop () =
Smart_flow.run scheduler raise io flow Smart.(recv ctx ack)
Smart_flow.run scheduler raise io flow
Smart.(recv ctx recv_ack)
>>| Smart.Negotiation.map ~f:of_hex
>>= fun ack ->
match ack with
Expand Down Expand Up @@ -253,7 +254,7 @@ let find_common (type t) scheduler io flow cfg
let rec go () =
if !flushes > 0 || cfg.multi_ack = `Some || cfg.multi_ack = `Detailed
then (
Smart_flow.run scheduler raise io flow Smart.(recv ctx ack)
Smart_flow.run scheduler raise io flow Smart.(recv ctx recv_ack)
>>| Smart.Negotiation.map ~f:of_hex
>>= fun ack ->
match ack with
Expand Down
28 changes: 28 additions & 0 deletions src/not-so-smart/protocol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1227,4 +1227,32 @@ module Encoder = struct
flush (go buffer (off + len) (max - len)) encoder
in
go payload 0 (String.length payload) encoder

let encode_acks encoder acks =
(* TODO: Remove NACK from [Negotiation.t]. *)
let write_ack ack encoder =
let write_ack uid suffix =
write encoder "ACK";
write_space encoder;
write encoder uid;
match suffix with
| None -> ()
| Some s ->
write_space encoder;
write encoder s
in
match ack with
| Negotiation.ACK uid -> write_ack uid None
| ACK_continue uid -> write_ack uid (Some "continue")
| ACK_ready uid -> write_ack uid (Some "ready")
| ACK_common uid -> write_ack uid (Some "common")
| NAK -> write encoder "NAK"
in
let rec go acks encoder =
match acks with
| [] ->
delayed_write_pkt (write_ack Negotiation.NAK) (flush kdone) encoder
| hd :: tl -> delayed_write_pkt (write_ack hd) (go tl) encoder
in
go acks encoder
end
3 changes: 3 additions & 0 deletions src/not-so-smart/protocol.mli
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ module Encoder : sig
val encode_flush : encoder -> error state
val encode_commands : encoder -> (string, string) Commands.t -> error state

val encode_acks : encoder -> string Negotiation.t list -> error state
(** Sends a list of [ACK]s and terminate with a [NAK]. *)

val encode_advertised_refs :
encoder -> (string, string) Advertised_refs.t -> error state

Expand Down
5 changes: 4 additions & 1 deletion src/not-so-smart/smart.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Witness = struct
| Commands : (string, string) Commands.t send
| Send_pack : { side_band : bool; stateless : bool } -> string send
| Advertised_refs : (string, string) Advertised_refs.t send
| Acks : string Negotiation.t list send

type 'a recv =
| Advertised_refs : (string, string) Advertised_refs.t recv
Expand Down Expand Up @@ -72,6 +73,7 @@ module Value = struct
encode_pack ~side_band ~stateless encoder v
| Flush -> encode_flush encoder
| Advertised_refs -> encode_advertised_refs encoder v
| Acks -> encode_acks encoder v
in
let rec translate_to_state_t = function
| Encoder.Done -> State.Return ()
Expand Down Expand Up @@ -152,7 +154,8 @@ let recv_pack ?(push_stdout = ignore) ?(push_stderr = ignore) side_band =
let recv_flush : _ recv = Flush
let status sideband = Status sideband
let flush : _ send = Flush
let ack = Ack
let recv_ack : _ recv = Ack
let send_acks : _ send = Acks
let shallows = Shallows

let send_pack ?(stateless = false) side_band =
Expand Down
3 changes: 2 additions & 1 deletion src/not-so-smart/smart.mli
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ val recv_pack :

val recv_flush : unit recv
val recv_commands : (string, string) Commands.t option recv
val ack : string Negotiation.t recv
val send_acks : string Negotiation.t list send
val recv_ack : string Negotiation.t recv
val shallows : string Shallow.t list recv
val status : bool -> string Status.t recv
val packet : trim:bool -> string recv
Expand Down

0 comments on commit da063d9

Please sign in to comment.