MCPcopy Create free account
hub / github.com/arvidn/libtorrent / start_proxy

Function start_proxy

test/setup_transfer.cpp:736–796  ·  view source on GitHub ↗

returns a port on success and -1 on failure

Source from the content-addressed store, hash-verified

734
735// returns a port on success and -1 on failure
736int start_proxy(int proxy_type)
737{
738 using namespace lt;
739
740 std::map<int, proxy_t> :: iterator i = running_proxies.begin();
741 for (; i != running_proxies.end(); ++i)
742 {
743 if (i->second.type == proxy_type) { return i->first; }
744 }
745
746 int const port = find_available_port();
747
748 char const* type = "";
749 char const* auth = "";
750 char const* cmd = "";
751
752 switch (proxy_type)
753 {
754 case settings_pack::socks4:
755 type = "socks4";
756 auth = " --allow-v4";
757 cmd = ".." SEPARATOR "socks.py";
758 break;
759 case settings_pack::socks5:
760 type = "socks5";
761 cmd = ".." SEPARATOR "socks.py";
762 break;
763 case settings_pack::socks5_pw:
764 type = "socks5";
765 auth = " --username testuser --password testpass";
766 cmd = ".." SEPARATOR "socks.py";
767 break;
768 case settings_pack::http:
769 type = "http";
770 cmd = ".." SEPARATOR "http_proxy.py";
771 break;
772 case settings_pack::http_pw:
773 type = "http";
774 auth = " --basic-auth testuser:testpass";
775 cmd = ".." SEPARATOR "http_proxy.py";
776 break;
777 }
778 std::vector<std::string> python_exes = get_python();
779 for (auto const& python_exe : python_exes)
780 {
781 char buf[1024];
782 std::snprintf(buf, sizeof(buf), "%s %s --port %d%s", python_exe.c_str(), cmd, port, auth);
783
784 std::printf("%s starting proxy on port %d (%s %s)...\n", time_now_string().c_str(), port, type, auth);
785 std::printf("%s\n", buf);
786 pid_type r = async_run(buf);
787 if (r == 0) continue;
788 proxy_t t = { r, proxy_type };
789 running_proxies.insert(std::make_pair(port, t));
790 std::printf("%s launched\n", time_now_string().c_str());
791 std::this_thread::sleep_for(lt::milliseconds(500));
792 wait_for_port(port);
793 return port;

Callers 3

run_suiteFunction · 0.85
test_transferFunction · 0.85
test_transferFunction · 0.85

Calls 9

find_available_portFunction · 0.85
get_pythonFunction · 0.85
time_now_stringFunction · 0.85
async_runFunction · 0.85
wait_for_portFunction · 0.85
abortFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45

Tested by 3

run_suiteFunction · 0.68
test_transferFunction · 0.68
test_transferFunction · 0.68