cjongseok / mtproto

Telegram MTProto and its proxy (over gRPC) in Go (golang). API Layer: 71
Apache License 2.0
151 stars 20 forks source link

Changing DC? #18

Closed FedorZaytsev closed 5 years ago

FedorZaytsev commented 5 years ago

In order to download something from telegram servers, I sometimes need to change datacenter (error "mtproto RPC error: 303 FILE_MIGRATE_2 " if you are interested why). How can I do it with your lib? As far as I understand I have no option to get "dcOptions" field from Session struct which contains all the information about available DCs, because it is a private field and apiDcOption(...) is private too.

Can you please provide any way either to get "dcOptions" or to reconnect to the specific DC? The second way is a little bit harder because it will require to first call AuthExportAuthorization, reconnect to new dc and then call AuthImportAuthorization.

P.S. Thanks for the project and really great support. I can do a merge request if you are busy

cjongseok commented 5 years ago

@FedorZaytsev Thanks for your interest in this project. Good point. It needs a modal to change the server. I will add a function to mconn, so the migration flow would be:

// Auth to a server first to fetch dc list
manager, err := mtproto.NewManager(config)
mconn, err := manager.LoadAuthentication()

// And then you can reconnect to the preferred server
mconn.MigrateSessionTo(2) // Close the current session and make a session to the server 2

I will let you know when it is ready.

cjongseok commented 5 years ago

Can you try this commit? it is in migrate_session branch

FedorZaytsev commented 5 years ago

It looks like that this branch works. Can you merge it into master?

cjongseok commented 5 years ago

@FedorZaytsev Good. I merged it into master.