Adds better support for TCP in SIP (using the latest improvements in jain-sip)

cusax-fix
Emil Ivov 16 years ago
parent 92565966cc
commit 2cd08f0a85

@ -906,11 +906,28 @@ public ArrayList<ViaHeader> getLocalViaHeaders(SipURI intendedDestination)
InetAddress localAddress = SipActivator
.getNetworkAddressManagerService().getLocalHost(
getIntendedDestination(intendedDestination));
int localPort = srcListeningPoint.getPort();
String transport = srcListeningPoint.getTransport();
if (ListeningPoint.TCP.equalsIgnoreCase(transport))
{
int dstPort = intendedDestination.getPort();
if (dstPort == -1)
dstPort = 5060;
InetSocketAddress localSockAddr
= sipStackSharing.obtainLocalAddress(
NetworkUtils.getInetAddress(
intendedDestination.getHost()),
dstPort,
localAddress);
localPort = localSockAddr.getPort();
}
ViaHeader viaHeader = headerFactory.createViaHeader(
localAddress.getHostAddress()
, srcListeningPoint.getPort()
, srcListeningPoint.getTransport()
, null
localAddress.getHostAddress(),
localPort,
transport,
null
);
viaHeaders.add(viaHeader);
logger.debug("generated via headers:" + viaHeader);
@ -937,6 +954,18 @@ public ArrayList<ViaHeader> getLocalViaHeaders(SipURI intendedDestination)
,OperationFailedException.INTERNAL_ERROR
,ex);
}
catch (java.io.IOException ex)
{
logger.error(
"Unable to create a via header for port "
+ sipStackSharing.getLP(ListeningPoint.UDP).getPort(),
ex);
throw new OperationFailedException(
"Unable to create a via header for port "
+ sipStackSharing.getLP(ListeningPoint.UDP).getPort()
,OperationFailedException.INTERNAL_ERROR
,ex);
}
}
/**
@ -1017,8 +1046,29 @@ public ContactHeader getContactHeader(SipURI intendedDestination)
getAccountID().getUserID()
, localAddress.getHostAddress() );
contactURI.setTransportParam(srcListeningPoint.getTransport());
contactURI.setPort(srcListeningPoint.getPort());
String transport = srcListeningPoint.getTransport();
contactURI.setTransportParam(transport);
int localPort = srcListeningPoint.getPort();
//if we are using tcp, make sure that we include the port of the
//socket that we are actually using and not that of LP
if (ListeningPoint.TCP.equalsIgnoreCase(transport))
{
int dstPort = intendedDestination.getPort();
if (dstPort == -1)
dstPort = 5060;
InetSocketAddress localSockAddr
= sipStackSharing.obtainLocalAddress(
NetworkUtils.getInetAddress(
intendedDestination.getHost()),
dstPort,
localAddress);
localPort = localSockAddr.getPort();
}
contactURI.setPort(localPort);
// set a custom param to ease incoming requests dispatching in case
// we have several registrar accounts with the same username
@ -1027,8 +1077,7 @@ public ContactHeader getContactHeader(SipURI intendedDestination)
{
contactURI.setParameter(
SipStackSharing.CONTACT_ADDRESS_CUSTOM_PARAM_NAME,
paramValue
);
paramValue);
}
Address contactAddress = addressFactory.createAddress( contactURI );
@ -1050,6 +1099,14 @@ public ContactHeader getContactHeader(SipURI intendedDestination)
"A ParseException occurred while creating From Header!"
, ex);
}
catch (java.io.IOException ex)
{
logger.error(
"A ParseException occurred while creating From Header!", ex);
throw new IllegalArgumentException(
"A ParseException occurred while creating From Header!"
, ex);
}
return registrationContactHeader;
}

@ -6,8 +6,10 @@
*/
package net.java.sip.communicator.impl.protocol.sip;
import gov.nist.javax.sip.*;
import gov.nist.javax.sip.stack.*;
import java.io.*;
import java.util.*;
import javax.sip.*;
@ -73,6 +75,20 @@ public class SipStackSharing
private final Set<ProtocolProviderServiceSipImpl> listeners
= new HashSet<ProtocolProviderServiceSipImpl>();
/**
* The property indicating the preferred UDP and TCP
* port to bind to for clear communications.
*/
private static final String PREFERRED_CLEAR_PORT_PROPERTY_NAME
= "net.java.sip.communicator.SIP_PREFERRED_CLEAR_PORT";
/**
* The property indicating the preferred TLS (TCP)
* port to bind to for secure communications.
*/
private static final String PREFERRED_SECURE_PORT_PROPERTY_NAME
= "net.java.sip.communicator.SIP_PREFERRED_SECURE_PORT";
/**
* Constructor for this class. Creates the JAIN-SIP stack.
*/
@ -381,8 +397,7 @@ else if(transport.equalsIgnoreCase(ListeningPoint.TLS))
private int getPreferredClearPort()
{
return SipActivator.getConfigurationService().getInt(
ProtocolProviderFactory.PREFERRED_CLEAR_PORT_PROPERTY_NAME,
ListeningPoint.PORT_5060);
PREFERRED_CLEAR_PORT_PROPERTY_NAME, ListeningPoint.PORT_5060);
}
/**
@ -394,8 +409,7 @@ private int getPreferredClearPort()
private int getPreferredSecurePort()
{
return SipActivator.getConfigurationService().getInt(
ProtocolProviderFactory.PREFERRED_CLEAR_PORT_PROPERTY_NAME,
ListeningPoint.PORT_5061);
PREFERRED_SECURE_PORT_PROPERTY_NAME, ListeningPoint.PORT_5061);
}
/**
@ -928,7 +942,7 @@ private void logApplicationException(
* @throws javax.sip.TransactionUnavailableException if unavailable
*/
public static ServerTransaction getOrCreateServerTransaction(
RequestEvent event)
RequestEvent event)
throws TransactionAlreadyExistsException,
TransactionUnavailableException
{
@ -944,4 +958,35 @@ public static ServerTransaction getOrCreateServerTransaction(
}
return serverTransaction;
}
/**
* Returns a local address to use with the specified TCP destination.
* The method forces the JAIN-SIP stack to creates and binds (if necessary)
* and return a socket connected to the specified destination address and
* port and then return its local address.
*
* @param dst the destination address that the socket would need to connect
* to.
* @param dstPort the port number that the connection would be established
* with.
* @param localAddress the address that we would like to bind on
* (null for the "any" address).
* @param localPort the port that we'd like our socket to bind to (0 for a
* random port).
*
* @return the SocketAddress that this handler would use when connecting to
* the specified destination address and port.
*
* @throws IOException !!!!!!!!!!!!!!!!!!!!!!! FILL IN !!!!!!!!!!!!!!
*/
public java.net.InetSocketAddress obtainLocalAddress(
java.net.InetAddress dst,
int dstPort,
java.net.InetAddress localAddress)
throws IOException
{
return (java.net.InetSocketAddress)(((SipStackImpl)this.stack)
.obtainLocalAddress( dst, dstPort, localAddress, 0));
}
}

Loading…
Cancel
Save