@routr/location 2.17.0 → 2.18.0

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/helper.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MessageRequest, Route } from "@routr/common";
2
- export declare function createRoute(request: MessageRequest): Route;
2
+ export declare function createRoute(request: MessageRequest, defaultExpires?: number): Route;
3
3
  /**
4
4
  * A request traversing a second EdgePort would have updated the requestUri.
5
5
  * Therefore, we are able to re-construct the Route from the request.
package/dist/helper.js CHANGED
@@ -29,7 +29,7 @@ const processor_1 = require("@routr/processor");
29
29
  //
30
30
  // Also consider: https://github.com/fonoster/routr/blob/ee5d339888344013939d06c734385f17f0cd75c2/mod/registrar/utils.js#L116
31
31
  // and https://github.com/fonoster/routr/blob/ee5d339888344013939d06c734385f17f0cd75c2/mod/registrar/utils.js#L131
32
- function buildRoute(request, uri) {
32
+ function buildRoute(request, uri, defaultExpires) {
33
33
  var _a;
34
34
  const via = request.message.via[0];
35
35
  const sessionCount = processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.SESSION_COUNT)
@@ -45,13 +45,13 @@ function buildRoute(request, uri) {
45
45
  transport: (_a = uri.transportParam) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
46
46
  registeredOn: Date.now(),
47
47
  sessionCount,
48
- expires: processor_1.Target.getTargetExpires(request),
48
+ expires: processor_1.Target.getTargetExpires(request, defaultExpires),
49
49
  listeningPoints: request.listeningPoints,
50
50
  localnets: request.localnets,
51
51
  externalAddrs: request.externalAddrs
52
52
  };
53
53
  }
54
- function createRoute(request) {
54
+ function createRoute(request, defaultExpires) {
55
55
  const via = request.message.via[0];
56
56
  const uri = {
57
57
  host: via.received || via.host,
@@ -59,7 +59,7 @@ function createRoute(request) {
59
59
  transportParam: via.transport.toUpperCase(),
60
60
  user: request.message.from.address.uri.user
61
61
  };
62
- return buildRoute(request, uri);
62
+ return buildRoute(request, uri, defaultExpires);
63
63
  }
64
64
  /**
65
65
  * A request traversing a second EdgePort would have updated the requestUri.
@@ -40,7 +40,14 @@ class RedisStore {
40
40
  put(key, route) {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
42
  // Formatted the key to ensure it is unique
43
- yield this.client.set(`${key}:${route.user}${route.host}${route.port}`, JSON.stringify(route), {
43
+ const routeKey = `${key}:${route.user}${route.host}${route.port}`;
44
+ // An expires of zero removes the binding (RFC 3261 section 10.3, step 7).
45
+ // Redis rejects SET with EX 0, so delete the key instead.
46
+ if (route.expires <= 0) {
47
+ yield this.client.del(routeKey);
48
+ return;
49
+ }
50
+ yield this.client.set(routeKey, JSON.stringify(route), {
44
51
  EX: route.expires
45
52
  });
46
53
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/location",
3
- "version": "2.17.0",
3
+ "version": "2.18.0",
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",
@@ -28,7 +28,7 @@
28
28
  "@fonoster/logger": "0.6.0",
29
29
  "@grpc/grpc-js": "~1.14.6",
30
30
  "@routr/common": "^2.17.0",
31
- "@routr/processor": "^2.17.0",
31
+ "@routr/processor": "^2.18.0",
32
32
  "ajv": "^6.12.6",
33
33
  "fp-ts": "^2.11.8",
34
34
  "redis": "^4.0.4"
@@ -40,5 +40,5 @@
40
40
  "bugs": {
41
41
  "url": "https://github.com/fonoster/routr/issues"
42
42
  },
43
- "gitHead": "9bc2d0a407a82e7b3724bb139ba62504c7b3d49e"
43
+ "gitHead": "53d48803760e0d8d6af1efa63db2414594d79454"
44
44
  }