-
Notifications
You must be signed in to change notification settings - Fork 80
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
Change the default Deephaven java client TLS port to 443 #2066
Merged
devinrsmith
merged 1 commit into
deephaven:main
from
devinrsmith:java-client-default-tls-443
Mar 10, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 19 additions & 23 deletions
42
java-client/session/src/main/java/io/deephaven/client/impl/ChannelHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,33 @@ | ||
package io.deephaven.client.impl; | ||
|
||
import io.deephaven.uri.DeephavenTarget; | ||
import io.grpc.ManagedChannel; | ||
import io.grpc.ChannelCredentials; | ||
import io.grpc.Grpc; | ||
import io.grpc.InsecureChannelCredentials; | ||
import io.grpc.ManagedChannelBuilder; | ||
import io.grpc.TlsChannelCredentials; | ||
|
||
public class ChannelHelper { | ||
public final class ChannelHelper { | ||
|
||
public static final int DEFAULT_TLS_PORT = 8080; | ||
public static final int DEFAULT_TLS_PORT = 443; | ||
|
||
public static final int DEFAULT_PLAINTEXT_PORT = 8080; | ||
|
||
public static ManagedChannel channel(DeephavenTarget target) { | ||
return channelBuilder(target).build(); | ||
} | ||
public static final int DEFAULT_PLAINTEXT_PORT = 10000; | ||
|
||
/** | ||
* Creates a basic {@link ManagedChannelBuilder} by invoking | ||
* {@link Grpc#newChannelBuilder(String, ChannelCredentials)} with {@link DeephavenTarget#toString()} and the | ||
* appropriate {@link io.grpc.CallCredentials}. | ||
* | ||
* @param target the Deephaven target | ||
* @return the channel builder | ||
*/ | ||
public static ManagedChannelBuilder<?> channelBuilder(DeephavenTarget target) { | ||
final ManagedChannelBuilder<?> builder = ManagedChannelBuilder.forAddress(target.host(), port(target)); | ||
final ChannelCredentials credentials; | ||
if (target.isSecure()) { | ||
builder.useTransportSecurity(); | ||
credentials = TlsChannelCredentials.newBuilder().build(); | ||
} else { | ||
builder.usePlaintext(); | ||
} | ||
return builder; | ||
} | ||
|
||
public static int port(DeephavenTarget target) { | ||
if (target.port().isPresent()) { | ||
return target.port().getAsInt(); | ||
} | ||
// TODO(deephaven-core#1489): Support service discovery for DeephavenTarget | ||
if (target.isSecure()) { | ||
return Integer.getInteger("deephaven.target.port", DEFAULT_TLS_PORT); | ||
credentials = InsecureChannelCredentials.create(); | ||
} | ||
return Integer.getInteger("deephaven.target.plaintext_port", DEFAULT_PLAINTEXT_PORT); | ||
return Grpc.newChannelBuilder(target.toString(), credentials); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
.../session/src/main/java/io/deephaven/client/impl/DeephavenTargetNameResolverProviders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package io.deephaven.client.impl; | ||
|
||
import com.google.auto.service.AutoService; | ||
import io.deephaven.uri.DeephavenTarget; | ||
import io.deephaven.uri.DeephavenUri; | ||
import io.grpc.NameResolver; | ||
import io.grpc.NameResolver.Args; | ||
import io.grpc.NameResolverProvider; | ||
import io.grpc.internal.DnsNameResolverProvider; | ||
|
||
import java.net.URI; | ||
|
||
public final class DeephavenTargetNameResolverProviders { | ||
|
||
// TODO(deephaven-core#1489): Support service discovery for DeephavenTarget | ||
|
||
private static final DnsNameResolverProvider DNS_NAME_RESOLVER_PROVIDER = new DnsNameResolverProvider(); | ||
|
||
private static URI deephavenToDnsTarget(URI targetUri) { | ||
final DeephavenTarget deephavenTarget = DeephavenTarget.of(targetUri); | ||
// https://grpc.github.io/grpc/core/md_doc_naming.html | ||
return deephavenTarget.port().isPresent() | ||
? URI.create(String.format("dns:///%s:%d", deephavenTarget.host(), deephavenTarget.port().getAsInt())) | ||
: URI.create(String.format("dns:///%s", deephavenTarget.host())); | ||
} | ||
|
||
/** | ||
* Provides {@link NameResolver} support for plaintext {@link DeephavenTarget}. | ||
*/ | ||
@AutoService(NameResolverProvider.class) | ||
public static final class Plaintext extends NameResolverProvider { | ||
|
||
private static Args setDefaultPort(Args args) { | ||
return args.toBuilder().setDefaultPort(ChannelHelper.DEFAULT_PLAINTEXT_PORT).build(); | ||
} | ||
|
||
@Override | ||
protected boolean isAvailable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected int priority() { | ||
return 5; | ||
} | ||
|
||
@Override | ||
public NameResolver newNameResolver(URI targetUri, Args args) { | ||
if (!DeephavenUri.PLAINTEXT_SCHEME.equals(targetUri.getScheme())) { | ||
return null; | ||
} | ||
return DNS_NAME_RESOLVER_PROVIDER.newNameResolver(deephavenToDnsTarget(targetUri), setDefaultPort(args)); | ||
} | ||
|
||
@Override | ||
public String getDefaultScheme() { | ||
return DeephavenUri.PLAINTEXT_SCHEME; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Provides {@link NameResolver} support for secure {@link DeephavenTarget}. | ||
*/ | ||
@AutoService(NameResolverProvider.class) | ||
public static final class Secure extends NameResolverProvider { | ||
|
||
private static Args setDefaultPort(Args args) { | ||
return args.toBuilder().setDefaultPort(ChannelHelper.DEFAULT_TLS_PORT).build(); | ||
} | ||
|
||
@Override | ||
protected boolean isAvailable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected int priority() { | ||
return 5; | ||
} | ||
|
||
@Override | ||
public NameResolver newNameResolver(URI targetUri, Args args) { | ||
if (!DeephavenUri.SECURE_SCHEME.equals(targetUri.getScheme())) { | ||
return null; | ||
} | ||
return DNS_NAME_RESOLVER_PROVIDER.newNameResolver(deephavenToDnsTarget(targetUri), setDefaultPort(args)); | ||
} | ||
|
||
@Override | ||
public String getDefaultScheme() { | ||
return DeephavenUri.SECURE_SCHEME; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this was functionally the default before from the context of the examples (ConnectOptions.DEFAULT_PORT).