1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00

Improve comparison of transportmanagers

This commit is contained in:
vanitasvitae 2017-07-27 11:37:32 +02:00
parent 4234e1d5ab
commit 3915a71824
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 33 additions and 5 deletions

View file

@ -29,4 +29,11 @@ public interface JingleTransportManager extends Comparable<JingleTransportManage
JingleTransport<?> createTransport(JingleContent content);
JingleTransport<?> createTransport(JingleContent content, JingleTransport<?> peersTransport);
/**
* Return a (usually) positive integer, which is used to define a strict order over the set of available transport
* managers.
* @return priority.
*/
int getPriority();
}

View file

@ -56,8 +56,13 @@ public class JingleIBBTransportManager extends Manager implements JingleTranspor
return new JingleIBBTransport(other.getSid(), (short) Math.min(other.getBlockSize(), MAX_BLOCKSIZE));
}
@Override
public int getPriority() {
return -1;
}
@Override
public int compareTo(JingleTransportManager manager) {
return -1; // We are literally the worst.
return Integer.compare(getPriority(), manager.getPriority());
}
}

View file

@ -28,6 +28,7 @@ import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Utils;
@ -325,9 +326,9 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
}
private void handleCandidateActivate(JingleS5BTransportInfoElement info) {
//Socks5BytestreamSession bs = new Socks5BytestreamSession(ourChoice.socket,
// ourChoice.candidate.getJid().asBareJid().equals(jingleSession.getRemote().asBareJid()));
//callback.onSessionInitiated(bs);
this.bytestreamSession = new Socks5BytestreamSession(getSelectedCandidate().getSocket(),
getSelectedCandidate().getStreamHost().getJID().asBareJid().equals(getParent().getParent().getPeer().asBareJid()));
getParent().onTransportReady();
}
private void handleCandidateError(JingleS5BTransportInfoElement info) {
@ -352,4 +353,14 @@ public class JingleS5BTransport extends JingleTransport<JingleS5BTransportElemen
* Kinda depressing, isn't it?
*/
private final static JingleS5BTransportCandidate CANDIDATE_FAILURE = new JingleS5BTransportCandidate(null, null, -1, null);
@Override
protected boolean isNonFatalException(Exception exception) {
return false;
}
@Override
protected void handleStanza(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
}
}

View file

@ -106,6 +106,11 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
return new JingleS5BTransport(content, transport, candidates);
}
@Override
public int getPriority() {
return 10000;
}
private List<JingleTransportCandidate<?>> collectCandidates() {
List<JingleTransportCandidate<?>> candidates = new ArrayList<>();
@ -236,7 +241,7 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
@Override
public int compareTo(JingleTransportManager manager) {
return 1; // We are #1!
return Integer.compare(getPriority(), manager.getPriority());
}
private ConnectionListener connectionListener = new ConnectionListener() {