mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-11-30 00:56:50 +00:00
Stop subscribing to un-namespaced provisioning pub-sub
This commit is contained in:
1 parent
e3b303e2c8
commit
b6685b5140
2 files changed
+5
-50
No files matched your search
+5
-16
@@ -7,7 +7,6 @@ package org.whispersystems.textsecuregcm.push;
|
||||
|
||||
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import io.dropwizard.lifecycle.Managed;
|
||||
@@ -67,14 +66,12 @@ public class ProvisioningManager extends RedisPubSubAdapter<byte[], byte[]> impl
|
||||
|
||||
public void addListener(final String address, final Consumer<PubSubProtos.PubSubMessage> listener) {
|
||||
listenersByProvisioningAddress.put(address, listener);
|
||||
pubSubConnection.usePubSubConnection(connection -> connection.sync().subscribe(
|
||||
getPrefixedChannel(address), getUnprefixedChannel(address)));
|
||||
pubSubConnection.usePubSubConnection(connection -> connection.sync().subscribe(getChannel(address)));
|
||||
}
|
||||
|
||||
public void removeListener(final String address) {
|
||||
RedisOperation.unchecked(() ->
|
||||
pubSubConnection.usePubSubConnection(connection -> connection.sync().unsubscribe(
|
||||
getPrefixedChannel(address), getUnprefixedChannel(address))));
|
||||
pubSubConnection.usePubSubConnection(connection -> connection.sync().unsubscribe(getChannel(address))));
|
||||
|
||||
listenersByProvisioningAddress.remove(address);
|
||||
}
|
||||
@@ -87,7 +84,7 @@ public class ProvisioningManager extends RedisPubSubAdapter<byte[], byte[]> impl
|
||||
|
||||
final boolean receiverPresent = ResilienceUtil.getGeneralRedisRetry(RETRY_NAME)
|
||||
.executeSupplier(() -> pubSubClient.withBinaryConnection(connection ->
|
||||
connection.sync().publish(getPrefixedChannel(address), pubSubMessage.toByteArray()) > 0));
|
||||
connection.sync().publish(getChannel(address), pubSubMessage.toByteArray()) > 0));
|
||||
|
||||
Metrics.counter(SEND_PROVISIONING_MESSAGE_COUNTER_NAME, "online", String.valueOf(receiverPresent)).increment();
|
||||
|
||||
@@ -122,19 +119,11 @@ public class ProvisioningManager extends RedisPubSubAdapter<byte[], byte[]> impl
|
||||
listenersByProvisioningAddress.remove(getAddress(channel));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static byte[] getPrefixedChannel(final String address) {
|
||||
private static byte[] getChannel(final String address) {
|
||||
return (CHANNEL_PREFIX + address).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static byte[] getUnprefixedChannel(final String address) {
|
||||
return address.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static String getAddress(final byte[] channel) {
|
||||
final String channelName = new String(channel, StandardCharsets.UTF_8);
|
||||
|
||||
return channelName.startsWith(CHANNEL_PREFIX) ? channelName.substring(CHANNEL_PREFIX.length()) : channelName;
|
||||
return new String(channel, StandardCharsets.UTF_8).substring(CHANNEL_PREFIX.length());
|
||||
}
|
||||
}
|
||||
-34
@@ -14,8 +14,6 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.whispersystems.textsecuregcm.redis.RedisServerExtension;
|
||||
import org.whispersystems.textsecuregcm.storage.PubSubProtos;
|
||||
@@ -74,36 +72,4 @@ class ProvisioningManagerTest {
|
||||
// Make sure that we give the message enough time to show up (if it was going to) before declaring victory
|
||||
verify(subscribedConsumer, after(PUBSUB_TIMEOUT_MILLIS).never()).accept(any());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {true, false})
|
||||
void receiveProvisioningMessageChannelMigration(final boolean prefixedChannel) {
|
||||
final String provisioningAddress = UUID.randomUUID().toString();
|
||||
|
||||
final byte[] channel = prefixedChannel
|
||||
? ProvisioningManager.getPrefixedChannel(provisioningAddress)
|
||||
: ProvisioningManager.getUnprefixedChannel(provisioningAddress);
|
||||
|
||||
final byte[] content = TestRandomUtil.nextBytes(16);
|
||||
|
||||
@SuppressWarnings("unchecked") final Consumer<PubSubProtos.PubSubMessage> subscribedConsumer = mock(Consumer.class);
|
||||
|
||||
provisioningManager.addListener(provisioningAddress, subscribedConsumer);
|
||||
|
||||
final PubSubProtos.PubSubMessage pubSubMessage = PubSubProtos.PubSubMessage.newBuilder()
|
||||
.setType(PubSubProtos.PubSubMessage.Type.DELIVER)
|
||||
.setContent(ByteString.copyFrom(content))
|
||||
.build();
|
||||
|
||||
REDIS_EXTENSION.getRedisClient().useBinaryConnection(connection ->
|
||||
connection.sync().publish(channel, pubSubMessage.toByteArray()));
|
||||
|
||||
final ArgumentCaptor<PubSubProtos.PubSubMessage> messageCaptor =
|
||||
ArgumentCaptor.forClass(PubSubProtos.PubSubMessage.class);
|
||||
|
||||
verify(subscribedConsumer, timeout(PUBSUB_TIMEOUT_MILLIS)).accept(messageCaptor.capture());
|
||||
|
||||
assertEquals(PubSubProtos.PubSubMessage.Type.DELIVER, messageCaptor.getValue().getType());
|
||||
assertEquals(ByteString.copyFrom(content), messageCaptor.getValue().getContent());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user