-
Notifications
You must be signed in to change notification settings - Fork 8
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
Socks proxy support #24
Comments
Not so sure about this, I'm really wary about adding things to a library that can easily be done outside. First of all, you avoid unnecessary dependencies that only a few people might actually use. And secondly, you don't have to handle all possible, weird edge cases (in your example, when the destination is the same as the proxy). Because if you do forget one case, the API consumer doesn't have a way of quickly fixing that without having to fork the package or submit a pull request, etc. However, I'm thinking about an implementation that allows you to just write some glue code and have the whole thing run over a custom stream. Then you could just do something like this: // The first argument is a function which returns a stream via Promise
// The second argument is a function that gets called on disconnect
const query = new TeamspeakQuery.Custom(async query => {
query.socks = await socks.createConnection({
destination: { host: '127.0.0.1', port: 10011 },
proxy: 'my.proxy.org:873'
}
query.socket = sock.socket;
return sock.socket;
}, query => {
query.socket.end();
}); I guess this is just a glorified way to extend the Base class, but it makes a lot simpler, in my opinion. What do you think? |
It'll be very nice if it is possible to achieve this without dependencies. As I noted earlier, I don't know much about networking. I tend to focus on stuff directly affecting other parts of my projects, while TS is the only case I need networking for :) Therefore I took a socks library (and yours too), thinking it handles all the pitfalls I don't know about. Yes, your suggestion is fine and I'd play with it as soon as it comes to life, but it does not avoid the need of socks library yet ;) |
I meant that it avoids the need to add a dependency to this library. |
So you're saying that |
No, no, I wasn't saying that it's already available. It was just a proposal. I'm just gonna go ahead and create something that you can try out :) |
Alright, so I implemented a first iteration as well as some helper methods, which might be useful for custom connections (4d2c3f4, ffef9a5). I will create a pre-release in the next few minutes and then you could use SOCKS like this: const socks = require("socks").SocksClient;
const TeamspeakQuery = require('teamspeak-query');
const query = new TeamspeakQuery.Custom(async (instance, callback) => {
instance.socks = await socks.createConnection({
destination: { host: '127.0.0.1', port: 10011 },
proxy: 'my.proxy.org:873'
}
// ready event does not fire with awaited socks, so we'll fire it manually
process.nextTick(() => {
if (sock.socket._events.ready)
sock.socket._events.ready();
});
const socket = instance.socks.socket;
callback(socket, socket);
}, instance => {
// Do any cleanup you might have to do for SOCKS
}); Off-Topic: If you wanna have some fun you can play teamspeak-server like this: const query = new TeamspeakQuery.Custom((inst, cb) => {
cb(process.stdin, process.stdout);
});
query.send('login', 'username', 'password')
.then(response => response.foo === 'bar' ? Promise.resolve() : Promise.reject('Oh no!'))
.catch(console.error); Everything you type into stdin will get processed as if it's coming from an actual server. user@device ~/D/p/teamspeak-query (master)> node example.js
login username password
foo=bar
error id=0
Oh yes!
^C⏎
user@device ~/D/p/teamspeak-query (master)> node example.js
login username password
foo=baz
error id=0
Oh no!
^C⏎
user@device ~/D/p/teamspeak-query (master)> I guess that this can be used for testing quite well. |
Alright, I created a pre-release. Install it via |
Hey, I don't mean to bother you, but did it work out fine? |
Sorry, I'm not always available - working on a number of projects doesn't help... From what you wrote so far, I'm excited to try this out and will definitely do as soon as I find the time in a few days, then write you back. Thanks! :) |
In my project, I need to hide server IP from users (they are able to register their own TS servers), so I ended up with this modification.
Would be nice to have it from a box :)
Same as Raw https://github.com/schroffl/teamspeak-query/blob/master/lib/raw.js but with socks proxy support (I bet it could be done better). Note an additional proxy argument on init.
Usage:
Docs for socks client: https://github.com/JoshGlazebrook/socks
Socks proxy server used for testing: https://github.com/z3APA3A/3proxy
The text was updated successfully, but these errors were encountered: