fixups for last commit

This commit is contained in:
Daniel Gultsch 2019-12-05 14:03:54 +01:00
parent 8263fb73e9
commit a3d639747a
3 changed files with 155 additions and 151 deletions

View File

@ -95,7 +95,11 @@ public class JingleConnection implements Transferable {
private OnIqPacketReceived responseListener = (account, packet) -> { private OnIqPacketReceived responseListener = (account, packet) -> {
if (packet.getType() != IqPacket.TYPE.RESULT) { if (packet.getType() != IqPacket.TYPE.RESULT) {
if (mJingleStatus != JINGLE_STATUS_FAILED && mJingleStatus != JINGLE_STATUS_FINISHED) {
fail(IqParser.extractErrorMessage(packet)); fail(IqParser.extractErrorMessage(packet));
} else {
Log.d(Config.LOGTAG,"ignoring late delivery of jingle packet to jingle session with status="+mJingleStatus+": "+packet.toString());
}
} }
}; };
private byte[] expectedHash = new byte[0]; private byte[] expectedHash = new byte[0];
@ -674,7 +678,7 @@ public class JingleConnection implements Transferable {
} }
private void sendAcceptIbb() { private void sendAcceptIbb() {
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize); this.transport = new JingleInBandTransport(this, this.transportId, this.ibbBlockSize);
final JinglePacket packet = bootstrapPacket("session-accept"); final JinglePacket packet = bootstrapPacket("session-accept");
final Content content = new Content(contentCreator, contentName); final Content content = new Content(contentCreator, contentName);
content.setFileOffer(fileOffer, ftVersion); content.setFileOffer(fileOffer, ftVersion);
@ -734,7 +738,7 @@ public class JingleConnection implements Transferable {
} }
} }
respondToIq(packet, true); respondToIq(packet, true);
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize); this.transport = new JingleInBandTransport(this, this.transportId, this.ibbBlockSize);
this.transport.connect(onIbbTransportConnected); this.transport.connect(onIbbTransportConnected);
} else { } else {
respondToIq(packet, false); respondToIq(packet, false);
@ -943,7 +947,7 @@ public class JingleConnection implements Transferable {
} }
} }
this.transportId = packet.getJingleContent().getTransportId(); this.transportId = packet.getJingleContent().getTransportId();
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize); this.transport = new JingleInBandTransport(this, this.transportId, this.ibbBlockSize);
final JinglePacket answer = bootstrapPacket("transport-accept"); final JinglePacket answer = bootstrapPacket("transport-accept");
@ -994,7 +998,7 @@ public class JingleConnection implements Transferable {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to parse block size in transport-accept"); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to parse block size in transport-accept");
} }
} }
this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize); this.transport = new JingleInBandTransport(this, this.transportId, this.ibbBlockSize);
if (sid == null || !sid.equals(this.transportId)) { if (sid == null || !sid.equals(this.transportId)) {
Log.w(Config.LOGTAG, String.format("%s: sid in transport-accept (%s) did not match our sid (%s) ", account.getJid().asBareJid(), sid, transportId)); Log.w(Config.LOGTAG, String.format("%s: sid in transport-accept (%s) did not match our sid (%s) ", account.getJid().asBareJid(), sid, transportId));
@ -1015,7 +1019,7 @@ public class JingleConnection implements Transferable {
this.mJingleStatus = JINGLE_STATUS_FINISHED; this.mJingleStatus = JINGLE_STATUS_FINISHED;
this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_RECEIVED); this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_RECEIVED);
this.disconnectSocks5Connections(); this.disconnectSocks5Connections();
if (this.transport instanceof JingleInbandTransport) { if (this.transport instanceof JingleInBandTransport) {
this.transport.disconnect(); this.transport.disconnect();
} }
this.message.setTransferable(null); this.message.setTransferable(null);
@ -1033,7 +1037,7 @@ public class JingleConnection implements Transferable {
void abort(final String reason) { void abort(final String reason) {
this.disconnectSocks5Connections(); this.disconnectSocks5Connections();
if (this.transport instanceof JingleInbandTransport) { if (this.transport instanceof JingleInBandTransport) {
this.transport.disconnect(); this.transport.disconnect();
} }
sendSessionTerminate(reason); sendSessionTerminate(reason);
@ -1057,7 +1061,7 @@ public class JingleConnection implements Transferable {
private void fail(String errorMessage) { private void fail(String errorMessage) {
this.mJingleStatus = JINGLE_STATUS_FAILED; this.mJingleStatus = JINGLE_STATUS_FAILED;
this.disconnectSocks5Connections(); this.disconnectSocks5Connections();
if (this.transport instanceof JingleInbandTransport) { if (this.transport instanceof JingleInBandTransport) {
this.transport.disconnect(); this.transport.disconnect();
} }
FileBackend.close(mFileInputStream); FileBackend.close(mFileInputStream);

View File

@ -49,6 +49,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
return; return;
} }
} }
Log.d(Config.LOGTAG, "unable to route jingle packet: " + packet);
IqPacket response = packet.generateResponse(IqPacket.TYPE.ERROR); IqPacket response = packet.generateResponse(IqPacket.TYPE.ERROR);
Element error = response.addChild("error"); Element error = response.addChild("error");
error.setAttribute("type", "cancel"); error.setAttribute("type", "cancel");
@ -65,7 +66,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
old.cancel(); old.cancel();
} }
JingleConnection connection = new JingleConnection(this); JingleConnection connection = new JingleConnection(this);
mXmppConnectionService.markMessage(message,Message.STATUS_WAITING); mXmppConnectionService.markMessage(message, Message.STATUS_WAITING);
connection.init(message); connection.init(message);
this.connections.add(connection); this.connections.add(connection);
return connection; return connection;
@ -92,7 +93,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
IqPacket iq = new IqPacket(IqPacket.TYPE.GET); IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setTo(proxy); iq.setTo(proxy);
iq.query(Namespace.BYTE_STREAMS); iq.query(Namespace.BYTE_STREAMS);
account.getXmppConnection().sendIqPacket(iq,new OnIqPacketReceived() { account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {
@Override @Override
public void onIqPacketReceived(Account account, IqPacket packet) { public void onIqPacketReceived(Account account, IqPacket packet) {
@ -107,14 +108,14 @@ public class JingleConnectionManager extends AbstractConnectionManager {
candidate.setType(JingleCandidate.TYPE_PROXY); candidate.setType(JingleCandidate.TYPE_PROXY);
candidate.setJid(proxy); candidate.setJid(proxy);
candidate.setPriority(655360 + (initiator ? 30 : 0)); candidate.setPriority(655360 + (initiator ? 30 : 0));
primaryCandidates.put(account.getJid().asBareJid(),candidate); primaryCandidates.put(account.getJid().asBareJid(), candidate);
listener.onPrimaryCandidateFound(true,candidate); listener.onPrimaryCandidateFound(true, candidate);
} catch (final NumberFormatException e) { } catch (final NumberFormatException e) {
listener.onPrimaryCandidateFound(false,null); listener.onPrimaryCandidateFound(false, null);
return; return;
} }
} else { } else {
listener.onPrimaryCandidateFound(false,null); listener.onPrimaryCandidateFound(false, null);
} }
} }
}); });
@ -141,7 +142,7 @@ public class JingleConnectionManager extends AbstractConnectionManager {
} else if (packet.hasChild("data", "http://jabber.org/protocol/ibb")) { } else if (packet.hasChild("data", "http://jabber.org/protocol/ibb")) {
payload = packet.findChild("data", "http://jabber.org/protocol/ibb"); payload = packet.findChild("data", "http://jabber.org/protocol/ibb");
sid = payload.getAttribute("sid"); sid = payload.getAttribute("sid");
} else if (packet.hasChild("close","http://jabber.org/protocol/ibb")) { } else if (packet.hasChild("close", "http://jabber.org/protocol/ibb")) {
payload = packet.findChild("close", "http://jabber.org/protocol/ibb"); payload = packet.findChild("close", "http://jabber.org/protocol/ibb");
sid = payload.getAttribute("sid"); sid = payload.getAttribute("sid");
} }
@ -150,17 +151,16 @@ public class JingleConnectionManager extends AbstractConnectionManager {
if (connection.getAccount() == account if (connection.getAccount() == account
&& connection.hasTransportId(sid)) { && connection.hasTransportId(sid)) {
JingleTransport transport = connection.getTransport(); JingleTransport transport = connection.getTransport();
if (transport instanceof JingleInbandTransport) { if (transport instanceof JingleInBandTransport) {
JingleInbandTransport inbandTransport = (JingleInbandTransport) transport; JingleInBandTransport inbandTransport = (JingleInBandTransport) transport;
inbandTransport.deliverPayload(packet, payload); inbandTransport.deliverPayload(packet, payload);
return; return;
} }
} }
} }
Log.d(Config.LOGTAG,"couldn't deliver payload: " + payload.toString());
} else {
Log.d(Config.LOGTAG, "no sid found in incoming ibb packet");
} }
Log.d(Config.LOGTAG, "unable to deliver ibb packet: " + packet.toString());
account.getXmppConnection().sendIqPacket(packet.generateResponse(IqPacket.TYPE.ERROR), null);
} }
public void cancelInTransmission() { public void cancelInTransmission() {

View File

@ -20,20 +20,20 @@ import eu.siacs.conversations.xmpp.OnIqPacketReceived;
import eu.siacs.conversations.xmpp.stanzas.IqPacket; import eu.siacs.conversations.xmpp.stanzas.IqPacket;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
public class JingleInbandTransport extends JingleTransport { public class JingleInBandTransport extends JingleTransport {
private Account account; private final Account account;
private Jid counterpart; private final Jid counterpart;
private int blockSize; private final int blockSize;
private int seq = 0; private int seq = 0;
private String sessionId; private final String sessionId;
private boolean established = false; private boolean established = false;
private boolean connected = true; private boolean connected = true;
private DownloadableFile file; private DownloadableFile file;
private JingleConnection connection; private final JingleConnection connection;
private InputStream fileInputStream = null; private InputStream fileInputStream = null;
private InputStream innerInputStream = null; private InputStream innerInputStream = null;
@ -60,11 +60,11 @@ public class JingleInbandTransport extends JingleTransport {
} }
}; };
public JingleInbandTransport(final JingleConnection connection, final String sid, final int blocksize) { JingleInBandTransport(final JingleConnection connection, final String sid, final int blockSize) {
this.connection = connection; this.connection = connection;
this.account = connection.getAccount(); this.account = connection.getAccount();
this.counterpart = connection.getCounterPart(); this.counterpart = connection.getCounterPart();
this.blockSize = blocksize; this.blockSize = blockSize;
this.sessionId = sid; this.sessionId = sid;
} }
@ -224,7 +224,7 @@ public class JingleInbandTransport extends JingleTransport {
} }
} }
public void deliverPayload(IqPacket packet, Element payload) { void deliverPayload(IqPacket packet, Element payload) {
if (payload.getName().equals("open")) { if (payload.getName().equals("open")) {
if (!established) { if (!established) {
established = true; established = true;