antonio-antuan / rust-tdlib

Rust client for TDlib
MIT License
57 stars 11 forks source link

Valid api_id must be provided. #37

Open MrAliSalehi opened 11 months ago

MrAliSalehi commented 11 months ago

The #35 is happening in version 1.8.21 again

[ 3][t 4][1700971024.492456197][Td.cpp:4112][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "version"
  value = optionValueString {
    value = "1.8.21"
  }
}
setTdlibParameters {
  use_test_dc = false
  database_directory = ""
  files_directory = ""
  database_encryption_key = bytes [0] { }
  use_file_database = false
  use_chat_info_database = false
  use_message_database = false
  use_secret_chats = false
  api_id = 0
  api_hash = ""
  system_language_code = ""
  device_model = ""
  system_version = ""
  application_version = ""
  enable_storage_optimizer = false
  ignore_file_names = false
}

they are "" and 0 even when i set them manually. is there any fix for this?

antonio-antuan commented 11 months ago

As I said here library currently supports only 1.8.0. You have two options:

  1. use tdlib of version 1.8.0
  2. wait for #38 to be merged (several days) or use a version from this branch directly. Take into account that tdlib a bit broke backward compatibility, look in the PR's examples. What also is broken - I don't know yet.
MrAliSalehi commented 11 months ago

i just tried with the 1.8 and I got this :

DEBUG tdlib parameters set
DEBUG state changes handled properly
DEBUG received new auth state: UpdateAuthorizationState { extra: None, client_id: Some(1), authorization_state: WaitEncryptionKey(AuthorizationStateWaitEncryptionKey { extra: None, client_id: None, is_encrypted: false }) }
DEBUG handling new auth state: WaitEncryptionKey(AuthorizationStateWaitEncryptionKey { extra: None, client_id: None, is_encrypted: false })
INFO wait for client's encryption key
waiting for encryption key
[ 3][t 0][1700992099.440389156][Client.cpp:291][&td_requests]   End to wait for updates, returning object 0 (nil)
[ 3][t 0][1700992099.440802097][Client.cpp:278][&td_requests]   Begin to wait for updates with timeout 1.000000

and then nothing happens, just endless loop of Begin/End messages... weird

antonio-antuan commented 11 months ago

It tells you "waiting for encryption key" (BTW removed in 1.8.21) Push "enter" here. On Sun, Nov 26, 2023, at 10:50, Ali wrote:

i just tried with the 1.8 and I got this :

`DEBUG tdlib parameters set DEBUG state changes handled properly DEBUG received new auth state: UpdateAuthorizationState { extra: None, client_id: Some(1), authorization_state: WaitEncryptionKey(AuthorizationStateWaitEncryptionKey { extra: None, client_id: None, is_encrypted: false }) } DEBUG handling new auth state: WaitEncryptionKey(AuthorizationStateWaitEncryptionKey { extra: None, client_id: None, is_encrypted: false }) INFO wait for client's encryption key waiting for encryption key [ 3][t 0][1700992099.440389156][Client.cpp:291][&td_requests] End to wait for updates, returning object 0 (nil) [ 3][t 0][1700992099.440802097][Client.cpp:278][&td_requests] Begin to wait for updates with timeout 1.000000

` and then nothing happens, just endless loop of Begin/End messages... weird

— Reply to this email directly, view it on GitHub https://github.com/antonio-antuan/rust-tdlib/issues/37#issuecomment-1826737955, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRBAYCGRJLQO6HT3SQD3RDYGMGFNAVCNFSM6AAAAAA72RZZN6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRWG4ZTOOJVGU. You are receiving this because you commented.Message ID: @.***>

MrAliSalehi commented 11 months ago

Push "enter" here.

then it crashes without asking for verification code. shouldn't it print something ? like enter the thing or whatever...

update: it seems that you have to press enter everytime program reaches the "encryption key" even tho the user is logged-in.

antonio-antuan commented 11 months ago

yes, this is how tdlib (c library) is implemented. 1.8.21 doesn't have this requirement - you don't need to enter encryption key at all. if I'm not mistaken it become a parameter of setTdlibParameters structure.

