… | |
… | |
38 | C<$node> is either an IPv4 or IPv6 address or a hostname, C<$service> is |
38 | C<$node> is either an IPv4 or IPv6 address or a hostname, C<$service> is |
39 | either a service name (port name from F</etc/services>) or a numerical |
39 | either a service name (port name from F</etc/services>) or a numerical |
40 | port number. If both C<$node> and C<$service> are names, then SRV records |
40 | port number. If both C<$node> and C<$service> are names, then SRV records |
41 | will be consulted to find the real service, otherwise they will be |
41 | will be consulted to find the real service, otherwise they will be |
42 | used as-is. If you know that the service name is not in your services |
42 | used as-is. If you know that the service name is not in your services |
43 | database, then you cna specify the service in the format C<name=port> |
43 | database, 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 | |
46 | C<$proto> must be a protocol name, currently C<tcp>, C<udp> or |
46 | C<$proto> must be a protocol name, currently C<tcp>, C<udp> or |
47 | C<sctp>. The default is C<tcp>. |
47 | C<sctp>. The default is C<tcp>. |
48 | |
48 | |
49 | C<$family> must be either C<0> (meaning any protocol is ok), C<4> (use |
49 | C<$family> must be either C<0> (meaning any protocol is OK), C<4> (use |
50 | only IPv4) or C<6> (use only IPv6). This setting might be influenced by |
50 | only IPv4) or C<6> (use only IPv6). This setting might be influenced by |
51 | C<$ENV{PERL_ANYEVENT_PROTOCOLS}>. |
51 | C<$ENV{PERL_ANYEVENT_PROTOCOLS}>. |
52 | |
52 | |
53 | C<$type> must be C<SOCK_STREAM>, C<SOCK_DGRAM> or C<SOCK_SEQPACKET> (or |
53 | C<$type> must be C<SOCK_STREAM>, C<SOCK_DGRAM> or C<SOCK_SEQPACKET> (or |
54 | C<undef> in which case it gets automatically chosen). |
54 | C<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 | |
89 | Tries to resolve the given service, protocol and domain name into a list |
89 | Tries to resolve the given service, protocol and domain name into a list |
90 | of service records. |
90 | of service records. |
91 | |
91 | |
92 | Each srv_rr is an arrayref with the following contents: |
92 | Each srv_rr is an array reference with the following contents: |
93 | C<[$priority, $weight, $transport, $target]>. |
93 | C<[$priority, $weight, $transport, $target]>. |
94 | |
94 | |
95 | They will be sorted with lowest priority, highest weight first (TODO: |
95 | They will be sorted with lowest priority, highest weight first (TODO: |
96 | should use the rfc algorithm to reorder same-priority records for weight). |
96 | should use the RFC algorithm to reorder same-priority records for weight). |
97 | |
97 | |
98 | Example: |
98 | Example: |
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 | |
323 | This variable decides whether dns_pack automatically enables EDNS0 |
324 | This variable decides whether dns_pack automatically enables EDNS0 |
324 | support. By default, this is disabled (C<0>), unless overriden by |
325 | support. By default, this is disabled (C<0>), unless overridden by |
325 | C<$ENV{PERL_ANYEVENT_EDNS0>), but when set to C<1>, AnyEvent::DNS will use |
326 | C<$ENV{PERL_ANYEVENT_EDNS0>), but when set to C<1>, AnyEvent::DNS will use |
326 | EDNS0 in all requests. |
327 | EDNS0 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 | |
698 | A list of server addressses (default: C<v127.0.0.1>) in network format (4 |
699 | A list of server addresses (default: C<v127.0.0.1>) in network format (4 |
699 | octets for IPv4, 16 octets for IPv6 - not yet supported). |
700 | octets for IPv4, 16 octets for IPv6 - not yet supported). |
700 | |
701 | |
701 | =item timeout => [...] |
702 | =item timeout => [...] |
702 | |
703 | |
703 | A list of timeouts to use (also determines the number of retries). To make |
704 | A list of timeouts to use (also determines the number of retries). To make |
… | |
… | |
714 | tries to resolve the name without any suffixes first. |
715 | tries to resolve the name without any suffixes first. |
715 | |
716 | |
716 | =item max_outstanding => $integer |
717 | =item max_outstanding => $integer |
717 | |
718 | |
718 | Most name servers do not handle many parallel requests very well. This option |
719 | Most name servers do not handle many parallel requests very well. This option |
719 | limits the numbe rof outstanding requests to C<$n> (default: C<10>), that means |
720 | limits the number of outstanding requests to C<$n> (default: C<10>), that means |
720 | if you request more than this many requests, then the additional requests will be queued |
721 | if you request more than this many requests, then the additional requests will be queued |
721 | until some other requests have been resolved. |
722 | until 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 | |
766 | Parses the given string a sif it were a F<resolv.conf> file. The following |
767 | Parses the given string as if it were a F<resolv.conf> file. The following |
767 | directives are supported (but not neecssarily implemented). |
768 | directives are supported (but not necessarily implemented). |
768 | |
769 | |
769 | C<#>-style comments, C<nameserver>, C<domain>, C<search>, C<sortlist>, |
770 | C<#>-style comments, C<nameserver>, C<domain>, C<search>, C<sortlist>, |
770 | C<options> (C<timeout>, C<attempts>, C<ndots>). |
771 | C<options> (C<timeout>, C<attempts>, C<ndots>). |
771 | |
772 | |
772 | Everything else is silently ignored. |
773 | Everything 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 | |
823 | Tries so load and parse F</etc/resolv.conf> on portable opertaing systems. Tries various |
824 | Tries so load and parse F</etc/resolv.conf> on portable operating systems. Tries various |
824 | egregious hacks on windows to force the dns servers and searchlist out of the config. |
825 | egregious hacks on windows to force the DNS servers and searchlist out of the system. |
825 | |
826 | |
826 | =cut |
827 | =cut |
827 | |
828 | |
828 | sub os_config { |
829 | sub 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 | }); |
… | |
… | |
1049 | The callback will be invoked with a list of matching result records or |
1049 | The callback will be invoked with a list of matching result records or |
1050 | none on any error or if the name could not be found. |
1050 | none on any error or if the name could not be found. |
1051 | |
1051 | |
1052 | CNAME chains (although illegal) are followed up to a length of 8. |
1052 | CNAME chains (although illegal) are followed up to a length of 8. |
1053 | |
1053 | |
1054 | Note that this resolver is just a stub resolver: it requires a nameserver |
1054 | Note that this resolver is just a stub resolver: it requires a name server |
1055 | supporting recursive queries, will not do any recursive queries itself and |
1055 | supporting recursive queries, will not do any recursive queries itself and |
1056 | is not secure when used against an untrusted name server. |
1056 | is not secure when used against an untrusted name server. |
1057 | |
1057 | |
1058 | The following options are supported: |
1058 | The following options are supported: |
1059 | |
1059 | |