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

AddProxy #3260

Open
pfeux opened this issue Feb 28, 2025 · 12 comments
Open

AddProxy #3260

pfeux opened this issue Feb 28, 2025 · 12 comments

Comments

@pfeux
Copy link

pfeux commented Feb 28, 2025

Hi

What is the best way to use AddProxy? Is there any sequence that needs to be followed?

Thanks

@levlam
Copy link
Contributor

levlam commented Feb 28, 2025

AddProxy is just a method that can be called like any other method.

@pfeux
Copy link
Author

pfeux commented Feb 28, 2025

AddProxy is just a method that can be called like any other method.

When do we call that method? Any particular sequence we need to follow? Any implementation sample you can provide?

@levlam
Copy link
Contributor

levlam commented Mar 1, 2025

You call it whenever you want to enable the proxy. It can be called any time.

@pfeux
Copy link
Author

pfeux commented Mar 1, 2025

You call it whenever you want to enable the proxy. It can be called any time.

Thanks @levlam for your reply.

In python sample provided in this repo, if I call AddProxy function before the following line, will my client use proxy for rest of the functions called e.g. calling setTdlibParameters, or setAuthenticationPhoneNumber, or other td_send commands OR do I need to call AddProxy before I call any td_send commands in that file?

td_send({'@type': 'getOption', 'name': 'version', '@extra': 1.01234})

@levlam
Copy link
Contributor

levlam commented Mar 1, 2025

You need to enable the proxy only once.

@pfeux
Copy link
Author

pfeux commented Mar 2, 2025

Following is my implementations:

    # create client
    client_id = _td_create_client_id()

    # setting TDLib log verbosity level to 1 (errors)
    print("setting log verbosity level to 4\n\n")
    print(td_execute(
        {
            "@type": "setLogVerbosityLevel",
            "new_verbosity_level": 4,
            "@extra": 1.01234,
        }
    ))

    print("setting the proxy\n\n")
    td_send(client_id,
        {
            "@type": "addProxy",
            "server": "socks.domain.io",
            "port": "1080",
            "enable": True,
            "type": {
                '@type': 'proxyTypeSocks5',
                'username': 'user1',
                'password': 'password1',
            }
        }
    )
    
    while True:
        event = td_receive()
        if event:
            print(str(event).encode("utf-8"))
            sys.stdout.flush()
        else:
            break

And following is log

[ 3][t 0][1740908168.974244117][Client.cpp:482] Created managed client 1
setting log verbosity level to 4


{'@type': 'ok', '@extra': 1.01234}
setting the proxy


