@livestore/webmesh 0.3.0-dev.14 → 0.3.0-dev.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livestore/webmesh",
3
- "version": "0.3.0-dev.14",
3
+ "version": "0.3.0-dev.16",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -16,8 +16,8 @@
16
16
  "types": "./dist/mod.d.ts",
17
17
  "dependencies": {
18
18
  "ws": "8.18.0",
19
- "@livestore/common": "0.3.0-dev.14",
20
- "@livestore/utils": "0.3.0-dev.14"
19
+ "@livestore/utils": "0.3.0-dev.16",
20
+ "@livestore/common": "0.3.0-dev.16"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/ws": "^8.5.12",
@@ -1,9 +0,0 @@
1
- import { Effect, Scope, WebChannel } from '@livestore/utils/effect';
2
- import type { MakeMessageChannelArgs } from './message-channel-internal.js';
3
- /**
4
- * Behaviour:
5
- * - Waits until there is an initial connection
6
- * - Automatically reconnects on disconnect
7
- */
8
- export declare const makeMessageChannel: ({ schema, newConnectionAvailablePubSub, channelName, checkTransferableConnections, nodeName, incomingPacketsQueue, target, sendPacket, }: MakeMessageChannelArgs) => Effect.Effect<WebChannel.WebChannel<any, any, never>, never, Scope.Scope>;
9
- //# sourceMappingURL=message-channel%20copy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message-channel copy.d.ts","sourceRoot":"","sources":["../../src/channel/message-channel copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAKN,KAAK,EAGL,UAAU,EACX,MAAM,yBAAyB,CAAA;AAIhC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAE3E;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,6IAS5B,sBAAsB,8EAwLtB,CAAA"}
@@ -1,137 +0,0 @@
1
- import { Cause, Deferred, Effect, Either, Exit, Queue, Schema, Scope, Stream, TQueue, WebChannel, } from '@livestore/utils/effect';
2
- import { nanoid } from '@livestore/utils/nanoid';
3
- import { WebmeshSchema } from '../mod.js';
4
- import { makeMessageChannelInternal } from './message-channel-internal.js';
5
- /**
6
- * Behaviour:
7
- * - Waits until there is an initial connection
8
- * - Automatically reconnects on disconnect
9
- */
10
- export const makeMessageChannel = ({ schema, newConnectionAvailablePubSub, channelName, checkTransferableConnections, nodeName, incomingPacketsQueue, target, sendPacket, }) => Effect.scopeWithCloseable((scope) => Effect.gen(function* () {
11
- // const internalChannelSref = yield* SubscriptionRef.make<WebChannel.WebChannel<any, any> | false>(false)
12
- // const state: 'connecting' | 'connected' = 'connecting'
13
- const sourceId = nanoid();
14
- const listenQueue = yield* Queue.unbounded();
15
- const sendQueue = yield* TQueue.unbounded();
16
- const initialConnectionDeferred = yield* Deferred.make();
17
- let connectionCounter = 0;
18
- // #region reconnect-loop
19
- yield* Effect.gen(function* () {
20
- const resultDeferred = yield* Deferred.make();
21
- while (true) {
22
- connectionCounter++;
23
- const channelVersion = connectionCounter;
24
- yield* Effect.spanEvent(`Connecting#${channelVersion}`);
25
- const makeMessageChannelScope = yield* Scope.make();
26
- // Attach the new scope to the parent scope
27
- yield* Effect.addFinalizer((ex) => Scope.close(makeMessageChannelScope, ex));
28
- /**
29
- * Expected concurrency behaviour:
30
- * - We're concurrently running the connection setup and the waitForNewConnectionFiber
31
- * - Happy path:
32
- * - The connection setup succeeds and we can interrupt the waitForNewConnectionFiber
33
- * - Tricky paths:
34
- * - While a connection is still being setup, we want to re-try when there is a new connection
35
- * - If the connection setup returns a `MessageChannelResponseNoTransferables` error,
36
- * we want to wait for a new connection and then re-try
37
- * - Further notes:
38
- * - If the parent scope closes, we want to also interrupt both the connection setup and the waitForNewConnectionFiber
39
- * - We're creating a separate scope for each connection attempt, which
40
- * - we'll use to fork the message channel in which allows us to interrupt it later
41
- * - We need to make sure that "interruption" isn't "bubbling out"
42
- */
43
- const waitForNewConnectionFiber = yield* Stream.fromPubSub(newConnectionAvailablePubSub).pipe(Stream.tap((connectionName) => Effect.spanEvent(`new-conn:${connectionName}`)), Stream.take(1), Stream.runDrain, Effect.as('new-connection'), Effect.fork);
44
- const makeChannel = makeMessageChannelInternal({
45
- nodeName,
46
- sourceId,
47
- incomingPacketsQueue,
48
- target,
49
- checkTransferableConnections,
50
- channelName,
51
- schema,
52
- channelVersion,
53
- newConnectionAvailablePubSub,
54
- sendPacket,
55
- scope: makeMessageChannelScope,
56
- }).pipe(Scope.extend(makeMessageChannelScope), Effect.forkIn(makeMessageChannelScope));
57
- const res = yield* Effect.raceFirst(makeChannel, waitForNewConnectionFiber.pipe(Effect.disconnect));
58
- if (res === 'new-connection') {
59
- yield* Scope.close(makeMessageChannelScope, Exit.fail('new-connection'));
60
- // We'll try again
61
- }
62
- else {
63
- const result = yield* res.pipe(Effect.exit);
64
- if (result._tag === 'Failure') {
65
- yield* Scope.close(makeMessageChannelScope, result);
66
- if (Cause.isFailType(result.cause) &&
67
- Schema.is(WebmeshSchema.MessageChannelResponseNoTransferables)(result.cause.error)) {
68
- yield* waitForNewConnectionFiber.pipe(Effect.exit);
69
- }
70
- // yield* Effect.log('result.fail', { nodeName, channelVersion }, Cause.pretty(result.cause))
71
- }
72
- else {
73
- const channel = result.value;
74
- yield* Deferred.succeed(resultDeferred, { channel, makeMessageChannelScope, channelVersion });
75
- break;
76
- }
77
- }
78
- }
79
- // Now we wait until the first channel is established
80
- const { channel, makeMessageChannelScope, channelVersion } = yield* resultDeferred;
81
- yield* Effect.spanEvent(`Connected#${channelVersion}`);
82
- yield* Deferred.succeed(initialConnectionDeferred, void 0);
83
- // We'll now forward all incoming messages to the listen queue
84
- yield* channel.listen.pipe(Stream.flatten(),
85
- // Stream.tap((msg) => Effect.log(`${target}→${channelName}→${nodeName}:message:${msg.message}`)),
86
- Stream.tapChunk((chunk) => Queue.offerAll(listenQueue, chunk)), Stream.runDrain, Effect.tapCauseLogPretty, Effect.forkIn(makeMessageChannelScope));
87
- yield* Effect.gen(function* () {
88
- while (true) {
89
- const [msg, deferred] = yield* TQueue.peek(sendQueue);
90
- // NOTE we don't need an explicit retry flow here since in case of the channel being closed,
91
- // the send will never succeed. Meanwhile the send-loop fiber will be interrupted and
92
- // given we only peeked at the queue, the message to send is still there.
93
- yield* channel.send(msg);
94
- yield* Deferred.succeed(deferred, void 0);
95
- yield* TQueue.take(sendQueue); // Remove the message from the queue
96
- }
97
- }).pipe(Effect.forkIn(makeMessageChannelScope));
98
- // Wait until the channel is closed and then try to reconnect
99
- yield* channel.closedDeferred;
100
- yield* Scope.close(makeMessageChannelScope, Exit.succeed('channel-closed'));
101
- yield* Effect.spanEvent(`Disconnected#${channelVersion}`);
102
- }).pipe(Effect.scoped, // Additionally scoping here to clean up finalizers after each loop run
103
- Effect.forever,
104
- // Effect.withSpan('makeMessageChannelManaged:connect-loop'),
105
- Effect.tapCauseLogPretty, Effect.forkScoped);
106
- // #endregion reconnect-loop
107
- const debugInfo = {
108
- pendingSends: 0,
109
- totalSends: 0,
110
- connectCounter: 1,
111
- };
112
- const parentSpan = yield* Effect.currentSpan.pipe(Effect.orDie);
113
- const send = (message) => Effect.gen(function* () {
114
- // const sendFiberHandle = yield* FiberHandle.make<void, never>()
115
- const sentDeferred = yield* Deferred.make();
116
- debugInfo.pendingSends++;
117
- debugInfo.totalSends++;
118
- yield* TQueue.offer(sendQueue, [message, sentDeferred]);
119
- yield* sentDeferred;
120
- debugInfo.pendingSends--;
121
- }).pipe(Effect.scoped, Effect.withParentSpan(parentSpan));
122
- const listen = Stream.fromQueue(listenQueue, { maxChunkSize: 1 }).pipe(Stream.map(Either.right));
123
- const closedDeferred = yield* Deferred.make().pipe(Effect.acquireRelease(Deferred.done(Exit.void)));
124
- yield* initialConnectionDeferred;
125
- const webChannel = {
126
- [WebChannel.WebChannelSymbol]: WebChannel.WebChannelSymbol,
127
- send,
128
- listen,
129
- closedDeferred,
130
- supportsTransferables: true,
131
- schema,
132
- debugInfo,
133
- shutdown: Scope.close(scope, Exit.succeed('shutdown')),
134
- };
135
- return webChannel;
136
- }));
137
- //# sourceMappingURL=message-channel%20copy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message-channel copy.js","sourceRoot":"","sources":["../../src/channel/message-channel copy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,EACJ,KAAK,EACL,MAAM,EACN,KAAK,EACL,MAAM,EACN,MAAM,EACN,UAAU,GACX,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAA;AAC1E;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EACjC,MAAM,EACN,4BAA4B,EAC5B,WAAW,EACX,4BAA4B,EAC5B,QAAQ,EACR,oBAAoB,EACpB,MAAM,EACN,UAAU,GACa,EAAE,EAAE,CAC3B,MAAM,CAAC,kBAAkB,CAAC,CAAC,KAAK,EAAE,EAAE,CAClC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,0GAA0G;IAE1G,yDAAyD;IACzD,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAA;IAEzB,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,SAAS,EAAO,CAAA;IACjD,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,SAAS,EAAiD,CAAA;IAE1F,MAAM,yBAAyB,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAQ,CAAA;IAE9D,IAAI,iBAAiB,GAAG,CAAC,CAAA;IAEzB,yBAAyB;IACzB,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACzB,MAAM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I,EAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAEzG,KAAK,CAAC,CAAC,yBAAyB,CAAA;IAEhC,MAAM,UAAU,GAAG;QACjB,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,UAAU,CAAC,gBAAgB;QAC1D,IAAI;QACJ,MAAM;QACN,cAAc;QACd,qBAAqB,EAAE,IAAI;QAC3B,MAAM;QACN,SAAS;QACT,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;KACb,CAAA;IAE3C,OAAO,UAA6C,CAAA;AACtD,CAAC,CAAC,CACH,CAAA"}
@@ -1,42 +0,0 @@
1
- import type { PubSub } from '@livestore/utils/effect';
2
- import { Effect, Queue, Scope, WebChannel } from '@livestore/utils/effect';
3
- import { type ChannelName, type MeshNodeName, type MessageQueueItem } from '../common.js';
4
- import * as MeshSchema from '../mesh-schema.js';
5
- export interface MakeMessageChannelArgs {
6
- nodeName: MeshNodeName;
7
- /** Queue of incoming messages for this channel */
8
- incomingPacketsQueue: Queue.Queue<MessageQueueItem>;
9
- newConnectionAvailablePubSub: PubSub.PubSub<MeshNodeName>;
10
- channelName: ChannelName;
11
- target: MeshNodeName;
12
- sendPacket: (packet: typeof MeshSchema.MessageChannelPacket.Type) => Effect.Effect<void>;
13
- checkTransferableConnections: (packet: typeof MeshSchema.MessageChannelPacket.Type) => typeof MeshSchema.MessageChannelResponseNoTransferables.Type | undefined;
14
- schema: WebChannel.OutputSchema<any, any, any, any>;
15
- }
16
- /**
17
- * `makeChannel` needs to be called on both sides to establish a connection ("symmetrically")
18
- *
19
- * Implementation notes:
20
- * - There is an internal web channel and a wrapping "proxy channel"
21
- * - Reasons for outside proxy channel:
22
- * - Re-try to establish initial channel when there are new connections available
23
- * - Re-connect if the connection is lost
24
- * - Create a separate layer as "channel wrapper" which is responsible for:
25
- * - initial connection based on new connection available
26
- * - re-connect on disconnect
27
- * - heartbeat
28
- * - ...
29
- *
30
- * Channel connection init process:
31
- * - Both sides send a `MessageChannelRequest` packet which includes a channel version
32
- * - The other side responds with a `MessageChannelResponseSuccess` packet which includes
33
- * the max version of both sides as the agreed upon version for the channel
34
- * - The channel starts listening on the port of the side with the highest version (or with the "larger" name as tie-breaker)
35
- *
36
- */
37
- export declare const makeMessageChannelInternal: ({ nodeName, incomingPacketsQueue, target, checkTransferableConnections, channelName, schema: schema_, sendPacket, channelVersion, scope, sourceId, }: MakeMessageChannelArgs & {
38
- channelVersion: number;
39
- scope: Scope.CloseableScope;
40
- sourceId: string;
41
- }) => Effect.Effect<WebChannel.WebChannel<any, any>, typeof MeshSchema.MessageChannelResponseNoTransferables.Type, Scope.Scope>;
42
- //# sourceMappingURL=message-channel-internal%20copy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message-channel-internal copy.d.ts","sourceRoot":"","sources":["../../src/channel/message-channel-internal copy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAEL,MAAM,EAIN,KAAK,EAEL,KAAK,EAEL,UAAU,EACX,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,gBAAgB,EAA0B,MAAM,cAAc,CAAA;AACjH,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,YAAY,CAAA;IACtB,kDAAkD;IAClD,oBAAoB,EAAE,KAAK,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;IACnD,4BAA4B,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;IACzD,WAAW,EAAE,WAAW,CAAA;IACxB,MAAM,EAAE,YAAY,CAAA;IACpB,UAAU,EAAE,CAAC,MAAM,EAAE,OAAO,UAAU,CAAC,oBAAoB,CAAC,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACxF,4BAA4B,EAAE,CAC5B,MAAM,EAAE,OAAO,UAAU,CAAC,oBAAoB,CAAC,IAAI,KAChD,OAAO,UAAU,CAAC,qCAAqC,CAAC,IAAI,GAAG,SAAS,CAAA;IAC7E,MAAM,EAAE,UAAU,CAAC,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;CACpD;AAOD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,0BAA0B,yJAWpC,sBAAsB,GAAG;IAC1B,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,EAAE,KAAK,CAAC,cAAc,CAAA;IAC3B,QAAQ,EAAE,MAAM,CAAA;CACjB,KAAG,MAAM,CAAC,MAAM,CACf,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,EAC/B,OAAO,UAAU,CAAC,qCAAqC,CAAC,IAAI,EAC5D,KAAK,CAAC,KAAK,CA0S2D,CAAA"}
@@ -1,239 +0,0 @@
1
- import { casesHandled, shouldNeverHappen } from '@livestore/utils';
2
- import { Deferred, Effect, Exit, OtelTracer, Predicate, Queue, Schema, Scope, Stream, WebChannel, } from '@livestore/utils/effect';
3
- import { packetAsOtelAttributes } from '../common.js';
4
- import * as MeshSchema from '../mesh-schema.js';
5
- const makeDeferredResult = (Deferred.make);
6
- /**
7
- * `makeChannel` needs to be called on both sides to establish a connection ("symmetrically")
8
- *
9
- * Implementation notes:
10
- * - There is an internal web channel and a wrapping "proxy channel"
11
- * - Reasons for outside proxy channel:
12
- * - Re-try to establish initial channel when there are new connections available
13
- * - Re-connect if the connection is lost
14
- * - Create a separate layer as "channel wrapper" which is responsible for:
15
- * - initial connection based on new connection available
16
- * - re-connect on disconnect
17
- * - heartbeat
18
- * - ...
19
- *
20
- * Channel connection init process:
21
- * - Both sides send a `MessageChannelRequest` packet which includes a channel version
22
- * - The other side responds with a `MessageChannelResponseSuccess` packet which includes
23
- * the max version of both sides as the agreed upon version for the channel
24
- * - The channel starts listening on the port of the side with the highest version (or with the "larger" name as tie-breaker)
25
- *
26
- */
27
- export const makeMessageChannelInternal = ({ nodeName, incomingPacketsQueue, target, checkTransferableConnections, channelName, schema: schema_, sendPacket, channelVersion, scope, sourceId, }) => Effect.gen(function* () {
28
- // yield* Effect.addFinalizer((exit) =>
29
- // Effect.spanEvent(`shutdown:${exit._tag === 'Success' ? 'Success' : Cause.pretty(exit.cause)}`),
30
- // )
31
- const deferred = yield* makeDeferredResult();
32
- const span = yield* OtelTracer.currentOtelSpan.pipe(Effect.catchAll(() => Effect.succeed(undefined)));
33
- const schema = {
34
- send: Schema.Union(schema_.send, MeshSchema.MessageChannelPing, MeshSchema.MessageChannelPong),
35
- listen: Schema.Union(schema_.listen, MeshSchema.MessageChannelPing, MeshSchema.MessageChannelPong),
36
- };
37
- const channelStateRef = {
38
- current: { _tag: 'Initial' },
39
- };
40
- const processMessagePacket = ({ packet, respondToSender }) => Effect.gen(function* () {
41
- const channelState = channelStateRef.current;
42
- span?.addEvent(`process:${packet._tag}`, {
43
- channelState: channelState._tag,
44
- packetId: packet.id,
45
- packetReqId: packet.reqId,
46
- packetChannelVersion: Predicate.hasProperty('channelVersion')(packet) ? packet.channelVersion : undefined,
47
- });
48
- yield* Effect.log(`${nodeName}→${channelName}→${target}:process packet ${packet._tag} [${channelVersion}], channel state: ${channelState._tag}`);
49
- if (channelState._tag === 'Initial')
50
- return shouldNeverHappen();
51
- if (packet._tag === 'MessageChannelResponseNoTransferables') {
52
- yield* Deferred.fail(deferred, packet);
53
- return 'close';
54
- }
55
- // If the other side has a higher version, we need to close this channel and
56
- // recreate it with the new version
57
- if (packet.channelVersion > channelVersion) {
58
- span?.addEvent(`incoming packet has higher version (${packet.channelVersion}), closing channel`);
59
- yield* Scope.close(scope, Exit.succeed('higher-version-expected'));
60
- // TODO include expected version in the error so the channel gets recreated with the new version
61
- return 'close';
62
- }
63
- // If this channel has a higher version, we need to signal the other side to close
64
- // and recreate the channel with the new version
65
- if (packet.channelVersion < channelVersion) {
66
- const newPacket = MeshSchema.MessageChannelRequest.make({
67
- source: nodeName,
68
- sourceId,
69
- target,
70
- channelName,
71
- channelVersion,
72
- hops: [],
73
- remainingHops: packet.hops,
74
- reqId: undefined,
75
- });
76
- span?.addEvent(`incoming packet has lower version (${packet.channelVersion}), sending request to reconnect (${newPacket.id})`);
77
- yield* sendPacket(newPacket);
78
- return;
79
- }
80
- // Ignore further incoming packets if the channel is already established
81
- // if (channelState._tag === 'Established') return
82
- if (channelState._tag === 'Established' && packet._tag === 'MessageChannelRequest') {
83
- if (packet.sourceId === channelState.otherSourceId) {
84
- return;
85
- }
86
- else {
87
- span?.addEvent(`force-new-channel`);
88
- yield* Scope.close(scope, Exit.succeed('force-new-channel'));
89
- return 'close';
90
- }
91
- }
92
- switch (packet._tag) {
93
- case 'MessageChannelRequest': {
94
- /*
95
- New impl idea:
96
- - For request that has a lower version, send its own request as a signal
97
- - Determine "winner" in request handler and only the winner is sending a response
98
- - The loser will instead listen for a response on the channel itself
99
-
100
- How to avoid request loops / circuit-breakering
101
- - we need to gurantee that each side has received the request
102
- - each other side needs to know it
103
- - idea: use the request packet id from A as a reference when sending a request back from B to A
104
- - this way A knows that
105
-
106
-
107
- Assumptions:
108
- - each side has sent their request which has to arrive at the other side
109
- */
110
- if (channelState._tag !== 'RequestSent') {
111
- // We can safely ignore further incoming requests as we're already creating a channel
112
- return;
113
- }
114
- if (packet.reqId === channelState.reqPacketId) {
115
- // Circuit-breaker: We've already sent a request so we don't need to send another one
116
- }
117
- else {
118
- const newRequestPacket = MeshSchema.MessageChannelRequest.make({
119
- source: nodeName,
120
- sourceId,
121
- target,
122
- channelName,
123
- channelVersion,
124
- hops: [],
125
- remainingHops: packet.hops,
126
- reqId: packet.id,
127
- });
128
- span?.addEvent(`Re-sending new request (${newRequestPacket.id}) for incoming request (${packet.id})`);
129
- yield* sendPacket(newRequestPacket);
130
- }
131
- const isWinner = nodeName > target;
132
- if (isWinner) {
133
- span?.addEvent(`winner side: creating message channel and sending response`);
134
- const mc = new MessageChannel();
135
- const channel = yield* WebChannel.messagePortChannelWithAck({
136
- port: mc.port1,
137
- schema,
138
- debugId: channelVersion,
139
- }).pipe(Effect.andThen(WebChannel.toOpenChannel));
140
- yield* respondToSender(MeshSchema.MessageChannelResponseSuccess.make({
141
- reqId: packet.id,
142
- target,
143
- source: nodeName,
144
- channelName: packet.channelName,
145
- hops: [],
146
- remainingHops: packet.hops,
147
- port: mc.port2,
148
- channelVersion,
149
- }));
150
- channelStateRef.current = { _tag: 'winner:ResponseSent', channel, otherSourceId: packet.sourceId };
151
- // Now we wait for the other side to respond via the channel
152
- yield* channel.listen.pipe(Stream.flatten(), Stream.filter(Schema.is(MeshSchema.MessageChannelPing)), Stream.take(1), Stream.runDrain);
153
- yield* channel.send(MeshSchema.MessageChannelPong.make({}));
154
- span?.addEvent(`winner side: established`);
155
- channelStateRef.current = { _tag: 'Established', otherSourceId: packet.sourceId };
156
- yield* Deferred.succeed(deferred, channel);
157
- }
158
- else {
159
- span?.addEvent(`loser side: waiting for response`);
160
- // Wait for `MessageChannelResponseSuccess` packet
161
- channelStateRef.current = { _tag: 'loser:WaitingForResponse', otherSourceId: packet.sourceId };
162
- }
163
- break;
164
- }
165
- // Since there can be concurrent MessageChannel responses from both sides,
166
- // we need to decide which side's port we want to use and which side's port we want to ignore.
167
- // This is only relevant in the case where both sides already sent their responses.
168
- // In this case we're using the target name as a "tie breaker" to decide which side's port to use.
169
- // We do this by sorting the target names lexicographically and use the first one as the winner.
170
- case 'MessageChannelResponseSuccess': {
171
- if (channelState._tag !== 'loser:WaitingForResponse') {
172
- return shouldNeverHappen(`Expected to find message channel response from ${target}, but was in ${channelState._tag} state`);
173
- }
174
- const channel = yield* WebChannel.messagePortChannelWithAck({
175
- port: packet.port,
176
- schema,
177
- debugId: channelVersion,
178
- }).pipe(Effect.andThen(WebChannel.toOpenChannel));
179
- const waitForPongFiber = yield* channel.listen.pipe(Stream.flatten(), Stream.filter(Schema.is(MeshSchema.MessageChannelPong)), Stream.take(1), Stream.runDrain, Effect.fork);
180
- yield* channel.send(MeshSchema.MessageChannelPing.make({}));
181
- yield* waitForPongFiber;
182
- span?.addEvent(`loser side: established`);
183
- channelStateRef.current = { _tag: 'Established', otherSourceId: channelState.otherSourceId };
184
- yield* Deferred.succeed(deferred, channel);
185
- return;
186
- }
187
- default: {
188
- return casesHandled(packet);
189
- }
190
- }
191
- }).pipe(Effect.withSpan(`handleMessagePacket:${packet._tag}:${packet.source}→${packet.target}`, {
192
- attributes: packetAsOtelAttributes(packet),
193
- }));
194
- // yield* Stream.fromQueue(queue).pipe(
195
- // Stream.tap(processMessagePacket),
196
- // Stream.runDrain,
197
- // Effect.interruptible,
198
- // Effect.tapCauseLogPretty,
199
- // Effect.forkScoped,
200
- // )
201
- yield* Effect.gen(function* () {
202
- while (true) {
203
- const packet = yield* Queue.take(incomingPacketsQueue);
204
- const res = yield* processMessagePacket(packet);
205
- // We want to give requests another chance to be processed
206
- if (res === 'close') {
207
- return;
208
- }
209
- }
210
- }).pipe(Effect.interruptible, Effect.tapCauseLogPretty, Effect.forkScoped);
211
- const channelState = channelStateRef.current;
212
- if (channelState._tag !== 'Initial') {
213
- return shouldNeverHappen(`Expected channel to be in Initial state, but was in ${channelState._tag} state`);
214
- }
215
- const connectionRequest = Effect.gen(function* () {
216
- const packet = MeshSchema.MessageChannelRequest.make({
217
- source: nodeName,
218
- sourceId,
219
- target,
220
- channelName,
221
- channelVersion,
222
- hops: [],
223
- reqId: undefined,
224
- });
225
- channelStateRef.current = { _tag: 'RequestSent', reqPacketId: packet.id };
226
- // yield* Effect.log(`${nodeName}→${channelName}→${target}:connectionRequest [${channelVersion}]`)
227
- const noTransferableResponse = checkTransferableConnections(packet);
228
- if (noTransferableResponse !== undefined) {
229
- yield* Effect.spanEvent(`No transferable connections found for ${packet.source}→${packet.target}`);
230
- return yield* Effect.fail(noTransferableResponse);
231
- }
232
- yield* sendPacket(packet);
233
- span?.addEvent(`initial connection request sent (${packet.id})`);
234
- });
235
- yield* connectionRequest;
236
- const channel = yield* deferred;
237
- return channel;
238
- }).pipe(Effect.withSpanScoped(`makeMessageChannel:${channelVersion}`));
239
- //# sourceMappingURL=message-channel-internal%20copy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message-channel-internal copy.js","sourceRoot":"","sources":["../../src/channel/message-channel-internal copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAElE,OAAO,EACL,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,UAAU,EACV,SAAS,EACT,KAAK,EACL,MAAM,EACN,KAAK,EACL,MAAM,EACN,UAAU,GACX,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EAA8D,sBAAsB,EAAE,MAAM,cAAc,CAAA;AACjH,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAgB/C,MAAM,kBAAkB,GAAG,CAAA,QAAQ,CAAC,IAGnC,CAAA,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,EACzC,QAAQ,EACR,oBAAoB,EACpB,MAAM,EACN,4BAA4B,EAC5B,WAAW,EACX,MAAM,EAAE,OAAO,EACf,UAAU,EACV,cAAc,EACd,KAAK,EACL,QAAQ,GAKT,EAIC,EAAE,CACF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,uCAAuC;IACvC,oGAAoG;IACpG,IAAI;IAwBJ,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,kBAAkB,EAAE,CAAA;IAE5C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GA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