Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

DC Migration

Note

This project is no longer maintained or supported. Its original purpose for personal SDK/APK experimentation and learning has been fulfilled.

Instead, please use ferogram, which will receive future development and updates. Development may proceed at a slower pace.

Telegram’s infrastructure is split across multiple Data Centers (DCs). When you connect to the wrong DC for your account, Telegram responds with a PHONE_MIGRATE_X or USER_MIGRATE_X error telling you which DC to use instead.

layer-client handles DC migration automatically and transparently. You don’t need to do anything.

How it works

  1. You connect to DC2 (the default)
  2. You log in with a phone number registered on DC1
  3. Telegram returns PHONE_MIGRATE_1
  4. layer-client reconnects to DC1, re-performs the DH handshake, and retries your request
  5. Your code sees a successful response: the migration is invisible

The correct DC is then saved in the session file for future connections.

Each new DC connection performs a full DH key exchange to establish a fresh auth key for that DC.

Overriding the initial DC

By default, layer-client starts on DC2. If you know your account is on a different DC, you can set the initial address:

#![allow(unused)]
fn main() {
let (client, _shutdown) = Client::builder()
    .api_id(12345)
    .api_hash("your_hash")
    .session("my.session")
    .dc_addr("149.154.167.91:443")   // DC4
    .connect()
    .await?;
}

DC addresses:

DCPrimary IPNotes
DC1149.154.175.53US East
DC2149.154.167.51US East (default)
DC3149.154.175.100US West
DC4149.154.167.91EU Amsterdam
DC591.108.56.130Singapore

In practice, just leave the default and let auto-migration handle it.

DC pool (for media)

When downloading media, Telegram may route large files through CDN DCs different from your account’s home DC. layer-client maintains a connection pool across DCs and handles this automatically via invoke_on_dc.