Skip Menu |

This queue is for tickets about the Net-Async-SOCKS CPAN distribution.

Report information
The Basics
Id: 124746
Status: new
Priority: 0/
Queue: Net-Async-SOCKS

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.002
Fixed in: (no value)



Subject: Various fixes: FQDN, preëxisting 'handle'
The attached patch fixes the following issues: * Deconfigure $stream's on_read after setup * Slightly neater sequencing; always remember to $loop->remove($stream) even after failure * Only add/remove $stream to loop if we constructed it; stream given by 'handle' argument should already be a member * Use ATYPE_FQDN except for hostnames that look a bit like IPv4 addresses (see also RT124730) With these in place, a small additional patch to Net::Async::HTTP allows the latter to use NaSOCKS as a proxy. -- Paul Evans
Subject: rt.patch
=== modified file 'lib/Net/Async/SOCKS.pm' --- lib/Net/Async/SOCKS.pm 2018-03-09 19:07:50 +0000 +++ lib/Net/Async/SOCKS.pm 2018-03-09 19:17:32 +0000 @@ -77,6 +77,10 @@ my $stream = delete $params{handle} || IO::Async::Stream->new; + # If 'handle' is already given then it will already be a member of the + # Loop + my $must_add = not defined $stream->loop; + $stream->isa( "IO::Async::Stream" ) or croak "Can only SOCKS_connect a handle instance of IO::Async::Stream"; @@ -122,7 +126,7 @@ } } ); - $loop->add($stream); + $loop->add($stream) if $must_add; # Version and auth header goes first $stream->write($proto->init_packet); @@ -134,18 +138,19 @@ # process. $proto->auth( )->then(sub { + my $host = $params{host}; + $proto->connect( - ATYPE_IPV4, - $params{host}, + $host =~ m/^\d{1,3}(\.\d{1,3}){3}+$/ ? ATYPE_IPV4 : ATYPE_FQDN, + $host, $params{service}, - )->transform( - done => sub { - $loop->remove($stream); - $stream - } - ) + ); }) - }); + })->on_ready(sub { + $loop->remove($stream) if $must_add; + $stream->configure(on_read => undef); + })->then_done($stream); + $f->on_done($on_done) if $on_done; $f->on_fail(sub { $on_socks_error->($_[0]) if defined $_[1] and $_[1] eq "socks";
On Fri Mar 09 14:21:58 2018, PEVANS wrote: Show quoted text
> * Use ATYPE_FQDN except for hostnames that look a bit like IPv4 > addresses (see also RT124730)
Oops; that had a typo. - $host =~ m/^\d{1,3}(\.\d{1,3}){3}+$/ ? ATYPE_IPV4 : ATYPE_FQDN, + $host =~ m/^\d{1,3}(\.\d{1,3}){3}$/ ? ATYPE_IPV4 : ATYPE_FQDN, -- Paul Evans
On Fri Mar 09 14:21:58 2018, PEVANS wrote: Show quoted text
> * Only add/remove $stream to loop if we constructed it; stream given > by 'handle' argument should already be a member
Ugh :( Moreover the exact API required for ->connect is that its future returns the original stream handle if "handle" was provided, or the plain underlying socket filedescriptor itself, if it wasn't. I'm not sure I like this interface shape any more, but in any case IO::Async::SSL 's connect extension relies on that, so without this additional change, you can't nest SSL within SOCKS. -- Paul Evans
Subject: return-raw-sock.patch
=== modified file 'examples/socks-connect.pl' --- examples/socks-connect.pl 2018-03-09 19:07:50 +0000 +++ examples/socks-connect.pl 2018-03-09 19:56:58 +0000 @@ -7,6 +7,8 @@ my $loop = IO::Async::Loop->new; $loop->connect( + handle => IO::Async::Stream->new, + extensions => [qw(SOCKS)], SOCKS_host => 'localhost', SOCKS_port => '9020', === modified file 'lib/Net/Async/SOCKS.pm' --- lib/Net/Async/SOCKS.pm 2018-03-09 19:27:05 +0000 +++ lib/Net/Async/SOCKS.pm 2018-03-09 19:56:58 +0000 @@ -75,7 +75,8 @@ my $on_socks_error = delete $params{on_socks_error} or defined wantarray or croak "Expected 'on_socks_error' or to return a Future"; - my $stream = delete $params{handle} || IO::Async::Stream->new; + my $orig_stream = delete $params{handle}; + my $stream = $orig_stream || IO::Async::Stream->new; # If 'handle' is already given then it will already be a member of the # Loop @@ -145,11 +146,11 @@ $host, $params{service}, ); - }) + })->then_done($orig_stream // $sock); })->on_ready(sub { $loop->remove($stream) if $must_add; $stream->configure(on_read => undef); - })->then_done($stream); + }); $f->on_done($on_done) if $on_done; $f->on_fail(sub {