@@ -105,6 +105,10 @@ fn create_config(args: &Config, should_log_keys: bool) -> quiche::Config {
105105 config. set_max_stream_window ( args. max_stream_window ) ;
106106 config. grease ( false ) ;
107107
108+ if args. enable_early_data {
109+ config. enable_early_data ( ) ;
110+ }
111+
108112 if args. enable_dgram {
109113 config. enable_dgram (
110114 true ,
@@ -132,6 +136,16 @@ fn create_config(args: &Config, should_log_keys: bool) -> quiche::Config {
132136pub fn connect (
133137 args : Config , actions : Vec < Action > ,
134138 close_trigger_frames : Option < CloseTriggerFrames > ,
139+ ) -> std:: result:: Result < ConnectionSummary , ClientError > {
140+ connect_with_early_data ( args, None , actions, close_trigger_frames)
141+ }
142+
143+ /// Connect to a server and execute provided early_action and actions.
144+ ///
145+ /// See `connect` for additional documentation.
146+ pub fn connect_with_early_data (
147+ args : Config , early_actions : Option < Vec < Action > > , actions : Vec < Action > ,
148+ close_trigger_frames : Option < CloseTriggerFrames > ,
135149) -> std:: result:: Result < ConnectionSummary , ClientError > {
136150 let mut buf = [ 0 ; 65535 ] ;
137151 let mut out = [ 0 ; MAX_DATAGRAM_SIZE ] ;
@@ -178,11 +192,16 @@ pub fn connect(
178192 return Err ( ClientError :: Other ( "invalid socket" . to_string ( ) ) ) ;
179193 } ;
180194
181- // Create a QUIC connection and initiate handshake .
195+ // Create a new client-side QUIC connection .
182196 let mut conn =
183197 quiche:: connect ( connect_url, & scid, local_addr, peer_addr, & mut config)
184198 . map_err ( |e| ClientError :: Other ( e. to_string ( ) ) ) ?;
185199
200+ if let Some ( session) = & args. session {
201+ conn. set_session ( session)
202+ . map_err ( |error| ClientError :: Other ( error. to_string ( ) ) ) ?;
203+ }
204+
186205 if let Some ( keylog) = & mut keylog {
187206 if let Ok ( keylog) = keylog. try_clone ( ) {
188207 conn. set_keylog ( Box :: new ( keylog) ) ;
@@ -195,8 +214,30 @@ pub fn connect(
195214
196215 let mut app_proto_selected = false ;
197216
217+ // Send ClientHello and initiate the handshake.
198218 let ( write, send_info) = conn. send ( & mut out) . expect ( "initial send failed" ) ;
199219
220+ let mut client = SyncClient :: new ( close_trigger_frames) ;
221+ // Send early data if connection is_in_early_data (resumption with 0-RTT was
222+ // successful) and if we have early_actions.
223+ if conn. is_in_early_data ( ) {
224+ if let Some ( early_actions) = early_actions {
225+ let mut early_action_iter = early_actions. iter ( ) ;
226+ let mut wait_duration = None ;
227+ let mut wait_instant = None ;
228+ let mut waiting_for = WaitingFor :: default ( ) ;
229+
230+ check_duration_and_do_actions (
231+ & mut wait_duration,
232+ & mut wait_instant,
233+ & mut early_action_iter,
234+ & mut conn,
235+ & mut waiting_for,
236+ client. stream_parsers_mut ( ) ,
237+ ) ;
238+ }
239+ }
240+
200241 while let Err ( e) = socket. send_to ( & out[ ..write] , send_info. to ) {
201242 if e. kind ( ) == std:: io:: ErrorKind :: WouldBlock {
202243 log:: debug!(
@@ -216,7 +257,6 @@ pub fn connect(
216257 let mut wait_duration = None ;
217258 let mut wait_instant = None ;
218259
219- let mut client = SyncClient :: new ( close_trigger_frames) ;
220260 let mut waiting_for = WaitingFor :: default ( ) ;
221261
222262 loop {
0 commit comments