mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
Reuse S5B-Managers discovery methods
This commit is contained in:
parent
135f1ed77b
commit
6c0162c341
3 changed files with 24 additions and 36 deletions
|
@ -17,24 +17,20 @@
|
|||
package org.jivesoftware.smackx.jingle_s5b;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.StanzaListener;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
||||
import org.jivesoftware.smackx.jingle.AbstractJingleContentTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleTransportInputStreamCallback;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentTransportProvider;
|
||||
import org.jivesoftware.smackx.jingle_s5b.elements.JingleSocks5BytestreamTransport;
|
||||
import org.jivesoftware.smackx.jingle_s5b.provider.JingleSocks5BytestreamTransportProvider;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
* Manager for JingleSocks5BytestreamTransports.
|
||||
|
@ -45,34 +41,15 @@ public final class JingleSocks5BytestreamTransportManager extends AbstractJingle
|
|||
super(connection);
|
||||
}
|
||||
|
||||
public ArrayList<Bytestream.StreamHost> getProxyIdentities() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
final ArrayList<Bytestream.StreamHost> streamHosts = new ArrayList<>();
|
||||
DiscoverInfo.Feature bytestreams = new DiscoverInfo.Feature(Bytestream.NAMESPACE);
|
||||
ServiceDiscoveryManager dm = ServiceDiscoveryManager.getInstanceFor(connection());
|
||||
DiscoverItems disco = dm.discoverItems(connection().getXMPPServiceDomain());
|
||||
public List<Bytestream.StreamHost> getAvailableStreamHosts() throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
Socks5BytestreamManager s5m = Socks5BytestreamManager.getBytestreamManager(connection());
|
||||
List<Jid> proxies = s5m.determineProxies();
|
||||
return s5m.determineStreamHostInfos(proxies);
|
||||
}
|
||||
|
||||
for (DiscoverItems.Item item : disco.getItems()) {
|
||||
DiscoverInfo info = dm.discoverInfo(item.getEntityID());
|
||||
if (!info.getFeatures().contains(bytestreams)) {
|
||||
continue;
|
||||
}
|
||||
List<DiscoverInfo.Identity> identities = info.getIdentities("proxy", "bytestreams");
|
||||
if (identities.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
Bytestream b = new Bytestream();
|
||||
b.setTo(item.getEntityID());
|
||||
connection().sendIqWithResponseCallback(b, new StanzaListener() {
|
||||
@Override
|
||||
public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException {
|
||||
Bytestream result = (Bytestream) packet;
|
||||
if (result != null) {
|
||||
streamHosts.addAll(result.getStreamHosts());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return streamHosts;
|
||||
public List<Bytestream.StreamHost> getLocalStreamHosts() {
|
||||
return Socks5BytestreamManager.getBytestreamManager(connection())
|
||||
.getLocalStreamHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,6 +20,8 @@ import java.util.logging.Logger;
|
|||
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.jingle.JingleTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
@ -55,6 +57,15 @@ public final class JingleSocks5BytestreamTransportCandidate extends JingleConten
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
public JingleSocks5BytestreamTransportCandidate(Bytestream.StreamHost streamHost, int priority) {
|
||||
this.cid = JingleTransportManager.generateSessionId();
|
||||
this.host = streamHost.getAddress();
|
||||
this.jid = streamHost.getJID();
|
||||
this.port = streamHost.getPort();
|
||||
this.priority = priority;
|
||||
this.type = Type.proxy;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
assisted (120),
|
||||
direct (126),
|
||||
|
|
|
@ -536,7 +536,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
|||
* @throws NotConnectedException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
private List<Jid> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
public List<Jid> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||
XMPPConnection connection = connection();
|
||||
ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
|
||||
|
@ -585,7 +585,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
|||
* @param proxies a list of SOCKS5 proxy JIDs
|
||||
* @return a list of stream hosts containing the IP address an the port
|
||||
*/
|
||||
private List<StreamHost> determineStreamHostInfos(List<Jid> proxies) {
|
||||
public List<StreamHost> determineStreamHostInfos(List<Jid> proxies) {
|
||||
XMPPConnection connection = connection();
|
||||
List<StreamHost> streamHosts = new ArrayList<StreamHost>();
|
||||
|
||||
|
@ -632,7 +632,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
|
|||
* @return the stream host information of the local SOCKS5 proxy or null if local SOCKS5 proxy
|
||||
* is not running
|
||||
*/
|
||||
private List<StreamHost> getLocalStreamHost() {
|
||||
public List<StreamHost> getLocalStreamHost() {
|
||||
XMPPConnection connection = connection();
|
||||
// get local proxy singleton
|
||||
Socks5Proxy socks5Server = Socks5Proxy.getSocks5Proxy();
|
||||
|
|
Loading…
Reference in a new issue