antonio-antuan commented 11 months ago

about "it crashes" - is there any output?

MrAliSalehi commented 11 months ago

it dumped an error when unwraping the result of GetMe saying you are unauthorized, which was solved when i copy pasted this example.

antonio-antuan commented 11 months ago

So everything is fine? :)

On Sun, Nov 26, 2023, at 13:01, Ali wrote:

it dumped an error when unwraping the result of GetMe saying you are unauthorized, which was solved when i copy pasted this example https://github.com/antonio-antuan/rust-tdlib/blob/master/examples/auth_bot.rs.

— Reply to this email directly, view it on GitHub https://github.com/antonio-antuan/rust-tdlib/issues/37#issuecomment-1826764669, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRBAYHW3LDN4OGF4S6SKUTYGMVQTAVCNFSM6AAAAAA72RZZN6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRWG43DINRWHE. You are receiving this because you commented.Message ID: @.***>

MrAliSalehi commented 11 months ago

one more thing, its not related to this issue tho but im not sure if i should open another one.

when I tried to Ping a proxy, after half a second it returned "time out on send operation", without aborting or anything, it just kept saying it, and the proxy was fine tho, is this behaviour from tdlib or this crate?

MrAliSalehi commented 11 months ago

So everything is fine? :)

kinda yes, however im not sure what solved the issue or how it happend, but its gone for now, LoL

antonio-antuan commented 11 months ago

one more thing, its not related to this issue tho but im not sure if i should open another one.

when I tried to Ping a proxy, after half a second it returned "time out on send operation", without aborting or anything, it just kept saying it, and the proxy was fine tho, is this behaviour from tdlib or this crate?

This is a part of api.rs. Everything in that file is generated from td_api.tl (of particular version). Therefore - this is a part of tdlib implementation.

MrAliSalehi commented 11 months ago

its weird, is it possible to somehow cancel the operation? its blocks the process unfortunately and doesnt return anything

antonio-antuan commented 11 months ago

Could you provide your code?

On Sun, Nov 26, 2023, at 13:29, Ali wrote:

its weird, is it possible to somehow cancel the operation? its blocks the process unfortunately and doesnt return anything

— Reply to this email directly, view it on GitHub https://github.com/antonio-antuan/rust-tdlib/issues/37#issuecomment-1826771251, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRBAYCQJR36NZZIHYEOYODYGMY3TAVCNFSM6AAAAAA72RZZN6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRWG43TCMRVGE. You are receiving this because you commented.Message ID: @.***>

MrAliSalehi commented 11 months ago
tdjson::set_log_verbosity_level(2);
let tdlib_parameters = TdlibParameters::builder()
    .database_directory("tddb")
    .use_test_dc(false)
    .api_id(api_id)
    .api_hash(api_hash)
    .system_language_code("en")
    .device_model("Desktop")
    .system_version("Unknown")
    .application_version(env!("CARGO_PKG_VERSION"))
    .enable_storage_optimizer(true)
    .build();

let (sender, mut receiver) = tokio::sync::mpsc::channel::<Box<Update>>(100);

let client = Client::builder()
    .with_tdlib_parameters(tdlib_parameters)
    .with_updates_sender(sender)
    .with_client_auth_state_handler(ConsoleClientStateHandlerIdentified::new(ClientIdentifier::PhoneNumber(phone) ))
    .build()
    .unwrap();

let mut worker = Worker::builder()
    .with_auth_state_handler(AuthStateHandlerProxy::default())
    .build()
    .unwrap();
worker.start();

let client = worker.bind_client(client).await.unwrap();

let me1 = client.get_me(GetMe::builder().build()).await.unwrap();
log::info!("me: {:?}", me1);

// id :3
/*    let proxy = client.add_proxy(AddProxy::builder()
    .server("116.203.10.150")
    .port(8085)
    .type_(ProxyType::Mtproto(ProxyTypeMtproto::builder().secret("3QAAAAAAAAAAAAAAAAAAAAA=").build()))
    .enable(true)
    .build())
    .await;
*/ 

