@ -93,6 +93,13 @@ var Server = {
return srv . _ commandHandlers [ cmd [ 1 ] ] . apply ( null , cmd . slice ( 2 ) ) . then ( onSuccess , onError ) ;
}
, onconnection : function ( tun ) {
// I don't think this event can happen since this relay
// is acting the part of the client, but just in case...
// (in fact it should probably be explicitly disallowed)
console . error ( "[SANITY FAIL] reverse connection start" ) ;
}
, onmessage : function ( tun ) {
var cid = Packer . addrToId ( tun ) ;
if ( state . debug ) { console . log ( "remote '" + Server . logName ( state , srv ) + "' has data for '" + cid + "'" , tun . data . byteLength ) ; }
@ -231,7 +238,11 @@ var Server = {
Server . sendTunnelMsg ( srv , null , [ 1 , 'hello' , [ srv . unpacker . _ version ] , Object . keys ( srv . _ commandHandlers ) ] , 'control' ) ;
}
, sendTunnelMsg : function sendTunnelMsg ( srv , addr , data , service ) {
srv . ws . send ( Packer . pack ( addr , data , service ) , { binary : true } ) ;
if ( data && ! Buffer . isBuffer ( ) ) {
data = Buffer . from ( JSON . stringify ( data ) ) ;
}
srv . ws . send ( Packer . packHeader ( addr , data , service ) , { binary : true } ) ;
srv . ws . send ( data , { binary : true } ) ;
}
, logName : function logName ( state , srv ) {
var result = Object . keys ( srv . grants ) . map ( function ( jwtoken ) {
@ -379,7 +390,16 @@ var Server = {
return ;
}
conn . once ( 'data' , function ( firstChunk ) {
// When using raw TCP we're already paired to the client by port
// and we can begin connecting right away, but we'll wait just a sec
// to reject known bad connections
var sendConnection = setTimeout ( function ( ) {
conn . removeListener ( 'data' , peekFirstPacket )
console . log ( "[debug tcp conn] Connecting possible telnet client to device..." ) ;
pipeWs ( null , 'tcp' , nextDevice , conn , serviceport ) ;
} , 350 ) ;
function peekFirstPacket ( firstChunk ) {
clearTimeout ( sendConnection ) ;
if ( state . debug ) { console . log ( "[DynTcp]" , serviceport , "examining firstChunk from" , Packer . socketToId ( conn ) ) ; }
conn . pause ( ) ;
//conn.unshift(firstChunk);
@ -414,7 +434,8 @@ var Server = {
pipeWs ( null , 'tcp' , nextDevice , conn , serviceport ) ;
process . nextTick ( function ( ) { conn . resume ( ) ; } ) ;
} ) ;
}
conn . once ( 'data' , peekFirstPacket ) ;
}
, addToken : function addToken ( state , srv , newAuth ) {
console . log ( "addToken" , newAuth ) ;