Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Share MessageRetrievalService's pipe by reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitris Papavasiliou committed Sep 30, 2018
1 parent 5f5bab7 commit 1b9a981
Showing 1 changed file with 11 additions and 15 deletions.
Expand Up @@ -81,11 +81,11 @@ public class SignalServiceMessageSender {

private static final String TAG = SignalServiceMessageSender.class.getSimpleName();

private final PushServiceSocket socket;
private final SignalProtocolStore store;
private final SignalServiceAddress localAddress;
private final AtomicReference<Optional<SignalServiceMessagePipe>> pipe;
private final Optional<EventListener> eventListener;
private final PushServiceSocket socket;
private final SignalProtocolStore store;
private final SignalServiceAddress localAddress;
private final AtomicReference<SignalServiceMessagePipe> pipe;
private final Optional<EventListener> eventListener;

/**
* Construct a SignalServiceMessageSender.
Expand All @@ -101,7 +101,7 @@ public SignalServiceMessageSender(SignalServiceConfiguration urls,
String user, String password,
SignalProtocolStore store,
String userAgent,
Optional<SignalServiceMessagePipe> pipe,
AtomicReference<SignalServiceMessagePipe> pipe,
Optional<EventListener> eventListener)
{
this(urls, new StaticCredentialsProvider(user, password, null), store, userAgent, pipe, eventListener);
Expand All @@ -111,13 +111,13 @@ public SignalServiceMessageSender(SignalServiceConfiguration urls,
CredentialsProvider credentialsProvider,
SignalProtocolStore store,
String userAgent,
Optional<SignalServiceMessagePipe> pipe,
AtomicReference<SignalServiceMessagePipe> pipe,
Optional<EventListener> eventListener)
{
this.socket = new PushServiceSocket(urls, credentialsProvider, userAgent);
this.store = store;
this.localAddress = new SignalServiceAddress(credentialsProvider.getUser());
this.pipe = new AtomicReference<>(pipe);
this.pipe = pipe;
this.eventListener = eventListener;
}

Expand Down Expand Up @@ -243,10 +243,6 @@ public void cancelInFlightRequests() {
socket.cancelInFlightRequests();
}

public void setMessagePipe(SignalServiceMessagePipe pipe) {
this.pipe.set(Optional.fromNullable(pipe));
}

private void sendMessage(VerifiedMessage message) throws IOException, UntrustedIdentityException {
byte[] nullMessageBody = DataMessage.newBuilder()
.setBody(Base64.encodeBytes(Util.getRandomLengthBytes(140)))
Expand Down Expand Up @@ -652,12 +648,12 @@ private SendMessageResponse sendMessage(SignalServiceAddress recipient, long tim
for (int i=0;i<3;i++) {
try {
OutgoingPushMessageList messages = getEncryptedMessages(socket, recipient, timestamp, content, silent);
Optional<SignalServiceMessagePipe> pipe = this.pipe.get();
SignalServiceMessagePipe pipe = this.pipe.get();

if (pipe.isPresent()) {
if (pipe != null) {
try {
Log.w(TAG, "Transmitting over pipe...");
return pipe.get().send(messages);
return pipe.send(messages);
} catch (IOException e) {
Log.w(TAG, e);
Log.w(TAG, "Falling back to new connection...");
Expand Down

0 comments on commit 1b9a981

Please sign in to comment.