[ 3][t 0][1740908168.975667238][Client.cpp:383] Initialize client 1
[ 3][t 0][1740908168.975809335][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 10.000000
[ 3][t 5][1740908168.976253986][Td.cpp:138][#1][!MultiTd]       Create Td with layer 199, database version 14 and version 54 on 4 threads
[ 3][t 5][1740908168.976453304][Td.cpp:1346][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "version"
  value = optionValueString {
    value = "1.8.45"
  }
}
[ 3][t 5][1740908168.976557970][Td.cpp:1346][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "commit_hash"
  value = optionValueString {
    value = "521aed8e497beb19d97c26ff39708542dc262023"
  }
}
[ 3][t 0][1740908168.976570129][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0000027C70AFF2A0
[ 3][t 5][1740908168.976685047][Td.cpp:1353][#1][!Td][&td_requests]     Sending update: updateAuthorizationState {
  authorization_state = authorizationStateWaitTdlibParameters {
  }
}
b"{'@type': 'updateOption', 'name': 'version', 'value': {'@type': 'optionValueString', 'value': '1.8.45'}, '@client_id': 1}"
[ 3][t 5][1740908168.976894855][Td.cpp:280][#1][!Td][&td_requests]  Receive request 1: addProxy {
  server = "socks.domain.io"
  port = 1080
  enable = true
  type = proxyTypeSocks5 {
    username = "user1"
    password = "password1"
  }
}

[ 3][t 0][1740908168.977263212][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 10.000000
[ 3][t 0][1740908168.978175878][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0000027C70AFF810
b"{'@type': 'updateOption', 'name': 'commit_hash', 'value': {'@type': 'optionValueString', 'value': '521aed8e497beb19d97c26ff39708542dc262023'}, '@client_id': 1}"
[ 3][t 0][1740908168.978806734][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 10.000000
[ 3][t 0][1740908168.978893518][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0000027C7012DE20
b"{'@type': 'updateAuthorizationState', 'authorization_state': {'@type': 'authorizationStateWaitTdlibParameters'}, '@client_id': 1}"
[ 3][t 0][1740908168.979180097][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 10.000000
[ 3][t 0][1740908178.982606172][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0000000000000000

I am sure I am not connected to socks proxy. Can you please let me know what is wrong with my code?

@levlam
Copy link
Contributor

levlam commented Mar 3, 2025

The code is correct. The proxy will be used whenever network requests are sent.

@tdlib tdlib deleted a comment from Phlphat746 Mar 3, 2025
@tdlib tdlib deleted a comment from Abudl68 Mar 3, 2025
@pfeux
Copy link
Author

pfeux commented Mar 4, 2025

Hi @levlam

It's not picking up proxy. In my devices list, I get the country where I run the code and not proxy's country.

@levlam
Copy link
Contributor

levlam commented Mar 4, 2025

Check TDLib logs for details.

@pfeux
Copy link
Author

pfeux commented Mar 4, 2025

I get no difference in log. I only changed 60 seconds for timeout. What is the expected response when I send AddProxy?

[ 3][t 0][1741077494.374069213][Client.cpp:482] Created managed client 1
[ 3][t 0][1741077494.374596834][Client.cpp:383] Initialize client 1
[ 3][t 0][1741077494.374835014][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 60.000000
[ 3][t 5][1741077494.375391006][Td.cpp:138][#1][!MultiTd]       Create Td with layer 199, database version 14 and version 54 on 4 threads
[ 3][t 5][1741077494.375548601][Td.cpp:1346][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "version"
  value = optionValueString {
    value = "1.8.45"
  }
}
[ 3][t 5][1741077494.375674247][Td.cpp:1346][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "commit_hash"
  value = optionValueString {
    value = "521aed8e497beb19d97c26ff39708542dc262023"
  }
}
[ 3][t 0][1741077494.375684022][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0000022B7D113E40
[ 3][t 5][1741077494.375776052][Td.cpp:1353][#1][!Td][&td_requests]     Sending update: updateAuthorizationState {
  authorization_state = authorizationStateWaitTdlibParameters {
  }
}
b"{'@type': 'updateOption', 'name': 'version', 'value': {'@type': 'optionValueString', 'value': '1.8.45'}, '@client_id': 1}"[ 3][t 5][1741077494.376001834][Td.cpp:280][#1][!Td][&td_requests]  Receive request 1: addProxy {
server = "socks.domain.io"
  port = 1080
  enable = true
  type = proxyTypeSocks5 {
    username = "user1"
    password = "password1"
  }
}

[ 3][t 0][1741077494.376305103][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 60.000000
[ 3][t 0][1741077494.376430273][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0000022B7D113DE0
b"{'@type': 'updateOption', 'name': 'commit_hash', 'value': {'@type': 'optionValueString', 'value': '521aed8e497beb19d97c26ff39708542dc262023'}, '@client_id': 1}"
[ 3][t 0][1741077494.376805782][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 60.000000
[ 3][t 0][1741077494.376943111][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0000022B7D12DB40
b"{'@type': 'updateAuthorizationState', 'authorization_state': {'@type': 'authorizationStateWaitTdlibParameters'}, '@client_id': 1}"
[ 3][t 0][1741077494.377299308][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 60.000000
[ 3][t 0][1741077554.386652708][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0000000000000000

@levlam
Copy link
Contributor

levlam commented Mar 4, 2025

You didn't even try to initialize and use TDLib in the provided log.

@pfeux
Copy link
Author

pfeux commented Mar 4, 2025

Apologies for my limited knowledge but can you please elaborate initialize?

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

2 participants