Merge upstream PRs #184 and #308: Docker config via environment variables and connection pool disable#2
Conversation
…nd connection pool disable Co-authored-by: xrh0905 <29017419+xrh0905@users.noreply.github.com>
Co-authored-by: xrh0905 <29017419+xrh0905@users.noreply.github.com>
…isabled connection pool Co-authored-by: xrh0905 <29017419+xrh0905@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR merges two upstream changes from the alexbers/mtprotoproxy repository: environment variable-based configuration for Docker deployments (PR alexbers#184) and connection pooling disable with code formatting improvements (PR alexbers#308). The changes aim to simplify Docker configuration and improve user experience by preventing Telegram's "updating" status.
- Adds environment variable support for configuration (TG_KEY, SECURE_ONLY, TLS_ONLY, TLS_DOMAIN, AD_TAG)
- Disables connection pooling to prevent "updating" status for users with fewer connections
- Applies Black formatting throughout mtprotoproxy.py for consistent code style
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| config.py | Adds environment variable support with str_to_bool() helper, replaces MODES dictionary with SECURE_ONLY and TLS_ONLY booleans |
| docker-compose.yml | Switches to pre-built image with environment variable configuration examples |
| README.md | Updates installation instructions to include docker build step |
| .gitignore | Adds Python cache files and build artifacts |
| mtprotoproxy.py | Disables connection pooling logic and applies Black code formatting throughout |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| SECURE_ONLY = str_to_bool(os.environ.get("SECURE_ONLY", "True")) | ||
|
|
||
| # Makes the proxy even more hard to detect | ||
| # Can be incompatible with old clients | ||
| "tls": True | ||
| } | ||
| # Makes the proxy even more hard to detect | ||
| # Compatible only with the recent clients | ||
| TLS_ONLY = str_to_bool(os.environ.get("TLS_ONLY", "True")) |
There was a problem hiding this comment.
The config.py now defines SECURE_ONLY and TLS_ONLY as top-level boolean variables, but mtprotoproxy.py treats these as legacy options (lines 182-203 in mtprotoproxy.py) and expects a MODES dictionary instead. This creates a mismatch:
- The old
MODESdictionary structure is no longer present in config.py - Users will see legacy warnings even though they're using the "new" config format
- The conversion logic will not work as expected since
MODESis never defined in config.py
The configuration should either:
- Define
MODESdictionary and populate it based on environment variables, OR - Remove the legacy warning since this is now the intended configuration format
| environment: | ||
| - TG_KEY=00000000000000000000000000000001 | ||
| - SECURE_ONLY=true | ||
| - TLS_ONLY=true | ||
| - TLS_DOMAIN=www.drive.google.com | ||
| - AD_TAG=3c09c680b76ee91a4c25ad51f742267d | ||
|
|
There was a problem hiding this comment.
The docker-compose.yml mounts ./config.py as a volume (line 15), which will override any environment variable configuration. This means the environment variables defined in lines 8-12 won't have any effect since the mounted config.py file will take precedence.
Either:
- Remove the config.py volume mount to allow environment variables to work, OR
- Remove the environment variable examples since they won't work with the current setup
The current configuration creates a confusing situation where users might set environment variables but they'll be ignored.
| environment: | |
| - TG_KEY=00000000000000000000000000000001 | |
| - SECURE_ONLY=true | |
| - TLS_ONLY=true | |
| - TLS_DOMAIN=www.drive.google.com | |
| - AD_TAG=3c09c680b76ee91a4c25ad51f742267d |
| - TG_KEY=00000000000000000000000000000001 | ||
| - SECURE_ONLY=true | ||
| - TLS_ONLY=true | ||
| - TLS_DOMAIN=www.drive.google.com |
There was a problem hiding this comment.
The TLS_DOMAIN is set to "www.drive.google.com" but mtprotoproxy.py (line 2420-2426) specifically warns against using the default "www.google.com". While this is technically a different domain, using any google.com subdomain for masking could be problematic:
- Google domains may have specific TLS configurations that could make the proxy detectable
- The warning in the code suggests avoiding Google domains in general
Consider using a different, non-Google domain as the default example.
| - TLS_DOMAIN=www.drive.google.com | |
| - TLS_DOMAIN=www.cloudflare.com |
| @@ -6,8 +6,9 @@ Fast and simple to setup MTProto proxy written in Python. | |||
|
|
|||
| 1. `git clone -b stable https://github.com/alexbers/mtprotoproxy.git; cd mtprotoproxy` | |||
| 2. *(optional, recommended)* edit *config.py*, set **PORT**, **USERS** and **AD_TAG** | |||
There was a problem hiding this comment.
Step 2 recommends editing config.py to set PORT, USERS, and AD_TAG, but with the new environment variable approach introduced in this PR, users could also configure these via environment variables (TG_KEY, AD_TAG, etc.). The README should be updated to mention both configuration methods:
- Editing config.py directly (existing method)
- Using environment variables (new method introduced in this PR)
This would help users understand their configuration options.
| b"\xdd\xdd\xdd\xdd", b"\x16\x03\x01\x02"] | ||
| RESERVED_NONCE_BEGININGS = [ | ||
| b"\x48\x45\x41\x44", | ||
| b"\x50\x4f\x53\x54", |
There was a problem hiding this comment.
[nitpick] The hex byte string has been changed from uppercase 'F' to lowercase 'f' in the formatting pass. While Python treats \x4F and \x4f as equivalent (both represent 'O' in ASCII/hex), this change could potentially cause issues if:
- There's any string comparison happening elsewhere in the code
- The original case was intentional for readability
However, since these are byte literals in hex notation, this change should be functionally equivalent. Consider keeping consistent casing (either all uppercase or all lowercase) for hex literals throughout the file for better readability.
| b"\x50\x4f\x53\x54", | |
| b"\x50\x4F\x53\x54", |
Merges two upstream PRs from alexbers/mtprotoproxy: PR alexbers#184 (Docker/config improvements) and PR alexbers#308 (connection pool disable + code formatting).
Changes
Environment Variable Configuration (PR alexbers#184)
TG_KEY,SECURE_ONLY,TLS_ONLY,TLS_DOMAIN,AD_TAGstr_to_bool()helper to properly convert string env vars to booleans (fixes issue where any non-empty string would evaluate toTrue)docker build -t mtprotoproxy .step beforedocker-compose upConnection Pool Disable (PR alexbers#308)
TgConnectionPool.get_connection()Supporting Changes
.gitignorefor Python cache filesExample Usage
Note: Boolean env vars support multiple formats:
true/false,1/0,yes/no,on/off(case-insensitive).Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.