@interopio/bridge 0.0.1-alpha → 0.0.3-beta

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 (84) hide show
  1. package/bin/bridge.js +1 -1
  2. package/dist/main.js +2139 -0
  3. package/dist/main.js.map +7 -0
  4. package/package.json +9 -6
  5. package/gen/instance/GeneratedBuildInfo.ts +0 -4
  6. package/src/cluster/Address.ts +0 -57
  7. package/src/cluster/Cluster.ts +0 -13
  8. package/src/cluster/Endpoint.ts +0 -5
  9. package/src/cluster/Member.ts +0 -9
  10. package/src/cluster/MembershipListener.ts +0 -6
  11. package/src/config/Config.ts +0 -100
  12. package/src/config/DiscoveryConfig.ts +0 -21
  13. package/src/config/Duration.ts +0 -168
  14. package/src/config/KubernetesConfig.ts +0 -7
  15. package/src/config/NamedDiscoveryConfig.ts +0 -17
  16. package/src/config/Properties.ts +0 -49
  17. package/src/config/index.ts +0 -1
  18. package/src/discovery/SimpleDiscoveryNode.ts +0 -14
  19. package/src/discovery/index.ts +0 -207
  20. package/src/discovery/multicast/MulticastDiscoveryStrategy.ts +0 -141
  21. package/src/discovery/multicast/MulticastDiscoveryStrategyFactory.ts +0 -30
  22. package/src/discovery/multicast/MulticastProperties.ts +0 -4
  23. package/src/discovery/settings.ts +0 -37
  24. package/src/error/RequestFailure.ts +0 -48
  25. package/src/gossip/ApplicationState.ts +0 -48
  26. package/src/gossip/EndpointState.ts +0 -141
  27. package/src/gossip/FailureDetector.ts +0 -235
  28. package/src/gossip/Gossiper.ts +0 -1133
  29. package/src/gossip/HeartbeatState.ts +0 -66
  30. package/src/gossip/Messenger.ts +0 -130
  31. package/src/gossip/VersionedValue.ts +0 -59
  32. package/src/index.ts +0 -3
  33. package/src/instance/AddressPicker.ts +0 -245
  34. package/src/instance/BridgeNode.ts +0 -141
  35. package/src/instance/ClusterTopologyIntentTracker.ts +0 -4
  36. package/src/io/VersionedSerializer.ts +0 -230
  37. package/src/io/util.ts +0 -117
  38. package/src/kubernetes/DnsEndpointResolver.ts +0 -70
  39. package/src/kubernetes/KubernetesApiEndpointResolver.ts +0 -111
  40. package/src/kubernetes/KubernetesApiProvider.ts +0 -75
  41. package/src/kubernetes/KubernetesClient.ts +0 -264
  42. package/src/kubernetes/KubernetesConfig.ts +0 -130
  43. package/src/kubernetes/KubernetesDiscoveryStrategy.ts +0 -30
  44. package/src/kubernetes/KubernetesDiscoveryStrategyFactory.ts +0 -71
  45. package/src/kubernetes/KubernetesEndpointResolver.ts +0 -43
  46. package/src/kubernetes/KubernetesProperties.ts +0 -22
  47. package/src/license/BridgeLicenseValidator.ts +0 -19
  48. package/src/license/LicenseValidator.ts +0 -114
  49. package/src/license/types.ts +0 -40
  50. package/src/logging.ts +0 -22
  51. package/src/main.mts +0 -53
  52. package/src/net/Action.ts +0 -143
  53. package/src/net/AddressSerializer.ts +0 -44
  54. package/src/net/ByteBufferAllocator.ts +0 -27
  55. package/src/net/FrameDecoder.ts +0 -314
  56. package/src/net/FrameEncoder.ts +0 -138
  57. package/src/net/HandshakeProtocol.ts +0 -143
  58. package/src/net/InboundConnection.ts +0 -108
  59. package/src/net/InboundConnectionInitiator.ts +0 -150
  60. package/src/net/InboundMessageHandler.ts +0 -377
  61. package/src/net/InboundSink.ts +0 -38
  62. package/src/net/Message.ts +0 -428
  63. package/src/net/OutboundConnection.ts +0 -1141
  64. package/src/net/OutboundConnectionInitiator.ts +0 -76
  65. package/src/net/RequestCallbacks.ts +0 -148
  66. package/src/net/ResponseHandler.ts +0 -30
  67. package/src/net/ShareableBytes.ts +0 -125
  68. package/src/net/internal/AsyncResourceExecutor.ts +0 -464
  69. package/src/net/internal/AsyncSocketPromise.ts +0 -37
  70. package/src/net/internal/channel/ChannelHandlerAdapter.ts +0 -99
  71. package/src/net/internal/channel/types.ts +0 -188
  72. package/src/utils/bigint.ts +0 -23
  73. package/src/utils/buffer.ts +0 -434
  74. package/src/utils/clock.ts +0 -148
  75. package/src/utils/collections.ts +0 -283
  76. package/src/utils/crc.ts +0 -39
  77. package/src/utils/internal/IpAddressUtil.ts +0 -161
  78. package/src/utils/memory/BufferPools.ts +0 -40
  79. package/src/utils/network.ts +0 -130
  80. package/src/utils/promise.ts +0 -38
  81. package/src/utils/uuid.ts +0 -5
  82. package/src/utils/vint.ts +0 -238
  83. package/src/version/MemberVersion.ts +0 -42
  84. package/src/version/Version.ts +0 -12
