mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-26 04:28:00 +01:00
More progress
This commit is contained in:
parent
09548855dd
commit
5ebd07ac3c
2 changed files with 105 additions and 37 deletions
|
@ -177,4 +177,16 @@ public final class JingleS5BTransportManager extends JingleTransportManager<Jing
|
|||
return jingle;
|
||||
}
|
||||
|
||||
public Jingle createProxyError(FullJid remote, String sessionId, JingleContent.Senders senders, JingleContent.Creator creator, String name, String streamId) {
|
||||
Jingle.Builder jb = Jingle.getBuilder();
|
||||
jb.setSessionId(sessionId).setAction(JingleAction.transport_info);
|
||||
|
||||
|
||||
|
||||
Jingle jingle = jb.build();
|
||||
jingle.setTo(remote);
|
||||
jingle.setFrom(getConnection().getUser().asFullJidOrThrow());
|
||||
return jingle;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.util.logging.Logger;
|
|||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Client;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5ClientForInitiator;
|
||||
|
@ -35,6 +34,7 @@ import org.jivesoftware.smackx.bytestreams.socks5.Socks5Utils;
|
|||
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.JingleUtil;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate;
|
||||
|
@ -53,6 +53,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportSession.class.getName());
|
||||
private final JingleS5BTransportManager transportManager;
|
||||
|
||||
private final JingleUtil jutil;
|
||||
private Socket connectedSocket;
|
||||
private JingleS5BTransportCandidate localUsedCandidate;
|
||||
private JingleS5BTransportCandidate remoteUsedCandidate;
|
||||
|
@ -63,6 +64,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
public JingleS5BTransportSession(JingleSession jingleSession) {
|
||||
super(jingleSession);
|
||||
transportManager = JingleS5BTransportManager.getInstanceFor(jingleSession.getConnection());
|
||||
jutil = new JingleUtil(jingleSession.getConnection());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -184,6 +186,7 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private JingleS5BTransportCandidate determineUsedCandidate() {
|
||||
|
@ -226,37 +229,93 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
|
||||
if (remoteUsedCandidate == null) {
|
||||
callback.onException(new Exception("Unknown candidate"));
|
||||
return IQ.createResultIQ(candidateUsed);
|
||||
return jutil.createErrorMalformedRequest(candidateUsed);
|
||||
}
|
||||
|
||||
if (localUsedCandidate != null) {
|
||||
JingleS5BTransportCandidate used = determineUsedCandidate();
|
||||
|
||||
// Our candidate is nominated.
|
||||
if (used == remoteUsedCandidate) {
|
||||
|
||||
if (used.getType() == JingleS5BTransportCandidate.Type.proxy) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
callback.onSessionInitiated();
|
||||
}
|
||||
// Remotes candidate is nominated.
|
||||
else {
|
||||
if (connectedSocket != null) {
|
||||
callback.onSessionInitiated(new Socks5BytestreamSession(connectedSocket,
|
||||
used.getJid().asBareJid().equals(jingleSession.get().getRemote().asBareJid())));
|
||||
} else {
|
||||
throw new AssertionError("Connected socket is null.");
|
||||
}
|
||||
}
|
||||
connect(determineUsedCandidate());
|
||||
}
|
||||
|
||||
return IQ.createResultIQ(candidateUsed);
|
||||
}
|
||||
|
||||
private void connect(JingleS5BTransportCandidate candidate) {
|
||||
JingleSession jSession = jingleSession.get();
|
||||
if (jSession == null) {
|
||||
throw new NullPointerException("Lost reference to JingleSession.");
|
||||
}
|
||||
// Used candidate belongs to remote.
|
||||
if (candidate == localUsedCandidate) {
|
||||
|
||||
if (connectedSocket != null) {
|
||||
callback.onSessionInitiated(new Socks5BytestreamSession(connectedSocket,
|
||||
candidate.getJid().asBareJid().equals(jSession.getRemote().asBareJid())));
|
||||
}
|
||||
else {
|
||||
throw new AssertionError("Connected socket is null.");
|
||||
}
|
||||
}
|
||||
|
||||
// Used candidate belongs to us.
|
||||
else {
|
||||
|
||||
if (candidate.getType() == JingleS5BTransportCandidate.Type.proxy) {
|
||||
|
||||
if (candidate.getJid().asBareJid().equals(jSession.getLocal().asBareJid())) {
|
||||
|
||||
Socks5ClientForInitiator socks5Client = new Socks5ClientForInitiator(candidate.getStreamHost(),
|
||||
((JingleS5BTransport) localTransport).getDestinationAddress(),
|
||||
jSession.getConnection(), ((JingleS5BTransport) localTransport).getStreamId(),
|
||||
jSession.getLocal());
|
||||
try {
|
||||
connectedSocket = socks5Client.getSocket(10 * 1000);
|
||||
} catch (IOException | XMPPException | SmackException | InterruptedException | TimeoutException e) {
|
||||
callback.onException(e);
|
||||
return;
|
||||
}
|
||||
callback.onSessionInitiated(new Socks5BytestreamSession(connectedSocket, true));
|
||||
} else {
|
||||
Bytestream activateProxy = new Bytestream(((JingleS5BTransport) localTransport).getStreamId());
|
||||
activateProxy.setToActivate(candidate.getJid());
|
||||
activateProxy.setTo(candidate.getJid());
|
||||
try {
|
||||
jSession.getConnection().createStanzaCollectorAndSend(activateProxy).nextResultOrThrow();
|
||||
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not activate proxy server: " + e, e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IQ handleCandidateActivated(Jingle candidateActivated) {
|
||||
|
||||
return IQ.createResultIQ(candidateActivated);
|
||||
}
|
||||
|
||||
public IQ handleCandidateError(Jingle candidateError) {
|
||||
remoteError = true;
|
||||
|
||||
closeIfBothSidesFailed();
|
||||
|
||||
if (localUsedCandidate.getType() != JingleS5BTransportCandidate.Type.proxy) {
|
||||
//TODO: Connect
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
return IQ.createResultIQ(candidateError);
|
||||
}
|
||||
|
||||
public IQ handleProxyError(Jingle proxyError) {
|
||||
|
||||
return IQ.createResultIQ(proxyError);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return transportManager.getNamespace();
|
||||
|
@ -266,30 +325,27 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
public IQ handleTransportInfo(Jingle transportInfo) {
|
||||
JingleS5BTransport transport = (JingleS5BTransport) transportInfo.getContents().get(0).getJingleTransport();
|
||||
JingleS5BTransportInfo info = (JingleS5BTransportInfo) transport.getInfos().get(0);
|
||||
if (info != null) {
|
||||
switch (info.getElementName()) {
|
||||
|
||||
if (info != null) {
|
||||
|
||||
switch (info.getElementName()) {
|
||||
case JingleS5BTransportInfo.CandidateUsed.ELEMENT:
|
||||
return handleCandidateUsed(transportInfo);
|
||||
|
||||
case JingleS5BTransportInfo.CandidateActivated.ELEMENT:
|
||||
return handleCandidateActivated(transportInfo);
|
||||
|
||||
case JingleS5BTransportInfo.CandidateError.ELEMENT:
|
||||
remoteError = true;
|
||||
|
||||
closeIfBothSidesFailed();
|
||||
|
||||
if (localUsedCandidate.getType() != JingleS5BTransportCandidate.Type.proxy) {
|
||||
//TODO: Connect
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
return handleCandidateError(transportInfo);
|
||||
|
||||
case JingleS5BTransportInfo.ProxyError.ELEMENT:
|
||||
return handleProxyError(transportInfo);
|
||||
|
||||
default:
|
||||
return IQ.createResultIQ(transportInfo);
|
||||
}
|
||||
} else {
|
||||
return jutil.createErrorMalformedRequest(transportInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue