@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.
- package/package.json +2 -2
- package/src/codec/index.ts +82 -157
- package/src/dispatch/dispatcher/index.ts +116 -33
- package/src/dispatch/session/index.ts +9 -3
- 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/binary/v18/index.ts +26 -1
- package/src/photon/binary/value/index.ts +52 -3
- 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/binary/index.ts +35 -1
- package/src/photon/message/client/index.ts +14 -11
- package/src/photon/message/format/index.ts +9 -0
- package/src/photon/message/handler/index.ts +48 -63
- 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 +127 -15
- package/src/photon/server/config/index.ts +5 -0
- package/src/photon/server/deferral/index.ts +57 -0
- package/src/photon/server/host/index.ts +36 -10
- package/src/photon/server/index.ts +1 -0
- package/src/photon/server/listeners/index.ts +11 -0
- package/src/photon/tcp/client/index.ts +1 -1
- package/src/photon/tcp/codec/index.ts +41 -38
- package/src/photon/tcp/framing/index.ts +24 -4
- 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/batch/index.ts +14 -6
- 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 +24 -16
- package/src/scale/sink/index.ts +6 -11
- package/src/scale/transport/index.ts +27 -44
- package/src/scale/tunnel/index.ts +56 -86
- 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 +34 -40
- 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
package/src/scale/sink/index.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import type { Transport } from '@netifyjs/netify'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* A socket
|
|
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
|
|
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
|
|
27
|
+
* Nothing to end
|
|
33
28
|
*/
|
|
34
29
|
public end(): void {
|
|
35
30
|
return
|
|
36
31
|
}
|
|
37
32
|
|
|
38
33
|
/**
|
|
39
|
-
* Nothing
|
|
34
|
+
* Nothing ever arrives
|
|
40
35
|
*/
|
|
41
|
-
public pause():
|
|
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
|
-
*
|
|
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,16 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
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 {
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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 = (
|
|
276
|
-
|
|
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 = (
|
|
279
|
-
|
|
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
|
|
364
|
+
const handler = pipeline.get(name)
|
|
382
365
|
if (handler === null || handler === relay) continue
|
|
383
|
-
if (this.portable.retires(handler)) pipeline.remove
|
|
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
|
|
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
|
|
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
|
-
|
|
517
|
+
Session.of(channel).moved = true
|
|
533
518
|
this.courier.tell(from, 'opened', opening.id)
|
|
534
519
|
|
|
535
|
-
channel
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
680
|
+
guest.channel.ended()
|
|
711
681
|
}
|
|
712
682
|
|
|
713
683
|
/**
|