Skip to content
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

store data through connection #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

store data through connection #9

wants to merge 1 commit into from

Conversation

vavrecan
Copy link

I would like to implement bandwidth monitoring as well as request log.
I need to have some object where I can store current user between different events.
How would you suggest to do it? I think passing socket object to connection event is not best idea - should I create custom extra-data object?

Here is the sample of what I am trying to do:

var socks = require('socksv5');

var srv = socks.createServer(function(info, accept, deny, socket) {
  accept();

  // log request
  console.log(socket.authUser + " requested: ");
  console.log(info);
});

srv.listen(1080, '0.0.0.0', function() {
  console.log('SOCKS server listening on port 1080');
});

srv.useAuth(socks.auth.UserPassword(function(user, password, cb, socket) {
  cb(user === 'user' && password === 'xxx');
  socket.authUser = "user"; // save user in the socket object
}));

srv.on("clientClose", function(socket) {
  console.log("Client");
  console.log("user:" + socket.authUser); // get user from socket object

  // collect data transferred to specific user
  console.log("read:" + socket.bytesRead);
  console.log("written:" + socket.bytesWritten);
}); 

@mscdex
Copy link
Owner

mscdex commented Aug 11, 2015

Well, you can already get at the socket object via the intercept method, that would take care of all but the auth part. I guess I could just call the auth callbacks with this === socket... shrug

@vavrecan
Copy link
Author

but if i pass intercept = true, proxySocket() will not get called - right?

@alanhe421
Copy link

Well, you can already get at the socket object via the intercept method, that would take care of all but the auth part. I guess I could just call the auth callbacks with this === socket... shrug

Can you give an example?

I have the same need, I need to get the user information after socks authentication in socks.createServer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants