private void onMsgKexInit(SshMsgKexInit msg) throws IOException {
    log.debug("Received remote key exchange init message");
    log.debug(msg.toString());

    synchronized (kexLock) {
      setRemoteKexInit(msg);

      // As either party can initiate a key exchange then we
      // must check to see if we have sent our own
      if (state.getValue() != TransportProtocolState.PERFORMING_KEYEXCHANGE) {
        // if (getLocalKexInit() == null) {
        sendKeyExchangeInit();
      }

      // }
      beginKeyExchange();
    }
  }
 /**
  * @return
  * @throws AlgorithmNotAgreedException
  */
 protected String getKexAlgorithm() throws AlgorithmNotAgreedException {
   return determineAlgorithm(clientKexInit.getSupportedKex(), serverKexInit.getSupportedKex());
 }