Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valid api_id must be provided. #37

Open
MrAliSalehi opened this issue Nov 26, 2023 · 32 comments
Open

Valid api_id must be provided. #37

MrAliSalehi opened this issue Nov 26, 2023 · 32 comments

Comments

@MrAliSalehi
Copy link

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
Copy link
Owner

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 1.8.21 support #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
Copy link
Author

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
Copy link
Owner

antonio-antuan commented Nov 26, 2023 via email

@MrAliSalehi
Copy link
Author

MrAliSalehi commented Nov 26, 2023

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
Copy link
Owner

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
Copy link
Owner

about "it crashes" - is there any output?

@MrAliSalehi
Copy link
Author

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
Copy link
Owner

antonio-antuan commented Nov 26, 2023 via email

@MrAliSalehi
Copy link
Author

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

@antonio-antuan
Copy link
Owner

antonio-antuan commented Nov 26, 2023 via email

@MrAliSalehi
Copy link
Author

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
Copy link
Owner

  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
Copy link
Author

MrAliSalehi commented Nov 27, 2023

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
Copy link
Author

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

@antonio-antuan
Copy link
Owner

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
Copy link
Author

MrAliSalehi commented Nov 27, 2023

probably it fixes the problem

it did not, same thing happened again

@antonio-antuan
Copy link
Owner

ok I have to dive deeply into it

@MrAliSalehi
Copy link
Author

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

@antonio-antuan
Copy link
Owner

antonio-antuan commented Nov 27, 2023 via email

@MrAliSalehi
Copy link
Author

let me know If I could help!

@antonio-antuan
Copy link
Owner

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

@MrAliSalehi
Copy link
Author

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
Copy link
Owner

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
Copy link

alimhdv commented Feb 2, 2024

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
Copy link
Owner

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

@alimhdv
Copy link

alimhdv commented Feb 2, 2024

yeah in desktop

@antonio-antuan
Copy link
Owner

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

@alimhdv
Copy link

alimhdv commented Feb 2, 2024

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
Copy link
Owner

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

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

No branches or pull requests

3 participants