@routr/processor 2.0.8-alpha.5 → 2.0.8-alpha.6
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 +33 -32
- 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
|
|
@@ -37,25 +37,10 @@ const updateRequestURI = (route) => (request) => {
|
|
|
37
37
|
};
|
|
38
38
|
exports.updateRequestURI = updateRequestURI;
|
|
39
39
|
const addSelfVia = (route) => (request) => {
|
|
40
|
-
var _a;
|
|
41
40
|
const req = common_1.Helper.deepCopy(request);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
? route.host
|
|
46
|
-
: route.egressListeningPoint.host;
|
|
47
|
-
const egressListeningPoint = common_1.Helper.getListeningPoint(request, route.transport);
|
|
48
|
-
// If the nextHopHost host is local, then use use lp to construct via
|
|
49
|
-
// otherwise, we use the first available external ip.
|
|
50
|
-
const via = common_1.IpUtils.isLocalnet(req.localnets, nextHopHost)
|
|
51
|
-
? route.egressListeningPoint
|
|
52
|
-
: {
|
|
53
|
-
// fallback to lp host if there is no external ips
|
|
54
|
-
host: (_a = req.externalAddrs[0]) !== null && _a !== void 0 ? _a : egressListeningPoint.host,
|
|
55
|
-
port: egressListeningPoint.port,
|
|
56
|
-
transport: egressListeningPoint.transport
|
|
57
|
-
};
|
|
58
|
-
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];
|
|
59
44
|
return req;
|
|
60
45
|
};
|
|
61
46
|
exports.addSelfVia = addSelfVia;
|
|
@@ -75,14 +60,20 @@ const addRoute = (route) => (request) => {
|
|
|
75
60
|
return req;
|
|
76
61
|
};
|
|
77
62
|
exports.addRoute = addRoute;
|
|
78
|
-
const
|
|
63
|
+
const addRouteToPeerEdgePort = (route) => (request) => {
|
|
79
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
|
+
});
|
|
80
71
|
const r = {
|
|
81
72
|
address: {
|
|
82
73
|
uri: {
|
|
83
|
-
host:
|
|
84
|
-
port:
|
|
85
|
-
transportParam:
|
|
74
|
+
host: targetIntf.host,
|
|
75
|
+
port: targetIntf.port,
|
|
76
|
+
transportParam: targetIntf.transport,
|
|
86
77
|
lrParam: true
|
|
87
78
|
}
|
|
88
79
|
}
|
|
@@ -90,7 +81,7 @@ const addRouteToListeningPoint = (route) => (request) => {
|
|
|
90
81
|
req.message.route = [r, ...req.message.route];
|
|
91
82
|
return req;
|
|
92
83
|
};
|
|
93
|
-
exports.
|
|
84
|
+
exports.addRouteToPeerEdgePort = addRouteToPeerEdgePort;
|
|
94
85
|
const applyXHeaders = (route) => (request) => {
|
|
95
86
|
const req = common_1.Helper.deepCopy(request);
|
|
96
87
|
if (route.headers && route.headers.length > 0) {
|
|
@@ -108,8 +99,18 @@ const applyXHeaders = (route) => (request) => {
|
|
|
108
99
|
exports.applyXHeaders = applyXHeaders;
|
|
109
100
|
const addSelfRecordRoute = (route) => (request) => {
|
|
110
101
|
const req = common_1.Helper.deepCopy(request);
|
|
111
|
-
const originIntf = (0, helper_1.getEdgeInterface)(
|
|
112
|
-
|
|
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
|
+
});
|
|
113
114
|
const originRoute = {
|
|
114
115
|
address: {
|
|
115
116
|
uri: {
|
|
@@ -176,15 +177,15 @@ const removeAuthorization = (request) => {
|
|
|
176
177
|
exports.removeAuthorization = removeAuthorization;
|
|
177
178
|
const removeRoutes = (request) => {
|
|
178
179
|
const req = common_1.Helper.deepCopy(request);
|
|
180
|
+
const localIps = request.localnets.map((ln) => ln.split("/")[0]);
|
|
179
181
|
req.message.route = req.message.route.filter((r) => {
|
|
180
182
|
var _a;
|
|
181
|
-
const
|
|
182
|
-
const lp = common_1.Helper.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()) ||
|
|
183
184
|
common_1.Transport.UDP);
|
|
184
|
-
const
|
|
185
|
-
return !((localIps.includes(
|
|
186
|
-
request.externalAddrs.includes(
|
|
187
|
-
|
|
185
|
+
const routeUri = r.address.uri;
|
|
186
|
+
return !((localIps.includes(routeUri.host) ||
|
|
187
|
+
request.externalAddrs.includes(routeUri.host)) &&
|
|
188
|
+
routeUri.port === lp.port);
|
|
188
189
|
});
|
|
189
190
|
return req;
|
|
190
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.6",
|
|
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.6",
|
|
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": "0647d7472b78b4a60e54e3577fed9e9fd4e9eaa4"
|
|
47
47
|
}
|