ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/DNS.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/DNS.pm (file contents):
Revision 1.22 by root, Sat May 24 02:06:43 2008 UTC vs.
Revision 1.24 by root, Sat May 24 02:50:45 2008 UTC

38C<$node> is either an IPv4 or IPv6 address or a hostname, C<$service> is 38C<$node> is either an IPv4 or IPv6 address or a hostname, C<$service> is
39either a service name (port name from F</etc/services>) or a numerical 39either a service name (port name from F</etc/services>) or a numerical
40port number. If both C<$node> and C<$service> are names, then SRV records 40port number. If both C<$node> and C<$service> are names, then SRV records
41will be consulted to find the real service, otherwise they will be 41will be consulted to find the real service, otherwise they will be
42used as-is. If you know that the service name is not in your services 42used as-is. If you know that the service name is not in your services
43database, then you cna specify the service in the format C<name=port> 43database, then you can specify the service in the format C<name=port>
44(e.g. C<http=80>). 44(e.g. C<http=80>).
45 45
46C<$proto> must be a protocol name, currently C<tcp>, C<udp> or 46C<$proto> must be a protocol name, currently C<tcp>, C<udp> or
47C<sctp>. The default is C<tcp>. 47C<sctp>. The default is C<tcp>.
48 48
49C<$family> must be either C<0> (meaning any protocol is ok), C<4> (use 49C<$family> must be either C<0> (meaning any protocol is OK), C<4> (use
50only IPv4) or C<6> (use only IPv6). This setting might be influenced by 50only IPv4) or C<6> (use only IPv6). This setting might be influenced by
51C<$ENV{PERL_ANYEVENT_PROTOCOLS}>. 51C<$ENV{PERL_ANYEVENT_PROTOCOLS}>.
52 52
53C<$type> must be C<SOCK_STREAM>, C<SOCK_DGRAM> or C<SOCK_SEQPACKET> (or 53C<$type> must be C<SOCK_STREAM>, C<SOCK_DGRAM> or C<SOCK_SEQPACKET> (or
54C<undef> in which case it gets automatically chosen). 54C<undef> in which case it gets automatically chosen).
87=item AnyEvent::DNS::srv $service, $proto, $domain, $cb->(@srv_rr) 87=item AnyEvent::DNS::srv $service, $proto, $domain, $cb->(@srv_rr)
88 88
89Tries to resolve the given service, protocol and domain name into a list 89Tries to resolve the given service, protocol and domain name into a list
90of service records. 90of service records.
91 91
92Each srv_rr is an arrayref with the following contents: 92Each srv_rr is an array reference with the following contents:
93C<[$priority, $weight, $transport, $target]>. 93C<[$priority, $weight, $transport, $target]>.
94 94
95They will be sorted with lowest priority, highest weight first (TODO: 95They will be sorted with lowest priority, highest weight first (TODO:
96should use the rfc algorithm to reorder same-priority records for weight). 96should use the RFC algorithm to reorder same-priority records for weight).
97 97
98Example: 98Example:
99 99
100 AnyEvent::DNS::srv "sip", "udp", "schmorp.de", sub { ... 100 AnyEvent::DNS::srv "sip", "udp", "schmorp.de", sub { ...
101 # @_ = ( [10, 10, 5060, "sip1.schmorp.de" ] ) 101 # @_ = ( [10, 10, 5060, "sip1.schmorp.de" ] )
283 $cv->end; 283 $cv->end;
284 }; 284 };
285 285
286 # try srv records, if applicable 286 # try srv records, if applicable
287 if ($node eq "localhost") { 287 if ($node eq "localhost") {
288 @target = ([v127.0.0.1, $port], [v0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1, $port]); 288 @target = (["127.0.0.1", $port], ["::1", $port]);
289 &$resolve;
289 } elsif (defined $service && !AnyEvent::Socket::parse_ip ($node)) { 290 } elsif (defined $service && !AnyEvent::Socket::parse_ip ($node)) {
290 srv $service, $proto, $node, sub { 291 srv $service, $proto, $node, sub {
291 my (@srv) = @_; 292 my (@srv) = @_;
292 293
293 # no srv records, continue traditionally 294 # no srv records, continue traditionally
319=over 4 320=over 4
320 321
321=item $AnyEvent::DNS::EDNS0 322=item $AnyEvent::DNS::EDNS0
322 323
323This variable decides whether dns_pack automatically enables EDNS0 324This variable decides whether dns_pack automatically enables EDNS0
324support. By default, this is disabled (C<0>), unless overriden by 325support. By default, this is disabled (C<0>), unless overridden by
325C<$ENV{PERL_ANYEVENT_EDNS0>), but when set to C<1>, AnyEvent::DNS will use 326C<$ENV{PERL_ANYEVENT_EDNS0>), but when set to C<1>, AnyEvent::DNS will use
326EDNS0 in all requests. 327EDNS0 in all requests.
327 328
328=cut 329=cut
329 330
693 694
694=over 4 695=over 4
695 696
696=item server => [...] 697=item server => [...]
697 698
698A list of server addressses (default: C<v127.0.0.1>) in network format (4 699A list of server addresses (default: C<v127.0.0.1>) in network format (4
699octets for IPv4, 16 octets for IPv6 - not yet supported). 700octets for IPv4, 16 octets for IPv6 - not yet supported).
700 701
701=item timeout => [...] 702=item timeout => [...]
702 703
703A list of timeouts to use (also determines the number of retries). To make 704A list of timeouts to use (also determines the number of retries). To make
714tries to resolve the name without any suffixes first. 715tries to resolve the name without any suffixes first.
715 716
716=item max_outstanding => $integer 717=item max_outstanding => $integer
717 718
718Most name servers do not handle many parallel requests very well. This option 719Most name servers do not handle many parallel requests very well. This option
719limits the numbe rof outstanding requests to C<$n> (default: C<10>), that means 720limits the number of outstanding requests to C<$n> (default: C<10>), that means
720if you request more than this many requests, then the additional requests will be queued 721if you request more than this many requests, then the additional requests will be queued
721until some other requests have been resolved. 722until some other requests have been resolved.
722 723
723=item reuse => $seconds 724=item reuse => $seconds
724 725
761 $self 762 $self
762} 763}
763 764
764=item $resolver->parse_resolv_conv ($string) 765=item $resolver->parse_resolv_conv ($string)
765 766
766Parses the given string a sif it were a F<resolv.conf> file. The following 767Parses the given string as if it were a F<resolv.conf> file. The following
767directives are supported (but not neecssarily implemented). 768directives are supported (but not necessarily implemented).
768 769
769C<#>-style comments, C<nameserver>, C<domain>, C<search>, C<sortlist>, 770C<#>-style comments, C<nameserver>, C<domain>, C<search>, C<sortlist>,
770C<options> (C<timeout>, C<attempts>, C<ndots>). 771C<options> (C<timeout>, C<attempts>, C<ndots>).
771 772
772Everything else is silently ignored. 773Everything else is silently ignored.
818 $self->_compile; 819 $self->_compile;
819} 820}
820 821
821=item $resolver->os_config 822=item $resolver->os_config
822 823
823Tries so load and parse F</etc/resolv.conf> on portable opertaing systems. Tries various 824Tries so load and parse F</etc/resolv.conf> on portable operating systems. Tries various
824egregious hacks on windows to force the dns servers and searchlist out of the config. 825egregious hacks on windows to force the DNS servers and searchlist out of the system.
825 826
826=cut 827=cut
827 828
828sub os_config { 829sub os_config {
829 my ($self) = @_; 830 my ($self) = @_;
998 while @{ $self->{reuse_q} } && $self->{reuse_q}[0][0] <= $NOW; 999 while @{ $self->{reuse_q} } && $self->{reuse_q}[0][0] <= $NOW;
999 1000
1000 while ($self->{outstanding} < $self->{max_outstanding}) { 1001 while ($self->{outstanding} < $self->{max_outstanding}) {
1001 1002
1002 if (@{ $self->{reuse_q} } >= 30000) { 1003 if (@{ $self->{reuse_q} } >= 30000) {
1003 warn "reusing id's, waiting ",$self->{reuse_q}[0][0] - $NOW;#d#
1004 # we ran out of ID's, wait a bit 1004 # we ran out of ID's, wait a bit
1005 $self->{reuse_to} ||= AnyEvent->timer (after => $self->{reuse_q}[0][0] - $NOW, cb => sub { 1005 $self->{reuse_to} ||= AnyEvent->timer (after => $self->{reuse_q}[0][0] - $NOW, cb => sub {
1006 delete $self->{reuse_to}; 1006 delete $self->{reuse_to};
1007 $self->_scheduler; 1007 $self->_scheduler;
1008 }); 1008 });
1049The callback will be invoked with a list of matching result records or 1049The callback will be invoked with a list of matching result records or
1050none on any error or if the name could not be found. 1050none on any error or if the name could not be found.
1051 1051
1052CNAME chains (although illegal) are followed up to a length of 8. 1052CNAME chains (although illegal) are followed up to a length of 8.
1053 1053
1054Note that this resolver is just a stub resolver: it requires a nameserver 1054Note that this resolver is just a stub resolver: it requires a name server
1055supporting recursive queries, will not do any recursive queries itself and 1055supporting recursive queries, will not do any recursive queries itself and
1056is not secure when used against an untrusted name server. 1056is not secure when used against an untrusted name server.
1057 1057
1058The following options are supported: 1058The following options are supported:
1059 1059

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines