@routr/edgeport 2.0.5-alpha.2 → 2.0.5-alpha.21

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.
@@ -2,35 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assertNoDuplicatedPort = exports.assertNoDuplicatedProto = exports.assertHasSecurityContext = exports.isSecureProto = void 0;
4
4
  // We need to have the spec.securityContext for all secure protocol
5
- var isSecureProto = function (proto) { return proto === 'wss' || proto === 'tls'; };
5
+ const isSecureProto = (proto) => proto === "wss" || proto === "tls";
6
6
  exports.isSecureProto = isSecureProto;
7
7
  // We need to have the spec.securityContext for all secure protocol
8
- var assertHasSecurityContext = function (config) {
9
- var hasSecureProto = config.spec.transport.some(function (t1) { return exports.isSecureProto(t1.protocol); });
8
+ const assertHasSecurityContext = (config) => {
9
+ const hasSecureProto = config.spec.transport.some((t1) => (0, exports.isSecureProto)(t1.protocol));
10
10
  if (hasSecureProto && !config.spec.securityContext) {
11
- throw new Error('found at least one secure protocol which requires setting the .spec.securityContext');
11
+ throw new Error("found at least one secure protocol which requires setting the .spec.securityContext");
12
12
  }
13
13
  };
14
14
  exports.assertHasSecurityContext = assertHasSecurityContext;
15
15
  // Only one entry per protocol is allowed
16
- var assertNoDuplicatedProto = function (transports) {
17
- if (transports.some(function (t1) {
18
- return transports.filter(function (t2) { return t1.protocol === t2.protocol; }).length > 1;
19
- })) {
20
- throw new Error('found duplicated entries at .spec.transport');
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");
21
19
  }
22
20
  };
23
21
  exports.assertNoDuplicatedProto = assertNoDuplicatedProto;
24
22
  // The only protocol that can accept the same port twice are udp and tcp
25
- var assertNoDuplicatedPort = function (transports) {
26
- var duplicateCondition = function (t1, t2) {
27
- return (t1.port === t2.port &&
28
- t1.protocol !== 'udp' &&
29
- t1.protocol !== 'tcp');
30
- };
31
- if (transports.some(function (t1) {
32
- return transports.filter(function (t2) { return duplicateCondition(t1, t2); }).length > 1;
33
- })) {
23
+ const assertNoDuplicatedPort = (transports) => {
24
+ const duplicateCondition = (t1, t2) => t1.port === t2.port && t1.protocol !== "udp" && t1.protocol !== "tcp";
25
+ if (transports.some((t1) => transports.filter((t2) => duplicateCondition(t1, t2)).length > 1)) {
34
26
  throw new Error("found the same port on more that one entry at .spec.transport");
35
27
  }
36
28
  };
@@ -1,2 +1,2 @@
1
- export declare const readFile: (path: string) => any;
1
+ export declare const readFile: (path: string) => string;
2
2
  export declare const writeFile: (path: string, text: string) => void;
package/dist/config/fs.js CHANGED
@@ -1,23 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.writeFile = exports.readFile = void 0;
4
- var BufferedWriter = Java.type('java.io.BufferedWriter');
5
- var FileWriter = Java.type('java.io.FileWriter');
6
- var JFile = Java.type('java.io.File');
7
- var Files = Java.type('java.nio.file.Files');
8
- var Paths = Java.type('java.nio.file.Paths');
9
- var readFile = function (path) {
10
- var lines = Files.readAllLines(Paths.get(path), Java.type('java.nio.charset.StandardCharsets').UTF_8);
11
- var data = [];
12
- lines.forEach(function (line) {
4
+ const BufferedWriter = Java.type("java.io.BufferedWriter");
5
+ const FileWriter = Java.type("java.io.FileWriter");
6
+ const JFile = Java.type("java.io.File");
7
+ const Files = Java.type("java.nio.file.Files");
8
+ const Paths = Java.type("java.nio.file.Paths");
9
+ const readFile = (path) => {
10
+ const lines = Files.readAllLines(Paths.get(path), Java.type("java.nio.charset.StandardCharsets").UTF_8);
11
+ const data = [];
12
+ lines.forEach((line) => {
13
13
  data.push(line);
14
14
  });
15
- return data.join('\n').trim();
15
+ return data.join("\n").trim();
16
16
  };
17
17
  exports.readFile = readFile;
18
- var writeFile = function (path, text) {
19
- var file = new JFile(path);
20
- var out = new BufferedWriter(new FileWriter(file));
18
+ const writeFile = (path, text) => {
19
+ const file = new JFile(path);
20
+ const out = new BufferedWriter(new FileWriter(file));
21
21
  out.write(text);
22
22
  out.close();
23
23
  };
@@ -1,5 +1,5 @@
1
- import * as J from 'fp-ts/Json';
2
- import * as E from 'fp-ts/Either';
1
+ import * as J from "fp-ts/Json";
2
+ import * as E from "fp-ts/Either";
3
3
  export declare const readFile: (path: string) => E.Either<Error, string>;
4
4
  export declare const validateConfig: (j: J.Json) => E.Either<Error, J.Json>;
5
5
  export declare const getConfig: <C>(path: string) => E.Either<Error, C>;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -23,31 +27,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
27
  };
24
28
  Object.defineProperty(exports, "__esModule", { value: true });
25
29
  exports.getConfig = exports.validateConfig = exports.readFile = void 0;
26
- var E = __importStar(require("fp-ts/Either"));
27
- var F = __importStar(require("./fs"));
28
- var function_1 = require("fp-ts/function");
29
- var schema_1 = require("./schema");
30
- var ajv_1 = __importDefault(require("ajv"));
31
- var ajv = new ajv_1.default();
32
- var validate = ajv.compile(schema_1.schema);
30
+ const E = __importStar(require("fp-ts/Either"));
31
+ const F = __importStar(require("./fs"));
32
+ const function_1 = require("fp-ts/function");
33
+ const schema_1 = require("./schema");
34
+ const ajv_1 = __importDefault(require("ajv"));
35
+ const ajv = new ajv_1.default();
36
+ const validate = ajv.compile(schema_1.schema);
33
37
  // Reads a file a returns as a string
34
- var readFile = function (path) {
35
- return E.tryCatch(function () { return F.readFile(path); }, E.toError);
36
- };
38
+ const readFile = (path) => E.tryCatch(() => F.readFile(path), E.toError);
37
39
  exports.readFile = readFile;
38
40
  // Validate Json with Ajv
39
- var validateConfig = function (j) {
40
- return E.tryCatch(function () {
41
- if (validate(j))
42
- return j;
43
- throw new Error(validate.errors[0].message);
44
- }, E.toError);
45
- };
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
46
  exports.validateConfig = validateConfig;
47
47
  // Read a file and validate its content with Ajv
48
- var getConfig = function (path) {
49
- return function_1.pipe(path, exports.readFile, E.chain(function (value) {
50
- return function_1.pipe(E.tryCatch(function () { return JSON.parse(value); }, E.toError), E.chain(exports.validateConfig));
51
- }), E.map(function (v) { return v; }));
52
- };
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));
53
49
  exports.getConfig = getConfig;
@@ -34,7 +34,7 @@ export declare const schema: {
34
34
  description: string;
35
35
  type: string;
36
36
  };
37
- externalAddrs: {
37
+ externalIps: {
38
38
  description: string;
39
39
  type: string;
40
40
  items: {
@@ -60,6 +60,10 @@ export declare const schema: {
60
60
  };
61
61
  uniqueItems: boolean;
62
62
  };
63
+ unknownMethodAction: {
64
+ description: string;
65
+ enum: string[];
66
+ };
63
67
  transport: {
64
68
  description: string;
65
69
  type: string;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.schema = void 0;
4
4
  /*
5
- * Copyright (C) 2021 by Fonoster Inc (https://fonoster.com)
5
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/routr
7
7
  *
8
8
  * This file is part of Routr
@@ -20,98 +20,102 @@ exports.schema = void 0;
20
20
  * limitations under the License.
21
21
  */
22
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"
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
31
  },
32
- "apiVersion": {
33
- "enum": ["v2draft1", "v2.0", "v2"]
32
+ apiVersion: {
33
+ enum: ["v2draft1", "v2.0", "v2"]
34
34
  },
35
- "metadata": {
36
- "description": "Resource metadata",
37
- "type": "object",
38
- "properties": {
39
- "ref": {
40
- "description": "EdgePort reference",
41
- "type": "string"
35
+ metadata: {
36
+ description: "Resource metadata",
37
+ type: "object",
38
+ properties: {
39
+ ref: {
40
+ description: "EdgePort reference",
41
+ type: "string"
42
42
  },
43
- "region": {
44
- "description": "Optional region where the EdgePort is operating",
45
- "type": "string"
43
+ region: {
44
+ description: "Optional region where the EdgePort is operating",
45
+ type: "string"
46
46
  }
47
47
  },
48
- "required": ["ref"]
48
+ required: ["ref"]
49
49
  },
50
- "spec": {
51
- "description": "Operation spec for the EdgePort",
52
- "type": "object",
53
- "properties": {
54
- "bindAddr": {
55
- "description": "Ipv4 interface to accept request on",
56
- "type": "string"
50
+ spec: {
51
+ description: "Operation spec for the EdgePort",
52
+ type: "object",
53
+ properties: {
54
+ bindAddr: {
55
+ description: "Ipv4 interface to accept request on",
56
+ type: "string"
57
57
  },
58
- "externalAddrs": {
59
- "description": "EdgePort external addresses. Might be Ipv4, Hostname",
60
- "type": "array",
61
- "items": {
62
- "type": "string"
58
+ externalIps: {
59
+ description: "EdgePort external ip addresses.",
60
+ type: "array",
61
+ items: {
62
+ type: "string"
63
63
  },
64
- "uniqueItems": true,
65
- "minItems": 1,
64
+ uniqueItems: true,
65
+ minItems: 1
66
66
  },
67
- "localnets": {
68
- "description": "Networks considered to be in the same local network",
69
- "type": "array",
70
- "items": {
71
- "type": "string"
67
+ localnets: {
68
+ description: "Networks considered to be in the same local network",
69
+ type: "array",
70
+ items: {
71
+ type: "string"
72
72
  },
73
- "uniqueItems": true,
74
- "minItems": 1,
73
+ uniqueItems: true,
74
+ minItems: 1
75
75
  },
76
- "methods": {
77
- "description": "Acceptable SIP Methods",
78
- "type": "array",
79
- "items": {
80
- "type": "string"
76
+ methods: {
77
+ description: "Acceptable SIP Methods",
78
+ type: "array",
79
+ items: {
80
+ type: "string"
81
81
  },
82
- "uniqueItems": true
82
+ uniqueItems: true
83
83
  },
84
- "transport": {
85
- "description": "Acceptable Transport Protocols",
86
- "type": "array",
87
- "items": {
88
- "type": "object"
84
+ unknownMethodAction: {
85
+ description: "What to do if an incomming request type is not allowed",
86
+ enum: ["Discard", "Respond"]
87
+ },
88
+ transport: {
89
+ description: "Acceptable Transport Protocols",
90
+ type: "array",
91
+ items: {
92
+ type: "object"
89
93
  },
90
- "properties": {
91
- "protocol": {
92
- "type": "string"
94
+ properties: {
95
+ protocol: {
96
+ type: "string"
93
97
  },
94
- "bindAddr": {
95
- "type": "string"
98
+ bindAddr: {
99
+ type: "string"
96
100
  },
97
- "port": {
98
- "type": "integer"
101
+ port: {
102
+ type: "integer"
99
103
  }
100
104
  },
101
- "required": ["port", "protocol"]
105
+ required: ["port", "protocol"]
102
106
  },
103
- "processor": {
104
- "description": "Adjacent service for message routing",
105
- "type": "object",
106
- "properties": {
107
- "addr": {
108
- "type": "string"
107
+ processor: {
108
+ description: "Adjacent service for message routing",
109
+ type: "object",
110
+ properties: {
111
+ addr: {
112
+ type: "string"
109
113
  }
110
114
  }
111
115
  }
112
116
  },
113
- "required": ["methods", "transport", "processor"]
114
- },
117
+ required: ["methods", "transport", "processor"]
118
+ }
115
119
  },
116
- "required": ["kind", "metadata", "spec", "apiVersion"]
120
+ required: ["kind", "metadata", "spec", "apiVersion"]
117
121
  };
@@ -1,2 +1,9 @@
1
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
+ */
2
9
  export default function createListeningPoints(sipStack: SipStack, config: EdgePortConfig): Array<ListeningPoint>;
@@ -1,43 +1,28 @@
1
1
  "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
- // Creates LPs for all of the given transport and throws if upstream function fails
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
+ */
15
10
  function createListeningPoints(sipStack, config) {
16
- var e_1, _a;
17
- var listeningPoints = [];
18
- try {
19
- for (var _b = __values(config.spec.transport), _c = _b.next(); !_c.done; _c = _b.next()) {
20
- var trans = _c.value;
21
- var proto = trans.protocol.toLowerCase();
22
- // If none was found we use the global bindAddr
23
- if (trans.bindAddr === undefined) {
24
- trans.bindAddr = config.spec.bindAddr;
25
- }
26
- try {
27
- var lp = sipStack.createListeningPoint(trans.bindAddr, trans.port, proto);
28
- listeningPoints.push(lp);
29
- }
30
- catch (e) {
31
- throw new Error("unable to bind " + proto + "://" + trans.bindAddr + ":" + trans.port);
32
- }
11
+ const listeningPoints = [];
12
+ // eslint-disable-next-line no-loops/no-loops
13
+ for (const trans of config.spec.transport) {
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;
33
18
  }
34
- }
35
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
36
- finally {
37
19
  try {
38
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
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}`);
39
25
  }
40
- finally { if (e_1) throw e_1.error; }
41
26
  }
42
27
  return listeningPoints;
43
28
  }
@@ -1,2 +1,9 @@
1
- import { SipStack, ListeningPoint, SipProvider } from "./types";
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
+ */
2
9
  export default function createSipProvider(sipStack: SipStack, listeningPoints: Array<ListeningPoint>): SipProvider;
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
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
+ */
3
10
  function createSipProvider(sipStack, listeningPoints) {
4
- var _a;
5
- var sipProvider = sipStack.createSipProvider(listeningPoints[0]);
6
- (_a = listeningPoints === null || listeningPoints === void 0 ? void 0 : listeningPoints.filter((function (lp, index) { return index > 0; }))) === null || _a === void 0 ? void 0 : _a.forEach(function (lp) { return sipProvider.addListeningPoint(lp); });
11
+ const sipProvider = sipStack.createSipProvider(listeningPoints[0]);
12
+ // eslint-disable-next-line no-loops/no-loops
13
+ for (const lp1 of listeningPoints === null || listeningPoints === void 0 ? void 0 : listeningPoints.filter((lp, index) => index > 0)) {
14
+ sipProvider.addListeningPoint(lp1);
15
+ }
7
16
  return sipProvider;
8
17
  }
9
18
  exports.default = createSipProvider;
@@ -1,6 +1,8 @@
1
1
  import { SipStack } from "./types";
2
2
  /**
3
- * Takes a properties map and returns an instance of the
4
- * Java object SipStack
3
+ * Takes a properties map and returns an instance of the SipStack(Java object).
4
+ *
5
+ * @param {Map<string, string>} props - Properties map
6
+ * @return {SipStack}
5
7
  */
6
8
  export default function createSipStack(props: Map<string, string>): SipStack;
@@ -1,40 +1,21 @@
1
1
  "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
- var SipFactory = Java.type('javax.sip.SipFactory');
15
- var Properties = Java.type('java.util.Properties');
3
+ const SipFactory = Java.type("javax.sip.SipFactory");
4
+ const Properties = Java.type("java.util.Properties");
16
5
  /**
17
- * Takes a properties map and returns an instance of the
18
- * Java object SipStack
6
+ * Takes a properties map and returns an instance of the SipStack(Java object).
7
+ *
8
+ * @param {Map<string, string>} props - Properties map
9
+ * @return {SipStack}
19
10
  */
20
11
  function createSipStack(props) {
21
- var e_1, _a;
22
- var properties = new Properties();
23
- try {
24
- for (var props_1 = __values(props), props_1_1 = props_1.next(); !props_1_1.done; props_1_1 = props_1.next()) {
25
- var entry = props_1_1.value;
26
- properties.setProperty(entry[0], entry[1]);
27
- }
12
+ const properties = new Properties();
13
+ // eslint-disable-next-line no-loops/no-loops
14
+ for (const entry of props) {
15
+ properties.setProperty(entry[0], entry[1]);
28
16
  }
29
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
30
- finally {
31
- try {
32
- if (props_1_1 && !props_1_1.done && (_a = props_1.return)) _a.call(props_1);
33
- }
34
- finally { if (e_1) throw e_1.error; }
35
- }
36
- var sipFactory = SipFactory.getInstance();
37
- sipFactory.setPathName('gov.nist');
17
+ const sipFactory = SipFactory.getInstance();
18
+ sipFactory.setPathName("gov.nist");
38
19
  return sipFactory.createSipStack(properties);
39
20
  }
40
21
  exports.default = createSipStack;
@@ -1,2 +1,7 @@
1
1
  import { EdgePortConfig } from "./types";
2
- export default function EdgePort(config: EdgePortConfig): void;
2
+ /**
3
+ * Starts a new Edgeport service.
4
+ *
5
+ * @param {EdgePortConfig} config - Edgeport configuration
6
+ */
7
+ export default function edgePort(config: EdgePortConfig): void;
package/dist/edgeport.js CHANGED
@@ -3,18 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var assertions_1 = require("./assertions");
7
- var create_listening_points_1 = __importDefault(require("./create_listening_points"));
8
- var create_sip_provider_1 = __importDefault(require("./create_sip_provider"));
9
- var create_sip_stack_1 = __importDefault(require("./create_sip_stack"));
10
- var server_properties_1 = __importDefault(require("./server_properties"));
11
- var GRPCSipListener = Java.type("io.routr.GRPCSipListener");
12
- function EdgePort(config) {
13
- assertions_1.assertNoDuplicatedProto(config.spec.transport);
14
- assertions_1.assertNoDuplicatedPort(config.spec.transport);
15
- assertions_1.assertHasSecurityContext(config);
16
- var sipStack = create_sip_stack_1.default(server_properties_1.default(config));
17
- var sipProvider = create_sip_provider_1.default(sipStack, create_listening_points_1.default(sipStack, config));
18
- sipProvider.addSipListener(new GRPCSipListener(sipProvider, config));
6
+ const assertions_1 = require("./assertions");
7
+ const create_listening_points_1 = __importDefault(require("./create_listening_points"));
8
+ const create_sip_provider_1 = __importDefault(require("./create_sip_provider"));
9
+ const create_sip_stack_1 = __importDefault(require("./create_sip_stack"));
10
+ const server_properties_1 = __importDefault(require("./server_properties"));
11
+ const GRPCSipListener = Java.type("io.routr.GRPCSipListener");
12
+ const ArrayList = Java.type("java.util.ArrayList");
13
+ /**
14
+ * Starts a new Edgeport service.
15
+ *
16
+ * @param {EdgePortConfig} config - Edgeport configuration
17
+ */
18
+ function edgePort(config) {
19
+ var _a, _b;
20
+ (0, assertions_1.assertNoDuplicatedProto)(config.spec.transport);
21
+ (0, assertions_1.assertNoDuplicatedPort)(config.spec.transport);
22
+ (0, assertions_1.assertHasSecurityContext)(config);
23
+ const sipStack = (0, create_sip_stack_1.default)((0, server_properties_1.default)(config));
24
+ const sipProvider = (0, create_sip_provider_1.default)(sipStack, (0, create_listening_points_1.default)(sipStack, config));
25
+ const externalIps = new ArrayList();
26
+ const localnets = new ArrayList();
27
+ (_a = config.spec.externalIps) === null || _a === void 0 ? void 0 : _a.forEach((addr) => externalIps.add(addr));
28
+ (_b = config.spec.localnets) === null || _b === void 0 ? void 0 : _b.forEach((net) => localnets.add(net));
29
+ sipProvider.addSipListener(new GRPCSipListener(sipProvider, config, externalIps, localnets));
19
30
  }
20
- exports.default = EdgePort;
31
+ exports.default = edgePort;
package/dist/runner.js CHANGED
@@ -3,12 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var edgeport_1 = __importDefault(require("./edgeport"));
7
- var get_config_1 = require("./config/get_config");
8
- var config = get_config_1.getConfig(System.getenv('CONFIG_PATH'));
9
- if (config._tag === 'Right') {
10
- edgeport_1.default(config.right);
6
+ // require("./tracer").init("dispatcher")
7
+ const edgeport_1 = __importDefault(require("./edgeport"));
8
+ const get_config_1 = require("./config/get_config");
9
+ const config = (0, get_config_1.getConfig)(System.getenv("CONFIG_PATH"));
10
+ if (config._tag === "Right") {
11
+ (0, edgeport_1.default)(config.right);
11
12
  }
12
13
  else {
13
- console.error(config.left);
14
+ // WARNING: Using @fonoster/logger causes conflict with Webpack.
15
+ // eslint-disable-next-line no-console
16
+ console.log(config.left);
14
17
  }
@@ -3,5 +3,8 @@ import { EdgePortConfig } from "./types";
3
3
  * Returns a Map object with the properties for the server's SipStack.
4
4
  * For more options see:
5
5
  * https://github.com/RestComm/jain-sip/blob/master/src/gov/nist/javax/sip/SipStackImpl.java
6
+ *
7
+ * @param {EdgePortConfig} config - Configuration object
8
+ * @return {Map<string, string>}
6
9
  */
7
10
  export default function getServerProperties(config: EdgePortConfig): Map<string, string>;
@@ -4,31 +4,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  * Returns a Map object with the properties for the server's SipStack.
5
5
  * For more options see:
6
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 {Map<string, string>}
7
10
  */
8
11
  function getServerProperties(config) {
9
- var properties = new Map();
10
- properties.set('javax.sip.STACK_NAME', 'routr');
11
- properties.set('javax.sip.AUTOMATIC_DIALOG_SUPPORT', 'OFF');
12
- properties.set('gov.nist.javax.sip.MESSAGE_PROCESSOR_FACTORY', 'gov.nist.javax.sip.stack.NioMessageProcessorFactory');
13
- properties.set('gov.nist.javax.sip.PATCH_SIP_WEBSOCKETS_HEADERS', 'false');
14
- properties.set('gov.nist.javax.sip.CACHE_CLIENT_CONNECTIONS', 'true');
15
- properties.set('gov.nist.javax.sip.REENTRANT_LISTENER', 'false');
16
- properties.set('gov.nist.javax.sip.THREAD_POOL_SIZE', '16');
17
- properties.set('gov.nist.javax.sip.NIO_BLOCKING_MODE', 'NONBLOCKING');
12
+ var _a, _b;
13
+ const properties = new Map();
14
+ properties.set("javax.sip.STACK_NAME", "routr");
15
+ properties.set("javax.sip.AUTOMATIC_DIALOG_SUPPORT", "OFF");
16
+ properties.set("gov.nist.javax.sip.MESSAGE_PROCESSOR_FACTORY", "gov.nist.javax.sip.stack.NioMessageProcessorFactory");
17
+ properties.set("gov.nist.javax.sip.PATCH_SIP_WEBSOCKETS_HEADERS", "false");
18
+ properties.set("gov.nist.javax.sip.CACHE_CLIENT_CONNECTIONS", "true");
19
+ properties.set("gov.nist.javax.sip.REENTRANT_LISTENER", "false");
20
+ properties.set("gov.nist.javax.sip.THREAD_POOL_SIZE", "16");
21
+ properties.set("gov.nist.javax.sip.NIO_BLOCKING_MODE", "NONBLOCKING");
18
22
  // Guard against denial of service attack.
19
- properties.set('gov.nist.javax.sip.MAX_MESSAGE_SIZE', '1048576');
20
- properties.set('gov.nist.javax.sip.LOG_MESSAGE_CONTENT', 'true');
23
+ properties.set("gov.nist.javax.sip.MAX_MESSAGE_SIZE", "1048576");
24
+ properties.set("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "true");
21
25
  // Default host
22
- properties.set('javax.sip.IP_ADDRESS', config.spec.bindAddr);
26
+ properties.set("javax.sip.IP_ADDRESS", config.spec.bindAddr);
23
27
  if (config.spec.securityContext) {
24
- properties.set('gov.nist.javax.sip.TLS_CLIENT_PROTOCOLS', config.spec.securityContext.client.protocols.join());
28
+ properties.set("gov.nist.javax.sip.TLS_CLIENT_PROTOCOLS", (_a = config.spec.securityContext.client) === null || _a === void 0 ? void 0 : _a.protocols.join());
25
29
  // This must be set to 'Disabled' when using WSS
26
- properties.set('gov.nist.javax.sip.TLS_CLIENT_AUTH_TYPE', config.spec.securityContext.client.authType);
27
- properties.set('javax.net.ssl.keyStore', config.spec.securityContext.keyStore);
28
- properties.set('javax.net.ssl.trustStore', config.spec.securityContext.trustStore);
29
- properties.set('javax.net.ssl.keyStorePassword', config.spec.securityContext.keyStorePassword);
30
- properties.set('javax.net.ssl.trustStorePassword', config.spec.securityContext.trustStorePassword);
31
- properties.set('javax.net.ssl.keyStoreType', config.spec.securityContext.keyStoreType);
30
+ properties.set("gov.nist.javax.sip.TLS_CLIENT_AUTH_TYPE", (_b = config.spec.securityContext.client) === null || _b === void 0 ? void 0 : _b.authType);
31
+ properties.set("javax.net.ssl.keyStore", config.spec.securityContext.keyStore);
32
+ properties.set("javax.net.ssl.trustStore", config.spec.securityContext.trustStore);
33
+ properties.set("javax.net.ssl.keyStorePassword", config.spec.securityContext.keyStorePassword);
34
+ properties.set("javax.net.ssl.trustStorePassword", config.spec.securityContext.trustStorePassword);
35
+ properties.set("javax.net.ssl.keyStoreType", config.spec.securityContext.keyStoreType);
32
36
  }
33
37
  return properties;
34
38
  }
@@ -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) 2022 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;
package/dist/types.d.ts CHANGED
@@ -10,6 +10,8 @@ export interface EdgePortConfig {
10
10
  processor: {
11
11
  addr: string;
12
12
  };
13
+ externalIps: string[];
14
+ localnets: string[];
13
15
  securityContext?: {
14
16
  debugging: boolean;
15
17
  keyStore: string;
@@ -27,13 +29,13 @@ export interface EdgePortConfig {
27
29
  export declare interface SipStack {
28
30
  createListeningPoint: (bindAddr: string, port: number, proto: string) => unknown;
29
31
  createSipProvider: (lp: ListeningPoint) => SipProvider;
30
- getClass: () => any;
32
+ getClass: any;
31
33
  }
32
34
  export declare interface ListeningPoint {
33
35
  }
36
+ export declare interface Java {
37
+ }
34
38
  export declare interface SipProvider {
35
39
  addListeningPoint: (lp: ListeningPoint) => void;
36
40
  addSipListener: (lp: unknown) => void;
37
41
  }
38
- export declare interface Java {
39
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/edgeport",
3
- "version": "2.0.5-alpha.2",
3
+ "version": "2.0.5-alpha.21",
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",
@@ -31,5 +31,5 @@
31
31
  "dependencies": {
32
32
  "fp-ts": "^2.11.8"
33
33
  },
34
- "gitHead": "3570106be9a96cb6672de4a850a377bfa7d9bb3e"
34
+ "gitHead": "904559d8d4694e16d63f553704345a987dc0d93a"
35
35
  }