geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/HandShake.java
private byte write(DataOutputStream dos, DataInputStream dis, CommunicationMode communicationMode,
      int replyCode, int readTimeout, List ports, Properties p_credentials,
      DistributedMember member, boolean isCallbackConnection) throws IOException {
    HeapDataOutputStream hdos = new HeapDataOutputStream(32, Version.CURRENT);
    byte acceptanceCode = -1;
    try {
      hdos.writeByte(communicationMode.getModeNumber());
      if (overrideClientVersion > 0) {
        // for testing
        Version.writeOrdinal(hdos, overrideClientVersion, true);
      } else {
        Version.writeOrdinal(hdos, currentClientVersion.ordinal(), true);
      }

      hdos.writeByte(replyCode);
      if (ports != null) {
        hdos.writeInt(ports.size());
        for (int i = 0; i < ports.size(); i++) {
          hdos.writeInt(Integer.parseInt((String) ports.get(i)));
        }
      } else {
        hdos.writeInt(readTimeout);
      }
      // we do not know the receiver's version at this point, but the on-wire
      // form of InternalDistributedMember changed in 9.0, so we must serialize
      // it using the previous version
      DataOutput idOut = new VersionedDataOutputStream(hdos, Version.GFE_82);
      DataSerializer.writeObject(this.id, idOut);

      if (currentClientVersion.compareTo(Version.GFE_603) >= 0) {
        for (int bytes = 0; bytes < this.overrides.length; bytes++) {
          hdos.writeByte(this.overrides[bytes]);
        }
      } else {
        // write the client conflation setting byte
        if (setClientConflationForTesting) {
          hdos.writeByte(clientConflationForTesting);
        } else {
          hdos.writeByte(this.clientConflation);
        }
      }

      if (isCallbackConnection || communicationMode.isWAN()) {
        if (isCallbackConnection && this.multiuserSecureMode && !communicationMode.isWAN()) {
          hdos.writeByte(SECURITY_MULTIUSER_NOTIFICATIONCHANNEL);
          hdos.flush();
          dos.write(hdos.toByteArray());
          dos.flush();
        } else {
          writeCredentials(dos, dis, p_credentials, ports != null, member, hdos);
        }
      } else {
        String authInitMethod = this.system.getProperties().getProperty(SECURITY_CLIENT_AUTH_INIT);
        acceptanceCode = writeCredential(dos, dis, authInitMethod, ports != null, member, hdos);
      }
    } finally {
      hdos.close();
    }
    return acceptanceCode;
  }
/**
   * client-to-server handshake. Nothing is sent to the server prior to invoking this method.
   */
client-to-server handshake. Nothing is sent to the server prior to invoking this method.
client - to - server handshake . Nothing is sent to the server prior to invoking this method .
private byte write(DataOutputStream dos, DataInputStream dis, CommunicationMode communicationMode,
      int replyCode, int readTimeout, List ports, Properties p_credentials,
      DistributedMember member, boolean isCallbackConnection) throws IOException {
    HeapDataOutputStream hdos = new HeapDataOutputStream(32, Version.CURRENT);
    byte acceptanceCode = -1;
    try {
      hdos.writeByte(communicationMode.getModeNumber());
      if (overrideClientVersion > 0) {
        Version.writeOrdinal(hdos, overrideClientVersion, true);
      } else {
        Version.writeOrdinal(hdos, currentClientVersion.ordinal(), true);
      }
      hdos.writeByte(replyCode);
      if (ports != null) {
        hdos.writeInt(ports.size());
        for (int i = 0; i < ports.size(); i++) {
          hdos.writeInt(Integer.parseInt((String) ports.get(i)));
        }
      } else {
        hdos.writeInt(readTimeout);
      }
      DataOutput idOut = new VersionedDataOutputStream(hdos, Version.GFE_82);
      DataSerializer.writeObject(this.id, idOut);
      if (currentClientVersion.compareTo(Version.GFE_603) >= 0) {
        for (int bytes = 0; bytes < this.overrides.length; bytes++) {
          hdos.writeByte(this.overrides[bytes]);
        }
      } else {
        if (setClientConflationForTesting) {
          hdos.writeByte(clientConflationForTesting);
        } else {
          hdos.writeByte(this.clientConflation);
        }
      }
      if (isCallbackConnection || communicationMode.isWAN()) {
        if (isCallbackConnection && this.multiuserSecureMode && !communicationMode.isWAN()) {
          hdos.writeByte(SECURITY_MULTIUSER_NOTIFICATIONCHANNEL);
          hdos.flush();
          dos.write(hdos.toByteArray());
          dos.flush();
        } else {
          writeCredentials(dos, dis, p_credentials, ports != null, member, hdos);
        }
      } else {
        String authInitMethod = this.system.getProperties().getProperty(SECURITY_CLIENT_AUTH_INIT);
        acceptanceCode = writeCredential(dos, dis, authInitMethod, ports != null, member, hdos);
      }
    } finally {
      hdos.close();
    }
    return acceptanceCode;
  }
private byte write ( DataOutputStream dos , DataInputStream dis , CommunicationMode communicationMode , int replyCode , int readTimeout , List ports , Properties p_credentials , DistributedMember member , boolean isCallbackConnection ) throws IOException { HeapDataOutputStream hdos = new HeapDataOutputStream ( 32 , Version . CURRENT ) ; byte acceptanceCode = - 1 ; try { hdos . writeByte ( communicationMode . getModeNumber ( ) ) ; if ( overrideClientVersion > 0 ) { Version . writeOrdinal ( hdos , overrideClientVersion , true ) ; } else { Version . writeOrdinal ( hdos , currentClientVersion . ordinal ( ) , true ) ; } hdos . writeByte ( replyCode ) ; if ( ports != null ) { hdos . writeInt ( ports . size ( ) ) ; for ( int i = 0 ; i < ports . size ( ) ; i ++ ) { hdos . writeInt ( Integer . parseInt ( ( String ) ports . get ( i ) ) ) ; } } else { hdos . writeInt ( readTimeout ) ; } DataOutput idOut = new VersionedDataOutputStream ( hdos , Version . GFE_82 ) ; DataSerializer . writeObject ( this . id , idOut ) ; if ( currentClientVersion . compareTo ( Version . GFE_603 ) >= 0 ) { for ( int bytes = 0 ; bytes < this . overrides . length ; bytes ++ ) { hdos . writeByte ( this . overrides [ bytes ] ) ; } } else { if ( setClientConflationForTesting ) { hdos . writeByte ( clientConflationForTesting ) ; } else { hdos . writeByte ( this . clientConflation ) ; } } if ( isCallbackConnection || communicationMode . isWAN ( ) ) { if ( isCallbackConnection && this . multiuserSecureMode && ! communicationMode . isWAN ( ) ) { hdos . writeByte ( SECURITY_MULTIUSER_NOTIFICATIONCHANNEL ) ; hdos . flush ( ) ; dos . write ( hdos . toByteArray ( ) ) ; dos . flush ( ) ; } else { writeCredentials ( dos , dis , p_credentials , ports != null , member , hdos ) ; } } else { String authInitMethod = this . system . getProperties ( ) . getProperty ( SECURITY_CLIENT_AUTH_INIT ) ; acceptanceCode = writeCredential ( dos , dis , authInitMethod , ports != null , member , hdos ) ; } } finally { hdos . close ( ) ; } return acceptanceCode ; }
client-to-server handshake.
client - to - server handshake .
// for testing // we do not know the receiver's version at this point, but the on-wire // form of InternalDistributedMember changed in 9.0, so we must serialize // it using the previous version // write the client conflation setting byte