Skip to content

Conversation

@willianpaixao
Copy link

@willianpaixao willianpaixao commented Jan 6, 2026

This is for testing purposes, do not merge

#3446 explains what I'm trying to archive with this PR.

Usage

Enable migration support

import libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic"

host, err := libp2p.New(
    libp2p.Transport(libp2pquic.NewTransport,
        libp2pquic.EnableExperimentalConnectionMigration()),
)

Perform a migration

// Get MigratableConn from any connection
var migratable network.MigratableConn
if conn.As(&migratable) && migratable.SupportsMigration() {
    // Add a new path using a different local address
    path, err := migratable.AddPath(ctx, newLocalAddr)
    if err != nil {
        return err
    }

    // Probe the path to verify connectivity
    if err := path.Probe(ctx); err != nil {
        path.Close()
        return err
    }

    // Switch to the new path
    if err := path.Switch(); err != nil {
        return err
    }
    // Connection is now using the new path, all streams preserved
}

Monitor migration events

sub, _ := host.EventBus().Subscribe([]any{
    new(event.EvtConnectionMigrationStarted),
    new(event.EvtConnectionMigrationCompleted),
    new(event.EvtConnectionMigrationFailed),
})

Constraints

Per the QUIC specification:

  • Only client-initiated (outbound) connections support migration: server-side connections return SupportsMigration() == false
  • Single active path at a time: QUIC maintains one active path per connection
  • Requires separate UDP socket per interface: each local address needs its own transport

Failure Handling

If migration fails:

  1. The connection attempts to continue on the original path
  2. If the original path is also unavailable, the connection is closed
  3. EvtConnectionMigrationFailed event is emitted with error details

Future Work (Out of scope)

  • Automatic migration based on OS network interface events
  • Automatic retry with exponential backoff on transient failures
  • Policy configuration for migration preferences

@willianpaixao willianpaixao force-pushed the conn-migration branch 4 times, most recently from 6db8a62 to 0b608ba Compare January 6, 2026 19:47
Add support for QUIC connection migration, allowing outbound connections
to switch network paths (e.g., from a primary interface to a failover
interface) without disrupting active streams.

This feature leverages quic-go's connection migration APIs (AddPath,
Probe, Switch) introduced in v0.51.0. Migration is opt-in via the
EnableExperimentalConnectionMigration() transport option.

Key changes:
- Add MigratableConn and Path interfaces in core/network
- Add migration event types in core/event
- Implement MigratableConn in QUIC connection via Conn.As()
- Add TransportForMigration to ConnManager for alternate paths
- Add comprehensive tests and documentation

Only client-initiated (outbound) connections support migration per the
QUIC specification. Server-side connections return SupportsMigration() == false.

Signed-off-by: Willian Paixao <[email protected]>
@MarcoPolo
Copy link
Collaborator

Thanks for the PR. Let's use the existing Conn.As functionality for this use case for now.

@willianpaixao willianpaixao deleted the conn-migration branch January 8, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants