mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-21 13:08:08 +00:00
create jxta resource for super peer proxies
git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@23 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
This commit is contained in:
parent
c437ade5b9
commit
01408ff07f
7 changed files with 391 additions and 6 deletions
|
|
@ -30,10 +30,10 @@ import org.apache.log4j.Logger;
|
|||
import org.linphone.p2pproxy.api.P2pProxyException;
|
||||
import org.linphone.p2pproxy.core.Configurator;
|
||||
|
||||
import org.linphone.p2pproxy.core.sipproxy.NetworkResources;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SdpProcessor;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar.Registration;
|
||||
import org.linphone.p2pproxy.core.sipproxy.peers.NetworkResources;
|
||||
import org.zoolu.sdp.AttributeField;
|
||||
import org.zoolu.sdp.ConnectionField;
|
||||
import org.zoolu.sdp.MediaDescriptor;
|
||||
|
|
|
|||
|
|
@ -91,12 +91,12 @@ public class SipProxyRegistrar implements SipProviderListener,SipProxyRegistrarM
|
|||
|
||||
public static class Registration {
|
||||
long RegistrationDate;
|
||||
long Expiration;
|
||||
public long Expiration;
|
||||
//implementation specific context
|
||||
public Object NetResources;
|
||||
public Map<MediaType,InetSocketAddress> RtpRelays = new HashMap<MediaType,InetSocketAddress>() ;
|
||||
String Contact;
|
||||
final String From;
|
||||
public String Contact;
|
||||
public final String From;
|
||||
public Registration(String aFrom) {From = aFrom;}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ 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.sipproxy;
|
||||
package org.linphone.p2pproxy.core.sipproxy.peers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
|
@ -38,6 +38,11 @@ import org.linphone.p2pproxy.api.P2pProxyUserNotFoundException;
|
|||
import org.linphone.p2pproxy.core.JxtaNetworkManager;
|
||||
import org.linphone.p2pproxy.core.P2pProxyAdvertisementNotFoundException;
|
||||
import org.linphone.p2pproxy.core.media.rtprelay.SdpProcessorImpl;
|
||||
import org.linphone.p2pproxy.core.sipproxy.RegistrationHandler;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SdpProcessor;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipProxy;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipUtils;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar.Registration;
|
||||
import org.zoolu.sip.address.NameAddress;
|
||||
import org.zoolu.sip.address.SipURL;
|
||||
|
|
@ -17,7 +17,7 @@ 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.sipproxy;
|
||||
package org.linphone.p2pproxy.core.sipproxy.peers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
p2pproxy Copyright (C) 2007 Jehan Monnier ()
|
||||
|
||||
JxtaNetworkResources.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.sipproxy.superpeers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.jxta.discovery.DiscoveryService;
|
||||
import net.jxta.document.AdvertisementFactory;
|
||||
import net.jxta.id.IDFactory;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.linphone.p2pproxy.api.P2pProxyException;
|
||||
import org.linphone.p2pproxy.core.JxtaNetworkManager;
|
||||
import org.linphone.p2pproxy.core.P2pUserProfileAdvertisement;
|
||||
import org.zoolu.sip.address.SipURL;
|
||||
|
||||
public class JxtaNetworkResources {
|
||||
private final JxtaNetworkManager mJxtaNetworkManager;
|
||||
private final static Logger mLog = Logger.getLogger(JxtaNetworkResources.class);
|
||||
private final P2pUserRegistrationAdvertisement mP2pUserRegistrationAdvertisement;
|
||||
private final static long EXPIRATION= 120000;
|
||||
|
||||
JxtaNetworkResources (SipURL aUserName, JxtaNetworkManager aJxtaNetworkManager,SipURL aRegistrarAddress) {
|
||||
mJxtaNetworkManager = aJxtaNetworkManager;
|
||||
mP2pUserRegistrationAdvertisement = (P2pUserRegistrationAdvertisement) AdvertisementFactory.newAdvertisement(P2pUserProfileAdvertisement.getAdvertisementType());
|
||||
mP2pUserRegistrationAdvertisement.setID(IDFactory.newCodatID(mJxtaNetworkManager.getPeerGroup().getPeerGroupID(), aUserName.toString().getBytes()));
|
||||
mP2pUserRegistrationAdvertisement.setUserName(aUserName.toString());
|
||||
mP2pUserRegistrationAdvertisement.setRegistrarAddress(aRegistrarAddress.toString());
|
||||
}
|
||||
|
||||
void publish(long aLiveTime) throws P2pProxyException {
|
||||
try {
|
||||
DiscoveryService lDiscoveryService = mJxtaNetworkManager.getPeerGroup().getDiscoveryService();
|
||||
if (aLiveTime > 0) {
|
||||
lDiscoveryService.publish(mP2pUserRegistrationAdvertisement,aLiveTime,EXPIRATION);
|
||||
} else {
|
||||
//first flush in any cases
|
||||
lDiscoveryService.flushAdvertisement(mP2pUserRegistrationAdvertisement);
|
||||
}
|
||||
} catch (IOException e1) {
|
||||
throw new P2pProxyException(e1);
|
||||
}
|
||||
mLog.debug("publishing P2pUserRegistration Advertisement published expire ["+aLiveTime+"]");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,271 @@
|
|||
/*
|
||||
p2pproxy
|
||||
Copyright (C) 2007 Jehan Monnier ()
|
||||
|
||||
P2pUserRegistrationAdvertisement.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.sipproxy.superpeers;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
import net.jxta.document.Advertisement;
|
||||
import net.jxta.document.AdvertisementFactory;
|
||||
import net.jxta.document.Attributable;
|
||||
import net.jxta.document.Document;
|
||||
import net.jxta.document.Element;
|
||||
import net.jxta.document.ExtendableAdvertisement;
|
||||
import net.jxta.document.MimeMediaType;
|
||||
import net.jxta.document.StructuredDocument;
|
||||
import net.jxta.document.StructuredDocumentFactory;
|
||||
import net.jxta.document.TextElement;
|
||||
import net.jxta.id.ID;
|
||||
import net.jxta.id.IDFactory;
|
||||
|
||||
/**
|
||||
* derivated from jxta Advertisement tutorial
|
||||
* <pre>
|
||||
* <?xml version="1.0"?>
|
||||
* <!DOCTYPE jxta:System>
|
||||
* <jxta:System xmlns:jxta="http://jxta.org">
|
||||
* <id>NULL </id>
|
||||
* <user-name>address where the sip endpoint is currently registered</user-name>
|
||||
* <registrar-address>address where the sip endpoint is currently registered</registrar-address>
|
||||
* </jxta:System>
|
||||
* </pre>
|
||||
*/
|
||||
public class P2pUserRegistrationAdvertisement extends ExtendableAdvertisement implements Comparable, Cloneable, Serializable {
|
||||
/**
|
||||
* Instantiator
|
||||
*/
|
||||
public static class Instantiator implements AdvertisementFactory.Instantiator {
|
||||
|
||||
/**
|
||||
* Returns the identifying type of this Advertisement.
|
||||
*
|
||||
* @return String the type of advertisement
|
||||
*/
|
||||
public String getAdvertisementType() {
|
||||
return P2pUserRegistrationAdvertisement.getAdvertisementType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of <CODE>Advertisement</CODE> matching the
|
||||
* type specified by the <CODE>advertisementType</CODE> parameter.
|
||||
*
|
||||
* @return The instance of <CODE>Advertisement</CODE> or null if it
|
||||
* could not be created.
|
||||
*/
|
||||
public Advertisement newInstance() {
|
||||
return new P2pUserRegistrationAdvertisement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of <CODE>Advertisement</CODE> matching the
|
||||
* type specified by the <CODE>advertisementType</CODE> parameter.
|
||||
*
|
||||
* @param root Specifies a portion of a StructuredDocument which will
|
||||
* be converted into an Advertisement.
|
||||
* @return The instance of <CODE>Advertisement</CODE> or null if it
|
||||
* could not be created.
|
||||
*/
|
||||
public Advertisement newInstance(net.jxta.document.Element root) {
|
||||
return new P2pUserRegistrationAdvertisement(root);
|
||||
}
|
||||
}
|
||||
private ID mId ;;
|
||||
private String mRegistrarAddress;
|
||||
private String mUserUri;
|
||||
public final static String REGISTRAR_ADDRESS_TAG = "registrar-address";
|
||||
public final static String USER_NAME_TAG = "user-name";
|
||||
private final static String ID_TAG = "ID";
|
||||
private final static String[] mIndexs = {USER_NAME_TAG};
|
||||
private final static Logger mLog = Logger.getLogger(P2pUserRegistrationAdvertisement.class);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public P2pUserRegistrationAdvertisement(Element root) {
|
||||
|
||||
TextElement doc = (TextElement) root;
|
||||
|
||||
if (!getAdvertisementType().equals(doc.getName())) {
|
||||
throw new IllegalArgumentException("Could not construct : " + getClass().getName() + "from doc containing a " + doc.getName());
|
||||
}
|
||||
initialize(doc);
|
||||
|
||||
}
|
||||
public P2pUserRegistrationAdvertisement() {
|
||||
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see net.jxta.document.ExtendableAdvertisement#getDocument(net.jxta.document.MimeMediaType)
|
||||
*/
|
||||
@Override
|
||||
public Document getDocument(MimeMediaType asMimeType) {
|
||||
|
||||
StructuredDocument adv = StructuredDocumentFactory.newStructuredDocument(asMimeType,
|
||||
getAdvertisementType());
|
||||
if (adv instanceof Attributable) {
|
||||
((Attributable) adv).addAttribute("xmlns:jxta", "http://jxta.org");
|
||||
}
|
||||
Element e;
|
||||
e = adv.createElement(ID_TAG, getID().toString());
|
||||
adv.appendChild(e);
|
||||
e = adv.createElement(USER_NAME_TAG, getUserName().trim());
|
||||
adv.appendChild(e);
|
||||
e = adv.createElement(REGISTRAR_ADDRESS_TAG, getRegistrarAddress().trim());
|
||||
adv.appendChild(e);
|
||||
return adv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ID getID() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getIndexFields() {
|
||||
return mIndexs;
|
||||
}
|
||||
public static String getAdvertisementType() {
|
||||
return "jxta:p2p-proxy-user-registration";
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see net.jxta.document.Advertisement#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO Auto-generated method stub
|
||||
return super.toString();
|
||||
}
|
||||
public int compareTo(Object other) {
|
||||
return getID().toString().compareTo(other.toString());
|
||||
}
|
||||
/**
|
||||
* Intialize a System advertisement from a portion of a structured document.
|
||||
*
|
||||
* @param root document root
|
||||
*/
|
||||
protected void initialize(Element root) {
|
||||
if (!TextElement.class.isInstance(root)) {
|
||||
throw new IllegalArgumentException(getClass().getName() +
|
||||
" only supports TextElement");
|
||||
}
|
||||
TextElement doc = (TextElement) root;
|
||||
if (!doc.getName().equals(getAdvertisementType())) {
|
||||
throw new IllegalArgumentException("Could not construct : "
|
||||
+ getClass().getName() + "from doc containing a " +
|
||||
doc.getName());
|
||||
}
|
||||
Enumeration elements = doc.getChildren();
|
||||
while (elements.hasMoreElements()) {
|
||||
TextElement elem = (TextElement) elements.nextElement();
|
||||
if (!handleElement(elem)) {
|
||||
mLog.warn("Unhandleded element \'" + elem.getName() + "\' in " + doc.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Process an individual element from the document.
|
||||
*
|
||||
* @param elem the element to be processed.
|
||||
* @return true if the element was recognized, otherwise false.
|
||||
*/
|
||||
protected boolean handleElement(TextElement elem) {
|
||||
if (elem.getName().equals(ID_TAG)) {
|
||||
try {
|
||||
URI id = new URI(elem.getTextValue());
|
||||
setID(IDFactory.fromURI(id));
|
||||
} catch (URISyntaxException badID) {
|
||||
throw new IllegalArgumentException("unknown ID format in advertisement: " +
|
||||
elem.getTextValue());
|
||||
}
|
||||
catch (ClassCastException badID) {
|
||||
throw new IllegalArgumentException("Id is not a known id type: " +
|
||||
elem.getTextValue());
|
||||
}
|
||||
return true;
|
||||
} else if (elem.getName().equals(USER_NAME_TAG)) {
|
||||
setUserName(elem.getTextValue());
|
||||
return true;
|
||||
} else if (elem.getName().equals(REGISTRAR_ADDRESS_TAG)) {
|
||||
setRegistrarAddress(elem.getTextValue());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void setID(ID id) {
|
||||
mId = id;
|
||||
}
|
||||
@Override
|
||||
public String getBaseAdvType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @return Returns the mName.
|
||||
*/
|
||||
public String getRegistrarAddress() {
|
||||
return mRegistrarAddress;
|
||||
}
|
||||
/**
|
||||
* @param name The mName to set.
|
||||
*/
|
||||
public void setRegistrarAddress(String anAddress) {
|
||||
mRegistrarAddress = anAddress;
|
||||
}
|
||||
/**
|
||||
* @return Returns the mName.
|
||||
*/
|
||||
public String getUserName() {
|
||||
return mUserUri;
|
||||
}
|
||||
/**
|
||||
* @param name The mName to set.
|
||||
*/
|
||||
public void setUserName(String anName) {
|
||||
mUserUri = anName;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof P2pUserRegistrationAdvertisement) {
|
||||
P2pUserRegistrationAdvertisement adv = (P2pUserRegistrationAdvertisement) obj;
|
||||
return getID().equals(adv.getID());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
p2pproxy Copyright (C) 2007 Jehan Monnier ()
|
||||
|
||||
SuperPeerProxy.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.sipproxy.superpeers;
|
||||
|
||||
import org.linphone.p2pproxy.api.P2pProxyException;
|
||||
import org.linphone.p2pproxy.core.sipproxy.RegistrationHandler;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipProxy;
|
||||
import org.linphone.p2pproxy.core.sipproxy.SipProxyRegistrar.Registration;
|
||||
import org.zoolu.sip.message.Message;
|
||||
import org.zoolu.sip.provider.SipProvider;
|
||||
|
||||
public class SuperPeerProxy implements SipProxy, RegistrationHandler {
|
||||
|
||||
public void proxyRequest(SipProvider provider, Message message) throws P2pProxyException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void proxyResponse(SipProvider provider, Message message) throws P2pProxyException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void updateRegistration(Registration registration, Message registrationMessage) throws P2pProxyException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue