1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-12 10:39:38 +02:00

Simplify content state handling, add Fallback test

This commit is contained in:
vanitasvitae 2017-08-05 20:28:36 +02:00
parent 9712dc1df7
commit 0d8b383b1c
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 185 additions and 45 deletions

View file

@ -67,41 +67,6 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
private final List<Callback> callbacks = Collections.synchronizedList(new ArrayList<Callback>());
private final Set<String> transportBlacklist = Collections.synchronizedSet(new HashSet<String>());
private short state;
public enum STATE {
pending_accept((short) 1),
pending_transmission_start((short) 2),
pending_transport_replace((short) 4),
transmission_in_progress((short) 8),
transmission_successful((short) 16),
transmission_failed((short) 32),
transmission_cancelled((short) 64),
;
final short value;
STATE(short value) {
this.value = value;
}
short getValue() {
return value;
}
}
public void addState(STATE state) {
this.state |= state.getValue();
}
public void removeState(STATE state) {
this.state ^= state.getValue();
}
public boolean hasState(STATE state) {
return (this.state & state.getValue()) == state.getValue();
}
public JingleContent(JingleContentElement.Creator creator, JingleContentElement.Senders senders) {
this(null, null, null, randomName(), null, creator, senders);
}
@ -114,7 +79,6 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
this.disposition = disposition;
this.creator = creator;
this.senders = senders;
this.addState(STATE.pending_accept);
}
public static JingleContent fromElement(JingleContentElement content) {
@ -226,7 +190,7 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
public IQ handleTransportAccept(JingleElement request, XMPPConnection connection) {
if (pendingReplacingTransport == null || !hasState(STATE.pending_transport_replace)) {
if (pendingReplacingTransport == null) {
LOGGER.log(Level.WARNING, "Received transport-accept, but apparently we did not try to replace the transport.");
return JingleElement.createJingleErrorOutOfOrder(request);
}
@ -234,8 +198,6 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
transport = pendingReplacingTransport;
pendingReplacingTransport = null;
removeState(STATE.pending_transport_replace);
onAccept(connection);
return IQ.createResultIQ(request);
@ -249,13 +211,12 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
}
public IQ handleTransportReject(JingleElement request, XMPPConnection connection) {
removeState(STATE.pending_transport_replace);
return IQ.createResultIQ(request);
}
public IQ handleTransportReplace(final JingleElement request, final XMPPConnection connection) {
//Tie Break?
if (hasState(STATE.pending_transport_replace)) {
if (pendingReplacingTransport != null) {
Async.go(new Runnable() {
@Override
public void run() {
@ -487,7 +448,7 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
private void replaceTransport(Set<String> blacklist, XMPPConnection connection)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
if (hasState(STATE.pending_transport_replace)) {
if (pendingReplacingTransport != null) {
throw new AssertionError("Transport replace already pending.");
}
@ -508,7 +469,6 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
session.getSessionId(), getCreator(), getName(), pendingReplacingTransport.getElement());
connection.createStanzaCollectorAndSend(transportReplace).nextResultOrThrow();
addState(STATE.pending_transport_replace);
}
public static String randomName() {

View file

@ -65,8 +65,8 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
private List<Bytestream.StreamHost> localStreamHosts = null;
private List<Bytestream.StreamHost> availableStreamHosts = null;
private static boolean useLocalCandidates = true;
private static boolean useExternalCandidates = true;
public static boolean useLocalCandidates = true;
public static boolean useExternalCandidates = true;
static {
JingleManager.addJingleTransportAdapter(new JingleS5BTransportAdapter());