Skip to content

Commit

Permalink
Added i2p support
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Jan 21, 2016
1 parent f7e6d77 commit 537c3c3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
54 changes: 36 additions & 18 deletions src/btfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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
};

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/btfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit 537c3c3

Please sign in to comment.