Skip to content

S2A not available on platforms which netty-tcnative doesn't support #12151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions s2a/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,11 @@ dependencies {
classifier = "linux-aarch_64"
}
}
testRuntimeOnly (libraries.netty.tcnative) {
artifact {
classifier = "osx-x86_64"
}
}
testRuntimeOnly (libraries.netty.tcnative) {
artifact {
classifier = "osx-aarch_64"
}
}
testRuntimeOnly (libraries.netty.tcnative) {
artifact {
classifier = "windows-x86_64"
}
}

signature (libraries.signature.java) {
artifact {
Expand Down
17 changes: 17 additions & 0 deletions s2a/src/main/java/io/grpc/s2a/S2AChannelCredentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -52,6 +53,7 @@ public final class S2AChannelCredentials {
public static Builder newBuilder(String s2aAddress, ChannelCredentials s2aChannelCredentials) {
checkArgument(!isNullOrEmpty(s2aAddress), "S2A address must not be null or empty.");
checkNotNull(s2aChannelCredentials, "S2A channel credentials must not be null");
checkState(isPlatformSupported(), "S2A is not suported on Windows or MacOS Intel");
return new Builder(s2aAddress, s2aChannelCredentials);
}

Expand Down Expand Up @@ -131,5 +133,20 @@ InternalProtocolNegotiator.ClientFactory buildProtocolNegotiatorFactory() {
}
}

/**
* S2A has a runtime dependency on netty-tcnative. This function returns true
* if netty-tcnative is supported on the current platform.
*
* @return whether S2A is supported on current platform
*/
private static boolean isPlatformSupported() {
if (System.getProperty("os.name").contains("Windows")
|| (System.getProperty("os.name").contains("OS X")
&& System.getProperty("os.arch").contains("x86_64"))) {
return false;
}
return true;
}

private S2AChannelCredentials() {}
}