| 1 |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 2 |
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 3 |
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 4 |
// option. This file may not be copied, modified, or distributed |
| 5 |
// except according to those terms. |
| 6 |
|
| 7 |
// Stream management for a connection. |
| 8 |
use std::{ |
| 9 |
cell::RefCell, |
| 10 |
cmp::Ordering, |
| 11 |
rc::Rc, |
| 12 |
time::{Duration, Instant}, |
| 13 |
}; |
| 14 |
|
| 15 |
use neqo_common::{qtrace, qwarn, Role}; |
| 16 |
|
| 17 |
use crate::{ |
| 18 |
fc::{LocalStreamLimits, ReceiverFlowControl, RemoteStreamLimits, SenderFlowControl}, |
| 19 |
frame::Frame, |
| 20 |
packet::PacketBuilder, |
| 21 |
recovery::{RecoveryToken, StreamRecoveryToken}, |
| 22 |
recv_stream::{RecvStream, RecvStreams}, |
| 23 |
send_stream::{SendStream, SendStreams, TransmissionPriority}, |
| 24 |
stats::FrameStats, |
| 25 |
stream_id::{StreamId, StreamType}, |
| 26 |
tparams::{ |
| 27 |
TransportParameterId::{ |
| 28 |
InitialMaxData, InitialMaxStreamDataBidiLocal, InitialMaxStreamDataBidiRemote, |
| 29 |
InitialMaxStreamDataUni, InitialMaxStreamsBidi, InitialMaxStreamsUni, |
| 30 |
}, |
| 31 |
TransportParametersHandler, |
| 32 |
}, |
| 33 |
ConnectionEvents, Error, Res, |
| 34 |
}; |
| 35 |
|
| 36 |
pub type SendOrder = i64; |
| 37 |
|
| 38 |
#[derive(Copy, Clone)] |
| 39 |
pub struct StreamOrder { |
| 40 |
pub sendorder: Option<SendOrder>, |
| 41 |
} |
| 42 |
|
| 43 |
// We want highest to lowest, with None being higher than any value |
| 44 |
impl Ord for StreamOrder { |
| 45 |
fn cmp(&self, other: &Self) -> Ordering { |
| 46 |
if self.sendorder.is_some() && other.sendorder.is_some() { |
| 47 |
// We want reverse order (high to low) when both values are specified. |
| 48 |
other.sendorder.cmp(&self.sendorder) |
| 49 |
} else { |
| 50 |
self.sendorder.cmp(&other.sendorder) |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
impl PartialOrd for StreamOrder { |
| 56 |
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { |
| 57 |
Some(self.cmp(other)) |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
impl PartialEq for StreamOrder { |
| 62 |
fn eq(&self, other: &Self) -> bool { |
| 63 |
self.sendorder == other.sendorder |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
impl Eq for StreamOrder {} |
| 68 |
|
| 69 |
pub struct Streams { |
| 70 |
role: Role, |
| 71 |
tps: Rc<RefCell<TransportParametersHandler>>, |
| 72 |
events: ConnectionEvents, |
| 73 |
sender_fc: Rc<RefCell<SenderFlowControl<()>>>, |
| 74 |
receiver_fc: Rc<RefCell<ReceiverFlowControl<()>>>, |
| 75 |
remote_stream_limits: RemoteStreamLimits, |
| 76 |
local_stream_limits: LocalStreamLimits, |
| 77 |
send: SendStreams, |
| 78 |
recv: RecvStreams, |
| 79 |
} |
| 80 |
|
| 81 |
impl Streams { |
| 82 |
pub fn new( |
| 83 |
tps: Rc<RefCell<TransportParametersHandler>>, |
| 84 |
role: Role, |
| 85 |
events: ConnectionEvents, |
| 86 |
) -> Self { |
| 87 |
let limit_bidi = tps.borrow().local().get_integer(InitialMaxStreamsBidi); |
| 88 |
let limit_uni = tps.borrow().local().get_integer(InitialMaxStreamsUni); |
| 89 |
let max_data = tps.borrow().local().get_integer(InitialMaxData); |
| 90 |
Self { |
| 91 |
role, |
| 92 |
tps, |
| 93 |
events, |
| 94 |
sender_fc: Rc::new(RefCell::new(SenderFlowControl::new((), 0))), |
| 95 |
receiver_fc: Rc::new(RefCell::new(ReceiverFlowControl::new((), max_data))), |
| 96 |
remote_stream_limits: RemoteStreamLimits::new(limit_bidi, limit_uni, role), |
| 97 |
local_stream_limits: LocalStreamLimits::new(role), |
| 98 |
send: SendStreams::default(), |
| 99 |
recv: RecvStreams::default(), |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
#[must_use] |
| 104 |
pub fn is_stream_id_allowed(&self, stream_id: StreamId) -> bool { |
| 105 |
self.remote_stream_limits[stream_id.stream_type()].is_allowed(stream_id) |
| 106 |
} |
| 107 |
|
| 108 |
pub fn zero_rtt_rejected(&mut self) { |
| 109 |
self.clear_streams(); |
| 110 |
debug_assert_eq!( |
| 111 |
self.remote_stream_limits[StreamType::BiDi].max_active(), |
| 112 |
self.tps.borrow().local().get_integer(InitialMaxStreamsBidi) |
| 113 |
); |
| 114 |
debug_assert_eq!( |
| 115 |
self.remote_stream_limits[StreamType::UniDi].max_active(), |
| 116 |
self.tps.borrow().local().get_integer(InitialMaxStreamsUni) |
| 117 |
); |
| 118 |
self.local_stream_limits = LocalStreamLimits::new(self.role); |
| 119 |
} |
| 120 |
|
| 121 |
/// # Errors |
| 122 |
/// When the frame is invalid. |
| 123 |
pub fn input_frame(&mut self, frame: &Frame, stats: &mut FrameStats) -> Res<()> { |
| 124 |
match frame { |
| 125 |
Frame::ResetStream { |
| 126 |
stream_id, |
| 127 |
application_error_code, |
| 128 |
final_size, |
| 129 |
} => { |
| 130 |
stats.reset_stream += 1; |
| 131 |
if let (_, Some(rs)) = self.obtain_stream(*stream_id)? { |
| 132 |
rs.reset(*application_error_code, *final_size)?; |
| 133 |
} |
| 134 |
} |
| 135 |
Frame::StopSending { |
| 136 |
stream_id, |
| 137 |
application_error_code, |
| 138 |
} => { |
| 139 |
stats.stop_sending += 1; |
| 140 |
self.events |
| 141 |
.send_stream_stop_sending(*stream_id, *application_error_code); |
| 142 |
if let (Some(ss), _) = self.obtain_stream(*stream_id)? { |
| 143 |
ss.reset(*application_error_code); |
| 144 |
} |
| 145 |
} |
| 146 |
Frame::Stream { |
| 147 |
fin, |
| 148 |
stream_id, |
| 149 |
offset, |
| 150 |
data, |
| 151 |
.. |
| 152 |
} => { |
| 153 |
stats.stream += 1; |
| 154 |
if let (_, Some(rs)) = self.obtain_stream(*stream_id)? { |
| 155 |
rs.inbound_stream_frame(*fin, *offset, data)?; |
| 156 |
} |
| 157 |
} |
| 158 |
Frame::MaxData { maximum_data } => { |
| 159 |
stats.max_data += 1; |
| 160 |
self.handle_max_data(*maximum_data); |
| 161 |
} |
| 162 |
Frame::MaxStreamData { |
| 163 |
stream_id, |
| 164 |
maximum_stream_data, |
| 165 |
} => { |
| 166 |
qtrace!( |
| 167 |
"Stream {} Received MaxStreamData {}", |
| 168 |
*stream_id, |
| 169 |
*maximum_stream_data |
| 170 |
); |
| 171 |
stats.max_stream_data += 1; |
| 172 |
if let (Some(ss), _) = self.obtain_stream(*stream_id)? { |
| 173 |
ss.set_max_stream_data(*maximum_stream_data); |
| 174 |
} |
| 175 |
} |
| 176 |
Frame::MaxStreams { |
| 177 |
stream_type, |
| 178 |
maximum_streams, |
| 179 |
} => { |
| 180 |
stats.max_streams += 1; |
| 181 |
self.handle_max_streams(*stream_type, *maximum_streams); |
| 182 |
} |
| 183 |
Frame::DataBlocked { data_limit } => { |
| 184 |
// Should never happen since we set data limit to max |
| 185 |
qwarn!("Received DataBlocked with data limit {data_limit}"); |
| 186 |
stats.data_blocked += 1; |
| 187 |
self.handle_data_blocked(); |
| 188 |
} |
| 189 |
Frame::StreamDataBlocked { stream_id, .. } => { |
| 190 |
qtrace!("Received StreamDataBlocked"); |
| 191 |
stats.stream_data_blocked += 1; |
| 192 |
// Terminate connection with STREAM_STATE_ERROR if send-only |
| 193 |
// stream (-transport 19.13) |
| 194 |
if stream_id.is_send_only(self.role) { |
| 195 |
return Err(Error::StreamStateError); |
| 196 |
} |
| 197 |
|
| 198 |
if let (_, Some(rs)) = self.obtain_stream(*stream_id)? { |
| 199 |
rs.send_flowc_update(); |
| 200 |
} |
| 201 |
} |
| 202 |
Frame::StreamsBlocked { .. } => { |
| 203 |
stats.streams_blocked += 1; |
| 204 |
// We send an update every time we retire a stream. There is no need to |
| 205 |
// trigger flow updates here. |
| 206 |
} |
| 207 |
_ => return Err(Error::InternalError), // This is not a stream frame. |
| 208 |
} |
| 209 |
Ok(()) |
| 210 |
} |
| 211 |
|
| 212 |
pub fn write_maintenance_frames( |
| 213 |
&mut self, |
| 214 |
builder: &mut PacketBuilder, |
| 215 |
tokens: &mut Vec<RecoveryToken>, |
| 216 |
stats: &mut FrameStats, |
| 217 |
now: Instant, |
| 218 |
rtt: Duration, |
| 219 |
) { |
| 220 |
// Send `DATA_BLOCKED` as necessary. |
| 221 |
self.sender_fc |
| 222 |
.borrow_mut() |
| 223 |
.write_frames(builder, tokens, stats); |
| 224 |
if builder.is_full() { |
| 225 |
return; |
| 226 |
} |
| 227 |
|
| 228 |
// Send `MAX_DATA` as necessary. |
| 229 |
self.receiver_fc |
| 230 |
.borrow_mut() |
| 231 |
.write_frames(builder, tokens, stats); |
| 232 |
if builder.is_full() { |
| 233 |
return; |
| 234 |
} |
| 235 |
|
| 236 |
self.recv.write_frames(builder, tokens, stats, now, rtt); |
| 237 |
|
| 238 |
self.remote_stream_limits[StreamType::BiDi].write_frames(builder, tokens, stats); |
| 239 |
if builder.is_full() { |
| 240 |
return; |
| 241 |
} |
| 242 |
self.remote_stream_limits[StreamType::UniDi].write_frames(builder, tokens, stats); |
| 243 |
if builder.is_full() { |
| 244 |
return; |
| 245 |
} |
| 246 |
|
| 247 |
self.local_stream_limits[StreamType::BiDi].write_frames(builder, tokens, stats); |
| 248 |
if builder.is_full() { |
| 249 |
return; |
| 250 |
} |
| 251 |
|
| 252 |
self.local_stream_limits[StreamType::UniDi].write_frames(builder, tokens, stats); |
| 253 |
} |
| 254 |
|
| 255 |
pub fn write_frames( |
| 256 |
&mut self, |
| 257 |
priority: TransmissionPriority, |
| 258 |
builder: &mut PacketBuilder, |
| 259 |
tokens: &mut Vec<RecoveryToken>, |
| 260 |
stats: &mut FrameStats, |
| 261 |
) { |
| 262 |
self.send.write_frames(priority, builder, tokens, stats); |
| 263 |
} |
| 264 |
|
| 265 |
pub fn lost(&mut self, token: &StreamRecoveryToken) { |
| 266 |
match token { |
| 267 |
StreamRecoveryToken::Stream(st) => self.send.lost(st), |
| 268 |
StreamRecoveryToken::ResetStream { stream_id } => self.send.reset_lost(*stream_id), |
| 269 |
StreamRecoveryToken::StreamDataBlocked { stream_id, limit } => { |
| 270 |
self.send.blocked_lost(*stream_id, *limit); |
| 271 |
} |
| 272 |
StreamRecoveryToken::MaxStreamData { |
| 273 |
stream_id, |
| 274 |
max_data, |
| 275 |
} => { |
| 276 |
if let Ok((_, Some(rs))) = self.obtain_stream(*stream_id) { |
| 277 |
rs.max_stream_data_lost(*max_data); |
| 278 |
} |
| 279 |
} |
| 280 |
StreamRecoveryToken::StopSending { stream_id } => { |
| 281 |
if let Ok((_, Some(rs))) = self.obtain_stream(*stream_id) { |
| 282 |
rs.stop_sending_lost(); |
| 283 |
} |
| 284 |
} |
| 285 |
StreamRecoveryToken::StreamsBlocked { stream_type, limit } => { |
| 286 |
self.local_stream_limits[*stream_type].frame_lost(*limit); |
| 287 |
} |
| 288 |
StreamRecoveryToken::MaxStreams { |
| 289 |
stream_type, |
| 290 |
max_streams, |
| 291 |
} => { |
| 292 |
self.remote_stream_limits[*stream_type].frame_lost(*max_streams); |
| 293 |
} |
| 294 |
StreamRecoveryToken::DataBlocked(limit) => { |
| 295 |
self.sender_fc.borrow_mut().frame_lost(*limit); |
| 296 |
} |
| 297 |
StreamRecoveryToken::MaxData(maximum_data) => { |
| 298 |
self.receiver_fc.borrow_mut().frame_lost(*maximum_data); |
| 299 |
} |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
pub fn acked(&mut self, token: &StreamRecoveryToken) { |
| 304 |
match token { |
| 305 |
StreamRecoveryToken::Stream(st) => self.send.acked(st), |
| 306 |
StreamRecoveryToken::ResetStream { stream_id } => self.send.reset_acked(*stream_id), |
| 307 |
StreamRecoveryToken::StopSending { stream_id } => { |
| 308 |
if let Ok((_, Some(rs))) = self.obtain_stream(*stream_id) { |
| 309 |
rs.stop_sending_acked(); |
| 310 |
} |
| 311 |
} |
| 312 |
// We only worry when these are lost |
| 313 |
StreamRecoveryToken::DataBlocked(_) |
| 314 |
| StreamRecoveryToken::StreamDataBlocked { .. } |
| 315 |
| StreamRecoveryToken::MaxStreamData { .. } |
| 316 |
| StreamRecoveryToken::StreamsBlocked { .. } |
| 317 |
| StreamRecoveryToken::MaxStreams { .. } |
| 318 |
| StreamRecoveryToken::MaxData(_) => (), |
| 319 |
} |
| 320 |
} |
| 321 |
|
| 322 |
pub fn clear_streams(&mut self) { |
| 323 |
self.send.clear(); |
| 324 |
self.recv.clear(); |
| 325 |
} |
| 326 |
|
| 327 |
pub fn cleanup_closed_streams(&mut self) { |
| 328 |
// filter the list, removing closed streams |
| 329 |
self.send.remove_terminal(); |
| 330 |
|
| 331 |
let (removed_bidi, removed_uni) = self.recv.clear_terminal(&self.send, self.role); |
| 332 |
|
| 333 |
// Send max_streams updates if we removed remote-initiated recv streams. |
| 334 |
// The updates will be send if any streams has been removed. |
| 335 |
self.remote_stream_limits[StreamType::BiDi].add_retired(removed_bidi); |
| 336 |
self.remote_stream_limits[StreamType::UniDi].add_retired(removed_uni); |
| 337 |
} |
| 338 |
|
| 339 |
fn ensure_created_if_remote(&mut self, stream_id: StreamId) -> Res<()> { |
| 340 |
if !stream_id.is_remote_initiated(self.role) |
| 341 |
|| !self.remote_stream_limits[stream_id.stream_type()].is_new_stream(stream_id)? |
| 342 |
{ |
| 343 |
// If it is not a remote stream and stream already exist. |
| 344 |
return Ok(()); |
| 345 |
} |
| 346 |
|
| 347 |
let tp = match stream_id.stream_type() { |
| 348 |
// From the local perspective, this is a remote- originated BiDi stream. From |
| 349 |
// the remote perspective, this is a local-originated BiDi stream. Therefore, |
| 350 |
// look at the local transport parameters for the |
| 351 |
// INITIAL_MAX_STREAM_DATA_BIDI_REMOTE value to decide how much this endpoint |
| 352 |
// will allow its peer to send. |
| 353 |
StreamType::BiDi => InitialMaxStreamDataBidiRemote, |
| 354 |
StreamType::UniDi => InitialMaxStreamDataUni, |
| 355 |
}; |
| 356 |
let recv_initial_max_stream_data = self.tps.borrow().local().get_integer(tp); |
| 357 |
|
| 358 |
while self.remote_stream_limits[stream_id.stream_type()].is_new_stream(stream_id)? { |
| 359 |
let next_stream_id = |
| 360 |
self.remote_stream_limits[stream_id.stream_type()].take_stream_id(); |
| 361 |
self.events.new_stream(next_stream_id); |
| 362 |
|
| 363 |
self.recv.insert( |
| 364 |
next_stream_id, |
| 365 |
RecvStream::new( |
| 366 |
next_stream_id, |
| 367 |
recv_initial_max_stream_data, |
| 368 |
Rc::clone(&self.receiver_fc), |
| 369 |
self.events.clone(), |
| 370 |
), |
| 371 |
); |
| 372 |
|
| 373 |
if next_stream_id.is_bidi() { |
| 374 |
// From the local perspective, this is a remote- originated BiDi stream. |
| 375 |
// From the remote perspective, this is a local-originated BiDi stream. |
| 376 |
// Therefore, look at the remote's transport parameters for the |
| 377 |
// INITIAL_MAX_STREAM_DATA_BIDI_LOCAL value to decide how much this endpoint |
| 378 |
// is allowed to send its peer. |
| 379 |
let send_initial_max_stream_data = self |
| 380 |
.tps |
| 381 |
.borrow() |
| 382 |
.remote() |
| 383 |
.get_integer(InitialMaxStreamDataBidiLocal); |
| 384 |
self.send.insert( |
| 385 |
next_stream_id, |
| 386 |
SendStream::new( |
| 387 |
next_stream_id, |
| 388 |
send_initial_max_stream_data, |
| 389 |
Rc::clone(&self.sender_fc), |
| 390 |
self.events.clone(), |
| 391 |
), |
| 392 |
); |
| 393 |
} |
| 394 |
} |
| 395 |
Ok(()) |
| 396 |
} |
| 397 |
|
| 398 |
/// Get or make a stream, and implicitly open additional streams as |
| 399 |
/// indicated by its stream id. |
| 400 |
/// # Errors |
| 401 |
/// When the stream cannot be created due to stream limits. |
| 402 |
/// When the stream is locally-initiated and has not existed. |
| 403 |
pub fn obtain_stream( |
| 404 |
&mut self, |
| 405 |
stream_id: StreamId, |
| 406 |
) -> Res<(Option<&mut SendStream>, Option<&mut RecvStream>)> { |
| 407 |
self.ensure_created_if_remote(stream_id)?; |
| 408 |
let ss = self.send.get_mut(stream_id).ok(); |
| 409 |
let rs = self.recv.get_mut(stream_id).ok(); |
| 410 |
// If it is: |
| 411 |
// - neither a known send nor receive stream, |
| 412 |
// - and it must be locally initiated, |
| 413 |
// - and its index is larger than the local used stream limit, |
| 414 |
// then it is an illegal stream. |
| 415 |
if ss.is_none() |
| 416 |
&& rs.is_none() |
| 417 |
&& !stream_id.is_remote_initiated(self.role) |
| 418 |
&& self.local_stream_limits[stream_id.stream_type()].used() <= stream_id.index() |
| 419 |
{ |
| 420 |
return Err(Error::StreamStateError); |
| 421 |
} |
| 422 |
Ok((ss, rs)) |
| 423 |
} |
| 424 |
|
| 425 |
/// # Errors |
| 426 |
/// When the stream does not exist. |
| 427 |
pub fn set_sendorder(&mut self, stream_id: StreamId, sendorder: Option<SendOrder>) -> Res<()> { |
| 428 |
self.send.set_sendorder(stream_id, sendorder) |
| 429 |
} |
| 430 |
|
| 431 |
/// # Errors |
| 432 |
/// When the stream does not exist. |
| 433 |
pub fn set_fairness(&mut self, stream_id: StreamId, fairness: bool) -> Res<()> { |
| 434 |
self.send.set_fairness(stream_id, fairness) |
| 435 |
} |
| 436 |
|
| 437 |
/// # Errors |
| 438 |
/// When a stream cannot be created, which might be temporary. |
| 439 |
pub fn stream_create(&mut self, st: StreamType) -> Res<StreamId> { |
| 440 |
match self.local_stream_limits.take_stream_id(st) { |
| 441 |
None => Err(Error::StreamLimitError), |
| 442 |
Some(new_id) => { |
| 443 |
let send_limit_tp = match st { |
| 444 |
StreamType::UniDi => InitialMaxStreamDataUni, |
| 445 |
StreamType::BiDi => InitialMaxStreamDataBidiRemote, |
| 446 |
}; |
| 447 |
let send_limit = self.tps.borrow().remote().get_integer(send_limit_tp); |
| 448 |
let stream = SendStream::new( |
| 449 |
new_id, |
| 450 |
send_limit, |
| 451 |
Rc::clone(&self.sender_fc), |
| 452 |
self.events.clone(), |
| 453 |
); |
| 454 |
self.send.insert(new_id, stream); |
| 455 |
|
| 456 |
if st == StreamType::BiDi { |
| 457 |
// From the local perspective, this is a local- originated BiDi stream. From the |
| 458 |
// remote perspective, this is a remote-originated BiDi stream. Therefore, look |
| 459 |
// at the local transport parameters for the |
| 460 |
// INITIAL_MAX_STREAM_DATA_BIDI_LOCAL value to decide how |
| 461 |
// much this endpoint will allow its peer to send. |
| 462 |
let recv_initial_max_stream_data = self |
| 463 |
.tps |
| 464 |
.borrow() |
| 465 |
.local() |
| 466 |
.get_integer(InitialMaxStreamDataBidiLocal); |
| 467 |
|
| 468 |
self.recv.insert( |
| 469 |
new_id, |
| 470 |
RecvStream::new( |
| 471 |
new_id, |
| 472 |
recv_initial_max_stream_data, |
| 473 |
Rc::clone(&self.receiver_fc), |
| 474 |
self.events.clone(), |
| 475 |
), |
| 476 |
); |
| 477 |
} |
| 478 |
Ok(new_id) |
| 479 |
} |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
pub fn handle_max_data(&mut self, maximum_data: u64) { |
| 484 |
let previous_limit = self.sender_fc.borrow().available(); |
| 485 |
let Some(current_limit) = self.sender_fc.borrow_mut().update(maximum_data) else { |
| 486 |
return; |
| 487 |
}; |
| 488 |
|
| 489 |
for (_id, ss) in &mut self.send { |
| 490 |
ss.maybe_emit_writable_event(previous_limit, current_limit); |
| 491 |
} |
| 492 |
} |
| 493 |
|
| 494 |
pub fn handle_data_blocked(&self) { |
| 495 |
self.receiver_fc.borrow_mut().send_flowc_update(); |
| 496 |
} |
| 497 |
|
| 498 |
pub fn set_initial_limits(&mut self) { |
| 499 |
_ = self.local_stream_limits[StreamType::BiDi].update( |
| 500 |
self.tps |
| 501 |
.borrow() |
| 502 |
.remote() |
| 503 |
.get_integer(InitialMaxStreamsBidi), |
| 504 |
); |
| 505 |
_ = self.local_stream_limits[StreamType::UniDi] |
| 506 |
.update(self.tps.borrow().remote().get_integer(InitialMaxStreamsUni)); |
| 507 |
|
| 508 |
// As a client, there are two sets of initial limits for sending stream data. |
| 509 |
// If the second limit is higher and streams have been created, then |
| 510 |
// ensure that streams are not blocked on the lower limit. |
| 511 |
if self.role == Role::Client { |
| 512 |
self.send.update_initial_limit(self.tps.borrow().remote()); |
| 513 |
} |
| 514 |
|
| 515 |
self.sender_fc |
| 516 |
.borrow_mut() |
| 517 |
.update(self.tps.borrow().remote().get_integer(InitialMaxData)); |
| 518 |
|
| 519 |
if self.local_stream_limits[StreamType::BiDi].available() > 0 { |
| 520 |
self.events.send_stream_creatable(StreamType::BiDi); |
| 521 |
} |
| 522 |
if self.local_stream_limits[StreamType::UniDi].available() > 0 { |
| 523 |
self.events.send_stream_creatable(StreamType::UniDi); |
| 524 |
} |
| 525 |
} |
| 526 |
|
| 527 |
pub fn handle_max_streams(&mut self, stream_type: StreamType, maximum_streams: u64) { |
| 528 |
let increased = self.local_stream_limits[stream_type] |
| 529 |
.update(maximum_streams) |
| 530 |
.is_some(); |
| 531 |
if increased { |
| 532 |
self.events.send_stream_creatable(stream_type); |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
/// # Errors |
| 537 |
/// When the stream does not exist. |
| 538 |
pub fn get_send_stream_mut(&mut self, stream_id: StreamId) -> Res<&mut SendStream> { |
| 539 |
self.send.get_mut(stream_id) |
| 540 |
} |
| 541 |
|
| 542 |
/// # Errors |
| 543 |
/// When the stream does not exist. |
| 544 |
pub fn get_send_stream(&self, stream_id: StreamId) -> Res<&SendStream> { |
| 545 |
self.send.get(stream_id) |
| 546 |
} |
| 547 |
|
| 548 |
/// # Errors |
| 549 |
/// When the stream does not exist. |
| 550 |
pub fn get_recv_stream_mut(&mut self, stream_id: StreamId) -> Res<&mut RecvStream> { |
| 551 |
self.recv.get_mut(stream_id) |
| 552 |
} |
| 553 |
|
| 554 |
/// # Errors |
| 555 |
/// When the stream does not exist. |
| 556 |
pub fn keep_alive(&mut self, stream_id: StreamId, keep: bool) -> Res<()> { |
| 557 |
self.recv.keep_alive(stream_id, keep) |
| 558 |
} |
| 559 |
|
| 560 |
#[must_use] |
| 561 |
pub fn need_keep_alive(&self) -> bool { |
| 562 |
self.recv.need_keep_alive() |
| 563 |
} |
| 564 |
} |