From 699a19d3c23fe92556bfd4a9aca7d74f10156b72 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Sat, 24 Jun 2017 17:46:03 +0200 Subject: [PATCH] Add S5B candidate accept/error --- .../IncomingJingleFileOffer.java | 46 +++++++++++-------- .../JingleFileTransferSession.java | 3 -- .../OutgoingJingleFileOffer.java | 6 ++- .../smackx/jingle/JingleSession.java | 16 +++++++ .../transports/JingleTransportSession.java | 4 -- .../jingle_ibb/JingleIBBTransportSession.java | 3 -- .../jingle_s5b/JingleS5BTransportManager.java | 40 ++++++++++++++++ .../jingle_s5b/JingleS5BTransportSession.java | 32 ++++++++++++- 8 files changed, 118 insertions(+), 32 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/IncomingJingleFileOffer.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/IncomingJingleFileOffer.java index 3bce33306..f713a37da 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/IncomingJingleFileOffer.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/IncomingJingleFileOffer.java @@ -64,7 +64,9 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement } @Override - public IQ handleSessionInitiate(Jingle initiate) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { + public IQ handleSessionInitiate(final Jingle initiate) + throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, + SmackException.NoResponseException { JingleTransportMethodManager tm = JingleTransportMethodManager.getInstanceFor(connection); if (state != State.fresh) { @@ -73,10 +75,8 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement return jutil.createErrorOutOfOrder(initiate); } - JingleContent content = initiate.getContents().get(0); - this.creator = content.getCreator(); - this.file = (JingleFileTransfer) content.getDescription(); - this.name = content.getName(); + this.contents.addAll(initiate.getContents()); + this.file = (JingleFileTransfer) contents.get(0).getDescription(); JingleTransportManager transportManager = tm.getTransportManager(initiate); if (transportManager == null) { @@ -87,23 +87,27 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement if (transportManager == null) { //No usable transports. LOGGER.log(Level.WARNING, "No usable transports."); - jutil.sendSessionTerminateUnsupportedTransports(initiate.getInitiator(), initiate.getSid()); + jutil.sendSessionTerminateUnsupportedTransports(getInitiator(), getSessionId()); state = State.terminated; return jutil.createAck(initiate); } transportSession = transportManager.transportSession(this); - jutil.sendTransportReplace(initiate.getFrom().asFullJidOrThrow(), initiate.getInitiator(), - initiate.getSid(), creator, name, transportSession.createTransport()); + jutil.sendTransportReplace(initiate.getFrom().asFullJidOrThrow(), getInitiator(), + getSessionId(), contents.get(0).getCreator(), contents.get(0).getName(), + transportSession.createTransport()); state = State.sent_transport_replace; return jutil.createAck(initiate); } transportSession = transportManager.transportSession(this); - transportSession.setRemoteTransport(initiate.getContents().get(0).getJingleTransport()); + transportSession.processJingle(initiate); - JingleFileTransferManager.getInstanceFor(connection).notifyIncomingFileOffer(initiate, this); state = State.pending; + + JingleFileTransferManager.getInstanceFor(connection).notifyIncomingFileOffer(initiate, + IncomingJingleFileOffer.this); + return jutil.createAck(initiate); } @@ -115,8 +119,9 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement return jutil.createErrorOutOfOrder(transportAccept); } - JingleFileTransferManager.getInstanceFor(connection).notifyIncomingFileOffer(pendingSessionInitiate, this); - transportSession.setRemoteTransport(transportAccept.getContents().get(0).getJingleTransport()); + JingleFileTransferManager.getInstanceFor(connection) + .notifyIncomingFileOffer(pendingSessionInitiate, this); + transportSession.processJingle(transportAccept); state = State.pending; return jutil.createAck(transportAccept); } @@ -129,7 +134,8 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement LOGGER.log(Level.WARNING, "Unsupported Transport method."); try { jutil.sendSessionTerminateUnsupportedTransports(request.getFrom().asFullJidOrThrow(), sid); - } catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) { + } catch (InterruptedException | SmackException.NoResponseException | + SmackException.NotConnectedException | XMPPException.XMPPErrorException e) { LOGGER.log(Level.SEVERE, "Could not send session-terminate: " + e, e); } return; @@ -140,10 +146,8 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement transportSession.initiateIncomingSession(new JingleTransportInitiationCallback() { @Override public void onSessionInitiated(BytestreamSession bytestreamSession) { - LOGGER.log(Level.INFO, "BEFORE THREAD START!"); receivingThread = new ReceiveTask(bytestreamSession, file, target); queued.add(threadPool.submit(receivingThread)); - LOGGER.log(Level.INFO,"AFTER THREAD START!"); } @Override @@ -153,9 +157,12 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement }); try { - jutil.sendSessionAccept(getInitiator(), sid, creator, name, JingleContent.Senders.initiator, file, transportSession.createTransport()); - } catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException e) { - e.printStackTrace(); + jutil.sendSessionAccept(getInitiator(), sid, getContents().get(0).getCreator(), + getContents().get(0).getName(), JingleContent.Senders.initiator, file, + transportSession.createTransport()); + } catch (SmackException.NotConnectedException | SmackException.NoResponseException | + XMPPException.XMPPErrorException | InterruptedException e) { + LOGGER.log(Level.WARNING, "Could not send session-accept.", e); } } @@ -164,7 +171,8 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement state = State.terminated; try { jutil.sendSessionTerminateDecline(request.getInitiator(), request.getSid()); - } catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException e) { + } catch (SmackException.NotConnectedException | SmackException.NoResponseException | + XMPPException.XMPPErrorException | InterruptedException e) { LOGGER.log(Level.SEVERE, "Could not send session-terminate: " + e, e); } } diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java index f7d82bf49..5bb5c36ec 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/JingleFileTransferSession.java @@ -20,7 +20,6 @@ import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smackx.jingle.JingleSession; import org.jivesoftware.smackx.jingle.JingleUtil; import org.jivesoftware.smackx.jingle.Role; -import org.jivesoftware.smackx.jingle.element.JingleContent; import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer; import org.jxmpp.jid.FullJid; @@ -39,8 +38,6 @@ public abstract class JingleFileTransferSession extends JingleSession { protected final XMPPConnection connection; protected final JingleUtil jutil; - protected JingleContent.Creator creator; - protected String name; protected JingleFileTransfer file; private final Type type; diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java index c4459899c..1f96d37a8 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/jingle_filetransfer/OutgoingJingleFileOffer.java @@ -147,12 +147,14 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession { if (replacementManager != null) { LOGGER.log(Level.INFO, "Accept transport-replace."); jutil.sendTransportAccept(transportReplace.getFrom().asFullJidOrThrow(), - transportReplace.getInitiator(), transportReplace.getSid(), creator, name, + transportReplace.getInitiator(), transportReplace.getSid(), + getContents().get(0).getCreator(), getContents().get(0).getName(), transportSession.createTransport()); } else { LOGGER.log(Level.INFO, "Unsupported transport. Reject transport-replace."); jutil.sendTransportReject(transportReplace.getFrom().asFullJidOrThrow(), transportReplace.getInitiator(), - transportReplace.getSid(), creator, name, transportReplace.getContents().get(0).getJingleTransport()); + transportReplace.getSid(), getContents().get(0).getCreator(), + getContents().get(0).getName(), transportReplace.getContents().get(0).getJingleTransport()); } } catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) { LOGGER.log(Level.SEVERE, "Help me please!", e); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java index b5955f32b..b90f53046 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/JingleSession.java @@ -17,6 +17,7 @@ package org.jivesoftware.smackx.jingle; import java.util.ArrayList; +import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -27,6 +28,7 @@ import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smackx.jingle.element.Jingle; +import org.jivesoftware.smackx.jingle.element.JingleContent; import org.jivesoftware.smackx.jingle.transports.JingleTransportSession; import org.jxmpp.jid.FullJid; @@ -42,11 +44,17 @@ public abstract class JingleSession implements JingleSessionHandler { protected final String sid; + protected final List contents = new ArrayList<>(); + protected ExecutorService threadPool = Executors.newSingleThreadExecutor(); protected ArrayList> queued = new ArrayList<>(); protected JingleTransportSession transportSession; public JingleSession(FullJid initiator, FullJid responder, Role role, String sid) { + this(initiator, responder, role, sid, null); + } + + public JingleSession(FullJid initiator, FullJid responder, Role role, String sid, List contents) { if (role == Role.initiator) { this.local = initiator; this.remote = responder; @@ -56,6 +64,10 @@ public abstract class JingleSession implements JingleSessionHandler { } this.sid = sid; this.role = role; + + if (contents != null) { + this.contents.addAll(contents); + } } public FullJid getInitiator() { @@ -90,6 +102,10 @@ public abstract class JingleSession implements JingleSessionHandler { return new FullJidAndSessionId(remote, sid); } + public List getContents() { + return contents; + } + public JingleTransportSession getTransportSession() { return transportSession; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportSession.java index fdd3c0653..26ff5028e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/JingleTransportSession.java @@ -59,9 +59,5 @@ public abstract class JingleTransportSession { public abstract IQ handleTransportInfo(Jingle transportInfo); - public void setRemoteTransport(JingleContentTransport remoteTransport) { - this.remoteTransport = remoteTransport; - } - public abstract JingleTransportManager transportManager(); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_ibb/JingleIBBTransportSession.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_ibb/JingleIBBTransportSession.java index 27f9ceec3..85c9c1838 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_ibb/JingleIBBTransportSession.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_ibb/JingleIBBTransportSession.java @@ -89,7 +89,6 @@ public class JingleIBBTransportSession extends JingleTransportSession