Skip to content

Merge upstream PRs #184 and #308: Docker config via environment variables and connection pool disable#2

Merged
xrh0905 merged 4 commits into
edgefrom
copilot/merge-code-upgrade-prs
Dec 9, 2025
Merged

Merge upstream PRs #184 and #308: Docker config via environment variables and connection pool disable#2
xrh0905 merged 4 commits into
edgefrom
copilot/merge-code-upgrade-prs

Conversation

Copy link
Copy Markdown

Copilot AI commented Dec 9, 2025

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)

  • config.py: Added environment variable support for TG_KEY, SECURE_ONLY, TLS_ONLY, TLS_DOMAIN, AD_TAG
  • Implemented str_to_bool() helper to properly convert string env vars to booleans (fixes issue where any non-empty string would evaluate to True)
  • docker-compose.yml: Switched from inline build to pre-built image with configurable environment variables
  • README.md: Added docker build -t mtprotoproxy . step before docker-compose up

Connection Pool Disable (PR alexbers#308)

  • mtprotoproxy.py: Commented out connection pool logic in TgConnectionPool.get_connection()
  • Prevents Telegram from showing "updating" status for users with fewer connections
  • Applied black formatting across codebase

Supporting Changes

  • Added .gitignore for Python cache files

Example Usage

# Build once
docker build -t mtprotoproxy .

# Run with custom config via environment variables
TG_KEY=custom_secret_here TLS_DOMAIN=example.com docker-compose up -d

Note: Boolean env vars support multiple formats: true/false, 1/0, yes/no, on/off (case-insensitive).

Original prompt

This section details on the original issue you should resolve

<issue_title>Code upgrade</issue_title>
<issue_description>alexbers#184
alexbers#308

Merge these PR.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

Copilot AI and others added 3 commits December 9, 2025 15:10
…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>
Copilot AI changed the title [WIP] Merge code upgrade pull requests Merge upstream PRs #184 and #308: Docker config via environment variables and connection pool disable Dec 9, 2025
Copilot AI requested a review from xrh0905 December 9, 2025 15:17
@xrh0905 xrh0905 marked this pull request as ready for review December 9, 2025 15:19
Copilot AI review requested due to automatic review settings December 9, 2025 15:19
@xrh0905 xrh0905 merged commit 0cf317d into edge Dec 9, 2025
4 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread config.py
Comment on lines +23 to +27
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"))
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. The old MODES dictionary structure is no longer present in config.py
  2. Users will see legacy warnings even though they're using the "new" config format
  3. The conversion logic will not work as expected since MODES is never defined in config.py

The configuration should either:

  • Define MODES dictionary and populate it based on environment variables, OR
  • Remove the legacy warning since this is now the intended configuration format

Copilot uses AI. Check for mistakes.
Comment thread docker-compose.yml
Comment on lines +7 to +13
environment:
- TG_KEY=00000000000000000000000000000001
- SECURE_ONLY=true
- TLS_ONLY=true
- TLS_DOMAIN=www.drive.google.com
- AD_TAG=3c09c680b76ee91a4c25ad51f742267d

Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Remove the config.py volume mount to allow environment variables to work, OR
  2. 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.

Suggested change
environment:
- TG_KEY=00000000000000000000000000000001
- SECURE_ONLY=true
- TLS_ONLY=true
- TLS_DOMAIN=www.drive.google.com
- AD_TAG=3c09c680b76ee91a4c25ad51f742267d

Copilot uses AI. Check for mistakes.
Comment thread docker-compose.yml
- TG_KEY=00000000000000000000000000000001
- SECURE_ONLY=true
- TLS_ONLY=true
- TLS_DOMAIN=www.drive.google.com
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Google domains may have specific TLS configurations that could make the proxy detectable
  2. The warning in the code suggests avoiding Google domains in general

Consider using a different, non-Google domain as the default example.

Suggested change
- TLS_DOMAIN=www.drive.google.com
- TLS_DOMAIN=www.cloudflare.com

Copilot uses AI. Check for mistakes.
Comment thread README.md
@@ -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**
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Editing config.py directly (existing method)
  2. Using environment variables (new method introduced in this PR)

This would help users understand their configuration options.

Copilot uses AI. Check for mistakes.
Comment thread mtprotoproxy.py
b"\xdd\xdd\xdd\xdd", b"\x16\x03\x01\x02"]
RESERVED_NONCE_BEGININGS = [
b"\x48\x45\x41\x44",
b"\x50\x4f\x53\x54",
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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:

  1. There's any string comparison happening elsewhere in the code
  2. 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.

Suggested change
b"\x50\x4f\x53\x54",
b"\x50\x4F\x53\x54",

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

Code upgrade

3 participants