some minor i2p cleanups

This commit is contained in:
arvidn 2017-12-02 19:33:56 +01:00 committed by Arvid Norberg
parent a286b9da47
commit b00b3184c0
9 changed files with 39 additions and 47 deletions

View File

@ -93,9 +93,6 @@ namespace libtorrent
tracker_manager& m_man;
boost::shared_ptr<http_connection> m_tracker_connection;
address m_tracker_ip;
#if TORRENT_USE_I2P
i2p_connection* m_i2p_conn;
#endif
};
TORRENT_EXTRA_EXPORT tracker_response parse_tracker_response(

View File

@ -149,7 +149,7 @@ private:
// send and receive buffer
std::vector<char> m_buffer;
char const* m_id;
int m_command; // 0 = connect, 1 = accept
command_t m_command;
std::string m_dest;
std::string m_name_lookup;
@ -162,7 +162,7 @@ private:
read_name_lookup_response
};
int m_state;
state_t m_state;
#if TORRENT_USE_ASSERTS
int m_magic;
#endif

View File

@ -284,9 +284,12 @@ void http_connection::start(std::string const& hostname, int port
error_code err;
if (m_sock.is_open()) m_sock.close(err);
aux::proxy_settings const* proxy = ps;
#if TORRENT_USE_I2P
bool is_i2p = false;
char const* top_domain = strrchr(hostname.c_str(), '.');
aux::proxy_settings i2p_proxy;
if (top_domain && strcmp(top_domain, ".i2p") == 0 && i2p_conn)
{
// this is an i2p name, we need to use the sam connection
@ -297,23 +300,14 @@ void http_connection::start(std::string const& hostname, int port
// because i2p is sloooooow
m_completion_timeout *= 4;
m_read_timeout *= 4;
}
#endif
#if TORRENT_USE_I2P
if (is_i2p && i2p_conn->proxy().type != settings_pack::i2p_proxy)
if (i2p_conn->proxy().type != settings_pack::i2p_proxy)
{
m_timer.get_io_service().post(boost::bind(&http_connection::callback
, me, error_code(errors::no_i2p_router), static_cast<char*>(NULL), 0));
return;
}
#endif
aux::proxy_settings const* proxy = ps;
#if TORRENT_USE_I2P
aux::proxy_settings i2p_proxy;
if (is_i2p)
{
i2p_proxy = i2p_conn->proxy();
proxy = &i2p_proxy;
}
@ -493,17 +487,13 @@ void http_connection::close(bool force)
#if TORRENT_USE_I2P
void http_connection::connect_i2p_tracker(char const* destination)
{
TORRENT_ASSERT(m_sock.get<i2p_stream>());
#ifdef TORRENT_USE_OPENSSL
TORRENT_ASSERT(m_ssl == false);
TORRENT_ASSERT(m_sock.get<i2p_stream>());
m_sock.get<i2p_stream>()->set_destination(destination);
m_sock.get<i2p_stream>()->set_command(i2p_stream::cmd_connect);
m_sock.get<i2p_stream>()->set_session_id(m_i2p_conn->session_id());
#else
m_sock.get<i2p_stream>()->set_destination(destination);
m_sock.get<i2p_stream>()->set_command(i2p_stream::cmd_connect);
m_sock.get<i2p_stream>()->set_session_id(m_i2p_conn->session_id());
#endif
m_sock.get<i2p_stream>()->set_destination(destination);
m_sock.get<i2p_stream>()->set_command(i2p_stream::cmd_connect);
m_sock.get<i2p_stream>()->set_session_id(m_i2p_conn->session_id());
#if defined TORRENT_ASIO_DEBUGGING
add_outstanding_async("http_connection::on_connect");
#endif
@ -513,8 +503,7 @@ void http_connection::connect_i2p_tracker(char const* destination)
, shared_from_this(), _1));
}
void http_connection::on_i2p_resolve(error_code const& e
, char const* destination)
void http_connection::on_i2p_resolve(error_code const& e, char const* destination)
{
#if defined TORRENT_ASIO_DEBUGGING
complete_async("http_connection::on_i2p_resolve");

View File

@ -70,9 +70,6 @@ namespace libtorrent
, boost::weak_ptr<request_callback> c)
: tracker_connection(man, req, ios, c)
, m_man(man)
#if TORRENT_USE_I2P
, m_i2p_conn(NULL)
#endif
{}
void http_tracker_connection::start()
@ -94,7 +91,7 @@ namespace libtorrent
}
#if TORRENT_USE_I2P
bool i2p = is_i2p_url(url);
bool const i2p = is_i2p_url(url);
#else
static const bool i2p = false;
#endif
@ -425,7 +422,7 @@ namespace libtorrent
}
tracker_response parse_tracker_response(char const* data, int size, error_code& ec
, int flags, sha1_hash scrape_ih)
, int const flags, sha1_hash scrape_ih)
{
tracker_response resp;
@ -443,7 +440,7 @@ namespace libtorrent
int interval = int(e.dict_find_int_value("interval", 0));
// if no interval is specified, default to 30 minutes
if (interval == 0) interval = 1800;
int min_interval = int(e.dict_find_int_value("min interval", 30));
int const min_interval = int(e.dict_find_int_value("min interval", 30));
resp.interval = interval;
resp.min_interval = min_interval;

View File

@ -225,7 +225,7 @@ namespace libtorrent
: proxy_base(io_service)
, m_id(0)
, m_command(cmd_create_session)
, m_state(0)
, m_state(read_hello_response)
{
#if TORRENT_USE_ASSERTS
m_magic = 0x1337;
@ -446,7 +446,9 @@ namespace libtorrent
case cmd_connect:
send_connect(h);
break;
default:
case cmd_none:
case cmd_name_lookup:
case cmd_incoming:
(*h)(e);
std::vector<char>().swap(m_buffer);
}

View File

@ -3312,7 +3312,7 @@ namespace {
#endif
req.key = tracker_key();
#ifdef TORRENT_USE_OPENSSL
#if TORRENT_USE_I2P
if (is_i2p())
{
req.kind |= tracker_request::i2p;
@ -7441,8 +7441,10 @@ namespace {
error_code ec;
torrent_peer const* p = *i;
address addr = p->address();
#if TORRENT_USE_I2P
if (p->is_i2p_addr)
continue;
#endif
if (p->banned)
{
#if TORRENT_USE_IPV6

View File

@ -91,12 +91,12 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
flags &= ~expect_dht_msg;
#endif
fprintf(stderr, "\n=== TEST == proxy: %s anonymous-mode: %s\n\n", proxy_name[proxy_type], (flags & force_proxy_mode) ? "yes" : "no");
int http_port = start_web_server();
int udp_port = start_udp_tracker();
int dht_port = start_dht();
int peer_port = start_peer();
int const http_port = start_web_server();
int const udp_port = start_udp_tracker();
int const dht_port = start_dht();
int const peer_port = start_peer();
int prev_udp_announces = num_udp_announces();
int const prev_udp_announces = num_udp_announces();
int const alert_mask = alert::all_categories
& ~alert::progress_notification
@ -131,7 +131,7 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
// in non-anonymous mode we circumvent/ignore the proxy if it fails
// wheras in anonymous mode, we just fail
sett.set_str(settings_pack::proxy_hostname, "non-existing.com");
sett.set_int(settings_pack::proxy_type, (settings_pack::proxy_type_t)proxy_type);
sett.set_int(settings_pack::proxy_type, proxy_type);
sett.set_int(settings_pack::proxy_port, 4444);
lt::session* s = new lt::session(sett);
@ -276,10 +276,12 @@ TORRENT_TEST(http_pt)
test_proxy(settings_pack::http_pw, expect_udp_connection | expect_dht_msg);
}
#if TORRENT_USE_I2P
TORRENT_TEST(i2p)
{
test_proxy(settings_pack::i2p_proxy, expect_udp_connection | expect_dht_msg);
}
#endif
// using anonymous mode
@ -317,8 +319,10 @@ TORRENT_TEST(anon_http_pw)
test_proxy(settings_pack::http_pw, force_proxy_mode | expect_udp_reject);
}
#if TORRENT_USE_I2P
TORRENT_TEST(anon_i2p)
{
test_proxy(settings_pack::i2p_proxy, force_proxy_mode);
}
#endif

View File

@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/announce_entry.hpp"
#include <fstream>
#include <boost/bind.hpp>
using namespace libtorrent;
namespace lt = libtorrent;