Skip to content

Commit

Permalink
anti none ext-hub sourced connection for proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
kaven276 committed Sep 28, 2012
1 parent 733c431 commit d5113e3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
51 changes: 36 additions & 15 deletions lib/dco_proxy.js
Expand Up @@ -56,22 +56,43 @@ utl.gracefulExit(function(){
exports.createServer = function(handler){ exports.createServer = function(handler){
var server = net.createServer(function(extHubSock){ var server = net.createServer(function(extHubSock){
console.log('connect from ext_hub'); console.log('connect from ext_hub');
extHubSocks.push(extHubSock);
(function(extHubID){ extHubSock.once('data', function onHandshake(data){
extHubSock.on('close', function(){
console.log('ext-hub(%d) will not send new request, in-bound socket half closed', extHubID); try {
delete extHubSocks[extHubID - 1]; var ptoken = data.readInt32BE(0);
}); } catch (e) {
})(extHubSocks.length); ptoken = -1;
new StreamSpliter(extHubSock, 'readInt32BE', onRequest);
function onRequest(pdu){
counter.start();
if (pdu.readInt32BE(0) > 0) {
handler(new Request(pdu, true), new Response(extHubSock, pdu.readUInt16BE(4)));
} else {
handler(new Request(pdu, false), new DummyResponse());
} }
} if (ptoken !== 197610263) {
console.warn('none ext-hub connection to out proxy attempt found');
extHubSock.end();
extHubSock.destroy();
return;
}

extHubSocks.push(extHubSock);
(function(extHubID){
extHubSock.on('close', function(){
console.log('ext-hub(%d) will not send new request, in-bound socket half closed', extHubID);
delete extHubSocks[extHubID - 1];
});
})(extHubSocks.length);
new StreamSpliter(extHubSock, 'readInt32BE', onRequest);
function onRequest(pdu){
counter.start();
if (pdu.readInt32BE(0) > 0) {
handler(new Request(pdu, true), new Response(extHubSock, pdu.readUInt16BE(4)));
} else {
handler(new Request(pdu, false), new DummyResponse());
}
}

if (data.length !== 4) {
logConnOra('first chunk is not 4 bytes length.');
oraSock.emit('data', data.slice(4));
}
});
}); });
return new DcoWorkerProxy(server); return new DcoWorkerProxy(server);
}; };
Expand Down
3 changes: 3 additions & 0 deletions lib/ext_hub.js
Expand Up @@ -162,6 +162,9 @@ function WPWrapper(wpSock, id, hostp, maxPendingRpc, desc){


wpSock.on('connect', function(){ wpSock.on('connect', function(){
wpw.setStatus('opened', 'TCP socket connected'); wpw.setStatus('opened', 'TCP socket connected');
var ptoken = new Buffer(4);
ptoken.writeInt32BE(197610263, 0);
wpSock.write(ptoken);
logConnWP('Connect to proxy NO.%d(%s) is ok', wpw.id, wpw.desc); logConnWP('Connect to proxy NO.%d(%s) is ok', wpw.id, wpw.desc);
wpw.queue.forEach(function(PDU){ wpw.queue.forEach(function(PDU){
wpSock.write(PDU); wpSock.write(PDU);
Expand Down

0 comments on commit d5113e3

Please sign in to comment.