@@ -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 ,
@@ -130,7 +134,7 @@ fn create_config(args: &Config, should_log_keys: bool) -> quiche::Config {
130134///
131135/// Returns a [ConnectionSummary] on success, [ClientError] on failure.
132136pub fn connect (
133- args : Config , actions : Vec < Action > ,
137+ args : Config , early_actions : Option < Vec < Action > > , actions : Vec < Action > ,
134138 close_trigger_frames : Option < CloseTriggerFrames > ,
135139) -> std:: result:: Result < ConnectionSummary , ClientError > {
136140 let mut buf = [ 0 ; 65535 ] ;
@@ -178,11 +182,16 @@ pub fn connect(
178182 return Err ( ClientError :: Other ( "invalid socket" . to_string ( ) ) ) ;
179183 } ;
180184
181- // Create a QUIC connection and initiate handshake .
185+ // Create a new client-side QUIC connection .
182186 let mut conn =
183187 quiche:: connect ( connect_url, & scid, local_addr, peer_addr, & mut config)
184188 . map_err ( |e| ClientError :: Other ( e. to_string ( ) ) ) ?;
185189
190+ if let Some ( session) = & args. session {
191+ conn. set_session ( session)
192+ . map_err ( |error| ClientError :: Other ( error. to_string ( ) ) ) ?;
193+ }
194+
186195 if let Some ( keylog) = & mut keylog {
187196 if let Ok ( keylog) = keylog. try_clone ( ) {
188197 conn. set_keylog ( Box :: new ( keylog) ) ;
@@ -195,8 +204,30 @@ pub fn connect(
195204
196205 let mut app_proto_selected = false ;
197206
207+ // Send ClientHello and initiate the handshake.
198208 let ( write, send_info) = conn. send ( & mut out) . expect ( "initial send failed" ) ;
199209
210+ let mut client = SyncClient :: new ( close_trigger_frames) ;
211+ // Send early data if connection is_in_early_data (resumption with 0-RTT was
212+ // successful) and if we have early_actions.
213+ if conn. is_in_early_data ( ) {
214+ if let Some ( early_actions) = early_actions {
215+ let mut early_action_iter = early_actions. iter ( ) ;
216+ let mut wait_duration = None ;
217+ let mut wait_instant = None ;
218+ let mut waiting_for = WaitingFor :: default ( ) ;
219+
220+ check_duration_and_do_actions (
221+ & mut wait_duration,
222+ & mut wait_instant,
223+ & mut early_action_iter,
224+ & mut conn,
225+ & mut waiting_for,
226+ client. stream_parsers_mut ( ) ,
227+ ) ;
228+ }
229+ }
230+
200231 while let Err ( e) = socket. send_to ( & out[ ..write] , send_info. to ) {
201232 if e. kind ( ) == std:: io:: ErrorKind :: WouldBlock {
202233 log:: debug!(
@@ -216,7 +247,6 @@ pub fn connect(
216247 let mut wait_duration = None ;
217248 let mut wait_instant = None ;
218249
219- let mut client = SyncClient :: new ( close_trigger_frames) ;
220250 let mut waiting_for = WaitingFor :: default ( ) ;
221251
222252 loop {
0 commit comments