mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
More Progress
This commit is contained in:
parent
4feda2ffa9
commit
1cd59370e6
2 changed files with 106 additions and 77 deletions
|
@ -504,11 +504,6 @@ public class JingleFileTransferSession extends AbstractJingleSession {
|
||||||
return state.handleTransportAccept(transportAccept);
|
return state.handleTransportAccept(transportAccept);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected IQ handleTransportInfo(Jingle transportInfo) {
|
|
||||||
return state.handleTransportInfo(transportInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IQ handleTransportReplace(Jingle transportReplace) {
|
protected IQ handleTransportReplace(Jingle transportReplace) {
|
||||||
return state.handleTransportReplace(transportReplace);
|
return state.handleTransportReplace(transportReplace);
|
||||||
|
|
|
@ -52,9 +52,14 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
|
|
||||||
private final WeakReference<JingleSessionHandler> sessionHandler;
|
private final WeakReference<JingleSessionHandler> sessionHandler;
|
||||||
|
|
||||||
|
private JingleManager.FullJidAndSessionId fullJidAndSessionId;
|
||||||
|
private JingleContent receivedContent;
|
||||||
|
private JingleContent proposedContent;
|
||||||
|
private JingleTransportEstablishedCallback callback;
|
||||||
private JingleS5BTransport myTransport;
|
private JingleS5BTransport myTransport;
|
||||||
|
|
||||||
private JingleS5BTransportCandidate receivedCandidateUsed = null;
|
private JingleS5BTransportCandidate receivedCandidateUsed = null;
|
||||||
|
private JingleS5BTransportCandidate selectedCandidateUsed = null;
|
||||||
|
|
||||||
private Socket connectedSocket = null;
|
private Socket connectedSocket = null;
|
||||||
|
|
||||||
|
@ -88,6 +93,10 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
JingleContent receivedContent,
|
JingleContent receivedContent,
|
||||||
JingleContent proposedContent,
|
JingleContent proposedContent,
|
||||||
JingleTransportEstablishedCallback callback) {
|
JingleTransportEstablishedCallback callback) {
|
||||||
|
this.fullJidAndSessionId = fullJidAndSessionId;
|
||||||
|
this.receivedContent = receivedContent;
|
||||||
|
this.proposedContent = proposedContent;
|
||||||
|
this.callback = callback;
|
||||||
|
|
||||||
JingleContentTransport hopefullyS5BTransport = receivedContent.getJingleTransports().get(0);
|
JingleContentTransport hopefullyS5BTransport = receivedContent.getJingleTransports().get(0);
|
||||||
if (!hopefullyS5BTransport.getNamespace().equals(JingleS5BTransport.NAMESPACE_V1)) {
|
if (!hopefullyS5BTransport.getNamespace().equals(JingleS5BTransport.NAMESPACE_V1)) {
|
||||||
|
@ -110,17 +119,10 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
LOGGER.log(Level.INFO, "Connect to " + address);
|
LOGGER.log(Level.INFO, "Connect to " + address);
|
||||||
// establish socket
|
// establish socket
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// build SOCKS5 client
|
|
||||||
final Socks5Client socks5Client = new Socks5Client(streamHost, transport.getDestinationAddress());
|
final Socks5Client socks5Client = new Socks5Client(streamHost, transport.getDestinationAddress());
|
||||||
|
|
||||||
// connect to SOCKS5 proxy with a timeout
|
|
||||||
connectedSocket = socks5Client.getSocket(10 * 1000);
|
connectedSocket = socks5Client.getSocket(10 * 1000);
|
||||||
|
selectedCandidateUsed = usedCandidate;
|
||||||
|
|
||||||
// set selected host
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (TimeoutException | IOException | SmackException | XMPPException | InterruptedException e) {
|
catch (TimeoutException | IOException | SmackException | XMPPException | InterruptedException e) {
|
||||||
LOGGER.log(Level.WARNING, "Could not connect to " + address + ": " + e, e);
|
LOGGER.log(Level.WARNING, "Could not connect to " + address + ": " + e, e);
|
||||||
|
@ -128,6 +130,42 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connectedSocket != null) {
|
if (connectedSocket != null) {
|
||||||
|
//Send candidate-used
|
||||||
|
Jingle jingle = createCandidateUsed(usedCandidate, fullJidAndSessionId, receivedContent);
|
||||||
|
try {
|
||||||
|
getConnection().sendStanza(jingle);
|
||||||
|
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||||
|
LOGGER.log(Level.WARNING, "Could not send candidate-used stanza: " + e, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void activateProxy() {
|
||||||
|
//Activate proxy
|
||||||
|
if (selectedCandidateUsed.getType() == JingleS5BTransportCandidate.Type.proxy) {
|
||||||
|
Bytestream bytestream = new Bytestream(fullJidAndSessionId.getSessionId());
|
||||||
|
bytestream.setToActivate(fullJidAndSessionId.getFullJid());
|
||||||
|
bytestream.setTo(fullJidAndSessionId.getFullJid());
|
||||||
|
try {
|
||||||
|
getConnection().sendStanza(bytestream);
|
||||||
|
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||||
|
LOGGER.log(Level.WARNING, "Could not activate proxy: " + e, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Jingle activate = createCandidateActive(selectedCandidateUsed, fullJidAndSessionId, receivedContent);
|
||||||
|
try {
|
||||||
|
getConnection().sendStanza(activate);
|
||||||
|
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||||
|
LOGGER.log(Level.SEVERE, "Could not send transport-activated: " + e, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback.onSessionEstablished(new Socks5BytestreamSession(connectedSocket, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
Jingle createCandidateUsed(JingleS5BTransportCandidate usedCandidate, JingleManager.FullJidAndSessionId fullJidAndSessionId, JingleContent receivedContent) {
|
||||||
Jingle.Builder jb = Jingle.getBuilder();
|
Jingle.Builder jb = Jingle.getBuilder();
|
||||||
jb.setSessionId(fullJidAndSessionId.getSessionId())
|
jb.setSessionId(fullJidAndSessionId.getSessionId())
|
||||||
.setAction(JingleAction.transport_info)
|
.setAction(JingleAction.transport_info)
|
||||||
|
@ -148,34 +186,20 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
Jingle jingle = jb.build();
|
Jingle jingle = jb.build();
|
||||||
jingle.setFrom(getConnection().getUser());
|
jingle.setFrom(getConnection().getUser());
|
||||||
jingle.setTo(fullJidAndSessionId.getFullJid());
|
jingle.setTo(fullJidAndSessionId.getFullJid());
|
||||||
try {
|
return jingle;
|
||||||
getConnection().sendStanza(jingle);
|
|
||||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
|
||||||
LOGGER.log(Level.WARNING, "Could not send candidate-used stanza: " + e, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Activate proxy
|
Jingle createCandidateActive(JingleS5BTransportCandidate usedCandidate, JingleManager.FullJidAndSessionId fullJidAndSessionId, JingleContent receivedContent) {
|
||||||
if (usedCandidate.getType() == JingleS5BTransportCandidate.Type.proxy) {
|
Jingle.Builder jb = Jingle.getBuilder();
|
||||||
Bytestream bytestream = new Bytestream(fullJidAndSessionId.getSessionId());
|
|
||||||
bytestream.setToActivate(fullJidAndSessionId.getFullJid());
|
|
||||||
bytestream.setTo(usedCandidate.getJid());
|
|
||||||
try {
|
|
||||||
getConnection().sendStanza(bytestream);
|
|
||||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
|
||||||
LOGGER.log(Level.WARNING, "Could not activate proxy: " + e, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
jb = Jingle.getBuilder();
|
|
||||||
jb.setAction(JingleAction.transport_info)
|
jb.setAction(JingleAction.transport_info)
|
||||||
.setSessionId(fullJidAndSessionId.getSessionId());
|
.setSessionId(fullJidAndSessionId.getSessionId())
|
||||||
//TODO: setInitiator
|
.setInitiator(fullJidAndSessionId.getFullJid());
|
||||||
|
|
||||||
cb = JingleContent.getBuilder();
|
JingleContent.Builder cb = JingleContent.getBuilder();
|
||||||
cb.setCreator(JingleContent.Creator.initiator)
|
cb.setCreator(JingleContent.Creator.initiator)
|
||||||
.setName(receivedContent.getName());
|
.setName(receivedContent.getName());
|
||||||
|
|
||||||
tb = JingleS5BTransport.getBuilder();
|
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
|
||||||
tb.setStreamId(((JingleS5BTransport) receivedContent.getJingleTransports().get(0)).getStreamId());
|
tb.setStreamId(((JingleS5BTransport) receivedContent.getJingleTransports().get(0)).getStreamId());
|
||||||
tb.setCandidateActivated(usedCandidate.getCandidateId());
|
tb.setCandidateActivated(usedCandidate.getCandidateId());
|
||||||
|
|
||||||
|
@ -186,16 +210,7 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
activate.setTo(fullJidAndSessionId.getFullJid());
|
activate.setTo(fullJidAndSessionId.getFullJid());
|
||||||
activate.setFrom(getConnection().getUser());
|
activate.setFrom(getConnection().getUser());
|
||||||
|
|
||||||
try {
|
return activate;
|
||||||
getConnection().sendStanza(activate);
|
|
||||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
|
||||||
LOGGER.log(Level.SEVERE, "Could not send transport-activated: " + e, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
callback.onSessionEstablished(new Socks5BytestreamSession(connectedSocket, false));
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -204,10 +219,6 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
return handler != null ? handler.getConnection() : null;
|
return handler != null ? handler.getConnection() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReceivedCandidateUsed(JingleS5BTransportCandidate used) {
|
|
||||||
this.receivedCandidateUsed = used;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTransportInfoReceived(Jingle jingle) {
|
public void onTransportInfoReceived(Jingle jingle) {
|
||||||
if (jingle.getAction() != JingleAction.transport_info) {
|
if (jingle.getAction() != JingleAction.transport_info) {
|
||||||
|
@ -223,8 +234,31 @@ public class JingleS5BTransportHandler implements JingleTransportHandler<JingleS
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
throw new IllegalArgumentException("Jingle must contain at least one JingleS5BTransportInfo.");
|
throw new IllegalArgumentException("Jingle must contain at least one JingleS5BTransportInfo.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JingleS5BTransportCandidate finalCandidateUsed;
|
||||||
|
|
||||||
if (info.getElementName().equals(JingleS5BTransportInfo.CandidateUsed.ELEMENT)) {
|
if (info.getElementName().equals(JingleS5BTransportInfo.CandidateUsed.ELEMENT)) {
|
||||||
String candidateUsedId = ((JingleS5BTransportInfo.CandidateUsed) info).getCandidateId();
|
String candidateUsedId = ((JingleS5BTransportInfo.CandidateUsed) info).getCandidateId();
|
||||||
|
for (JingleContentTransportCandidate c : myTransport.getCandidates()) {
|
||||||
|
if (((JingleS5BTransportCandidate) c).getCandidateId().equals(candidateUsedId)) {
|
||||||
|
receivedCandidateUsed = (JingleS5BTransportCandidate) c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (receivedCandidateUsed == null) {
|
||||||
|
//TODO: Unknown candidate.
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void onCandidateUsed() {
|
||||||
|
if (selectedCandidateUsed.getPriority() > receivedCandidateUsed.getPriority()) {
|
||||||
|
activateProxy();
|
||||||
|
} else if (selectedCandidateUsed.getPriority() < receivedCandidateUsed.getPriority()) {
|
||||||
|
//createCandidateActive()
|
||||||
|
} else { //==
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue