From a9cee752df4d83a9ea4e4b415297aa2a2d02b0eb Mon Sep 17 00:00:00 2001 From: ygrek Date: Tue, 3 Sep 2013 00:26:10 +0800 Subject: [PATCH] BT: use porttest service from EDK module --- src/daemon/common/commonInteractive.ml | 29 +++++++++++++++++++++++++++++ src/networks/bittorrent/bTInteractive.ml | 9 +++++++++ src/networks/donkey/donkeyInteractive.ml | 23 ++--------------------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/daemon/common/commonInteractive.ml b/src/daemon/common/commonInteractive.ml index 57ab02ea..80fea1ad 100644 --- a/src/daemon/common/commonInteractive.ml +++ b/src/daemon/common/commonInteractive.ml @@ -1153,3 +1153,32 @@ let _ = option_hook max_concurrent_downloads (fun _ -> ignore (force_download_quotas ()) ) + +let run_porttest ?udp ~tcp result = + result := PorttestInProgress (last_time ()); + let module H = Http_client in + let url = Printf.sprintf "http://porttest.emule-project.net:81/ct_noframe.php?lang=&tcpport=%d" tcp in + let url = match udp with + | None -> url + | Some udp -> url ^ Printf.sprintf "&udpport=%d" udp + in + let r = { H.basic_request with + H.req_url = Url.of_string url; + (* no sense to test ports via proxy! *) +(* H.req_proxy = !CommonOptions.http_proxy; *) + H.req_max_retry = 3; + H.req_user_agent = get_user_agent () } + in + H.wget r begin fun file -> + Unix2.tryopen_read file begin fun cin -> + try + while true do + let line = input_line cin in + try + if Str.string_match (Str.regexp "^

Testing IP") line 0 then + result := PorttestResult (last_time (), line) + with _ -> () + done + with End_of_file -> () + end + end diff --git a/src/networks/bittorrent/bTInteractive.ml b/src/networks/bittorrent/bTInteractive.ml index fe4ed8fc..6dddf07f 100644 --- a/src/networks/bittorrent/bTInteractive.ml +++ b/src/networks/bittorrent/bTInteractive.ml @@ -56,6 +56,10 @@ module VB = VerificationBitmap let porttest_result = ref PorttestNotStarted +(* + +(* not used - services are down *) + let interpret_azureus_porttest s = let failure_message fmt = Printf.sprintf ("Port test failure, " ^^ fmt) in @@ -114,6 +118,7 @@ let perform_porttests tests = (fun _ _ -> ()) in loop tests +*) let op_file_all_sources file = let list = ref [] in @@ -1515,6 +1520,9 @@ let _ = ] @ (match !bt_dht with None -> [] | Some dht -> [dht.BT_DHT.M.dht_port,"dht_port UDP"])); network.op_network_porttest_result <- (fun _ -> !porttest_result); network.op_network_porttest_start <- (fun _ -> + let udp = match !bt_dht with None -> None | Some dht -> Some dht.BT_DHT.M.dht_port in + CommonInteractive.run_porttest ~tcp:!!client_port ?udp porttest_result +(* azureus_porttest_random := (Random.int 100000); let tests = [ Printf.sprintf "http://www.utorrent.com/testport?port=%d" !!client_port, interpret_utorrent_porttest; @@ -1522,6 +1530,7 @@ let _ = !!client_port !azureus_porttest_random, interpret_azureus_porttest; ] in perform_porttests tests +*) ); network.op_network_check_upload_slots <- (fun _ -> check_bt_uploaders ()); client_ops.op_client_info <- op_client_info; diff --git a/src/networks/donkey/donkeyInteractive.ml b/src/networks/donkey/donkeyInteractive.ml index eda1c562..dda628c5 100644 --- a/src/networks/donkey/donkeyInteractive.ml +++ b/src/networks/donkey/donkeyInteractive.ml @@ -1655,27 +1655,8 @@ let _ = network.op_network_close_search <- (fun s -> ()); network.op_network_check_upload_slots <- (fun _ -> ()); network.op_network_porttest_start <- (fun _ -> - porttest_result := PorttestInProgress (last_time ()); - let module H = Http_client in - let r = { H.basic_request with - H.req_url = Url.of_string - (Printf.sprintf "http://porttest.emule-project.net:81/ct_noframe.php?lang=&tcpport=%d&udpport=%d" - !!donkey_port (!!donkey_port + 4)); - H.req_proxy = !CommonOptions.http_proxy; - H.req_max_retry = 10; - H.req_user_agent = get_user_agent () } in - H.wget r (fun file -> - Unix2.tryopen_read file (fun cin -> - try - while true do - let line = input_line cin in - try - if Str.string_match (Str.regexp "^

Testing IP") line 0 then - porttest_result := PorttestResult (last_time (), line) - with _ -> () - done - with End_of_file -> ()) - )); + CommonInteractive.run_porttest porttest_result ~tcp:(!!donkey_port) ~udp:(!!donkey_port+4) + ); network.op_network_forget_search <- forget_search (* emule<->mldonkey disconnects during chat, and this doesn't seem to auto reconnect -- 2.11.4.GIT