line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::DNS::Cache::Simple; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
2375
|
use 5.008005; |
|
4
|
|
|
|
|
32
|
|
4
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
99
|
|
5
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
130
|
|
6
|
4
|
|
|
4
|
|
22
|
use base qw/AnyEvent::DNS/; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
2436
|
|
7
|
4
|
|
|
4
|
|
141892
|
use Cache::Memory::Simple; |
|
4
|
|
|
|
|
10412
|
|
|
4
|
|
|
|
|
132
|
|
8
|
4
|
|
|
4
|
|
28
|
use List::Util qw//; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
61
|
|
9
|
4
|
|
|
4
|
|
21
|
use Time::HiRes qw//; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1777
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub request($$) { |
14
|
4
|
|
|
4
|
1
|
2849
|
my ($self, $req, $cb) = @_; |
15
|
4
|
|
|
|
|
11
|
my ($name, $qtype, $class) = @{$req->{qd}[0]}; |
|
4
|
|
|
|
|
13
|
|
16
|
4
|
|
|
|
|
15
|
my $cache_key = "$class $qtype $name"; #compatibility with Net::DNS::Lite |
17
|
4
|
100
|
|
|
|
17
|
if ( my $cached = $self->{adcs_cache}->get($cache_key) ) { |
18
|
2
|
|
|
|
|
42
|
my ($res,$expires_at) = @$cached; |
19
|
2
|
50
|
|
|
|
7
|
if ( $expires_at < Time::HiRes::time ) { |
20
|
0
|
|
|
|
|
0
|
undef $res; |
21
|
0
|
|
|
|
|
0
|
$self->{adcs_cache}->remove($cache_key) |
22
|
|
|
|
|
|
|
} |
23
|
2
|
50
|
|
|
|
6
|
if ( !defined $res ) { |
24
|
0
|
|
|
|
|
0
|
$cb->(); |
25
|
0
|
|
|
|
|
0
|
return; |
26
|
|
|
|
|
|
|
} |
27
|
2
|
|
|
|
|
6
|
return $cb->($res); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# request |
31
|
|
|
|
|
|
|
$self->SUPER::request($req, sub { |
32
|
2
|
|
|
2
|
|
2011917
|
my ($res) = @_; |
33
|
2
|
100
|
|
|
|
12
|
if ( !@_ ) { |
34
|
1
|
|
|
|
|
20
|
$self->{adcs_cache}->set($cache_key, [undef, $self->{adcs_negative_ttl} + Time::HiRes::time() ], $self->{adcs_negative_ttl}); |
35
|
1
|
|
|
|
|
16
|
return $cb->(); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
my $ttl = List::Util::min( |
38
|
|
|
|
|
|
|
$self->{adcs_ttl}, |
39
|
|
|
|
|
|
|
map { |
40
|
1
|
|
|
|
|
6
|
$_->[3] |
41
|
1
|
50
|
|
|
|
3
|
} (@{$res->{an}} ? @{$res->{an}} : @{$res->{ns}}), |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
3
|
|
|
0
|
|
|
|
|
0
|
|
42
|
|
|
|
|
|
|
); |
43
|
1
|
|
|
|
|
31
|
$self->{adcs_cache}->set($cache_key, [$res, $ttl + Time::HiRes::time ], $ttl); |
44
|
1
|
|
|
|
|
14
|
$cb->($res); |
45
|
2
|
|
|
|
|
52
|
}); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub register { |
49
|
2
|
|
|
2
|
1
|
26636
|
my $class = shift; |
50
|
2
|
50
|
|
|
|
16
|
my %args = @_ == 1 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
51
|
2
|
50
|
|
|
|
8
|
my $ttl = exists $args{ttl} ? delete $args{ttl} : 5; |
52
|
2
|
50
|
|
|
|
7
|
my $negative_ttl = exists $args{negative_ttl} ? delete $args{negative_ttl} : 1; |
53
|
2
|
100
|
|
|
|
14
|
my $cache = exists $args{cache} ? delete $args{cache} : Cache::Memory::Simple->new; |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
13
|
my $old = $AnyEvent::DNS::RESOLVER; |
56
|
2
|
|
|
|
|
4
|
$AnyEvent::DNS::RESOLVER = do { |
57
|
4
|
|
|
4
|
|
32
|
no warnings 'uninitialized'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
749
|
|
58
|
|
|
|
|
|
|
my $resolver = AnyEvent::DNS::Cache::Simple->new( |
59
|
|
|
|
|
|
|
untaint => 1, |
60
|
2
|
|
50
|
|
|
41
|
max_outstanding => $ENV{PERL_ANYEVENT_MAX_OUTSTANDING_DNS}*1 || 1, |
61
|
|
|
|
|
|
|
adcs_ttl => $ttl, |
62
|
|
|
|
|
|
|
adcs_negative_ttl => $negative_ttl, |
63
|
|
|
|
|
|
|
adcs_cache => $cache, |
64
|
|
|
|
|
|
|
%args |
65
|
|
|
|
|
|
|
); |
66
|
2
|
100
|
|
|
|
9714
|
if ( !$args{server} ) { |
67
|
|
|
|
|
|
|
$ENV{PERL_ANYEVENT_RESOLV_CONF} |
68
|
|
|
|
|
|
|
? $resolver->_load_resolv_conf_file ($ENV{PERL_ANYEVENT_RESOLV_CONF}) |
69
|
1
|
50
|
|
|
|
9
|
: $resolver->os_config; |
70
|
|
|
|
|
|
|
} |
71
|
2
|
|
|
|
|
3111
|
$resolver; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
AnyEvent::Util::guard { |
74
|
2
|
|
|
2
|
|
3420
|
$AnyEvent::DNS::RESOLVER = $old; |
75
|
2
|
|
|
|
|
51
|
}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
__END__ |