Skip to content

Commit

Permalink
Merge pull request #252 from fonoster/feat/maxContact-peer-support
Browse files Browse the repository at this point in the history
Replace "backend" prefix in AORs with "maxContact" for clarity
  • Loading branch information
psanders authored Feb 12, 2024
2 parents 4af0a4c + ac4122e commit 96410ee
Show file tree
Hide file tree
Showing 385 changed files with 1,150 additions and 943 deletions.
2 changes: 1 addition & 1 deletion .scripts/custom-jre.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ echo ""
$JAVA_HOME/bin/jlink -c --no-man-pages --no-header-files -G \
--module-path $TARGET_HOME/jmods/ \
--add-modules \
java.base,java.management,java.naming,java.sql,java.instrument,jdk.crypto.cryptoki,jdk.scripting.nashorn,jdk.unsupported,jdk.management.agent,jdk.unsupported.desktop,jdk.crypto.ec,java.security.jgss,jdk.jartool \
java.base,java.management,java.naming,java.sql,java.instrument,jdk.crypto.cryptoki,jdk.unsupported,jdk.management.agent,jdk.unsupported.desktop,jdk.crypto.ec,java.security.jgss,jdk.jartool,java.scripting \
--output jre
2 changes: 1 addition & 1 deletion .scripts/tag-changelog-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
* http://github.com/fonoster
*
* This file is part of Routr.
Expand Down
6 changes: 3 additions & 3 deletions CONNECT.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Furthermore, an Agent can utilize the custom header X-Connect-Token to transmit
{
"ref": "agent-01",
"aor": "sip:[email protected]",
"aorLink": "backend:voice",
"aorLink": "sip:voice@sip.local",
"domain": "sip.local",
"domainRef": "domain-01",
"allowedMethods": [ "INVITE", "REGISTER"],
Expand Down Expand Up @@ -245,7 +245,7 @@ Numbers represent virtual numbers that route calls from/to the PSTN via a Trunk.
"trunkRef": "trunk-01",
"location": {
"telUrl": "tel:+17066041487",
"aorLink": "backend:conference",
"aorLink": "sip:conference@sip.local",
"sessionAffinityHeader": "X-Room-Id",
"extraHeaders": [{
"name": "X-Room-Id",
Expand All @@ -268,7 +268,7 @@ Like Agents, Peers represent SIP endpoints such as Media Servers. Unlike Agents,
},
"spec": {
"username": "asterisk",
"aor": "backend:conference",
"aor": "sip:conference@sip.local",
"contactAddr": "192.168.1.2:6060",
"credentialsRef": "credentials-01",
"loadBalancing": {
Expand Down
6 changes: 4 additions & 2 deletions CORE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Routr Specification

### Version 0.1.4 (Draft)
### Version 0.1.5 (Draft)

<details>
<summary>Table of Contents</summary>
Expand Down Expand Up @@ -700,14 +700,16 @@ The following functions are MUST have for an implementation of a *Location Servi
- *Accept gRPC Requests* - Accept gRPC Requests
- *Find Routes* - Find all the routes to an endpoint
- *Filtering Labels* - MUST be able to store endpoints using labels (for filtering)
- *Backend or Endpoint* - MUST allow AOR the "sip:" and "backend:" schemes
- *Backend or Endpoint* - MUST allow AOR the "sip:" and "backend:" schemes ("backend:" is deprecated since v0.1.5)
- *Balancing Algorithm* - Implements `round-robin` and `least-sessions`
- *Session Affinity* - Implements session base affinity
- *Cache* - Caching must be done via "providers" that are easily replaceable (e.g.: `Memory`, `Redis`, etc.)
- *Health Check* - MUST have a mechanism to identify the health of the service
- *M.E.L.T* - Must be capable of collecting and sending M.E.L.T to external systems
- *Service Port* - The default gRPC port at the Location Service SHOULD be `51902`

> Since SPEC v0.1.5 using "backend:" scheme is deprecated. The Location Service will continue to support it for backward compatibility.
**Non-functional Requirements**

The following requirements are essential to have for an implementation of a *Location Service*:
Expand Down
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
##
## Build and pack the service
##
FROM alpine:3.18 as builder
FROM alpine:3.19 as builder
LABEL maintainer="Pedro Sanders <[email protected]>"

ENV JAVA_HOME=/usr/lib/jvm/java-11-openjdk
ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk
WORKDIR /work

COPY mods/one .
COPY mods/pgdata/schema.prisma .
COPY .scripts/custom-jre.sh .

RUN apk add --no-cache --update npm nodejs curl git tini python3 make cmake g++ openjdk11-jdk \
RUN apk add --no-cache --update npm nodejs curl git tini python3 make cmake g++ openjdk17-jdk \
&& sh custom-jre.sh \
&& npm install --omit=dev \
&& mv schema.prisma node_modules/@routr/pgdata/ \
Expand All @@ -23,7 +23,7 @@ RUN apk add --no-cache --update npm nodejs curl git tini python3 make cmake g++
##
## Runner
##
FROM alpine:3.18 as runner
FROM alpine:3.19 as runner

ARG PKCS_PASSWORD=changeme
ARG POSTGRES_USER=postgres
Expand All @@ -42,8 +42,7 @@ ENV PKCS_PASSWORD=$PKCS_PASSWORD \
CA_CERT_SUBJECT=$CA_CERT_SUBJECT \
SERVER_CERT_SUBJECT=$SERVER_CERT_SUBJECT \
DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@localhost:5432/routr \
IGNORE_LOOPBACK_FROM_LOCALNETS=true \
LOG4J2=/etc/routr/log4j2.yaml
IGNORE_LOOPBACK_FROM_LOCALNETS=true

WORKDIR /service

Expand Down
6 changes: 3 additions & 3 deletions config/resources/numbers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
trunkRef: trunk-01
location:
telUrl: tel:+17066041487
aorLink: backend:conference
aorLink: sip:conference@sip.local
sessionAffinityHeader: X-Room-Id
extraHeaders:
- name: X-Room-Id
Expand Down Expand Up @@ -60,7 +60,7 @@
trunkRef: trunk-03
location:
telUrl: tel:+18095863314
aorLink: backend:voice
aorLink: sip:voice@sip.local

- apiVersion: v2beta1
kind: Number
Expand All @@ -75,4 +75,4 @@
trunkRef: trunk-01
location:
telUrl: tel:+14045551212
aorLink: backend:voice
aorLink: sip:voice@sip.local
5 changes: 3 additions & 2 deletions config/resources/peers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
metadata:
name: Asterisk (Media Server)
spec:
aor: backend:conference
aor: sip:conference@sip.local
username: asterisk
credentialsRef: credentials-03
loadBalancing:
withSessionAffinity: true
algorithm: least-sessions

- apiVersion: v2beta1
kind: Peer
ref: peer-02
metadata:
name: FS Voice Feature Server
spec:
aor: backend:voice
aor: sip:voice@sip.local
username: freeswitch
credentialsRef: credentials-05
loadBalancing:
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/connect/command-line/ctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ DESCRIPTION
EXAMPLES
$ rctl peers get
Ref Name Username AOR Balancing Algorithm Session Affinity
6f941c63-880c-419a-a72a-4a107cbaf5c5 Asterisk Conference conference backend:conference ROUND_ROBIN Yes
Ref Name Username AOR Balancing Algorithm Session Affinity
6f941c63-880c-419a-a72a-4a107cbaf5c5 Asterisk Conference conference sip:conference@sip.local ROUND_ROBIN Yes
```

_See code: [dist/commands/peers/get.ts](https://github.com/fonoster/routr/blob/v2.1.11/dist/commands/peers/get.ts)_
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/connect/nodesdk/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ const peers = new SDK.Peers()
const request = {
name: "Asterisk Conference Server",
username: "conference",
aor: "backend:conference",
aor: "sip:conference@sip.local",
contactAddr: "10.0.0.1:5060",
accessControlListRef: "4671371b-ff5d-48b1-aabe-d3c5ca5317a3",
credentialsRef: "4671371b-ff5d-48b1-aabe-d3c5ca5317a3",
Expand Down Expand Up @@ -1004,7 +1004,7 @@ Creates a new Peer on Routr.
const request = {
name: "Asterisk Conference Server",
username: "conference",
aor: "backend:conference",
aor: "sip:conference@sip.local",
contactAddr: "10.0.0.1:5060",
accessControlListRef: "4671371b-ff5d-48b1-aabe-d3c5ca5317a3",
credentialsRef: "4671371b-ff5d-48b1-aabe-d3c5ca5317a3",
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/development/components/apiserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Filename: `numbers.yaml`
trunkRef: trunk-01
location:
telUrl: tel:+17066041487
aorLink: backend:conference
aorLink: sip:conference@sip.local
sessionAffinityHeader: X-Room-Id
extraHeaders:
- name: X-Room-Id
Expand Down Expand Up @@ -251,7 +251,7 @@ Filename: `peers.yaml`
metadata:
name: Asterisk (Media Server)
spec:
aor: backend:conference
aor: sip:conference@sip.local
username: asterisk
credentialsRef: credentials-03
loadBalancing:
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/development/components/location.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ref: peer-01
metadata:
name: Asterisk (Media Server)
spec:
aor: backend:conference
aor: sip:conference@sip.local
username: asterisk
credentialsRef: credentials-01
loadBalancing:
Expand All @@ -29,7 +29,7 @@ spec:
Notice that the load balancing section sets the `withSessionAffinity` to `true`. We need session affinity to ensure that all calls related to the conference arrive on the same Asterisk server.

Every Asterisk server that registers using the `asterisk` username will join the same group under the `backend:conference` Address of Record (AOR).
Every Asterisk server that registers using the `asterisk` username will join the same group under the `sip:conference@sip.local` Address of Record (AOR).

## Configuration Spec

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/overview/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ref: peer-01
metadata:
name: Asterisk (Media Server)
spec:
aor: backend:conference
aor: sip:conference@sip.local
username: asterisk
credentialsRef: credentials-01
loadBalancing:
Expand All @@ -135,7 +135,7 @@ spec:

Notice that the load balancing section sets the `withSessionAffinity` to `true`. We need session affinity to ensure that all calls related to the conference arrive on the same Asterisk server.

Every Asterisk server that registers using the `asterisk` username will join the same group under the `backend:conference` Address of Record (AOR).
Every Asterisk server that registers using the `asterisk` username will join the same group under the `sip:conference@sip.local` Address of Record (AOR).

## Middlewares

Expand Down
2 changes: 1 addition & 1 deletion docs/docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
* http://github.com/fonoster/routr
*
* This file is part of Routr.
Expand Down
2 changes: 1 addition & 1 deletion mods/common/src/assertions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
* http://github.com/fonoster/routr
*
* This file is part of Routr
Expand Down
67 changes: 4 additions & 63 deletions mods/common/src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
* http://github.com/fonoster/routr
*
* This file is part of Routr
Expand All @@ -16,16 +16,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AuthChallengeResponse, ResponseType } from "./types"
import { AuthChallengeResponse } from "./types"
import crypto from "crypto"

const DEFAULT_ALGORITHM = "MD5"
export const DEFAULT_ALGORITHM = "MD5"

const md5hex = (str: string, algorithm = DEFAULT_ALGORITHM) =>
crypto.createHash(algorithm).update(str).digest("hex")

const decToHex = (dec: number) =>
(dec + Math.pow(16, 8)).toString(16).substr(-8)
const decToHex = (dec: number) => (dec + Math.pow(16, 8)).toString(16).slice(-8)

export const generateNonce = (algorithm: string = DEFAULT_ALGORITHM) =>
md5hex(`${new Date().getTime()}${Math.random()}`, algorithm)
Expand Down Expand Up @@ -54,61 +53,3 @@ export const getCredentials = (
username: string,
users: { username: string; secret: string }[]
) => users.find((user) => user.username === username)

export const createUnauthorizedResponse = (
realm: string,
params: {
qop: string
algorithm: string
} = { qop: "auth", algorithm: DEFAULT_ALGORITHM }
) => {
return {
message: {
responseType: ResponseType.UNAUTHORIZED,
reasonPhrase: "Unauthorized",
wwwAuthenticate: {
scheme: "Digest",
realm: realm,
qop: params.qop,
opaque: "",
stale: false,
nonce: generateNonce(),
algorithm: params.algorithm
}
}
}
}

export const createUnauthorizedResponseWithoutChallenge = (
metadata?: Record<string, string>
) => {
return {
metadata,
message: {
responseType: ResponseType.UNAUTHORIZED,
reasonPhrase: "Unauthorized"
}
}
}

export const createServerInternalErrorResponse = (
metadata?: Record<string, string>
) => {
return {
metadata,
message: {
responseType: ResponseType.SERVER_INTERNAL_ERROR,
reasonPhrase: "Server Internal Error"
}
}
}

export const createForbideenResponse = (metadata?: Record<string, string>) => {
return {
metadata,
message: {
responseType: ResponseType.FORBIDDEN,
reasonPhrase: "Forbidden"
}
}
}
2 changes: 1 addition & 1 deletion mods/common/src/connect/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
* http://github.com/fonoster/routr
*
* This file is part of Routr
Expand Down
2 changes: 1 addition & 1 deletion mods/common/src/connect/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
* http://github.com/fonoster/routr
*
* This file is part of Routr.
Expand Down
2 changes: 1 addition & 1 deletion mods/common/src/connect/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
* http://github.com/fonoster/routr
*
* This file is part of Routr.
Expand Down
Loading

0 comments on commit 96410ee

Please sign in to comment.