mirror of
https://github.com/moparisthebest/mail
synced 2024-11-25 02:12:17 -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-string-replace": "~1.0.0",
|
||||||
"grunt-svgmin": "~1.0.0",
|
"grunt-svgmin": "~1.0.0",
|
||||||
"grunt-svgstore": "~0.3.4",
|
"grunt-svgstore": "~0.3.4",
|
||||||
"imap-client": "~0.9.0",
|
"imap-client": "~0.10.0",
|
||||||
"jquery": "~2.1.1",
|
"jquery": "~2.1.1",
|
||||||
"mailreader": "~0.4.0",
|
"mailreader": "~0.4.0",
|
||||||
"mocha": "^1.21.4",
|
"mocha": "^1.21.4",
|
||||||
"ng-infinite-scroll": "~1.1.2",
|
"ng-infinite-scroll": "~1.1.2",
|
||||||
"pgpbuilder": "~0.5.0",
|
"pgpbuilder": "~0.5.0",
|
||||||
"pgpmailer": "~0.7.0",
|
"pgpmailer": "~0.8.0",
|
||||||
"sinon": "~1.7.3",
|
"sinon": "~1.7.3",
|
||||||
"tcp-socket": "~0.4.0",
|
"tcp-socket": "~0.5.0",
|
||||||
"time-grunt": "^1.0.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
|
// Socket.io proxy
|
||||||
//
|
//
|
||||||
|
|
||||||
// TODO:test origin constraint
|
|
||||||
//io.origins(config.server.inboundOrigins.join(' '));
|
|
||||||
|
|
||||||
io.on('connection', function(socket) {
|
io.on('connection', function(socket) {
|
||||||
|
log.info('io', 'New connection [%s] from %s', socket.conn.id, socket.conn.remoteAddress);
|
||||||
log.info('io', 'New connection [%s]', socket.conn.id);
|
|
||||||
|
|
||||||
var idCounter = 0;
|
|
||||||
|
|
||||||
socket.on('open', function(data, fn) {
|
socket.on('open', function(data, fn) {
|
||||||
var socketId = ++idCounter;
|
|
||||||
var tcp;
|
|
||||||
|
|
||||||
if (!development && config.server.outboundPorts.indexOf(data.port) < 0) {
|
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();
|
socket.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.verbose('io', 'Open request 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() {
|
||||||
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);
|
||||||
log.verbose('io', 'Opened tcp connection to %s:%s [%s:%s]', data.host, data.port, socket.conn.id, socketId);
|
|
||||||
|
|
||||||
tcp.on('data', function(chunk) {
|
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);
|
log.silly('io', 'Received %s bytes from %s:%s [%s]', chunk.length, data.host, data.port, socket.conn.id);
|
||||||
socket.emit('data-' + socketId, chunk);
|
socket.emit('data', chunk);
|
||||||
});
|
});
|
||||||
|
|
||||||
tcp.on('error', function(err) {
|
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);
|
log.verbose('io', 'Error for %s:%s [%s]: %s', data.host, data.port, socket.conn.id, err.message);
|
||||||
socket.emit('error-' + socketId, err.message);
|
socket.emit('error', err.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
tcp.on('end', function() {
|
tcp.on('end', function() {
|
||||||
socket.emit('end-' + socketId);
|
socket.emit('end');
|
||||||
});
|
});
|
||||||
|
|
||||||
tcp.on('close', function() {
|
tcp.on('close', function() {
|
||||||
log.verbose('io', 'Closed tcp connection to %s:%s [%s:%s]', data.host, data.port, socket.conn.id, socketId);
|
log.verbose('io', 'Closed tcp connection to %s:%s [%s]', data.host, data.port, socket.conn.id);
|
||||||
socket.emit('close-' + socketId);
|
socket.emit('close');
|
||||||
|
|
||||||
socket.removeAllListeners('data-' + socketId);
|
socket.removeAllListeners('data');
|
||||||
socket.removeAllListeners('end-' + socketId);
|
socket.removeAllListeners('end');
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('data-' + socketId, function(chunk, fn) {
|
socket.on('data', function(chunk, fn) {
|
||||||
if (!chunk || !chunk.length) {
|
if (!chunk || !chunk.length) {
|
||||||
if (typeof fn === 'function') {
|
if (typeof fn === 'function') {
|
||||||
fn();
|
fn();
|
||||||
}
|
}
|
||||||
return;
|
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() {
|
tcp.write(chunk, function() {
|
||||||
if (typeof fn === 'function') {
|
if (typeof fn === 'function') {
|
||||||
fn();
|
fn();
|
||||||
@ -170,24 +160,21 @@ io.on('connection', function(socket) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('end-' + socketId, function() {
|
socket.on('end', function() {
|
||||||
log.verbose('io', 'Received request to close connection to %s:%s [%s:%s]', data.host, data.port, socket.conn.id, socketId);
|
log.verbose('io', 'Received request to close connection to %s:%s [%s]', data.host, data.port, socket.conn.id);
|
||||||
tcp.end();
|
tcp.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof fn === 'function') {
|
if (typeof fn === 'function') {
|
||||||
fn(socketId);
|
fn(os.hostname());
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('disconnect', function() {
|
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.removeAllListeners();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
socket.on('hostname', function(fn) {
|
|
||||||
fn(os.hostname());
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user