-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc3cab9
commit 8d995e4
Showing
15 changed files
with
545 additions
and
189 deletions.
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
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
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
35 changes: 35 additions & 0 deletions
35
service/src/main/java/org/whispersystems/textsecuregcm/grpc/GrpcServerManagedWrapper.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,35 @@ | ||
/* | ||
* Copyright 2023 Signal Messenger, LLC | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package org.whispersystems.textsecuregcm.grpc; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import io.dropwizard.lifecycle.Managed; | ||
import io.grpc.Server; | ||
|
||
public class GrpcServerManagedWrapper implements Managed { | ||
|
||
private final Server server; | ||
|
||
public GrpcServerManagedWrapper(final Server server) { | ||
this.server = server; | ||
} | ||
|
||
@Override | ||
public void start() throws IOException { | ||
server.start(); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
try { | ||
server.shutdown().awaitTermination(5, TimeUnit.MINUTES); | ||
} catch (InterruptedException e) { | ||
server.shutdownNow(); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
service/src/main/java/org/whispersystems/textsecuregcm/grpc/StatusConstants.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,12 @@ | ||
/* | ||
* Copyright 2023 Signal Messenger, LLC | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package org.whispersystems.textsecuregcm.grpc; | ||
|
||
import io.grpc.Status; | ||
|
||
public abstract class StatusConstants { | ||
public static final Status UPGRADE_NEEDED_STATUS = Status.INVALID_ARGUMENT.withDescription("signal-upgrade-required"); | ||
} |
43 changes: 43 additions & 0 deletions
43
service/src/main/java/org/whispersystems/textsecuregcm/grpc/UserAgentInterceptor.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,43 @@ | ||
/* | ||
* Copyright 2023 Signal Messenger, LLC | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package org.whispersystems.textsecuregcm.grpc; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
import org.whispersystems.textsecuregcm.util.ua.UnrecognizedUserAgentException; | ||
import org.whispersystems.textsecuregcm.util.ua.UserAgent; | ||
import org.whispersystems.textsecuregcm.util.ua.UserAgentUtil; | ||
|
||
import io.grpc.Context; | ||
import io.grpc.Contexts; | ||
import io.grpc.Metadata; | ||
import io.grpc.ServerCall; | ||
import io.grpc.ServerCallHandler; | ||
import io.grpc.ServerInterceptor; | ||
import io.grpc.Status; | ||
|
||
public class UserAgentInterceptor implements ServerInterceptor { | ||
@VisibleForTesting | ||
public static final Metadata.Key<String> USER_AGENT_GRPC_HEADER = | ||
Metadata.Key.of("user-agent", Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
@Override | ||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> call, | ||
final Metadata headers, | ||
final ServerCallHandler<ReqT, RespT> next) { | ||
|
||
UserAgent userAgent; | ||
try { | ||
userAgent = UserAgentUtil.parseUserAgentString(headers.get(USER_AGENT_GRPC_HEADER)); | ||
} catch (final UnrecognizedUserAgentException e) { | ||
userAgent = null; | ||
} | ||
|
||
final Context context = Context.current().withValue(UserAgentUtil.USER_AGENT_CONTEXT_KEY, userAgent); | ||
return Contexts.interceptCall(context, call, headers, next); | ||
} | ||
|
||
} |
Oops, something went wrong.