@routr/processor 2.0.8-alpha.1 → 2.0.8-alpha.10
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/alterations.d.ts +1 -1
- package/dist/alterations.js +34 -34
- package/dist/helper.d.ts +6 -1
- package/dist/helper.js +9 -7
- package/package.json +3 -3
package/dist/alterations.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { MessageRequest, Route } from "@routr/common";
|
|
|
2
2
|
export declare const updateRequestURI: (route: Route) => (request: MessageRequest) => MessageRequest;
|
|
3
3
|
export declare const addSelfVia: (route: Route) => (request: MessageRequest) => MessageRequest;
|
|
4
4
|
export declare const addRoute: (route: Route) => (request: MessageRequest) => MessageRequest;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const addRouteToPeerEdgePort: (route: Route) => (request: MessageRequest) => MessageRequest;
|
|
6
6
|
export declare const applyXHeaders: (route: Route) => (request: MessageRequest) => MessageRequest;
|
|
7
7
|
export declare const addSelfRecordRoute: (route: Route) => (request: MessageRequest) => MessageRequest;
|
|
8
8
|
export declare const addXEdgePortRef: (request: MessageRequest) => MessageRequest;
|
package/dist/alterations.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decreaseMaxForwards = exports.removeTopVia = exports.removeRoutes = exports.removeAuthorization = exports.removeXEdgePortRef = exports.addXEdgePortRef = exports.addSelfRecordRoute = exports.applyXHeaders = exports.
|
|
3
|
+
exports.decreaseMaxForwards = exports.removeTopVia = exports.removeRoutes = exports.removeAuthorization = exports.removeXEdgePortRef = exports.addXEdgePortRef = exports.addSelfRecordRoute = exports.applyXHeaders = exports.addRouteToPeerEdgePort = exports.addRoute = exports.addSelfVia = exports.updateRequestURI = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/routr
|
|
@@ -20,8 +20,7 @@ exports.decreaseMaxForwards = exports.removeTopVia = exports.removeRoutes = expo
|
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
22
|
const common_1 = require("@routr/common");
|
|
23
|
-
const helper_1 = require("
|
|
24
|
-
const helper_2 = require("./helper");
|
|
23
|
+
const helper_1 = require("./helper");
|
|
25
24
|
// Q: Should we deprecate this method since we are not doing strict routing?
|
|
26
25
|
const updateRequestURI = (route) => (request) => {
|
|
27
26
|
const req = common_1.Helper.deepCopy(request);
|
|
@@ -38,25 +37,10 @@ const updateRequestURI = (route) => (request) => {
|
|
|
38
37
|
};
|
|
39
38
|
exports.updateRequestURI = updateRequestURI;
|
|
40
39
|
const addSelfVia = (route) => (request) => {
|
|
41
|
-
var _a;
|
|
42
40
|
const req = common_1.Helper.deepCopy(request);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
? route.host
|
|
47
|
-
: route.egressListeningPoint.host;
|
|
48
|
-
const egressListeningPoint = common_1.Helper.getListeningPoint(request, route.transport);
|
|
49
|
-
// If the nextHopHost host is local, then use use lp to construct via
|
|
50
|
-
// otherwise, we use the first available external ip.
|
|
51
|
-
const via = common_1.IpUtils.isLocalnet(req.localnets, nextHopHost)
|
|
52
|
-
? route.egressListeningPoint
|
|
53
|
-
: {
|
|
54
|
-
// fallback to lp host if there is no external ips
|
|
55
|
-
host: (_a = req.externalAddrs[0]) !== null && _a !== void 0 ? _a : egressListeningPoint.host,
|
|
56
|
-
port: egressListeningPoint.port,
|
|
57
|
-
transport: egressListeningPoint.transport
|
|
58
|
-
};
|
|
59
|
-
req.message.via = [via, ...req.message.via];
|
|
41
|
+
const routingObjects = request.edgePortRef === route.edgePortRef ? request : route;
|
|
42
|
+
const targetIntf = (0, helper_1.getEdgeInterface)(Object.assign(Object.assign({}, routingObjects), { endpointIntf: route }));
|
|
43
|
+
req.message.via = [Object.assign({}, targetIntf), ...req.message.via];
|
|
60
44
|
return req;
|
|
61
45
|
};
|
|
62
46
|
exports.addSelfVia = addSelfVia;
|
|
@@ -76,14 +60,20 @@ const addRoute = (route) => (request) => {
|
|
|
76
60
|
return req;
|
|
77
61
|
};
|
|
78
62
|
exports.addRoute = addRoute;
|
|
79
|
-
const
|
|
63
|
+
const addRouteToPeerEdgePort = (route) => (request) => {
|
|
80
64
|
const req = common_1.Helper.deepCopy(request);
|
|
65
|
+
const targetIntf = (0, helper_1.getEdgeInterface)({
|
|
66
|
+
listeningPoints: route.listeningPoints,
|
|
67
|
+
localnets: route.localnets,
|
|
68
|
+
externalAddrs: route.externalAddrs,
|
|
69
|
+
endpointIntf: route
|
|
70
|
+
});
|
|
81
71
|
const r = {
|
|
82
72
|
address: {
|
|
83
73
|
uri: {
|
|
84
|
-
host:
|
|
85
|
-
port:
|
|
86
|
-
transportParam:
|
|
74
|
+
host: targetIntf.host,
|
|
75
|
+
port: targetIntf.port,
|
|
76
|
+
transportParam: targetIntf.transport,
|
|
87
77
|
lrParam: true
|
|
88
78
|
}
|
|
89
79
|
}
|
|
@@ -91,7 +81,7 @@ const addRouteToListeningPoint = (route) => (request) => {
|
|
|
91
81
|
req.message.route = [r, ...req.message.route];
|
|
92
82
|
return req;
|
|
93
83
|
};
|
|
94
|
-
exports.
|
|
84
|
+
exports.addRouteToPeerEdgePort = addRouteToPeerEdgePort;
|
|
95
85
|
const applyXHeaders = (route) => (request) => {
|
|
96
86
|
const req = common_1.Helper.deepCopy(request);
|
|
97
87
|
if (route.headers && route.headers.length > 0) {
|
|
@@ -109,8 +99,18 @@ const applyXHeaders = (route) => (request) => {
|
|
|
109
99
|
exports.applyXHeaders = applyXHeaders;
|
|
110
100
|
const addSelfRecordRoute = (route) => (request) => {
|
|
111
101
|
const req = common_1.Helper.deepCopy(request);
|
|
112
|
-
const originIntf = (0,
|
|
113
|
-
|
|
102
|
+
const originIntf = (0, helper_1.getEdgeInterface)({
|
|
103
|
+
listeningPoints: request.listeningPoints,
|
|
104
|
+
localnets: request.localnets,
|
|
105
|
+
externalAddrs: request.externalAddrs,
|
|
106
|
+
endpointIntf: request.sender
|
|
107
|
+
});
|
|
108
|
+
const targetIntf = (0, helper_1.getEdgeInterface)({
|
|
109
|
+
listeningPoints: request.listeningPoints,
|
|
110
|
+
localnets: request.localnets,
|
|
111
|
+
externalAddrs: request.externalAddrs,
|
|
112
|
+
endpointIntf: route
|
|
113
|
+
});
|
|
114
114
|
const originRoute = {
|
|
115
115
|
address: {
|
|
116
116
|
uri: {
|
|
@@ -177,15 +177,15 @@ const removeAuthorization = (request) => {
|
|
|
177
177
|
exports.removeAuthorization = removeAuthorization;
|
|
178
178
|
const removeRoutes = (request) => {
|
|
179
179
|
const req = common_1.Helper.deepCopy(request);
|
|
180
|
+
const localIps = request.localnets.map((ln) => ln.split("/")[0]);
|
|
180
181
|
req.message.route = req.message.route.filter((r) => {
|
|
181
182
|
var _a;
|
|
182
|
-
const
|
|
183
|
-
const lp = (0, helper_1.getListeningPoint)(request, ((_a = r.address.uri.transportParam) === null || _a === void 0 ? void 0 : _a.toLowerCase()) ||
|
|
183
|
+
const lp = common_1.Helper.getListeningPoint(request.listeningPoints, ((_a = r.address.uri.transportParam) === null || _a === void 0 ? void 0 : _a.toLowerCase()) ||
|
|
184
184
|
common_1.Transport.UDP);
|
|
185
|
-
const
|
|
186
|
-
return !((localIps.includes(
|
|
187
|
-
request.externalAddrs.includes(
|
|
188
|
-
|
|
185
|
+
const routeUri = r.address.uri;
|
|
186
|
+
return !((localIps.includes(routeUri.host) ||
|
|
187
|
+
request.externalAddrs.includes(routeUri.host)) &&
|
|
188
|
+
routeUri.port === lp.port);
|
|
189
189
|
});
|
|
190
190
|
return req;
|
|
191
191
|
};
|
package/dist/helper.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { MessageRequest, Route, NetInterface } from "@routr/common";
|
|
2
2
|
export declare const isTypeResponse: (request: MessageRequest) => boolean;
|
|
3
3
|
export declare const isTypeRequest: (request: MessageRequest) => boolean;
|
|
4
|
-
export declare const getEdgeInterface: (
|
|
4
|
+
export declare const getEdgeInterface: (nets: {
|
|
5
|
+
listeningPoints: NetInterface[];
|
|
6
|
+
endpointIntf: NetInterface;
|
|
7
|
+
localnets: string[];
|
|
8
|
+
externalAddrs: string[];
|
|
9
|
+
}) => NetInterface;
|
|
5
10
|
/**
|
|
6
11
|
* A request traversing a second EdgePort would have an updated the requestUri.
|
|
7
12
|
* Therefore, we are able to re-construct the Route from the request.
|
package/dist/helper.js
CHANGED
|
@@ -26,11 +26,12 @@ const isTypeResponse = (request) => request.message.messageType === common_1.Com
|
|
|
26
26
|
exports.isTypeResponse = isTypeResponse;
|
|
27
27
|
const isTypeRequest = (request) => !(0, exports.isTypeResponse)(request);
|
|
28
28
|
exports.isTypeRequest = isTypeRequest;
|
|
29
|
-
const getEdgeInterface = (
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
29
|
+
const getEdgeInterface = (nets) => {
|
|
30
|
+
const { listeningPoints, endpointIntf, localnets, externalAddrs } = nets;
|
|
31
|
+
const localnetIp = common_2.IpUtils.getLocalnetIp(localnets, endpointIntf.host);
|
|
32
|
+
const host = localnetIp !== null && localnetIp !== void 0 ? localnetIp : externalAddrs[0];
|
|
33
|
+
const lp = common_1.Helper.getListeningPoint(listeningPoints, endpointIntf.transport);
|
|
34
|
+
if (!localnetIp && externalAddrs.length === 0) {
|
|
34
35
|
throw new Error(`unable to find a valid interface for host ${endpointIntf.host} and transport ${lp.transport}`);
|
|
35
36
|
}
|
|
36
37
|
if (localnetIp && lp.host !== "0.0.0.0" && lp.host !== host) {
|
|
@@ -55,7 +56,6 @@ function createRouteFromLastMessage(request) {
|
|
|
55
56
|
const sessionCount = index_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.SESSION_COUNT)
|
|
56
57
|
? parseInt(index_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.SESSION_COUNT))
|
|
57
58
|
: -1;
|
|
58
|
-
const egressListeningPoint = common_1.Helper.getListeningPoint(request, uri.transportParam.toLowerCase());
|
|
59
59
|
return {
|
|
60
60
|
edgePortRef: request.edgePortRef,
|
|
61
61
|
user: uri.user,
|
|
@@ -65,7 +65,9 @@ function createRouteFromLastMessage(request) {
|
|
|
65
65
|
registeredOn: Date.now(),
|
|
66
66
|
sessionCount,
|
|
67
67
|
expires: index_1.Target.getTargetExpires(request),
|
|
68
|
-
|
|
68
|
+
listeningPoints: request.listeningPoints,
|
|
69
|
+
localnets: request.localnets,
|
|
70
|
+
externalAddrs: request.externalAddrs
|
|
69
71
|
};
|
|
70
72
|
}
|
|
71
73
|
exports.createRouteFromLastMessage = createRouteFromLastMessage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/processor",
|
|
3
|
-
"version": "2.0.8-alpha.
|
|
3
|
+
"version": "2.0.8-alpha.10",
|
|
4
4
|
"description": "Processor server and API",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@opentelemetry/sdk-trace-base": "^1.0.4",
|
|
24
24
|
"@opentelemetry/sdk-trace-node": "^1.0.4",
|
|
25
25
|
"@opentelemetry/semantic-conventions": "^1.0.4",
|
|
26
|
-
"@routr/common": "^2.0.8-alpha.
|
|
26
|
+
"@routr/common": "^2.0.8-alpha.10",
|
|
27
27
|
"fp-ts": "^2.11.8"
|
|
28
28
|
},
|
|
29
29
|
"directories": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"bugs": {
|
|
44
44
|
"url": "https://github.com/fonoster/routr/issues"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "5082233fb155ddb8535f934550fa4013da87468e"
|
|
47
47
|
}
|