@netifyjs/protocol 1.0.0-alpha.3 → 1.0.0-beta.1
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 +2 -2
- package/src/codec/index.ts +51 -221
- package/src/dispatch/dispatcher/index.ts +89 -47
- package/src/dispatch/session/index.ts +6 -24
- package/src/index.ts +2 -4
- package/src/photon/balancing/codec/index.ts +27 -53
- package/src/photon/balancing/format/authenticate/request/index.ts +52 -6
- package/src/photon/balancing/format/friends/request/index.ts +21 -5
- package/src/photon/balancing/format/game/create/request/index.ts +45 -8
- package/src/photon/balancing/format/game/debug/request/index.ts +19 -4
- package/src/photon/balancing/format/game/join/request/index.ts +65 -13
- package/src/photon/balancing/format/game/list/request/index.ts +29 -3
- package/src/photon/balancing/format/game/random/request/index.ts +58 -10
- package/src/photon/balancing/format/groups/request/index.ts +19 -3
- package/src/photon/balancing/format/index.ts +7 -0
- package/src/photon/balancing/format/leave/request/index.ts +19 -3
- package/src/photon/balancing/format/lobby/join/request/index.ts +23 -3
- package/src/photon/balancing/format/lobby/stats/request/index.ts +19 -3
- package/src/photon/balancing/format/once/request/index.ts +31 -8
- package/src/photon/balancing/format/properties/get/request/index.ts +31 -4
- package/src/photon/balancing/format/properties/set/request/index.ts +36 -7
- package/src/photon/balancing/format/raise/request/index.ts +76 -10
- package/src/photon/balancing/format/reader/index.ts +75 -6
- package/src/photon/balancing/format/regions/request/index.ts +16 -1
- package/src/photon/balancing/format/rpc/request/index.ts +26 -3
- package/src/photon/balancing/format/settings/request/index.ts +15 -2
- package/src/photon/balancing/format/shared/credentials/index.ts +77 -33
- package/src/photon/balancing/format/shared/lobby/index.ts +41 -5
- package/src/photon/balancing/format/shared/options/index.ts +56 -24
- package/src/photon/balancing/format/table/index.ts +399 -0
- package/src/photon/balancing/index.ts +11 -1
- package/src/photon/balancing/travel/index.ts +15 -12
- package/src/photon/client/connection/index.ts +6 -6
- package/src/photon/cluster/back/index.ts +32 -45
- package/src/photon/cluster/dresser/index.ts +7 -8
- package/src/photon/cluster/front/index.ts +25 -49
- package/src/photon/cluster/grid/index.ts +1 -1
- package/src/photon/cluster/mover/index.ts +12 -12
- package/src/photon/cluster/press/index.ts +2 -18
- package/src/photon/cluster/route/game/index.ts +9 -11
- package/src/photon/cluster/route/master/index.ts +15 -34
- package/src/photon/cluster/route/name/index.ts +4 -21
- package/src/photon/cluster/seat/game/index.ts +6 -26
- package/src/photon/cluster/seat/master/index.ts +1 -1
- package/src/photon/cluster/sessions/index.ts +5 -6
- package/src/photon/cluster/spread/index.ts +8 -147
- package/src/photon/enet/client/index.ts +1 -8
- package/src/photon/enet/gateway/index.ts +5 -15
- package/src/photon/enet/index.ts +1 -1
- package/src/photon/enet/link/index.ts +34 -15
- package/src/photon/enet/outbound/index.ts +279 -0
- package/src/photon/enet/peer/index.ts +59 -0
- package/src/photon/enet/transport/index.ts +8 -24
- package/src/photon/game/admission/index.ts +353 -0
- package/src/photon/game/bag/index.ts +13 -0
- package/src/photon/game/broadcast/index.ts +79 -0
- package/src/photon/game/editor/index.ts +446 -0
- package/src/photon/game/gate/index.ts +9 -8
- package/src/photon/game/handler/index.ts +30 -3
- package/src/photon/game/history/index.ts +234 -0
- package/src/photon/game/hooked/index.ts +16 -15
- package/src/photon/game/index.ts +12 -1
- package/src/photon/game/lifecycle/index.ts +193 -0
- package/src/photon/game/peer/index.ts +1 -10
- package/src/photon/game/properties/index.ts +342 -0
- package/src/photon/game/room/index.ts +435 -1793
- package/src/photon/game/rooms/index.ts +2 -1
- package/src/photon/game/seats/index.ts +237 -0
- package/src/photon/game/server/index.ts +12 -2
- package/src/photon/game/services/index.ts +41 -0
- package/src/photon/game/settings/index.ts +22 -0
- package/src/photon/game/snapshot/index.ts +133 -0
- package/src/photon/game/throttle/index.ts +60 -0
- package/src/photon/game/touch/index.ts +2 -5
- package/src/photon/game/venue/index.ts +31 -0
- package/src/photon/master/application/index.ts +7 -0
- package/src/photon/master/gate/index.ts +12 -8
- package/src/photon/master/handler/index.ts +36 -748
- package/src/photon/master/index.ts +5 -0
- package/src/photon/master/list/sql/index.ts +37 -3
- package/src/photon/master/listing/index.ts +133 -0
- package/src/photon/master/lobby/index.ts +9 -0
- package/src/photon/master/login/index.ts +424 -0
- package/src/photon/master/matchmaking/index.ts +282 -0
- package/src/photon/master/query/index.ts +45 -0
- package/src/photon/master/redirect/index.ts +8 -7
- package/src/photon/master/services/index.ts +35 -0
- package/src/photon/master/settings/index.ts +44 -0
- package/src/photon/master/sql/cost/index.ts +263 -0
- package/src/photon/master/sql/index.ts +1 -0
- package/src/photon/message/client/index.ts +14 -11
- package/src/photon/message/handler/index.ts +22 -64
- package/src/photon/message/pipeline/index.ts +12 -12
- package/src/photon/message/server/index.ts +87 -43
- package/src/photon/message/watch/index.ts +14 -37
- package/src/photon/server/deferral/index.ts +57 -0
- package/src/photon/server/host/index.ts +32 -10
- package/src/photon/server/index.ts +1 -0
- package/src/photon/tcp/client/index.ts +1 -1
- package/src/photon/tcp/codec/index.ts +13 -42
- package/src/photon/tcp/server/index.ts +4 -4
- package/src/photon/websocket/bridge/index.ts +16 -20
- package/src/photon/websocket/message/index.ts +27 -39
- package/src/photon/websocket/path/index.ts +2 -5
- package/src/scale/fanout/index.ts +6 -6
- package/src/scale/index.ts +2 -4
- package/src/scale/outbound/index.ts +192 -0
- package/src/scale/relay/index.ts +20 -31
- package/src/scale/sink/index.ts +6 -11
- package/src/scale/transport/index.ts +27 -44
- package/src/scale/tunnel/index.ts +37 -91
- package/src/smartfox/common/bluebox/gateway/index.ts +401 -0
- package/src/smartfox/common/bluebox/index.ts +4 -0
- package/src/smartfox/{x2 → common}/bluebox/transport/index.ts +36 -23
- package/src/smartfox/common/index.ts +5 -0
- package/src/smartfox/common/strikes/index.ts +74 -0
- package/src/smartfox/pro/bluebox/index.ts +176 -4
- package/src/smartfox/pro/codec/index.ts +8 -7
- package/src/smartfox/pro/escalation/index.ts +28 -20
- package/src/smartfox/pro/flood/index.ts +2 -2
- package/src/smartfox/pro/format/extension/raw/index.ts +12 -2
- package/src/smartfox/pro/handler/chat/index.ts +11 -8
- package/src/smartfox/pro/handler/login/index.ts +2 -25
- package/src/smartfox/pro/handler/shared/index.ts +4 -3
- package/src/smartfox/pro/index.ts +11 -5
- package/src/smartfox/pro/login/gate/index.ts +166 -0
- package/src/smartfox/pro/login/index.ts +1 -0
- package/src/smartfox/pro/moderation/index.ts +220 -0
- package/src/smartfox/pro/options/index.ts +5 -5
- package/src/smartfox/pro/protocol/index.ts +62 -8
- package/src/smartfox/pro/web/index.ts +33 -26
- package/src/smartfox/pro/zone/index.ts +59 -282
- package/src/smartfox/pro/zones/index.ts +3 -3
- package/src/smartfox/x2/bluebox/index.ts +149 -4
- package/src/smartfox/x2/chat/index.ts +9 -19
- package/src/smartfox/x2/codec/index.ts +31 -39
- package/src/smartfox/x2/config/index.ts +6 -1
- package/src/smartfox/x2/data/array/index.ts +96 -60
- package/src/smartfox/x2/data/object/index.ts +144 -82
- package/src/smartfox/x2/data/serializer/index.ts +41 -23
- package/src/smartfox/x2/flood/gate/index.ts +19 -13
- package/src/smartfox/x2/format/buddy/init/response/index.ts +4 -3
- package/src/smartfox/x2/format/find/rooms/response/index.ts +4 -3
- package/src/smartfox/x2/format/find/users/response/index.ts +4 -3
- package/src/smartfox/x2/format/group/subscribe/response/index.ts +4 -3
- package/src/smartfox/x2/format/login/response/index.ts +4 -3
- package/src/smartfox/x2/format/mmo/position/response/index.ts +8 -6
- package/src/smartfox/x2/format/room/join/response/index.ts +4 -3
- package/src/smartfox/x2/games/index.ts +35 -8
- package/src/smartfox/x2/hall/index.ts +0 -6
- package/src/smartfox/x2/handler/session/index.ts +1 -1
- package/src/smartfox/x2/index.ts +8 -3
- package/src/smartfox/x2/member/index.ts +10 -3
- package/src/smartfox/x2/packet/login/response/index.ts +12 -0
- package/src/smartfox/x2/protocol/index.ts +11 -1
- package/src/smartfox/x2/rooms/index.ts +1 -2
- package/src/smartfox/x2/sessions/index.ts +6 -0
- package/src/smartfox/x2/udp/index.ts +61 -24
- package/src/smartfox/x2/web/index.ts +35 -17
- package/src/smartfox/x2/websocket/index.ts +18 -36
- package/src/smartfox/x2/zone/index.ts +77 -28
- package/src/smartfox/x2/zones/index.ts +17 -5
- package/src/photon/enet/handler/index.ts +0 -65
- package/src/scale/hosted/index.ts +0 -68
- package/src/scale/outlet/index.ts +0 -121
- package/src/smartfox/pro/bluebox/gateway/index.ts +0 -310
- package/src/smartfox/pro/bluebox/session/index.ts +0 -63
- package/src/smartfox/pro/bluebox/transport/index.ts +0 -104
- package/src/smartfox/x2/bluebox/gateway/index.ts +0 -315
- /package/src/smartfox/{x2 → common}/bluebox/session/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/memory/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/offender/index.ts +0 -0
- /package/src/smartfox/{pro → common}/counters/store/index.ts +0 -0
- /package/src/smartfox/{pro → common}/sequence/index.ts +0 -0
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
import type { Transport } from '@netifyjs/netify'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* What a moved session's transport tells the tunnel
|
|
5
|
-
*/
|
|
6
|
-
export type TransportEvents = {
|
|
7
|
-
/**
|
|
8
|
-
* The session wrote bytes
|
|
9
|
-
* @param bytes a borrowed view of what was written
|
|
10
|
-
*/
|
|
11
|
-
wrote(bytes: Uint8Array): void
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The session hung up
|
|
15
|
-
*/
|
|
16
|
-
ended(): void
|
|
17
|
-
}
|
|
3
|
+
import type { TunnelSink } from '../outbound/index.ts'
|
|
18
4
|
|
|
19
5
|
/**
|
|
20
6
|
* Stands in for the socket of a session whose client is on another shard
|
|
@@ -22,91 +8,88 @@ export type TransportEvents = {
|
|
|
22
8
|
*/
|
|
23
9
|
export class TunnelTransport implements Transport {
|
|
24
10
|
/**
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
public readonly datagram: boolean = false
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Where the client connected from
|
|
11
|
+
* The client's address on its own shard
|
|
31
12
|
*/
|
|
32
13
|
public readonly remoteAddress: string
|
|
33
14
|
|
|
34
15
|
/**
|
|
35
|
-
*
|
|
16
|
+
* The client's port on its own shard
|
|
36
17
|
*/
|
|
37
18
|
public readonly remotePort: number
|
|
38
19
|
|
|
39
20
|
/**
|
|
40
|
-
* Whether
|
|
21
|
+
* Whether the session is over
|
|
41
22
|
*/
|
|
42
23
|
public ended: boolean
|
|
43
24
|
|
|
44
25
|
/**
|
|
45
|
-
*
|
|
26
|
+
* Where frames go
|
|
46
27
|
*/
|
|
47
|
-
|
|
28
|
+
private readonly sink: TunnelSink
|
|
48
29
|
|
|
49
30
|
/**
|
|
50
|
-
* Hears
|
|
31
|
+
* Hears that the session ended here
|
|
51
32
|
*/
|
|
52
|
-
private readonly
|
|
33
|
+
private readonly over: () => void
|
|
53
34
|
|
|
54
35
|
/**
|
|
55
|
-
* @param remoteAddress
|
|
56
|
-
* @param remotePort
|
|
57
|
-
* @param
|
|
36
|
+
* @param remoteAddress the client's address on its own shard
|
|
37
|
+
* @param remotePort the client's port on its own shard
|
|
38
|
+
* @param sink where frames go
|
|
39
|
+
* @param over hears that the session ended here
|
|
58
40
|
*/
|
|
59
41
|
public constructor(
|
|
60
42
|
remoteAddress: string,
|
|
61
43
|
remotePort: number,
|
|
62
|
-
|
|
44
|
+
sink: TunnelSink,
|
|
45
|
+
over: () => void,
|
|
63
46
|
) {
|
|
64
47
|
this.remoteAddress = remoteAddress
|
|
65
48
|
this.remotePort = remotePort
|
|
66
|
-
this.
|
|
49
|
+
this.sink = sink
|
|
50
|
+
this.over = over
|
|
67
51
|
this.ended = false
|
|
68
|
-
this.paused = false
|
|
69
52
|
}
|
|
70
53
|
|
|
71
54
|
/**
|
|
72
|
-
*
|
|
73
|
-
* @param bytes
|
|
55
|
+
* Hands bytes to the client's shard
|
|
56
|
+
* @param bytes one or more whole frames
|
|
74
57
|
*/
|
|
75
58
|
public write(bytes: Uint8Array): number {
|
|
76
59
|
if (this.ended) return -1
|
|
77
60
|
|
|
78
|
-
this.
|
|
61
|
+
this.sink(bytes, 0, bytes.length)
|
|
79
62
|
return bytes.length
|
|
80
63
|
}
|
|
81
64
|
|
|
82
65
|
/**
|
|
83
|
-
*
|
|
66
|
+
* Ends the session and tells the client's shard
|
|
84
67
|
*/
|
|
85
68
|
public end(): void {
|
|
86
69
|
if (this.ended) return
|
|
87
70
|
|
|
88
71
|
this.ended = true
|
|
89
|
-
this.
|
|
72
|
+
this.over()
|
|
90
73
|
}
|
|
91
74
|
|
|
92
75
|
/**
|
|
93
|
-
*
|
|
76
|
+
* Ends the session without telling anyone
|
|
94
77
|
*/
|
|
95
78
|
public cut(): void {
|
|
96
79
|
this.ended = true
|
|
97
80
|
}
|
|
98
81
|
|
|
99
82
|
/**
|
|
100
|
-
*
|
|
83
|
+
* Can't stop the other shard, so the channel holds reads back itself
|
|
101
84
|
*/
|
|
102
|
-
public pause():
|
|
103
|
-
|
|
85
|
+
public pause(): boolean {
|
|
86
|
+
return false
|
|
104
87
|
}
|
|
105
88
|
|
|
106
89
|
/**
|
|
107
|
-
*
|
|
90
|
+
* Nothing to resume
|
|
108
91
|
*/
|
|
109
92
|
public resume(): void {
|
|
110
|
-
|
|
93
|
+
return
|
|
111
94
|
}
|
|
112
95
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AttributeKey,
|
|
3
2
|
ByteBuf,
|
|
3
|
+
Channel,
|
|
4
4
|
ShutdownEvent,
|
|
5
|
-
type Channel,
|
|
6
|
-
type ChannelHandler,
|
|
7
5
|
type ChannelSetup,
|
|
8
6
|
type Logger,
|
|
9
7
|
} from '@netifyjs/netify'
|
|
10
8
|
|
|
9
|
+
import { Session } from '../../dispatch/session/index.ts'
|
|
11
10
|
import { Batch, type BatchVisitor } from '../batch/index.ts'
|
|
12
11
|
import { Courier } from '../courier/index.ts'
|
|
13
|
-
import {
|
|
14
|
-
import { type OutletSink, TunnelOutlet } from '../outlet/index.ts'
|
|
12
|
+
import { TunnelOutbound, type TunnelSink } from '../outbound/index.ts'
|
|
15
13
|
import { Pending } from '../pending/index.ts'
|
|
16
14
|
import type { Portable, Reach } from '../portable/index.ts'
|
|
17
15
|
import { TunnelRelay } from '../relay/index.ts'
|
|
@@ -37,7 +35,7 @@ export type TunnelOptions<S> = {
|
|
|
37
35
|
readonly setup: ChannelSetup | null
|
|
38
36
|
|
|
39
37
|
/**
|
|
40
|
-
*
|
|
38
|
+
* Where moved sessions log
|
|
41
39
|
*/
|
|
42
40
|
readonly logger: Logger
|
|
43
41
|
}
|
|
@@ -152,12 +150,6 @@ type Stopping = readonly [id: number, deadline: number]
|
|
|
152
150
|
* @class
|
|
153
151
|
*/
|
|
154
152
|
export class Tunnel<S = unknown> {
|
|
155
|
-
/**
|
|
156
|
-
* Marks a connection whose client is on another shard
|
|
157
|
-
*/
|
|
158
|
-
private static readonly hosted: AttributeKey<boolean> =
|
|
159
|
-
new AttributeKey<boolean>('netify:protocol:scale:hosted')
|
|
160
|
-
|
|
161
153
|
/**
|
|
162
154
|
* Bytes a session id takes in front of a payload
|
|
163
155
|
*/
|
|
@@ -179,7 +171,7 @@ export class Tunnel<S = unknown> {
|
|
|
179
171
|
private readonly setup: ChannelSetup | null
|
|
180
172
|
|
|
181
173
|
/**
|
|
182
|
-
*
|
|
174
|
+
* Where moved sessions log
|
|
183
175
|
*/
|
|
184
176
|
private readonly logger: Logger
|
|
185
177
|
|
|
@@ -203,16 +195,6 @@ export class Tunnel<S = unknown> {
|
|
|
203
195
|
*/
|
|
204
196
|
private readonly lost: (shard: number) => void
|
|
205
197
|
|
|
206
|
-
/**
|
|
207
|
-
* Clients with broadcast bytes waiting to leave
|
|
208
|
-
*/
|
|
209
|
-
private readonly touched: Set<Channel>
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Sends the broadcast bytes that wait
|
|
213
|
-
*/
|
|
214
|
-
private readonly flusher: () => void
|
|
215
|
-
|
|
216
198
|
/**
|
|
217
199
|
* Replies waiting to go back to the clients' shards
|
|
218
200
|
*/
|
|
@@ -253,12 +235,6 @@ export class Tunnel<S = unknown> {
|
|
|
253
235
|
this.lost = (shard: number): void => {
|
|
254
236
|
this.abandon(shard)
|
|
255
237
|
}
|
|
256
|
-
this.touched = new Set<Channel>()
|
|
257
|
-
this.flusher = (): void => {
|
|
258
|
-
for (const channel of this.touched) channel.flushEncoded()
|
|
259
|
-
|
|
260
|
-
this.touched.clear()
|
|
261
|
-
}
|
|
262
238
|
this.downs = Pending.of(
|
|
263
239
|
this.courier,
|
|
264
240
|
'down',
|
|
@@ -291,16 +267,7 @@ export class Tunnel<S = unknown> {
|
|
|
291
267
|
const guest = this.guests.get(from)?.get(id)
|
|
292
268
|
if (guest === undefined) return
|
|
293
269
|
|
|
294
|
-
|
|
295
|
-
new ByteBuf(
|
|
296
|
-
bytes,
|
|
297
|
-
size,
|
|
298
|
-
ByteBuf.defaultMaxCapacity,
|
|
299
|
-
start,
|
|
300
|
-
start + size,
|
|
301
|
-
),
|
|
302
|
-
size,
|
|
303
|
-
)
|
|
270
|
+
guest.channel.receiveBytes(bytes.slice(start, start + size))
|
|
304
271
|
}
|
|
305
272
|
|
|
306
273
|
this.courier
|
|
@@ -341,14 +308,6 @@ export class Tunnel<S = unknown> {
|
|
|
341
308
|
return new Tunnel<S>(options)
|
|
342
309
|
}
|
|
343
310
|
|
|
344
|
-
/**
|
|
345
|
-
* Whether a connection's client is on another shard
|
|
346
|
-
* @param channel the connection handlers see
|
|
347
|
-
*/
|
|
348
|
-
public static carries(channel: Channel): boolean {
|
|
349
|
-
return channel.attributes.get<boolean>(Tunnel.hosted) === true
|
|
350
|
-
}
|
|
351
|
-
|
|
352
311
|
/**
|
|
353
312
|
* Hands a client's session to another shard
|
|
354
313
|
* @param channel the client's connection
|
|
@@ -402,9 +361,9 @@ export class Tunnel<S = unknown> {
|
|
|
402
361
|
pipeline.addLast<TunnelRelay>(this.courier.topic('relay'), relay)
|
|
403
362
|
|
|
404
363
|
for (const name of pipeline.names().reverse()) {
|
|
405
|
-
const handler = pipeline.get
|
|
364
|
+
const handler = pipeline.get(name)
|
|
406
365
|
if (handler === null || handler === relay) continue
|
|
407
|
-
if (this.portable.retires(handler)) pipeline.remove
|
|
366
|
+
if (this.portable.retires(handler)) pipeline.remove(name)
|
|
408
367
|
}
|
|
409
368
|
}
|
|
410
369
|
|
|
@@ -515,23 +474,7 @@ export class Tunnel<S = unknown> {
|
|
|
515
474
|
return
|
|
516
475
|
}
|
|
517
476
|
|
|
518
|
-
const
|
|
519
|
-
/**
|
|
520
|
-
* Sends what bypassed the pipeline
|
|
521
|
-
* @param bytes what the session wrote
|
|
522
|
-
*/
|
|
523
|
-
wrote: (bytes: Uint8Array): void => {
|
|
524
|
-
this.downs.hold(from, opening.id, bytes, 0, bytes.length)
|
|
525
|
-
},
|
|
526
|
-
/**
|
|
527
|
-
* Ends the session with its connection
|
|
528
|
-
*/
|
|
529
|
-
ended: (): void => {
|
|
530
|
-
this.forget(guest)
|
|
531
|
-
this.courier.tell(from, 'end', opening.id)
|
|
532
|
-
},
|
|
533
|
-
})
|
|
534
|
-
const sink: OutletSink = (
|
|
477
|
+
const sink: TunnelSink = (
|
|
535
478
|
source: Uint8Array,
|
|
536
479
|
start: number,
|
|
537
480
|
size: number,
|
|
@@ -540,7 +483,25 @@ export class Tunnel<S = unknown> {
|
|
|
540
483
|
this.downs.hold(from, opening.id, source, start, size)
|
|
541
484
|
}
|
|
542
485
|
}
|
|
543
|
-
const
|
|
486
|
+
const transport = new TunnelTransport(
|
|
487
|
+
opening.address,
|
|
488
|
+
opening.port,
|
|
489
|
+
sink,
|
|
490
|
+
(): void => {
|
|
491
|
+
this.forget(guest)
|
|
492
|
+
this.courier.tell(from, 'end', opening.id)
|
|
493
|
+
},
|
|
494
|
+
)
|
|
495
|
+
const channel = new Channel(transport, {
|
|
496
|
+
/**
|
|
497
|
+
* Where the session logs
|
|
498
|
+
*/
|
|
499
|
+
logger: this.logger,
|
|
500
|
+
/**
|
|
501
|
+
* Hands frames to the client's shard without a socket buffer
|
|
502
|
+
*/
|
|
503
|
+
outbound: TunnelOutbound.factory(sink),
|
|
504
|
+
})
|
|
544
505
|
const guest: Hosted = {
|
|
545
506
|
front: from,
|
|
546
507
|
id: opening.id,
|
|
@@ -553,23 +514,14 @@ export class Tunnel<S = unknown> {
|
|
|
553
514
|
guests.set(opening.id, guest)
|
|
554
515
|
this.guests.set(from, guests)
|
|
555
516
|
this.hosts.set(channel, guest)
|
|
556
|
-
|
|
517
|
+
Session.of(channel).moved = true
|
|
557
518
|
this.courier.tell(from, 'opened', opening.id)
|
|
558
519
|
|
|
559
|
-
channel
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
new TunnelOutlet(sink),
|
|
565
|
-
)
|
|
566
|
-
this.portable.adopt(fresh, opening.state)
|
|
567
|
-
})
|
|
568
|
-
.catch((err: unknown): void => {
|
|
569
|
-
this.logger.warn({ err }, 'Session failed to start')
|
|
570
|
-
this.evict(guest, true)
|
|
571
|
-
})
|
|
572
|
-
void channel.handleData(opening.bytes)
|
|
520
|
+
channel.activate((fresh: Channel): void => {
|
|
521
|
+
setup(fresh)
|
|
522
|
+
this.portable.adopt(fresh, opening.state)
|
|
523
|
+
})
|
|
524
|
+
channel.receiveBytes(opening.bytes)
|
|
573
525
|
}
|
|
574
526
|
|
|
575
527
|
/**
|
|
@@ -685,10 +637,7 @@ export class Tunnel<S = unknown> {
|
|
|
685
637
|
* @param bytes whole frames
|
|
686
638
|
*/
|
|
687
639
|
private share(channel: Channel, bytes: Uint8Array): void {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
channel.writeEncodedSync(bytes)
|
|
691
|
-
this.touched.add(channel)
|
|
640
|
+
channel.send(ByteBuf.wrap(bytes))
|
|
692
641
|
}
|
|
693
642
|
|
|
694
643
|
/**
|
|
@@ -699,10 +648,7 @@ export class Tunnel<S = unknown> {
|
|
|
699
648
|
private warn(guest: Hosted | undefined, deadline: number): void {
|
|
700
649
|
if (guest === undefined) return
|
|
701
650
|
|
|
702
|
-
|
|
703
|
-
void channel.execute((): Promise<void> =>
|
|
704
|
-
channel.pipeline.fireUserEventTriggered(new ShutdownEvent(deadline)),
|
|
705
|
-
)
|
|
651
|
+
guest.channel.pipeline.fireUserEventTriggered(new ShutdownEvent(deadline))
|
|
706
652
|
}
|
|
707
653
|
|
|
708
654
|
/**
|
|
@@ -731,7 +677,7 @@ export class Tunnel<S = unknown> {
|
|
|
731
677
|
guest.transport.cut()
|
|
732
678
|
if (notify) this.courier.tell(guest.front, 'end', guest.id)
|
|
733
679
|
|
|
734
|
-
|
|
680
|
+
guest.channel.ended()
|
|
735
681
|
}
|
|
736
682
|
|
|
737
683
|
/**
|