@netifyjs/protocol 1.0.0-alpha.2 → 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.
Files changed (183) hide show
  1. package/package.json +2 -2
  2. package/src/codec/index.ts +82 -157
  3. package/src/dispatch/dispatcher/index.ts +116 -33
  4. package/src/dispatch/session/index.ts +9 -3
  5. package/src/index.ts +2 -4
  6. package/src/photon/balancing/codec/index.ts +27 -53
  7. package/src/photon/balancing/format/authenticate/request/index.ts +52 -6
  8. package/src/photon/balancing/format/friends/request/index.ts +21 -5
  9. package/src/photon/balancing/format/game/create/request/index.ts +45 -8
  10. package/src/photon/balancing/format/game/debug/request/index.ts +19 -4
  11. package/src/photon/balancing/format/game/join/request/index.ts +65 -13
  12. package/src/photon/balancing/format/game/list/request/index.ts +29 -3
  13. package/src/photon/balancing/format/game/random/request/index.ts +58 -10
  14. package/src/photon/balancing/format/groups/request/index.ts +19 -3
  15. package/src/photon/balancing/format/index.ts +7 -0
  16. package/src/photon/balancing/format/leave/request/index.ts +19 -3
  17. package/src/photon/balancing/format/lobby/join/request/index.ts +23 -3
  18. package/src/photon/balancing/format/lobby/stats/request/index.ts +19 -3
  19. package/src/photon/balancing/format/once/request/index.ts +31 -8
  20. package/src/photon/balancing/format/properties/get/request/index.ts +31 -4
  21. package/src/photon/balancing/format/properties/set/request/index.ts +36 -7
  22. package/src/photon/balancing/format/raise/request/index.ts +76 -10
  23. package/src/photon/balancing/format/reader/index.ts +75 -6
  24. package/src/photon/balancing/format/regions/request/index.ts +16 -1
  25. package/src/photon/balancing/format/rpc/request/index.ts +26 -3
  26. package/src/photon/balancing/format/settings/request/index.ts +15 -2
  27. package/src/photon/balancing/format/shared/credentials/index.ts +77 -33
  28. package/src/photon/balancing/format/shared/lobby/index.ts +41 -5
  29. package/src/photon/balancing/format/shared/options/index.ts +56 -24
  30. package/src/photon/balancing/format/table/index.ts +399 -0
  31. package/src/photon/balancing/index.ts +11 -1
  32. package/src/photon/balancing/travel/index.ts +15 -12
  33. package/src/photon/binary/v18/index.ts +26 -1
  34. package/src/photon/binary/value/index.ts +52 -3
  35. package/src/photon/client/connection/index.ts +6 -6
  36. package/src/photon/cluster/back/index.ts +32 -45
  37. package/src/photon/cluster/dresser/index.ts +7 -8
  38. package/src/photon/cluster/front/index.ts +25 -49
  39. package/src/photon/cluster/grid/index.ts +1 -1
  40. package/src/photon/cluster/mover/index.ts +12 -12
  41. package/src/photon/cluster/press/index.ts +2 -18
  42. package/src/photon/cluster/route/game/index.ts +9 -11
  43. package/src/photon/cluster/route/master/index.ts +15 -34
  44. package/src/photon/cluster/route/name/index.ts +4 -21
  45. package/src/photon/cluster/seat/game/index.ts +6 -26
  46. package/src/photon/cluster/seat/master/index.ts +1 -1
  47. package/src/photon/cluster/sessions/index.ts +5 -6
  48. package/src/photon/cluster/spread/index.ts +8 -147
  49. package/src/photon/enet/client/index.ts +1 -8
  50. package/src/photon/enet/gateway/index.ts +5 -15
  51. package/src/photon/enet/index.ts +1 -1
  52. package/src/photon/enet/link/index.ts +34 -15
  53. package/src/photon/enet/outbound/index.ts +279 -0
  54. package/src/photon/enet/peer/index.ts +59 -0
  55. package/src/photon/enet/transport/index.ts +8 -24
  56. package/src/photon/game/admission/index.ts +353 -0
  57. package/src/photon/game/bag/index.ts +13 -0
  58. package/src/photon/game/broadcast/index.ts +79 -0
  59. package/src/photon/game/editor/index.ts +446 -0
  60. package/src/photon/game/gate/index.ts +9 -8
  61. package/src/photon/game/handler/index.ts +30 -3
  62. package/src/photon/game/history/index.ts +234 -0
  63. package/src/photon/game/hooked/index.ts +16 -15
  64. package/src/photon/game/index.ts +12 -1
  65. package/src/photon/game/lifecycle/index.ts +193 -0
  66. package/src/photon/game/peer/index.ts +1 -10
  67. package/src/photon/game/properties/index.ts +342 -0
  68. package/src/photon/game/room/index.ts +435 -1793
  69. package/src/photon/game/rooms/index.ts +2 -1
  70. package/src/photon/game/seats/index.ts +237 -0
  71. package/src/photon/game/server/index.ts +12 -2
  72. package/src/photon/game/services/index.ts +41 -0
  73. package/src/photon/game/settings/index.ts +22 -0
  74. package/src/photon/game/snapshot/index.ts +133 -0
  75. package/src/photon/game/throttle/index.ts +60 -0
  76. package/src/photon/game/touch/index.ts +2 -5
  77. package/src/photon/game/venue/index.ts +31 -0
  78. package/src/photon/master/application/index.ts +7 -0
  79. package/src/photon/master/gate/index.ts +12 -8
  80. package/src/photon/master/handler/index.ts +36 -748
  81. package/src/photon/master/index.ts +5 -0
  82. package/src/photon/master/list/sql/index.ts +37 -3
  83. package/src/photon/master/listing/index.ts +133 -0
  84. package/src/photon/master/lobby/index.ts +9 -0
  85. package/src/photon/master/login/index.ts +424 -0
  86. package/src/photon/master/matchmaking/index.ts +282 -0
  87. package/src/photon/master/query/index.ts +45 -0
  88. package/src/photon/master/redirect/index.ts +8 -7
  89. package/src/photon/master/services/index.ts +35 -0
  90. package/src/photon/master/settings/index.ts +44 -0
  91. package/src/photon/master/sql/cost/index.ts +263 -0
  92. package/src/photon/master/sql/index.ts +1 -0
  93. package/src/photon/message/binary/index.ts +35 -1
  94. package/src/photon/message/client/index.ts +14 -11
  95. package/src/photon/message/format/index.ts +9 -0
  96. package/src/photon/message/handler/index.ts +48 -63
  97. package/src/photon/message/pipeline/index.ts +12 -12
  98. package/src/photon/message/server/index.ts +87 -43
  99. package/src/photon/message/watch/index.ts +127 -15
  100. package/src/photon/server/config/index.ts +5 -0
  101. package/src/photon/server/deferral/index.ts +57 -0
  102. package/src/photon/server/host/index.ts +36 -10
  103. package/src/photon/server/index.ts +1 -0
  104. package/src/photon/server/listeners/index.ts +11 -0
  105. package/src/photon/tcp/client/index.ts +1 -1
  106. package/src/photon/tcp/codec/index.ts +41 -38
  107. package/src/photon/tcp/framing/index.ts +24 -4
  108. package/src/photon/tcp/server/index.ts +4 -4
  109. package/src/photon/websocket/bridge/index.ts +16 -20
  110. package/src/photon/websocket/message/index.ts +27 -39
  111. package/src/photon/websocket/path/index.ts +2 -5
  112. package/src/scale/batch/index.ts +14 -6
  113. package/src/scale/fanout/index.ts +6 -6
  114. package/src/scale/index.ts +2 -4
  115. package/src/scale/outbound/index.ts +192 -0
  116. package/src/scale/relay/index.ts +24 -16
  117. package/src/scale/sink/index.ts +6 -11
  118. package/src/scale/transport/index.ts +27 -44
  119. package/src/scale/tunnel/index.ts +56 -86
  120. package/src/smartfox/common/bluebox/gateway/index.ts +401 -0
  121. package/src/smartfox/common/bluebox/index.ts +4 -0
  122. package/src/smartfox/{x2 → common}/bluebox/transport/index.ts +36 -23
  123. package/src/smartfox/common/index.ts +5 -0
  124. package/src/smartfox/common/strikes/index.ts +74 -0
  125. package/src/smartfox/pro/bluebox/index.ts +176 -4
  126. package/src/smartfox/pro/codec/index.ts +8 -7
  127. package/src/smartfox/pro/escalation/index.ts +28 -20
  128. package/src/smartfox/pro/flood/index.ts +2 -2
  129. package/src/smartfox/pro/format/extension/raw/index.ts +12 -2
  130. package/src/smartfox/pro/handler/chat/index.ts +11 -8
  131. package/src/smartfox/pro/handler/login/index.ts +2 -25
  132. package/src/smartfox/pro/handler/shared/index.ts +4 -3
  133. package/src/smartfox/pro/index.ts +11 -5
  134. package/src/smartfox/pro/login/gate/index.ts +166 -0
  135. package/src/smartfox/pro/login/index.ts +1 -0
  136. package/src/smartfox/pro/moderation/index.ts +220 -0
  137. package/src/smartfox/pro/options/index.ts +5 -5
  138. package/src/smartfox/pro/protocol/index.ts +62 -8
  139. package/src/smartfox/pro/web/index.ts +33 -26
  140. package/src/smartfox/pro/zone/index.ts +59 -282
  141. package/src/smartfox/pro/zones/index.ts +3 -3
  142. package/src/smartfox/x2/bluebox/index.ts +149 -4
  143. package/src/smartfox/x2/chat/index.ts +9 -19
  144. package/src/smartfox/x2/codec/index.ts +34 -40
  145. package/src/smartfox/x2/config/index.ts +6 -1
  146. package/src/smartfox/x2/data/array/index.ts +96 -60
  147. package/src/smartfox/x2/data/object/index.ts +144 -82
  148. package/src/smartfox/x2/data/serializer/index.ts +41 -23
  149. package/src/smartfox/x2/flood/gate/index.ts +19 -13
  150. package/src/smartfox/x2/format/buddy/init/response/index.ts +4 -3
  151. package/src/smartfox/x2/format/find/rooms/response/index.ts +4 -3
  152. package/src/smartfox/x2/format/find/users/response/index.ts +4 -3
  153. package/src/smartfox/x2/format/group/subscribe/response/index.ts +4 -3
  154. package/src/smartfox/x2/format/login/response/index.ts +4 -3
  155. package/src/smartfox/x2/format/mmo/position/response/index.ts +8 -6
  156. package/src/smartfox/x2/format/room/join/response/index.ts +4 -3
  157. package/src/smartfox/x2/games/index.ts +35 -8
  158. package/src/smartfox/x2/hall/index.ts +0 -6
  159. package/src/smartfox/x2/handler/session/index.ts +1 -1
  160. package/src/smartfox/x2/index.ts +8 -3
  161. package/src/smartfox/x2/member/index.ts +10 -3
  162. package/src/smartfox/x2/packet/login/response/index.ts +12 -0
  163. package/src/smartfox/x2/protocol/index.ts +11 -1
  164. package/src/smartfox/x2/rooms/index.ts +1 -2
  165. package/src/smartfox/x2/sessions/index.ts +6 -0
  166. package/src/smartfox/x2/udp/index.ts +61 -24
  167. package/src/smartfox/x2/web/index.ts +35 -17
  168. package/src/smartfox/x2/websocket/index.ts +18 -36
  169. package/src/smartfox/x2/zone/index.ts +77 -28
  170. package/src/smartfox/x2/zones/index.ts +17 -5
  171. package/src/photon/enet/handler/index.ts +0 -65
  172. package/src/scale/hosted/index.ts +0 -68
  173. package/src/scale/outlet/index.ts +0 -121
  174. package/src/smartfox/pro/bluebox/gateway/index.ts +0 -310
  175. package/src/smartfox/pro/bluebox/session/index.ts +0 -63
  176. package/src/smartfox/pro/bluebox/transport/index.ts +0 -104
  177. package/src/smartfox/x2/bluebox/gateway/index.ts +0 -315
  178. /package/src/smartfox/{x2 → common}/bluebox/session/index.ts +0 -0
  179. /package/src/smartfox/{pro → common}/counters/index.ts +0 -0
  180. /package/src/smartfox/{pro → common}/counters/memory/index.ts +0 -0
  181. /package/src/smartfox/{pro → common}/counters/offender/index.ts +0 -0
  182. /package/src/smartfox/{pro → common}/counters/store/index.ts +0 -0
  183. /package/src/smartfox/{pro → common}/sequence/index.ts +0 -0
