mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-27 06:22:07 +01:00
Temp
This commit is contained in:
parent
366dbf66d6
commit
064af388b4
4 changed files with 44 additions and 11 deletions
|
@ -48,6 +48,7 @@ import org.jivesoftware.smackx.jingle.exception.UnsupportedJingleTransportExcept
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.JingleFileTransferCallback;
|
import org.jivesoftware.smackx.jingle_filetransfer.callback.JingleFileTransferCallback;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferContentDescription;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferContentDescription;
|
||||||
|
import org.jivesoftware.smackx.jingle_ibb.element.JingleIBBTransport;
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,6 +79,7 @@ public class JingleFileTransferSession extends AbstractJingleSession {
|
||||||
this.sessionId = StringUtils.randomString(24);
|
this.sessionId = StringUtils.randomString(24);
|
||||||
this.role = JingleContent.Creator.initiator;
|
this.role = JingleContent.Creator.initiator;
|
||||||
|
|
||||||
|
//Create file content element
|
||||||
JingleFileTransferChild fileTransferChild = fileElementFromFile(send);
|
JingleFileTransferChild fileTransferChild = fileElementFromFile(send);
|
||||||
JingleContent.Builder cb = JingleContent.getBuilder();
|
JingleContent.Builder cb = JingleContent.getBuilder();
|
||||||
cb.setSenders(JingleContent.Senders.initiator)
|
cb.setSenders(JingleContent.Senders.initiator)
|
||||||
|
@ -88,7 +90,7 @@ public class JingleFileTransferSession extends AbstractJingleSession {
|
||||||
try {
|
try {
|
||||||
cb.addTransport(defaultTransport());
|
cb.addTransport(defaultTransport());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new AssertionError("At least IBB should work. " + e);
|
throw new AssertionError("At least IBB should work as a transport method. " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.proposedContent = cb.build();
|
this.proposedContent = cb.build();
|
||||||
|
@ -423,7 +425,14 @@ public class JingleFileTransferSession extends AbstractJingleSession {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSessionFailure(JingleTransportFailureException reason) {
|
public void onSessionFailure(JingleTransportFailureException reason) {
|
||||||
//TODO: Send transport-failed or so.
|
//TODO: Send transport-replace to fall back to IBB
|
||||||
|
// Do we already use IBB?
|
||||||
|
if (transportHandler.getNamespace().equals(JingleIBBTransport.NAMESPACE_V1)) {
|
||||||
|
//fail
|
||||||
|
} else {
|
||||||
|
Jingle.Builder jb = Jingle.getBuilder();
|
||||||
|
jb.setAction(JingleAction.transport_replace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -436,7 +445,7 @@ public class JingleFileTransferSession extends AbstractJingleSession {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSessionFailure(JingleTransportFailureException reason) {
|
public void onSessionFailure(JingleTransportFailureException reason) {
|
||||||
//TODO: Send transport failed
|
LOGGER.log(Level.SEVERE, "SESSION FAILIURE: ", reason);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,11 @@ public class JingleIBBTransportHandler implements JingleTransportHandler<JingleI
|
||||||
return jingleSessionHandler.getConnection();
|
return jingleSessionHandler.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNamespace() {
|
||||||
|
return JingleIBBTransport.NAMESPACE_V1;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTransportInfoReceived(Jingle transportInfo) {
|
public boolean onTransportInfoReceived(Jingle transportInfo) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate;
|
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate;
|
||||||
|
import org.jivesoftware.smackx.jingle.exception.JingleTransportFailureException;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransport;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportCandidate;
|
||||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportInfo;
|
import org.jivesoftware.smackx.jingle_s5b.elements.JingleS5BTransportInfo;
|
||||||
|
@ -109,6 +110,7 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch (TimeoutException | IOException | SmackException | XMPPException | InterruptedException e) {
|
catch (TimeoutException | IOException | SmackException | XMPPException | InterruptedException e) {
|
||||||
|
//We cannot connect to transport candidate. Try others...
|
||||||
LOGGER.log(Level.WARNING, "Could not connect to " + address + ": " + e, e);
|
LOGGER.log(Level.WARNING, "Could not connect to " + address + ": " + e, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +140,7 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
try {
|
try {
|
||||||
getConnection().sendStanza(jingle);
|
getConnection().sendStanza(jingle);
|
||||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not send candidate-used transport-info: " + e, e);
|
callback.onSessionFailure(new JingleTransportFailureException(e));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//Candidate error
|
//Candidate error
|
||||||
|
@ -168,7 +170,7 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
try {
|
try {
|
||||||
getConnection().sendStanza(jingle);
|
getConnection().sendStanza(jingle);
|
||||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not send candidate-error transport-info: " + e, e);
|
callback.onSessionFailure(new JingleTransportFailureException(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,6 +182,11 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
return sessionHandler.getConnection();
|
return sessionHandler.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNamespace() {
|
||||||
|
return JingleS5BTransport.NAMESPACE_V1;
|
||||||
|
}
|
||||||
|
|
||||||
private interface JingleS5BTransportHandlerInterface {
|
private interface JingleS5BTransportHandlerInterface {
|
||||||
boolean onTransportInfoReceived(Jingle transportInfo);
|
boolean onTransportInfoReceived(Jingle transportInfo);
|
||||||
}
|
}
|
||||||
|
@ -216,7 +223,7 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
|
|
||||||
if (usedCandidate == null) {
|
if (usedCandidate == null) {
|
||||||
//Error unknown candidate.
|
//Error unknown candidate.
|
||||||
|
//TODO: Ignore? Not specified in xep-0260
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//We already have a remote candidate selected.
|
//We already have a remote candidate selected.
|
||||||
|
@ -244,6 +251,7 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
}
|
}
|
||||||
catch (TimeoutException | IOException | SmackException | XMPPException | InterruptedException e) {
|
catch (TimeoutException | IOException | SmackException | XMPPException | InterruptedException e) {
|
||||||
LOGGER.log(Level.WARNING, "Could not connect to own proxy at " + address + ": " + e, e);
|
LOGGER.log(Level.WARNING, "Could not connect to own proxy at " + address + ": " + e, e);
|
||||||
|
callback.onSessionFailure(new JingleTransportFailureException(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,13 +267,14 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
parent.remoteCandidateError = true;
|
parent.remoteCandidateError = true;
|
||||||
if (parent.localCandidateError) {
|
if (parent.localCandidateError) {
|
||||||
//Session transport-failed
|
//Session transport-failed
|
||||||
|
//TODO: Fallback
|
||||||
} else {
|
} else {
|
||||||
state = new CandidateUsedReceived(parent);
|
state = new CandidateUsedReceived(parent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JingleS5BTransportInfo.ProxyError.ELEMENT:
|
case JingleS5BTransportInfo.ProxyError.ELEMENT:
|
||||||
|
//???
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,10 +299,16 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
JingleS5BTransport transport = (JingleS5BTransport) content.getJingleTransports().get(0);
|
JingleS5BTransport transport = (JingleS5BTransport) content.getJingleTransports().get(0);
|
||||||
JingleS5BTransportInfo info = (JingleS5BTransportInfo) transport.getInfos().get(0);
|
JingleS5BTransportInfo info = (JingleS5BTransportInfo) transport.getInfos().get(0);
|
||||||
|
|
||||||
if (info.getElementName().equals(JingleS5BTransportInfo.CandidateActivated.ELEMENT)) {
|
if (JingleS5BTransportInfo.CandidateActivated.ELEMENT.equals(info.getElementName())) {
|
||||||
//TODO: Check if same candidate
|
JingleS5BTransportInfo.CandidateActivated candidateActivated =
|
||||||
LOGGER.log(Level.INFO, "Established connection with " + parent.usedCandidate.getHost());
|
(JingleS5BTransportInfo.CandidateActivated) info;
|
||||||
callback.onSessionEstablished(new Socks5BytestreamSession(parent.connectedSocket, parent.usedCandidate.getType() == JingleS5BTransportCandidate.Type.direct));
|
|
||||||
|
if (!parent.usedCandidate.getCandidateId().equals(candidateActivated.getCandidateId())) {
|
||||||
|
//TODO: Unknown candidate. Not specified in xep-0260?
|
||||||
|
} else {
|
||||||
|
LOGGER.log(Level.INFO, "Established connection with " + parent.usedCandidate.getHost());
|
||||||
|
callback.onSessionEstablished(new Socks5BytestreamSession(parent.connectedSocket, parent.usedCandidate.getType() == JingleS5BTransportCandidate.Type.direct));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -315,6 +330,7 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
getConnection().createStanzaCollectorAndSend(activateProxy).nextResultOrThrow();
|
getConnection().createStanzaCollectorAndSend(activateProxy).nextResultOrThrow();
|
||||||
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
|
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not activate proxy server: " + e, e);
|
LOGGER.log(Level.SEVERE, "Could not activate proxy server: " + e, e);
|
||||||
|
callback.onSessionFailure(new JingleTransportFailureException(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,6 +363,7 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
getConnection().sendStanza(j);
|
getConnection().sendStanza(j);
|
||||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Could not send candidate-activated : " + e, e);
|
LOGGER.log(Level.SEVERE, "Could not send candidate-activated : " + e, e);
|
||||||
|
callback.onSessionFailure(new JingleTransportFailureException(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.log(Level.INFO, "Established connection with " + parent.usedCandidate.getHost());
|
LOGGER.log(Level.INFO, "Established connection with " + parent.usedCandidate.getHost());
|
||||||
|
|
|
@ -31,4 +31,6 @@ public interface JingleTransportHandler<D extends JingleContentTransport> extend
|
||||||
void establishIncomingSession(JingleTransportEstablishedCallback callback);
|
void establishIncomingSession(JingleTransportEstablishedCallback callback);
|
||||||
|
|
||||||
XMPPConnection getConnection();
|
XMPPConnection getConnection();
|
||||||
|
|
||||||
|
String getNamespace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue