Skip to content

Commit

Permalink
Improved support for rfc5658
Browse files Browse the repository at this point in the history
  • Loading branch information
psanders committed Mar 12, 2021
1 parent 2d7a087 commit 32837cf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 27 deletions.
37 changes: 28 additions & 9 deletions mod/core/processor/request_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,49 @@ class RequestHandler {

async processRoute (transaction, request, route, routeInfo) {
try {
// If the request autof dialog we wont have a route. Therefore, we get
// the transport from the request URI.
const transport = route
const lpTransport = request
.getHeader(ViaHeader.NAME)
.getTransport()
.toLowerCase()
const targetTransport = route
? route.transport
: request.getRequestURI().getParameter('transport')
const lp = this.sipProvider.getListeningPoint(transport)
: request
.getRequestURI()
.getParameter('transport')
.toLowerCase()

const lp = this.sipProvider.getListeningPoint(lpTransport)
const localAddr = {
host: lp.getIPAddress().toString(),
port: lp.getPort()
port: lp.getPort(),
transport: lpTransport
}
const advertisedAddr = getAdvertisedAddr(request, route, localAddr)
const advertisedAddr = getAdvertisedAddr(
request,
route,
localAddr,
targetTransport
)

LOG.debug(
`core.processor.RequestHandler.processRoute [targetTransport = ${targetTransport}]`
)
LOG.debug(
`core.processor.RequestHandler.processRoute [lpTransport = ${lpTransport}]`
)

let requestOut = configureMaxForwards(request)
requestOut = configureProxyAuthorization(requestOut)
requestOut = configureRoute(requestOut, localAddr)
requestOut = configureVia(requestOut, advertisedAddr, transport)
requestOut = configureVia(requestOut, advertisedAddr, targetTransport)
//requestOut = configureContact(requestOut)

if (!isInDialog(request)) {
requestOut = configureRequestURI(requestOut, routeInfo, route)
requestOut = configurePrivacy(requestOut, routeInfo)
requestOut = configureIdentity(requestOut, route)
requestOut = configureXHeaders(requestOut, route)
requestOut = configureRecordRoute(requestOut, advertisedAddr, localAddr)
requestOut = configureRecordRoute(requestOut, localAddr, advertisedAddr)
}

if (routeInfo.getRoutingType() === RoutingType.DOMAIN_EGRESS_ROUTING) {
Expand Down
44 changes: 26 additions & 18 deletions mod/core/processor/request_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ownedAddresss = localAddr =>
}
]
: [localAddr]
const getAdvertisedAddr = (request, route, localAddr) => {
const getAdvertisedAddr = (request, route, localAddr, targetTransport) => {
// After the initial invite the route object will be null
// and we need to the the target address from the request uri.
// If the routing is type IDR the initial request uri will be a local
Expand All @@ -44,9 +44,13 @@ const getAdvertisedAddr = (request, route, localAddr) => {
? LocatorUtils.aorAsObj(route.contactURI).getHost()
: request.getRequestURI().getHost()
const externAddr = config.spec.externAddr
return config.spec.externAddr && needsExternAddress(route, targetAddr)
? { host: addrHost(externAddr), port: addrPort(externAddr, localAddr) }
: localAddr
return externAddr && needsExternAddress(route, targetAddr)
? {
host: addrHost(externAddr),
port: addrPort(externAddr, localAddr),
transport: targetTransport
}
: { host: localAddr.host, port: localAddr.port, transport: targetTransport }
}
const getToUser = request => {
const toHeader = request.getHeader(ToHeader.NAME)
Expand Down Expand Up @@ -128,27 +132,31 @@ const configureVia = (request, advertisedAddr, transport) => {
requestOut.addFirst(viaHeader)
return requestOut
}
const configureRecordRoute = (request, advertisedAddr, localAddr) => {

// rfc5658
const configureRecordRoute = (request, localAddr, advertisedAddr) => {
const requestOut = request.clone()
if (config.spec.recordRoute) {
const viaHeader = request.getHeaders(ViaHeader.NAME).next()
const transport = viaHeader.getTransport().toLowerCase()

if (config.spec.recordRoute || transport === 'ws' || transport === 'wss') {
// First we need the input interface from the top ViaHeader
const p1 = addressFactory.createSipURI(null, localAddr.host)
p1.setLrParam()
p1.setPort(localAddr.port)
p1.setTransportParam(localAddr.transport)
p1.setLrParam()
const pa1 = addressFactory.createAddress(p1)
const rr1 = headerFactory.createRecordRouteHeader(pa1)
requestOut.addHeader(rr1)

if (config.spec.externAddr && isPublicAddress(advertisedAddr.host)) {
const p2 = addressFactory.createSipURI(
null,
addrHost(config.spec.externAddr)
)
p2.setLrParam()
p2.setPort(addrPort(config.spec.externAddr, localAddr))
const pa2 = addressFactory.createAddress(p2)
const rr2 = headerFactory.createRecordRouteHeader(pa2)
requestOut.addFirst(rr2)
}
// Then we get the advertisedAddr
const p2 = addressFactory.createSipURI(null, advertisedAddr.host)
p2.setLrParam()
p2.setTransportParam(advertisedAddr.transport)
p2.setPort(advertisedAddr.port)
const pa2 = addressFactory.createAddress(p2)
const rr2 = headerFactory.createRecordRouteHeader(pa2)
requestOut.addLast(rr2)
}
return requestOut
}
Expand Down

0 comments on commit 32837cf

Please sign in to comment.