@@ -1,15 +1,10 @@
1
1
  import type { Transport } from '@netifyjs/netify'
2
2
 
3
3
  /**
4
- * A socket that throws away everything written to it
4
+ * A socket with nobody on the other end, for channels that only hold subscriptions
5
5
  * @class
6
6
  */
7
7
  export class SinkTransport implements Transport {
8
- /**
9
- * Never a datagram socket
10
- */
11
- public readonly datagram: boolean = false
12
-
13
8
  /**
14
9
  * No peer
15
10
  */
@@ -21,7 +16,7 @@ export class SinkTransport implements Transport {
21
16
  public readonly remotePort: number = 0
22
17
 
23
18
  /**
24
- * Takes the bytes and drops them
19
+ * Takes everything and drops it
25
20
  * @param bytes what was written
26
21
  */
27
22
  public write(bytes: Uint8Array): number {
@@ -29,17 +24,17 @@ export class SinkTransport implements Transport {
29
24
  }
30
25
 
31
26
  /**
32
- * Nothing to shut down
27
+ * Nothing to end
33
28
  */
34
29
  public end(): void {
35
30
  return
36
31
  }
37
32
 
38
33
  /**
39
- * Nothing to pause
34
+ * Nothing ever arrives
40
35
  */
41
- public pause(): void {
42
- return
36
+ public pause(): boolean {
37
+ return true
43
38
  }
44
39
 
45
40
  /**
@@ -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
- * Never a datagram socket
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
- * Port the client connected from
16
+ * The client's port on its own shard
36
17
  */
37
18
  public readonly remotePort: number
38
19
 
39
20
  /**
40
- * Whether either end hung up
21
+ * Whether the session is over
41
22
  */
42
23
  public ended: boolean
43
24
 
44
25
  /**
45
- * Whether the session asked for reads to stop
26
+ * Where frames go
46
27
  */
47
- public paused: boolean
28
+ private readonly sink: TunnelSink
48
29
 
49
30
  /**
50
- * Hears what the session does
31
+ * Hears that the session ended here
51
32
  */
52
- private readonly events: TransportEvents
33
+ private readonly over: () => void
53
34
 
54
35
  /**
55
- * @param remoteAddress where the client connected from
56
- * @param remotePort port the client connected from
57
- * @param events hears what the session does
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
- events: TransportEvents,
44
+ sink: TunnelSink,
45
+ over: () => void,
63
46
  ) {
64
47
  this.remoteAddress = remoteAddress
65
48
  this.remotePort = remotePort
66
- this.events = events
49
+ this.sink = sink
50
+ this.over = over
67
51
  this.ended = false
68
- this.paused = false
69
52
  }
70
53
 
71
54
  /**
72
- * Sends bytes towards the client
73
- * @param bytes what the session wrote
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.events.wrote(bytes)
61
+ this.sink(bytes, 0, bytes.length)
79
62
  return bytes.length
80
63
  }
81
64
 
82
65
  /**
83
- * Tells the client's shard to hang up
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.events.ended()
72
+ this.over()
90
73
  }
91
74
 
92
75
  /**
93
- * Stops writes after the client went away
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
- * Notes that the session asked for reads to stop
83
+ * Can't stop the other shard, so the channel holds reads back itself
101
84
  */
102
- public pause(): void {
103
- this.paused = true
85
+ public pause(): boolean {
86
+ return false
104
87
  }
105
88
 
106
89
  /**
107
- * Notes that the session takes reads again
90
+ * Nothing to resume
108
91
  */
109
92
  public resume(): void {
110
- this.paused = false
93
+ return
111
94
  }
112
95
  }
@@ -1,16 +1,15 @@
1
1
  import {
2
- AttributeKey,
2
+ ByteBuf,
3
+ Channel,
3
4
  ShutdownEvent,
4
- type Channel,
5
- type ChannelHandler,
6
5
  type ChannelSetup,
7
6
  type Logger,
8
7
  } from '@netifyjs/netify'
9
8
 
9
+ import { Session } from '../../dispatch/session/index.ts'
10
10
  import { Batch, type BatchVisitor } from '../batch/index.ts'
11
11
  import { Courier } from '../courier/index.ts'
12
- import { HostedChannel } from '../hosted/index.ts'
13
- import { type OutletSink, TunnelOutlet } from '../outlet/index.ts'
12
+ import { TunnelOutbound, type TunnelSink } from '../outbound/index.ts'
14
13
  import { Pending } from '../pending/index.ts'
15
14
  import type { Portable, Reach } from '../portable/index.ts'
16
15
  import { TunnelRelay } from '../relay/index.ts'
@@ -36,7 +35,7 @@ export type TunnelOptions<S> = {
36
35
  readonly setup: ChannelSetup | null
37
36
 
38
37
  /**
39
- * Hears about sessions that failed to start
38
+ * Where moved sessions log
40
39
  */
41
40
  readonly logger: Logger
42
41
  }
@@ -151,12 +150,6 @@ type Stopping = readonly [id: number, deadline: number]
151
150
  * @class
152
151
  */
153
152
  export class Tunnel<S = unknown> {
154
- /**
155
- * Marks a connection whose client is on another shard
156
- */
157
- private static readonly hosted: AttributeKey<boolean> =
158
- new AttributeKey<boolean>('netify:protocol:scale:hosted')
159
-
160
153
  /**
161
154
  * Bytes a session id takes in front of a payload
162
155
  */
@@ -178,7 +171,7 @@ export class Tunnel<S = unknown> {
178
171
  private readonly setup: ChannelSetup | null
179
172
 
180
173
  /**
181
- * Hears about sessions that failed to start
174
+ * Where moved sessions log
182
175
  */
183
176
  private readonly logger: Logger
184
177
 
@@ -202,16 +195,6 @@ export class Tunnel<S = unknown> {
202
195
  */
203
196
  private readonly lost: (shard: number) => void
204
197
 
205
- /**
206
- * Clients with broadcast bytes waiting to leave
207
- */
208
- private readonly touched: Set<Channel>
209
-
210
- /**
211
- * Sends the broadcast bytes that wait
212
- */
213
- private readonly flusher: () => void
214
-
215
198
  /**
216
199
  * Replies waiting to go back to the clients' shards
217
200
  */
@@ -252,12 +235,6 @@ export class Tunnel<S = unknown> {
252
235
  this.lost = (shard: number): void => {
253
236
  this.abandon(shard)
254
237
  }
255
- this.touched = new Set<Channel>()
256
- this.flusher = (): void => {
257
- for (const channel of this.touched) channel.flushEncoded()
258
-
259
- this.touched.clear()
260
- }
261
238
  this.downs = Pending.of(
262
239
  this.courier,
263
240
  'down',
@@ -272,11 +249,25 @@ export class Tunnel<S = unknown> {
272
249
  this.strand(ids)
273
250
  },
274
251
  )
275
- this.delivering = (id: number, bytes: Uint8Array): void => {
276
- this.fronted.get(id)?.relay.deliver(bytes)
252
+ this.delivering = (
253
+ id: number,
254
+ bytes: Uint8Array,
255
+ start: number,
256
+ size: number,
257
+ ): void => {
258
+ this.fronted.get(id)?.relay.deliver(bytes, start, size)
277
259
  }
278
- this.arriving = (id: number, bytes: Uint8Array, from: number): void => {
279
- void this.guests.get(from)?.get(id)?.channel.handleData(bytes)
260
+ this.arriving = (
261
+ id: number,
262
+ bytes: Uint8Array,
263
+ start: number,
264
+ size: number,
265
+ from: number,
266
+ ): void => {
267
+ const guest = this.guests.get(from)?.get(id)
268
+ if (guest === undefined) return
269
+
270
+ guest.channel.receiveBytes(bytes.slice(start, start + size))
280
271
  }
281
272
 
282
273
  this.courier
@@ -317,14 +308,6 @@ export class Tunnel<S = unknown> {
317
308
  return new Tunnel<S>(options)
318
309
  }
319
310
 
320
- /**
321
- * Whether a connection's client is on another shard
322
- * @param channel the connection handlers see
323
- */
324
- public static carries(channel: Channel): boolean {
325
- return channel.attributes.get<boolean>(Tunnel.hosted) === true
326
- }
327
-
328
311
  /**
329
312
  * Hands a client's session to another shard
330
313
  * @param channel the client's connection
@@ -378,9 +361,9 @@ export class Tunnel<S = unknown> {
378
361
  pipeline.addLast<TunnelRelay>(this.courier.topic('relay'), relay)
379
362
 
380
363
  for (const name of pipeline.names().reverse()) {
381
- const handler = pipeline.get<ChannelHandler>(name)
364
+ const handler = pipeline.get(name)
382
365
  if (handler === null || handler === relay) continue
383
- if (this.portable.retires(handler)) pipeline.remove<ChannelHandler>(name)
366
+ if (this.portable.retires(handler)) pipeline.remove(name)
384
367
  }
385
368
  }
386
369
 
@@ -491,23 +474,7 @@ export class Tunnel<S = unknown> {
491
474
  return
492
475
  }
493
476
 
494
- const transport = new TunnelTransport(opening.address, opening.port, {
495
- /**
496
- * Sends what bypassed the pipeline
497
- * @param bytes what the session wrote
498
- */
499
- wrote: (bytes: Uint8Array): void => {
500
- this.downs.hold(from, opening.id, bytes, 0, bytes.length)
501
- },
502
- /**
503
- * Ends the session with its connection
504
- */
505
- ended: (): void => {
506
- this.forget(guest)
507
- this.courier.tell(from, 'end', opening.id)
508
- },
509
- })
510
- const sink: OutletSink = (
477
+ const sink: TunnelSink = (
511
478
  source: Uint8Array,
512
479
  start: number,
513
480
  size: number,
@@ -516,7 +483,25 @@ export class Tunnel<S = unknown> {
516
483
  this.downs.hold(from, opening.id, source, start, size)
517
484
  }
518
485
  }
519
- const channel = new HostedChannel(transport, sink)
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
+ })
520
505
  const guest: Hosted = {
521
506
  front: from,
522
507
  id: opening.id,
@@ -529,23 +514,14 @@ export class Tunnel<S = unknown> {
529
514
  guests.set(opening.id, guest)
530
515
  this.guests.set(from, guests)
531
516
  this.hosts.set(channel, guest)
532
- channel.attributes.set<boolean>(Tunnel.hosted, true)
517
+ Session.of(channel).moved = true
533
518
  this.courier.tell(from, 'opened', opening.id)
534
519
 
535
- channel
536
- .activate(async (fresh: Channel): Promise<void> => {
537
- await setup(fresh)
538
- fresh.pipeline.addFirst<TunnelOutlet>(
539
- this.courier.topic('outlet'),
540
- new TunnelOutlet(sink),
541
- )
542
- this.portable.adopt(fresh, opening.state)
543
- })
544
- .catch((err: unknown): void => {
545
- this.logger.warn({ err }, 'Session failed to start')
546
- this.evict(guest, true)
547
- })
548
- 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)
549
525
  }
550
526
 
551
527
  /**
@@ -651,7 +627,7 @@ export class Tunnel<S = unknown> {
651
627
  if (session === undefined) continue
652
628
 
653
629
  if (session.reach === 'socket') this.share(session.channel, bytes)
654
- else session.relay.deliver(bytes)
630
+ else session.relay.deliver(bytes, 0, bytes.length)
655
631
  }
656
632
  }
657
633
 
@@ -661,10 +637,7 @@ export class Tunnel<S = unknown> {
661
637
  * @param bytes whole frames
662
638
  */
663
639
  private share(channel: Channel, bytes: Uint8Array): void {
664
- if (this.touched.size === 0) queueMicrotask(this.flusher)
665
-
666
- channel.writeEncodedSync(bytes)
667
- this.touched.add(channel)
640
+ channel.send(ByteBuf.wrap(bytes))
668
641
  }
669
642
 
670
643
  /**
@@ -675,10 +648,7 @@ export class Tunnel<S = unknown> {
675
648
  private warn(guest: Hosted | undefined, deadline: number): void {
676
649
  if (guest === undefined) return
677
650
 
678
- const channel = guest.channel
679
- void channel.execute((): Promise<void> =>
680
- channel.pipeline.fireUserEventTriggered(new ShutdownEvent(deadline)),
681
- )
651
+ guest.channel.pipeline.fireUserEventTriggered(new ShutdownEvent(deadline))
682
652
  }
683
653
 
684
654
  /**
@@ -707,7 +677,7 @@ export class Tunnel<S = unknown> {
707
677
  guest.transport.cut()
708
678
  if (notify) this.courier.tell(guest.front, 'end', guest.id)
709
679
 
710
- void guest.channel.handleClose()
680
+ guest.channel.ended()
711
681
  }
712
682
 
713
683
  /**