@interopio/bridge 0.0.1-alpha → 0.0.4-beta.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.
Files changed (85) hide show
  1. package/bin/bridge.js +1 -1
  2. package/changelog.md +24 -0
  3. package/dist/main.js +2201 -0
  4. package/dist/main.js.map +7 -0
  5. package/package.json +9 -6
  6. package/gen/instance/GeneratedBuildInfo.ts +0 -4
  7. package/src/cluster/Address.ts +0 -57
  8. package/src/cluster/Cluster.ts +0 -13
  9. package/src/cluster/Endpoint.ts +0 -5
  10. package/src/cluster/Member.ts +0 -9
  11. package/src/cluster/MembershipListener.ts +0 -6
  12. package/src/config/Config.ts +0 -100
  13. package/src/config/DiscoveryConfig.ts +0 -21
  14. package/src/config/Duration.ts +0 -168
  15. package/src/config/KubernetesConfig.ts +0 -7
  16. package/src/config/NamedDiscoveryConfig.ts +0 -17
  17. package/src/config/Properties.ts +0 -49
  18. package/src/config/index.ts +0 -1
  19. package/src/discovery/SimpleDiscoveryNode.ts +0 -14
  20. package/src/discovery/index.ts +0 -207
  21. package/src/discovery/multicast/MulticastDiscoveryStrategy.ts +0 -141
  22. package/src/discovery/multicast/MulticastDiscoveryStrategyFactory.ts +0 -30
  23. package/src/discovery/multicast/MulticastProperties.ts +0 -4
  24. package/src/discovery/settings.ts +0 -37
  25. package/src/error/RequestFailure.ts +0 -48
  26. package/src/gossip/ApplicationState.ts +0 -48
  27. package/src/gossip/EndpointState.ts +0 -141
  28. package/src/gossip/FailureDetector.ts +0 -235
  29. package/src/gossip/Gossiper.ts +0 -1133
  30. package/src/gossip/HeartbeatState.ts +0 -66
  31. package/src/gossip/Messenger.ts +0 -130
  32. package/src/gossip/VersionedValue.ts +0 -59
  33. package/src/index.ts +0 -3
  34. package/src/instance/AddressPicker.ts +0 -245
  35. package/src/instance/BridgeNode.ts +0 -141
  36. package/src/instance/ClusterTopologyIntentTracker.ts +0 -4
  37. package/src/io/VersionedSerializer.ts +0 -230
  38. package/src/io/util.ts +0 -117
  39. package/src/kubernetes/DnsEndpointResolver.ts +0 -70
  40. package/src/kubernetes/KubernetesApiEndpointResolver.ts +0 -111
  41. package/src/kubernetes/KubernetesApiProvider.ts +0 -75
  42. package/src/kubernetes/KubernetesClient.ts +0 -264
  43. package/src/kubernetes/KubernetesConfig.ts +0 -130
  44. package/src/kubernetes/KubernetesDiscoveryStrategy.ts +0 -30
  45. package/src/kubernetes/KubernetesDiscoveryStrategyFactory.ts +0 -71
  46. package/src/kubernetes/KubernetesEndpointResolver.ts +0 -43
  47. package/src/kubernetes/KubernetesProperties.ts +0 -22
  48. package/src/license/BridgeLicenseValidator.ts +0 -19
  49. package/src/license/LicenseValidator.ts +0 -114
  50. package/src/license/types.ts +0 -40
  51. package/src/logging.ts +0 -22
  52. package/src/main.mts +0 -53
  53. package/src/net/Action.ts +0 -143
  54. package/src/net/AddressSerializer.ts +0 -44
  55. package/src/net/ByteBufferAllocator.ts +0 -27
  56. package/src/net/FrameDecoder.ts +0 -314
  57. package/src/net/FrameEncoder.ts +0 -138
  58. package/src/net/HandshakeProtocol.ts +0 -143
  59. package/src/net/InboundConnection.ts +0 -108
  60. package/src/net/InboundConnectionInitiator.ts +0 -150
  61. package/src/net/InboundMessageHandler.ts +0 -377
  62. package/src/net/InboundSink.ts +0 -38
  63. package/src/net/Message.ts +0 -428
  64. package/src/net/OutboundConnection.ts +0 -1141
  65. package/src/net/OutboundConnectionInitiator.ts +0 -76
  66. package/src/net/RequestCallbacks.ts +0 -148
  67. package/src/net/ResponseHandler.ts +0 -30
  68. package/src/net/ShareableBytes.ts +0 -125
  69. package/src/net/internal/AsyncResourceExecutor.ts +0 -464
  70. package/src/net/internal/AsyncSocketPromise.ts +0 -37
  71. package/src/net/internal/channel/ChannelHandlerAdapter.ts +0 -99
  72. package/src/net/internal/channel/types.ts +0 -188
  73. package/src/utils/bigint.ts +0 -23
  74. package/src/utils/buffer.ts +0 -434
  75. package/src/utils/clock.ts +0 -148
  76. package/src/utils/collections.ts +0 -283
  77. package/src/utils/crc.ts +0 -39
  78. package/src/utils/internal/IpAddressUtil.ts +0 -161
  79. package/src/utils/memory/BufferPools.ts +0 -40
  80. package/src/utils/network.ts +0 -130
  81. package/src/utils/promise.ts +0 -38
  82. package/src/utils/uuid.ts +0 -5
  83. package/src/utils/vint.ts +0 -238
  84. package/src/version/MemberVersion.ts +0 -42
  85. package/src/version/Version.ts +0 -12
