From 464a852948da1bdbaf206adf406b619092f91a2c Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Sat, 9 Jan 2016 17:49:12 -0700 Subject: [PATCH 1/8] Added proxy support --- src/btfs.cc | 61 ++++++++++++++++++++++++++++++++++++++++++++++------- src/btfs.h | 14 ++++++++++++ 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/btfs.cc b/src/btfs.cc index d88c05e..ae3b865 100644 --- a/src/btfs.cc +++ b/src/btfs.cc @@ -499,6 +499,39 @@ btfs_init(struct fuse_conn_info *conn) { libtorrent::session::add_default_plugins, alerts); + if (params.proxy != NULL) { + if (params.proxy_type == NULL) { + params.proxy_type = "socks5h"; + } + bool found_proxy_type = false; + libtorrent::proxy_settings::proxy_type libtorrent_proxy_type; + for (unsigned int i = 0; i < sizeof(proxy_types) / sizeof(proxy_types[0]); i++) { + proxy_type type = proxy_types[i]; + if (type.libcurl_name == params.proxy_type) { + found_proxy_type = true; + libtorrent_proxy_type = type.libtorrent_type; + break; + } + } + if (!found_proxy_type) { + fprintf(stderr, "Unkown proxy type"); + exit(1); + } + + libtorrent::proxy_settings proxy = libtorrent::proxy_settings(); + std::string proxyString = std::string(params.proxy); + int index = proxyString.find(':'); + if (index != std::string::npos) { + proxy.hostname = proxyString.substr(0, index); + proxy.port = atoi(proxyString.substr(index).c_str()); + } else { + proxy.hostname = params.proxy; + proxy.port = 1080; + } + proxy.type = libtorrent_proxy_type; + session->set_proxy(proxy); + } + pthread_create(&alert_thread, NULL, alert_queue_loop, new Log(p->save_path + "/../log.txt")); @@ -604,6 +637,13 @@ populate_metadata(libtorrent::add_torrent_params& p, const char *arg) { curl_easy_setopt(ch, CURLOPT_WRITEDATA, (void *) &output); curl_easy_setopt(ch, CURLOPT_USERAGENT, "btfs/" VERSION); curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1); + if (params.proxy_type == NULL) { + params.proxy_type = "socks5h"; + } + if (params.proxy != NULL) { + curl_easy_setopt(ch, CURLOPT_PROXY, params.proxy); + curl_easy_setopt(ch, CURLOPT_PROXYTYPE, params.proxy_type); + } CURLcode res = curl_easy_perform(ch); @@ -658,14 +698,17 @@ populate_metadata(libtorrent::add_torrent_params& p, const char *arg) { #define BTFS_OPT(t, p, v) { t, offsetof(struct btfs_params, p), v } static const struct fuse_opt btfs_opts[] = { - BTFS_OPT("-v", version, 1), - BTFS_OPT("--version", version, 1), - BTFS_OPT("-h", help, 1), - BTFS_OPT("--help", help, 1), - BTFS_OPT("-b", browse_only, 1), - BTFS_OPT("--browse-only", browse_only, 1), - BTFS_OPT("-k", keep, 1), - BTFS_OPT("--keep", keep, 1), + BTFS_OPT("-v", version, 1), + BTFS_OPT("--version", version, 1), + BTFS_OPT("-h", help, 1), + BTFS_OPT("--help", help, 1), + BTFS_OPT("-b", browse_only, 1), + BTFS_OPT("--browse-only", browse_only, 1), + BTFS_OPT("-k", keep, 1), + BTFS_OPT("-p=%s", proxy, 4), + BTFS_OPT("-proxy=%s", proxy, 4), + BTFS_OPT("--proxy-type=%s", proxy_type, 4), + BTFS_OPT("--keep", keep, 1), FUSE_OPT_END }; @@ -727,6 +770,8 @@ main(int argc, char *argv[]) { printf(" --help -h show this message\n"); printf(" --browse-only -b download metadata only\n"); printf(" --keep -k keep files after unmount\n"); + printf(" --proxy= -p= use a proxy with the given address\n"); + printf(" --proxy-type= set the type of proxy (defaults to socks5h)\n"); printf("\n"); // Let FUSE print more help diff --git a/src/btfs.h b/src/btfs.h index 7fb2758..f642f92 100644 --- a/src/btfs.h +++ b/src/btfs.h @@ -21,6 +21,7 @@ along with BTFS. If not, see . #define BTFS_H #include +#include namespace btfs { @@ -111,11 +112,24 @@ enum { KEY_HELP, }; +struct proxy_type { + const char *libcurl_name; + libtorrent::proxy_settings::proxy_type libtorrent_type; +}; + +proxy_type proxy_types[] = { + {"socks5h", libtorrent::proxy_settings::socks5}, + {"socks5", libtorrent::proxy_settings::socks5}, + {"http", libtorrent::proxy_settings::http} +}; + struct btfs_params { int version; int help; int browse_only; int keep; + const char *proxy; + const char *proxy_type; const char *metadata; }; From d6b024be1d22055ae53f04e488e792ad50d5fc21 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Sat, 9 Jan 2016 19:17:10 -0700 Subject: [PATCH 2/8] Added force_proxy support --- src/btfs.cc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/btfs.cc b/src/btfs.cc index ae3b865..de3dc9c 100644 --- a/src/btfs.cc +++ b/src/btfs.cc @@ -499,7 +499,21 @@ btfs_init(struct fuse_conn_info *conn) { libtorrent::session::add_default_plugins, alerts); + pthread_create(&alert_thread, NULL, alert_queue_loop, + new Log(p->save_path + "/../log.txt")); + +#ifndef __APPLE__ + pthread_setname_np(alert_thread, "alert"); +#endif + + libtorrent::session_settings se = session->settings(); + + se.strict_end_game_mode = false; + se.announce_to_all_trackers = true; + se.announce_to_all_tiers = true; + if (params.proxy != NULL) { + se.force_proxy = true; if (params.proxy_type == NULL) { params.proxy_type = "socks5h"; } @@ -532,19 +546,6 @@ btfs_init(struct fuse_conn_info *conn) { session->set_proxy(proxy); } - pthread_create(&alert_thread, NULL, alert_queue_loop, - new Log(p->save_path + "/../log.txt")); - -#ifndef __APPLE__ - pthread_setname_np(alert_thread, "alert"); -#endif - - libtorrent::session_settings se = session->settings(); - - se.strict_end_game_mode = false; - se.announce_to_all_trackers = true; - se.announce_to_all_tiers = true; - session->set_settings(se); session->async_add_torrent(*p); From 6a44afd3e0873d5bbd0417d1ccd548e71cc60eca Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Sat, 9 Jan 2016 19:19:53 -0700 Subject: [PATCH 3/8] Pass additional btplay args to btfs --- scripts/btplay | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/btplay b/scripts/btplay index e81c6b6..ff5ebf4 100755 --- a/scripts/btplay +++ b/scripts/btplay @@ -36,7 +36,7 @@ if not cmd: mountpoint = tempfile.mkdtemp(prefix="btplay-") -ret = subprocess.call(("btfs", args.URI, mountpoint, )) +ret = subprocess.call(["btfs", args.URI, mountpoint, ] + sys.argv[1:]) def find_files(p): for dirpath, dnames, fnames in os.walk(p): From 970c709713d368419c9728557eb6d54ef7296c25 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Sun, 10 Jan 2016 08:21:56 -0700 Subject: [PATCH 4/8] Added proxy authentication support Also enabled C++11 for static map initialization --- src/Makefile.am | 2 +- src/btfs.cc | 69 ++++++++++++++++++++++++++++++------------------- src/btfs.h | 15 ++++++----- 3 files changed, 52 insertions(+), 34 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 8ccc474..2eb7467 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ bin_PROGRAMS = btfs btfs_SOURCES = btfs.cc btfs.h -btfs_CPPFLAGS = -Wall $(FUSE_CFLAGS) $(LIBTORRENT_CFLAGS) $(LIBCURL_CFLAGS) +btfs_CPPFLAGS = -Wall -std=c++11 $(FUSE_CFLAGS) $(LIBTORRENT_CFLAGS) $(LIBCURL_CFLAGS) btfs_LDADD = $(FUSE_LIBS) $(LIBTORRENT_LIBS) $(LIBCURL_LIBS) diff --git a/src/btfs.cc b/src/btfs.cc index de3dc9c..1990dc1 100644 --- a/src/btfs.cc +++ b/src/btfs.cc @@ -517,24 +517,21 @@ btfs_init(struct fuse_conn_info *conn) { if (params.proxy_type == NULL) { params.proxy_type = "socks5h"; } - bool found_proxy_type = false; - libtorrent::proxy_settings::proxy_type libtorrent_proxy_type; - for (unsigned int i = 0; i < sizeof(proxy_types) / sizeof(proxy_types[0]); i++) { - proxy_type type = proxy_types[i]; - if (type.libcurl_name == params.proxy_type) { - found_proxy_type = true; - libtorrent_proxy_type = type.libtorrent_type; - break; - } - } - if (!found_proxy_type) { + libtorrent::proxy_settings::proxy_type libtorrent_proxy_type = libtorrent_proxy_types[params.proxy_type]; + if (libtorrent_proxy_type == libtorrent::proxy_settings::none) { // None is the default value fprintf(stderr, "Unkown proxy type"); exit(1); } + if (params.proxy_username != NULL && params.proxy_password != NULL) { + libtorrent::proxy_settings::proxy_type new_type = libtorrent_authed_proxy_types[libtorrent_proxy_type]; + if (new_type != libtorrent::proxy_settings::none) { + libtorrent_proxy_type = new_type; + } + } - libtorrent::proxy_settings proxy = libtorrent::proxy_settings(); + libtorrent::proxy_settings proxy = session->proxy(); std::string proxyString = std::string(params.proxy); - int index = proxyString.find(':'); + unsigned int index = proxyString.find(':'); if (index != std::string::npos) { proxy.hostname = proxyString.substr(0, index); proxy.port = atoi(proxyString.substr(index).c_str()); @@ -542,6 +539,12 @@ btfs_init(struct fuse_conn_info *conn) { proxy.hostname = params.proxy; proxy.port = 1080; } + if (params.proxy_username) { + proxy.username = params.proxy_username; + } + if (params.proxy_password) { + proxy.password = params.proxy_password; + } proxy.type = libtorrent_proxy_type; session->set_proxy(proxy); } @@ -638,12 +641,18 @@ populate_metadata(libtorrent::add_torrent_params& p, const char *arg) { curl_easy_setopt(ch, CURLOPT_WRITEDATA, (void *) &output); curl_easy_setopt(ch, CURLOPT_USERAGENT, "btfs/" VERSION); curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1); - if (params.proxy_type == NULL) { - params.proxy_type = "socks5h"; - } if (params.proxy != NULL) { curl_easy_setopt(ch, CURLOPT_PROXY, params.proxy); + if (params.proxy_type == NULL) { + params.proxy_type = "socks5h"; + } curl_easy_setopt(ch, CURLOPT_PROXYTYPE, params.proxy_type); + if (params.proxy_username != NULL) { + curl_easy_setopt(ch, CURLOPT_PROXYUSERNAME, params.proxy_username); + } + if (params.proxy_password != NULL) { + curl_easy_setopt(ch, CURLOPT_PROXYPASSWORD, params.proxy_password); + } } CURLcode res = curl_easy_perform(ch); @@ -699,17 +708,19 @@ populate_metadata(libtorrent::add_torrent_params& p, const char *arg) { #define BTFS_OPT(t, p, v) { t, offsetof(struct btfs_params, p), v } static const struct fuse_opt btfs_opts[] = { - BTFS_OPT("-v", version, 1), - BTFS_OPT("--version", version, 1), - BTFS_OPT("-h", help, 1), - BTFS_OPT("--help", help, 1), - BTFS_OPT("-b", browse_only, 1), - BTFS_OPT("--browse-only", browse_only, 1), - BTFS_OPT("-k", keep, 1), - BTFS_OPT("-p=%s", proxy, 4), - BTFS_OPT("-proxy=%s", proxy, 4), - BTFS_OPT("--proxy-type=%s", proxy_type, 4), - BTFS_OPT("--keep", keep, 1), + BTFS_OPT("-v", version, 1), + BTFS_OPT("--version", version, 1), + BTFS_OPT("-h", help, 1), + BTFS_OPT("--help", help, 1), + BTFS_OPT("-b", browse_only, 1), + BTFS_OPT("--browse-only", browse_only, 1), + BTFS_OPT("-k", keep, 1), + BTFS_OPT("--keep", keep, 1), + BTFS_OPT("-p=%s", proxy, 4), + BTFS_OPT("-proxy=%s", proxy, 4), + BTFS_OPT("--proxy-type=%s", proxy_type, 4), + BTFS_OPT("--proxy-username=%s", proxy_username, 4), + BTFS_OPT("--proxy-password=%s", proxy_password, 4), FUSE_OPT_END }; @@ -773,6 +784,10 @@ main(int argc, char *argv[]) { printf(" --keep -k keep files after unmount\n"); printf(" --proxy= -p= use a proxy with the given address\n"); printf(" --proxy-type= set the type of proxy (defaults to socks5h)\n"); + printf(" --proxy-username= login to the proxy with the given username\n"); + printf(" --proxy-password= login to the proxy with the given password\n"); + printf(" As a process argument, this is readable\n"); + printf(" by any user by looking at a list of processes\n"); printf("\n"); // Let FUSE print more help diff --git a/src/btfs.h b/src/btfs.h index f642f92..1e56ba1 100644 --- a/src/btfs.h +++ b/src/btfs.h @@ -112,17 +112,18 @@ enum { KEY_HELP, }; -struct proxy_type { - const char *libcurl_name; - libtorrent::proxy_settings::proxy_type libtorrent_type; -}; - -proxy_type proxy_types[] = { +std::map libtorrent_proxy_types = { + {"socks4", libtorrent::proxy_settings::socks4}, {"socks5h", libtorrent::proxy_settings::socks5}, {"socks5", libtorrent::proxy_settings::socks5}, {"http", libtorrent::proxy_settings::http} }; +std::map libtorrent_authed_proxy_types = { + {libtorrent::proxy_settings::socks5, libtorrent::proxy_settings::socks5_pw}, + {libtorrent::proxy_settings::http, libtorrent::proxy_settings::http_pw} +}; + struct btfs_params { int version; int help; @@ -130,6 +131,8 @@ struct btfs_params { int keep; const char *proxy; const char *proxy_type; + const char *proxy_username; + const char *proxy_password; const char *metadata; }; From ce050d6fbdbbbe850507d36f849d2fcd3d0e0c20 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Thu, 21 Jan 2016 07:14:03 -0700 Subject: [PATCH 5/8] Added i2p support --- src/btfs.cc | 54 +++++++++++++++++++++++++++++++++++------------------ src/btfs.h | 1 + 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/btfs.cc b/src/btfs.cc index 1990dc1..279b90f 100644 --- a/src/btfs.cc +++ b/src/btfs.cc @@ -518,14 +518,16 @@ btfs_init(struct fuse_conn_info *conn) { params.proxy_type = "socks5h"; } libtorrent::proxy_settings::proxy_type libtorrent_proxy_type = libtorrent_proxy_types[params.proxy_type]; - if (libtorrent_proxy_type == libtorrent::proxy_settings::none) { // None is the default value - fprintf(stderr, "Unkown proxy type"); - exit(1); - } - if (params.proxy_username != NULL && params.proxy_password != NULL) { - libtorrent::proxy_settings::proxy_type new_type = libtorrent_authed_proxy_types[libtorrent_proxy_type]; - if (new_type != libtorrent::proxy_settings::none) { - libtorrent_proxy_type = new_type; + if (strcmp(params.proxy_type, "i2p") != 0) { + if (libtorrent_proxy_type == libtorrent::proxy_settings::none) { // None is the default value + fprintf(stderr, "Unkown proxy type"); + exit(1); + } + if (params.proxy_username != NULL && params.proxy_password != NULL) { + libtorrent::proxy_settings::proxy_type new_type = libtorrent_authed_proxy_types[libtorrent_proxy_type]; + if (new_type != libtorrent::proxy_settings::none) { + libtorrent_proxy_type = new_type; + } } } @@ -545,8 +547,12 @@ btfs_init(struct fuse_conn_info *conn) { if (params.proxy_password) { proxy.password = params.proxy_password; } - proxy.type = libtorrent_proxy_type; - session->set_proxy(proxy); + if (strcmp(params.proxy_type, "i2p") == 0) { + session->set_i2p_proxy(proxy); + } else { + proxy.type = libtorrent_proxy_type; + session->set_proxy(proxy); + } } session->set_settings(se); @@ -642,16 +648,25 @@ populate_metadata(libtorrent::add_torrent_params& p, const char *arg) { curl_easy_setopt(ch, CURLOPT_USERAGENT, "btfs/" VERSION); curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1); if (params.proxy != NULL) { - curl_easy_setopt(ch, CURLOPT_PROXY, params.proxy); if (params.proxy_type == NULL) { params.proxy_type = "socks5h"; } - curl_easy_setopt(ch, CURLOPT_PROXYTYPE, params.proxy_type); - if (params.proxy_username != NULL) { - curl_easy_setopt(ch, CURLOPT_PROXYUSERNAME, params.proxy_username); - } - if (params.proxy_password != NULL) { - curl_easy_setopt(ch, CURLOPT_PROXYPASSWORD, params.proxy_password); + if (strcmp(params.proxy_type, "i2p") == 0) { + if (params.i2p_http_proxy) { + curl_easy_setopt(ch, CURLOPT_PROXY, params.i2p_http_proxy); + } else { + curl_easy_setopt(ch, CURLOPT_PROXY, "127.0.0.1:4444"); + } + curl_easy_setopt(ch, CURLOPT_PROXYTYPE, "http"); + } else { + curl_easy_setopt(ch, CURLOPT_PROXY, params.proxy); + curl_easy_setopt(ch, CURLOPT_PROXYTYPE, params.proxy_type); + if (params.proxy_username != NULL) { + curl_easy_setopt(ch, CURLOPT_PROXYUSERNAME, params.proxy_username); + } + if (params.proxy_password != NULL) { + curl_easy_setopt(ch, CURLOPT_PROXYPASSWORD, params.proxy_password); + } } } @@ -717,10 +732,11 @@ static const struct fuse_opt btfs_opts[] = { BTFS_OPT("-k", keep, 1), BTFS_OPT("--keep", keep, 1), BTFS_OPT("-p=%s", proxy, 4), - BTFS_OPT("-proxy=%s", proxy, 4), + BTFS_OPT("--proxy=%s", proxy, 4), BTFS_OPT("--proxy-type=%s", proxy_type, 4), BTFS_OPT("--proxy-username=%s", proxy_username, 4), BTFS_OPT("--proxy-password=%s", proxy_password, 4), + BTFS_OPT("--i2p-http-proxy=%s", i2p_http_proxy, 4), FUSE_OPT_END }; @@ -788,6 +804,8 @@ main(int argc, char *argv[]) { printf(" --proxy-password= login to the proxy with the given password\n"); printf(" As a process argument, this is readable\n"); printf(" by any user by looking at a list of processes\n"); + printf(" --i2p-http-proxy= provide an http proxy for use by curl in place of i2p\n"); + printf(" Only used if the proxy type is set to i2p\n"); printf("\n"); // Let FUSE print more help diff --git a/src/btfs.h b/src/btfs.h index 1e56ba1..5ecca4f 100644 --- a/src/btfs.h +++ b/src/btfs.h @@ -133,6 +133,7 @@ struct btfs_params { const char *proxy_type; const char *proxy_username; const char *proxy_password; + const char *i2p_http_proxy; const char *metadata; }; From 4f1937e4edd7f205a6fe9bf4696154678cfee89e Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Thu, 21 Jan 2016 10:38:42 -0700 Subject: [PATCH 6/8] Added default i2p proxy --- src/btfs.cc | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/btfs.cc b/src/btfs.cc index 279b90f..ddefec7 100644 --- a/src/btfs.cc +++ b/src/btfs.cc @@ -511,6 +511,10 @@ btfs_init(struct fuse_conn_info *conn) { se.strict_end_game_mode = false; se.announce_to_all_trackers = true; se.announce_to_all_tiers = true; + + if (params.proxy == NULL && params.proxy_type != NULL && strcmp(params.proxy_type, "i2p") == 0) { + params.proxy = "127.0.0.1:7656"; + } if (params.proxy != NULL) { se.force_proxy = true; @@ -647,26 +651,24 @@ populate_metadata(libtorrent::add_torrent_params& p, const char *arg) { curl_easy_setopt(ch, CURLOPT_WRITEDATA, (void *) &output); curl_easy_setopt(ch, CURLOPT_USERAGENT, "btfs/" VERSION); curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1); - if (params.proxy != NULL) { + if (params.proxy_type != NULL && strcmp(params.proxy_type, "i2p") == 0) { + if (params.i2p_http_proxy) { + curl_easy_setopt(ch, CURLOPT_PROXY, params.i2p_http_proxy); + } else { + curl_easy_setopt(ch, CURLOPT_PROXY, "127.0.0.1:4444"); + } + curl_easy_setopt(ch, CURLOPT_PROXYTYPE, "http"); + } else if (params.proxy != NULL) { if (params.proxy_type == NULL) { params.proxy_type = "socks5h"; } - if (strcmp(params.proxy_type, "i2p") == 0) { - if (params.i2p_http_proxy) { - curl_easy_setopt(ch, CURLOPT_PROXY, params.i2p_http_proxy); - } else { - curl_easy_setopt(ch, CURLOPT_PROXY, "127.0.0.1:4444"); - } - curl_easy_setopt(ch, CURLOPT_PROXYTYPE, "http"); - } else { - curl_easy_setopt(ch, CURLOPT_PROXY, params.proxy); - curl_easy_setopt(ch, CURLOPT_PROXYTYPE, params.proxy_type); - if (params.proxy_username != NULL) { - curl_easy_setopt(ch, CURLOPT_PROXYUSERNAME, params.proxy_username); - } - if (params.proxy_password != NULL) { - curl_easy_setopt(ch, CURLOPT_PROXYPASSWORD, params.proxy_password); - } + curl_easy_setopt(ch, CURLOPT_PROXY, params.proxy); + curl_easy_setopt(ch, CURLOPT_PROXYTYPE, params.proxy_type); + if (params.proxy_username != NULL) { + curl_easy_setopt(ch, CURLOPT_PROXYUSERNAME, params.proxy_username); + } + if (params.proxy_password != NULL) { + curl_easy_setopt(ch, CURLOPT_PROXYPASSWORD, params.proxy_password); } } From 2056cd43b5b3a8e30e1d550e9132f74c2cdeb51c Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Thu, 21 Jan 2016 18:59:00 -0700 Subject: [PATCH 7/8] Fixed curl PROXYTYPE --- src/btfs.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/btfs.cc b/src/btfs.cc index ddefec7..9bd3362 100644 --- a/src/btfs.cc +++ b/src/btfs.cc @@ -657,13 +657,17 @@ populate_metadata(libtorrent::add_torrent_params& p, const char *arg) { } else { curl_easy_setopt(ch, CURLOPT_PROXY, "127.0.0.1:4444"); } - curl_easy_setopt(ch, CURLOPT_PROXYTYPE, "http"); + curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); } else if (params.proxy != NULL) { if (params.proxy_type == NULL) { params.proxy_type = "socks5h"; } - curl_easy_setopt(ch, CURLOPT_PROXY, params.proxy); - curl_easy_setopt(ch, CURLOPT_PROXYTYPE, params.proxy_type); + int proxy_type_len = strlen(params.proxy_type); + char proxy_string[proxy_type_len + 3 + strlen(params.proxy) + 1]; + strcpy(proxy_string, params.proxy_type); + strcpy(proxy_string + proxy_type_len, "://"); + strcpy(proxy_string + proxy_type_len + 3, params.proxy); // includes ending null byte + curl_easy_setopt(ch, CURLOPT_PROXY, proxy_string); if (params.proxy_username != NULL) { curl_easy_setopt(ch, CURLOPT_PROXYUSERNAME, params.proxy_username); } @@ -801,6 +805,7 @@ main(int argc, char *argv[]) { printf(" --browse-only -b download metadata only\n"); printf(" --keep -k keep files after unmount\n"); printf(" --proxy= -p= use a proxy with the given address\n"); + printf(" should be in the form of host or host:port\n"); printf(" --proxy-type= set the type of proxy (defaults to socks5h)\n"); printf(" --proxy-username= login to the proxy with the given username\n"); printf(" --proxy-password= login to the proxy with the given password\n"); From d099e1ac6cf7ecdcd7a350d397f15e20362964a7 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Fri, 22 Jan 2016 12:13:01 -0700 Subject: [PATCH 8/8] Switched to seperate host and port parameters --- src/btfs.cc | 41 ++++++++++++++++++++--------------------- src/btfs.h | 3 ++- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/btfs.cc b/src/btfs.cc index 9bd3362..48e62b3 100644 --- a/src/btfs.cc +++ b/src/btfs.cc @@ -512,11 +512,16 @@ btfs_init(struct fuse_conn_info *conn) { se.announce_to_all_trackers = true; se.announce_to_all_tiers = true; - if (params.proxy == NULL && params.proxy_type != NULL && strcmp(params.proxy_type, "i2p") == 0) { - params.proxy = "127.0.0.1:7656"; + if (params.proxy_hostname == NULL && params.proxy_type != NULL && strcmp(params.proxy_type, "i2p") == 0) { + params.proxy_hostname = "127.0.0.1"; + params.proxy_port = 7656; + } + + if (params.proxy_hostname != NULL && params.proxy_port == 0) { + params.proxy_port = 1080; } - if (params.proxy != NULL) { + if (params.proxy_hostname != NULL) { se.force_proxy = true; if (params.proxy_type == NULL) { params.proxy_type = "socks5h"; @@ -536,15 +541,8 @@ btfs_init(struct fuse_conn_info *conn) { } libtorrent::proxy_settings proxy = session->proxy(); - std::string proxyString = std::string(params.proxy); - unsigned int index = proxyString.find(':'); - if (index != std::string::npos) { - proxy.hostname = proxyString.substr(0, index); - proxy.port = atoi(proxyString.substr(index).c_str()); - } else { - proxy.hostname = params.proxy; - proxy.port = 1080; - } + proxy.hostname = params.proxy_hostname; + proxy.port = params.proxy_port; if (params.proxy_username) { proxy.username = params.proxy_username; } @@ -658,16 +656,17 @@ populate_metadata(libtorrent::add_torrent_params& p, const char *arg) { curl_easy_setopt(ch, CURLOPT_PROXY, "127.0.0.1:4444"); } curl_easy_setopt(ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); - } else if (params.proxy != NULL) { + } else if (params.proxy_hostname != NULL) { if (params.proxy_type == NULL) { params.proxy_type = "socks5h"; } - int proxy_type_len = strlen(params.proxy_type); - char proxy_string[proxy_type_len + 3 + strlen(params.proxy) + 1]; - strcpy(proxy_string, params.proxy_type); - strcpy(proxy_string + proxy_type_len, "://"); - strcpy(proxy_string + proxy_type_len + 3, params.proxy); // includes ending null byte - curl_easy_setopt(ch, CURLOPT_PROXY, proxy_string); + std::string proxy_string = ""; + proxy_string += params.proxy_type; + proxy_string += "://"; + proxy_string += params.proxy_hostname; + proxy_string += ":"; + proxy_string += params.proxy_port; + curl_easy_setopt(ch, CURLOPT_PROXY, proxy_string.c_str()); if (params.proxy_username != NULL) { curl_easy_setopt(ch, CURLOPT_PROXYUSERNAME, params.proxy_username); } @@ -737,8 +736,8 @@ static const struct fuse_opt btfs_opts[] = { BTFS_OPT("--browse-only", browse_only, 1), BTFS_OPT("-k", keep, 1), BTFS_OPT("--keep", keep, 1), - BTFS_OPT("-p=%s", proxy, 4), - BTFS_OPT("--proxy=%s", proxy, 4), + BTFS_OPT("--proxy-hostname=%s", proxy_hostname, 4), + BTFS_OPT("--proxy-port=%u", proxy_port, 4), BTFS_OPT("--proxy-type=%s", proxy_type, 4), BTFS_OPT("--proxy-username=%s", proxy_username, 4), BTFS_OPT("--proxy-password=%s", proxy_password, 4), diff --git a/src/btfs.h b/src/btfs.h index 5ecca4f..748d91e 100644 --- a/src/btfs.h +++ b/src/btfs.h @@ -129,7 +129,8 @@ struct btfs_params { int help; int browse_only; int keep; - const char *proxy; + const char *proxy_hostname; + int proxy_port; const char *proxy_type; const char *proxy_username; const char *proxy_password;