mirror of
https://github.com/moparisthebest/mail
synced 2024-11-22 00:42:20 -05:00
Merge pull request #250 from whiteout-io/dev/WO-765
[WO-765] do not multiplex sockets through single websocket
This commit is contained in:
commit
978822ae55
@ -61,16 +61,16 @@
|
||||
"grunt-string-replace": "~1.0.0",
|
||||
"grunt-svgmin": "~1.0.0",
|
||||
"grunt-svgstore": "~0.3.4",
|
||||
"imap-client": "~0.9.0",
|
||||
"imap-client": "~0.10.0",
|
||||
"jquery": "~2.1.1",
|
||||
"mailreader": "~0.4.0",
|
||||
"mocha": "^1.21.4",
|
||||
"ng-infinite-scroll": "~1.1.2",
|
||||
"pgpbuilder": "~0.5.0",
|
||||
"pgpmailer": "~0.7.0",
|
||||
"pgpmailer": "~0.8.0",
|
||||
"sinon": "~1.7.3",
|
||||
"tcp-socket": "~0.4.0",
|
||||
"tcp-socket": "~0.5.0",
|
||||
"time-grunt": "^1.0.0",
|
||||
"wo-smtpclient": "~0.5.0"
|
||||
"wo-smtpclient": "~0.6.0"
|
||||
}
|
||||
}
|
||||
|
57
server.js
57
server.js
@ -109,60 +109,50 @@ app.use(express.static(__dirname + '/dist'));
|
||||
// Socket.io proxy
|
||||
//
|
||||
|
||||
// TODO:test origin constraint
|
||||
//io.origins(config.server.inboundOrigins.join(' '));
|
||||
|
||||
io.on('connection', function(socket) {
|
||||
|
||||
log.info('io', 'New connection [%s]', socket.conn.id);
|
||||
|
||||
var idCounter = 0;
|
||||
log.info('io', 'New connection [%s] from %s', socket.conn.id, socket.conn.remoteAddress);
|
||||
|
||||
socket.on('open', function(data, fn) {
|
||||
var socketId = ++idCounter;
|
||||
var tcp;
|
||||
|
||||
if (!development && config.server.outboundPorts.indexOf(data.port) < 0) {
|
||||
log.warn('io', 'Open request to %s:%s was rejected, closing [%s:%s]', data.host, data.port, socket.conn.id, socketId);
|
||||
log.info('io', 'Open request to %s:%s was rejected, closing [%s]', data.host, data.port, socket.conn.id);
|
||||
socket.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
log.verbose('io', 'Open request to %s:%s [%s:%s]', data.host, data.port, socket.conn.id, socketId);
|
||||
|
||||
tcp = net.connect(data.port, data.host, function() {
|
||||
log.verbose('io', 'Opened tcp connection to %s:%s [%s:%s]', data.host, data.port, socket.conn.id, socketId);
|
||||
log.verbose('io', 'Open request to %s:%s [%s]', data.host, data.port, socket.conn.id);
|
||||
var tcp = net.connect(data.port, data.host, function() {
|
||||
log.verbose('io', 'Opened tcp connection to %s:%s [%s]', data.host, data.port, socket.conn.id);
|
||||
|
||||
tcp.on('data', function(chunk) {
|
||||
log.silly('io', 'Received %s bytes from %s:%s [%s:%s]', chunk.length, data.host, data.port, socket.conn.id, socketId);
|
||||
socket.emit('data-' + socketId, chunk);
|
||||
log.silly('io', 'Received %s bytes from %s:%s [%s]', chunk.length, data.host, data.port, socket.conn.id);
|
||||
socket.emit('data', chunk);
|
||||
});
|
||||
|
||||
tcp.on('error', function(err) {
|
||||
log.verbose('io', 'Error for %s:%s [%s:%s]: %s', data.host, data.port, socket.conn.id, socketId, err.message);
|
||||
socket.emit('error-' + socketId, err.message);
|
||||
log.verbose('io', 'Error for %s:%s [%s]: %s', data.host, data.port, socket.conn.id, err.message);
|
||||
socket.emit('error', err.message);
|
||||
});
|
||||
|
||||
tcp.on('end', function() {
|
||||
socket.emit('end-' + socketId);
|
||||
socket.emit('end');
|
||||
});
|
||||
|
||||
tcp.on('close', function() {
|
||||
log.verbose('io', 'Closed tcp connection to %s:%s [%s:%s]', data.host, data.port, socket.conn.id, socketId);
|
||||
socket.emit('close-' + socketId);
|
||||
log.verbose('io', 'Closed tcp connection to %s:%s [%s]', data.host, data.port, socket.conn.id);
|
||||
socket.emit('close');
|
||||
|
||||
socket.removeAllListeners('data-' + socketId);
|
||||
socket.removeAllListeners('end-' + socketId);
|
||||
socket.removeAllListeners('data');
|
||||
socket.removeAllListeners('end');
|
||||
});
|
||||
|
||||
socket.on('data-' + socketId, function(chunk, fn) {
|
||||
socket.on('data', function(chunk, fn) {
|
||||
if (!chunk || !chunk.length) {
|
||||
if (typeof fn === 'function') {
|
||||
fn();
|
||||
}
|
||||
return;
|
||||
}
|
||||
log.silly('io', 'Sending %s bytes to %s:%s [%s:%s]', chunk.length, data.host, data.port, socket.conn.id, socketId);
|
||||
log.silly('io', 'Sending %s bytes to %s:%s [%s]', chunk.length, data.host, data.port, socket.conn.id);
|
||||
tcp.write(chunk, function() {
|
||||
if (typeof fn === 'function') {
|
||||
fn();
|
||||
@ -170,24 +160,21 @@ io.on('connection', function(socket) {
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('end-' + socketId, function() {
|
||||
log.verbose('io', 'Received request to close connection to %s:%s [%s:%s]', data.host, data.port, socket.conn.id, socketId);
|
||||
socket.on('end', function() {
|
||||
log.verbose('io', 'Received request to close connection to %s:%s [%s]', data.host, data.port, socket.conn.id);
|
||||
tcp.end();
|
||||
});
|
||||
|
||||
if (typeof fn === 'function') {
|
||||
fn(socketId);
|
||||
fn(os.hostname());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
log.info('io', 'Closed connection [%s]', socket.conn.id);
|
||||
log.verbose('io', 'Closed connection [%s], closing connection to %s:%s ', socket.conn.id, data.host, data.port);
|
||||
tcp.end();
|
||||
socket.removeAllListeners();
|
||||
});
|
||||
|
||||
socket.on('hostname', function(fn) {
|
||||
fn(os.hostname());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user