@@ -1,148 +0,0 @@
1
- import {convert} from '../config/Duration.ts';
2
-
3
- export interface Clock {
4
- now(): bigint
5
- error(): number
6
- readonly translate: ClockTranslation
7
- isBefore(instantNs: bigint, nowNs?: bigint): boolean
8
- }
9
-
10
-
11
- export const globalClock: {epochTime: () => bigint, nanoTime: () => bigint} = new (class {
12
- epochTime(): bigint {
13
- return BigInt(Date.now());
14
- }
15
- nanoTime(): bigint {
16
- return process.hrtime.bigint();
17
- }
18
-
19
- });
20
-
21
- export interface ClockTranslation {
22
- fromMillisSinceEpoch(currentTimeMillis: bigint): bigint
23
- toMillisSinceEpoch(nanoTime: bigint): bigint
24
- readonly error: number
25
- }
26
-
27
- class AlmostSameTime implements ClockTranslation {
28
- private readonly millisSinceEpoch: bigint;
29
- private readonly monotonicNanos: bigint;
30
- readonly error: number;
31
- constructor(millisSinceEpoch: bigint | number, monotonicNanos: bigint | number, error: number) {
32
- this.millisSinceEpoch = BigInt(millisSinceEpoch);
33
- this.monotonicNanos = BigInt(monotonicNanos);
34
- this.error = error;
35
- }
36
- fromMillisSinceEpoch(currentTimeMillis: bigint): bigint {
37
- return this.monotonicNanos + convert('nanoseconds', currentTimeMillis - this.millisSinceEpoch, 'milliseconds');
38
- }
39
-
40
- toMillisSinceEpoch(nanoTime: bigint): bigint {
41
- return this.millisSinceEpoch + convert('milliseconds', nanoTime - this.monotonicNanos, 'nanoseconds');
42
- }
43
- }
44
- export class HrTimeClock implements Clock {
45
- translate: ClockTranslation = new AlmostSameTime(Date.now(), this.now(), Number.MAX_SAFE_INTEGER);
46
- now(): bigint {
47
- return process.hrtime.bigint();
48
- }
49
-
50
- error(): number {
51
- return 1;
52
- }
53
-
54
- isBefore(instantNs: bigint, nowNs?: bigint): boolean {
55
- return instantNs < (nowNs ?? this.now());
56
- }
57
- }
58
-
59
- export class PerformanceClock implements Clock {
60
- translate: ClockTranslation = new AlmostSameTime(Date.now(), this.now(), Number.MAX_SAFE_INTEGER);
61
- // performance.now() returns a double representing milliseconds.microsenconds
62
- now(): bigint {
63
- return BigInt(Math.trunc(globalThis.performance.now() * 1e3) * 1e3);
64
- }
65
- error() {
66
- return 1e3;
67
- }
68
- isBefore(instantNs: bigint, nowNs?: bigint): boolean {
69
- return (instantNs ?? this.now()) < instantNs;
70
- }
71
- }
72
-
73
- function approx(clock: Clock): SampledClock {
74
- return new SampledClock(clock);
75
- }
76
-
77
- class SampledClock implements Clock {
78
- private almostNowIntervalId: ReturnType<typeof setInterval> = undefined;
79
- private almostNow: bigint = 0n;
80
- private readonly updateIntervalMs: number;
81
- private readonly errorNs: bigint;
82
- private readonly precise: Clock;
83
-
84
- constructor(precise: Clock, updateIntervalMs?: number) {
85
- this.precise = precise;
86
- this.updateIntervalMs = Math.max(1, updateIntervalMs ?? 2);
87
- this.errorNs = BigInt(this.updateIntervalMs * 1e6);
88
- this.resumeSampling();
89
- }
90
-
91
- now(): bigint {
92
- return this.almostNow;
93
- }
94
-
95
- error(): number {
96
- return Number(this.errorNs);
97
- }
98
-
99
- get translate(): ClockTranslation {
100
- return this.precise.translate;
101
- }
102
-
103
- isBefore(instantNs: bigint, nowNs?: bigint): boolean {
104
- return ((nowNs ?? this.almostNow) - this.errorNs) < instantNs;
105
- }
106
-
107
- pauseSampling() {
108
- let intervalId = this.almostNowIntervalId;
109
- if (intervalId === undefined) {
110
- return;
111
- }
112
- this.almostNowIntervalId = undefined;
113
- clearInterval(intervalId);
114
- }
115
-
116
- resumeSampling() {
117
- if (this.almostNowIntervalId) {
118
- throw new Error("already sampling");
119
- }
120
- this.almostNow = this.precise.now();
121
- this.almostNowIntervalId = setInterval(() => {
122
- if (this.almostNowIntervalId !== undefined) {
123
- this.almostNow = this.precise.now();
124
- }
125
- }, this.updateIntervalMs);
126
- }
127
-
128
- public refreshNow(): void {
129
- this.pauseSampling();
130
- this.resumeSampling();
131
- }
132
- }
133
-
134
- export const preciseClock = new HrTimeClock();
135
- let _approximateClock: SampledClock;
136
- export const approximateClock: () => Clock = () => {
137
- if (_approximateClock === undefined) {
138
- _approximateClock = approx(preciseClock);
139
- }
140
- return _approximateClock;
141
- }
142
-
143
- export function cleanUp() {
144
- if (_approximateClock !== undefined) {
145
- _approximateClock.pauseSampling();
146
- _approximateClock = undefined;
147
- }
148
- }
@@ -1,283 +0,0 @@
1
- export interface KeySerializer<T> {
2
- serialize(a: Record<string, unknown>): T
3
- }
4
-
5
- const defaultKeySerializer: KeySerializer<string> = {
6
- serialize(o: Record<string, unknown>): string {
7
- const order = o === undefined ? [] : Object.keys(o).sort((a, b) => a.localeCompare(b));
8
- return JSON.stringify(o, order);
9
- }
10
- }
11
-
12
- export class ObjectSet<T extends Record<string, unknown>> implements Set<T> {
13
- private readonly map: Map<unknown, T> = new Map<unknown, T>();
14
- private readonly serializer: KeySerializer<unknown> = defaultKeySerializer;
15
-
16
- constructor(values?: readonly T[] | null, serializer: KeySerializer<unknown> = defaultKeySerializer) {
17
- this.serializer = serializer;
18
- this.map = new Map<unknown, T>((values ?? new Array<T>()).map((value) => {
19
- const key: unknown = serializer.serialize(value);
20
- return [key, value];
21
- }));
22
- }
23
-
24
- [Symbol.iterator](): SetIterator<T> {
25
- return this.values();
26
- }
27
-
28
- [Symbol.toStringTag]: string = 'ObjectSet';
29
-
30
- *entries(): SetIterator<[T, T]> {
31
- for (const value of this.values()) {
32
- yield [value, value];
33
- }
34
- }
35
-
36
- keys = this.values;
37
-
38
- values(): SetIterator<T> {
39
- return this.map.values();
40
- }
41
-
42
- add(value: T): this {
43
- const key = this.serializer.serialize(value);
44
- this.map.set(key, value);
45
- return this;
46
- }
47
-
48
- clear() {
49
- this.map.clear();
50
- }
51
-
52
- delete(value: T): boolean {
53
- const key = this.serializer.serialize(value);
54
- return this.map.delete(key);
55
- }
56
-
57
- forEach(callbackfn: (value: T, key: T, set: Set<T>) => void, thisArg?: any) {
58
- for (const value of this.map.values()) {
59
- callbackfn.call(thisArg, value, value, this);
60
- }
61
- }
62
-
63
- has(value: T): boolean {
64
- const key = this.serializer.serialize(value);
65
- return this.map.has(key);
66
- }
67
-
68
- get size(): number {
69
- return this.map.size;
70
- }
71
- }
72
-
73
- export class ObjectMap<K extends Record<string, unknown>, V> implements Map<K, V> {
74
- private readonly map: Map<unknown, [K, V]> = new Map<unknown, [K, V]>();
75
-
76
- private readonly serializer: KeySerializer<unknown> = defaultKeySerializer;
77
-
78
- constructor(entries?:[[K, V]],
79
- serializer: KeySerializer<unknown> = defaultKeySerializer) {
80
- this.serializer = serializer;
81
- this.map = new Map<unknown, [K, V]>((entries ?? new Array<[K, V]>()).map(([key, value]) => {
82
- const k: unknown = serializer.serialize(key);
83
- return [k, [key, value]];
84
- }));
85
- }
86
-
87
- [Symbol.iterator](): MapIterator<[K, V]> {
88
- return this.entries();
89
- }
90
-
91
- [Symbol.toStringTag]: string = 'ObjectMap';
92
-
93
-
94
- clear() {
95
- this.map.clear();
96
- }
97
-
98
- delete(key: K): boolean {
99
- return this.map.delete(this.serializer.serialize(key));
100
- }
101
-
102
- *entries(): MapIterator<[K, V]> {
103
- for (const [, [key, value]] of this.map.entries()) {
104
- yield [key, value];
105
- }
106
- }
107
-
108
- *keys(): MapIterator<K> {
109
- for (const [key,] of this.map.values()) {
110
- yield key;
111
- }
112
- }
113
-
114
- *values(): MapIterator<V> {
115
- for (const [, value] of this.map.values()) {
116
- yield value;
117
- }
118
- }
119
-
120
- forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: any) {
121
- for (const [,[key, value]] of this.map) {
122
- callbackfn.call(thisArg, value, key, this);
123
- }
124
- }
125
-
126
- get(key: K): V | undefined {
127
- const result = this.map.get(this.serializer.serialize(key));
128
- if (result) {
129
- const [, value] = result;
130
- return value;
131
- }
132
- }
133
-
134
- has(key: K): boolean {
135
- return this.map.has(this.serializer.serialize(key));
136
- }
137
-
138
- set(key: K, value: V): this {
139
- this.map.set(this.serializer.serialize(key), [key, value]);
140
- return this;
141
- }
142
-
143
- get size(): number {
144
- return this.map.size;
145
- }
146
- }
147
-
148
- export type Comparator<T> = (e1: T, e2: T) => -1 | 0 | 1;
149
-
150
- export function composeComparators<T>(...comparators: Comparator<T>[]): Comparator<T> {
151
- return (e1: T, e2: T) => {
152
- for (const comparator of comparators) {
153
- const result = comparator(e1, e2);
154
- if (result !== 0) {
155
- return result;
156
- }
157
- }
158
- return 0;
159
- };
160
- }
161
-
162
- export function compareArrays<T>(a1: ArrayLike<T>, offset1: number, length1: number,
163
- a2: ArrayLike<T>, offset2: number, length2: number,
164
- comparator: Comparator<T>): ReturnType<Comparator<ArrayLike<T>>> {
165
- if (a1 == a2 && offset1 == offset2 && length1 == length2)
166
- return 0;
167
-
168
- const end1 = offset1 + length1;
169
- const end2 = offset2 + length2;
170
- for (let i = offset1, j = offset2; i < end1 && j < end2; i++, j++)
171
- {
172
- const result = comparator(a1[i], a2[j]);
173
- if (result !== 0) {
174
- return result;
175
- }
176
- }
177
- return length1 < length2 ? -1 : length1 === length2 ? 0 : 1;
178
- }
179
-
180
- export class PriorityQueue<T> {
181
- readonly comparator: Comparator<T>;
182
- private _count: number = 0;
183
- private _items: Array<T>;
184
-
185
- constructor(comparator: Comparator<T>, initialCapacity: number = 11) {
186
- this._items = new Array<T>(initialCapacity);
187
- this.comparator = comparator;
188
- }
189
-
190
- get size(): number {
191
- return this._count;
192
- }
193
-
194
- dequeue(): T | undefined {
195
- const result = this.peek();
196
- if (result === undefined) {
197
- return undefined;
198
- }
199
- const newCount = --this._count;
200
- const lastItem = this._items[newCount];
201
- this._items[newCount] = undefined as unknown as T;
202
- if (newCount > 0) {
203
- this.trickleDown(0, lastItem);
204
- }
205
- return result;
206
- }
207
-
208
- peek(): T | undefined {
209
- if (this._count === 0) {
210
- return undefined;
211
- }
212
- return this._items[0];
213
- }
214
-
215
- enqueue(item: T): void {
216
- if (item === undefined) {
217
- throw new Error('element is undefined');
218
- }
219
-
220
- const oldCount = this._count;
221
- if (oldCount === this._items.length) {
222
- this.growHeap();
223
- }
224
- this._count = oldCount + 1;
225
- this.bubbleUp(oldCount, item);
226
- }
227
-
228
- remove(item: T): boolean {
229
- const index = this._items.indexOf(item);
230
- if (index === -1) {
231
- return false;
232
- }
233
- const newCount = --this._count;
234
- if (index === newCount) {
235
- this._items[index] = undefined as unknown as T;
236
- }
237
- else {
238
- const lastItem = this._items[newCount];
239
- this._items[newCount] = undefined as unknown as T;
240
- this.trickleDown(index, lastItem);
241
- if (this._items[index] === lastItem) {
242
- this.bubbleUp(index, lastItem);
243
- }
244
- }
245
- return true;
246
- }
247
-
248
- private bubbleUp(index: number, item: T): void {
249
- while (index > 0) {
250
- const parentIndex = (index - 1) >> 1;
251
- const parentItem = this._items[parentIndex];
252
- if (this.comparator(item, parentItem) >= 0) {
253
- break;
254
- }
255
- this._items[index] = parentItem;
256
- index = parentIndex;
257
- }
258
- this._items[index] = item;
259
- }
260
-
261
- private trickleDown(index: number, item: T): void {
262
- const middleIndex = this._count >> 1;
263
- while (index < middleIndex) {
264
- let childIndex = (index << 1) + 1;
265
- let childItem = this._items[childIndex];
266
- const rightChildIndex = childIndex + 1;
267
- if (rightChildIndex < this._count && this.comparator(childItem, this._items[rightChildIndex]) > 0) {
268
- childIndex = rightChildIndex;
269
- childItem = this._items[rightChildIndex];
270
- }
271
- if (this.comparator(item, childItem) <= 0) {
272
- break;
273
- }
274
- this._items[index] = childItem;
275
- index = childIndex;
276
- }
277
- this._items[index] = item;
278
- }
279
-
280
- private growHeap() {
281
- // do nothing for now
282
- }
283
- }
package/src/utils/crc.ts DELETED
@@ -1,39 +0,0 @@
1
- import {crc32} from 'node:zlib'; // requires Node.js >=22.2 || >=20.15
2
- import type {ByteBuffer} from "./buffer";
3
-
4
-
5
- const CRC32_INIT = crc32(new Uint8Array([0xFA,0x2D, 0x55, 0xCA]));
6
-
7
- export function computeCrc32(buffer: ByteBuffer, start: number, end: number): number {
8
- const savePosition = buffer.position;
9
- const saveLimit = buffer.limit;
10
- buffer.limit = end;
11
- buffer.position = start;
12
-
13
- const data = new Uint8Array(end - start);
14
- buffer.getUint8Array(data);
15
- const crc = crc32(data, CRC32_INIT);
16
-
17
- buffer.limit = saveLimit;
18
- buffer.position = savePosition;
19
-
20
- return 0xffffffff & crc;
21
- }
22
-
23
- const CRC24_INIT = 0x875060;
24
- const CRC24_POLY = 0x1974F0B;
25
-
26
- export function crc24(bytes: bigint, length: number): number {
27
- let crc: number = CRC24_INIT;
28
- while (length-- > 0) {
29
- crc ^= Number((bytes & 0xffn) << 16n); // no sign will be lost
30
- bytes >>= 8n;
31
- for (let i = 0; i < 8; i++) {
32
- crc <<= 1;
33
- if ((crc & 0x1000000) !== 0) {
34
- crc ^= CRC24_POLY;
35
- }
36
- }
37
- }
38
- return crc;
39
- }
@@ -1,161 +0,0 @@
1
- const DOT = '.'.charCodeAt(0);
2
- const INET_ADDRESS_V4_SIZE = 4;
3
- const INET_ADDRESS_V6_SIZE = 16;
4
- const BYTE_SIZE = 2; // 8 bits in hex
5
- const COLON = ':'.charCodeAt(0);
6
-
7
- export function textToNumericFormatV4(address: string): Uint8Array {
8
- const result = new Uint8Array(4);
9
- const len = address.length;
10
- if (len == 0 || len > 15) {
11
- return;
12
- }
13
-
14
- let currentValue = 0;
15
- let currentByte = 0;
16
- let newByte = true;
17
- for (let i = 0; i < len; i++) {
18
- const ch = address.charCodeAt(i);
19
- if (ch === DOT) {
20
- if (newByte || currentValue < 0 || currentValue > 0xff || currentByte > 3) {
21
- return;
22
- }
23
- result[currentByte++] = currentValue & 0xff;
24
- currentValue = 0;
25
- newByte = true;
26
- } else {
27
- const digit = ch - 48;
28
- if (digit < 0) {
29
- return;
30
- }
31
- currentValue *= 10;
32
- currentValue += digit;
33
- newByte = false;
34
- }
35
- }
36
- if (newByte || currentValue < 0 || currentValue >= (1 << ((4 - currentByte) * 8))) {
37
- return;
38
- }
39
-
40
- switch (currentByte) {
41
- case 0:
42
- result[0] = (currentValue >> 24) & 0xff;
43
- //fall through
44
- case 1:
45
- result[1] = (currentValue >> 16) & 0xff;
46
- //fall through
47
- case 2:
48
- result[2] = (currentValue >> 8) & 0xff;
49
- //fall through
50
- case 3:
51
- result[3] = (currentValue >> 0) & 0xff;
52
- }
53
- return result;
54
- }
55
-
56
- export function textToNumericFormatV6(address: string): Uint8Array {
57
- if (address.length < 2) {
58
- return;
59
- }
60
-
61
- // let colonp: number;
62
- // let char: number;
63
- // let saw_xdigit: boolean;
64
- // let val: number;
65
- // const dst = new Uint8Array(INET_ADDRESS_V6_SIZE);
66
- //
67
- // const srcb_length = address.length;
68
- // const pc = src.indexOf('%');
69
- // if (pc === srcb_length -1) {
70
- // return;
71
- // }
72
- //
73
- // colonp = -1;
74
- //
75
- // let i = 0, j = 0;
76
- // /* Leading :: requires some special handling. */
77
- // if (address.charAt(i) === ':')
78
- // if (address.charAt(++i) !== ':')
79
- // return;
80
- // curtok = i;
81
- // saw_xdigit = false;
82
- // val = 0;
83
- // while (i < srcb_length) {
84
- // const ch = address.charCodeAt(i++);
85
- // const chval = ch - 48;
86
- // if (chval !== -1) {
87
- // val <<= 4;
88
- // val |= chval;
89
- // if (val > 0xffff)
90
- // return;
91
- // saw_xdigit = true;
92
- // continue;
93
- // }
94
- // if (ch == ':') {
95
- // curtok = i;
96
- // if (!saw_xdigit) {
97
- // if (colonp != -1)
98
- // return null;
99
- // colonp = j;
100
- // continue;
101
- // } else if (i == srcb_length) {
102
- // return null;
103
- // }
104
- // if (j + INT16SZ > INADDR16SZ)
105
- // return null;
106
- // dst[j++] = (byte) ((val >> 8) & 0xff);
107
- // dst[j++] = (byte) (val & 0xff);
108
- // saw_xdigit = false;
109
- // val = 0;
110
- // continue;
111
- // }
112
- // if (ch == '.' && ((j + BYTE_SIZE) <= INET_ADDRESS_V6_SIZE)) {
113
- // const ia4 = address.substring(curtok, srcb_length);
114
- // /* check this IPv4 address has 3 dots, ie. A.B.C.D */
115
- // let dot_count = 0, index=0;
116
- // while ((index = ia4.indexOf ('.', index)) != -1) {
117
- // dot_count ++;
118
- // index ++;
119
- // }
120
- // if (dot_count != 3) {
121
- // return null;
122
- // }
123
- // const v4addr = textToNumericFormatV4(ia4);
124
- // if (v4addr == null) {
125
- // return null;
126
- // }
127
- // for (let k = 0; k < INET_ADDRESS_V4_SIZE; k++) {
128
- // dst[j++] = v4addr[k];
129
- // }
130
- // saw_xdigit = false;
131
- // break; /* '\0' was seen by inet_pton4(). */
132
- // }
133
- // return null;
134
- // }
135
- // if (saw_xdigit) {
136
- // if (j + INT16SZ > INADDR16SZ)
137
- // return null;
138
- // dst[j++] = (byte) ((val >> 8) & 0xff);
139
- // dst[j++] = (byte) (val & 0xff);
140
- // }
141
- //
142
- // if (colonp != -1) {
143
- // const n = j - colonp;
144
- //
145
- // if (j == INADDR16SZ)
146
- // return null;
147
- // for (i = 1; i <= n; i++) {
148
- // dst[INADDR16SZ - i] = dst[colonp + n - i];
149
- // dst[colonp + n - i] = 0;
150
- // }
151
- // j = INADDR16SZ;
152
- // }
153
- // if (j != INADDR16SZ)
154
- // return null;
155
- // const newdst = convertFromIPv4MappedAddress(dst);
156
- // if (newdst != null) {
157
- // return newdst;
158
- // } else {
159
- // return dst;
160
- // }
161
- }
@@ -1,40 +0,0 @@
1
- import {allocate, type ByteBuffer} from '../buffer.ts';
2
-
3
- class BufferPool {
4
-
5
- protected readonly name: string;
6
- private readonly memoryUsageThreshold: number;
7
- private overflowMemoryUsage: number = 0;
8
- private readonly recyclePartially: boolean;
9
-
10
- constructor(name: string, memoryUsageThreshold: number, recyclePartially: boolean = false) {
11
- this.name = name;
12
- this.memoryUsageThreshold = memoryUsageThreshold;
13
- this.recyclePartially = recyclePartially;
14
- }
15
-
16
- private allocateBuf(size: number): ByteBuffer {
17
- this.updateOverflowMemoryUsage(size);
18
- return allocate(size);
19
- }
20
-
21
- public getAtLeast(size: number): ByteBuffer {
22
- return this.allocateBuf(size);
23
- }
24
-
25
- public put(buffer: ByteBuffer) {
26
- this.updateOverflowMemoryUsage(-buffer.capacity);
27
- }
28
-
29
- private updateOverflowMemoryUsage(size: number) {
30
- this.overflowMemoryUsage += size;
31
- }
32
- }
33
-
34
- const NETWORKING_POOL = new BufferPool("networking", 1024 * 1024 * 10); // 10 MB
35
-
36
- export type {BufferPool};
37
-
38
- export function forNetworking(): BufferPool {
39
- return NETWORKING_POOL;
40
- }