Permalink
Browse files

Another one of those megacommits I promised I'd never make again.

  • Loading branch information...
1 parent d4ea4e9 commit 1464cae85d8f6d42ecf9f9a4a5462fc912308b69 @sanko committed Nov 5, 2010
Showing with 720 additions and 399 deletions.
  1. +3 −3 Build.PL
  2. +2 −2 Changes
  3. +1 −1 examples/generate_torrent.pl
  4. +4 −3 examples/standalone_dht.pl
  5. +1 −1 examples/swarm_statistics.pl
  6. +56 −31 lib/Net/BitTorrent.pm
  7. +6 −6 lib/Net/BitTorrent/DHT.pm
  8. +8 −11 lib/Net/BitTorrent/DHT/Standalone.pm
  9. +1 −1 lib/Net/BitTorrent/Network/IPFilter.pm
  10. +1 −1 lib/Net/BitTorrent/Network/IPFilter/Rule.pm
  11. +1 −1 lib/Net/BitTorrent/Network/TCP.pm
  12. +20 −22 lib/Net/BitTorrent/Network/UDP.pm
  13. +1 −1 lib/Net/BitTorrent/Network/Utility.pm
  14. +58 −31 lib/Net/BitTorrent/Peer.pm
  15. +19 −19 lib/Net/BitTorrent/Protocol/BEP03/Metadata.pm
  16. +19 −8 lib/Net/BitTorrent/Protocol/BEP03/Metadata/Piece.pm
  17. +47 −11 lib/Net/BitTorrent/Protocol/BEP03/Metadata/Piece/Block.pm
  18. +1 −1 lib/Net/BitTorrent/Protocol/BEP03/Packets.pm
  19. +178 −44 lib/Net/BitTorrent/Protocol/BEP03/Peer.pm
  20. +7 −7 lib/Net/BitTorrent/Protocol/BEP03/Peer/Incoming.pm
  21. +23 −15 lib/Net/BitTorrent/Protocol/BEP03/Peer/Outgoing.pm
  22. +3 −2 lib/Net/BitTorrent/Protocol/BEP03/Tracker/HTTP.pm
  23. +2 −2 lib/Net/BitTorrent/Protocol/BEP05/Bucket.pm
  24. +33 −21 lib/Net/BitTorrent/Protocol/BEP05/Node.pm
  25. +1 −1 lib/Net/BitTorrent/Protocol/BEP05/Packets.pm
  26. +1 −1 lib/Net/BitTorrent/Protocol/BEP05/RoutingTable.pm
  27. +1 −1 lib/Net/BitTorrent/Protocol/BEP05/Tracker.pm
  28. +1 −1 lib/Net/BitTorrent/Protocol/BEP07/Compact.pm
  29. +18 −10 lib/Net/BitTorrent/Protocol/BEP12/MultiTracker.pm
  30. +3 −3 lib/Net/BitTorrent/Protocol/BEP15/Tracker/UDP.pm
  31. +1 −1 lib/Net/BitTorrent/Protocol/BEP23/Compact.pm
  32. +1 −1 lib/Net/BitTorrent/Protocol/BEP27/Private/Metadata.pm
  33. +2 −2 lib/Net/BitTorrent/Protocol/MSE/Peer.pm
  34. +1 −1 lib/Net/BitTorrent/Storage.pm
  35. +1 −1 lib/Net/BitTorrent/Storage/Cache.pm
  36. +2 −2 lib/Net/BitTorrent/Storage/File.pm
  37. +1 −1 lib/Net/BitTorrent/Storage/Node.pm
  38. +77 −38 lib/Net/BitTorrent/Torrent.pm
  39. +30 −27 lib/Net/BitTorrent/Torrent/Generator.pm
  40. +26 −15 lib/Net/BitTorrent/Torrent/PieceSelector.pm
  41. +1 −1 lib/Net/BitTorrent/Torrent/PieceSelector/Endgame.pm
  42. +1 −1 lib/Net/BitTorrent/Torrent/PieceSelector/Hybrid.pm
  43. +1 −1 lib/Net/BitTorrent/Torrent/PieceSelector/Linear.pm
  44. +1 −1 lib/Net/BitTorrent/Torrent/PieceSelector/Popular.pm
  45. +17 −5 lib/Net/BitTorrent/Torrent/PieceSelector/Random.pm
  46. +1 −1 lib/Net/BitTorrent/Torrent/PieceSelector/Rarest.pm
  47. +1 −1 lib/Net/BitTorrent/Types.pm
  48. +7 −7 t/10000_by_class/Net/BitTorrent.t
  49. +1 −1 t/10000_by_class/Net/BitTorrent/DHT.t
  50. +1 −1 t/10000_by_class/Net/BitTorrent/DHT/Standalone.t
  51. +1 −1 t/10000_by_class/Net/BitTorrent/Network/IPFilter.t
  52. +1 −1 t/10000_by_class/Net/BitTorrent/Network/IPFilter/Rule.t
  53. +1 −1 t/10000_by_class/Net/BitTorrent/Network/IPFilter_path.t
  54. +3 −3 t/10000_by_class/Net/BitTorrent/Protocol/BEP03/Peer/Incoming.t
  55. +2 −2 t/10000_by_class/Net/BitTorrent/Protocol/BEP03/Peer/Outgoing.t
  56. +1 −1 t/10000_by_class/Net/BitTorrent/Protocol/BEP03/Peer/Outgoing_bad_info_hash.t
  57. +1 −1 t/10000_by_class/Net/BitTorrent/Storage/File.t
  58. +2 −3 t/10000_by_class/Net/BitTorrent/Torrent/Generator.t
  59. +3 −3 t/10000_by_class/Net/BitTorrent/Torrent/Generator_announce.t
  60. +3 −4 t/10000_by_class/Net/BitTorrent/Torrent/Generator_announce_list.t
  61. +1 −1 t/10000_by_class/Net/BitTorrent/Torrent/Generator_multiple_files.t
  62. +1 −1 t/10000_by_class/Net/BitTorrent/Torrent/Generator_piece_length.t
  63. +1 −1 t/10000_by_class/Net/BitTorrent/Torrent/Generator_single_file.t
  64. +1 −1 t/10000_by_class/Net/BitTorrent_random_port.t
  65. +1 −1 t/10000_by_class/Net/BitTorrent_single_port.t
  66. +1 −1 t/60000_swarm/60010_http.t
  67. +1 −1 t/80000_utility/Net/BitTorrent/Tracker.pm
  68. +1 −1 t/80000_utility/Net/BitTorrent/Tracker/HTTP.pm
