Skip to content

Commit

Permalink
Merge pull request fonoster#103 from fonoster/rtpengine-support
Browse files Browse the repository at this point in the history
Rtpengine support
  • Loading branch information
psanders authored Mar 13, 2021
2 parents d8175f4 + 82fe179 commit f72147a
Show file tree
Hide file tree
Showing 33 changed files with 530 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: routr
description: Next-generation SIP Server
type: application
version: 0.0.6
version: 0.0.7
appVersion: 1.0.0-rc5
dependencies:
- name: redis
Expand Down
1 change: 1 addition & 0 deletions .helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ The following table lists the configurable parameters of the Routr chart and the
| routr.localnets | Local networks in CIDR format. Use in combination with `externAddr` | [] |
| routr.recordRoute | Stay within the signaling path | `false` |
| routr.useToAsAOR | Uses the `To` header, instead of `Request-URI`, to locate endpoints | `false` |
| routr.patchRequestURI | Uses the user part of the `To` header to ammend the `Request-URI` if it doesn't have user| `false` |
| routr.registrarIntf | `Internal` causes the server to use the IP and port it "sees"(received & rport) from a device attempting to register | `External` |
| routr.accessControlList.deny | Deny incoming traffic from network list. Must be valid CIDR values | [] |
| routr.accessControlList.allow | Allow incoming traffic from network list. Must be valid CIDR values | [] |
Expand Down
2 changes: 2 additions & 0 deletions .helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ spec:
value: {{ .Values.routr.recordRoute | quote }}
- name: USE_TO_AS_AOR
value: {{ .Values.routr.useToAsAOR | quote }}
- name: PATCH_REQUEST_URI
value: {{ .Values.routr.patchRequestURI | quote }}
- name: REGISTRAR_INTF
value: {{ .Values.routr.registrarIntf | quote }}
- name: ACCESS_CONTROL_LIST_ALLOW
Expand Down
12 changes: 12 additions & 0 deletions .helm/templates/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ metadata:
labels:
{{- include ".helm2.labels" . | nindent 4 }}
namespace: {{ .Release.Namespace }}
{{- with .Values.adminService.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.adminService.type }}
ports:
Expand All @@ -25,6 +29,10 @@ metadata:
labels:
{{- include ".helm2.labels" . | nindent 4 }}
namespace: {{ .Release.Namespace }}
{{- with .Values.udpSignalingService.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.udpSignalingService.type }}
{{- if ne .Values.udpSignalingService.type "ClusterIP" }}
Expand All @@ -48,6 +56,10 @@ metadata:
labels:
{{- include ".helm2.labels" . | nindent 4 }}
namespace: {{ .Release.Namespace }}
{{- with .Values.tcpSignalingService.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.tcpSignalingService.type }}
{{- if ne .Values.tcpSignalingService.type "ClusterIP" }}
Expand Down
6 changes: 4 additions & 2 deletions .helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ adminService:
name: api
type: ClusterIP
port: 4567
annotations: {}

# Use this service to enable UDP access to the server's signaling
# capabilities. Keep in mind that this will create the service for you
Expand All @@ -25,6 +26,7 @@ udpSignalingService:
name: sipudp
type: ClusterIP
port: 5060
annotations: {}

# Use this service to enable TCP access to the server's signaling
# capabilities. Keep in mind that this will create the service for you
Expand All @@ -37,6 +39,7 @@ tcpSignalingService:
ports:
- name: siptcp
port: 5060
annotations: {}

# Routr internal configurations
routr:
Expand All @@ -46,6 +49,7 @@ routr:
localnets: []
recordRoute: false
useToAsAOR: false
patchRequestURI: false
registrarIntf: External
accessControlList:
deny: []
Expand Down Expand Up @@ -80,8 +84,6 @@ redis:
mountPath: /bitnami/redis
size: 5Gi

# Omiting this for now