@@ -1,130 +0,0 @@
1
- import {networkInterfaces} from 'node:os';
2
- import {ADDRCONFIG, type LookupAddress} from 'node:dns';
3
- import {lookup, lookupService} from 'node:dns/promises';
4
-
5
- import {textToNumericFormatV4, textToNumericFormatV6} from './internal/IpAddressUtil.ts';
6
- import {readFileSync} from "node:fs";
7
-
8
- const INET_ADDRESS_V4_SIZE = 4;
9
-
10
- class IpAddress {
11
- readonly address: string;
12
- readonly family: 4 | 6;
13
- private _hostname?: string;
14
-
15
- constructor(host: string | undefined, address: string, family: 4 | 6) {
16
- this._hostname = host;
17
- this.address = address;
18
- this.family = family;
19
- }
20
-
21
- get addressBytes(): Uint8Array {
22
- if (this.family === 4) {
23
- return textToNumericFormatV4(this.address);
24
- }
25
- //return textToNumericFormatV6(this.address);
26
- }
27
-
28
- async getHost(): Promise<string> {
29
- if (!this._hostname) {
30
- this._hostname = (await lookupService(this.address, 0)).hostname;
31
- }
32
- return this._hostname;
33
- }
34
-
35
- async getIpAddress(nonLoopback: boolean = false): Promise<LookupAddress> {
36
- const hints = nonLoopback ? ADDRCONFIG : undefined;
37
- return await lookup(this.address, {family: this.family, hints: hints});
38
- }
39
- }
40
-
41
- export type {IpAddress};
42
-
43
- export function isLoopback(address: IpAddress): boolean {
44
- return address.family === 4 && address.address.startsWith('127.') || address.family === 6 && address.address.startsWith('::1');
45
- }
46
-
47
- export async function getByName(host: string): Promise<IpAddress> {
48
- const {address, family} = await lookup(host, {family: 4});
49
- if (family !== 4 && family !== 6) {
50
- throw new Error('unexpected address type');
51
- }
52
- return new IpAddress(undefined, address, family);
53
- }
54
-
55
- let _anyLocalAddress: IpAddress;
56
-
57
- export function anyLocalAddress(): IpAddress {
58
- if (!_anyLocalAddress) {
59
- _anyLocalAddress = getByAddress('0.0.0.0', 0);
60
- }
61
- return _anyLocalAddress;
62
- }
63
-
64
- export function getByAddress(host: string, bytes: Uint8Array | number): IpAddress {
65
- if (typeof bytes === 'number') {
66
- const n = bytes;
67
- bytes = new Uint8Array(INET_ADDRESS_V4_SIZE);
68
- new DataView(bytes.buffer).setInt32(0, n);
69
- }
70
- const family = bytes.length === INET_ADDRESS_V4_SIZE ? 4 : 6;
71
- const address = Array.from(bytes).join('.');
72
- return new IpAddress(host, address, family);
73
- }
74
-
75
- export async function resolveByAddress(host: string, address: string): Promise<IpAddress> {
76
- const byName = await getByName(address);
77
- // todo: check if address and host names are correct
78
- return new IpAddress(host, byName.address, byName.family);
79
- }
80
-
81
- export async function getAllByName(host: string): Promise<IpAddress[]> {
82
- const addresses = await lookup(host, {all: true});
83
- return addresses.map(({address, family}) => {
84
- if (family !== 4 && family !== 6) {
85
- throw new Error('unexpected address type');
86
- }
87
- return new IpAddress(undefined, address, family);
88
- });
89
- }
90
-
91
- export interface NetworkInterface {
92
- name: string
93
- loopback: boolean
94
- addresses: Array<IpAddress>
95
- }
96
-
97
- export function getNetworkInterfaces(): NetworkInterface[] {
98
- return Object.entries(networkInterfaces()).map(([name, addresses]) => {
99
- return {
100
- name,
101
- loopback: addresses.some(info => info.internal),
102
- addresses: addresses.map(info => {
103
- return new IpAddress(undefined, info.address, info.family === 'IPv6' ? 6 : 4);
104
- })
105
- };
106
- });
107
- }
108
-
109
- function soMaxConn() {
110
- let somaxconn;
111
- if (process.platform === 'win32') {
112
- somaxconn = 200;
113
- }
114
- else if (process.platform === 'darwin') {
115
- somaxconn = 128;
116
- }
117
- else {
118
- somaxconn = 4096;
119
- }
120
-
121
- try {
122
- somaxconn = parseInt(readFileSync('/proc/sys/net/core/somaxconn').toString());
123
- } catch (error) {
124
- // todo log
125
- }
126
- return somaxconn;
127
- }
128
-
129
- export const SOMAXCONN = soMaxConn();
130
-
@@ -1,38 +0,0 @@
1
- export type DeferredPromise<T> = {
2
- readonly promise: Promise<T>;
3
- success(value: T): void;
4
- failure(reason?: any): void;
5
- cancel(): boolean;
6
- readonly canceled: boolean;
7
- }
8
-
9
- export function deferred<T>(canceler?: (callback: (err?: Error) => void) => boolean): DeferredPromise<T> {
10
- let success, failure;
11
- const promise = new Promise<T>((resolve, reject) => {
12
- success = resolve;
13
- failure = reject;
14
- });
15
- let canceled = false;
16
- const cancel = () => {
17
- if (canceled) {
18
- return false;
19
- }
20
- canceled = true;
21
- if (canceler) {
22
- canceled = canceler((err?: Error) => {
23
- failure(new Error('canceled', {cause: err}));
24
- });
25
- }
26
- else {
27
- failure(new Error('canceled'));
28
- }
29
- return canceled;
30
- }
31
- return {
32
- promise,
33
- success,
34
- failure,
35
- cancel,
36
- get canceled() { return canceled; },
37
- };
38
- }
package/src/utils/uuid.ts DELETED
@@ -1,5 +0,0 @@
1
- import {nanoid} from 'nanoid';
2
-
3
- export function newUUID() : string {
4
- return nanoid();
5
- }
package/src/utils/vint.ts DELETED
@@ -1,238 +0,0 @@
1
- /**
2
- * Borrows idea from
3
- * https://developers.google.com/protocol-buffers/docs/encoding#varints
4
- */
5
- import type {ByteBuffer} from "./buffer";
6
- import type {DataInput} from "../io/VersionedSerializer";
7
-
8
-
9
- const HI = 0;
10
- const LO = 1;
11
- type Int64 = [hi: number, lo: number];
12
- const zero: () => Int64 = () => [0, 0];
13
-
14
- function encodeZigZag64([hi, lo]: Int64): Int64 {
15
- const mask = hi >> 31;
16
- hi = ((hi << 1 | lo >>> 31) ^ mask) >>> 0;
17
- lo = ((lo << 1) ^ mask) >>> 0;
18
- return [hi, lo];
19
- }
20
-
21
- function decodeZigZag64([hi, lo]: Int64): Int64 {
22
- const mask = -(hi & 1);
23
- lo = ((lo >>> 1 | hi << 31) ^ mask) >>> 0;
24
- hi = ((hi >>> 1) ^ mask) >>> 0;
25
- return [hi, lo];
26
- }
27
-
28
- function numberOfExtraBytesToRead(firstByte: number) {
29
- return numberOfLeadingZeros32(~firstByte) - 24;
30
- }
31
-
32
- function firstByteValueMask(size:number) {
33
- return 0xff >> size;
34
- }
35
-
36
- export function getUnsignedVInt32(buffer: ByteBuffer, position?: number, limit?: number): number {
37
- const i64 = getUnsignedVInt64(buffer, position, limit);
38
- if (i64 === -1) {
39
- return -1;
40
- }
41
- return i64[HI] === -1 ? -i64[LO] : i64[LO];
42
- }
43
-
44
- export function getUnsignedVIntSize(buffer: ByteBuffer, position?: number, limit?: number): number {
45
- limit ??= buffer.limit;
46
- position ??= buffer.position;
47
- if (position >= limit) {
48
- return -1;
49
- }
50
-
51
- const firstByte = buffer.getInt8(position++);
52
- return 1 + (firstByte >= 0 ? 0 : numberOfExtraBytesToRead(firstByte));
53
- }
54
-
55
- export function getUnsignedVInt(buffer: ByteBuffer, position?: number, limit?: number): number | bigint {
56
- const i64 = getUnsignedVInt64(buffer, position, limit);
57
- if (i64 === -1) {
58
- return -1;
59
- }
60
- if (i64[HI] === 0) {
61
- return i64[LO];
62
- }
63
- return BigInt(i64[HI]) << 32n | BigInt(i64[LO]);
64
- }
65
-
66
- function getUnsignedVInt64(buffer: ByteBuffer, position?: number, limit?: number): Int64 | -1 {
67
- limit ??= buffer.limit;
68
- position ??= buffer.position;
69
- if (position >= limit) {
70
- return -1;
71
- }
72
-
73
- const firstByte = buffer.getInt8(position++);
74
- if (firstByte >= 0) {
75
- return [0, firstByte];
76
- }
77
-
78
- const size = numberOfExtraBytesToRead(firstByte);
79
- if (position + size > limit) {
80
- return -1;
81
- }
82
-
83
- let result: Int64 = zero();
84
- result[size > 4 ? HI : LO] = firstByte & firstByteValueMask(size);
85
- for (let i = 0; i < size; i++) {
86
- const vi = size - i > 4 ? HI : LO;
87
- const b = buffer.getInt8(position++);
88
- result[vi] <<= 8;
89
- result[vi] |= b & 0xff
90
- }
91
- return result;
92
- }
93
-
94
- function encodeExtraBytesToRead(extraBytesToRead: number) {
95
- return ~firstByteValueMask(extraBytesToRead);
96
- }
97
- const TMP = new Uint8Array(9);
98
- function encodeUnsignedVint64(value: Int64, size: number): Uint8Array {
99
- const encodingSpace = TMP;
100
-
101
- const extraBytes = size - 1;
102
- for (let i = extraBytes; i>= 0; i--) {
103
- const vi = i > 4 ? HI : LO;
104
- encodingSpace[i] = value[vi] & 0xff;
105
- value[vi] >>= 8;
106
- }
107
- encodingSpace[0] |= encodeExtraBytesToRead(extraBytes);
108
- return encodingSpace;
109
- }
110
-
111
- export function setUnsignedVInt32(i: number, buffer: ByteBuffer) {
112
- setUnsignedVInt64(int64(i, true), buffer);
113
- }
114
-
115
- export function setUnsignedVInt(i: bigint | number, buffer: ByteBuffer) {
116
- const i64 = int64(i);
117
- setUnsignedVInt64(i64, buffer);
118
- }
119
-
120
- function setUnsignedVInt64(i64: Int64, buffer: ByteBuffer) {
121
- const size = computeUnsignedVIntSize64(i64);
122
- if (size === 1) {
123
- buffer.setUint8(i64[LO]);
124
- }
125
- else if (size < 9)
126
- {
127
- const limit = buffer.limit;
128
- const position = buffer.position;
129
- if (limit - position >= 8) {
130
- const shift = (8 - size) << 3;
131
- const extraBytes = size - 1;
132
- const mask = encodeExtraBytesToRead(extraBytes) << 24;
133
-
134
- if (shift < 32) {
135
- buffer.setInt32(position, ((i64[HI] << shift) | (i64[LO] >> (32 - shift))) | mask);
136
- buffer.setInt32(position + 4, i64[LO] << shift);
137
- }
138
- else {
139
- buffer.setInt32(position, (i64[LO] << (shift - 32)) | mask);
140
- }
141
- buffer.position = position + size;
142
- }
143
- else {
144
- buffer.setUint8Array(encodeUnsignedVint64(i64, size), 0, size);
145
- }
146
-
147
- }
148
- else if (size === 9) {
149
- buffer.setUint8(0xFF);
150
- buffer.setUint32(i64[HI]);
151
- buffer.setUint32(i64[LO]);
152
- }
153
- else {
154
- throw new Error();
155
- }
156
- }
157
-
158
- export function computeVIntSize(i: bigint | number): number {
159
- return computeUnsignedVIntSize64(encodeZigZag64(int64(i)));
160
- }
161
-
162
- function int64(i: bigint | number, from32 = false): [hi: number, lo: number] {
163
- if (typeof i === 'number') {
164
- if (from32) {
165
- const lo = i & 0xFFFFFFFF;
166
- const hi = lo >> 31 === -1 ? -1 : 0;
167
- return [hi, lo];
168
- }
169
- i = BigInt(i);
170
- }
171
- const lo = Number(i & 0xFFFFFFFFn);
172
- const hi = Number((i & 0xFFFFFFFF00000000n) >> 32n);
173
-
174
- return [hi, lo];
175
- }
176
-
177
- function computeUnsignedVIntSize64([hi, lo]: Int64) {
178
- const magnitude = numberOfLeadingZeros64([hi, lo | 1]);
179
- return (639 - magnitude * 9) >> 6;
180
- }
181
-
182
- export function computeUnsignedVIntSize(i: bigint | number): number {
183
- return computeUnsignedVIntSize64(int64(i));
184
- }
185
-
186
- function numberOfLeadingZeros64([hi, lo]: Int64): number {
187
- return hi === 0 ? numberOfLeadingZeros32(lo) + 32 : numberOfLeadingZeros32(hi);
188
- }
189
-
190
- function numberOfLeadingZeros32(i: number): number {
191
-
192
- if (i === 0) {
193
- return 32;
194
- }
195
- if (i < 0) {
196
- return 0;
197
- }
198
-
199
- let n = 31;
200
- if (i >= 1 << 16) { n -= 16; i >>>= 16; }
201
- if (i >= 1 << 8) { n -= 8; i >>>= 8; }
202
- if (i >= 1 << 4) { n -= 4; i >>>= 4; }
203
- if (i >= 1 << 2) { n -= 2; i >>>= 2; }
204
- return n - (i >>> 1);
205
- }
206
-
207
- export function skipUnsignedVInt(input: DataInput): void {
208
- const firstByte = input.readInt8();
209
- if (firstByte < 0) {
210
- input.skipBytesFully(numberOfExtraBytesToRead(firstByte));
211
- }
212
- }
213
-
214
-
215
- export function readUnsignedVInt32(input: DataInput): number {
216
- const i64 = readUnsignedVInt64(input);
217
- return i64[HI] === -1 ? -i64[LO] : i64[LO];
218
- }
219
-
220
- function readUnsignedVInt64(input: DataInput): Int64 {
221
- const firstByte = input.readInt8();
222
- if (firstByte >= 0) {
223
- return [0, firstByte];
224
- }
225
-
226
- const size = numberOfExtraBytesToRead(firstByte);
227
-
228
- let result: Int64 = zero();
229
- result[size > 4 ? HI : LO] = firstByte & firstByteValueMask(size);
230
- for (let i = 0; i < size; i++) {
231
- const vi = size - i > 4 ? HI : LO;
232
- const b = input.readInt8();
233
- result[vi] <<= 8;
234
- result[vi] |= b & 0xff
235
- }
236
- return result;
237
-
238
- }
@@ -1,42 +0,0 @@
1
- function parse(version: string): [number, number, number] {
2
- const pattern = /(\d+)\.(\d+)(\.(\d+))?(-\w+(?:-\d+)?)?$/g;
3
-
4
- const x = pattern.exec(version);
5
- const major = parseInt(x[1]);
6
- const minor = parseInt(x[2]);
7
- const patch = x[3] ? parseInt(x[4]) : 0;
8
-
9
- return [major, minor, patch];
10
- }
11
-
12
- class MemberVersion {
13
-
14
- readonly major: number;
15
- readonly minor: number;
16
- readonly patch: number;
17
-
18
- public get isUnknown(): boolean {
19
- return this.major === 0 && this.minor === 0 && this.patch === 0;
20
- }
21
-
22
- public toString(): string {
23
- return `${this.major}.${this.minor}.${this.patch}`;
24
- }
25
-
26
- constructor(major: number, minor: number, patch: number) {
27
- this.major = major;
28
- this.minor = minor;
29
- this.patch = patch;
30
- }
31
- }
32
-
33
- export const UNKNOWN_VERSION: MemberVersion = new MemberVersion(0, 0, 0);
34
-
35
- export function parseVersion(version?: string): MemberVersion {
36
- if (!version || version.startsWith('0.0.0')) {
37
- return UNKNOWN_VERSION;
38
- }
39
- return new MemberVersion(...parse(version));
40
- }
41
-
42
- export type {MemberVersion};
@@ -1,12 +0,0 @@
1
- export class Version {
2
- public static of(major: number, minor: number) {
3
- return new Version(major, minor);
4
- }
5
- readonly major: number;
6
- readonly minor: number;
7
-
8
- private constructor(major: number, minor: number) {
9
- this.major = major;
10
- this.minor = minor;
11
- }
12
- }