mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-16 12:12:06 +01:00
Add Public IP Disco for STUN Services
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7681 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
f19bedac1f
commit
2e06fdad64
2 changed files with 36 additions and 1 deletions
|
@ -35,6 +35,10 @@ import org.xmlpull.v1.XmlPullParser;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* STUN IQ Packet used to request and retrieve a STUN server and port to make p2p connections easier. STUN is usually used by Jingle Media Transmission between two parties that are behind NAT.
|
||||
|
@ -49,6 +53,8 @@ public class STUN extends IQ {
|
|||
|
||||
private List<StunServerAddress> servers = new ArrayList<StunServerAddress>();
|
||||
|
||||
private String publicIp = null;
|
||||
|
||||
/**
|
||||
* Element name of the packet extension.
|
||||
*/
|
||||
|
@ -83,6 +89,24 @@ public class STUN extends IQ {
|
|||
return servers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Public Ip returned from the XMPP server
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPublicIp() {
|
||||
return publicIp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Public Ip returned from the XMPP server
|
||||
*
|
||||
* @param publicIp
|
||||
*/
|
||||
private void setPublicIp(String publicIp) {
|
||||
this.publicIp = publicIp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Child Element XML of the Packet
|
||||
*
|
||||
|
@ -138,6 +162,15 @@ public class STUN extends IQ {
|
|||
if (host != null && port != null)
|
||||
iq.servers.add(new StunServerAddress(host, port));
|
||||
}
|
||||
else if (elementName.equals("publicip")) {
|
||||
String host = null;
|
||||
for (int i = 0; i < parser.getAttributeCount(); i++) {
|
||||
if (parser.getAttributeName(i).equals("ip"))
|
||||
host = parser.getAttributeValue(i);
|
||||
}
|
||||
if (host != null && !host.equals(""))
|
||||
iq.setPublicIp(host);
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals(ELEMENT_NAME)) {
|
||||
|
|
|
@ -172,6 +172,8 @@ public class STUNResolverTest extends SmackTestCase {
|
|||
for (STUN.StunServerAddress stunServerAddress : stun.getServers())
|
||||
System.out.println(stunServerAddress.getServer() + ":" + stunServerAddress.getPort());
|
||||
|
||||
System.out.println(stun.getPublicIp());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue