use of org.apache.geode.internal.VersionedDataInputStream in project geode by apache.
the class TcpClient method getServerVersion.
private Short getServerVersion(InetSocketAddress ipAddr, int timeout) throws IOException, ClassNotFoundException {
int gossipVersion = TcpServer.getCurrentGossipVersion();
Short serverVersion = null;
// Get GemFire version of TcpServer first, before sending any other request.
synchronized (serverVersions) {
serverVersion = serverVersions.get(ipAddr);
}
if (serverVersion != null) {
return serverVersion;
}
gossipVersion = TcpServer.getOldGossipVersion();
Socket sock = null;
try {
sock = socketCreator.connect(ipAddr.getAddress(), ipAddr.getPort(), timeout, null, false);
sock.setSoTimeout(timeout);
} catch (SSLException e) {
throw new LocatorCancelException("Unable to form SSL connection", e);
}
try {
DataOutputStream out = new DataOutputStream(sock.getOutputStream());
out = new VersionedDataOutputStream(out, Version.GFE_57);
out.writeInt(gossipVersion);
VersionRequest verRequest = new VersionRequest();
DataSerializer.writeObject(verRequest, out);
out.flush();
InputStream inputStream = sock.getInputStream();
DataInputStream in = new DataInputStream(inputStream);
in = new VersionedDataInputStream(in, Version.GFE_57);
try {
Object readObject = DataSerializer.readObject(in);
if (!(readObject instanceof VersionResponse)) {
throw new LocatorCancelException("Unrecognisable response received: object is null. This could be the result of trying to connect a non-SSL-enabled locator to an SSL-enabled locator.");
}
VersionResponse response = (VersionResponse) readObject;
if (response != null) {
serverVersion = Short.valueOf(response.getVersionOrdinal());
synchronized (serverVersions) {
serverVersions.put(ipAddr, serverVersion);
}
return serverVersion;
}
} catch (EOFException ex) {
// old locators will not recognize the version request and will close the connection
}
} finally {
try {
// initiate an abort on close to shut down the server's socket
sock.setSoLinger(true, 0);
sock.close();
} catch (Exception e) {
logger.error("Error closing socket ", e);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Locator " + ipAddr + " did not respond to a request for its version. I will assume it is using v5.7 for safety.");
}
synchronized (serverVersions) {
serverVersions.put(ipAddr, Version.GFE_57.ordinal());
}
return Short.valueOf(Version.GFE_57.ordinal());
}
use of org.apache.geode.internal.VersionedDataInputStream in project geode by apache.
the class CacheClientNotifier method registerClient.
/**
* Registers a new client updater that wants to receive updates with this server.
*
* @param socket The socket over which the server communicates with the client.
*/
public void registerClient(Socket socket, boolean isPrimary, long acceptorId, boolean notifyBySubscription) throws IOException {
// Since no remote ports were specified in the message, wait for them.
long startTime = this.statistics.startTime();
DataInputStream dis = new DataInputStream(socket.getInputStream());
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
// Read the client version
short clientVersionOrdinal = Version.readOrdinal(dis);
Version clientVersion = null;
try {
clientVersion = Version.fromOrdinal(clientVersionOrdinal, true);
if (logger.isDebugEnabled()) {
logger.debug("{}: Registering client with version: {}", this, clientVersion);
}
} catch (UnsupportedVersionException e) {
SocketAddress sa = socket.getRemoteSocketAddress();
UnsupportedVersionException uve = e;
if (sa != null) {
String sInfo = " Client: " + sa.toString() + ".";
uve = new UnsupportedVersionException(e.getMessage() + sInfo);
}
logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientNotifier_CACHECLIENTNOTIFIER_CAUGHT_EXCEPTION_ATTEMPTING_TO_CLIENT), uve);
writeException(dos, Acceptor.UNSUCCESSFUL_SERVER_TO_CLIENT, uve, clientVersion);
return;
}
// Read and ignore the reply code. This is used on the client to server
// handshake.
// replyCode
dis.readByte();
if (Version.GFE_57.compareTo(clientVersion) <= 0) {
if (Version.CURRENT.compareTo(clientVersion) > 0) {
dis = new VersionedDataInputStream(dis, clientVersion);
dos = new VersionedDataOutputStream(dos, clientVersion);
}
registerGFEClient(dis, dos, socket, isPrimary, startTime, clientVersion, acceptorId, notifyBySubscription);
} else {
Exception e = new UnsupportedVersionException(clientVersionOrdinal);
throw new IOException(e.toString());
}
}
use of org.apache.geode.internal.VersionedDataInputStream in project geode by apache.
the class HandShake method handshakeWithServer.
/**
* Client-side handshake with a Server
*/
public ServerQueueStatus handshakeWithServer(Connection conn, ServerLocation location, byte communicationMode) throws IOException, AuthenticationRequiredException, AuthenticationFailedException, ServerRefusedConnectionException {
try {
ServerQueueStatus serverQStatus = null;
Socket sock = conn.getSocket();
DataOutputStream dos = new DataOutputStream(sock.getOutputStream());
final InputStream in = sock.getInputStream();
DataInputStream dis = new DataInputStream(in);
DistributedMember member = getIDForSocket(sock);
// if running in a loner system, use the new port number in the ID to
// help differentiate from other clients
DM dm = ((InternalDistributedSystem) this.system).getDistributionManager();
InternalDistributedMember idm = dm.getDistributionManagerId();
synchronized (idm) {
if (idm.getPort() == 0 && dm instanceof LonerDistributionManager) {
int port = sock.getLocalPort();
((LonerDistributionManager) dm).updateLonerPort(port);
updateProxyID(dm.getDistributionManagerId());
}
}
if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY) {
this.credentials = getCredentials(member);
}
byte intermediateAcceptanceCode = write(dos, dis, communicationMode, REPLY_OK, this.clientReadTimeout, null, this.credentials, member, false);
String authInit = this.system.getProperties().getProperty(SECURITY_CLIENT_AUTH_INIT);
if (communicationMode != Acceptor.GATEWAY_TO_GATEWAY && intermediateAcceptanceCode != REPLY_AUTH_NOT_REQUIRED && (authInit != null && authInit.length() != 0)) {
location.compareAndSetRequiresCredentials(true);
}
// Read the acceptance code
byte acceptanceCode = dis.readByte();
if (acceptanceCode == (byte) 21 && !(sock instanceof SSLSocket)) {
// SSL
throw new AuthenticationRequiredException(LocalizedStrings.HandShake_SERVER_EXPECTING_SSL_CONNECTION.toLocalizedString());
}
if (acceptanceCode == REPLY_SERVER_IS_LOCATOR) {
throw new GemFireConfigException("Improperly configured client detected. " + "Server at " + location + " is actually a locator. Use addPoolLocator to configure locators.");
}
// Successful handshake for GATEWAY_TO_GATEWAY mode sets the peer version in connection
if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && !(acceptanceCode == REPLY_EXCEPTION_AUTHENTICATION_REQUIRED || acceptanceCode == REPLY_EXCEPTION_AUTHENTICATION_FAILED)) {
short wanSiteVersion = Version.readOrdinal(dis);
conn.setWanSiteVersion(wanSiteVersion);
// establish a versioned stream for the other site, if necessary
if (wanSiteVersion < Version.CURRENT_ORDINAL) {
dis = new VersionedDataInputStream(dis, Version.fromOrdinalOrCurrent(wanSiteVersion));
}
}
// No need to check for return value since DataInputStream already throws
// EOFException in case of EOF
byte epType = dis.readByte();
int qSize = dis.readInt();
// Read the server member
member = readServerMember(dis);
serverQStatus = new ServerQueueStatus(epType, qSize, member);
// Read the message (if any)
readMessage(dis, dos, acceptanceCode, member);
// DSes with different values of this. It shoule be a member variable.
if (communicationMode != Acceptor.GATEWAY_TO_GATEWAY && currentClientVersion.compareTo(Version.GFE_61) >= 0) {
deltaEnabledOnServer = dis.readBoolean();
}
// validate that the remote side has a different distributed system id.
if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && Version.GFE_66.compareTo(conn.getWanSiteVersion()) <= 0 && currentClientVersion.compareTo(Version.GFE_66) >= 0) {
int remoteDistributedSystemId = in.read();
int localDistributedSystemId = ((InternalDistributedSystem) system).getDistributionManager().getDistributedSystemId();
if (localDistributedSystemId >= 0 && localDistributedSystemId == remoteDistributedSystemId) {
throw new GatewayConfigurationException("Remote WAN site's distributed system id " + remoteDistributedSystemId + " matches this sites distributed system id " + localDistributedSystemId);
}
}
// Read the PDX registry size from the remote size
if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && Version.GFE_80.compareTo(conn.getWanSiteVersion()) <= 0 && currentClientVersion.compareTo(Version.GFE_80) >= 0) {
int remotePdxSize = dis.readInt();
serverQStatus.setPdxSize(remotePdxSize);
}
return serverQStatus;
} catch (IOException ex) {
CancelCriterion stopper = this.system.getCancelCriterion();
stopper.checkCancelInProgress(null);
throw ex;
}
}
use of org.apache.geode.internal.VersionedDataInputStream in project geode by apache.
the class HandShake method readServerMember.
protected DistributedMember readServerMember(DataInputStream p_dis) throws IOException {
byte[] memberBytes = DataSerializer.readByteArray(p_dis);
ByteArrayInputStream bais = new ByteArrayInputStream(memberBytes);
DataInputStream dis = new DataInputStream(bais);
Version v = InternalDataSerializer.getVersionForDataStreamOrNull(p_dis);
if (v != null) {
dis = new VersionedDataInputStream(dis, v);
}
try {
return DataSerializer.readObject(dis);
} catch (EOFException e) {
throw e;
} catch (Exception e) {
throw new InternalGemFireException(LocalizedStrings.HandShake_UNABLE_TO_DESERIALIZE_MEMBER.toLocalizedString(), e);
}
}
use of org.apache.geode.internal.VersionedDataInputStream in project geode by apache.
the class OldClientSupportDUnitTest method testConversionOfArrayTypes.
@Test
public void testConversionOfArrayTypes() throws Exception {
OldClientSupportService oldClientSupport = OldClientSupportProvider.getService(myCache);
Version oldClientVersion = Version.GFE_82;
VersionedDataOutputStream dout = new VersionedDataOutputStream(new HeapDataOutputStream(10, oldClientVersion), oldClientVersion);
for (String geodeClassName : newArrayClassNames) {
String newName = oldClientSupport.processOutgoingClassName(geodeClassName, dout);
Assert.assertNotEquals(geodeClassName, newName);
}
for (String className : allNonconformingArrayClassNames) {
String newName = oldClientSupport.processOutgoingClassName(className, dout);
Assert.assertEquals(className, newName);
}
VersionedDataInputStream din = new VersionedDataInputStream(new DataInputStream(new ByteArrayInputStream(new byte[10])), oldClientVersion);
for (String oldClassName : oldArrayClassNames) {
String newName = oldClientSupport.processIncomingClassName(oldClassName, din);
Assert.assertNotEquals(oldClassName, newName);
}
}
Aggregations