store data through connection
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);
});
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
but if i pass intercept = true, proxySocket() will not get called - right?
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.