@@ -36,6 +36,7 @@ Connection::Connection(TCP& host, Socket local, Socket remote, ConnectCallback c
3636 cb{host_.window_size ()},
3737 read_request (nullptr ),
3838 writeq(),
39+ recv_wnd_getter{TCP::global_recv_wnd},
3940 on_connect_{std::move (callback)},
4041 on_disconnect_ ({this , &Connection::default_on_disconnect}),
4142 rtx_timer({this , &Connection::rtx_timeout}),
@@ -323,7 +324,9 @@ Packet_view_ptr Connection::create_outgoing_packet()
323324 // Set Destination (remote)
324325 packet->set_destination (remote_);
325326
326- packet->set_win (std::min ((cb.RCV .WND >> cb.RCV .wind_shift ), (uint32_t )default_window_size));
327+ const auto recv_wnd = recv_wnd_getter ();
328+ // printf("recv_wnd %u\n", recv_wnd);
329+ packet->set_win (cb.RCV .WND >> cb.RCV .wind_shift );
327330
328331 if (cb.SND .TS_OK )
329332 packet->add_tcp_option_aligned <Option::opt_ts_align>(host_.get_ts_value (), cb.get_ts_recent ());
@@ -683,6 +686,15 @@ void Connection::recv_data(const Packet_view& in)
683686{
684687 Expects (in.has_tcp_data ());
685688
689+ // just drop the packet if we don't have a recv wnd.
690+ // this is really awful and probably unnecesseary,
691+ // since it could be that we already preallocated that memory in our vector.
692+ // i also think we shouldn't reach this point due to State::check_seq checking
693+ // if we're inside the window. if packet is out of order tho we can change the RCV wnd (i think).
694+ if (recv_wnd_getter () == 0 )
695+ drop (in, Drop_reason::RCV_WND_ZERO);
696+
697+
686698 // Keep track if a packet is being sent during the async read callback
687699 const auto snd_nxt = cb.SND .NXT ;
688700
@@ -719,6 +731,8 @@ void Connection::recv_data(const Packet_view& in)
719731 const auto recv = read_request->insert (in.seq (), in.tcp_data (), length, in.isset (PSH));
720732 // this ensures that the data we ACK is actually put in our buffer.
721733 Ensures (recv == length);
734+ // adjust the rcv wnd to (maybe) new value
735+ cb.RCV .WND = recv_wnd_getter ();
722736 }
723737 }
724738 // Packet out of order
0 commit comments