@routr/edgeport 2.0.17 → 2.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import { EdgePortConfig, Transport } from "./types";
2
+ export declare const isSecureProto: (proto: string) => boolean;
3
+ export declare const assertHasSecurityContext: (config: EdgePortConfig) => void;
4
+ export declare const assertNoDuplicatedProto: (transports: Array<Transport>) => void;
5
+ export declare const assertNoDuplicatedPort: (transports: Array<Transport>) => void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertNoDuplicatedPort = exports.assertNoDuplicatedProto = exports.assertHasSecurityContext = exports.isSecureProto = void 0;
4
+ // We need to have the spec.securityContext for all secure protocol
5
+ const isSecureProto = (proto) => proto === "wss" || proto === "tls";
6
+ exports.isSecureProto = isSecureProto;
7
+ // We need to have the spec.securityContext for all secure protocol
8
+ const assertHasSecurityContext = (config) => {
9
+ const hasSecureProto = config.spec.transport.some((t1) => (0, exports.isSecureProto)(t1.protocol));
10
+ if (hasSecureProto && !config.spec.securityContext) {
11
+ throw new Error("found at least one secure protocol which requires setting the .spec.securityContext");
12
+ }
13
+ };
14
+ exports.assertHasSecurityContext = assertHasSecurityContext;
15
+ // Only one entry per protocol is allowed
16
+ const assertNoDuplicatedProto = (transports) => {
17
+ if (transports.some((t1) => transports.filter((t2) => t1.protocol === t2.protocol).length > 1)) {
18
+ throw new Error("found duplicated entries at .spec.transport");
19
+ }
20
+ };
21
+ exports.assertNoDuplicatedProto = assertNoDuplicatedProto;
22
+ // The only protocol that can accept the same port twice are udp and tcp
23
+ const assertNoDuplicatedPort = (transports) => {
24
+ const duplicateCondition = (t1, t2) => t1.port === t2.port && t1.protocol !== "UDP" && t1.protocol !== "TCP";
25
+ if (transports
26
+ .map((t) => {
27
+ return {
28
+ port: t.port,
29
+ protocol: t.protocol.toUpperCase()
30
+ };
31
+ })
32
+ .some((t1) => transports.filter((t2) => duplicateCondition(t1, t2)).length > 1)) {
33
+ throw new Error("found the same port on more that one entry at .spec.transport");
34
+ }
35
+ };
36
+ exports.assertNoDuplicatedPort = assertNoDuplicatedPort;
@@ -0,0 +1,16 @@
1
+ import { JsonObject } from "pb-util/build";
2
+ export declare const readFile: (path: string) => string;
3
+ export declare const exists: (path: string) => any;
4
+ export declare const isFile: (path: string) => any;
5
+ /**
6
+ * Reads a file and returns a JSON object or throws an error.
7
+ * The file must be a valid JSON, YAML, or TOML file.
8
+ *
9
+ * @param {string} path - The path to the file.
10
+ * @return {object} The JSON object.
11
+ * @throws {Error} If the file is not a valid JSON, YAML, or TOML file.
12
+ * @throws {Error} If the file does not exist.
13
+ * @throws {Error} If the file is not readable.
14
+ * @throws {Error} If the file is empty.
15
+ */
16
+ export declare const readConfigFile: (path: string) => JsonObject;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.readConfigFile = exports.isFile = exports.exists = exports.readFile = void 0;
27
+ const yaml = __importStar(require("js-yaml"));
28
+ const toml = __importStar(require("toml"));
29
+ const JFile = Java.type("java.io.File");
30
+ const Files = Java.type("java.nio.file.Files");
31
+ const Paths = Java.type("java.nio.file.Paths");
32
+ const readFile = (path) => {
33
+ const lines = Files.readAllLines(Paths.get(path), Java.type("java.nio.charset.StandardCharsets").UTF_8);
34
+ const data = [];
35
+ lines.forEach((line) => {
36
+ data.push(line);
37
+ });
38
+ return data.join("\n").trim();
39
+ };
40
+ exports.readFile = readFile;
41
+ const exists = (path) => new JFile(path).exists();
42
+ exports.exists = exists;
43
+ const isFile = (path) => new JFile(path).isFile();
44
+ exports.isFile = isFile;
45
+ /**
46
+ * Reads a file and returns a JSON object or throws an error.
47
+ * The file must be a valid JSON, YAML, or TOML file.
48
+ *
49
+ * @param {string} path - The path to the file.
50
+ * @return {object} The JSON object.
51
+ * @throws {Error} If the file is not a valid JSON, YAML, or TOML file.
52
+ * @throws {Error} If the file does not exist.
53
+ * @throws {Error} If the file is not readable.
54
+ * @throws {Error} If the file is empty.
55
+ */
56
+ const readConfigFile = (path) => {
57
+ if (!(0, exports.exists)(path) || !(0, exports.isFile)(path)) {
58
+ throw new Error(`config file ${path} does not exist`);
59
+ }
60
+ const content = (0, exports.readFile)(path);
61
+ try {
62
+ return yaml.load(content);
63
+ }
64
+ catch (e) {
65
+ // Ignore
66
+ }
67
+ // Experimental TOML support
68
+ try {
69
+ return toml.parse(content);
70
+ }
71
+ catch (e) {
72
+ // Ignore
73
+ }
74
+ try {
75
+ return JSON.parse(content);
76
+ }
77
+ catch (e) {
78
+ throw new Error("file is not a valid JSON or YAML file");
79
+ }
80
+ };
81
+ exports.readConfigFile = readConfigFile;
@@ -0,0 +1,5 @@
1
+ import * as J from "fp-ts/Json";
2
+ import * as E from "fp-ts/Either";
3
+ export declare const readFile: (path: string) => E.Either<Error, string>;
4
+ export declare const validateConfig: (j: J.Json) => E.Either<Error, J.Json>;
5
+ export declare const getConfig: <C>(path: string) => E.Either<Error, C>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.getConfig = exports.validateConfig = exports.readFile = void 0;
30
+ const E = __importStar(require("fp-ts/Either"));
31
+ const ajv_1 = __importDefault(require("ajv"));
32
+ const function_1 = require("fp-ts/function");
33
+ const schema_1 = require("./schema");
34
+ const fs_1 = require("./fs");
35
+ const ajv = new ajv_1.default();
36
+ const validate = ajv.compile(schema_1.schema);
37
+ // TODO: Fix this unnecessary conversion to string
38
+ const readFile = (path) => E.tryCatch(() => JSON.stringify((0, fs_1.readConfigFile)(path)), E.toError);
39
+ exports.readFile = readFile;
40
+ // Validate Json with Ajv
41
+ const validateConfig = (j) => E.tryCatch(() => {
42
+ if (validate(j))
43
+ return j;
44
+ throw new Error(validate.errors[0].message);
45
+ }, E.toError);
46
+ exports.validateConfig = validateConfig;
47
+ // Read a file and validate its content with Ajv
48
+ const getConfig = (path) => (0, function_1.pipe)(path, exports.readFile, E.chain((value) => (0, function_1.pipe)(E.tryCatch(() => JSON.parse(value), E.toError), E.chain(exports.validateConfig))), E.map((v) => v));
49
+ exports.getConfig = getConfig;
@@ -0,0 +1,99 @@
1
+ export declare const schema: {
2
+ $id: string;
3
+ title: string;
4
+ description: string;
5
+ type: string;
6
+ properties: {
7
+ kind: {
8
+ description: string;
9
+ type: string;
10
+ };
11
+ apiVersion: {
12
+ enum: string[];
13
+ };
14
+ ref: {
15
+ description: string;
16
+ type: string;
17
+ };
18
+ metadata: {
19
+ description: string;
20
+ type: string;
21
+ properties: {
22
+ region: {
23
+ description: string;
24
+ type: string;
25
+ };
26
+ };
27
+ };
28
+ spec: {
29
+ description: string;
30
+ type: string;
31
+ properties: {
32
+ bindAddr: {
33
+ description: string;
34
+ type: string;
35
+ };
36
+ externalAddrs: {
37
+ description: string;
38
+ type: string;
39
+ items: {
40
+ type: string;
41
+ };
42
+ uniqueItems: boolean;
43
+ minItems: number;
44
+ };
45
+ localnets: {
46
+ description: string;
47
+ type: string;
48
+ items: {
49
+ type: string;
50
+ };
51
+ uniqueItems: boolean;
52
+ minItems: number;
53
+ };
54
+ methods: {
55
+ description: string;
56
+ type: string;
57
+ items: {
58
+ type: string;
59
+ };
60
+ uniqueItems: boolean;
61
+ };
62
+ unknownMethodAction: {
63
+ description: string;
64
+ enum: string[];
65
+ };
66
+ transport: {
67
+ description: string;
68
+ type: string;
69
+ items: {
70
+ type: string;
71
+ };
72
+ properties: {
73
+ protocol: {
74
+ type: string;
75
+ };
76
+ bindAddr: {
77
+ type: string;
78
+ };
79
+ port: {
80
+ type: string;
81
+ };
82
+ };
83
+ required: string[];
84
+ };
85
+ processor: {
86
+ description: string;
87
+ type: string;
88
+ properties: {
89
+ addr: {
90
+ type: string;
91
+ };
92
+ };
93
+ };
94
+ };
95
+ required: string[];
96
+ };
97
+ };
98
+ required: string[];
99
+ };
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.schema = void 0;
4
+ /*
5
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster/routr
7
+ *
8
+ * This file is part of Routr
9
+ *
10
+ * Licensed under the MIT License (the "License");
11
+ * you may not use this file except in compliance with
12
+ * the License. You may obtain a copy of the License at
13
+ *
14
+ * https://opensource.org/licenses/MIT
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ exports.schema = {
23
+ $id: "https://json-schema.org/draft/2020-12/schema",
24
+ title: "EdgPort configuration",
25
+ description: "Configuration for an EdgePort instance",
26
+ type: "object",
27
+ properties: {
28
+ kind: {
29
+ description: "Resouce type",
30
+ type: "string"
31
+ },
32
+ apiVersion: {
33
+ enum: ["v2beta1", "v2"]
34
+ },
35
+ ref: {
36
+ description: "EdgePort reference",
37
+ type: "string"
38
+ },
39
+ metadata: {
40
+ description: "Resource metadata",
41
+ type: "object",
42
+ properties: {
43
+ region: {
44
+ description: "Optional region where the EdgePort is operating",
45
+ type: "string"
46
+ }
47
+ }
48
+ },
49
+ spec: {
50
+ description: "Operation spec for the EdgePort",
51
+ type: "object",
52
+ properties: {
53
+ bindAddr: {
54
+ description: "Ipv4 interface to accept request on",
55
+ type: "string"
56
+ },
57
+ externalAddrs: {
58
+ description: "EdgePort external ip addresses.",
59
+ type: "array",
60
+ items: {
61
+ type: "string"
62
+ },
63
+ uniqueItems: true,
64
+ minItems: 0
65
+ },
66
+ localnets: {
67
+ description: "Networks considered to be in the same local network",
68
+ type: "array",
69
+ items: {
70
+ type: "string"
71
+ },
72
+ uniqueItems: true,
73
+ minItems: 0
74
+ },
75
+ methods: {
76
+ description: "Acceptable SIP Methods",
77
+ type: "array",
78
+ items: {
79
+ type: "string"
80
+ },
81
+ uniqueItems: true
82
+ },
83
+ unknownMethodAction: {
84
+ description: "What to do if an incomming request type is not allowed",
85
+ enum: ["Discard", "Respond"]
86
+ },
87
+ transport: {
88
+ description: "Acceptable Transport Protocols",
89
+ type: "array",
90
+ items: {
91
+ type: "object"
92
+ },
93
+ properties: {
94
+ protocol: {
95
+ type: "string"
96
+ },
97
+ bindAddr: {
98
+ type: "string"
99
+ },
100
+ port: {
101
+ type: "integer"
102
+ }
103
+ },
104
+ required: ["port", "protocol"]
105
+ },
106
+ processor: {
107
+ description: "Adjacent service for message routing",
108
+ type: "object",
109
+ properties: {
110
+ addr: {
111
+ type: "string"
112
+ }
113
+ }
114
+ }
115
+ },
116
+ required: ["methods", "transport", "processor"]
117
+ }
118
+ },
119
+ required: ["kind", "ref", "spec", "apiVersion"]
120
+ };
@@ -0,0 +1,9 @@
1
+ import { EdgePortConfig, ListeningPoint, SipStack } from "./types";
2
+ /**
3
+ * Creates "listening" points for all the given transport.
4
+ *
5
+ * @param {SipStack} sipStack - SipStack to create LPs for
6
+ * @param {EdgePortConfig} config - Edgeport configuration
7
+ * @return {ListeningPoint[]}
8
+ */
9
+ export default function createListeningPoints(sipStack: SipStack, config: EdgePortConfig): Array<ListeningPoint>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Creates "listening" points for all the given transport.
5
+ *
6
+ * @param {SipStack} sipStack - SipStack to create LPs for
7
+ * @param {EdgePortConfig} config - Edgeport configuration
8
+ * @return {ListeningPoint[]}
9
+ */
10
+ function createListeningPoints(sipStack, config) {
11
+ var _a;
12
+ const listeningPoints = [];
13
+ (_a = config.spec.transport) === null || _a === void 0 ? void 0 : _a.forEach((trans) => {
14
+ const proto = trans.protocol.toLowerCase();
15
+ // If none was found we use the global bindAddr
16
+ if (trans.bindAddr === undefined) {
17
+ trans.bindAddr = config.spec.bindAddr;
18
+ }
19
+ try {
20
+ const lp = sipStack.createListeningPoint(trans.bindAddr, trans.port, proto);
21
+ listeningPoints.push(lp);
22
+ }
23
+ catch (e) {
24
+ throw new Error(`unable to bind ${proto}://${trans.bindAddr}:${trans.port}`);
25
+ }
26
+ });
27
+ return listeningPoints;
28
+ }
29
+ exports.default = createListeningPoints;
@@ -0,0 +1,9 @@
1
+ import { ListeningPoint, SipProvider, SipStack } from "./types";
2
+ /**
3
+ * Creates a new SIP provider object.
4
+ *
5
+ * @param {SipStack} sipStack - SIP stack to use
6
+ * @param {Array<ListeningPoint>} listeningPoints - Listening points to use
7
+ * @return {SipProvider}
8
+ */
9
+ export default function createSipProvider(sipStack: SipStack, listeningPoints: Array<ListeningPoint>): SipProvider;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Creates a new SIP provider object.
5
+ *
6
+ * @param {SipStack} sipStack - SIP stack to use
7
+ * @param {Array<ListeningPoint>} listeningPoints - Listening points to use
8
+ * @return {SipProvider}
9
+ */
10
+ function createSipProvider(sipStack, listeningPoints) {
11
+ const sipProvider = sipStack.createSipProvider(listeningPoints[0]);
12
+ listeningPoints
13
+ .filter((_, index) => index > 0)
14
+ .forEach((lp1) => {
15
+ sipProvider.addListeningPoint(lp1);
16
+ });
17
+ return sipProvider;
18
+ }
19
+ exports.default = createSipProvider;
@@ -0,0 +1,10 @@
1
+ import { SipStack } from "./types";
2
+ declare const Properties: any;
3
+ /**
4
+ * Takes a properties map and returns an instance of the SipStack(Java object).
5
+ *
6
+ * @param {Properties} properties - Properties map
7
+ * @return {SipStack}
8
+ */
9
+ export default function createSipStack(properties: typeof Properties): SipStack;
10
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const SipFactory = Java.type("javax.sip.SipFactory");
4
+ const Properties = Java.type("java.util.Properties");
5
+ /**
6
+ * Takes a properties map and returns an instance of the SipStack(Java object).
7
+ *
8
+ * @param {Properties} properties - Properties map
9
+ * @return {SipStack}
10
+ */
11
+ function createSipStack(properties) {
12
+ const sipFactory = SipFactory.getInstance();
13
+ sipFactory.setPathName("gov.nist");
14
+ return sipFactory.createSipStack(properties);
15
+ }
16
+ exports.default = createSipStack;
@@ -0,0 +1,7 @@
1
+ import { EdgePortConfig } from "./types";
2
+ /**
3
+ * Starts a new Edgeport service.
4
+ *
5
+ * @param {EdgePortConfig} config - Edgeport configuration
6
+ */
7
+ export default function edgePort(config: EdgePortConfig): void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const assertions_1 = require("./assertions");
7
+ const envs_1 = require("./envs");
8
+ const create_listening_points_1 = __importDefault(require("./create_listening_points"));
9
+ const create_sip_provider_1 = __importDefault(require("./create_sip_provider"));
10
+ const create_sip_stack_1 = __importDefault(require("./create_sip_stack"));
11
+ const server_properties_1 = __importDefault(require("./server_properties"));
12
+ const GRPCSipListener = Java.type("io.routr.GRPCSipListener");
13
+ const ArrayList = Java.type("java.util.ArrayList");
14
+ /**
15
+ * Starts a new Edgeport service.
16
+ *
17
+ * @param {EdgePortConfig} config - Edgeport configuration
18
+ */
19
+ function edgePort(config) {
20
+ var _a, _b;
21
+ (0, assertions_1.assertNoDuplicatedProto)(config.spec.transport);
22
+ (0, assertions_1.assertNoDuplicatedPort)(config.spec.transport);
23
+ (0, assertions_1.assertHasSecurityContext)(config);
24
+ const sipStack = (0, create_sip_stack_1.default)((0, server_properties_1.default)(config));
25
+ const sipProvider = (0, create_sip_provider_1.default)(sipStack, (0, create_listening_points_1.default)(sipStack, config));
26
+ const externalAddrs = new ArrayList();
27
+ const localnets = new ArrayList();
28
+ // Addresses from the environment
29
+ if (envs_1.EXTERNAL_ADDRS) {
30
+ envs_1.EXTERNAL_ADDRS.forEach((addr) => externalAddrs.add(addr));
31
+ }
32
+ (_a = config.spec.externalAddrs) === null || _a === void 0 ? void 0 : _a.forEach((addr) => externalAddrs.add(addr));
33
+ (_b = config.spec.localnets) === null || _b === void 0 ? void 0 : _b.forEach((net) => localnets.add(net));
34
+ sipProvider.addSipListener(new GRPCSipListener(sipProvider, config, externalAddrs, localnets));
35
+ }
36
+ exports.default = edgePort;
package/dist/envs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const EXTERNAL_ADDRS: string[];
package/dist/envs.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ var _a, _b;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.EXTERNAL_ADDRS = void 0;
5
+ exports.EXTERNAL_ADDRS = (_b = (_a = System.getenv("EXTERNAL_ADDRS")) === null || _a === void 0 ? void 0 : _a.split(",")) !== null && _b !== void 0 ? _b : [];
@@ -0,0 +1 @@
1
+ export {};
package/dist/runner.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ // require("./tracer").init("dispatcher")
8
+ const get_config_1 = require("./config/get_config");
9
+ const edgeport_1 = __importDefault(require("./edgeport"));
10
+ const config = (0, get_config_1.getConfig)(System.getenv("CONFIG_PATH"));
11
+ if (config._tag === "Right") {
12
+ // TODO: Remove this once we have a proper config (It should be managed by getConfig)
13
+ config.right.spec.bindAddr = (_a = config.right.spec.bindAddr) !== null && _a !== void 0 ? _a : "0.0.0.0";
14
+ (0, edgeport_1.default)(config.right);
15
+ }
16
+ else {
17
+ // WARNING: Using @fonoster/logger causes conflict with Webpack.
18
+ // eslint-disable-next-line no-console
19
+ console.log(config.left);
20
+ }
@@ -0,0 +1,12 @@
1
+ import { EdgePortConfig } from "./types";
2
+ declare const Properties: any;
3
+ /**
4
+ * Returns a Map object with the properties for the server's SipStack.
5
+ * For more options see:
6
+ * https://github.com/RestComm/jain-sip/blob/master/src/gov/nist/javax/sip/SipStackImpl.java
7
+ *
8
+ * @param {EdgePortConfig} config - Configuration object
9
+ * @return {Properties}
10
+ */
11
+ export default function getServerProperties(config: EdgePortConfig): typeof Properties;
12
+ export {};
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Properties = Java.type("java.util.Properties");
4
+ /**
5
+ * Returns a Map object with the properties for the server's SipStack.
6
+ * For more options see:
7
+ * https://github.com/RestComm/jain-sip/blob/master/src/gov/nist/javax/sip/SipStackImpl.java
8
+ *
9
+ * @param {EdgePortConfig} config - Configuration object
10
+ * @return {Properties}
11
+ */
12
+ function getServerProperties(config) {
13
+ var _a, _b;
14
+ const properties = new Properties();
15
+ properties.setProperty("javax.sip.STACK_NAME", "routr");
16
+ properties.setProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT", "OFF");
17
+ properties.setProperty("gov.nist.javax.sip.MESSAGE_PROCESSOR_FACTORY", "gov.nist.javax.sip.stack.NioMessageProcessorFactory");
18
+ properties.setProperty("gov.nist.javax.sip.PATCH_SIP_WEBSOCKETS_HEADERS", "false");
19
+ properties.setProperty("gov.nist.javax.sip.CACHE_CLIENT_CONNECTIONS", "true");
20
+ properties.setProperty("gov.nist.javax.sip.REENTRANT_LISTENER", "false");
21
+ properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE", "16");
22
+ properties.setProperty("gov.nist.javax.sip.NIO_BLOCKING_MODE", "NONBLOCKING");
23
+ // Guard against denial of service attack.
24
+ properties.setProperty("gov.nist.javax.sip.MAX_MESSAGE_SIZE", "1048576");
25
+ properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "true");
26
+ // Default host
27
+ properties.setProperty("javax.sip.IP_ADDRESS", config.spec.bindAddr);
28
+ if (config.spec.securityContext) {
29
+ properties.setProperty("gov.nist.javax.sip.TLS_CLIENT_PROTOCOLS", (_a = config.spec.securityContext.client) === null || _a === void 0 ? void 0 : _a.protocols.join());
30
+ // This must be set to 'Disabled' when using WSS
31
+ properties.setProperty("gov.nist.javax.sip.TLS_CLIENT_AUTH_TYPE", (_b = config.spec.securityContext.client) === null || _b === void 0 ? void 0 : _b.authType);
32
+ properties.setProperty("javax.net.ssl.keyStore", config.spec.securityContext.keyStore);
33
+ properties.setProperty("javax.net.ssl.trustStore", config.spec.securityContext.trustStore);
34
+ properties.setProperty("javax.net.ssl.keyStorePassword", config.spec.securityContext.keyStorePassword);
35
+ properties.setProperty("javax.net.ssl.trustStorePassword", config.spec.securityContext.trustStorePassword);
36
+ properties.setProperty("javax.net.ssl.keyStoreType", config.spec.securityContext.keyStoreType);
37
+ }
38
+ return properties;
39
+ }
40
+ exports.default = getServerProperties;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This function registers the instrumentations for the service.
3
+ *
4
+ * @param {string} serviceName - The name of the service.
5
+ * @return {Tracer} The tracer object.
6
+ */
7
+ export declare function init(serviceName: string): import("@opentelemetry/api").Tracer;
package/dist/tracer.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.init = void 0;
7
+ /*
8
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
9
+ * http://github.com/fonoster/routr
10
+ *
11
+ * This file is part of Routr
12
+ *
13
+ * Licensed under the MIT License (the "License")
14
+ * you may not use this file except in compliance with
15
+ * the License. You may obtain a copy of the License at
16
+ *
17
+ * https://opensource.org/licenses/MIT
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ const api_1 = __importDefault(require("@opentelemetry/api"));
26
+ const instrumentation_1 = require("@opentelemetry/instrumentation");
27
+ const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
28
+ const resources_1 = require("@opentelemetry/resources");
29
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
30
+ const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
31
+ const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
32
+ const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
33
+ /**
34
+ * This function registers the instrumentations for the service.
35
+ *
36
+ * @param {string} serviceName - The name of the service.
37
+ * @return {Tracer} The tracer object.
38
+ */
39
+ function init(serviceName) {
40
+ const provider = new sdk_trace_node_1.NodeTracerProvider({
41
+ resource: new resources_1.Resource({
42
+ [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName
43
+ })
44
+ });
45
+ const exporter = new exporter_jaeger_1.JaegerExporter();
46
+ provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
47
+ provider.register();
48
+ (0, instrumentation_1.registerInstrumentations)({
49
+ instrumentations: [new instrumentation_grpc_1.GrpcInstrumentation()]
50
+ });
51
+ return api_1.default.trace.getTracer("routr-tracer");
52
+ }
53
+ exports.init = init;
@@ -0,0 +1,41 @@
1
+ export interface Transport {
2
+ protocol: string;
3
+ bindAddr?: string;
4
+ port: number;
5
+ }
6
+ export interface EdgePortConfig {
7
+ spec: {
8
+ bindAddr: string;
9
+ transport: Transport[];
10
+ processor: {
11
+ addr: string;
12
+ };
13
+ externalAddrs?: string[];
14
+ localnets: string[];
15
+ securityContext?: {
16
+ debugging: boolean;
17
+ keyStore: string;
18
+ trustStore: string;
19
+ trustStorePassword: string;
20
+ keyStorePassword: string;
21
+ keyStoreType: string;
22
+ client: {
23
+ authType: string;
24
+ protocols: string[];
25
+ };
26
+ };
27
+ };
28
+ }
29
+ export declare interface SipStack {
30
+ createListeningPoint: (bindAddr: string, port: number, proto: string) => unknown;
31
+ createSipProvider: (lp: ListeningPoint) => SipProvider;
32
+ getClass: any;
33
+ }
34
+ export declare interface ListeningPoint {
35
+ }
36
+ export declare interface Java {
37
+ }
38
+ export declare interface SipProvider {
39
+ addListeningPoint: (lp: ListeningPoint) => void;
40
+ addSipListener: (lp: unknown) => void;
41
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/edgeport",
3
- "version": "2.0.17",
3
+ "version": "2.0.22",
4
4
  "description": "SIP endpoint at the edge of the network",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -29,11 +29,11 @@
29
29
  "url": "https://github.com/fonoster/routr/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@routr/common": "^2.0.17",
32
+ "@routr/common": "^2.0.20",
33
33
  "ajv": "^6.12.6",
34
34
  "fp-ts": "^2.11.8",
35
35
  "js-yaml": "^4.1.0",
36
36
  "toml": "^3.0.0"
37
37
  },
38
- "gitHead": "528a9e36b1b7dd1f885d04ee516ad6c75333ad18"
38
+ "gitHead": "acdbbb654d3066d0fdedecc29fbf0b65fbd22788"
39
39
  }