Re: about stun4j in jain-sip 1.2

Man-Chi Leung <[email protected]>
Newsgroups gmane.comp.voip.nist-sip
Message-ID <[email protected]>
hi,

i do have the following doubt, pls help!

1) when should I start running  stun4j  ?
it seems that I must start stun4j before [Step 2] :
Line: udpListeningPoint = sipStack.createListeningPoint(PRIVATE_IP, 
PRIVATE_PORT,transport);
bcos, this line will bind the address (e.g. 10.0.0.1:5060). stun4j will 
not able to bind the same address (10.0.0.1:5060) after this line!!


2) when should I stop running stun4j ?

i must explicitly call addressDiscovery.shutDown();  before [Step 2] , 
otherwise sipstack will fail to bind address & throw exception at [Step 
2]

3) is my implementation  correct?
[1st UDP session at NAT]
-> run stun4j
-> detect public address
-> shutdown stun4j
[2nd UDP session at NAT]
-> createListeningPoint via sipstack
-> set Via & contact address
-> send request

now, i have problem on re-running stun4j multiple times for KeepAlive. 
how should I do it in jain-sip?

btw, i also checked sip-communicator (in both old and new1.0 version). 
i could not find any actual integration of stun4j beside using stun4j 
as a diagnostic tool for debugging.
did i miss anything? pls advise on any example and tutorial guide on 
this area. anyone has a good example? can share with me?

~manchi

-----------------------------------------------------------
for stun4j with jain-sip 1.2, I did the following:
-----------------------------------------------------------
//
//  create a method to use stun4j API
//
private void setPublicAddress() {

		StunAddress localAddr =  new 
StunAddress(InetAddress.getLocalHost(),PRIVATE_IP);

		StunAddress serverAddr  serverAddr = new StunAddress(STUN_SERVER_IP, 
STUN_SERVER_PORT);
		NetworkConfigurationDiscoveryProcess addressDiscovery = new 
NetworkConfigurationDiscoveryProcess(
				localAddr, serverAddr);

		addressDiscovery.start();

		StunDiscoveryReport stunReport stunReport = 
addressDiscovery.determineAddress();
		
		StunAddress stunAddress = stunReport.getPublicAddress();
		
		//
		// overwrite class field for PUBLIC_IP and PUBLC_PORT with public 
address detected from stun4j
		//		
		this.PUBLIC_IP = stunAddress.getHostAddress();
		this.PUBLIC_PORT = stunAddress.getPort();

		// need to shutdown stun process, otherwise, stun4j is holding port
		addressDiscovery.shutDown();
	}

public void sendRegister() {
	//
	// [ Step 1 ]  run setPublicAddress() to set PUBLIC_IP & PUBLIC_PORT 
with stun4j
	//
	this.setPublicAddress();
	....

	//
	// [  Step 2 ] to avoid verfiication check by sip-stack-imp,
	// create listening point with private address first,
	// then use setSentBy to replace with public address.
	//
	udpListeningPoint = sipStack.createListeningPoint(PRIVATE_IP, 
PRIVATE_PORT,transport);
	udpListeningPoint.setSentBy(PUBLIC_IP + ":" + PUBLIC_PORT);

	//
	// [  Step 3 ] create  ViaHeaders with public address
	//	
	ArrayList viaHeaders = new ArrayList();
	ViaHeader viaHeader = 
headerFactory.createViaHeader(PUBLIC_IP,PUBLIC_PORT, transport, null);
	viaHeaders.add(viaHeader);

	//
	// [ Step 4 ] Create and add the contact name address
	// with public address		
	//		
	SipURI contactURI = addressFactory.createSipURI(fromUserName,PUBLIC_IP);
	contactURI.setPort(PUBLIC_PORT);
	Address contactAddress = addressFactory.createAddress(contactURI);
	contactAddress.setDisplayName(fromUserName);
	ContactHeader contactHeader = 
headerFactory.createContactHeader(contactAddress);
	request.addHeader(contactHeader);

	...
	clientTransaction.sendRequest();
	....
}


On 2006-06-13 19:44:11 +0800, "M. Rangnathan" <[email protected]> said:

> Man-Chi Leung wrote:
> 
>> hi,
>> 
>> ----------------------------------------------
>> in jain-sip 1.1 CVS source,
>> ----------------------------------------------
>> I found info about stun4j in /docs/faq.html
>> 
>> How do you enable/use the STUN support?
>> set the gov.nist.javax.sip.STUN_SERVER to point to 
>> stun_server_ip_address[:port] where your stun server resides. The stack 
>> will return mapped address when you getIpAddress() from the stack and 
>> getPort() from the listening point. With stun, if you have a NAT box, 
>> these will in general be different from the IP address and port used to 
>> create the LP. Your application needs to use these in setting up the 
>> contact address and SDP parameters as appropriate. The stack is not 
>> responsible for this.
>> 
>> 
>> ----------------------------------------------
>> in jain-sip 1.2 CVS source
>> ----------------------------------------------
>> i found the following snippet in Class "gov.nist.javax.sip.SIPStackImpl.java"
>> 
>>         String stunAddr = configurationProperties
>>                 .getProperty("gov.nist.javax.sip.STUN_SERVER");
>> 
>>         if ( stunAddr != null )
>>             this.logWriter.logWarning("Ignoring obsolete property "
>>                 + "gov.nist.javax.sip.STUN_SERVER");
>> 
>> -----------------------
>> my Question:
>> -----------------------
>> is stun4j totally ignored by jain-sip 1.2 ?
> 
> 
> Totally and absolutely ignored. :-) Stun was never part of JAIN-SIP. 
> The previous version had some Stun support in the RI. It was deemed 
> unecessary and therefore removed.
> 
>> 
>> 
>> so idea is to just call Stun's API from my jain-sip client, am i correct?
>> - get public address from Stun4j's  addressDiscovery.determineAddress();
>> - set public address in Via using API Jain-SIP's  
>> headerFactory.createViaHeader()
> 
> 
> Set the sentBy on your Listening point. See ListeningPoint.setSentBy()
> Set the public address in Via.
> 
> If you dont do the former,  the RI will throw an exception. It does a 
> little integrity check.
> 
> This may not be relevant to you but there is now an AddressResolver 
> (only part of the RI and not the spec).  When the reciever gets a 
> message it checks the via header to see if it can resolve the address. 
> To do this it uses the AddressResolver. If the address cannot be 
> resolved the message is dropped. Just a little security and integrity 
> feature that I thought people might find useful. Also a way to deal 
> with DNS SRV record lookups that the stack does not implement ( you can 
> implement this Interface and register with the stack).
> 
>> - set public address in Contact using API Jain-SIP's  
>> addressFactory.createAddress(contactURI);
> 
> Yes
> 
>> - set public address and port for  SDP c=  attribute.
> 
> 
> Yes.
> 
>> 
>> ~manchi
>> 
>> 
>> 
>> _______________________________________________
>> nist-sip mailing list
>> [email protected]
>> http://www-x.antd.nist.gov/mailman/listinfo/nist-sip
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.