replicaCount: 1
nameOverride: ""
fullnameOverride: ""
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
compile 'io.kotest:kotest-runner-junit5-jvm:4.0.3'
compile 'io.kotest:kotest-assertions-core-jvm:4.0.3'
compile 'io.kotest:kotest-property-jvm:4.0.3'
compile "com.mashape.unirest:unirest-java:1.4.9"
implementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.50'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7'
}
Expand Down
6 changes: 6 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ spec:
port: 5060
- protocol: udp
port: 5060
- protocol: tls
port: 5061
- protocol: ws
port: 5062
- protocol: wss
port: 5063
9 changes: 9 additions & 0 deletions etc/schemas/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@
"trustStorePassword": { "type": "string" }
}
},
"ex_rtpEngine": {
"type": "object",
"properties": {
"port": { "type": "integer" },
"host": { "type": "string" },
"proto": { "type": "string" }
},
"required": ["host"]
},
"dataSource": {
"type": "object",
"properties": {
Expand Down
32 changes: 32 additions & 0 deletions mod/core/config/config_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@ module.exports = upSince => {
dataSource: {
provider: 'files_data_provider'
},
ex_rtpEngine: {
enabled: false,
proto: 'http',
port: 8080,
bridgeParams: {
webToWeb: {
ICE: 'force',
SDES: 'off',
flags: 'trust-address replace-origin replace-session-connection'
},
webToSip: {
'transport-protocol': 'RTP/AVP',
'rtcp-mux': 'demux',
ICE: 'remove',
flags: 'trust-address replace-origin replace-session-connection'
},
sipToWeb: {
'transport-protocol': 'UDP/TLS/RTP/SAVP',
'rtcp-mux': 'offer',
ICE: 'force',
SDES: 'off',
flags:
'trust-address replace-origin replace-session-connection generate-mid'
},
sipToSip: {
'transport-protocol': 'RTP/AVP',
'rtcp-mux': 'demux',
ICE: 'remove',
flags: 'trust-address replace-origin replace-session-connection'
}
}
},
registrarIntf: 'External',
restService: {
keyStore: 'etc/certs/api-cert.jks',
Expand Down
4 changes: 4 additions & 0 deletions mod/core/config/config_from_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ envsMap.set(
'spec.securityContext.client.authType'
)
envsMap.set('SECURITY_CONTEXT_DEBUGGING', 'spec.securityContext.debugging')
envsMap.set('EX_RTP_ENGINE_ENABLED', 'spec.ex_rtpEngine.enabled')
envsMap.set('EX_RTP_ENGINE_PROTO', 'spec.ex_rtpEngine.proto')
envsMap.set('EX_RTP_ENGINE_HOST', 'spec.ex_rtpEngine.host')
envsMap.set('EX_RTP_ENGINE_PORT', 'spec.ex_rtpEngine.port')
envsMap.set('LOG4J', '')
envsMap.set('CONFIG_FILE', '')
envsMap.set('SALT', '')
Expand Down
15 changes: 12 additions & 3 deletions mod/core/processor/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
const postal = require('postal')
const RequestProcessor = require('@routr/core/processor/request_processor')
const ResponseProcessor = require('@routr/core/processor/response_processor')
const CallIdHeader = Java.type('javax.sip.header.CallIdHeader')
const FromHeader = Java.type('javax.sip.header.FromHeader')
const SipListener = Java.type('javax.sip.SipListener')
const LogManager = Java.type('org.apache.logging.log4j.LogManager')
const LOG = LogManager.getLogger()
Expand Down Expand Up @@ -45,22 +47,29 @@ class Processor {
channel: 'processor',
topic: 'transaction.timeout',
data: {
transactionId: transactionId,
transactionId,
isServerTransaction: event.isServerTransaction()
}
})
},

processTransactionTerminated: event => {
const request = event.getServerTransaction().getRequest()
const callId = request.getHeader(CallIdHeader.NAME).getCallId()
const fromTag = request.getHeader(FromHeader.NAME).getTag()

const transactionId = event.isServerTransaction()
? event.getServerTransaction().getBranchId()
: event.getClientTransaction().getBranchId()

postal.publish({
channel: 'processor',
topic: 'transaction.terminated',
data: {
transactionId: transactionId,
isServerTransaction: event.isServerTransaction()
transactionId,
isServerTransaction: event.isServerTransaction(),
callId,
fromTag
}
})
},
Expand Down
14 changes: 14 additions & 0 deletions mod/core/processor/processor_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ const AuthHelper = require('@routr/utils/auth_helper')
const { connectionException } = require('@routr/utils/exception_helpers')

const ToHeader = Java.type('javax.sip.header.ToHeader')
const FromHeader = Java.type('javax.sip.header.FromHeader')
const ContactHeader = Java.type('javax.sip.header.ContactHeader')
const ExpiresHeader = Java.type('javax.sip.header.ExpiresHeader')
const CSeqHeader = Java.type('javax.sip.header.CSeqHeader')
const ViaHeader = Java.type('javax.sip.header.ViaHeader')
const ContentType = Java.type('javax.sip.header.ContentTypeHeader')
const CallIdHeader = Java.type('javax.sip.header.CallIdHeader')
const Request = Java.type('javax.sip.message.Request')
const Response = Java.type('javax.sip.message.Response')
const AccountManager = Java.type(
Expand All @@ -22,6 +25,15 @@ const SipFactory = Java.type('javax.sip.SipFactory')
const headerFactory = SipFactory.getInstance().createHeaderFactory()
const messageFactory = SipFactory.getInstance().createMessageFactory()

const extractRTPEngineParams = r => {
return {
sdp: String.fromCharCode.apply(null, r.getContent()),
'call-id': r.getHeader(CallIdHeader.NAME).getCallId(),
'from-tag': r.getHeader(FromHeader.NAME).getTag(),
'to-tag': r.getHeader(ToHeader.NAME).getTag()
}
}
const hasSDP = r => r.getHeader(ContentType.NAME) != null
const hasCodes = (r, c) =>
c.filter(code => r.getStatusCode() === code).length > 0
const isMethod = (r, m) =>
Expand Down Expand Up @@ -142,3 +154,5 @@ module.exports.isRegisterNok = isRegisterNok
module.exports.isBehindNat = isBehindNat
module.exports.handleAuthChallenge = handleAuthChallenge
module.exports.getExpires = getExpires
module.exports.hasSDP = hasSDP
module.exports.extractRTPEngineParams = extractRTPEngineParams
Loading

0 comments on commit f72147a

Please sign in to comment.