View
@@ -3,7 +3,7 @@ use strict;
use warnings;
use File::Find;
use Module::Build;
-our $MAJOR = 0.074; our $MINOR = 0; our $DEV = 12; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
+our $MAJOR = 0; our $MINOR = 74; our $DEV = 13; our $VERSION = sprintf('%0d.%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
$|++;
my $automated_testing = $ENV{'AUTOMATED_TESTING'}
|| $ENV{'PERL_MM_USE_DEFAULT'};
@@ -24,7 +24,7 @@ my $mb = $class->new(
dist_version => $VERSION,
requires => {
AnyEvent => 0,
- 'AnyEvent::Handle::Throttle' => '0.000002004',
+ 'AnyEvent::Handle::Throttle' => '0.000002005',
'Bit::Vector' => 0,
'Digest::SHA' => 5.45,
Exporter => 0,
@@ -35,7 +35,7 @@ my $mb = $class->new(
'Scalar::Util' => 1.19
},
build_requires => {AnyEvent => 0,
- 'AnyEvent::Handle::Throttle' => '0.000002004',
+ 'AnyEvent::Handle::Throttle' => '0.000002005',
'Bit::Vector' => 0,
'Digest::SHA' => 5.45,
Exporter => 0,
View
@@ -1,4 +1,4 @@
-Version 0.XXXXX | In the not too distant future | baf5a6f
+Version 0.XXXXX | In the not too distant future | d4ea4e9
API Changes/Compatibility Information:
* Rewrite!
@@ -433,7 +433,7 @@ Version 0.008 | 2008-04-01 19:46:20 -0400 (Tue, 01 Apr 2008)
_ -.-. .... .- -. --. . ... _________________________________________
For more information, see the commit log:
- http://github.com/sanko/net-bittorrent/commits/summer-2010-moose-anyevent/
+ http://github.com/sanko/net-bittorrent/commits/
$Ver$ from git $Rev$
$Date$
@@ -2,7 +2,7 @@
use warnings;
use lib '../lib';
use Net::BitTorrent::Torrent::Generator;
-our $MAJOR = 0.074; our $MINOR = 0; our $DEV = 12; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
+our $MAJOR = 0; our $MINOR = 74; our $DEV = 13; our $VERSION = sprintf('%0d.%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
$|++;
#
@@ -5,7 +5,7 @@
use lib '../lib';
use Net::BitTorrent::DHT;
$|++;
-our $MAJOR = 0.074; our $MINOR = 0; our $DEV = 5; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
+our $MAJOR = 0; our $MINOR = 74; our $DEV = 13; our $VERSION = sprintf('%0d.%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
# Standalone node with user-defined port and boot_nodes
my $dht = Net::BitTorrent::DHT->new(
@@ -15,10 +15,11 @@
);
# Two 'quests' for peers (these are two popular Ubuntu swarms)
+# See http://torrent.ubuntu.com:6969/ for updated list
my $quest_A
- = $dht->get_peers('3e16157f0879eb43e9e51f45d485feff90a77283', \&dht_cb);
+ = $dht->get_peers('bcf2e587afd4d3b1bdd8ece5150d9fb4d2958af4', \&dht_cb);
my $quest_B
- = $dht->get_peers('a1425e0d6630336cdd9fb320f3fff1030098975a', \&dht_cb);
+ = $dht->get_peers('cdc844a364ae2417ea204ea4840129b2298e7dd4', \&dht_cb);
# Let's stay up to date with what's going on in the routing table
my $timer = AE::timer 60 * 2, 60 * 5,
@@ -4,7 +4,7 @@
use AnyEvent;
use Net::BitTorrent;
use 5.010.000;
-our $MAJOR = 0.074; our $MINOR = 0; our $DEV = 12; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
+our $MAJOR = 0; our $MINOR = 74; our $DEV = 13; our $VERSION = sprintf('%0d.%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
$|++;
my %torrents;
{
View
@@ -3,15 +3,23 @@ package Net::BitTorrent;
use 5.010;
use Moose;
use Moose::Util::TypeConstraints;
- our $MAJOR = 0.074; our $MINOR = 0; our $DEV = 7; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
+ our $MAJOR = 0; our $MINOR = 74; our $DEV = 13; our $VERSION = sprintf('%0d.%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
use AnyEvent;
use lib '../../lib';
use Net::BitTorrent::Types qw[:client];
sub BUILD {1}
#
sub timer { shift; AnyEvent->timer(@_) }
- sub run { AnyEvent->condvar->recv }
+ sub run { shift->recv }
+
+ #
+ has 'condvar' => (isa => 'Ref', # XXX - actual
+ is => 'ro',
+ lazy_build => 1,
+ handles => [qw[wait recv send]]
+ );
+ sub _build_condvar { return AnyEvent->condvar }
#
has 'peer_id' => (isa => 'NBTypes::Client::PeerID',
@@ -72,7 +80,7 @@ package Net::BitTorrent;
return
blessed $torrent
&& $code->($self, $torrent)
- && $torrent->client($self) ? $torrent : ();
+ && $torrent->_set_client($self) ? $torrent : ();
};
my $info_hash_constraint;
around 'torrent' => sub ($) {
@@ -86,7 +94,7 @@ package Net::BitTorrent;
$torrent = $self->find_torrent(
sub {
- #$_->_has_info_hash &&
+ #$_->has_info_hash &&
$_->info_hash->Lexicompare($info_hash) == 0;
}
);
@@ -129,39 +137,36 @@ package Net::BitTorrent;
#trigger => sub {...}
);
{
- my %_sock_types = (4 => '0.0.0.0', 6 => '::');
for my $prot (qw[tcp udp]) {
- for my $ipv (keys %_sock_types) {
+ for my $ipv (4, 6) {
has $prot
. $ipv => (is => 'ro',
init_arg => undef,
isa => 'Maybe[Object]',
lazy_build => 1,
- writer => '_set_' . $prot . $ipv,
- predicate => '_has_' . $prot . $ipv
+ writer => '_set_' . $prot . $ipv
);
has $prot
. $ipv
- . '_sock' => (
- is => 'ro',
- init_arg => undef,
- isa => 'GlobRef',
- lazy_build => 1,
- weak_ref => 1,
- writer => '_set_' . $prot . $ipv . '_sock',
- predicate => '_has_' . $prot . $ipv . '_sock'
+ . '_sock' => (is => 'ro',
+ init_arg => undef,
+ isa => 'GlobRef',
+ lazy_build => 1,
+ weak_ref => 1,
+ writer => '_set_' . $prot . $ipv . '_sock'
);
has $prot
. $ipv
- . '_host' => (
- is => 'ro',
- isa => 'Str',
- default => $_sock_types{$ipv},
- writer => '_set_' . $prot . $ipv . '_host',
- predicate => '_has_' . $prot . $ipv . '_host'
+ . '_host' => (is => 'ro',
+ isa => 'Str',
+ lazy_build => 1,
+ builder => '_build_' . $ipv . '_host',
+ writer => '_set_' . $prot . $ipv . '_host'
);
}
}
+ sub _build_4_host {'0.0.0.0'}
+ sub _build_6_host {'::'}
}
after 'BUILDALL' => sub { $_[0]->$_() for qw[tcp6 tcp4 udp4 udp6] };
@@ -376,11 +381,21 @@ package Net::BitTorrent;
$peer = Net::BitTorrent::Protocol::BEP03::Peer::Incoming->new(
client => $self,
handle => AnyEvent::Handle::Throttle->new(
- fh => $peer,
+ fh => $peer,
+ on_error => sub {
+ return if !defined $peer;
+ my ($hdl, $fatal, $msg) = @_;
+
+ #$peer->handle->destroy;
+ $peer->disconnect('Socket error: ' . $msg) if $fatal;
+ },
on_eof => sub {
return if !defined $peer;
- $peer->_handle->push_shutdown;
- $peer->_handle->destroy;
+ $peer->handle->push_shutdown
+ if defined $peer->handle->{'fh'};
+ $peer->handle->destroy;
+ $peer->disconnect(
+ 'Connection closed by remote connection');
}
)
);
@@ -416,11 +431,21 @@ package Net::BitTorrent;
$peer = Net::BitTorrent::Protocol::BEP03::Peer::Incoming->new(
client => $self,
handle => AnyEvent::Handle::Throttle->new(
- fh => $peer,
+ fh => $peer,
+ on_error => sub {
+ return if !defined $peer;
+ my ($hdl, $fatal, $msg) = @_;
+
+ #$s->handle->destroy;
+ $peer->disconnect('Socket error: ' . $msg) if $fatal;
+ },
on_eof => sub {
return if !defined $peer;
- $peer->_handle->push_shutdown;
- $peer->_handle->destroy;
+ $peer->handle->push_shutdown
+ if defined $peer->handle->{'fh'};
+ $peer->handle->destroy;
+ $peer->disconnect(
+ 'Connection closed by remote connection');
}
)
);
@@ -475,8 +500,8 @@ package Net::BitTorrent;
#
has 'max_peers' => (isa => 'Int',
- is => 'rw',
- default => '50'
+ is => 'ro',
+ default => 50
);
has '_peers' => (
is => 'HashRef[Net::BitTorrent::Peer]', # by creation id
@@ -505,7 +530,7 @@ package Net::BitTorrent;
sub {1}
}
has "on_$_" => (isa => 'CodeRef',
- is => 'rw',
+ is => 'ro',
traits => ['Code'],
handles => {"trigger_$_" => 'execute_method'},
lazy_build => 1,
@@ -9,7 +9,7 @@ package Net::BitTorrent::DHT;
use Net::BitTorrent::Types qw[:dht :addr];
use Net::BitTorrent::Protocol::BEP05::RoutingTable;
use 5.10.0;
- our $MAJOR = 0.074; our $MINOR = 0; our $DEV = 3; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
+ our $MAJOR = 0; our $MINOR = 74; our $DEV = 13; our $VERSION = sprintf('%0d.%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
# Stub
sub BUILD {1}
@@ -24,7 +24,7 @@ package Net::BitTorrent::DHT;
after 'BUILD' => sub {
my ($s, $a) = @_;
return has '+client' =>
- (handles => qr[^(?:(?:_has_)?udp\d.*?|ip_filter|port)])
+ (handles => qr[^(?:(?:has_)?udp\d.*?|ip_filter|port)])
if $s->has_client;
require Moose::Util;
Moose::Util::apply_all_roles($s,
@@ -88,9 +88,9 @@ package Net::BitTorrent::DHT;
return $s->routing_table->del_node($node);
}
my $sock
- = $node->ipv6 && $s->_has_udp6_sock ? $s->udp6_sock
- : $s->_has_udp4_sock ? $s->udp4_sock
- : ();
+ = $node->ipv6 && $s->has_udp6_sock ? $s->udp6_sock
+ : $s->has_udp4_sock ? $s->udp4_sock
+ : ();
my $sent = $sock ? send $sock, $packet, 0, $node->sockaddr : return;
if ($reply) {
$s->_inc_send_replies_count;
@@ -343,7 +343,7 @@ package Net::BitTorrent::DHT;
$self->_inc_recv_replies_count;
$self->_inc_recv_replies_length(length $data);
$node->_v($packet->{'v'})
- if !$node->_has_v && defined $packet->{'v'};
+ if !$node->has_v && defined $packet->{'v'};
my $req
= $node->del_request($packet->{'t'}); # For future ref
$req->{'cb'}->($packet, $host, $port)
@@ -3,7 +3,7 @@ package Net::BitTorrent::DHT::Standalone;
use Moose::Role;
use lib '../../../../lib';
use Net::BitTorrent::Protocol::BEP03::Bencode qw[:all];
- our $MAJOR = 0.074; our $MINOR = 0; our $DEV = 3; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
+ our $MAJOR = 0; our $MINOR = 74; our $DEV = 13; our $VERSION = sprintf('%0d.%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
has 'port' => (is => 'ro',
isa => 'Int|ArrayRef[Int]',
builder => '_build_port',
@@ -21,8 +21,7 @@ package Net::BitTorrent::DHT::Standalone;
init_arg => undef,
isa => 'Maybe[Object]',
lazy_build => 1,
- writer => '_set_udp' . $ipv,
- predicate => '_has_udp' . $ipv
+ writer => '_set_udp' . $ipv
);
has 'udp'
. $ipv
@@ -31,16 +30,14 @@ package Net::BitTorrent::DHT::Standalone;
isa => 'GlobRef',
lazy_build => 1,
weak_ref => 1,
- writer => '_set_udp' . $ipv . '_sock',
- predicate => '_has_udp' . $ipv . '_sock'
+ writer => '_set_udp' . $ipv . '_sock'
);
has 'udp'
. $ipv
- . '_host' => (is => 'ro',
- isa => 'Str',
- default => $_sock_types{$ipv},
- writer => '_set_udp' . $ipv . '_host',
- predicate => '_has_udp' . $ipv . '_host'
+ . '_host' => (is => 'ro',
+ isa => 'Str',
+ default => $_sock_types{$ipv},
+ writer => '_set_udp' . $ipv . '_host'
);
}
@@ -189,7 +186,7 @@ package Net::BitTorrent::DHT::Standalone;
sub {1}
}
has "on_$_" => (isa => 'CodeRef',
- is => 'rw',
+ is => 'ro',
traits => ['Code'],
handles => {"trigger_$_" => 'execute_method'},
lazy_build => 1,
@@ -3,7 +3,7 @@ package Net::BitTorrent::Network::IPFilter;
use Moose;
use Moose::Util::TypeConstraints;
use 5.010.000;
- our $MAJOR = 0.074; our $MINOR = 1; our $DEV = 6; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
+ our $MAJOR = 0; our $MINOR = 74; our $DEV = 13; our $VERSION = sprintf('%0d.%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
use lib '../../../';
use Net::BitTorrent::Network::Utility qw[:paddr];
sub BUILD { 1; }
@@ -3,7 +3,7 @@ package Net::BitTorrent::Network::IPFilter::Rule;
use Moose;
use Moose::Util::TypeConstraints;
use 5.010.000;
- our $MAJOR = 0.074; our $MINOR = 0; our $DEV = 2; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
+ our $MAJOR = 0; our $MINOR = 74; our $DEV = 13; our $VERSION = sprintf('%0d.%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
use lib '../../../../';
use Net::BitTorrent::Types qw[:addr];
sub BUILD { 1; }
@@ -4,7 +4,7 @@ package Net::BitTorrent::Network::TCP;
use AnyEvent;
use lib '../../../../lib';
use Net::BitTorrent::Network::Utility qw[server];
- our $MAJOR = 0.074; our $MINOR = 0; our $DEV = 2; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
+ our $MAJOR = 0; our $MINOR = 74; our $DEV = 13; our $VERSION = sprintf('%0d.%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
#
my %_sock_types = (4 => '0.0.0.0', 6 => '::');
Oops, something went wrong. Retry.

0 comments on commit 1464cae

Please sign in to comment.