@@ -241,7 +241,7 @@ let in_window cb seg =
241
241
let seq = seg.Segment. seq
242
242
and max = Sequence. addi cb.rcv_nxt cb.rcv_wnd
243
243
in
244
- match Cstruct. length seg.Segment. payload , cb.rcv_wnd with
244
+ match seg.Segment. payload_len , cb.rcv_wnd with
245
245
| 0 , 0 -> Sequence. equal seq cb.rcv_nxt
246
246
| 0 , _ -> Sequence. less_equal cb.rcv_nxt seq && Sequence. less seq max
247
247
| _ , 0 -> false
@@ -415,15 +415,15 @@ let di3_newackstuff now id conn ourfinisacked ack =
415
415
(* : If this socket has previously emitted a [[FIN]] segment and the
416
416
[[FIN]] has now been [[ACK]]ed, decrease [[snd_wnd]] by the length of
417
417
the send queue and clear the send queue.:*)
418
- cb.snd_wnd - Cstruct. lenv conn.sndq, []
418
+ cb.snd_wnd - Rope. length conn.sndq, Rope. empty
419
419
else
420
420
(* : Otherwise, reduce the send window by the amound of data acknowledged
421
421
as it is now consuming space on the receiver's receive queue. Remove
422
422
the acknowledged bytes from the send queue as they will never need to
423
423
be retransmitted.:*)
424
424
let acked = Sequence. window ack cb.snd_una in
425
425
cb.snd_wnd - acked,
426
- List. rev ( Cstruct. shiftv ( List. rev conn.sndq) acked)
426
+ Rope. shift conn.sndq acked
427
427
in
428
428
(* : Update the control block :*)
429
429
let cb' =
@@ -510,7 +510,7 @@ let di3_ackstuff now id conn seg ourfinisacked fin ack =
510
510
from the other end, these may all contain the same acknowledgement number
511
511
and trigger the retransmit logic erroneously. :*)
512
512
let maybe_dup_ack =
513
- Cstruct. length seg.payload = 0 && win = cb.snd_wnd &&
513
+ seg.payload_len = 0 && win = cb.snd_wnd &&
514
514
match cb.tt_rexmt with Some ((Rexmt , _ ), _ ) -> true | _ -> false
515
515
in
516
516
(* It turns out since some time the first FIN(+ACK) doesn't account for
@@ -636,11 +636,12 @@ let di3_datastuff_really now the_ststuff conn seg _bsd_fast_path ourfinisacked f
636
636
urgent data in the segment. :*)
637
637
let trim_amt_left =
638
638
if Sequence. greater cb.rcv_nxt seg.Segment. seq then
639
- Int. min (Sequence. window cb.rcv_nxt seg.seq) ( Cstruct. length seg.payload)
639
+ Int. min (Sequence. window cb.rcv_nxt seg.seq) seg.payload_len
640
640
else
641
641
0
642
642
in
643
- let data_trimmed_left = Cstruct. shift seg.payload trim_amt_left in
643
+ let data_trimmed_left = Rope. of_css seg.payload in
644
+ let data_trimmed_left = Rope. shift data_trimmed_left trim_amt_left in
644
645
let seq_trimmed = Sequence. addi seg.seq trim_amt_left in
645
646
(* : Trimmed data starts at [[seq_trimmed]] :*)
646
647
(* : Trim any data outside the receive window from the right hand edge. If all
@@ -650,10 +651,11 @@ let di3_datastuff_really now the_ststuff conn seg _bsd_fast_path ourfinisacked f
650
651
here because there is still urgent data to be received, but now in a future
651
652
segment. :*)
652
653
let data_trimmed_left_right =
653
- Cstruct. sub data_trimmed_left 0 (Int. min cb.rcv_wnd (Cstruct. length data_trimmed_left))
654
+ let len = Int. min cb.rcv_wnd (Rope. length data_trimmed_left) in
655
+ Rope. chop data_trimmed_left len
654
656
in
655
657
let fin_trimmed =
656
- fin && Cstruct . length data_trimmed_left_right == Cstruct . length data_trimmed_left
658
+ fin && Rope . length data_trimmed_left_right == Rope . length data_trimmed_left
657
659
in
658
660
(* : Build trimmed segment to place on reassembly queue. If urgent data is in
659
661
this segment and the socket is not doing inline delivery (and hence the
@@ -672,7 +674,7 @@ let di3_datastuff_really now the_ststuff conn seg _bsd_fast_path ourfinisacked f
672
674
the conditions below. :*)
673
675
let rseq_trimmed =
674
676
Sequence. addi seq_trimmed
675
- (Cstruct . length data_trimmed_left_right + (if fin_trimmed then 1 else 0 ))
677
+ (Rope . length data_trimmed_left_right + (if fin_trimmed then 1 else 0 ))
676
678
in
677
679
let (conn', fin_reass, out), cont =
678
680
if
@@ -683,7 +685,7 @@ let di3_datastuff_really now the_ststuff conn seg _bsd_fast_path ourfinisacked f
683
685
(* : Only need to acknowledge the segment if there is new in-window data
684
686
(including urgent data) or a valid [[FIN]] :*)
685
687
let have_stuff_to_ack =
686
- Cstruct . length data_trimmed_left_right > 0 || fin_trimmed
688
+ Rope . length data_trimmed_left_right > 0 || fin_trimmed
687
689
in
688
690
(* : If the socket is connected, has data to [[ACK]] but no [[FIN]] to
689
691
[[ACK]], the reassembly queue is empty, the socket is not currently
@@ -700,10 +702,10 @@ let di3_datastuff_really now the_ststuff conn seg _bsd_fast_path ourfinisacked f
700
702
let t_segq, r = Reassembly_queue. maybe_take cb.t_segq rseq_trimmed in
701
703
(* Length (in sequence space) of reassembled data, counting a [[FIN]] as
702
704
one byte and including any out-of-line urgent data previously removed *)
703
- let data_reass, fin_reass0 = Option. value ~default: (Cstruct . empty, false ) r in
704
- let data = Cstruct. append data_trimmed_left_right data_reass in
705
+ let data_reass, fin_reass0 = Option. value ~default: (Rope . empty, false ) r in
706
+ let data = Rope. concat data_trimmed_left_right data_reass in
705
707
let fin_reass_trimmed = fin_trimmed || fin_reass0 in
706
- let data_len = Cstruct . length data + if fin_reass_trimmed then 1 else 0 in
708
+ let data_len = Rope . length data + if fin_reass_trimmed then 1 else 0 in
707
709
(* : Add the reassembled data to the receive queue and increment [[rcv_nxt]]
708
710
to mark the sequence number of the byte past the last byte in the
709
711
receive queue:*)
@@ -723,7 +725,7 @@ let di3_datastuff_really now the_ststuff conn seg _bsd_fast_path ourfinisacked f
723
725
(* : Set if not delaying an [[ACK]] and have stuff to [[ACK]] :*)
724
726
not delay_ack && have_stuff_to_ack
725
727
and rcv_nxt = Sequence. addi cb.rcv_nxt data_len
726
- and rcv_wnd = cb.rcv_wnd - (Cstruct . length data)
728
+ and rcv_wnd = cb.rcv_wnd - (Rope . length data)
727
729
in
728
730
let control_block = {
729
731
cb with
@@ -733,7 +735,7 @@ let di3_datastuff_really now the_ststuff conn seg _bsd_fast_path ourfinisacked f
733
735
rcv_nxt ;
734
736
rcv_wnd ;
735
737
}
736
- and rcvq = data :: conn.rcvq
738
+ and rcvq = Rope. concat conn.rcvq data
737
739
in
738
740
({ conn with control_block ; rcvq }, fin_reass_trimmed, [] ), true
739
741
(* : Case (2) The segment contains new out-of-order in-window data, possibly
@@ -743,7 +745,7 @@ let di3_datastuff_really now the_ststuff conn seg _bsd_fast_path ourfinisacked f
743
745
else if
744
746
Sequence. greater seq_trimmed cb.rcv_nxt &&
745
747
Sequence. less seq_trimmed (Sequence. addi cb.rcv_nxt cb.rcv_wnd) &&
746
- Cstruct . length data_trimmed_left_right + (if fin_trimmed then 1 else 0 ) > 0 &&
748
+ Rope . length data_trimmed_left_right + (if fin_trimmed then 1 else 0 ) > 0 &&
747
749
cb.rcv_wnd > 0
748
750
then
749
751
(* : Hack: assertion used to share values with later conditions :*)
@@ -762,7 +764,7 @@ let di3_datastuff_really now the_ststuff conn seg _bsd_fast_path ourfinisacked f
762
764
segment) is used in the guard to ensure this really was a pure [[ACK]]
763
765
segment. :*)
764
766
else if Sequence. equal seq_trimmed cb.rcv_nxt &&
765
- Cstruct. length seg.payload + (if fin then 1 else 0 ) = 0
767
+ seg.payload_len + (if fin then 1 else 0 ) = 0
766
768
then
767
769
(* : Hack: assertion used to share values with later conditions :*)
768
770
let fin_reass = false in (* Have not received a FIN *)
@@ -823,7 +825,7 @@ let di3_datastuff now the_ststuff conn seg ourfinisacked fin ack =
823
825
((Sequence. greater ack cb.snd_una && Sequence. less_equal ack cb.snd_max &&
824
826
cb.snd_cwnd > = cb.snd_wnd && cb.t_dupacks < 3 )
825
827
|| (Sequence. equal ack cb.snd_una && Reassembly_queue. is_empty cb.t_segq &&
826
- Cstruct. length seg.payload < conn.rcvbufsize - Cstruct. lenv conn.rcvq))
828
+ seg.payload_len < conn.rcvbufsize - Rope. length conn.rcvq))
827
829
in
828
830
(* : Update the send window using the received segment if the segment will not be processed by
829
831
BSD's fast path, has the [[ACK]] flag set, is not to the right of the window, and either:
@@ -846,7 +848,7 @@ let di3_datastuff now the_ststuff conn seg ourfinisacked fin ack =
846
848
(Sequence. less cb.snd_wl2 ack || Sequence. equal cb.snd_wl2 ack && win > cb.snd_wnd)))
847
849
in
848
850
let seq_trimmed =
849
- Sequence. max seg.seq (Sequence. min cb.rcv_nxt (Sequence. addi seg.seq ( Cstruct. length seg.payload) ))
851
+ Sequence. max seg.seq (Sequence. min cb.rcv_nxt (Sequence. addi seg.seq seg.payload_len ))
850
852
in
851
853
(* : Write back the window updates :*)
852
854
let control_block =
@@ -923,7 +925,7 @@ let deliver_in_3 m now id conn seg flag ack =
923
925
let fin = flag = Some `Fin in
924
926
(* PAWS, timers, rcv_wnd may have opened! updates fin_wait_2 timer *)
925
927
let cb = conn.control_block in
926
- let wesentafin = Sequence. greater cb.snd_max (Sequence. addi cb.snd_una (Cstruct. lenv conn.sndq)) in
928
+ let wesentafin = Sequence. greater cb.snd_max (Sequence. addi cb.snd_una (Rope. length conn.sndq)) in
927
929
let ourfinisacked = wesentafin && Sequence. greater_equal ack cb.snd_max in
928
930
let control_block = di3_topstuff now conn in
929
931
(* ACK processing *)
@@ -1060,7 +1062,7 @@ let handle_conn t now id conn seg =
1060
1062
let * () =
1061
1063
guard (in_window conn.control_block seg)
1062
1064
(`Drop (fun () -> Fmt. str " in_window seq %a seql %u rcv_nxt %a rcv_wnd %u"
1063
- Sequence. pp seg.Segment. seq ( Cstruct. length seg.payload)
1065
+ Sequence. pp seg.Segment. seq seg.payload_len
1064
1066
Sequence. pp conn.control_block.rcv_nxt conn.control_block.rcv_wnd))
1065
1067
in
1066
1068
(* RFC5961: challenge acks for SYN and (RST where seq != rcv_nxt), keep state *)
@@ -1109,7 +1111,7 @@ let handle_buf t now ~src ~dst data =
1109
1111
| Ok (seg , id ) ->
1110
1112
Tracing. debug (fun m -> m " %a [%a] handle_buf %u %s"
1111
1113
Connection. pp id Mtime. pp now
1112
- ( Cstruct. length seg.payload)
1114
+ seg.payload_len
1113
1115
(Base64. encode_string (Cstruct. to_string data)));
1114
1116
(* deliver_in_3a deliver_in_4 are done now! *)
1115
1117
let t', outs = handle_segment t now id seg in
@@ -1125,8 +1127,8 @@ let handle_buf t now ~src ~dst data =
1125
1127
| Some s ->
1126
1128
s.tcp_state = Established ,
1127
1129
true ,
1128
- Cstruct. lenv s.rcvq > 0 ,
1129
- Cstruct. lenv s.sndq < s.sndbufsize,
1130
+ Rope. length s.rcvq > 0 ,
1131
+ Rope. length s.sndq < s.sndbufsize,
1130
1132
Some s.rcv_notify, Some s.snd_notify
1131
1133
in
1132
1134
match was_established, is_established, was_present, is_present with
0 commit comments