public boolean processMessage ( byte [ ] msg ) throws SshException { try { if ( msg . length < 1 ) { disconnect ( TransportProtocol . PROTOCOL_ERROR , "Invalid message received" ) ; throw new SshException ( "Invalid transport protocol message" , SshException . INTERNAL_ERROR ) ; } switch ( msg [ 0 ] ) { case SSH_MSG_DISCONNECT : { if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Received SSH_MSG_DISCONNECT" ) ; } internalDisconnect ( ) ; ByteArrayReader bar = new ByteArrayReader ( msg , 5 , msg . length - 5 ) ; try { EventServiceImplementation . getInstance ( ) . fireEvent ( new Event ( this , J2SSHEventCodes . EVENT_RECEIVED_DISCONNECT , true ) ) ; throw new SshException ( bar . readString ( ) , SshException . REMOTE_HOST_DISCONNECTED ) ; } finally { bar . close ( ) ; } } case SSH_MSG_IGNORE : { if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Received SSH_MSG_IGNORE" ) ; } return true ; } case SSH_MSG_DEBUG : { lastActivity = System . currentTimeMillis ( ) ; if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Received SSH_MSG_DEBUG" ) ; } return true ; } case SSH_MSG_NEWKEYS : { lastActivity = System . currentTimeMillis ( ) ; if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Received SSH_MSG_NEWKEYS" ) ; } return true ; } case SSH_MSG_KEX_INIT : { lastActivity = System . currentTimeMillis ( ) ; if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Received SSH_MSG_KEX_INIT" ) ; } if ( remotekex != null ) { disconnect ( TransportProtocol . PROTOCOL_ERROR , "Key exchange already in progress!" ) ; throw new SshException ( "Key exchange already in progress!" , SshException . PROTOCOL_VIOLATION ) ; } performKeyExchange ( msg ) ; return true ; } default : { lastActivity = System . currentTimeMillis ( ) ; // Not a transport protocol message return false ; } } } catch ( IOException ex1 ) { throw new SshException ( ex1 . getMessage ( ) , SshException . INTERNAL_ERROR ) ; } }
Process a message . This should be called when reading messages from outside of the transport protocol so that the transport protocol can parse its own messages .