Permalink
Browse files

perltidy (it's a fetish)

  • Loading branch information...
1 parent 7d0e1c5 commit 89d3f51477325ff5bac91a0ebef6e7e3eda8b277 @sanko committed Feb 1, 2011
View
9 examples/client.pl
@@ -5,7 +5,6 @@
# Track every object including where they're created
#use Devel::Leak::Object qw{ GLOBAL_bless };
#$Devel::Leak::Object::TRACKSOURCELINES = 1;
-
#
use AnyEvent::Impl::Perl;
use Data::Dump;
@@ -33,19 +32,21 @@
},
on_peer_disconnect => sub {
my ($s, $a) = @_;
- #
- warn 'Disconnect: ' . $a->{'message'};
+
+ #
+ warn 'Disconnect: ' . $a->{'message'};
},
on_peer_packet_in => sub {
my ($s, $a) = @_;
+
# warn $a->{'message'}; # ddx $a->{'packet'};
},
on_peer_packet_out => sub { ...; },
on_piece_hash_pass => sub {
my ($s, $i) = @_;
warn sprintf '+ We now have piece %-3d', $i;
- #exit if $s->torrent(0)->seed;
+ #exit if $s->torrent(0)->seed;
$cli->send if $s->torrent(0)->seed;
},
on_piece_hash_fail => sub {
View
3 lib/Net/BitTorrent/Peer.pm
@@ -134,7 +134,8 @@ package Net::BitTorrent::Peer;
around '_delete_request' => sub {
my ($c, $s, $i, $o, $l) = @_;
return $c->($s, $i) if !ref $i && !defined $o;
- my (undef, $x) = $s->_find_request(
+ my (undef, $x)
+ = $s->_find_request(
blessed $i ? ($i->index, $i->offset, $i->length) : ($i, $o, $l));
return $c->($s, $x);
};
View
3 lib/Net/BitTorrent/Protocol/BEP03/Metadata/Piece/Block.pm
@@ -60,7 +60,8 @@
require Scalar::Util;
Scalar::Util::weaken $s;
AE::timer(
- 5*60, 0,
+ 5 * 60,
+ 0,
sub {
$s // return;
$s->complete && return;
View
26 lib/Net/BitTorrent/Protocol/BEP03/Peer.pm
@@ -144,8 +144,8 @@ package Net::BitTorrent::Protocol::BEP03::Peer;
$s->disconnect(sprintf 'Bad piece index in request: %d > %d',
$i, $s->torrent->piece_count)
if $i > $s->torrent->piece_count;
- my $_l =
- ($i == $s->torrent->piece_count - 1)
+ my $_l
+ = ($i == $s->torrent->piece_count - 1)
? $s->torrent->size % $s->torrent->piece_length
: $s->torrent->piece_length;
return
@@ -189,14 +189,13 @@ package Net::BitTorrent::Protocol::BEP03::Peer;
my ($i, $o, $d) = @$p;
warn sprintf 'peer sent i:%d o:%d l:%d', $i, $o, length $d;
my $req = $s->_find_request($i, $o, length $d);
- $req //
- return $s->disconnect('Peer sent us a block we were not asking for')
- ;
+ $req // return $s->disconnect(
+ 'Peer sent us a block we were not asking for');
$req->_write($d);
$s->_delete_request($req);
return if $req->piece->_first_incompete_block;
- my $piece =
- $s->torrent->piece_selector->_get_working_piece($req->index);
+ my $piece
+ = $s->torrent->piece_selector->_get_working_piece($req->index);
$_->has_peer && $_->peer->_delete_request($_)
for $piece->_complete_blocks;
@@ -288,7 +287,8 @@ package Net::BitTorrent::Protocol::BEP03::Peer;
require Scalar::Util;
Scalar::Util::weaken $s;
AE::timer(
- 10 * 60, 0,
+ 10 * 60,
+ 0,
sub {
$s // return;
$s->disconnect('Peer disconnected due to inactivity');
@@ -324,8 +324,8 @@ package Net::BitTorrent::Protocol::BEP03::Peer;
$s->has_peer_id ? $s->peer_id : '[Unknown peer]'
}
);
- my $code =
- $s->can('_handle_packet_' . $_packet_dispatch{$p->{'type'}});
+ my $code
+ = $s->can('_handle_packet_' . $_packet_dispatch{$p->{'type'}});
return $code->($s, $p->{'payload'}) if $code;
return if !eval 'require Data::Dump;';
Data::Dump::ddx($p);
@@ -355,7 +355,6 @@ package Net::BitTorrent::Protocol::BEP03::Peer;
sub _send_request {
my ($s, $b) = @_;
return if $s->remote_choked;
-
warn sprintf 'Sending request for i:%d o:%d l:%d to %s', $b->index,
$b->offset, $b->length, $s->peer_id;
return $s->push_write(
@@ -365,7 +364,6 @@ package Net::BitTorrent::Protocol::BEP03::Peer;
sub _send_cancel {
my ($s, $b) = @_;
return if $s->remote_choked;
-
warn sprintf 'Sending cancel for i:%d o:%d l:%d to %s', $b->index,
$b->offset, $b->length, $s->peer_id;
return $s->push_write(
@@ -375,8 +373,8 @@ package Net::BitTorrent::Protocol::BEP03::Peer;
sub _send_piece {
my ($s, $i, $o, $l) = @_;
return if $s->choked;
-
- warn sprintf 'Sending block i:%d o:%d l:%d to %s', $i, $o, $l, $s->peer_id;
+ warn sprintf 'Sending block i:%d o:%d l:%d to %s', $i, $o, $l,
+ $s->peer_id;
return $s->push_write(
build_piece($i, $o, $l, $s->torrent->read($i, $o, $l)));
}
View
1 lib/Net/BitTorrent/Protocol/BEP03/Peer/Incoming.pm
@@ -96,6 +96,7 @@
$info_hash->to_Hex)
if !$t;
$s->_set_torrent($t);
+
#$s->_check_unique_connection;
return if !defined $s;
View
1 lib/Net/BitTorrent/Protocol/BEP03/Peer/Outgoing.pm
@@ -122,6 +122,7 @@
return $s->disconnect(
'Bad info_hash (Does not match the torrent we were seeking)')
if $info_hash->Compare($s->torrent->info_hash) != 0;
+
#$s->_check_unique_connection;
return if !defined $s;
$s->_send_bitfield;
View
34 lib/Net/BitTorrent/Torrent.pm
@@ -195,16 +195,17 @@ package Net::BitTorrent::Torrent;
return if !@{$source->[2]};
require Net::BitTorrent::Protocol::BEP03::Peer::Outgoing;
my $x = 1;
+
for ($self->_count_peers .. $self->max_peers) {
$self->client->add_peer(
- Net::BitTorrent::Protocol::BEP03::Peer::Outgoing
- ->new(
- torrent => $self,
- connect =>
- $source->[2]->[rand @{$source->[2]}],
- source => 'dht',
- client => $self->client
- )
+ Net::BitTorrent::Protocol::BEP03::Peer::Outgoing
+ ->new(
+ torrent => $self,
+ connect =>
+ $source->[2]->[rand @{$source->[2]}],
+ source => 'dht',
+ client => $self->client
+ )
);
last if $x == 3;
}
@@ -224,16 +225,17 @@ package Net::BitTorrent::Torrent;
return if !@{$source->[2]};
require Net::BitTorrent::Protocol::BEP03::Peer::Outgoing;
my $x = 1;
+
for ($self->_count_peers .. $self->max_peers) {
$self->client->add_peer(
- Net::BitTorrent::Protocol::BEP03::Peer::Outgoing
- ->new(
- torrent => $self,
- connect =>
- $source->[2]->[rand @{$source->[2]}],
- source => 'tracker',
- client => $self->client
- )
+ Net::BitTorrent::Protocol::BEP03::Peer::Outgoing
+ ->new(
+ torrent => $self,
+ connect =>
+ $source->[2]->[rand @{$source->[2]}],
+ source => 'tracker',
+ client => $self->client
+ )
);
last if $x == 3;
}
View
3 lib/Net/BitTorrent/Torrent/PieceSelector.pm
@@ -26,8 +26,9 @@
}
);
sub _build__working_pieces { {} }
+
sub _unassigned_working_pieces {
- grep { $_->_first_unassigned_block?1:0 } shift->working_pieces;
+ grep { $_->_first_unassigned_block ? 1 : 0 } shift->working_pieces;
}
has 'strategy' => (isa => 'RoleName',
is => 'ro',
View
2 lib/Net/BitTorrent/Torrent/PieceSelector/Random.pm
@@ -18,7 +18,7 @@
my @incomplete = $s->_unassigned_working_pieces;
return $incomplete[rand @incomplete] if @incomplete;
return if $s->_count_working_pieces >= $s->max_working_pieces;
- my @indices= $peer->_wanted_pieces->Index_List_Read();
+ my @indices = $peer->_wanted_pieces->Index_List_Read();
return scalar @indices ? $indices[rand @indices] : ();
}
View
3 t/10000_by_class/Net/BitTorrent.t
@@ -213,8 +213,7 @@ package t::10000_by_class::Net::BitTorrent;
sub validate_ip_filter : Test( 1 ) {
my $s = shift;
- isa_ok $s->{'nb'}->ip_filter, 'Config::IPFilter',
- '...->ip_filter( )';
+ isa_ok $s->{'nb'}->ip_filter, 'Config::IPFilter', '...->ip_filter( )';
}
sub validate_dht : Test( 1 ) {

0 comments on commit 89d3f51

Please sign in to comment.