gfw_resist_tls_proxy icon indicating copy to clipboard operation
gfw_resist_tls_proxy copied to clipboard

Some Improvements (Outlined Below)

Open nvv1d opened this issue 1 year ago • 4 comments

UPDATE: Here's an outline of the changes made in both the config.ini and gfw_resist_tls_proxy.py files:

  1. config.ini file:

    • Updated the Cloudflare_IP section to include a comma-separated list of IP addresses instead of a single IP address.
  2. .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 the Cloudflare_IPs global variable.
    • 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.
    • Updated the main() function to:
      • Print the list of IP addresses in the output message.

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)

  1. 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.
  2. 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.
  3. Added command line argument parsing using the argparse module.
  4. Added configuration file support using the configparser module.
  5. Replaced the ThreadedServer class with a ThreadPoolExecutor to handle multiple client connections concurrently.
  6. Moved the send_data_in_fragment function outside of the ThreadedServer class and made it a standalone function.
  7. Removed unnecessary imports and variables.
  8. Added logging support using the logging module.
  9. Refactored the my_upstream and my_downstream functions to use the "with" statement for better resource management.
  10. Changed print statements to logging statements for better readability and maintainability.
  11. Added docstrings to functions for better documentation.

nvv1d avatar Apr 25 '23 19:04 nvv1d

dear nvv1d i highly appreciate your effort i made a branch "LoadBalancer" for you please pull to that.

GFW-knocker avatar Apr 26 '23 06:04 GFW-knocker

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

GFW-knocker avatar Apr 26 '23 06:04 GFW-knocker

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 avatar Apr 26 '23 08:04 byehack

@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

GFW-knocker avatar Apr 26 '23 09:04 GFW-knocker