gfw_resist_tls_proxy
gfw_resist_tls_proxy copied to clipboard
Some Improvements (Outlined Below)
UPDATE: Here's an outline of the changes made in both the config.ini and gfw_resist_tls_proxy.py files:
-
config.ini file:
- Updated the
Cloudflare_IP
section to include a comma-separated list of IP addresses instead of a single IP address.
- Updated the
-
.py file:
- Imported the
random
module to enable random selection of IP addresses. - Modified the
load_config()
function to:- Read the
Cloudflare_IP
section as a comma-separated list of IP addresses and store them in theCloudflare_IPs
global variable.
- Read the
- Added a new function
get_next_backend_ip()
to:- Implement a round-robin load balancing algorithm by randomly selecting an IP address from the list and rotating the list.
- Modified the
my_upstream()
function to:- Call the
get_next_backend_ip()
function to get the next backend IP address for each request. - Updated the my_upstream() function to print the selected backend IP address when it's connected.
- Call the
- Updated the
main()
function to:- Print the list of IP addresses in the output message.
- Imported the
These changes allow the proxy server to accept a list of IP addresses and use a round-robin load balancing algorithm to randomly select and rotate IP addresses for each request. (https://github.com/GFW-knocker/gfw_resist_tls_proxy/issues/12#issue-1683062047)
- Added support for a configuration file:
- Imported
configparser
library to read settings from a configuration file. - Created a
config.ini
file with the necessary settings. - Added
parse_args()
function to handle command-line arguments. - Added
load_config()
function to load settings from the configuration file. - Updated the
main()
function to use the new configuration handling functions.
- Imported
- Added support for command-line arguments:
- Imported
argparse
library to handle command-line arguments. - Updated the
parse_args()
function to accept a--config
argument for specifying a custom configuration file.
- Imported
- Added command line argument parsing using the
argparse
module. - Added configuration file support using the
configparser
module. - Replaced the
ThreadedServer
class with aThreadPoolExecutor
to handle multiple client connections concurrently. - Moved the
send_data_in_fragment
function outside of theThreadedServer
class and made it a standalone function. - Removed unnecessary imports and variables.
- Added logging support using the logging module.
- Refactored the
my_upstream
andmy_downstream
functions to use the "with" statement for better resource management. - Changed print statements to logging statements for better readability and maintainability.
- Added docstrings to functions for better documentation.
dear nvv1d i highly appreciate your effort i made a branch "LoadBalancer" for you please pull to that.
6 month ago i extensively optimized this code to work in low-ram-vps i found that ThreadPoolExecutor is much resource hungry , even worse when using asyncio its obvious when +15000 simultaneous connection need to be handle
Asyncio brings efficient resource usage and better code safety. Do you need to update codebase to async? maybe I could help. or if this script is just POW and need to re-work in low-level, let keep this simple without major changes.
@byehack in theory asyncio is faster i waste two weeks , finally found that is faster in IO but use more CPU and RAM.
yes we finally need to add into xray-core so we may switch to c++ or go-lang perhaps