merged uTP branch into trunk (yay)

This commit is contained in:
Arvid Norberg
2010-11-29 01:33:05 +00:00
parent 5a1669cf03
commit e5f980d80d
77 changed files with 7497 additions and 630 deletions

View File

@@ -3,7 +3,8 @@ example_programs = \
dump_torrent \
enum_if \
make_torrent \
simple_client
simple_client \
utp_test
if ENABLE_EXAMPLES
bin_PROGRAMS = $(example_programs)

View File

@@ -174,6 +174,7 @@ bool print_file_progress = false;
bool show_pad_files = false;
bool show_dht_status = false;
bool sequential_download = false;
bool print_utp_stats = false;
bool print_ip = true;
bool print_as = false;
@@ -384,7 +385,7 @@ int peer_index(libtorrent::tcp::endpoint addr, std::vector<libtorrent::peer_info
void print_peer_info(std::string& out, std::vector<libtorrent::peer_info> const& peers)
{
using namespace libtorrent;
if (print_ip) out += "IP ";
if (print_ip) out += "IP ";
#ifndef TORRENT_DISABLE_GEO_IP
if (print_as) out += "AS ";
#endif
@@ -409,8 +410,8 @@ void print_peer_info(std::string& out, std::vector<libtorrent::peer_info> const&
if (print_ip)
{
error_code ec;
snprintf(str, sizeof(str), "%-22s %22s ", print_endpoint(i->ip).c_str()
snprintf(str, sizeof(str), "%-30s %-22s", (print_endpoint(i->ip) +
(i->connection_type == peer_info::bittorrent_utp ? " [uTP]" : "")).c_str()
, print_endpoint(i->local_endpoint).c_str());
out += str;
}
@@ -425,7 +426,7 @@ void print_peer_info(std::string& out, std::vector<libtorrent::peer_info> const&
#endif
snprintf(str, sizeof(str)
, "%s%s (%s|%s) %s%s (%s|%s) %s%3d (%3d) %3d %c%c%c%c%c%c%c%c%c%c%c%c%c%c %c%c%c%c%c%c "
, "%s%s (%s|%s) %s%s (%s|%s) %s%3d (%3d) %3d %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c %c%c%c%c%c%c "
, esc("32"), add_suffix(i->down_speed, "/s").c_str()
, add_suffix(i->total_download).c_str(), add_suffix(i->download_rate_peak, "/s").c_str()
, esc("31"), add_suffix(i->up_speed, "/s").c_str(), add_suffix(i->total_upload).c_str()
@@ -456,6 +457,8 @@ void print_peer_info(std::string& out, std::vector<libtorrent::peer_info> const&
#else
, '.'
#endif
, (i->flags & peer_info::holepunched)?'h':'.'
, (i->source & peer_info::tracker)?'T':'_'
, (i->source & peer_info::pex)?'P':'_'
, (i->source & peer_info::dht)?'D':'_'
@@ -833,9 +836,12 @@ int main(int argc, char* argv[])
" -L <user:passwd> Use the specified username and password for the\n"
" proxy specified by -P\n"
" -H Don't start DHT\n"
" -M Disable TCP/uTP bandwidth balancing\n"
" -W <num peers> Set the max number of peers to keep in the peer list\n"
" -N Do not attempt to use UPnP and NAT-PMP to forward ports\n"
" -Y Rate limit local peers\n"
" -y Disable TCP connections (disable outgoing TCP and reject\n"
" incoming TCP connections)\n"
" -q <num loops> automatically quit the client after <num loops> of refreshes\n"
" this is useful for scripting tests\n"
" "
@@ -903,8 +909,6 @@ int main(int argc, char* argv[])
{
if (argv[i][0] != '-')
{
// interpret this as a torrent
// match it against the <hash>@<tracker> format
if (strlen(argv[i]) > 45
&& is_hex(argv[i], 40)
@@ -955,7 +959,7 @@ int main(int argc, char* argv[])
case 'U': torrent_upload_limit = atoi(arg) * 1000; break;
case 'D': torrent_download_limit = atoi(arg) * 1000; break;
case 'm': monitor_dir = arg; break;
case 'M': share_mode = true; --i; break;
case 'Q': share_mode = true; --i; break;
case 'b': bind_to_interface = arg; break;
case 'w': settings.urlseed_wait_retry = atoi(arg); break;
case 't': poll_interval = atoi(arg); break;
@@ -1006,6 +1010,8 @@ int main(int argc, char* argv[])
case 'A': settings.allowed_fast_set_size = atoi(arg); break;
case 'R': settings.read_cache_line_size = atoi(arg); break;
case 'O': settings.allow_reordered_disk_operations = false; --i; break;
case 'M': settings.mixed_mode_algorithm = session_settings::prefer_tcp; --i; break;
case 'y': settings.enable_outgoing_tcp = false; settings.enable_incoming_tcp = false; --i; break;
case 'P':
{
char* port = (char*) strrchr(arg, ':');
@@ -1297,6 +1303,7 @@ int main(int argc, char* argv[])
if (c == 'h') show_pad_files = !show_pad_files;
if (c == 'a') print_piece_bar = !print_piece_bar;
if (c == 'g') show_dht_status = !show_dht_status;
if (c == 'u') print_utp_stats = !print_utp_stats;
// toggle columns
if (c == '1') print_ip = !print_ip;
if (c == '2') print_as = !print_as;
@@ -1566,6 +1573,15 @@ int main(int argc, char* argv[])
}
#endif
if (print_utp_stats)
{
snprintf(str, sizeof(str), "uTP idle: %d syn: %d est: %d fin: %d wait: %d\n"
, sess_stat.utp_stats.num_idle, sess_stat.utp_stats.num_syn_sent
, sess_stat.utp_stats.num_connected, sess_stat.utp_stats.num_fin_sent
, sess_stat.utp_stats.num_close_wait);
out += str;
}
if (active_handle.is_valid())
{
torrent_handle h = active_handle;

View File

@@ -61,15 +61,16 @@ int main()
return 1;
}
printf("%-18s%-18s%-35sinterface name\n", "destination", "network", "gateway");
printf("%-18s%-18s%-35s%-7sinterface\n", "destination", "network", "gateway", "mtu");
for (std::vector<ip_route>::const_iterator i = routes.begin()
, end(routes.end()); i != end; ++i)
{
printf("%-18s%-18s%-35s%s\n"
printf("%-18s%-18s%-35s%-7d%s\n"
, i->destination.to_string(ec).c_str()
, i->netmask.to_string(ec).c_str()
, i->gateway.to_string(ec).c_str()
, i->mtu
, i->name);
}
@@ -82,15 +83,16 @@ int main()
return 1;
}
printf("%-18s%-18s%-35sflags\n", "address", "netmask", "name");
printf("%-35s%-18s%-40s%-8sflags\n", "address", "netmask", "name", "mtu");
for (std::vector<ip_interface>::const_iterator i = net.begin()
, end(net.end()); i != end; ++i)
{
printf("%-18s%-18s%-35s%s%s%s\n"
printf("%-35s%-18s%-40s%-8d%s%s%s\n"
, i->interface_address.to_string(ec).c_str()
, i->netmask.to_string(ec).c_str()
, i->name
, i->mtu
, (is_multicast(i->interface_address)?"multicast ":"")
, (is_local(i->interface_address)?"local ":"")
, (is_loopback(i->interface_address)?"loopback ":"")

48
examples/utp_test.cpp Normal file
View File

@@ -0,0 +1,48 @@
#include "libtorrent/error_code.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/socket_type.hpp"
#include "libtorrent/utp_socket_manager.hpp"
#include "libtorrent/utp_stream.hpp"
using namespace libtorrent;
void on_connect(error_code const& e)
{
}
void on_udp_receive(error_code const& e, udp::endpoint const& ep
, char const* buf, int size)
{
}
void on_utp_incoming(void* userdata
, boost::shared_ptr<utp_stream> const& utp_sock)
{
}
int main(int argc, char* argv[])
{
//int rtt, rtt_var;
//int max_window, cur_window;
//int delay_factor, window_factor, scaled_gain;
/*session s;
s.listen_on(std::make_pair(6881, 6889));*/
io_service ios;
connection_queue cc(ios);
udp_socket udp_sock(ios, boost::bind(&on_udp_receive, _1, _2, _3, _4), cc);
void* userdata;
utp_socket_manager utp_sockets(udp_sock, boost::bind(&on_utp_incoming, _1, _2), userdata);
/*error_code ec;
utp_stream sock(ios, cc);
sock.bind(udp::endpoint(address_v4::any(), 0), ec);
tcp::endpoint ep(address_v4::from_string("239.192.152.143", ec), 6771);
sock.async_connect(ep, boost::bind(on_connect, _1));*/
return 0;
}