Permalink
Browse files

anti none ext-hub sourced connection for proxy

  • Loading branch information...
1 parent 733c431 commit d5113e380006334980e83c780178f7cb4a644d32 @kaven276 committed Sep 28, 2012
Showing with 39 additions and 15 deletions.
  1. +36 −15 lib/dco_proxy.js
  2. +3 −0 lib/ext_hub.js
View
@@ -56,22 +56,43 @@ utl.gracefulExit(function(){
exports.createServer = function(handler){
var server = net.createServer(function(extHubSock){
console.log('connect from ext_hub');
- 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());
+
+ extHubSock.once('data', function onHandshake(data){
+
+ try {
+ var ptoken = data.readInt32BE(0);
+ } catch (e) {
+ ptoken = -1;
}
- }
+ 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);
};
View
@@ -162,6 +162,9 @@ function WPWrapper(wpSock, id, hostp, maxPendingRpc, desc){
wpSock.on('connect', function(){
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);
wpw.queue.forEach(function(PDU){
wpSock.write(PDU);

0 comments on commit d5113e3

Please sign in to comment.