mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-12 15:22:05 +01:00
Add S5B candidate accept/error
This commit is contained in:
parent
a101de29fd
commit
699a19d3c2
8 changed files with 118 additions and 32 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<JingleContent> contents = new ArrayList<>();
|
||||
|
||||
protected ExecutorService threadPool = Executors.newSingleThreadExecutor();
|
||||
protected ArrayList<Future<?>> 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<JingleContent> 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<JingleContent> getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
public JingleTransportSession<?> getTransportSession() {
|
||||
return transportSession;
|
||||
}
|
||||
|
|
|
@ -59,9 +59,5 @@ public abstract class JingleTransportSession<T extends JingleContentTransport> {
|
|||
|
||||
public abstract IQ handleTransportInfo(Jingle transportInfo);
|
||||
|
||||
public void setRemoteTransport(JingleContentTransport remoteTransport) {
|
||||
this.remoteTransport = remoteTransport;
|
||||
}
|
||||
|
||||
public abstract JingleTransportManager<T> transportManager();
|
||||
}
|
||||
|
|
|
@ -89,7 +89,6 @@ public class JingleIBBTransportSession extends JingleTransportSession<JingleIBBT
|
|||
public void incomingBytestreamRequest(BytestreamRequest request) {
|
||||
if (request.getFrom().asFullJidIfPossible().equals(jingleSession.get().getRemote())
|
||||
&& request.getSessionID().equals(ibbTransport.getSessionId())) {
|
||||
LOGGER.log(Level.INFO,"MATCH! Create bytesteam session.");
|
||||
BytestreamSession session;
|
||||
|
||||
try {
|
||||
|
@ -99,8 +98,6 @@ public class JingleIBBTransportSession extends JingleTransportSession<JingleIBBT
|
|||
return;
|
||||
}
|
||||
callback.onSessionInitiated(session);
|
||||
} else {
|
||||
LOGGER.log(Level.SEVERE, "MISSMATCH");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -30,12 +30,16 @@ import org.jivesoftware.smack.packet.IQ;
|
|||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportSession;
|
||||
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport;
|
||||
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.provider.JingleS5BTransportProvider;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
|
@ -131,4 +135,40 @@ public final class JingleS5BTransportManager extends JingleTransportManager<Jing
|
|||
LOGGER.log(Level.WARNING, "Could not query available StreamHosts: " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
public Jingle createCandidateUsed(FullJid recipient, String sessionId, JingleContent.Senders contentSenders,
|
||||
JingleContent.Creator contentCreator, String contentName, String streamId,
|
||||
String candidateId) {
|
||||
Jingle.Builder jb = Jingle.getBuilder();
|
||||
jb.setSessionId(sessionId).setInitiator(recipient).setAction(JingleAction.transport_info);
|
||||
|
||||
JingleContent.Builder cb = JingleContent.getBuilder();
|
||||
cb.setName(contentName).setCreator(contentCreator).setSenders(contentSenders);
|
||||
|
||||
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
|
||||
tb.setCandidateUsed(candidateId).setStreamId(streamId);
|
||||
|
||||
Jingle jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
|
||||
jingle.setFrom(getConnection().getUser().asFullJidOrThrow());
|
||||
jingle.setTo(recipient);
|
||||
|
||||
return jingle;
|
||||
}
|
||||
|
||||
public Jingle createCandidateError(FullJid remote, String sessionId, JingleContent.Senders senders, JingleContent.Creator creator, String name, String streamId) {
|
||||
Jingle.Builder jb = Jingle.getBuilder();
|
||||
jb.setSessionId(sessionId).setInitiator(remote).setAction(JingleAction.transport_info);
|
||||
|
||||
JingleContent.Builder cb = JingleContent.getBuilder();
|
||||
cb.setName(name).setCreator(creator).setSenders(senders);
|
||||
|
||||
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
|
||||
tb.setCandidateError();
|
||||
|
||||
Jingle jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
|
||||
jingle.setFrom(getConnection().getUser().asFullJidOrThrow());
|
||||
jingle.setTo(remote);
|
||||
|
||||
return jingle;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
|||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||
|
@ -47,6 +48,9 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportSession.class.getName());
|
||||
private final JingleS5BTransportManager transportManager;
|
||||
|
||||
private Socket connectedSocket;
|
||||
private JingleS5BTransportCandidate usedCandidate;
|
||||
|
||||
public JingleS5BTransportSession(JingleSession jingleSession) {
|
||||
super(jingleSession);
|
||||
transportManager = JingleS5BTransportManager.getInstanceFor(jingleSession.getConnection());
|
||||
|
@ -91,6 +95,11 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
|
||||
@Override
|
||||
public void initiateOutgoingSession(JingleTransportInitiationCallback callback) {
|
||||
JingleSession jSession = jingleSession.get();
|
||||
if (jSession == null) {
|
||||
throw new NullPointerException("Lost reference to jingleSession.");
|
||||
}
|
||||
|
||||
JingleS5BTransport receivedTransport = (JingleS5BTransport) remoteTransport;
|
||||
|
||||
Socket socket = null;
|
||||
|
@ -112,8 +121,29 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
+ receivedTransport.getDestinationAddress());
|
||||
}
|
||||
|
||||
if (socket != null) {
|
||||
JingleContent content = jSession.getContents().get(0);
|
||||
|
||||
Jingle response;
|
||||
|
||||
if (socket != null) {
|
||||
connectedSocket = socket;
|
||||
usedCandidate = workedForUs;
|
||||
|
||||
response = transportManager.createCandidateUsed(jSession.getRemote(),
|
||||
jSession.getSessionId(), content.getSenders(), content.getCreator(),
|
||||
content.getName(), receivedTransport.getStreamId(), usedCandidate.getCandidateId());
|
||||
|
||||
} else {
|
||||
response = transportManager.createCandidateError(jSession.getRemote(),
|
||||
jSession.getSessionId(), content.getSenders(), content.getCreator(),
|
||||
content.getName(), receivedTransport.getStreamId());
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
jSession.getConnection().sendStanza(response);
|
||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||
LOGGER.log(Level.WARNING, "Could not send candidate-used.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue