Skip to content

store data through connection#9

Open
vavrecan wants to merge 1 commit intomscdex:masterfrom
vavrecan:master
Open

store data through connection#9
vavrecan wants to merge 1 commit intomscdex:masterfrom
vavrecan:master

Conversation

@vavrecan
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Author

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

@alanhe421
Copy link
Copy Markdown

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