@@ -2479,7 +2479,6 @@ int QuicSession::set_session(SSL_SESSION* session) {
24792479}
24802480
24812481// A client QuicSession can be migrated to a different QuicSocket instance.
2482- // TODO(@jasnell): This will be revisited.
24832482bool QuicSession::set_socket (QuicSocket* socket, bool nat_rebinding) {
24842483 CHECK (!is_server ());
24852484 CHECK (!is_destroyed ());
@@ -2492,8 +2491,6 @@ bool QuicSession::set_socket(QuicSocket* socket, bool nat_rebinding) {
24922491
24932492 Debug (this , " Migrating to %s" , socket->diagnostic_name ());
24942493
2495- SendSessionScope send (this );
2496-
24972494 // Ensure that we maintain a reference to keep this from being
24982495 // destroyed while we are starting the migration.
24992496 BaseObjectPtr<QuicSession> ptr (this );
@@ -2511,22 +2508,31 @@ bool QuicSession::set_socket(QuicSocket* socket, bool nat_rebinding) {
25112508
25122509 // Step 4: Update ngtcp2
25132510 auto local_address = socket->local_address ();
2514- if (nat_rebinding) {
2515- ngtcp2_addr addr;
2516- ngtcp2_addr_init (
2517- &addr,
2518- local_address.data (),
2519- local_address.length (),
2520- nullptr );
2521- ngtcp2_conn_set_local_addr (connection (), &addr);
2522- } else {
2511+
2512+ // The nat_rebinding option here should rarely, if ever
2513+ // be used in a real application. It is intended to serve
2514+ // as a way of simulating a silent local address change,
2515+ // such as when the NAT binding changes. Currently, Node.js
2516+ // does not really have an effective way of detecting that.
2517+ // Manual user code intervention to handle the migration
2518+ // to the new QuicSocket is required, which should always
2519+ // trigger path validation using the ngtcp2_conn_initiate_migration.
2520+ if (LIKELY (!nat_rebinding)) {
2521+ SendSessionScope send (this );
25232522 QuicPath path (local_address, remote_address_);
2524- if (ngtcp2_conn_initiate_migration (
2525- connection (),
2526- &path,
2527- uv_hrtime ()) != 0 ) {
2528- return false ;
2529- }
2523+ return ngtcp2_conn_initiate_migration (
2524+ connection (),
2525+ &path,
2526+ uv_hrtime ()) == 0 ;
2527+ } else {
2528+ ngtcp2_addr addr;
2529+ ngtcp2_conn_set_local_addr (
2530+ connection (),
2531+ ngtcp2_addr_init (
2532+ &addr,
2533+ local_address.data (),
2534+ local_address.length (),
2535+ nullptr ));
25302536 }
25312537
25322538 return true ;
@@ -3671,7 +3677,7 @@ void QuicSessionSetSocket(const FunctionCallbackInfo<Value>& args) {
36713677 ASSIGN_OR_RETURN_UNWRAP (&session, args.Holder ());
36723678 CHECK (args[0 ]->IsObject ());
36733679 ASSIGN_OR_RETURN_UNWRAP (&socket, args[0 ].As <Object>());
3674- args.GetReturnValue ().Set (session->set_socket (socket));
3680+ args.GetReturnValue ().Set (session->set_socket (socket, args[ 1 ]-> IsTrue () ));
36753681}
36763682
36773683// GracefulClose flips a flag that prevents new local streams
0 commit comments