let seconds = client.ping_proxy(PingProxy::builder().proxy_id(3).build()).await; //blocks 

println!("seconds: {:?}",seconds);
antonio-antuan commented 11 months ago
  1. try to set_log_verbosity_level(3) and check what's happening there. probably tdlib provides significant logs for it.
  2. you can run any async request with a timeout like I do here
MrAliSalehi commented 11 months ago

with level 3 its generates a massive amount of irrelevant logs, take a look at this:

[ 3][t 4][1701064615.421191930][Td.cpp:4062][#1][!Td][&td_requests]     Sending update: updateUserFullInfo {
  user_id = 5656037268
  user_full_info = userFullInfo {
    photo = null
    is_blocked = false
    can_be_called = false
    supports_video_calls = false
    has_private_calls = false
    has_private_forwards = false
    need_phone_number_privacy_exception = true
    bio = ""
    share_text = ""
    description = ""
    group_in_common_count = 0
    commands = vector[0] {
    }
  }
}
[ 3][t 4][1701064615.641546010][MessagesManager.cpp:28987][&notifications]      Pending notifications timeout in chat -1001260949088 has expired
[ 3][t 4][1701064615.641577005][MessagesManager.cpp:29075][#1][!MessagesManager][&notifications]        Have no pending notifications in chat -1001260949088 to flush
ERROR can't send update: timed out waiting on send operation
[ 3][t 0][1701064615.951704263][Client.cpp:278][&td_requests]   Begin to wait for updates with timeout 1.000000
[ 3][t 0][1701064615.951758146][Client.cpp:291][&td_requests]   End to wait for updates, returning object 0 0x7f2ff01594c0
[ 3][t 4][1701064616.091123104][QueryCombiner.cpp:49][#1][!GetChatFullCombiner] Send query -1001287519485

notice the timeout in between is happening for no reason.

here is the log_level(2) after logging-in and trying to GetMe:

DEBUG checking password
[ 2][t 4][1701064535.575283050][AuthDataShared.cpp:107][#1][!Session:4:main]    DcId{4} [auth_key_id:5718717466472171885][state:OK][created_at:1701064527.000000]
DEBUG password checked
DEBUG state changes handled properly
DEBUG received new auth state: UpdateAuthorizationState { extra: None, client_id: Some(1), authorization_state: Ready(AuthorizationStateReady { extra: None, client_id: None }) }
DEBUG handling new auth state: Ready(AuthorizationStateReady { extra: None, client_id: None })
DEBUG ready state received, send signal
DEBUG state changes handled properly
[ 2][t 4][1701064536.225793123][Session.cpp:169][#1][!SessionProxy:1:main]      Generate new session_id 16390085199560917073 for auth key 10685133649086141928 for DC1
[ 2][t 4][1701064537.167244195][AuthDataShared.cpp:107][#1][!Session:1:main]    DcId{1} [auth_key_id:10685133649086141928][state:OK][created_at:1701064524.000000]
ERROR can't send update: timed out waiting on send operation
ERROR can't send update: timed out waiting on send operation
ERROR can't send update: timed out waiting on send operation
ERROR can't send update: timed out waiting on send operation

i dont know maybe its because the version 1.8 is too old or something, I think the library is broken, it would be nice if someone could try out the code and see the results are the same...

UPDATE: its funny even with I commented out the GetMe and other calls it still says timeout, basically im not doing anything lol, maybe the library is trying to call something that is "deprecated" and it blocks other calls in the queue ...

MrAliSalehi commented 11 months ago

I think I might be able to help if you could specify what needs to be done in #38

antonio-antuan commented 11 months ago

try that:

let mut worker = Worker::builder()
    .with_auth_state_handler(AuthStateHandlerProxy::default())
    .with_read_updates_timeout(10)
    .build()
    .unwrap();

probably it fixes the problem

MrAliSalehi commented 11 months ago

probably it fixes the problem

it did not, same thing happened again

antonio-antuan commented 11 months ago

ok I have to dive deeply into it

MrAliSalehi commented 11 months ago

I Noticed that when i removed the update handler .with_updates_sender(sender) the error never happened again

antonio-antuan commented 11 months ago

Yes, that's the reason of this error. So if you don't want to listen for updates - you can remove it. But if you do want - I have to fix it. Well, I anyway have to fix it...)

On Mon, Nov 27, 2023, at 11:03, Ali wrote:

I Noticed that when i removed the update handler .with_updates_sender(sender) the error never happened again

— Reply to this email directly, view it on GitHub https://github.com/antonio-antuan/rust-tdlib/issues/37#issuecomment-1827519410, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRBAYGCBSK4QKGUB3LXJ7TYGRQONAVCNFSM6AAAAAA72RZZN6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRXGUYTSNBRGA. You are receiving this because you commented.Message ID: @.***>

MrAliSalehi commented 11 months ago

let me know If I could help!

antonio-antuan commented 10 months ago

@MrAliSalehi sorry, was way too busy...
do you have a proxy to let me test it?

MrAliSalehi commented 10 months ago

yes

https://t.me/proxy?server=49.13.173.80&port=7443&secret=AAAAAAAAAAAAAAAAAAAAACQ%3D

https://t.me/proxy?server=tootfarangii.com.who_bounty.ir.tvsam.ir.dikon.ir.mirashonar.ir.za_frantee.com.digicasebook.ir.1397.ir.tinos.ir.r_occotehran.com.sepano.org.ir.ne_wsan_jesh.com.pezhart.ir.napars.ir.offweb.ir.m_id_sabac.ir.daewoomarket.com.nikalyaf.com.parskhazarstore.sbs&port=443&secret=3dpBFlW2hP6Hq_WOwiNeKBY%3D

https://t.me/proxy?server=Cloudflare.com.Nokia.com.co.uk.do_yo.want_to.clash_wbth.this.www.microsoft.com.there_is_no.place_like.localhost.www.bing.com.count_with_me.cyou.net.now_sudo.rm.again_to_fight.everyone.i_am.the_internet.xnbk-n2kl.sbs.&port=7443&secret=AAAAAAAAAAAAAAAAAAAAABQ%3D

https://t.me/proxy?server=Cloudflare.com.Nokia.com.co.uk.do_yo.want_to.clash_with.this.www.microsoft.com.there_is_no.place_like.localhost.www.bing.com.count_with_me.cyou.net.now_sudo.rm.again_to_fight.everyone.i_am.the_internet.gluid-gowm.sbs.&port=3443&secret=AAAAAAAAAAAAAAAAAAAAAGQ%3D
antonio-antuan commented 10 months ago

I don't experience the same problem (but used proxies from here)

[2023-12-23T20:17:47Z WARN  read_updates] bind client
[2023-12-23T20:17:48Z WARN  read_updates] wait authorized
[2023-12-23T20:17:48Z WARN  read_updates] client authorized; can start interaction
[2023-12-23T20:17:49Z WARN  read_updates] proxy
[2023-12-23T20:17:49Z WARN  read_updates] proxy added, start ping
[2023-12-23T20:17:49Z WARN  read_updates] ping proxy: Ok(Seconds { extra: Some("197f7a86-05e1-489f-8f96-97c3c501bd0b"), client_id: Some(1), seconds: 0.101716 })

try the following code and please say if it helps. probably the reason is "wait_authorized" function call. also I used that rust-tdlib version (didn't have a chance to release it yet). also note, the process stucls

PHONE=+999999999 RUST_LOG=warn VERBOSITY=1 API_ID=999999 API_HASH=hash cargo run

#[tokio::main]
async fn main() {
    tdjson::set_log_verbosity_level(
        std::env::var("VERBOSITY")
            .unwrap_or("1".to_string())
            .parse::<i32>()
            .unwrap(),
    );
    env_logger::init();
    let tdlib_parameters = SetTdlibParameters::builder()
        .database_directory("tddb")
        .use_test_dc(false)
        .api_id(std::env::var("API_ID").unwrap().parse::<i32>().unwrap())
        .api_hash(std::env::var("API_HASH").unwrap())
        .system_language_code("en")
        .device_model("Desktop")
        .system_version("Unknown")
        .application_version(env!("CARGO_PKG_VERSION"))
        .enable_storage_optimizer(true)
        .build();

    let (sender, mut receiver) = tokio::sync::mpsc::channel::<Box<Update>>(100);

    let client = Client::builder()
        .with_tdlib_parameters(tdlib_parameters)
        .with_updates_sender(sender)
        .with_auth_state_channel(10)
        .with_client_auth_state_handler(ConsoleClientStateHandlerIdentified::new(
            ClientIdentifier::PhoneNumber(std::env::var("PHONE").unwrap()),
        ))
        .build()
        .unwrap();

    tokio::spawn(async move {
        while let Some(message) = receiver.recv().await {
            log::info!("updates handler received {:?}", message);
        }
    });

    let mut worker = Worker::builder()
        .with_auth_state_handler(AuthStateHandlerProxy::default())
        .build()
        .unwrap();
    let waiter = worker.start();

    log::warn!("bind client");
    let client = match worker.bind_client(client).await {
        Ok(cl) => cl,
        Err(err) => {
            panic!("cannot bind client: {}", err)
        }
    };

    log::warn!("wait authorized");
    wait_authorized(&client, &worker).await;
    let me1 = client.get_me(GetMe::builder().build()).await.unwrap();
    log::info!("me: {:?}", me1);
    log::warn!("proxy");
    let proxy = client
        .add_proxy(
            AddProxy::builder()
                .server("185.222.28.236")
                .port(4443)
                .type_(ProxyType::Mtproto(
                    ProxyTypeMtproto::builder()
                        .secret("FgMBAgABAAH8AwOG4kw63Q==")
                        .build(),
                ))
                .enable(true)
                .build(),
        )
        .await
        .unwrap();
    log::warn!("proxy added, start ping");
    let seconds = client
        .ping_proxy(PingProxy::builder().proxy_id(proxy.id()).build())
        .await;
    log::warn!("ping proxy: {:?}", seconds);
    worker.stop();
    log::warn!("worker stopped");
    waiter.await.unwrap();
    log::warn!("exit");
}

async fn wait_authorized(client: &Client<TdJson>, worker: &Worker<AuthStateHandlerProxy, TdJson>) {
    loop {
        match worker.wait_auth_state_change(&client).await {
            Ok(res) => match res {
                Ok(state) => match state {
                    ClientState::Opened => {
                        log::warn!("client authorized; can start interaction");
                        break;
                    }
                    _ => {
                        panic!("client not authorized: {:?}", state);
                    }
                },
                Err((err, auth_state)) => {
                    panic!("cannot handle auth state: {} {:?}", err, auth_state);
                }
            },
            Err(err) => {
                panic!("cannot wait for auth state changes: {}", err);
            }
        }
    }
}
alimhdv commented 9 months ago

hi there i got a question would u please tell me in steps how i should install a mtproto proxy for telegram in ubuntu like this one below? https://t.me/proxy?server=136.243.132.238&port=250&secret=FgMBAgABAAH8AwOG4kw63Q==

I read the comments above and installed tdlib but know i don't understand what to do );

antonio-antuan commented 9 months ago

How do you want to use it? In your desktop client?)

alimhdv commented 9 months ago

yeah in desktop

antonio-antuan commented 9 months ago

This is not the right place to ask such a question) Try to follow that link: https://github.com/telegramdesktop/tdesktop

alimhdv commented 9 months ago

No, I mean that I want to build proxies like that one I showed you above I tried most of the scripts in github like this https://github.com/seriyps/mtproto_proxy/tree/master or this https://github.com/TelegramMessenger/MTProxy but niether one gives me a proxy with this secret: FgMBAgABAAH8AwOG4kw63Q==

antonio-antuan commented 9 months ago

I don't know, my library is not for that