@routr/location 2.0.8-alpha.4 → 2.0.8-alpha.40

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.
package/dist/client.d.ts CHANGED
@@ -31,8 +31,8 @@ export default class Location implements ILocationService {
31
31
  *
32
32
  * @param {FindRoutesResponse} request - Request to find routes
33
33
  * @param {string} request.aor - AOR of the route
34
- * @param {Map<string, string>} request.labels - Optional Route labels
35
- * @param {string} request.sessionAffinityRef - Optiona session affinity ref
34
+ * @param {Map<string, string>} request.labels - Optional Route labels (reserved for future use)
35
+ * @param {object} request.backend - Optional Route backend (reserved for future use)
36
36
  * @return {Promise<void>}
37
37
  */
38
38
  findRoutes(request: FindRoutesRequest): Promise<Route[]>;
package/dist/client.js CHANGED
@@ -38,7 +38,7 @@ const container = (self, request, name) => {
38
38
  return new Promise((resolve, reject) => {
39
39
  self.location[name](request, (err, response) => {
40
40
  if ((err === null || err === void 0 ? void 0 : err.code) === grpc.status.UNAVAILABLE) {
41
- return reject(new common_1.ServiceUnavailableError(self.config.addr));
41
+ return reject(new common_1.CommonErrors.ServiceUnavailableError(self.config.addr));
42
42
  }
43
43
  resolve(response);
44
44
  });
@@ -75,8 +75,8 @@ class Location {
75
75
  *
76
76
  * @param {FindRoutesResponse} request - Request to find routes
77
77
  * @param {string} request.aor - AOR of the route
78
- * @param {Map<string, string>} request.labels - Optional Route labels
79
- * @param {string} request.sessionAffinityRef - Optiona session affinity ref
78
+ * @param {Map<string, string>} request.labels - Optional Route labels (reserved for future use)
79
+ * @param {object} request.backend - Optional Route backend (reserved for future use)
80
80
  * @return {Promise<void>}
81
81
  */
82
82
  findRoutes(request) {
@@ -1,4 +1,4 @@
1
1
  import { LocationConfig } from "../types";
2
2
  import * as E from "fp-ts/Either";
3
- import { InvalidConfiguration } from "../errors";
4
- export declare const getConfig: (path: string) => E.Either<InvalidConfiguration, LocationConfig>;
3
+ import { InvalidSchemaConfiguration } from "../errors";
4
+ export declare const getConfig: (path: string) => E.Either<InvalidSchemaConfiguration, LocationConfig>;
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.getConfig = void 0;
30
30
  /*
31
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
31
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
32
32
  * http://github.com/fonoster/routr
33
33
  *
34
34
  * This file is part of Routr
@@ -46,47 +46,29 @@ exports.getConfig = void 0;
46
46
  * limitations under the License.
47
47
  */
48
48
  const types_1 = require("../types");
49
- const fs_1 = __importDefault(require("fs"));
49
+ const common_1 = require("@routr/common");
50
50
  const schema_1 = require("./schema");
51
51
  const ajv_1 = __importDefault(require("ajv"));
52
52
  const E = __importStar(require("fp-ts/Either"));
53
53
  const errors_1 = require("../errors");
54
54
  const ajv = new ajv_1.default();
55
55
  const validate = ajv.compile(schema_1.schema);
56
- const hasBadCombiniation = (backends) => backends.some((b) => b.balancingAlgorithm === types_1.LB_ALGORITHM.ROUND_ROBIN && b.withSessionAffinity);
57
- const hasBadAlgorithm = (backends) => backends.some((b) => b.balancingAlgorithm !== types_1.LB_ALGORITHM.ROUND_ROBIN &&
58
- b.balancingAlgorithm !== types_1.LB_ALGORITHM.LEAST_SESSIONS);
59
56
  const getConfig = (path) => {
60
57
  var _a, _b, _c;
61
- const c = JSON.parse(fs_1.default.readFileSync(path, "utf8"));
58
+ const c = common_1.Helper.readConfigFile(path);
62
59
  if (!validate(Object.assign({}, c))) {
63
60
  return E.left(new errors_1.InvalidSchemaConfiguration(JSON.stringify(validate.errors[0].message)));
64
61
  }
65
62
  const config = c.spec;
66
- if (config.backends) {
67
- config.backends.map((b) => {
68
- // Setting round-robin by default
69
- b.balancingAlgorithm = b.balancingAlgorithm
70
- ? b.balancingAlgorithm
71
- : types_1.LB_ALGORITHM.ROUND_ROBIN;
72
- return b;
73
- });
74
- if (hasBadCombiniation(config.backends)) {
75
- return E.left(new errors_1.BadAlgorithmAndAffinityCombination());
76
- }
77
- if (hasBadAlgorithm(config.backends)) {
78
- return E.left(new errors_1.InvalidLoadBalancerAlgorithm());
79
- }
80
- }
81
- if (!((_a = config === null || config === void 0 ? void 0 : config.cache) === null || _a === void 0 ? void 0 : _a.provider)) {
63
+ if (!((_a = config.cache) === null || _a === void 0 ? void 0 : _a.provider)) {
82
64
  config.cache = {
83
- provider: types_1.CACHE_PROVIDER.MEMORY
65
+ provider: types_1.CacheProvider.MEMORY
84
66
  };
85
67
  }
86
- if (((_b = config === null || config === void 0 ? void 0 : config.cache) === null || _b === void 0 ? void 0 : _b.provider) === types_1.CACHE_PROVIDER.REDIS &&
87
- !((_c = config === null || config === void 0 ? void 0 : config.cache) === null || _c === void 0 ? void 0 : _c.parameters)) {
68
+ if (((_b = config.cache) === null || _b === void 0 ? void 0 : _b.provider) === types_1.CacheProvider.REDIS &&
69
+ !((_c = config.cache) === null || _c === void 0 ? void 0 : _c.parameters)) {
88
70
  config.cache = {
89
- provider: types_1.CACHE_PROVIDER.REDIS,
71
+ provider: types_1.CacheProvider.REDIS,
90
72
  parameters: "host=localhost,port=6379"
91
73
  };
92
74
  }
@@ -34,26 +34,6 @@ export declare const schema: {
34
34
  };
35
35
  required: string[];
36
36
  };
37
- backends: {
38
- description: string;
39
- type: string;
40
- items: {
41
- type: string;
42
- };
43
- properties: {
44
- ref: {
45
- type: string;
46
- };
47
- balancingAlgorithm: {
48
- enum: string[];
49
- };
50
- withSessionAffinity: {
51
- description: string;
52
- type: string;
53
- };
54
- };
55
- required: string[];
56
- };
57
37
  };
58
38
  };
59
39
  };
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.schema = void 0;
4
4
  /*
5
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
5
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/routr
7
7
  *
8
8
  * This file is part of Routr
@@ -29,7 +29,7 @@ exports.schema = {
29
29
  enum: ["Location", "location"]
30
30
  },
31
31
  apiVersion: {
32
- enum: ["v2draft1"]
32
+ enum: ["v2draft1", "v2"]
33
33
  },
34
34
  metadata: {
35
35
  description: "Resource metadata",
@@ -47,36 +47,16 @@ exports.schema = {
47
47
  type: "object",
48
48
  properties: {
49
49
  provider: {
50
- enum: ["memory", "redis"]
50
+ enum: ["Memory", "Redis", "memory", "redis"]
51
51
  },
52
52
  parameters: {
53
53
  type: "string"
54
54
  }
55
55
  },
56
56
  required: ["provider"]
57
- },
58
- backends: {
59
- description: "Optional SIP backends",
60
- type: "array",
61
- items: {
62
- type: "object"
63
- },
64
- properties: {
65
- ref: {
66
- type: "string"
67
- },
68
- balancingAlgorithm: {
69
- enum: ["round-robin", "least-sessions"]
70
- },
71
- withSessionAffinity: {
72
- description: "Optional session affinity",
73
- type: "boolean"
74
- }
75
- },
76
- required: ["ref"]
77
57
  }
78
58
  }
79
59
  }
80
60
  },
81
- required: ["kind", "spec", "apiVersion"]
61
+ required: ["apiVersion", "kind", "metadata", "spec"]
82
62
  };
package/dist/envs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const CONFIG_PATH: string;
package/dist/envs.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONFIG_PATH = void 0;
4
+ /*
5
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster
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
+ const common_1 = require("@routr/common");
23
+ common_1.Assertions.assertEnvsAreSet(["CONFIG_PATH"]);
24
+ exports.CONFIG_PATH = process.env.CONFIG_PATH;
package/dist/errors.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import * as grpc from "@grpc/grpc-js";
2
2
  export type LocationError = UnsupportedSchema | NotRoutesFoundForAOR;
3
- export type InvalidConfiguration = BadAlgorithmAndAffinityCombination | InvalidSchemaConfiguration;
4
3
  /**
5
4
  * Error thrown when the location service returns an unsupported schema.
6
5
  */
@@ -37,23 +36,3 @@ export declare class InvalidSchemaConfiguration extends Error {
37
36
  */
38
37
  constructor(msg: string);
39
38
  }
40
- /**
41
- * Error thrown when the location finds incompatible algorithm and session affinity.
42
- */
43
- export declare class BadAlgorithmAndAffinityCombination extends Error {
44
- code: grpc.status;
45
- /**
46
- * Create a new BadAlgorithmAndAffinityCombination error.
47
- */
48
- constructor();
49
- }
50
- /**
51
- * Error thrown when the location finds an invalid balancing algorithm.
52
- */
53
- export declare class InvalidLoadBalancerAlgorithm extends Error {
54
- code: grpc.status;
55
- /**
56
- * Create a new InvalidLoadBalancerAlgorithm error.
57
- */
58
- constructor();
59
- }
package/dist/errors.js CHANGED
@@ -23,9 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.InvalidLoadBalancerAlgorithm = exports.BadAlgorithmAndAffinityCombination = exports.InvalidSchemaConfiguration = exports.NotRoutesFoundForAOR = exports.UnsupportedSchema = void 0;
26
+ exports.InvalidSchemaConfiguration = exports.NotRoutesFoundForAOR = exports.UnsupportedSchema = void 0;
27
27
  /*
28
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
28
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
29
29
  * http://github.com/fonoster/routr
30
30
  *
31
31
  * This file is part of Routr
@@ -92,29 +92,3 @@ class InvalidSchemaConfiguration extends Error {
92
92
  }
93
93
  }
94
94
  exports.InvalidSchemaConfiguration = InvalidSchemaConfiguration;
95
- /**
96
- * Error thrown when the location finds incompatible algorithm and session affinity.
97
- */
98
- class BadAlgorithmAndAffinityCombination extends Error {
99
- /**
100
- * Create a new BadAlgorithmAndAffinityCombination error.
101
- */
102
- constructor() {
103
- super("session affinity can not be combined with round-robin load balancing");
104
- Object.setPrototypeOf(this, BadAlgorithmAndAffinityCombination.prototype);
105
- }
106
- }
107
- exports.BadAlgorithmAndAffinityCombination = BadAlgorithmAndAffinityCombination;
108
- /**
109
- * Error thrown when the location finds an invalid balancing algorithm.
110
- */
111
- class InvalidLoadBalancerAlgorithm extends Error {
112
- /**
113
- * Create a new InvalidLoadBalancerAlgorithm error.
114
- */
115
- constructor() {
116
- super("found invalid load balancing algorithm. must be round-robin or least-sessions");
117
- Object.setPrototypeOf(this, BadAlgorithmAndAffinityCombination.prototype);
118
- }
119
- }
120
- exports.InvalidLoadBalancerAlgorithm = InvalidLoadBalancerAlgorithm;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ /*
5
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster
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
+ const common_1 = require("@routr/common");
23
+ const get_config_1 = require("./config/get_config");
24
+ const logger_1 = require("@fonoster/logger");
25
+ const envs_1 = require("./envs");
26
+ const logger = (0, logger_1.getLogger)({ service: "location", filePath: __filename });
27
+ const result = (0, get_config_1.getConfig)(envs_1.CONFIG_PATH);
28
+ if (result._tag === "Right") {
29
+ common_1.HealthCheck.check(result.right.bindAddr);
30
+ }
31
+ else {
32
+ logger.error(result.left);
33
+ }
package/dist/helper.d.ts CHANGED
@@ -1,2 +1,10 @@
1
1
  import { MessageRequest, Route } from "@routr/common";
2
- export declare const createRoute: (request: MessageRequest) => Route;
2
+ export declare function createRoute(request: MessageRequest): Route;
3
+ /**
4
+ * A request traversing a second EdgePort would have updated the requestUri.
5
+ * Therefore, we are able to re-construct the Route from the request.
6
+ *
7
+ * @param {MessageRequest} request - the request
8
+ * @return {Route} the route
9
+ */
10
+ export declare function createRouteFromLastMessage(request: MessageRequest): Route;
package/dist/helper.js CHANGED
@@ -1,48 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRoute = void 0;
4
- /*
5
- * Copyright (C) 2022 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
- */
3
+ exports.createRouteFromLastMessage = exports.createRoute = void 0;
22
4
  const common_1 = require("@routr/common");
23
5
  const processor_1 = require("@routr/processor");
6
+ /* eslint-disable require-jsdoc */
24
7
  // TODO: Before finalizing this, consider using the old approach of saving the rport
25
8
  // and received values (like here:
26
9
  // https://github.com/fonoster/routr/blob/59bc98af86078088aede7e658c0d82a19fa18fa4/mod/registrar/utils.js#L87)
27
10
  //
28
11
  // Also consider: https://github.com/fonoster/routr/blob/ee5d339888344013939d06c734385f17f0cd75c2/mod/registrar/utils.js#L116
29
12
  // and https://github.com/fonoster/routr/blob/ee5d339888344013939d06c734385f17f0cd75c2/mod/registrar/utils.js#L131
30
- const createRoute = (request) => {
31
- const uri = request.message.contact.address.uri;
13
+ function buildRoute(request, uri) {
14
+ var _a;
32
15
  const sessionCount = processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.SESSION_COUNT)
33
16
  ? parseInt(processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.SESSION_COUNT))
34
17
  : -1;
35
- const egressListeningPoint = common_1.Helper.getListeningPoint(request, uri.transportParam.toLowerCase());
36
18
  return {
37
19
  edgePortRef: request.edgePortRef,
38
20
  user: uri.user,
39
21
  host: uri.host,
40
22
  port: uri.port,
41
- transport: uri.transportParam.toLowerCase(),
23
+ transport: (_a = uri.transportParam) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
42
24
  registeredOn: Date.now(),
43
25
  sessionCount,
44
26
  expires: processor_1.Target.getTargetExpires(request),
45
- egressListeningPoint
27
+ listeningPoints: request.listeningPoints,
28
+ localnets: request.localnets,
29
+ externalAddrs: request.externalAddrs
30
+ };
31
+ }
32
+ function createRoute(request) {
33
+ const via = request.message.via[0];
34
+ const uri = {
35
+ host: via.received || via.host,
36
+ port: via.rPort !== -1 ? via.rPort : via.port,
37
+ transportParam: via.transport.toUpperCase(),
38
+ user: request.message.from.address.uri.user
46
39
  };
47
- };
40
+ return buildRoute(request, uri);
41
+ }
48
42
  exports.createRoute = createRoute;
43
+ /**
44
+ * A request traversing a second EdgePort would have updated the requestUri.
45
+ * Therefore, we are able to re-construct the Route from the request.
46
+ *
47
+ * @param {MessageRequest} request - the request
48
+ * @return {Route} the route
49
+ */
50
+ function createRouteFromLastMessage(request) {
51
+ const uri = request.message.requestUri;
52
+ return buildRoute(request, uri);
53
+ }
54
+ exports.createRouteFromLastMessage = createRouteFromLastMessage;
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.LocationClient = exports.Utils = exports.Helper = void 0;
33
33
  /*
34
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
34
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
35
35
  * http://github.com/fonoster/routr
36
36
  *
37
37
  * This file is part of Routr
@@ -1,20 +1,17 @@
1
- import { AddRouteRequest, Backend, FindRoutesRequest, ILocationService, ILocatorStore, RemoveRoutesRequest } from "./types";
1
+ import { AddRouteRequest, FindRoutesRequest, ILocationService, ILocatorStore, RemoveRoutesRequest } from "./types";
2
2
  import { Route } from "@routr/common";
3
3
  /**
4
4
  * A locator store that uses the location service to find routes for AORs.
5
5
  */
6
6
  export default class Location implements ILocationService {
7
7
  private store;
8
- private backends;
9
8
  private rrCount;
10
- private affinityStore;
11
9
  /**
12
10
  * Creates a new Location service. Should fail if any backend has sessionAffinity and round-robin
13
11
  *
14
12
  * @param {ILocatorStore} store - The store to use for the location service
15
- * @param {Map<string, Backend>} backends - The backends to use for the location service
16
13
  */
17
- constructor(store: ILocatorStore, backends?: Map<string, Backend>);
14
+ constructor(store: ILocatorStore);
18
15
  /** @inheritdoc */
19
16
  addRoute(request: AddRouteRequest): Promise<void>;
20
17
  /** @inheritdoc */
package/dist/location.js CHANGED
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  /*
13
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
13
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
14
14
  * http://github.com/fonoster/routr
15
15
  *
16
16
  * This file is part of Routr
@@ -28,7 +28,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
28
28
  * limitations under the License.
29
29
  */
30
30
  const errors_1 = require("./errors");
31
- const types_1 = require("./types");
31
+ const common_1 = require("@routr/common");
32
32
  const utils_1 = require("./utils");
33
33
  var AOR_SCHEME;
34
34
  (function (AOR_SCHEME) {
@@ -43,14 +43,10 @@ class Location {
43
43
  * Creates a new Location service. Should fail if any backend has sessionAffinity and round-robin
44
44
  *
45
45
  * @param {ILocatorStore} store - The store to use for the location service
46
- * @param {Map<string, Backend>} backends - The backends to use for the location service
47
46
  */
48
- constructor(store, backends = new Map()) {
47
+ constructor(store) {
49
48
  this.store = store;
50
- this.backends = backends;
51
49
  this.rrCount = new Map();
52
- this.affinityStore = new Map();
53
- this.backends.forEach((value, key) => this.rrCount.set(key, 0));
54
50
  }
55
51
  /** @inheritdoc */
56
52
  addRoute(request) {
@@ -64,21 +60,29 @@ class Location {
64
60
  findRoutes(request) {
65
61
  var _a;
66
62
  return __awaiter(this, void 0, void 0, function* () {
67
- const routes = request.labels
63
+ let routes = yield this.store.get(`${request.aor}:${request.callId}`);
64
+ if (routes.length > 0) {
65
+ return routes;
66
+ }
67
+ routes = request.labels
68
68
  ? (yield this.store.get(request.aor)).filter((0, utils_1.filterOnlyMatchingLabels)(request.labels))
69
69
  : (_a = (yield this.store.get(request.aor))) !== null && _a !== void 0 ? _a : [];
70
70
  if (request.aor.startsWith(AOR_SCHEME.SIP)) {
71
+ // Set call to the last route
72
+ this.store.put(`${request.aor}:${request.callId}`, routes[0]);
71
73
  return routes;
72
74
  }
73
75
  else if (request.aor.startsWith(AOR_SCHEME.BACKEND)) {
74
- const backend = this.backends.get(request.aor);
75
- if (!backend) {
76
- throw new errors_1.NotRoutesFoundForAOR(request.aor);
77
- }
76
+ const { backend } = request;
78
77
  // If it has not affinity sesssion then get next
79
- return backend.withSessionAffinity
80
- ? [this.nextWithAffinity(routes, request.sessionAffinityRef)]
78
+ const r =
79
+ // Falls back to round-robin if no session affinity ref is provided
80
+ backend.withSessionAffinity && request.sessionAffinityRef
81
+ ? [yield this.nextWithAffinity(routes, request.sessionAffinityRef)]
81
82
  : [this.next(routes, backend)];
83
+ // Next time we will get the route with callId
84
+ this.store.put(`${request.aor}:${request.callId}`, r[0]);
85
+ return r;
82
86
  }
83
87
  throw new errors_1.UnsupportedSchema(request.aor);
84
88
  });
@@ -89,11 +93,12 @@ class Location {
89
93
  }
90
94
  // eslint-disable-next-line require-jsdoc
91
95
  next(routes, backend) {
92
- if (backend.balancingAlgorithm === types_1.LB_ALGORITHM.LEAST_SESSIONS) {
96
+ var _a;
97
+ if (backend.balancingAlgorithm === common_1.CommonTypes.LoadBalancingAlgorithm.LEAST_SESSIONS) {
93
98
  return routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
94
99
  }
95
100
  // Continues using round-robin
96
- const nextPosition = this.rrCount.get(`${AOR_SCHEME.BACKEND}${backend.ref}`);
101
+ const nextPosition = (_a = this.rrCount.get(`${AOR_SCHEME.BACKEND}${backend.ref}`)) !== null && _a !== void 0 ? _a : 0;
97
102
  const result = routes[nextPosition];
98
103
  if (nextPosition >= routes.length - 1) {
99
104
  // Restarting round-robin counter
@@ -106,14 +111,16 @@ class Location {
106
111
  }
107
112
  // Backend with session affinity does not support round-robin
108
113
  // eslint-disable-next-line require-jsdoc
109
- nextWithAffinity(routes, sessionAffinityRef) {
110
- let route = this.affinityStore.get(sessionAffinityRef);
111
- if (route) {
112
- return route;
113
- }
114
- route = routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
115
- this.affinityStore.set(sessionAffinityRef, route);
116
- return route;
114
+ nextWithAffinity(routes, sessionAffinityHeader) {
115
+ return __awaiter(this, void 0, void 0, function* () {
116
+ const route = yield this.store.get(sessionAffinityHeader);
117
+ if (route.length > 0) {
118
+ return route[0];
119
+ }
120
+ const r = routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
121
+ this.store.put(sessionAffinityHeader, r);
122
+ return r;
123
+ });
117
124
  }
118
125
  }
119
126
  exports.default = Location;
package/dist/runner.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  /*
8
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
8
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
9
9
  * http://github.com/fonoster/routr
10
10
  *
11
11
  * This file is part of Routr
package/dist/service.js CHANGED
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /*
7
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
7
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
8
8
  * http://github.com/fonoster/routr
9
9
  *
10
10
  * This file is part of Routr
@@ -36,17 +36,16 @@ const allowedParameters = ["host", "port", "username", "password", "secure"];
36
36
  * @param {LocationConfig} config - Service configuration
37
37
  */
38
38
  function LocationService(config) {
39
+ var _a;
39
40
  const { bindAddr, cache } = config;
40
41
  let store;
41
- if (cache.provider === types_1.CACHE_PROVIDER.REDIS) {
42
+ if (((_a = cache.provider) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === types_1.CacheProvider.REDIS) {
42
43
  store = new redis_store_1.default((0, utils_1.configFromString)(cache.parameters, allowedParameters));
43
44
  }
44
45
  else {
45
46
  store = new memory_store_1.default();
46
47
  }
47
- const backends = new Map();
48
- config.backends.forEach((b) => backends.set(`backend:${b.ref}`, b));
49
- (0, common_1.createService)((0, utils_1.getServiceInfo)(bindAddr, new location_1.default(store, backends)));
48
+ (0, common_1.createService)((0, utils_1.getServiceInfo)(bindAddr, new location_1.default(store)));
50
49
  logger.info(`using ${cache.provider} as cache provider`);
51
50
  }
52
51
  exports.default = LocationService;
package/dist/tracer.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.init = void 0;
7
7
  /*
8
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
8
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
9
9
  * http://github.com/fonoster/routr
10
10
  *
11
11
  * This file is part of Routr
package/dist/types.d.ts CHANGED
@@ -1,12 +1,4 @@
1
- import { Route } from "@routr/common";
2
- export declare enum LB_ALGORITHM {
3
- ROUND_ROBIN = "round-robin",
4
- LEAST_SESSIONS = "least-sessions"
5
- }
6
- export declare enum CACHE_PROVIDER {
7
- MEMORY = "memory",
8
- REDIS = "redis"
9
- }
1
+ import { Route, CommonTypes as CT } from "@routr/common";
10
2
  export interface ILocationService {
11
3
  addRoute(request: AddRouteRequest): Promise<void>;
12
4
  findRoutes(request: FindRoutesRequest): Promise<Route[]>;
@@ -23,8 +15,10 @@ export interface AddRouteRequest {
23
15
  }
24
16
  export interface FindRoutesRequest {
25
17
  aor: string;
26
- labels?: Map<string, string>;
18
+ callId: string;
27
19
  sessionAffinityRef?: string;
20
+ backend?: Backend;
21
+ labels?: Map<string, string>;
28
22
  }
29
23
  export interface FindRoutesResponse {
30
24
  routes: Array<Route>;
@@ -34,14 +28,17 @@ export interface RemoveRoutesRequest {
34
28
  }
35
29
  export interface Backend {
36
30
  ref: string;
37
- balancingAlgorithm?: LB_ALGORITHM;
38
- withSessionAffinity?: boolean;
31
+ balancingAlgorithm: CT.LoadBalancingAlgorithm;
32
+ withSessionAffinity: boolean;
33
+ }
34
+ export declare enum CacheProvider {
35
+ MEMORY = "MEMORY",
36
+ REDIS = "REDIS"
39
37
  }
40
38
  export interface LocationConfig {
41
39
  bindAddr: string;
42
- backends?: Backend[];
43
40
  cache?: {
44
- provider: CACHE_PROVIDER;
41
+ provider: CacheProvider;
45
42
  parameters?: string;
46
43
  };
47
44
  }
package/dist/types.js CHANGED
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CACHE_PROVIDER = exports.LB_ALGORITHM = void 0;
4
- var LB_ALGORITHM;
5
- (function (LB_ALGORITHM) {
6
- LB_ALGORITHM["ROUND_ROBIN"] = "round-robin";
7
- LB_ALGORITHM["LEAST_SESSIONS"] = "least-sessions";
8
- })(LB_ALGORITHM = exports.LB_ALGORITHM || (exports.LB_ALGORITHM = {}));
9
- var CACHE_PROVIDER;
10
- (function (CACHE_PROVIDER) {
11
- CACHE_PROVIDER["MEMORY"] = "memory";
12
- CACHE_PROVIDER["REDIS"] = "redis";
13
- })(CACHE_PROVIDER = exports.CACHE_PROVIDER || (exports.CACHE_PROVIDER = {}));
3
+ exports.CacheProvider = void 0;
4
+ var CacheProvider;
5
+ (function (CacheProvider) {
6
+ CacheProvider["MEMORY"] = "MEMORY";
7
+ CacheProvider["REDIS"] = "REDIS";
8
+ })(CacheProvider = exports.CacheProvider || (exports.CacheProvider = {}));
package/dist/utils.js CHANGED
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.configFromString = exports.getServiceInfo = exports.filterOnlyMatchingLabels = exports.compareArrays = exports.mergeKeyValue = exports.duplicateFilter = exports.expiredFilter = void 0;
13
13
  /*
14
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
14
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/routr
16
16
  *
17
17
  * This file is part of Routr
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/location",
3
- "version": "2.0.8-alpha.4",
3
+ "version": "2.0.8-alpha.40",
4
4
  "description": "Creates and maintains a list of routes to all registered endpoints",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -12,7 +12,8 @@
12
12
  "build": "tsc -b tsconfig.json"
13
13
  },
14
14
  "bin": {
15
- "run_location": "dist/runner.js"
15
+ "run_location": "dist/runner.js",
16
+ "healthcheck_location": "dist/healthcheck.js"
16
17
  },
17
18
  "directories": {
18
19
  "src": "src",
@@ -25,8 +26,8 @@
25
26
  "access": "public"
26
27
  },
27
28
  "dependencies": {
28
- "@fonoster/logger": "0.3.18",
29
- "@grpc/grpc-js": "^1.5.9",
29
+ "@fonoster/logger": "0.3.20",
30
+ "@grpc/grpc-js": "^1.8.4",
30
31
  "@opentelemetry/api": "^1.0.4",
31
32
  "@opentelemetry/exporter-jaeger": "^1.0.4",
32
33
  "@opentelemetry/instrumentation": "^0.27.0",
@@ -35,8 +36,8 @@
35
36
  "@opentelemetry/sdk-trace-base": "^1.0.4",
36
37
  "@opentelemetry/sdk-trace-node": "^1.0.4",
37
38
  "@opentelemetry/semantic-conventions": "^1.0.4",
38
- "@routr/common": "^2.0.8-alpha.4",
39
- "@routr/processor": "^2.0.8-alpha.4",
39
+ "@routr/common": "^2.0.8-alpha.40",
40
+ "@routr/processor": "^2.0.8-alpha.40",
40
41
  "ajv": "^6.12.6",
41
42
  "fp-ts": "^2.11.8",
42
43
  "redis": "^4.0.4"
@@ -48,5 +49,5 @@
48
49
  "bugs": {
49
50
  "url": "https://github.com/fonoster/routr/issues"
50
51
  },
51
- "gitHead": "320abeb05175976ddfca265096a2ea63004607f4"
52
+ "gitHead": "3ac346a36a43ba06578accf48d7a4adac24a0911"
52
53
  }