"server_config_pipeline.json", prepare_client_tun_config("client_config_pipeline.json"), "server_config_pipeline_balance.json", is_tun=True) != 0: output_log = True return 1 finally: close_process(test_server_process, output_log) print_time_log("!!!!! ALL SUCC, GREAT JOB !!!!") return 0 if __name__ == "__main__": print_time_log(__file__ + " args : " + str(sys.argv)) parser = argparse.ArgumentParser() parser.add_argument("binary", help='path of trojan binary') parser.add_argument( "-g", "--genfile", help='whether generate testing files and set quantity of files', type=int, nargs='?', const=TEST_FILES_COUNT) parser.add_argument("-gs", "--genfileSize", help='generating files\' size', type=int, nargs='?', const=TEST_FILES_SIZE)
def main(): if cmd_args.genfile: size = cmd_args.genfileSize if cmd_args.genfileSize else TEST_FILES_SIZE print_time_log('generating ' + str(cmd_args.genfile) + ' test files each ' + str(size) + ' bytes...') fulltest_gen_content.gen_files(TEST_FILES_DIR, cmd_args.genfile, size) global binary_path binary_path = os.path.realpath(cmd_args.binary) print_time_log("binary_path == " + binary_path) print_time_log("start testing server...") test_server_process = run_test_server() if not test_server_process: return 1 output_log = False print_time_log("done!") try: if cmd_args.normal or cmd_args.dns: print_time_log( "start trojan plus in client run_type without pipeline...") if main_stage("server_config.json", "client_config.json") != 0: output_log = True return 1 print_time_log( "start trojan plus in client run_type in pipeline...") if main_stage("server_config_pipeline.json", "client_config_pipeline.json", "server_config_pipeline_balance.json") != 0: output_log = True return 1 if cmd_args.normal: print_time_log( "start trojan plus in forward run_type without pipeline..." ) if main_stage("server_config.json", prepare_forward_config("client_config.json"), is_foward=True) != 0: output_log = True return 1 print_time_log( "start trojan plus in forward run_type in pipeline...") if main_stage( "server_config_pipeline.json", prepare_forward_config("client_config_pipeline.json"), "server_config_pipeline_balance.json", is_foward=True) != 0: output_log = True return 1 if cmd_args.tun: print_time_log( "restart test http server to test client_tun run_type...") close_process(test_server_process, False) test_server_process = run_test_server() if not test_server_process: return 1 print_time_log("done!") print_time_log( "start trojan plus in client_tun run_type without pipeline...") if main_stage("server_config.json", prepare_client_tun_config("client_config.json"), is_tun=True) != 0: output_log = True return 1 print_time_log( "start trojan plus in client_tun run_type in pipeline...") if main_stage( "server_config_pipeline.json", prepare_client_tun_config("client_config_pipeline.json"), "server_config_pipeline_balance.json", is_tun=True) != 0: output_log = True return 1 finally: close_process(test_server_process, output_log) print_time_log("!!!!! ALL SUCC, GREAT JOB !!!!") return 0
def start_query(ns, count, port): global query_port query_port = port with ThreadPoolExecutor(max_workers=PARALLEL_REQUEST_COUNT) as executor: for _ in range(0, 2): print_time_log('start lookup ' + str(len(direct_lookup_domains)) + ' direct domains...') if not main_process(executor, direct_lookup_domains, ns, count): return False print_time_log('done') print_time_log('start lookup ' + str(len(proxy_lookup_domains)) + ' proxy domains...') if not main_process(executor, proxy_lookup_domains, ns, count): return False print_time_log('done') print_time_log('start lookup ' + str(len(proxy_lookup_domains)) + ' direct NON-domains...') if not main_process(executor, direct_lookup_non_domains, ns, count, True): return False print_time_log('done') print_time_log('start lookup ' + str(len(proxy_lookup_domains)) + ' proxy NON-domains...') if not main_process(executor, proxy_lookup_non_domains, ns, count, True): return False print_time_log('done') return True
def main_stage(server_config, client_config, server_balance_config=None, is_foward=False, is_tun=False): server_balance_process = None if server_balance_config: server_balance_process = start_trojan_plus_process( "config/" + server_balance_config) if not server_balance_process: close_process(server_balance_process, True) return 0 server_process = start_trojan_plus_process("config/" + server_config) client_process = start_trojan_plus_process("config/" + client_config) if not server_process or not client_process: close_process(server_process, True) close_process(client_process, True) close_process(server_balance_process, True) return 1 output_log = False try: print_time_log("done!") server_balance_process_init_rss = get_process_rss_in_KB( server_balance_process) server_process_init_rss = get_process_rss_in_KB(server_process) client_process_init_rss = get_process_rss_in_KB(client_process) print_time_log("server balance process init RSS: " + "{:,}KB".format(server_balance_process_init_rss)) print_time_log("server process init RSS: " + "{:,}KB".format(server_process_init_rss)) print_time_log("client process init RSS: " + "{:,}KB".format(client_process_init_rss)) print_time_log("testing max init RSS: " + "{:,}KB".format(get_init_rss_limit())) if server_process_init_rss > get_init_rss_limit() \ or client_process_init_rss > get_init_rss_limit() \ or server_balance_process_init_rss > get_init_rss_limit(): print_time_log("init RSS error!!") output_log = True return 1 if is_foward: if not fulltest_client.start_query( LOCALHOST_IP, 0, TEST_PROXY_PORT, TEST_FILES_DIR): output_log = True return 1 elif is_tun: # for proxy (config/proxy_ips.txt) if not fulltest_client.start_query( "188.188.188.188", 0, TEST_SERVER_PORT, TEST_FILES_DIR): output_log = True return 1 # for forwarding (config/white_ips.txt) if not fulltest_client.start_query( "199.199.199.199", 0, TEST_SERVER_PORT, TEST_FILES_DIR): output_log = True return 1 if cmd_args.dns: if not fulltest_dns.start_query("10.0.0.2", 10, cmd_args.dns): output_log = True return 1 else: if cmd_args.normal: if not fulltest_client.start_query( LOCALHOST_IP, TEST_PROXY_PORT, TEST_SERVER_PORT, TEST_FILES_DIR): output_log = True return 1 if cmd_args.dns: if not fulltest_dns.start_query("127.0.0.1", 10, cmd_args.dns): output_log = True return 1 print_time_log( "server balance process RSS after testing: " + "{:,}KB".format(get_process_rss_in_KB(server_balance_process))) print_time_log("server process RSS after testing: " + "{:,}KB".format(get_process_rss_in_KB(server_process))) print_time_log("client process RSS after testing: " + "{:,}KB".format(get_process_rss_in_KB(client_process))) print_time_log("waiting " + str(TEST_WATING_FOR_RSS_COOLDOWN_TIME_IN_SEC) + " sec (config's udp_timeout+1) for RSS cooldown...") time.sleep(TEST_WATING_FOR_RSS_COOLDOWN_TIME_IN_SEC) server_balance_process_rss = get_process_rss_in_KB( server_balance_process) server_process_rss = get_process_rss_in_KB(server_process) client_process_rss = get_process_rss_in_KB(client_process) print_time_log("server balance process RSS after cooldown: " + "{:,}KB".format(server_balance_process_rss)) print_time_log("server process RSS after cooldown: " + "{:,}KB".format(server_process_rss)) print_time_log("client process RSS after cooldown: " + "{:,}KB".format(client_process_rss)) print_time_log("testing max RSS after cooldown: " + "{:,}KB".format(get_cooldown_rss_limit())) if server_process_rss > get_cooldown_rss_limit() \ or client_process_rss > get_cooldown_rss_limit() \ or server_balance_process_init_rss > get_cooldown_rss_limit(): print_time_log("[ERROR] cooldown RSS error!") output_log = True return 1 return 0 except: output_log = True traceback.print_exc(file=sys.stdout) finally: if output_log: print_time_log( "Has got error, wait for udp timeout log to flush...") time.sleep(TEST_WATING_FOR_RSS_COOLDOWN_TIME_IN_SEC) close_process(client_process, output_log) close_process(server_process, output_log) close_process(server_balance_process, output_log) return 1
def start_query(host_ip, socks_port, port, folder, log=True): # setup socket as socks5 proxy origin_socket = socket.socket if socks_port != 0: socks.set_default_proxy(socks.SOCKS5, host_ip, socks_port) socket.socket = socks.socksocket print_time_log("using pysocks version: " + str(socks.__version__)) try: global request_url_prefix global request_host_ip global compare_folder global enable_log global serv_port request_host_ip = host_ip request_url_prefix = 'http://' + host_ip + ':' + str(port) + '/' compare_folder = folder + '/' enable_log = log serv_port = port print_time_log("start query index file....") # get the main index file index = get_url(request_url_prefix).decode("utf-8") files = [] for f in index.splitlines(): files.append(f) if len(files) == 0: print_time_log("read index file get error!!") return False print_time_log("read index files " + str(len(files)) + " done!") print_time_log("start query....") with ThreadPoolExecutor( max_workers=PARALLEL_REQUEST_COUNT) as executor: print_time_log("start query get http...") if not compare_process(files, executor, True, True): return False print_time_log("finished!") time.sleep(1) print_time_log("start query post http...") if not compare_process(files, executor, False, True): return False print_time_log("finish!") time.sleep(1) print_time_log("start query get udp...") if not compare_process(files, executor, True, False): return False print_time_log("finish!") time.sleep(1) print_time_log("start query post udp...") if not compare_process(files, executor, False, False): return False print_time_log("finish!!") print_time_log("SUCC") return True finally: socket.socket = origin_socket