Skip to content

Commit

Permalink
GEODE-4084 rename handshake.proto (apache#1155)
Browse files Browse the repository at this point in the history
renamed to protocolVersion
  • Loading branch information
bschuchardt authored and galen-pivotal committed Dec 15, 2017
1 parent eff77bb commit 9ca4314
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ enum MinorVersions {
CURRENT_MINOR_VERSION = 1; // Protobuf implementation at initial release
}

message NewConnectionHandshake {
message NewConnectionClientVersion {
fixed32 majorVersion = 1;
fixed32 minorVersion = 2;
}

message HandshakeAcknowledgement {
message VersionAcknowledgement {
int32 serverMajorVersion = 1;
int32 serverMinorVersion = 2;
bool handshakePassed = 3;
bool versionAccepted = 3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.geode.internal.cache.client.protocol.ClientProtocolProcessor;
import org.apache.geode.internal.cache.tier.CommunicationMode;
import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.protobuf.Handshake;
import org.apache.geode.internal.protocol.protobuf.ProtocolVersion;
import org.apache.geode.internal.protocol.protobuf.v1.operations.VersionValidator;
import org.apache.geode.internal.protocol.state.ConnectionStateProcessor;
import org.apache.geode.internal.protocol.state.NoSecurityConnectionStateProcessor;
Expand Down Expand Up @@ -75,8 +75,8 @@ private void handleHandshakeMessage(InputStream inputStream) throws IOException
PushbackInputStream handshakeStream = new PushbackInputStream(inputStream);
handshakeStream.unread(CommunicationMode.ProtobufClientServerProtocol.getModeNumber());

Handshake.NewConnectionHandshake handshakeRequest =
Handshake.NewConnectionHandshake.parseDelimitedFrom(handshakeStream);
ProtocolVersion.NewConnectionClientVersion handshakeRequest =
ProtocolVersion.NewConnectionClientVersion.parseDelimitedFrom(handshakeStream);
int majorVersion = handshakeRequest.getMajorVersion();
int minorVersion = handshakeRequest.getMinorVersion();
if (!validator.isValid(majorVersion, minorVersion)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.apache.geode.distributed.internal.InternalLocator;
import org.apache.geode.internal.cache.client.protocol.ClientProtocolProcessor;
import org.apache.geode.internal.cache.client.protocol.ClientProtocolService;
import org.apache.geode.internal.protocol.protobuf.Handshake;
import org.apache.geode.internal.protocol.protobuf.ProtocolVersion;
import org.apache.geode.internal.protocol.protobuf.statistics.ProtobufClientStatisticsImpl;
import org.apache.geode.internal.protocol.statistics.NoOpStatistics;
import org.apache.geode.internal.protocol.statistics.ProtocolClientStatistics;
Expand Down Expand Up @@ -63,6 +63,6 @@ public ClientProtocolProcessor createProcessorForLocator(InternalLocator locator

@Override
public int getServiceProtocolVersion() {
return Handshake.MajorVersions.CURRENT_MAJOR_VERSION_VALUE;
return ProtocolVersion.MajorVersions.CURRENT_MAJOR_VERSION_VALUE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,35 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.apache.geode.internal.protocol.protobuf.Handshake;
import org.apache.geode.internal.protocol.protobuf.ProtocolVersion;
import org.apache.geode.internal.protocol.statistics.ProtocolClientStatistics;

public class HandshakeHandler {
public class ProtocolVersionHandler {
private static final Logger logger = LogManager.getLogger();
private static final VersionValidator validator = new VersionValidator();

public static boolean handleHandshake(InputStream inputStream, OutputStream outputStream,
public static boolean handleVersionMessage(InputStream inputStream, OutputStream outputStream,
ProtocolClientStatistics statistics) throws IOException {
Handshake.NewConnectionHandshake handshakeRequest =
Handshake.NewConnectionHandshake.parseDelimitedFrom(inputStream);
ProtocolVersion.NewConnectionClientVersion versionMessage =
ProtocolVersion.NewConnectionClientVersion.parseDelimitedFrom(inputStream);

statistics.messageReceived(handshakeRequest.getSerializedSize());
statistics.messageReceived(versionMessage.getSerializedSize());

final boolean handshakeSucceeded =
validator.isValid(handshakeRequest.getMajorVersion(), handshakeRequest.getMinorVersion());
final boolean versionAccepted =
validator.isValid(versionMessage.getMajorVersion(), versionMessage.getMinorVersion());

Handshake.HandshakeAcknowledgement handshakeResponse = Handshake.HandshakeAcknowledgement
.newBuilder().setServerMajorVersion(Handshake.MajorVersions.CURRENT_MAJOR_VERSION_VALUE)
.setServerMinorVersion(Handshake.MinorVersions.CURRENT_MINOR_VERSION_VALUE)
.setHandshakePassed(handshakeSucceeded).build();
ProtocolVersion.VersionAcknowledgement handshakeResponse =
ProtocolVersion.VersionAcknowledgement.newBuilder()
.setServerMajorVersion(ProtocolVersion.MajorVersions.CURRENT_MAJOR_VERSION_VALUE)
.setServerMinorVersion(ProtocolVersion.MinorVersions.CURRENT_MINOR_VERSION_VALUE)
.setVersionAccepted(versionAccepted).build();

handshakeResponse.writeDelimitedTo(outputStream);
statistics.messageSent(handshakeResponse.getSerializedSize());
if (!handshakeSucceeded) {
if (!versionAccepted) {
throw new IOException("Incompatible protobuf version.");
}

return handshakeSucceeded;
return versionAccepted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
*/
package org.apache.geode.internal.protocol.protobuf.v1.operations;

import org.apache.geode.internal.protocol.protobuf.Handshake;
import org.apache.geode.internal.protocol.protobuf.ProtocolVersion;

public class VersionValidator {
private int majorVersion;
private int minorVersion;

public VersionValidator() {
this(Handshake.MajorVersions.CURRENT_MAJOR_VERSION_VALUE,
Handshake.MinorVersions.CURRENT_MINOR_VERSION_VALUE);
this(ProtocolVersion.MajorVersions.CURRENT_MAJOR_VERSION_VALUE,
ProtocolVersion.MinorVersions.CURRENT_MINOR_VERSION_VALUE);
}

VersionValidator(int majorVersion, int minorVersion) {
Expand All @@ -31,9 +31,9 @@ public VersionValidator() {
}

public boolean isValid(int majorVersion, int minorVersion) {
if (majorVersion != Handshake.MajorVersions.INVALID_MAJOR_VERSION_VALUE
if (majorVersion != ProtocolVersion.MajorVersions.INVALID_MAJOR_VERSION_VALUE
&& majorVersion == this.majorVersion) {
if (minorVersion != Handshake.MinorVersions.INVALID_MINOR_VERSION_VALUE
if (minorVersion != ProtocolVersion.MinorVersions.INVALID_MINOR_VERSION_VALUE
&& minorVersion <= this.minorVersion) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.geode.internal.protocol.MessageExecutionContext;
import org.apache.geode.internal.protocol.OperationContext;
import org.apache.geode.internal.protocol.ProtocolErrorCode;
import org.apache.geode.internal.protocol.protobuf.v1.operations.HandshakeHandler;
import org.apache.geode.internal.protocol.protobuf.v1.operations.ProtocolVersionHandler;
import org.apache.geode.internal.protocol.state.ConnectionStateProcessor;
import org.apache.geode.internal.protocol.state.LegacySecurityConnectionStateProcessor;
import org.apache.geode.internal.protocol.state.NoSecurityConnectionStateProcessor;
Expand Down Expand Up @@ -64,7 +64,7 @@ public boolean handleMessageIndependently(InputStream inputStream, OutputStream
PushbackInputStream messageStream = new PushbackInputStream(inputStream);
messageStream.unread(CommunicationMode.ProtobufClientServerProtocol.getModeNumber());

if (HandshakeHandler.handleHandshake(messageStream, outputStream,
if (ProtocolVersionHandler.handleVersionMessage(messageStream, outputStream,
executionContext.getStatistics())) {
executionContext.setConnectionStateProcessor(nextConnectionState());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import com.google.protobuf.MessageLite;

import org.apache.geode.internal.protocol.protobuf.Handshake;
import org.apache.geode.internal.protocol.protobuf.ProtocolVersion;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufRequestUtilities;
import org.apache.geode.internal.protocol.protobuf.v1.utilities.ProtobufUtilities;
import org.apache.geode.internal.protocol.serialization.SerializationService;
Expand All @@ -38,15 +38,15 @@ public static void performAndVerifyHandshake(Socket socket) throws IOException {
}

public static void verifyHandshakeSuccess(Socket socket) throws IOException {
Handshake.HandshakeAcknowledgement handshakeResponse =
Handshake.HandshakeAcknowledgement.parseDelimitedFrom(socket.getInputStream());
assertTrue(handshakeResponse.getHandshakePassed());
ProtocolVersion.VersionAcknowledgement handshakeResponse =
ProtocolVersion.VersionAcknowledgement.parseDelimitedFrom(socket.getInputStream());
assertTrue(handshakeResponse.getVersionAccepted());
}

public static void sendHandshake(Socket socket) throws IOException {
Handshake.NewConnectionHandshake.newBuilder()
.setMajorVersion(Handshake.MajorVersions.CURRENT_MAJOR_VERSION_VALUE)
.setMinorVersion(Handshake.MinorVersions.CURRENT_MINOR_VERSION_VALUE).build()
ProtocolVersion.NewConnectionClientVersion.newBuilder()
.setMajorVersion(ProtocolVersion.MajorVersions.CURRENT_MAJOR_VERSION_VALUE)
.setMinorVersion(ProtocolVersion.MinorVersions.CURRENT_MINOR_VERSION_VALUE).build()
.writeDelimitedTo(socket.getOutputStream());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -41,15 +40,12 @@
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.distributed.ConfigurationProperties;
import org.apache.geode.internal.AvailablePortHelper;
import org.apache.geode.internal.cache.CacheServerImpl;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.tier.CommunicationMode;
import org.apache.geode.internal.protocol.protobuf.Handshake;
import org.apache.geode.internal.protocol.protobuf.ProtocolVersion;
import org.apache.geode.internal.protocol.protobuf.v1.serializer.ProtobufProtocolSerializer;
import org.apache.geode.test.junit.categories.IntegrationTest;

@Category(IntegrationTest.class)
public class HandshakeIntegrationTest {
public class ProtocolVersionIntegrationTest {
private Cache cache;

@Rule
Expand Down Expand Up @@ -104,13 +100,13 @@ public void testNormalHandshakeSucceeds() throws Exception {

@Test
public void testInvalidMajorVersionBreaksConnection() throws Exception {
Handshake.NewConnectionHandshake.newBuilder().setMajorVersion(2000)
.setMinorVersion(Handshake.MinorVersions.CURRENT_MINOR_VERSION_VALUE).build()
ProtocolVersion.NewConnectionClientVersion.newBuilder().setMajorVersion(2000)
.setMinorVersion(ProtocolVersion.MinorVersions.CURRENT_MINOR_VERSION_VALUE).build()
.writeDelimitedTo(socket.getOutputStream());

Handshake.HandshakeAcknowledgement handshakeResponse =
Handshake.HandshakeAcknowledgement.parseDelimitedFrom(socket.getInputStream());
assertFalse(handshakeResponse.getHandshakePassed());
ProtocolVersion.VersionAcknowledgement handshakeResponse =
ProtocolVersion.VersionAcknowledgement.parseDelimitedFrom(socket.getInputStream());
assertFalse(handshakeResponse.getVersionAccepted());

// Verify that connection is closed
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> {
Expand All @@ -129,9 +125,9 @@ public void testInvalidMajorVersionBreaksConnection() throws Exception {
*/
@Test
public void testMissingMajorVersionBreaksConnection() throws Exception {
Handshake.NewConnectionHandshake.newBuilder()
.setMajorVersion(Handshake.MajorVersions.CURRENT_MAJOR_VERSION_VALUE).setMinorVersion(0)
.build().writeDelimitedTo(socket.getOutputStream());
ProtocolVersion.NewConnectionClientVersion.newBuilder()
.setMajorVersion(ProtocolVersion.MajorVersions.CURRENT_MAJOR_VERSION_VALUE)
.setMinorVersion(0).build().writeDelimitedTo(socket.getOutputStream());

// Verify that connection is closed
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> {
Expand Down

This file was deleted.

Loading

0 comments on commit 9ca4314

Please sign in to comment.