mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-21 04:58:14 +00:00
add stun client
git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@88 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
This commit is contained in:
parent
d2aba13275
commit
3162faaaba
4 changed files with 87 additions and 2 deletions
|
|
@ -26,9 +26,7 @@ import java.io.ObjectOutputStream;
|
|||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
p2pproxy Copyright (C) 2007 Jehan Monnier ()
|
||||
|
||||
AddressInfo.java - .
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
package org.linphone.p2pproxy.core.stun;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class AddressInfo {
|
||||
InetSocketAddress mPublicAddress,mPrivateAddress;
|
||||
}
|
||||
60
p2pproxy/src/org/linphone/p2pproxy/core/stun/StunClient.java
Normal file
60
p2pproxy/src/org/linphone/p2pproxy/core/stun/StunClient.java
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
p2pproxy Copyright (C) 2007 Jehan Monnier ()
|
||||
|
||||
StunClient.java - .
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
package org.linphone.p2pproxy.core.stun;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.linphone.p2pproxy.api.P2pProxyException;
|
||||
import org.linphone.p2pproxy.core.JxtaNetworkManager;
|
||||
import org.linphone.p2pproxy.core.P2pProxyAdvertisementNotFoundException;
|
||||
import org.linphone.p2pproxy.core.sipproxy.NetworkResourceAdvertisement;
|
||||
|
||||
public class StunClient {
|
||||
private List<InetSocketAddress> mStunServerList;
|
||||
JxtaNetworkManager mJxtaNetworkManager;
|
||||
|
||||
StunClient(List<InetSocketAddress> aStunServerList) {
|
||||
mStunServerList = aStunServerList;
|
||||
}
|
||||
StunClient(JxtaNetworkManager aJxtaNetworkManager) throws P2pProxyException {
|
||||
//need to acquire stun server address()
|
||||
mJxtaNetworkManager = aJxtaNetworkManager;
|
||||
try {
|
||||
mStunServerList = acquireStunServerAddress();
|
||||
} catch (Exception e) {
|
||||
throw new P2pProxyException(e);
|
||||
}
|
||||
}
|
||||
private List<InetSocketAddress> acquireStunServerAddress() throws P2pProxyAdvertisementNotFoundException, InterruptedException, IOException {
|
||||
List<NetworkResourceAdvertisement> lStunServerAdv = (List<NetworkResourceAdvertisement>) mJxtaNetworkManager.getAdvertisementList(null, StunServer.ADV_NAME, true);
|
||||
List<InetSocketAddress> lSocketAddressList = new ArrayList<InetSocketAddress>(lStunServerAdv.size());
|
||||
for (NetworkResourceAdvertisement lNetworkResourceAdvertisement: lStunServerAdv) {
|
||||
URI lServerUri = URI.create(lNetworkResourceAdvertisement.getAddress());
|
||||
lSocketAddressList.add(new InetSocketAddress(lServerUri.getHost(),lServerUri.getPort()));
|
||||
}
|
||||
return lSocketAddressList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -50,6 +50,7 @@ import de.javawi.jstun.util.Address;
|
|||
public class StunServer implements GenericUdpSession.MessageHandler {
|
||||
private static Logger mLog = Logger.getLogger(StunServer.class);
|
||||
private final DatagramSocket mSocket;
|
||||
public final static String ADV_NAME = "p2p-proxy-stunserver";
|
||||
public StunServer(DatagramSocket mListeningSocket) throws SocketException {
|
||||
mSocket = mListeningSocket;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue