Permalink
Browse files

Minor bug fixes and some perltidy

  • Loading branch information...
1 parent 1e88b5b commit d7902651db26e6cd1ad754119354c537aff0e87c @sanko committed Oct 26, 2010
@@ -135,7 +135,7 @@ package Net::BitTorrent::DHT;
my ($s, $n) = @_;
require Net::BitTorrent::Protocol::BEP05::Node;
my $sockaddr = sockaddr($n->[0], $n->[1]);
- next if !$sockaddr;
+ return if !$sockaddr;
$n
= blessed $n ? $n
: Net::BitTorrent::Protocol::BEP05::Node->new(
@@ -3,33 +3,33 @@ package Net::BitTorrent::Network::IPFilter;
use Moose;
use Moose::Util::TypeConstraints;
use 5.010.000;
- our $MAJOR = 0.074; our $MINOR = 0; our $DEV = 6; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
+ our $MAJOR = 0.074; our $MINOR = 1; our $DEV = 6; our $VERSION = sprintf('%1.3f%03d' . ($DEV ? (($DEV < 0 ? '' : '_') . '%03d') : ('')), $MAJOR, $MINOR, abs $DEV);
use lib '../../../';
use Net::BitTorrent::Network::Utility qw[:paddr];
sub BUILD { 1; }
has 'rules' => (
- isa => 'ArrayRef[Net::BitTorrent::Network::IPFilter::Rule]' => is =>
- 'ro',
- traits => ['Array'],
- init_arg => undef,
- default => sub { [] },
- handles => {
- add_rule => 'push',
- count_rules => 'count',
- is_empty => 'is_empty',
- get_rule => 'get',
- first_rule => 'first',
- grep_rules => 'grep',
- map_rules => 'map',
- sort_rules => 'sort',
- sort_rules_in_place => 'sort_in_place',
- shuffle_rules => 'shuffle',
- clear_rules => 'clear',
- insert_rule => 'insert',
- delete_rule => 'delete',
- push_rule => 'push',
- pop_rule => 'pop'
- }
+ isa => 'ArrayRef[Net::BitTorrent::Network::IPFilter::Rule]',
+ is => 'ro',
+ traits => ['Array'],
+ init_arg => undef,
+ default => sub { [] },
+ handles => {
+ add_rule => 'push',
+ count_rules => 'count',
+ is_empty => 'is_empty',
+ get_rule => 'get',
+ first_rule => 'first',
+ grep_rules => 'grep',
+ map_rules => 'map',
+ sort_rules => 'sort',
+ sort_rules_in_place => 'sort_in_place',
+ shuffle_rules => 'shuffle',
+ clear_rules => 'clear',
+ insert_rule => 'insert',
+ delete_rule => 'delete',
+ push_rule => 'push',
+ pop_rule => 'pop'
+ }
);
around 'add_rule' => sub {
my ($c, $s, $l, $u, $a, $d) = @_;
@@ -118,8 +118,8 @@ Warning:
The example above will block any connection to the specified IP-range. This
may reduce the number of sources for downloads.
-At the moment only one access levels are implemented. A value below 127 means
-that any connection-attempt is denied.
+At the moment only one access levels are implemented. A value at or below
+C<127> means that any connection-attempt is denied.
=head2 Notes
@@ -178,7 +178,9 @@ Stores the in-memory ipfilter to disk.
Indicates whether or not C<$ip> is banned. If so, the
L<rule|Net::BitTorrent::Network::IPFilter::Rule> in which it was found is
-returned. If not, a false value is returned.
+returned. If not, a false value is returned. Currently, rules with an
+L<< access_level|Net::BitTorrent::Network::IPFilter::Rule/"$filter->B<access_level>( )" >>
+at or below C<127> are considered banned.
=head1 IPv6 Support
@@ -192,10 +194,24 @@ L<Emule Project's ipfilter.dat documentation|http://www.emule-project.net/home/p
=head1 Author
+=begin :html
+
+L<Sanko Robinson|http://sankorobinson.com/>
+<L<sanko@cpan.org|mailto://sanko@cpan.org>> -
+L<http://sankorobinson.com/|http://sankorobinson.com/>
+
+CPAN ID: L<SANKO|http://search.cpan.org/~sanko>
+
+=end :html
+
+=begin :text
+
Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/
CPAN ID: SANKO
+=end :text
+
=head1 License and Legal
Copyright (C) 2008-2010 by Sanko Robinson <sanko@cpan.org>
@@ -34,26 +34,26 @@ package Net::BitTorrent::Protocol::BEP03::Metadata;
);
sub _trigger_metadata { # Subclasses should override this and call super
- my ($self, $new_value, $old_value) = @_;
- if (@_ == 2) { # parse trackers
- $self->tracker->add_tier([$new_value->{'announce'}])
- if $new_value->{'announce'};
- if (defined $new_value->{'announce-list'}) {
- $self->tracker->add_tier($_)
- for @{$new_value->{'announce-list'}};
- }
+ my ($s, $n, $o) = @_;
+ if (@_ == 2) {
- #
- if ($_[0]->metadata->{'info'}{'private'}) {
+ # May have changed
+ $s->tracker->_clear_tiers;
+ if ($s->metadata->{'info'}{'private'}) {
require Net::BitTorrent::Protocol::BEP27::Private::Metadata;
Net::BitTorrent::Protocol::BEP27::Private::Metadata->meta
- ->apply($_[0]);
+ ->apply($s);
}
- return 1;
+ }
+
+ # parse trackers
+ $s->tracker->add_tier([$n->{'announce'}]) if $n->{'announce'};
+ if (defined $n->{'announce-list'}) {
+ $s->tracker->add_tier($_) for @{$n->{'announce-list'}};
}
#warn 'Someone changed the metadata!';
- $self->_reset_info_hash;
+ $s->_reset_info_hash;
#my $info_hash = $self->info_hash;
#$self->_reset_info_hash;
@@ -88,7 +88,7 @@
Moose::Util::TypeConstraints::find_type_constraint(
'NBTypes::Torrent::Infohash');
$info_hash = $infohash_constraint->coerce($info_hash);
- $s->_set_support_extensions(ord(substr($reserved, 5, 1)) & 0x10);
+ $s->_set_support_extensions if (ord(substr($reserved, 5, 1)) & 0x10);
$s->_set_peer_id($peer_id);
my $t = $s->client->torrent($info_hash);
return
@@ -109,7 +109,7 @@
Moose::Util::TypeConstraints::find_type_constraint(
'NBTypes::Torrent::Infohash');
$info_hash = $infohash_constraint->coerce($info_hash);
- $s->_set_support_extensions(ord(substr($reserved, 5, 1)) & 0x10);
+ $s->_set_support_extensions if (ord(substr($reserved, 5, 1)) & 0x10);
$s->_set_peer_id($peer_id);
return $s->disconnect(
'Bad info_hash (Does not match the torrent we were seeking)')
@@ -14,12 +14,14 @@ package Net::BitTorrent::Protocol::BEP12::MultiTracker;
required => 1
);
has 'tiers' => (
- traits => ['Array'],
- isa => 'NBTypes::Tracker::Tier',
- is => 'rw',
- coerce => 1,
- default => sub { [] },
- handles => {_push_tier => 'push', _shuffle_tiers => 'shuffle'}
+ traits => ['Array'],
+ isa => 'ArrayRef[NBTypes::Tracker::Tier]',
+ is => 'rw',
+
+ #coerce => 1,
+ default => sub { [] },
+ clearer => '_clear_tiers',
+ handles => {_push_tier => 'push', _shuffle_tiers => 'shuffle'}
);
my $tier_constraint;

0 comments on commit d790265

Please sign in to comment.