Conversation
|
dear nvv1d |
|
6 month ago i extensively optimized this code to work in low-ram-vps |
|
Asyncio brings efficient resource usage and better code safety. |
|
@byehack yes we finally need to add into xray-core |
| from logging.handlers import TimedRotatingFileHandler | ||
|
|
||
| import configparser | ||
| import random |
| global listen_PORT, Cloudflare_IPs, Cloudflare_port, L_fragment, fragment_sleep, my_socket_timeout, first_time_sleep, accept_time_sleep | ||
| listen_PORT = int(config.get('settings', 'listen_PORT')) | ||
| Cloudflare_IPs = [ip.strip() for ip in config.get('settings', 'Cloudflare_IP').split(',')] | ||
| Cloudflare_port = int(config.get('settings', 'Cloudflare_port')) |
There was a problem hiding this comment.
Cloudflare_IPs = itertools.cycle(Cloudflare_IPs)
| global Cloudflare_IPs | ||
| selected_ip = random.choice(Cloudflare_IPs) | ||
| Cloudflare_IPs = Cloudflare_IPs[1:] + [selected_ip] | ||
| return selected_ip |
There was a problem hiding this comment.
def get_next_backend_ip():
global Cloudflare_IPs
return next(Cloudflare_IPs)
|
It consumes a lot of CPU! |
UPDATE:
Here's an outline of the changes made in both the config.ini and gfw_resist_tls_proxy.py files:
config.ini file:
Cloudflare_IPsection to include a comma-separated list of IP addresses instead of a single IP address..py file:
randommodule to enable random selection of IP addresses.load_config()function to:Cloudflare_IPsection as a comma-separated list of IP addresses and store them in theCloudflare_IPsglobal variable.get_next_backend_ip()to:my_upstream()function to:get_next_backend_ip()function to get the next backend IP address for each request.main()function to: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.
(#12 (comment))
configparserlibrary to read settings from a configuration file.config.inifile with the necessary settings.parse_args()function to handle command-line arguments.load_config()function to load settings from the configuration file.main()function to use the new configuration handling functions.argparselibrary to handle command-line arguments.parse_args()function to accept a--configargument for specifying a custom configuration file.argparsemodule.configparsermodule.ThreadedServerclass with aThreadPoolExecutorto handle multiple client connections concurrently.send_data_in_fragmentfunction outside of theThreadedServerclass and made it a standalone function.my_upstreamandmy_downstreamfunctions to use the "with" statement for better resource management.