summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorAlex Clayton <alex.clayton@isode.com>2016-03-11 17:05:43 (GMT)
committerAlex Clayton <alex.clayton@isode.com>2016-03-14 15:33:25 (GMT)
commitde2704f8dfd9b807b37e72e61f2042a5e71227c5 (patch)
tree8694b4ea245a6f7fa7813f5ac8b3e045520378c6 /src/com
parenta0a0b9fd74f6d99da1c756b36aad6cc0122f011b (diff)
downloadstroke-de2704f8dfd9b807b37e72e61f2042a5e71227c5.zip
stroke-de2704f8dfd9b807b37e72e61f2042a5e71227c5.tar.bz2
Add FileTransfer.getState method
As per swiften patch of same name (cb62de17d1e17fd3049a6bc8155a100574a42a85) add getState() method to FileTransfer interface. Test-information: Unit tests pass ok. Change-Id: I27db4e60c3a8df251b813c90fc4a2e029762082d
Diffstat (limited to 'src/com')
-rw-r--r--src/com/isode/stroke/filetransfer/FileTransfer.java5
-rw-r--r--src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java61
-rw-r--r--src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java65
3 files changed, 72 insertions, 59 deletions
diff --git a/src/com/isode/stroke/filetransfer/FileTransfer.java b/src/com/isode/stroke/filetransfer/FileTransfer.java
index 8572d93..e12b07d 100644
--- a/src/com/isode/stroke/filetransfer/FileTransfer.java
+++ b/src/com/isode/stroke/filetransfer/FileTransfer.java
@@ -4,7 +4,7 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
- * Copyright (c) 2013-2015 Isode Limited.
+ * Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -64,4 +64,7 @@ public interface FileTransfer {
public long getFileSizeInBytes();
public void setFileInfo(final String name, long size);
+
+ public State getState();
+
}
diff --git a/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java b/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java
index 92b185d..f7f9c70 100644
--- a/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java
+++ b/src/com/isode/stroke/filetransfer/IncomingJingleFileTransfer.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -69,7 +69,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
private JingleContentPayload initialContent;
private CryptoProvider crypto;
- private State state;
+ private State internalState;
private JingleFileTransferDescription description;
private WriteBytestream stream;
private long receivedBytes;
@@ -93,7 +93,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
super(session, toJID, transporterFactory);
this.initialContent = content;
this.crypto = crypto;
- this.state = State.Initial;
+ this.internalState = State.Initial;
this. receivedBytes = 0;
this.hashCalculator = null;
this.description = initialContent.getDescription(new JingleFileTransferDescription());
@@ -125,7 +125,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
@Override
public void accept(WriteBytestream stream, final FileTransferOptions options) {
logger_.fine("\n");
- if (!State.Initial.equals(state)) { logger_.warning("Incorrect state \n"); return; }
+ if (!State.Initial.equals(internalState)) { logger_.warning("Incorrect state \n"); return; }
assert(this.stream == null);
this.stream = stream;
@@ -147,7 +147,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
logger_.fine("Got S5B transport as initial payload.\n");
setTransporter(transporterFactory.createResponderTransporter(getInitiator(), getResponder(), s5bTransport.getSessionID(), options));
transporter.addRemoteCandidates(s5bTransport.getCandidates(), s5bTransport.getDstAddr());
- setState(State.GeneratingInitialLocalCandidates);
+ setInternalState(State.GeneratingInitialLocalCandidates);
transporter.startGeneratingLocalCandidates();
}
else if(initialContent.getTransport(new JingleIBBTransportPayload()) != null) {
@@ -187,14 +187,14 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
@Override
public void cancel() {
logger_.fine("\n");
- terminate(State.Initial.equals(state) ? JinglePayload.Reason.Type.Decline : JinglePayload.Reason.Type.Cancel);
+ terminate(State.Initial.equals(internalState) ? JinglePayload.Reason.Type.Decline : JinglePayload.Reason.Type.Cancel);
}
protected void startTransferViaRemoteCandidate() {
logger_.fine("\n");
if (JingleS5BTransportPayload.Candidate.Type.ProxyType.equals(ourCandidateChoice.type)) {
- setState(State.WaitingForPeerProxyActivate);
+ setInternalState(State.WaitingForPeerProxyActivate);
}
else {
startTransferring(createRemoteCandidateSession());
@@ -205,7 +205,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
logger_.fine("\n");
if (JingleS5BTransportPayload.Candidate.Type.ProxyType.equals(theirCandidateChoice.type)) {
- setState(State.WaitingForLocalProxyActivate);
+ setInternalState(State.WaitingForLocalProxyActivate);
transporter.startActivatingProxy(theirCandidateChoice.jid);
}
else {
@@ -224,11 +224,11 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
}
protected void stopAll() {
- if (!State.Initial.equals(state)) {
+ if (!State.Initial.equals(internalState)) {
writeStreamDataReceivedConnection.disconnect();
hashCalculator = null;
}
- switch (state) {
+ switch (internalState) {
case Initial: break;
case GeneratingInitialLocalCandidates: transporter.stopGeneratingLocalCandidates(); break;
case TryingCandidates: transporter.stopTryingRemoteCandidates(); break;
@@ -244,20 +244,25 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
break;
case Finished: logger_.warning("Already finished\n"); break;
}
- if (!State.Initial.equals(state)) {
+ if (!State.Initial.equals(internalState)) {
removeTransporter();
}
}
- protected void setState(State state) {
+ protected void setInternalState(State state) {
logger_.fine(state + "\n");
- this.state = state;
+ this.internalState = state;
onStateChanged.emit(new FileTransfer.State(getExternalState(state)));
}
+
+ @Override
+ public com.isode.stroke.filetransfer.FileTransfer.State getState() {
+ return new FileTransfer.State(getExternalState(internalState));
+ }
protected void setFinishedState(FileTransfer.State.Type type, final FileTransferError error) {
logger_.fine("\n");
- this.state = State.Finished;
+ this.internalState = State.Finished;
onStateChanged.emit(new FileTransfer.State(type));
onFinished.emit(error);
}
@@ -283,7 +288,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
}
protected void fallback() {
- setState(State.WaitingForFallbackOrTerminate);
+ setInternalState(State.WaitingForFallbackOrTerminate);
}
protected void startTransferring(TransportSession transportSession) {
@@ -296,20 +301,20 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
handleTransferFinished(e);
}
});
- setState(State.Transferring);
+ setInternalState(State.Transferring);
transportSession.start();
}
protected boolean isWaitingForPeerProxyActivate() {
- return State.WaitingForPeerProxyActivate.equals(state);
+ return State.WaitingForPeerProxyActivate.equals(internalState);
}
protected boolean isWaitingForLocalProxyActivate() {
- return State.WaitingForLocalProxyActivate.equals(state);
+ return State.WaitingForLocalProxyActivate.equals(internalState);
}
protected boolean isTryingCandidates() {
- return State.TryingCandidates.equals(state);
+ return State.TryingCandidates.equals(internalState);
}
protected TransportSession createLocalCandidateSession() {
@@ -323,7 +328,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
protected void terminate(JinglePayload.Reason.Type reason) {
logger_.fine(reason + "\n");
- if (!State.Finished.equals(state)) {
+ if (!State.Finished.equals(internalState)) {
session.sendTerminate(reason);
}
stopAll();
@@ -344,9 +349,9 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
public void handleSessionTerminateReceived(JinglePayload.Reason reason) {
logger_.fine("\n");
- if (State.Finished.equals(state)) { logger_.warning("Incorrect state\n"); return; }
+ if (State.Finished.equals(internalState)) { logger_.warning("Incorrect state\n"); return; }
- if (State.Finished.equals(state)) {
+ if (State.Finished.equals(internalState)) {
logger_.fine("Already terminated\n");
return;
}
@@ -376,7 +381,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
if (transferHash.getFileInfo().getHashes().containsKey("md5")) {
hashes.put("md5", transferHash.getFileInfo().getHash("md5"));
}
- if (State.WaitingForHash.equals(state)) {
+ if (State.WaitingForHash.equals(internalState)) {
checkHashAndTerminate();
}
}
@@ -387,7 +392,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
public void handleTransportReplaceReceived(final JingleContentID content, JingleTransportPayload transport) {
logger_.fine("\n");
- if (!State.WaitingForFallbackOrTerminate.equals(state)) {
+ if (!State.WaitingForFallbackOrTerminate.equals(internalState)) {
logger_.warning("Incorrect state\n");
return;
}
@@ -407,7 +412,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
protected void handleLocalTransportCandidatesGenerated(final String s5bSessionID, final Vector<JingleS5BTransportPayload.Candidate> candidates, final String dstAddr) {
logger_.fine("\n");
- if (!State.GeneratingInitialLocalCandidates.equals(state)) { logger_.warning("Incorrect state\n"); return; }
+ if (!State.GeneratingInitialLocalCandidates.equals(internalState)) { logger_.warning("Incorrect state\n"); return; }
fillCandidateMap(localCandidates, candidates);
@@ -420,7 +425,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
}
session.sendAccept(getContentID(), initialContent.getDescriptions().get(0), transport);
- setState(State.TryingCandidates);
+ setInternalState(State.TryingCandidates);
transporter.startTryingRemoteCandidates();
}
@@ -453,7 +458,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
if (!hashInfoAvailable) {
logger_.fine("No hash information yet. Waiting a while on hash info.\n");
- setState(State.WaitingForHash);
+ setInternalState(State.WaitingForHash);
waitOnHashTimer.start();
}
else {
@@ -492,7 +497,7 @@ public class IncomingJingleFileTransfer extends JingleFileTransfer implements In
}
private void handleTransferFinished(FileTransferError error) {
- if (error != null && !State.WaitingForHash.equals(state)) {
+ if (error != null && !State.WaitingForHash.equals(internalState)) {
terminate(JinglePayload.Reason.Type.MediaError);
}
}
diff --git a/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java b/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java
index c5a1f11..63a11e8 100644
--- a/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java
+++ b/src/com/isode/stroke/filetransfer/OutgoingJingleFileTransfer.java
@@ -77,7 +77,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
private FileTransferOptions options;
private JingleContentID contentID;
private IncrementalBytestreamHashCalculator hashCalculator;
- private State state;
+ private State internalState;
private boolean candidateAcknowledged;
private Timer waitForRemoteTermination;
@@ -103,7 +103,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
this.options = options;
this.session = session;
this.contentID = new JingleContentID(idGenerator.generateID(), JingleContentPayload.Creator.InitiatorCreator);
- this.state = State.Initial;
+ this.internalState = State.Initial;
this.candidateAcknowledged = false;
setFileInfo(fileInfo.getName(), fileInfo.getSize());
@@ -130,13 +130,13 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
@Override
public void start() {
logger_.fine("\n");
- if (!State.Initial.equals(state)) {
+ if (!State.Initial.equals(internalState)) {
logger_.warning("Incorrect state\n");
return;
}
setTransporter(transporterFactory.createInitiatorTransporter(getInitiator(), getResponder(), options));
- setState(State.GeneratingInitialLocalCandidates);
+ setInternalState(State.GeneratingInitialLocalCandidates);
transporter.startGeneratingLocalCandidates();
}
@@ -164,12 +164,12 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
public void handleSessionAcceptReceived(final JingleContentID contentID, JingleDescription description, JingleTransportPayload transportPayload) {
logger_.fine("\n");
- if (!State.WaitingForAccept.equals(state)) { logger_.warning("Incorrect state\n"); return; }
+ if (!State.WaitingForAccept.equals(internalState)) { logger_.warning("Incorrect state\n"); return; }
if (transportPayload instanceof JingleS5BTransportPayload) {
JingleS5BTransportPayload s5bPayload = (JingleS5BTransportPayload)transportPayload;
transporter.addRemoteCandidates(s5bPayload.getCandidates(), s5bPayload.getDstAddr());
- setState(State.TryingCandidates);
+ setInternalState(State.TryingCandidates);
transporter.startTryingRemoteCandidates();
}
else {
@@ -180,10 +180,10 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
public void handleSessionTerminateReceived(JinglePayload.Reason reason) {
logger_.fine("\n");
- if (State.Finished.equals(state)) { logger_.warning("Incorrect state: " + state + "\n"); return; }
+ if (State.Finished.equals(internalState)) { logger_.warning("Incorrect state: " + internalState + "\n"); return; }
stopAll();
- if (State.WaitForTermination.equals(state)) {
+ if (State.WaitForTermination.equals(internalState)) {
waitForRemoteTermination.stop();
}
if (reason != null && JinglePayload.Reason.Type.Cancel.equals(reason.type)) {
@@ -202,7 +202,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
public void handleTransportAcceptReceived(final JingleContentID contentID, JingleTransportPayload transport) {
logger_.fine("\n");
- if (!State.FallbackRequested.equals(state)) { logger_.warning("Incorrect state\n"); return; }
+ if (!State.FallbackRequested.equals(internalState)) { logger_.warning("Incorrect state\n"); return; }
if (transport instanceof JingleIBBTransportPayload) {
JingleIBBTransportPayload ibbPayload = (JingleIBBTransportPayload)transport;
@@ -224,7 +224,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
logger_.fine("\n");
if (JingleS5BTransportPayload.Candidate.Type.ProxyType.equals(ourCandidateChoice.type)) {
- setState(State.WaitingForPeerProxyActivate);
+ setInternalState(State.WaitingForPeerProxyActivate);
}
else {
transportSession = createRemoteCandidateSession();
@@ -236,7 +236,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
logger_.fine("\n");
if (JingleS5BTransportPayload.Candidate.Type.ProxyType.equals(theirCandidateChoice.type)) {
- setState(State.WaitingForLocalProxyActivate);
+ setInternalState(State.WaitingForLocalProxyActivate);
transporter.startActivatingProxy(theirCandidateChoice.jid);
}
else {
@@ -250,13 +250,13 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
startTransferring(transportSession);
}
else {
- setState(State.WaitingForCandidateAcknowledge);
+ setInternalState(State.WaitingForCandidateAcknowledge);
}
}
protected void handleLocalTransportCandidatesGenerated(final String s5bSessionID, final Vector<JingleS5BTransportPayload.Candidate> candidates, final String dstAddr) {
logger_.fine("\n");
- if (!State.GeneratingInitialLocalCandidates.equals(state)) { logger_.warning("Incorrect state\n"); return; }
+ if (!State.GeneratingInitialLocalCandidates.equals(internalState)) { logger_.warning("Incorrect state\n"); return; }
fillCandidateMap(localCandidates, candidates);
@@ -273,7 +273,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
transport.addCandidate(candidate);
logger_.fine("\t" + "S5B candidate: " + candidate.hostPort.toString() + "\n");
}
- setState(State.WaitingForAccept);
+ setInternalState(State.WaitingForAccept);
session.sendInitiate(contentID, description, transport);
}
@@ -281,7 +281,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
if (id.equals(candidateSelectRequestID)) {
candidateAcknowledged = true;
}
- if (State.WaitingForCandidateAcknowledge.equals(state)) {
+ if (State.WaitingForCandidateAcknowledge.equals(internalState)) {
startTransferring(transportSession);
}
}
@@ -293,7 +293,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
protected void terminate(JinglePayload.Reason.Type reason) {
logger_.fine(reason + "\n");
- if (!State.Initial.equals(state) && !State.GeneratingInitialLocalCandidates.equals(state) && !State.Finished.equals(state)) {
+ if (!State.Initial.equals(internalState) && !State.GeneratingInitialLocalCandidates.equals(internalState) && !State.Finished.equals(internalState)) {
session.sendTerminate(reason);
}
stopAll();
@@ -306,7 +306,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
JingleIBBTransportPayload ibbTransport = new JingleIBBTransportPayload();
ibbTransport.setBlockSize(DEFAULT_BLOCK_SIZE);
ibbTransport.setSessionID(idGenerator.generateID());
- setState(State.FallbackRequested);
+ setInternalState(State.FallbackRequested);
session.sendTransportReplace(contentID, ibbTransport);
}
else {
@@ -317,7 +317,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
private void handleTransferFinished(FileTransferError error) {
logger_.fine("\n");
- if (!State.Transferring.equals(state)) { logger_.warning("Incorrect state: " + state + "\n"); return; }
+ if (!State.Transferring.equals(internalState)) { logger_.warning("Incorrect state: " + internalState + "\n"); return; }
if (error != null) {
terminate(JinglePayload.Reason.Type.ConnectivityError);
@@ -326,7 +326,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
sendSessionInfoHash();
// wait for other party to terminate session after they have verified the hash
- setState(State.WaitForTermination);
+ setInternalState(State.WaitForTermination);
waitForRemoteTermination.start();
}
}
@@ -351,7 +351,7 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
handleTransferFinished(e);
}
});
- setState(State.Transferring);
+ setInternalState(State.Transferring);
transportSession.start();
}
@@ -360,15 +360,15 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
}
protected boolean isWaitingForPeerProxyActivate() {
- return State.WaitingForPeerProxyActivate.equals(state);
+ return State.WaitingForPeerProxyActivate.equals(internalState);
}
protected boolean isWaitingForLocalProxyActivate() {
- return State.WaitingForLocalProxyActivate.equals(state);
+ return State.WaitingForLocalProxyActivate.equals(internalState);
}
protected boolean isTryingCandidates() {
- return State.TryingCandidates.equals(state);
+ return State.TryingCandidates.equals(internalState);
}
protected TransportSession createLocalCandidateSession() {
@@ -380,15 +380,15 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
}
private void handleWaitForRemoteTerminationTimeout() {
- assert(state.equals(State.WaitForTermination));
+ assert(internalState.equals(State.WaitForTermination));
logger_.warning("Other party did not terminate session. Terminate it now.\n");
waitForRemoteTermination.stop();
terminate(JinglePayload.Reason.Type.MediaError);
}
private void stopAll() {
- logger_.fine(state + "\n");
- switch (state) {
+ logger_.fine(internalState + "\n");
+ switch (internalState) {
case Initial: logger_.warning("Not yet started\n"); break;
case GeneratingInitialLocalCandidates: transporter.stopGeneratingLocalCandidates(); break;
case WaitingForAccept: break;
@@ -408,20 +408,25 @@ public class OutgoingJingleFileTransfer extends JingleFileTransfer implements Ou
break;
case Finished: logger_.warning("Already finished\n"); break;
}
- if (!State.Initial.equals(state)) {
+ if (!State.Initial.equals(internalState)) {
removeTransporter();
}
}
- private void setState(State state) {
+ private void setInternalState(State state) {
logger_.fine(state + "\n");
- this.state = state;
+ this.internalState = state;
onStateChanged.emit(new FileTransfer.State(getExternalState(state)));
}
+ @Override
+ public com.isode.stroke.filetransfer.FileTransfer.State getState() {
+ return new FileTransfer.State(getExternalState(internalState));
+ }
+
private void setFinishedState(FileTransfer.State.Type type, final FileTransferError error) {
logger_.fine("\n");
- this.state = State.Finished;
+ this.internalState = State.Finished;
onStateChanged.emit(new FileTransfer.State(type));
onFinished.emit(error);
}