-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add socks proxy #255
add socks proxy #255
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... I understand that this would allow you to use a Socks proxy on a per connection basis? Could you please provide a minimalistic demo plugin (could be outside this PR) and/or some instructions how to use this?
Overall I'm ok with the minimalist approach of this change. I think it's very well isolated.
Slim/Networking/Async/HTTP.pm
Outdated
@@ -43,6 +43,7 @@ use URI; | |||
use File::Spec::Functions qw(catdir); | |||
|
|||
use Slim::Networking::Async::Socket::HTTP; | |||
use Slim::Networking::Async::Socket::HTTPsocks; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this is the most nitpicky detail I could find: I'd use HTTPSocks
😁.
Another small change: could please not use
this module, but require
it only when needed? Eg. inside the elsif ($self->socksAddr) ...
conditional code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hesitating on that (HTTPSocks), but I'll do as you say. I'll move to a require as well
Slim/Networking/Async/HTTP.pm
Outdated
sub new { | ||
my ($class, $args) = @_; | ||
my $self = $class->SUPER::new; | ||
$self->socksAddr( $args->{socksAddr} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to add some input value validation? Throw an error if socksAddr
wasn't an IP or at least reasonable string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into that, I'm not very good at these this but I'll find some examples
Slim/Networking/Async/HTTP.pm
Outdated
my %args = @_; | ||
main::DEBUGLOG && $log->debug("Using SOCKS proxy", $self->socksAddr, ":", $self->socksAddr); | ||
# socks negotiation needs to be blocking or it terminates immediately on timeout | ||
my $sock Slim::Networking::Async::Socket::HTTPsocks->new( @_, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this missing the =
sign for the assignment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shame on me for bad process
|
||
use strict; | ||
|
||
use base qw(IO::Socket::Socks Net::HTTP::Methods Slim::Networking::Async::Socket); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is IO::Socket::Socks
pure Perl? Could you please include it in the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is pure Perl, no headache with compilation. I'll add it
One other thing - we should wait for the accepting the pull request, but I wanted to know before it you would accept the idea of the changes |
I think I’ll finish the changes during the weekend. Do you prefer a clean new pull request or do you want me to continue with this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes. Most importantly don't try to load HTTPSSocks
if IO::Socket::SSL
wasn't available.
As for the PR: with a relatively small change like this I'd prefer to have a small change set without all the minor commits. Instead of creating a new branch and PR you could git rebase --interactively
your work to squash everything in to one or two commits, then git push --force
back to your origin. This would update this PR. Just one more way to do this :-).
Slim/Networking/Async/HTTP.pm
Outdated
|
||
if ($self->socksAddr) { | ||
require Slim::Networking::Async::Socket::HTTPSocks; | ||
require Slim::Networking::Async::Socket::HTTPSSocks; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please only load if hasSSL()
. There still are systems without IO::Socket::SSL
which would crash LMS here.
Slim/Networking/Async/HTTP.pm
Outdated
if ($self->socksAddr) { | ||
require Slim::Networking::Async::Socket::HTTPSocks; | ||
require Slim::Networking::Async::Socket::HTTPSSocks; | ||
%socks = ( ProxyAddr => $self->socksAddr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whitespace terror! Please use tabs for main indentation of the code, but spaces to align stuff in a block...
Slim/Networking/Async/HTTP.pm
Outdated
|
||
if (%socks) { | ||
$sock = Slim::Networking::Async::Socket::HTTPSSocks->new( %args, %socks ); | ||
$sock->blocking(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this line be in ->new()
? This would avoid having to remember to call it after each instantiation.
All done what you've requested (I think) |
I've also created the following README
|
Where would you put that README? In a file's header? Or a separate file? |
I've been back & forth on the idea of making SOCKS configuration settings a general LMS item and I finally decided it's a bad idea. The objective is for plugins to be able to leverage the newt HTTPSocks and HTTPSSocks classes and use socks to improve reachability, but in fact every plugin should be able to decide what SOCKS server it wants, it cannot be a global parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this is looking good to me. See my comments for minor questions/issues.
@@ -166,8 +206,9 @@ sub send_request { | |||
$self->request->protocol( 'HTTP/1.0' ); | |||
} | |||
|
|||
# the used class is NET::HTTP::Method which now supports HTTP 1.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by "now supports 1.1"? That module is shipped with LMS. Would that support it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the module shipped with LMS supports 1.1, AFAIK
Slim/Utils/Misc.pm
Outdated
@@ -1435,6 +1436,28 @@ sub min { | |||
return $m; | |||
} | |||
|
|||
=head2 obfuscate ( ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can remove these, as we're not storing any credentials?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of keeping them here as a general services (I use it in my plugins) and maybe if we can think of a better way to implement that in the future, that would a good thing to have a centralized service
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just don't like to keep code around which is not being used by LMS itself. It risks to be ripped out as "unused" at some point...
At least call it deobfuscate
, and add a note that these are there as a service for plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it really bothers you, I can remove it and duplicate it in the plugins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
grammar! bad process cleaning cleaning cleaning adding SSL through SOCKS as well cleaning socks4 by default, error management, put HTTPSSocks at the right place add SOCKS5 authentication better reuse IO::Socket::Socks + add obf/unobf remove obfuscate function set HTTP 1.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready to merge?
If you are 👍 (cross fingers) |
Thanks! |
(scary - you you I have the habbit to propose crap paches ...) |
This is just a proposal at this moment to add socks proxy to Async::HTTP connection and SimpleAsyncHTTP. I've tried to make as little change as possible and make sure they have no side effect.
The only caveat so far is that the socks negotiation has to be in blocking mode (as I think the SSL is) but after that all read/write are set back to non-blocking. The IO::Socket::Socks package must be added and is not in the pull request
I think using socks can be useful because it allows to create tunnel per each HTTP request, and not have to VPN all or nothing. I understand this can be seen as specific to my plugins, but I've tried to make that generic in hope that it could be beneficial for others
NB: whatever you decide, my plugins ave overloaded version of the above class, so that still works. It's just not very elegant of me to replace part of these packages system-wide