| 108 | } |
| 109 | |
| 110 | function new_client(id, opt, cb) { |
| 111 | |
| 112 | // can't ask for id already is use |
| 113 | // TODO check this new id again |
| 114 | if (clients[id]) { |
| 115 | id = rand_id(); |
| 116 | } |
| 117 | |
| 118 | var popt = { |
| 119 | id: id, |
| 120 | max_tcp_sockets: opt.max_tcp_sockets |
| 121 | }; |
| 122 | |
| 123 | var client = Proxy(popt, function(err, info) { |
| 124 | if (err) { |
| 125 | return cb(err); |
| 126 | } |
| 127 | |
| 128 | ++stats.tunnels; |
| 129 | clients[id] = client; |
| 130 | |
| 131 | info.id = id; |
| 132 | |
| 133 | cb(err, info); |
| 134 | }); |
| 135 | |
| 136 | client.on('end', function() { |
| 137 | --stats.tunnels; |
| 138 | delete clients[id]; |
| 139 | }); |
| 140 | } |
| 141 | |
| 142 | module.exports = function(opt) { |
| 143 | opt = opt || {}; |